<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:#954F72;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang=EN-US link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal>Try stepping through with these commands at command prompt or similar (you’ll have to use diff and cp from Ubuntu, now available on Windows or similar commands under DOS)</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>$ cd /c/x3d-code/www.web3d.org/x3d/stylesheets/java/</p><p class=MsoNormal>$ javac -cp lib/javax.json-api-1.0.jar src/net/coderextreme/X3DJSONLD.java</p><p class=MsoNormal>$ cp src/net/coderextreme/X3DJSONLD.class classes/net/coderextreme/</p><p class=MsoNormal>$ jjs -cp "jars/X3DJSAIL.3.3.full.jar;classes" nashorn/examples/Json.js    # you may have to use the Java 8 way of specifying the classpath. See build.xml</p><p class=MsoNormal>$ diff -w nashorn/examples/HelloWorldProgramOutput.Java.x3d nashorn/examples/Json.x3d</p><p class=MsoNormal>32a33,35</p><p class=MsoNormal>>         <meta name='translated' content='27 May 2018'/></p><p class=MsoNormal>>         <meta name='generator' content='X3dToJson.xslt, http://www.web3d.org/x3d/stylesheets/X3dToJson.html'/></p><p class=MsoNormal>>         <meta name='reference' content='X3D JSON encoding: http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding'/></p><p class=MsoNormal>35,38c38</p><p class=MsoNormal><         <ViewpointGroup description='Available viewpoints'></p><p class=MsoNormal><             <Viewpoint DEF='DefaultView' description='Hello X3DJSAIL'/></p><p class=MsoNormal><             <Viewpoint DEF='TopDownView' description='top-down view from above' orientation='1 0 0 -1.570796' position='0 100 0'/></p><p class=MsoNormal><         </ViewpointGroup></p><p class=MsoNormal>---</p><p class=MsoNormal>>         <ViewpointGroup description='Available viewpoints'/></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>You will see the missing Viewpoint’s (children of ViewpointGroup) as above.  Also jjs will generate significant output.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I can’t connect through svn, so I may be out of date.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>John</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Sent from <a href="https://go.microsoft.com/fwlink/?LinkId=550986">Mail</a> for Windows 10</p><p class=MsoNormal><o:p> </o:p></p><div style='mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal style='border:none;padding:0in'><b>From: </b><a href="mailto:brutzman@nps.edu">Don Brutzman</a><br><b>Sent: </b>Wednesday, June 6, 2018 9:41 AM<br><b>To: </b><a href="mailto:yottzumm@gmail.com">John Carlson</a><br><b>Cc: </b><a href="mailto:x3d-public@web3d.org">x3d-public@web3d.org</a><br><b>Subject: </b>Re: X3DJSAIL, X3dToJava.xslt and DOM X3DLoaderObject testing:anotherClassCastException</p></div><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>1. Hi John, finally getting back to this one.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>On 4/30/2018 3:15 PM, John Carlson wrote:</p><p class=MsoNormal>> Previously reported problem, now assigned to the X3DLoaderObject, I believe.</p><p class=MsoNormal>> </p><p class=MsoNormal>> No Viewpoint children in X3D or JSON output.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Not sure what that means?  Viewpoint node typically does not have any children, except perhaps for a Metadata* node or an IS/connect.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>> Is a problem with X3DLoaderObject, looks like another class cast exception.  X3DJSONLD was eliminated from the problem by printing out the DOM object, and verifying the Viewpoint objects were there.   See x3d-code/www.web3d.org/x3d/stylesheets/java/nashorn/examples/Quotes.js.</p><p class=MsoNormal>> </p><p class=MsoNormal>> Can be regenerated by running `ant test.nashorn` in x3d-code/www.web3d.org/x3d/stylesheets/java</p><p class=MsoNormal>> </p><p class=MsoNormal>> See output in nashorn/examples/Json.{json,x3d}</p><p class=MsoNormal>> </p><p class=MsoNormal>> John</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>OK have recently updated to Java JDK 1.8.0_172 and adjusted PATH to confirm jjs is running OK.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Have also synchronized X3DJSAIL sudirectory nashorn/ and contents with subversion.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I get the following outputs when running test.nashorn build target:</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>============================================================</p><p class=MsoNormal>ant -f E:\\x3d-code\\www.web3d.org\\x3d\\stylesheets\\java test.nashorn</p><p class=MsoNormal>test.nashorn:</p><p class=MsoNormal>===========================================</p><p class=MsoNormal>ant nashorn/build.xml test.nashorn</p><p class=MsoNormal>X3D Nashorn SAI Library.test.nashorn:</p><p class=MsoNormal>Compile:</p><p class=MsoNormal>Compiling 1 source file to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\classes</p><p class=MsoNormal>Compiling 1 source file to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\classes</p><p class=MsoNormal>Copy:</p><p class=MsoNormal>Copying 1 file to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\nashorn\examples</p><p class=MsoNormal>Copying E:\x3d-code\www.web3d.org\x3d\stylesheets\java\examples\HelloWorldProgramOutput.x3d to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\nashorn\examples\HelloWorldProgramOutput.x3d</p><p class=MsoNormal>Copying 1 file to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\nashorn\examples</p><p class=MsoNormal>Copying E:\x3d-code\www.web3d.org\x3d\stylesheets\java\examples\HelloWorldProgramOutput.json to E:\x3d-code\www.web3d.org\x3d\stylesheets\java\nashorn\examples\HelloWorldProgramOutput.json</p><p class=MsoNormal>Run:</p><p class=MsoNormal>parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes, parsed using Document Object Model (DOM) X3DLoader</p><p class=MsoNormal>parameter: "-tojs" for conversion to X3DJSONLD JavaScript source</p><p class=MsoNormal>parameter: "-toFile" "nashorn/examples/HelloWorldProgramOutput.Nashorn.js" for result file name root nashorn/examples/HelloWorldProgramOutput.Nashorn</p><p class=MsoNormal>convert to JS JavaScript:</p><p class=MsoNormal>Warning: toFileJavaScript() is overwriting prior file nashorn/examples/HelloWorldProgramOutput.Nashorn.js</p><p class=MsoNormal>Script DEF=colorTypeConversionScript contains CDATA source-code text, copied as "#sourceText" using "strings" mode</p><p class=MsoNormal>Script DEF=MaterialModulatorScript contains CDATA source-code text, copied as "#sourceText" using "strings" mode</p><p class=MsoNormal>TypeError: input.readAllBytes is not a function</p><p class=MsoNormal>Error: Cannot read file [E:\x3d-code\www.web3d.org\x3d\stylesheets\java\nashorn\node_modules\xmldom\package.json]:</p><p class=MsoNormal>[Error] TODO problem handling local exception within CommandLine, exiting</p><p class=MsoNormal>org.web3d.x3d.sai.X3DException: ScriptException when processing fileName nashorn\examples\HelloWorldProgramOutput.Nashorn.js.intermediate.js, unable to save result: javax.script.ScriptException: Error: Cannot load JSON file in nashorn/jvm-npm.js at line number 216 at column number 8</p><p class=MsoNormal>                at org.web3d.x3d.jsail.Core.X3DObject.toFileJavaScript(X3DObject.java:1662)</p><p class=MsoNormal>                at org.web3d.x3d.jsail.CommandLine.run(CommandLine.java:628)</p><p class=MsoNormal>                at org.web3d.x3d.jsail.CommandLine.main(CommandLine.java:163)</p><p class=MsoNormal>parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes, parsed using Document Object Model (DOM) X3DLoader</p><p class=MsoNormal>parameter: "-toJSON" for conversion to JSON encoding</p><p class=MsoNormal>parameter: "-toFile" "nashorn/examples/HelloWorldProgramOutput.Java.json" for result file name root nashorn/examples/HelloWorldProgramOutput.Java</p><p class=MsoNormal>convert to JSON:</p><p class=MsoNormal>Warning: toFileStylesheetConversion(X3dToJson.xslt) is overwriting prior file nashorn/examples/HelloWorldProgramOutput.Java.json</p><p class=MsoNormal>Script DEF=colorTypeConversionScript contains CDATA source-code text, copied as "#sourceText" using "strings" mode</p><p class=MsoNormal>Script DEF=MaterialModulatorScript contains CDATA source-code text, copied as "#sourceText" using "strings" mode</p><p class=MsoNormal>file conversion successful: HelloWorldProgramOutput.Java.json (39749 bytes)</p><p class=MsoNormal>parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes, parsed using Document Object Model (DOM) X3DLoader</p><p class=MsoNormal>parameter: "-toX3D" for conversion to X3D encoding</p><p class=MsoNormal>parameter: "-toFile" "nashorn/examples/HelloWorldProgramOutput.Java.x3d" for result file name root nashorn/examples/HelloWorldProgramOutput.Java</p><p class=MsoNormal>convert to X3D:</p><p class=MsoNormal>Warning: toFileX3D() is overwriting prior file nashorn/examples/HelloWorldProgramOutput.Java.x3d</p><p class=MsoNormal>file conversion successful: HelloWorldProgramOutput.Java.x3d (20956 bytes)</p><p class=MsoNormal>===========================================</p><p class=MsoNormal>============================================================</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>As you can see, the exception is in nashorn/jvm-npm.js:</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                TypeError: input.readAllBytes is not a function</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Header in that file indicates that you have modified it.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Specific javascript code block of interest:</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>   function readFile (filename, core) {</p><p class=MsoNormal>     var input;</p><p class=MsoNormal>     try {</p><p class=MsoNormal>       if (core) {</p><p class=MsoNormal>         var classloader = java.lang.Thread.currentThread().getContextClassLoader();</p><p class=MsoNormal>         input = classloader.getResourceAsStream(filename);</p><p class=MsoNormal>       } else {</p><p class=MsoNormal>                input = new java.io.FileInputStream(filename);</p><p class=MsoNormal>       }</p><p class=MsoNormal>       return new java.lang.String(input.readAllBytes());</p><p class=MsoNormal>     } catch (e) {</p><p class=MsoNormal>       System.err.println(e);</p><p class=MsoNormal>       throw new ModuleError('Cannot read file [' + filename + ']: ', 'IO_ERROR', e);</p><p class=MsoNormal>     }</p><p class=MsoNormal>   }</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>JDK 8 Javadoc for java.io.FileInputStream does not provide a "readAllBytes()" method.  (Nor does JDK 1.9; however I am currently holding at 1.8 to stay compatible with Netbeans 8.)</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                https://docs.oracle.com/javase/8/docs/api/java/io/FileInputStream.html</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>So it looks like you need another method.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>A search for "java.io.FileInputStream readAllBytes" provides a number of hits.  For example:</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>                File to byte[] in Java</p><p class=MsoNormal>                https://stackoverflow.com/questions/858980/file-to-byte-in-java</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>2. Continuing with your prior error console also appears fruitful:</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>>       [exec] [X3DLoaderObject error] Incorrectly handled object construction, current elementObject=ViewpointGroup (ViewpointGroup), child=Viewpoint, java.lang.ClassCastException: org.web3d.x3d.jsail.Navigation.ViewpointGroupObject cannot be cast to org.web3d.x3d.sai.Grouping.X3DGroupingNode</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec] java.lang.ClassCastException: org.web3d.x3d.jsail.Navigation.ViewpointGroupObject cannot be cast to org.web3d.x3d.sai.Grouping.X3DGroupingNode</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:1146)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:542)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:542)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:430)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:399)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$372$Json$cu1$restOf.:program(nashorn/examples/Json.js:15)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:655)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.apply(Shell.java:519)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.runScripts(Shell.java:448)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at jdk.scripting.nashorn/jdk.nashorn.tools.Shell.run(Shell.java:186)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:104)</p><p class=MsoNormal>> </p><p class=MsoNormal>>       [exec]     at jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:80)</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Looks like it was trying to treat ViewpointGroup like a X3DGroupingNode - but it is not.  ViewpointGroup is not a X3DGroupingNode node, and can only contain a Metadata* node, Viewpoint/OrthoViewpoint/GeoViewpoint and other ViewpointGroup nodes.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>This might have been fixed already as part of the many DOM loader improvements performed; not seeing that error in my console.  Worth retesting if you can address the readAllBytes issue.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I've added a warning to X3D tooltips to clarify that.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Hope next round of improvement/testing can sort this one out fully.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>all the best, Don</p><p class=MsoNormal>-- </p><p class=MsoNormal>Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman@nps.edu</p><p class=MsoNormal>Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149</p><p class=MsoNormal>X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p></div></body></html>