[x3d-public] issue with ClassCastException, X3DJSAIL: bollard.java, fix forconsistent implementation of X3DNode by Metadata* nodes; still a JSON problem

yottzumm at gmail.com yottzumm at gmail.com
Mon Feb 27 04:03:00 PST 2017



John, looks like there is still a problem in .x3d -> .json stylesheet conversion.  Output attached.  Perhaps you can spot the difficulty there?  Looks like the MetadataSet for EntityDefinition doesn't have a proper containerField setting.  Further trickiness...

aha.  Each MetadataSetObject has two child-field methods

   SFNode:
	setMetadata(X3DMetadataObject newValue)
	http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/sai/Core/MetadataSet.html#setMetadata-org.web3d.x3d.sai.Core.X3DMetadataObject-
   MFNode:
	setValue(X3DNode[] newValue)
	http://www.web3d.org/specifications/java/javadoc/org/web3d/x3d/sai/Core/MetadataSet.html#setValue-org.web3d.x3d.sai.Core.X3DNode:A-
--

I believe I use the setMetadata option, even with multiple metadata objects.  But I need to confirm that.  It seems very confusing that setValue is used with MFNode, but oh well.   Results of research:  I use setMetadata() with the Metadata* objects, and addValue() with the MetadataSet objects.  See Bollard.java attached.  So the addValue must have superceded the containerField somehow.  Hmm.  Ah yes, I see, the are duplicate keys in my JSON object, and the addValue value overwrites setMetadata.  Hmm.  Should it be setMetadata or addValue?  I believe this is the only place that I have addValue in my map to method object.  So we can delete the method, but the question becomes, where does it come from, and would addChildren/addChild be better?  Anyway excellent catch!  I know I have some overriding of child object types which comes from non-discriminatory use of the Object Model (and I need to redo this with the new object model).  Consider what addValue means and if you really mean addChildren.  IDK.

I checked the original model and it appears to have the correct Metadata* containerField values.

	https://savage.nps.edu/Savage/Buildings/SecurityPerimeter/BollardIndex.html
	https://savage.nps.edu/Savage/Buildings/SecurityPerimeter/Bollard.html
	https://savage.nps.edu/Savage/Buildings/SecurityPerimeter/Bollard.x3d

Excerpt:

<MetadataSet name='SMAL' reference=' https://savage.nps.edu/Savage/Tools/SMAL/SMAL.html ' containerField='metadata'>
	<MetadataString containerField='value' name='version' value='"1.0"'>
		<MetadataString name='appinfo' value='"This is the version of SMAL employed, not of the model."' containerField='metadata'/>
	</MetadataString>
	<MetadataSet containerField='value' name='EntityDefinition'>
	<!-- Identifying metadata for the current simulation of interest -->
		etc.

John, it appears that you must already look at containerField values when populating MetadataSet children appropriately.  Please confirm whether all this makes sense.

This is what I do when I hit a containerField in DOM.  Grandparent is the parent of element.  Essentially, when I find a containerField in DOM, I create a set method based on the container field value, then call the set method on the parent node, passing the child.

       for (let a in element.attributes) {
                let attrs = element.attributes;
                try {
                        parseInt(a);
                        if (attrs.hasOwnProperty(a) && attrs[a].nodeType == 2) {
                                let attr = attrs[a].nodeName;
[snip]
                                if (attr === 'containerField') {
                                        let method = attrs[a].nodeValue;
                                        method = "set"+method.charAt(0).toUpperCase() + method.slice(1);
                                        str += "                "+grandparent.nodeName+gn+"."+method+"(";
                                        str += element.nodeName+n;
                                } else {
[snip]
  		   }
                                str += ");\n";
                        }
                } catch (e) {
                        console.error(e);
                }

I also disable regular parent/child adding/setting if the child has a containerField.

Not sure if that’s right or not.  Last I checked, it didn’t work with CADFace and Shape or perhaps Transform (shape container field), but something might have changed.  .  Attached is a recent set of files I worked with.

I do need to upgrade and run on a recent set of java files.  Mine are dated as of 2/26.

John
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170227/f2a238e8/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CadDesignPatternExampleBushing.diff
Type: application/octet-stream
Size: 4680 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170227/f2a238e8/attachment-0005.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CadDesignPatternExampleBushing.java
Type: application/octet-stream
Size: 12392 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170227/f2a238e8/attachment-0006.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CadDesignPatternExampleBushing.json
Type: application/json
Size: 9480 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170227/f2a238e8/attachment-0002.json>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CadDesignPatternExampleBushing.new.json
Type: application/json
Size: 9284 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170227/f2a238e8/attachment-0003.json>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CadDesignPatternExampleBushing.x3d
Type: application/octet-stream
Size: 3829 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170227/f2a238e8/attachment-0007.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: CadDesignPatternExampleBushing.x3d.new
Type: application/octet-stream
Size: 3829 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170227/f2a238e8/attachment-0008.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Bollard.java
Type: application/octet-stream
Size: 20061 bytes
Desc: not available
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20170227/f2a238e8/attachment-0009.obj>


More information about the x3d-public mailing list