14 Replies Latest reply on Jun 21, 2007 11:25 AM by cf_dev2

    javacast?

    ironyx Level 1
      I have finally gotten weblogic to work with coldfusion, still not sure completely how... but thanks to everyone who helped (esp cf_dev2 )~

      Now I have an error for one of the methods I am trying to call to load an xml file. It says that I am overloading the method and I need to use javacast. Now if no one feels like typing syntax I can probably look it up without too much issue, but if someone could humor me and tell me why I would really appreciate it. I like to understand how things work together... strange I know!

      Thanks again to all!
      Va. :-)
        • 1. Re: javacast?
          ironyx Level 1
          Oh... so when I looked up the syntax I found the answer as to why one uses them... now for a bigger issue.

          If you are trying to do a javacast and your two methods are:
          loadXML(java.io.InputStream is)
          &
          loadXML(org.xml.sax.InputSoource is)

          how the heck would you put a type for that? Now I am really perplexed!

          Thanks,
          Va.
          • 2. Re: javacast?
            Level 7
            > If you are trying to do a javacast and your two methods are:
            > loadXML(java.io.InputStream is)
            > &
            > loadXML(org.xml.sax.InputSoource is)
            >
            > how the heck would you put a type for that? Now I am really perplexed!

            You *don't* use javaCast() in this instance. javaCast() is for casting
            ambiguous (Adobe would prefer "typeless") CF variables to Java PRIMITIVES.

            These methods you cite call for specific Java object types to be passed in.
            Simply make sure the arguments you pass in ARE of the appropriate Java
            class.

            --
            Adam
            • 3. Re: javacast?
              Level 7
              ironyx wrote:
              > If you are trying to do a javacast and your two methods are:
              > loadXML(java.io.InputStream is)
              > &
              > loadXML(org.xml.sax.InputSoource is)
              >
              > how the heck would you put a type for that? Now I am really perplexed!

              you don't. you create those objects & add your data to them.
              • 4. Re: javacast?
                ironyx Level 1
                Sorry I was getting an error message that the method was not found, but I can see it in the class, there are the two and then the error message says that maybe the method is overloaded... and maybe I need to use javacast.

                So, what am I doing wrong?

                My code looks like:
                <cfscript>
                <bunch of connect info up here>
                jasperLoader = CreateObject("java", "net.sf.jasperreports.engine.xml.JRXmlLoader");
                jasperDesign = jasperLoader.loadXML(path\file.xml); <-- errors here
                <rest of script I have commented out for now>
                </cfscript>


                So any help would be appreciated. I have never done more than a simple class before so please stay very basic if you could!

                Thanks for your help and patience,
                Va. :-)
                • 5. Re: javacast?
                  Level 7
                  > jasperDesign = jasperLoader.loadXML(path\file.xml); <-- errors here

                  Well path\file.xml isn't even a string (which I might expect to work,
                  maybe), it's just a sequence of characters. So that won't wash.

                  You need to pass loadXML() either a java.io.InputStream or a
                  org.xml.sax.InputSoource (sic).

                  To do that, you need to first CREATE one of those objects.

                  --
                  Adam
                  • 6. javacast?
                    ironyx Level 1
                    Yeah, I figured that out after rereading what you guys typed, and then reading about what the method was expecting.

                    So I just created an an object thinking I could do:
                    input = CreateObject("java, "java.io.FileInputStream");
                    xmlStream = input.init("path\file.xml");
                    jasperLoader = CreateObject("java", "net.sf.jasperreports.engine.xml.JRXmlLoader");
                    jasperDesign = jasperLoader.loadXML(xmlStream);

                    That however doesn't work... now, I know I am trying to close a big knowledge gap and not doing so well, but I thought since there was a parameter that java.io.FileInputStream could take was a filename this might work... something else I am missing?

                    Thanks for all of your help!!!
                    Va.
                    • 7. Re: javacast?
                      insuractive Level 3
                      Have you tried using a complete file path to your XML file?

                      e.g.
                      xmlStream = input.init("C:\my\file\path\file.xml");
                      • 8. Re: javacast?
                        ironyx Level 1
                        yeah it is the whole path, I just shortened it for the forum. I have to type everything because my development side doesn't access the web... being lazy!

                        Thanks!
                        Va :-)
                        • 9. javacast?
                          cf_dev2 Level 1
                          Disclaimer: I haven't used any of these classes. I'm just reading the API ;-)

                          You need to instantiate the jasperLoader object before you call loadXML(). The JRXmlLoader class doesn't seem to have a default constructor, so you can't use jasperLoader.init();

                          The JRXmlLoader constructor accepts an org.apache.commons.digester.Digester object. So you'll need to create a digester object and pass it to init().

                          digester = createObject("java", "org.apache.commons.digester.Digester").init();
                          jasperLoader.init(digester);
                          jasperDesign = jasperLoader.loadXML(xmlStream);
                          ..

                          You may have to install the digester jar (if its not installed already ) and check the dependencies. You may need to install other jars as well.
                          http://jakarta.apache.org/commons/digester/

                          Constructors vary depending on the class you're using. So the java API is your best reference

                          JRXmlLoader API
                          Digester API
                          • 10. Re: javacast?
                            ironyx Level 1
                            cf-dev2, Thanks once again. I will work on that... I so appreciate your time and help!!!

                            I have some rather large knowledge gaps, so I am not even sure what to look for at some points. After I get done with this small "example" I need to read a lot before I try and tackle the "big" project. Any book suggestions would be really appreciated. I sucked it up and bought one of the dietal books which are great but any others that you know of, please let me know! of course a good portion of the docs are online, but it can be overwhelming...

                            Thanks bunches & bunches,
                            Va :-)
                            • 11. Re: javacast?
                              ironyx Level 1
                              I get an object instantiation exception...

                              it says the cause of this exception was that : .

                              So apprently my cause is a "." <-- little bugger... messing everything up...

                              Actually its on the digester line, and I have included the .jar, I will try checking the path too...

                              thanks!
                              Va.
                              • 12. Re: javacast?
                                cf_dev2 Level 1
                                I noticed the download page mentioned something about dependencies on other jars. Did you install any dependent jars too?

                                Check the stack trace message. It will be more informative than the infamous "cause of this exception was ." message.
                                • 13. Re: javacast?
                                  ironyx Level 1
                                  Yes, preposting of the last message i loaded all the dependant-type jar file... and the log files are not much more informative...of course I was just lookign in the normal coldfusion log files..if there is somewhere else please let me know. I would post it but my dev network is not the same as my internet network, so I would have to type it all out...

                                  I did get a coldfusion.runtime.java.JavaProxy.CreateObject(JavaProxy.java:130)

                                  which I did a search on and that wasn't very fruitful...

                                  thanks!
                                  Va.
                                  • 14. Re: javacast?
                                    cf_dev2 Level 1
                                    When you get the error, there should be a link near the bottom of the page titled stack trace. Click on it and look at the first dozen lines or so. Those should contain the relevant error.