You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xmlbeans-cvs@xml.apache.org by pc...@apache.org on 2004/06/17 00:33:39 UTC
cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar RuntimeTylar.java
pcal 2004/06/16 15:33:39
Modified: v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
RuntimeTylar.java
Log:
add sanity check to tylar loading
Revision Changes Path
1.4 +30 -1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/RuntimeTylar.java
Index: RuntimeTylar.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/RuntimeTylar.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- RuntimeTylar.java 28 May 2004 21:25:23 -0000 1.3
+++ RuntimeTylar.java 16 Jun 2004 22:33:39 -0000 1.4
@@ -29,8 +29,10 @@
import java.net.URI;
import java.net.URL;
+import java.net.URLClassLoader;
import java.io.IOException;
import java.io.InputStream;
+import java.io.StringWriter;
import java.util.Enumeration;
import java.util.List;
import java.util.ArrayList;
@@ -67,17 +69,21 @@
// ========================================================================
// Constructors
- /*package*/ RuntimeTylar(ClassLoader loader) {
+ /*package*/ RuntimeTylar(ClassLoader loader) throws IOException {
if (loader == null) throw new IllegalArgumentException("null loader");
+ sanityCheck(loader);
mClassLoader = loader;
mLocations = new URL[0];
mDescription = "loaded from "+loader.toString();
+
}
/*package*/ RuntimeTylar(ClassLoader loader, URL[] locs)
+ throws IOException
{
if (loader == null) throw new IllegalArgumentException("null loader");
+ sanityCheck(loader);
if (locs == null) throw new IllegalArgumentException("null locs");
mClassLoader = loader;
mLocations = locs;
@@ -155,5 +161,28 @@
JamServiceFactory.getInstance().createJamClassLoader(mClassLoader);
}
return mJamClassLoader;
+ }
+
+ // ========================================================================
+ // Private
+
+ private static void sanityCheck(ClassLoader cl) throws IOException {
+ Enumeration urls = cl.getResources(BINDING_FILE);
+ if (urls == null || !urls.hasMoreElements()) {
+ StringWriter msg = new StringWriter();
+ msg.write("The given classloader does not contain any xbean binding\n" +
+ "files ("+BINDING_FILE+"\n");
+ if (cl instanceof URLClassLoader) {
+ msg.write("URLClassLoader path:");
+ URL[] cl_urls = ((URLClassLoader)cl).getURLs();
+ for(int i=0; i<cl_urls.length; i++) {
+ msg.write(cl_urls[i].toString());
+ msg.write("\n");
+ }
+ } else {
+ msg.write(cl.getClass().toString());
+ }
+ throw new IOException(msg.toString());
+ }
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org