Referring to a method when where are two

I am trying to use the folling methods from a Jasper Reports Class...

public JasperDesign loadXML (java.io.InputStream is)

public JasperDesign loadXML (org.xml.sax.InputSource is)

Now if it were something like loadXML(int) & loadXML(double) I know you would pass an int and or double and it would call whatever method you needed right?

I am trying to call these methods from another programming language that doesn't strongly type, so when I call I have to guess what the input would be so it knows which method to call... uh, so you see my dilema? Could someone explain what I might do in this case? I am new to java so fairly perplexed and a little slow, so please use small words. :-)

Thanks!

Va.

[748 byte] By [ironyxa] at [2007-11-27 8:11:20]
# 1
How are you calling these methods from a different language? Or can you be more specific with what you're doing and how you are doing it? Some sample code possibly?
bryanoa at 2007-7-12 19:55:18 > top of Java-index,Java Essentials,New To Java...
# 2

<cfscript>

<connection code here>

jasperLoader = CreateObject ("java", "net.sf.jasperreports.engine.xml.JRXmlLoader");

jasperDesign = jasperLoader.loadXML(file.xml);

</cfscript>

It's Coldfusion running on a Weblogic server and coldfusion doesn't pass the file in before it tries to grab the appropriate method loadXML.

My issue is that I have to do something called a javacast to get it to select a method like :

myMethod(int)

myMethod(double)

So I would call it using myMethod(javacast(int, variableToBePassed);

But with the type not being simple, I am not sure what to do...

Thanks!

Va.

ironyxa at 2007-7-12 19:55:18 > top of Java-index,Java Essentials,New To Java...
# 3
Subclass the object and create a new method with a different name but with the parameter you want to call it with, then call the loadXML method from this new method.Make sense?
bryanoa at 2007-7-12 19:55:18 > top of Java-index,Java Essentials,New To Java...
# 4

Not sure, but I usually use scripting languages... so please be patient...

I would create a subclass to my jasperReports Class... which would inherit all the methods (please correct me if you need, I don't do much in java)

Then I add a method to it which I can call from coldfusion and I don't have to type because there is only one, but when calling the loadXML method, how do I reference it so it knows which of the two to pick?

Thanks!!!

Va.

ironyxa at 2007-7-12 19:55:18 > top of Java-index,Java Essentials,New To Java...
# 5

From Java, create a new class that extends the JasperReports class. It would inherit all the methods from that class, but you aren't concerned with that, you just then essentially want to subclass the loadXML method, or create a new method with a new name, that will call the correct loadXML method from the parent class.

E.G.

public class YourClass extends JasperReports

{

public void yourLoadXMLMethod( yourparmeter )

{

super.loadXML( yourparameter );

}

}

Then call yourLoadXMLMethod from your cold fusion page.

bryanoa at 2007-7-12 19:55:18 > top of Java-index,Java Essentials,New To Java...
# 6
And it won't matter that there are two methods called loadXML with the same name in the parent class in the line:super.loadXML( yourparameter );Sorry, I really appreciate your patience and help!
ironyxa at 2007-7-12 19:55:18 > top of Java-index,Java Essentials,New To Java...
# 7
You new method will only take one parameter that will be of the correct type, so you call to super.loadXML will call the correct method that has the same type as the parameter to your method.
bryanoa at 2007-7-12 19:55:18 > top of Java-index,Java Essentials,New To Java...
# 8
Alright, thanks I will give it a try!
ironyxa at 2007-7-12 19:55:18 > top of Java-index,Java Essentials,New To Java...
# 9
Hey, me again, haven't gotten far. If I can't access the .jar file containing the class, can I still extend it? If so do I have to reference it using the dot notation?like net.sf.jasperreports.etc?Thanks!Va
ironyxa at 2007-7-12 19:55:18 > top of Java-index,Java Essentials,New To Java...
# 10

> Hey, me again, haven't gotten far. If I can't access

> the .jar file containing the class, can I still

> extend it?

Well, no. But where did that question come from? You're already using the jar file, aren't you? So how could you not be able to access it?

> If so do I have to reference it using the dot notation?

No, you can import classes and packages from it just like anything else.

DrClapa at 2007-7-12 19:55:18 > top of Java-index,Java Essentials,New To Java...