Using Reflection but no network connection

  • Thread starter =?iso-8859-1?q?Jean-S=E9bastien_Goupil?=
  • Start date
?

=?iso-8859-1?q?Jean-S=E9bastien_Goupil?=

Hi,

I'm currently using Java5 and SAX Builder to read an XML file and load
dynamically by reflection classes from my packages.
The code tries to load each class represented by a tag, but if the
class doesn't exist, it tries to use the tag as a String member in the
previous loaded class.

The problem is that if the class represented by a tag doesn't exist,
Java will try to connect to the current website and ask for the class
file in the current working directory. I would like to prevent this
access because it takes a lot of time to parse a big XML file.

So, when the class is not found in the current package, I don't want
Java checks the server. Is there a way to do that?

Thank you very much
 
R

Roedy Green

So, when the class is not found in the current package, I don't want
Java checks the server. Is there a way to do that?

If you write your own ClassLoader you can define whatever behaviour
you want for where it searches for classes.

It sounds like a custom class loader might be being used already.
 
R

Raymond DeCampo

Jean-Sébastien Goupil said:
Hi,

I'm currently using Java5 and SAX Builder to read an XML file and load
dynamically by reflection classes from my packages.
The code tries to load each class represented by a tag, but if the
class doesn't exist, it tries to use the tag as a String member in the
previous loaded class.

The problem is that if the class represented by a tag doesn't exist,
Java will try to connect to the current website and ask for the class
file in the current working directory.

I'm assuming that we are talking about an applet?

I imagine that the problem is that the codebase is set to ".". Try
packaging your applet in such a way that this is not the case.
I would like to prevent this
access because it takes a lot of time to parse a big XML file.

So, when the class is not found in the current package, I don't want
Java checks the server. Is there a way to do that?

Thank you very much

HTH,
Ray
 
?

=?iso-8859-1?q?Jean-S=E9bastien_Goupil?=

Yes I'm using applet.
the classLoader is something like that :
try {
//qname = qname.substring(0, 1).toUpperCase() +
qname.substring(1);
element = (SimpleElement) Class.forName("utils.xml." +
qname) //$NON-NLS-1$
.newInstance();
} catch (Exception e) {
}

The forName checks in the package AND if it is not existing it checks
in the folder /utils/xml/... This completely slow the loading of the
applet...

You said to check the codebase. I don't really understand what do you
mean...
My codebase is
<object
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase="http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,7"

And there is no codebase in the <embed> tag...
When I print the codebase in the applet, I get the name of the server.
(http://.../)


Do you understand more what is the problem ?

Thank you for your help

Jean-Sébastien Goupil
 
R

Raymond DeCampo

Jean-Sébastien Goupil said:
Yes I'm using applet.
the classLoader is something like that :
try {
//qname = qname.substring(0, 1).toUpperCase() +
qname.substring(1);
element = (SimpleElement) Class.forName("utils.xml." +
qname) //$NON-NLS-1$
.newInstance();
} catch (Exception e) {
}

The forName checks in the package AND if it is not existing it checks
in the folder /utils/xml/... This completely slow the loading of the
applet...

You said to check the codebase. I don't really understand what do you
mean...
My codebase is
<object
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase="http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,7"

And there is no codebase in the <embed> tag...
When I print the codebase in the applet, I get the name of the server.
(http://.../)


Do you understand more what is the problem ?

Why don't you post the entire HTML snippet that defines your applet?

Ray
 
?

=?iso-8859-1?q?Jean-S=E9bastien_Goupil?=

Ok, I didn't think it was a good place to post it...
There is the code

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Trasitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Notificateur d'Alarme</title>
<style type="text/css">
body {
padding: 0px;
margin: 0px;
}
</style>
</head>
<body>

<object
classid="clsid:8AD9C840-044E-11D1-B3E9-00805F499D93"
codebase="http://java.sun.com/update/1.5.0/jinstall-1_5-windows-i586.cab#Version=5,0,0,7"
name="appletCristal"
standby="Please wait while downloading..."
border="0"
width="559"
height="431">
<param name="code" value="StartProgram" />
<param name="archive" value="jar/alarm.jar, jar/mail.jar,
jar/saaj-api.jar, jar/saaj-impl.jar, jar/activation.jar,
jar/FastInfoset.jar" />
<param name="type" value="application/x-java-applet;version=1.5" />
<param name="name" value="appletCristal" />
<param name="hostname" value="./WSDL/iLON100.WSDL" />
<param name="beepDelay" value="500" />

<comment>
<embed
type="application/x-java-applet;version=1.5"
code="StartProgram"
width="559"
height="431"
pluginspage="http://jdl.sun.com/webapps/getjava/BrowserRedirect?locale=en"
name="appletCristal"
archive="
jar/mail.jar,
jar/saaj-api.jar,
jar/saaj-impl.jar,
jar/activation.jar,
jar/FastInfoset.jar,
jar/alarm.jar"
hostname="./WSDL/iLON100.WSDL"
beepDelay="500">
<noembed>
You don't have any Java Program Installed.
</noembed>
</embed>
</comment>
</object>

</body>
</html>

Thank you !

Jean-Sébastien
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,175
Latest member
Vinay Kumar_ Nevatia
Top