Here is the cvs diff -ubR file. It is going to take me some time with
the tests. I need to see what JaxME does there today, and to test with
a new classloader might make things a little more difficult as I have to
load classes from outside the system classloader for a real test of it.
thanks,
dean
Jochen Wiedmann wrote:
Dean,
I am basically quite ready to add the feature. I have certain
requirements though:
- First of all, to save me work, please be so kind to provide a context diff
(diff -ubR), becase that will allow me to detect much better what you
have actually changed.
- Second, in your own interest: If you want this feature to stick in the code,
please provide a unit test as well, that verifies whether it works. Otherwise,
there will be no references in the source code, and the danger is high, that
someone (aka me) will remove it in the future without prior notice.
Jochen
Index: ws-jaxme3/src/jaxme/org/apache/ws/jaxme/impl/Configuration.java
===================================================================
RCS file:
/home/cvspublic/ws-jaxme/src/jaxme/org/apache/ws/jaxme/impl/Configuration.java,v
retrieving revision 1.7
diff -u -b -r1.7 Configuration.java
--- ws-jaxme3/src/jaxme/org/apache/ws/jaxme/impl/Configuration.java 10 Mar
2005 10:14:03 -0000 1.7
+++ ws-jaxme3/src/jaxme/org/apache/ws/jaxme/impl/Configuration.java 16 Sep
2005 03:13:05 -0000
@@ -42,9 +42,11 @@
private Class jmMarshallerClass = JMMarshallerImpl.class;
private Class jmUnmarshallerClass = JMUnmarshallerImpl.class;
private Class jmValidatorClass = JMValidatorImpl.class;
+ private ClassLoader classLoader;
- public Configuration(JAXBContextImpl pContext) {
+ public Configuration(JAXBContextImpl pContext, ClassLoader cl) {
context = pContext;
+ this.classLoader = cl;
}
public class Manager implements JMManager {
@@ -80,7 +82,11 @@
private Class pmClass;
private String prefix;
private Map properties;
+ private ClassLoader classLoader;
+ public Manager(ClassLoader classLoader) {
+ this.classLoader = classLoader;
+ }
public String getPrefix() {
return prefix;
}
@@ -93,16 +99,16 @@
public void setQName(QName pName) { name = pName; }
public QName getQName() { return name; }
public void setElementClass(String pElementClass) throws
ClassNotFoundException {
- elementClass = context.getClassLoader().loadClass(pElementClass);
+ elementClass = classLoader.loadClass(pElementClass);
}
public Class getElementClass() { return elementClass; }
public void setElementInterface(String pElementInterface) throws
ClassNotFoundException {
- elementInterface =
context.getClassLoader().loadClass(pElementInterface);
+ elementInterface = classLoader.loadClass(pElementInterface);
}
public Class getElementInterface() { return elementInterface; }
public Class getHandlerClass() { return handlerClass; }
public void setHandlerClass(String pHandlerClass) throws
ClassNotFoundException {
- handlerClass = context.getClassLoader().loadClass(pHandlerClass);
+ handlerClass = classLoader.loadClass(pHandlerClass);
if (!JMSAXElementParser.class.isAssignableFrom(handlerClass)) {
throw new IllegalStateException("The class " +
handlerClass.getName()
+ " is not implementing "
@@ -110,7 +116,7 @@
}
}
public void setDriverClass(String pMarshallerClass) throws
ClassNotFoundException {
- driverClass = context.getClassLoader().loadClass(pMarshallerClass);
+ driverClass = classLoader.loadClass(pMarshallerClass);
if (!JMSAXDriver.class.isAssignableFrom(driverClass)) {
throw new IllegalStateException("The class " +
driverClass.getName()
+ " is not implementing "
@@ -130,7 +136,7 @@
/** Sets the persistence manager class.
*/
public void setPmClass(String pPersistencyClass) throws
ClassNotFoundException {
- pmClass = context.getClassLoader().loadClass(pPersistencyClass);
+ pmClass = classLoader.loadClass(pPersistencyClass);
}
public Class getPmClass() { return pmClass; }
public JAXBContextImpl getFactory() { return context; }
@@ -204,7 +210,7 @@
if (currentManager != null) {
throw new IllegalStateException("currentManager != null");
}
- currentManager = new Manager();
+ currentManager = new Manager(classLoader);
return currentManager;
}
Index: ws-jaxme3/src/jaxme/org/apache/ws/jaxme/impl/JAXBContextImpl.java
===================================================================
RCS file:
/home/cvspublic/ws-jaxme/src/jaxme/org/apache/ws/jaxme/impl/JAXBContextImpl.java,v
retrieving revision 1.9
diff -u -b -r1.9 JAXBContextImpl.java
--- ws-jaxme3/src/jaxme/org/apache/ws/jaxme/impl/JAXBContextImpl.java 10 Mar
2005 10:14:03 -0000 1.9
+++ ws-jaxme3/src/jaxme/org/apache/ws/jaxme/impl/JAXBContextImpl.java 16 Sep
2005 03:13:05 -0000
@@ -16,6 +16,7 @@
*/
package org.apache.ws.jaxme.impl;
+
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
@@ -323,26 +324,20 @@
}
}
- /** <p>Initializes the context by loading the configuration
- * or the configurations from the given classpath.</p>
- */
- protected void init() throws JAXBException {
- if (packageNames == null || packageNames.length() == 0) {
- packageNames = JAXBContextImpl.class.getName();
- packageNames = packageNames.substring(0, packageNames.lastIndexOf('.'));
- }
- boolean first = true;
- for (StringTokenizer st = new StringTokenizer(packageNames, ":");
- st.hasMoreTokens(); ) {
+ private boolean first = true;
+ public void registerPackages(String packageNames, ClassLoader cl)
+ throws JAXBException {
+ for (StringTokenizer st = new StringTokenizer(packageNames, ":"); st
+ .hasMoreTokens();) {
String packageName = st.nextToken();
- String configFileName =
- ((packageName.length() > 0) ?
- (packageName.replace('.', '/') + '/') : "") + "Configuration.xml";
- URL url = getClassLoader().getResource(configFileName);
+ String configFileName = ((packageName.length() > 0) ?
(packageName
+ .replace('.', '/') + '/') : "")
+ + "Configuration.xml";
+ URL url = cl.getResource(configFileName);
if (url != null) {
InputStream istream = null;
try {
- Configuration c = new Configuration(this);
+ Configuration c = new
Configuration(this, cl);
Configurator configurator = new Configurator();
configurator.setNamespace(CONFIGURATION_URI);
configurator.setRootObject(c);
@@ -363,21 +358,33 @@
setJMValidatorClass(c.getJMValidatorClass());
}
} catch (IOException e) {
- throw new JAXBException("Failed to load config file " + url, e);
+ throw new JAXBException(
+ "Failed to load config
file " + url, e);
} catch (SAXParseException e) {
- Exception f = e.getException() == null ? e : e.getException();
- throw new JAXBException("Failed to parse config file " + url +
- " at line " + e.getLineNumber() +
- ", column " + e.getColumnNumber() +
- ": " + f.getMessage(), f);
+ Exception f = e.getException() == null
? e : e
+ .getException();
+ JAXBException jaxbExc = new
JAXBException("Failed to parse config file "
+ + url + " at line " +
e.getLineNumber()
+ + ", column " +
e.getColumnNumber() + ": "
+ + f.getMessage(), f);
+ jaxbExc.initCause(e);
+ throw jaxbExc;
} catch (SAXException e) {
- Exception f = e.getException() == null ? e : e.getException();
- String msg = "Failed to parse config file " + url +": " +
f.getMessage();
+ Exception f = e.getException() == null
? e : e
+ .getException();
+ String msg = "Failed to parse config
file " + url + ": "
+ + f.getMessage();
throw new JAXBException(msg, f);
} catch (ParserConfigurationException e) {
- throw new JAXBException("Failed to create a SAX Parser: " +
e.getMessage(), e);
+ throw new JAXBException("Failed to
create a SAX Parser: "
+ + e.getMessage(), e);
} finally {
- if (istream != null) { try { istream.close(); } catch (Throwable
ignore) {} }
+ if (istream != null) {
+ try {
+ istream.close();
+ } catch (Throwable ignore) {
+ }
+ }
}
}
}
@@ -386,6 +393,24 @@
}
}
+ public void unregisterPackages(String packageNames) {
+
+ }
+
+ /**
+ * <p>
+ * Initializes the context by loading the configuration or the
+ * configurations from the given classpath.
+ * </p>
+ */
+ protected void init() throws JAXBException {
+ if (packageNames == null || packageNames.length() == 0) {
+ packageNames = JAXBContextImpl.class.getName();
+ packageNames = packageNames.substring(0, packageNames.lastIndexOf('.'));
+ }
+ registerPackages(packageNames, getClassLoader());
+ }
+
/** Creates a new instance of [EMAIL PROTECTED] javax.xml.bind.JAXBContext}.
* Invoked implicitly by
* [EMAIL PROTECTED]
javax.xml.bind.JAXBContext#newInstance(java.lang.String)}.
@@ -399,7 +424,7 @@
public Configuration createConfiguration(Attributes pAttributes) throws
JAXBException {
String className = pAttributes.getValue("", "className");
if (className == null || className.length() == 0) {
- return new Configuration(this);
+ return new Configuration(this, cl);
} else {
try {
return (Configuration) cl.loadClass(className).newInstance();
Index: ws-jaxme3/src/jaxme/org/apache/ws/jaxme/util/Configurator.java
===================================================================
RCS file:
/home/cvspublic/ws-jaxme/src/jaxme/org/apache/ws/jaxme/util/Configurator.java,v
retrieving revision 1.4
diff -u -b -r1.4 Configurator.java
--- ws-jaxme3/src/jaxme/org/apache/ws/jaxme/util/Configurator.java 10 Mar
2005 10:14:03 -0000 1.4
+++ ws-jaxme3/src/jaxme/org/apache/ws/jaxme/util/Configurator.java 16 Sep
2005 03:13:06 -0000
@@ -422,10 +422,12 @@
getDocumentLocator(), e);
} catch (InvocationTargetException e) {
Throwable t = e.getTargetException();
- throw new SAXParseException("Failed to invoke method " +
setMethodName +
+ SAXParseException saxExc = new SAXParseException("Failed to
invoke method " + setMethodName +
" of class " +
currentBean.getClass().getName(),
getDocumentLocator(),
(t instanceof Exception) ?
((Exception) t) : e);
+ saxExc.initCause(e);
+ throw saxExc;
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]