You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlbeans.apache.org by pc...@apache.org on 2003/12/19 02:34:46 UTC
cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar DefaultTylarLoader.java
pcal 2003/12/18 17:34:46
Modified: v2/src/binding/org/apache/xmlbeans/impl/binding/compile
BindingCompiler.java
v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
DefaultTylarLoader.java
Log:
fix tylarloader url bug, add baseJCLassLoader to BindingCompiler
Revision Changes Path
1.5 +33 -0 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompiler.java
Index: BindingCompiler.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/BindingCompiler.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- BindingCompiler.java 18 Dec 2003 01:58:58 -0000 1.4
+++ BindingCompiler.java 19 Dec 2003 01:34:45 -0000 1.5
@@ -61,6 +61,8 @@
import org.apache.xmlbeans.impl.binding.bts.PathBindingLoader;
import org.apache.xmlbeans.impl.binding.bts.BuiltinBindingLoader;
import org.apache.xmlbeans.impl.jam.JElement;
+import org.apache.xmlbeans.impl.jam.JClassLoader;
+import org.apache.xmlbeans.impl.jam.JFactory;
import org.apache.xmlbeans.XmlObject;
import org.apache.xmlbeans.XmlBeans;
import org.apache.xmlbeans.SchemaTypeLoader;
@@ -109,6 +111,7 @@
private Tylar[] mBaseLibraries = null;
private BindingLoader mBaseBindingLoader = null;
private SchemaTypeLoader mBaseSchemaTypeLoader = null;
+ private JClassLoader mBaseJClassLoader = null;
private boolean mIsCompilationStarted = false;
// this is the joust we use to build up the tylar that is passed to
@@ -349,6 +352,36 @@
}
return mBaseSchemaTypeLoader;
+ }
+
+ /**
+ * Returns a JClassLoader to be used as a basis for the binding process.
+ * Normally, this will simply be the loader backed by the system
+ * classloader. However, if the user has setBaseLibraries, the returned
+ * loader will also load java classes that may be stored those libraries.
+ * Note that this method must not be called until binding has actually
+ * begun.
+ *
+ * @throws IllegalStateException if this method is called before
+ * the abstract bind() method is called.
+ */
+ protected JClassLoader getBaseJavaTypeLoader() throws XmlException
+ {
+ assertCompilationStarted(true);
+ if (mBaseJClassLoader == null) {
+ if (mBaseLibraries == null) {
+ mBaseJClassLoader = JFactory.getInstance().getSystemClassLoader();
+ } else {
+ //create a classloader chain that runs throw all of the base tylars
+ ClassLoader cl = ClassLoader.getSystemClassLoader();//FIXME this needs a knob
+ for(int i = mBaseLibraries.length; i >= 0; i--) {
+ cl = mBaseLibraries[i].createClassLoader(cl);
+ }
+ mBaseJClassLoader = JFactory.getInstance().
+ createClassLoader(cl,null,null);
+ }
+ }
+ return mBaseJClassLoader;
}
/**
1.3 +12 -4 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/DefaultTylarLoader.java
Index: DefaultTylarLoader.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/DefaultTylarLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DefaultTylarLoader.java 18 Dec 2003 01:58:58 -0000 1.2
+++ DefaultTylarLoader.java 19 Dec 2003 01:34:46 -0000 1.3
@@ -61,6 +61,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
+import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Collection;
import java.util.jar.JarEntry;
@@ -86,7 +87,7 @@
private static final char[] OTHER_SEPCHARS = {'\\'};
private static final char SEPCHAR = '/';
- private static final boolean VERBOSE = false;
+ private static final boolean VERBOSE = true;
private static final String BINDING_FILE_JARENTRY =
normalizeEntryName(TylarConstants.BINDING_FILE);
@@ -105,7 +106,8 @@
return DEFAULT_INSTANCE;
}
- private static /*final*/ TylarLoader DEFAULT_INSTANCE = new DefaultTylarLoader();
+ private static /*final*/ TylarLoader
+ DEFAULT_INSTANCE = new DefaultTylarLoader();
/**
* This is a gross quick hack to support pluggability for tylar loader.
@@ -146,7 +148,7 @@
} catch(Exception e) {
//sometimes File can't deal for some reason, so as a last ditch
//we assume it's a jar and read the stream directly
- return loadFromJar(new JarInputStream(uri.toURL().openStream()),uri);
+ return loadFromJar(uri.toURL().openStream(),uri);
}
if (!file.exists()) throw new FileNotFoundException(uri.toString());
if (file.isDirectory()) {
@@ -186,7 +188,8 @@
* exception, you can be sure that the tylars binding files and schemas are
* valid.
*
- * @param in input stream on the jar file
+ * @param in input stream on the jar file. This should NOT be a
+ * JarInputStream
* @param source uri from which the tylar was retrieved. This is used
* for informational purposes only, but it is required.
* @return Handle to the tylar
@@ -195,12 +198,16 @@
public static Tylar loadFromJar(InputStream in, URI source)
throws IOException, XmlException
{
+ // FIXME this will be broken if the InputStream is already a
+ // JarInputStream (or some InputStream in front of a JIS).
+ // Gotta sort this out. pcal 12/18/03
if (in == null) throw new IllegalArgumentException("null in");
if (source == null) throw new IllegalArgumentException("null uri");
HackJarInputStream hin = new HackJarInputStream(in);
JarEntry entry;
BindingFile bf = null;
Collection schemas = null;
+ if (VERBOSE) System.out.println("Reading jar entries");
while ((entry = hin.getNextJarEntry()) != null) {
if (entry.isDirectory()) continue;
String name = normalizeEntryName(entry.getName());
@@ -221,6 +228,7 @@
}
hin.closeEntry();
}
+ if (VERBOSE) System.out.println("Done reading jar entries");
if (bf == null) {
throw new IOException
("resource at '"+source+
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org