[x3d-public] X3DJSAIL, X3dToJava.xslt and DOM X3DLoaderObject testing:anotherClassCastException

John Carlson yottzumm at gmail.com
Wed Jun 6 15:39:08 PDT 2018


I've got an issue with classpath's containing either ; on ubuntu, or :
under git bash (windows).   Can that be fixed in
www.web3d.org/x3d/stylesheets/java/nashorn/build.xml (several places,
search for ;)?

Thanks,

John

On Wed, Jun 6, 2018 at 6:20 PM Don Brutzman <brutzman at nps.edu> wrote:

> Hmmm.  Likely it is your version John, just checked and we have a working
> round-trip "smoke test" for this construct.
>
> http://www.web3d.org/specifications/java/X3DJSAIL.html#Examples
>
> Excerpts in the examples/ directory, presented in order of production:
>
> 1. HelloWorldProgram.java
>
> // ========== More object declarations, some with DEF values ==========
> String       defaultViewpointDEF = "DefaultView";
> String       topDownViewpointDEF = "TopDownView";
> ViewpointGroupObject  viewpointGroup = new ViewpointGroupObject(); //
> requires <component name='Navigation' level='3'/>
> ViewpointObject defaultViewpoint = new
> ViewpointObject(defaultViewpointDEF);
> ViewpointObject topDownViewpoint = new
> ViewpointObject(topDownViewpointDEF);
>
> 2. HelloWorldProgramOutput.x3d
>
> <ViewpointGroup description='Available viewpoints'>
>         <Viewpoint DEF='DefaultView' description='Hello X3DJSAIL'/>
>         <Viewpoint DEF='TopDownView' description='top-down view from
> above' orientation='1 0 0 -1.570796' position='0 100 0'/>
> </ViewpointGroup>
>
> 3. Ant build.xml in stylesheets/ parent directory:
>
>          <echo message="==========================================="/>
>          <echo message="org.web3d.x3d.jsail.CommandLine
> java/examples/HelloWorldProgramOutput.x3d -toZIP -toFile
> ${java.examples.dir}/HelloWorldProgramOutput.ant.zip"/>
>          <java classname="org.web3d.x3d.jsail.CommandLine"
> classpath="${java.jars.dir}/${jsai.full.archive.jar.name};."
> fork="${fork}">
>              <arg
> value="${java.examples.dir}/HelloWorldProgramOutput.x3d"/><!-- input model
> -->
>              <arg value="-toZIP"/>
>              <arg value="-toFile"/>
>              <arg
> value="${java.examples.dir}/HelloWorldProgramOutput.ant.zip"/>
>          </java>
>          <echo message="==========================================="/>
>
> 4. HelloWorldProgramOutputLog.txt
> ===========================================
> org.web3d.x3d.jsail.CommandLine java/examples/HelloWorldProgramOutput.x3d
> -toZIP -toFile java/examples/HelloWorldProgramOutput.ant.zip
> parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes,
> parsed using Document Object Model (DOM) X3DLoader
> parameter: "-toZIP" for conversion to compressed ZIP containing model
> parameter: "-toFile" "java/examples/HelloWorldProgramOutput.ant.zip" for
> result file name root java/examples/HelloWorldProgramOutput.ant
> convert to ZIP:
> source: java/examples/HelloWorldProgramOutput.x3d filesize 20956 bytes
> result: HelloWorldProgramOutput.ant.zip filesize 5574 bytes, compression
> 26.60% of original
> ===========================================
>
> 5. HelloWorldProgramOutput.ReloadedDOM.x3d
>
> <ViewpointGroup description='Available viewpoints'>
>         <Viewpoint DEF='DefaultView' description='Hello X3DJSAIL'/>
>         <Viewpoint DEF='TopDownView' description='top-down view from
> above' orientation='1 0 0 -1.570796' position='0 100 0'/>
> </ViewpointGroup>
>
> so in this case, YMMV likely indicates that you need an update.
>
>
> On 6/6/2018 2:37 PM, John Carlson wrote:
> > 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)
> >
> > $ cd /c/x3d-code/www.web3d.org/x3d/stylesheets/java/
> >
> > $ javac -cp lib/javax.json-api-1.0.jar
> src/net/coderextreme/X3DJSONLD.java
> >
> > $ cp src/net/coderextreme/X3DJSONLD.class classes/net/coderextreme/
> >
> > $ 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
> >
> > $ diff -w nashorn/examples/HelloWorldProgramOutput.Java.x3d
> nashorn/examples/Json.x3d
> >
> > 32a33,35
> >
> >  >         <meta name='translated' content='27 May 2018'/>
> >
> >  >         <meta name='generator' content='X3dToJson.xslt,
> http://www.web3d.org/x3d/stylesheets/X3dToJson.html'/>
> >
> >  >         <meta name='reference' content='X3D JSON encoding:
> http://www.web3d.org/wiki/index.php/X3D_JSON_Encoding'/>
> >
> > 35,38c38
> >
> > <         <ViewpointGroup description='Available viewpoints'>
> >
> > <             <Viewpoint DEF='DefaultView' description='Hello X3DJSAIL'/>
> >
> > <             <Viewpoint DEF='TopDownView' description='top-down view
> from above' orientation='1 0 0 -1.570796' position='0 100 0'/>
> >
> > <         </ViewpointGroup>
> >
> > ---
> >
> >  >         <ViewpointGroup description='Available viewpoints'/>
> >
> > You will see the missing Viewpoint’s (children of ViewpointGroup) as
> above.  Also jjs will generate significant output.
> >
> > I can’t connect through svn, so I may be out of date.
> >
> > John
> >
> > Sent from Mail <https://go.microsoft.com/fwlink/?LinkId=550986> for
> Windows 10
> >
> > *From: *Don Brutzman <mailto:brutzman at nps.edu>
> > *Sent: *Wednesday, June 6, 2018 9:41 AM
> > *To: *John Carlson <mailto:yottzumm at gmail.com>
> > *Cc: *x3d-public at web3d.org <mailto:x3d-public at web3d.org>
> > *Subject: *Re: X3DJSAIL, X3dToJava.xslt and DOM X3DLoaderObject
> testing:anotherClassCastException
> >
> > 1. Hi John, finally getting back to this one.
> >
> > On 4/30/2018 3:15 PM, John Carlson wrote:
> >
> >  > Previously reported problem, now assigned to the X3DLoaderObject, I
> believe.
> >
> >  >
> >
> >  > No Viewpoint children in X3D or JSON output.
> >
> > Not sure what that means?  Viewpoint node typically does not have any
> children, except perhaps for a Metadata* node or an IS/connect.
> >
> >  > 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.
> >
> >  >
> >
> >  > Can be regenerated by running `ant test.nashorn` in x3d-code/
> www.web3d.org/x3d/stylesheets/java
> >
> >  >
> >
> >  > See output in nashorn/examples/Json.{json,x3d}
> >
> >  >
> >
> >  > John
> >
> > OK have recently updated to Java JDK 1.8.0_172 and adjusted PATH to
> confirm jjs is running OK.
> >
> > Have also synchronized X3DJSAIL sudirectory nashorn/ and contents with
> subversion.
> >
> > I get the following outputs when running test.nashorn build target:
> >
> > ============================================================
> >
> > ant -f E:\\x3d-code\\www.web3d.org\\x3d\\stylesheets\\java test.nashorn
> >
> > test.nashorn:
> >
> > ===========================================
> >
> > ant nashorn/build.xml test.nashorn
> >
> > X3D Nashorn SAI Library.test.nashorn:
> >
> > Compile:
> >
> > Compiling 1 source file to E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\classes
> >
> > Compiling 1 source file to E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\classes
> >
> > Copy:
> >
> > Copying 1 file to E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\nashorn\examples
> >
> > 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
> >
> > Copying 1 file to E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\nashorn\examples
> >
> > 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
> >
> > Run:
> >
> > parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes,
> parsed using Document Object Model (DOM) X3DLoader
> >
> > parameter: "-tojs" for conversion to X3DJSONLD JavaScript source
> >
> > parameter: "-toFile"
> "nashorn/examples/HelloWorldProgramOutput.Nashorn.js" for result file name
> root nashorn/examples/HelloWorldProgramOutput.Nashorn
> >
> > convert to JS JavaScript:
> >
> > Warning: toFileJavaScript() is overwriting prior file
> nashorn/examples/HelloWorldProgramOutput.Nashorn.js
> >
> > Script DEF=colorTypeConversionScript contains CDATA source-code text,
> copied as "#sourceText" using "strings" mode
> >
> > Script DEF=MaterialModulatorScript contains CDATA source-code text,
> copied as "#sourceText" using "strings" mode
> >
> > TypeError: input.readAllBytes is not a function
> >
> > Error: Cannot read file [E:\x3d-code\www.web3d.org
> \x3d\stylesheets\java\nashorn\node_modules\xmldom\package.json]:
> >
> > [Error] TODO problem handling local exception within CommandLine, exiting
> >
> > 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
> >
> >                  at
> org.web3d.x3d.jsail.Core.X3DObject.toFileJavaScript(X3DObject.java:1662)
> >
> >                  at
> org.web3d.x3d.jsail.CommandLine.run(CommandLine.java:628)
> >
> >                  at
> org.web3d.x3d.jsail.CommandLine.main(CommandLine.java:163)
> >
> > parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes,
> parsed using Document Object Model (DOM) X3DLoader
> >
> > parameter: "-toJSON" for conversion to JSON encoding
> >
> > parameter: "-toFile"
> "nashorn/examples/HelloWorldProgramOutput.Java.json" for result file name
> root nashorn/examples/HelloWorldProgramOutput.Java
> >
> > convert to JSON:
> >
> > Warning: toFileStylesheetConversion(X3dToJson.xslt) is overwriting prior
> file nashorn/examples/HelloWorldProgramOutput.Java.json
> >
> > Script DEF=colorTypeConversionScript contains CDATA source-code text,
> copied as "#sourceText" using "strings" mode
> >
> > Script DEF=MaterialModulatorScript contains CDATA source-code text,
> copied as "#sourceText" using "strings" mode
> >
> > file conversion successful: HelloWorldProgramOutput.Java.json (39749
> bytes)
> >
> > parameter: source file HelloWorldProgramOutput.x3d filesize 20956 bytes,
> parsed using Document Object Model (DOM) X3DLoader
> >
> > parameter: "-toX3D" for conversion to X3D encoding
> >
> > parameter: "-toFile" "nashorn/examples/HelloWorldProgramOutput.Java.x3d"
> for result file name root nashorn/examples/HelloWorldProgramOutput.Java
> >
> > convert to X3D:
> >
> > Warning: toFileX3D() is overwriting prior file
> nashorn/examples/HelloWorldProgramOutput.Java.x3d
> >
> > file conversion successful: HelloWorldProgramOutput.Java.x3d (20956
> bytes)
> >
> > ===========================================
> >
> > ============================================================
> >
> > As you can see, the exception is in nashorn/jvm-npm.js:
> >
> >                  TypeError: input.readAllBytes is not a function
> >
> > Header in that file indicates that you have modified it.
> >
> > Specific javascript code block of interest:
> >
> >     function readFile (filename, core) {
> >
> >       var input;
> >
> >       try {
> >
> >         if (core) {
> >
> >           var classloader =
> java.lang.Thread.currentThread().getContextClassLoader();
> >
> >           input = classloader.getResourceAsStream(filename);
> >
> >         } else {
> >
> >                  input = new java.io.FileInputStream(filename);
> >
> >         }
> >
> >         return new java.lang.String(input.readAllBytes());
> >
> >       } catch (e) {
> >
> >         System.err.println(e);
> >
> >         throw new ModuleError('Cannot read file [' + filename + ']: ',
> 'IO_ERROR', e);
> >
> >       }
> >
> >     }
> >
> > 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.)
> >
> >
> https://docs.oracle.com/javase/8/docs/api/java/io/FileInputStream.html
> >
> > So it looks like you need another method.
> >
> > A search for "java.io.FileInputStream readAllBytes" provides a number of
> hits.  For example:
> >
> >                  File to byte[] in Java
> >
> >
> https://stackoverflow.com/questions/858980/file-to-byte-in-java
> >
> > 2. Continuing with your prior error console also appears fruitful:
> >
> >  >       [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
> >
> >  >
> >
> >  >       [exec] java.lang.ClassCastException:
> org.web3d.x3d.jsail.Navigation.ViewpointGroupObject cannot be cast to
> org.web3d.x3d.sai.Grouping.X3DGroupingNode
> >
> >  >
> >
> >  >       [exec]     at
> org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:1146)
> >
> >  >
> >
> >  >       [exec]     at
> org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:542)
> >
> >  >
> >
> >  >       [exec]     at
> org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:542)
> >
> >  >
> >
> >  >       [exec]     at
> org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:430)
> >
> >  >
> >
> >  >       [exec]     at
> org.web3d.x3d.jsail.X3DLoaderObject.toX3dObjectTree(X3DLoaderObject.java:399)
> >
> >  >
> >
> >  >       [exec]     at
> jdk.scripting.nashorn.scripts/jdk.nashorn.internal.scripts.Script$Recompilation$372$Json$cu1$restOf.:program(nashorn/examples/Json.js:15)
> >
> >  >
> >
> >  >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:655)
> >
> >  >
> >
> >  >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:513)
> >
> >  >
> >
> >  >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:527)
> >
> >  >
> >
> >  >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.tools.Shell.apply(Shell.java:519)
> >
> >  >
> >
> >  >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.tools.Shell.runScripts(Shell.java:448)
> >
> >  >
> >
> >  >       [exec]     at
> jdk.scripting.nashorn/jdk.nashorn.tools.Shell.run(Shell.java:186)
> >
> >  >
> >
> >  >       [exec]     at
> jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:104)
> >
> >  >
> >
> >  >       [exec]     at
> jdk.scripting.nashorn.shell/jdk.nashorn.tools.jjs.Main.main(Main.java:80)
> >
> > 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.
> >
> > 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.
> >
> > I've added a warning to X3D tooltips to clarify that.
> >
> > Hope next round of improvement/testing can sort this one out fully.
> all the best, Don
> --
> Don Brutzman  Naval Postgraduate School, Code USW/Br
> brutzman at nps.edu
> Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
> X3D graphics, virtual worlds, navy robotics
> http://faculty.nps.edu/brutzman
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://web3d.org/pipermail/x3d-public_web3d.org/attachments/20180606/a5b14526/attachment-0001.html>


More information about the x3d-public mailing list