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/11 02:49:04 UTC
cvs commit: xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar JarredTylar.java TylarFactory.java ExplodedTylar.java ExplodedTylarImpl.java Tylar.java TylarConstants.java TylarWriter.java
pcal 2003/12/10 17:49:04
Modified: v2/src/binding/org/apache/xmlbeans/impl/binding/compile
Java2Schema.java Java2SchemaTask.java
SimpleBindingLogger.java
v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
ExplodedTylar.java ExplodedTylarImpl.java
Tylar.java TylarConstants.java TylarWriter.java
Added: v2/src/binding/org/apache/xmlbeans/impl/binding/tylar
JarredTylar.java TylarFactory.java
Log:
more tylar infrastructure
Revision Changes Path
1.18 +48 -15 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema.java
Index: Java2Schema.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2Schema.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- Java2Schema.java 10 Dec 2003 03:24:03 -0000 1.17
+++ Java2Schema.java 11 Dec 2003 01:49:03 -0000 1.18
@@ -61,7 +61,6 @@
import org.apache.xmlbeans.impl.binding.tylar.ExplodedTylarImpl;
import org.apache.xmlbeans.impl.binding.tylar.Tylar;
import org.apache.xmlbeans.impl.jam.*;
-import org.apache.tools.ant.BuildException;
import org.w3.x2001.xmlSchema.*;
import javax.xml.namespace.QName;
import java.util.ArrayList;
@@ -102,8 +101,10 @@
private static final String TAG_AT = "xsdgen:attribute";
private static final String TAG_AT_NAME = TAG_AT+".name";
- //for debugging only
- private static final boolean IGNORE_SEVERE_ERRORS = true;
+ // If true, the 'bind' methods will always try to return something,
+ // even if severe errors were encountered. Turn this on only for
+ // debugging.
+ private static final boolean IGNORE_SEVERE_ERRORS = false;
// =========================================================================
// Variables
@@ -137,10 +138,17 @@
* Performs the binding and returns an exploded tylar in the specified
* directory. Returns null if any severe errors were encountered.
*/
- public ExplodedTylar bindAsExplodedTylar(File tylarDestDir) {
+ public ExplodedTylar bindAsExplodedTylar(File tylarDestDir)
+ {
Java2SchemaResult result = bind();
if (result == null) return null;
- ExplodedTylarImpl tylar = new ExplodedTylarImpl(tylarDestDir);
+ ExplodedTylarImpl tylar = null;
+ try {
+ tylar = ExplodedTylarImpl.create(tylarDestDir);
+ } catch(IOException ioe) {
+ logError(ioe);
+ return null;
+ }
if (!tylarDestDir.exists()) {
if (!tylarDestDir.mkdirs()) {
logError("failed to create "+tylarDestDir);
@@ -156,7 +164,16 @@
* Returns null if any severe errors were encountered.
*/
public Tylar bindAsJarredTylar(File tylarJar) {
- throw new RuntimeException("NYI");
+ File tempDir = null;
+ try {
+ tempDir = createTempDir();
+ tempDir.deleteOnExit();//REVIEW maybe we should delete it ourselves?
+ ExplodedTylar et = bindAsExplodedTylar(tempDir);
+ return et.toJar(tylarJar);
+ } catch(IOException ioe) {
+ logError(ioe);
+ return null;
+ }
}
/**
@@ -196,6 +213,19 @@
// ========================================================================
// Private methods
+ private static File createTempDir() throws IOException
+ {
+ //FIXME this is not great
+ String prefix = "java2schema-"+System.currentTimeMillis();
+ File directory = null;
+ File f = File.createTempFile(prefix, null);
+ directory = f.getParentFile();
+ f.delete();
+ File out = new File(directory, prefix);
+ if (!out.mkdirs()) throw new IOException("Uknown problem creating temp file");
+ return out;
+ }
+
/**
* Feeds a tylar builder with the given compilation results.
*/
@@ -378,13 +408,16 @@
}
/**
- * Returns a QName for the builtin type bound to the given JClass.
+ * Returns a QName for the type bound to the given JClass.
*/
- private QName getBuiltinTypeNameFor(JClass clazz) {
- BindingType bt = mLoader.getBindingType
- (mLoader.lookupTypeFor(JavaTypeName.forString(clazz.getQualifiedName())));
+ private QName getQnameFor(JClass clazz) {
+ getBindingTypeFor(clazz); //ensure that we've bound it
+ JavaTypeName jtn = JavaTypeName.forString(clazz.getQualifiedName());
+ BindingTypeName btn = mLoader.lookupTypeFor(jtn);
+ logVerbose(clazz,"BindingTypeName is "+btn);
+ BindingType bt = mLoader.getBindingType(btn);
if (bt != null) return bt.getName().getXmlName().getQName();
- logError(clazz,"no builtin type found");
+ logError(clazz,"could not get qname");
return new QName("ERROR",clazz.getQualifiedName());
}
@@ -587,7 +620,7 @@
public void setSetter(String s) { mBtsProp.setSetterName(s); }
/**
- * Sets whether the type of the property. Currently handles arrays
+ * Sets the type of the property. Currently handles arrays
* correctly but not collections.
*/
public void setType(JClass propType) {
@@ -598,13 +631,13 @@
}
JClass componentType = propType.getArrayComponentType();
mXsElement.setMaxOccurs("unbounded");
- mXsElement.setType(getBuiltinTypeNameFor(componentType));
+ mXsElement.setType(getQnameFor(componentType));
mBtsProp.setMultiple(true);
mBtsProp.setCollectionClass //FIXME
(JavaTypeName.forString(componentType.getQualifiedName()+"[]"));
mBtsProp.setBindingType(getBindingTypeFor(componentType));
} else {
- mXsElement.setType(getBuiltinTypeNameFor(propType));
+ mXsElement.setType(getQnameFor(propType));
mBtsProp.setBindingType(getBindingTypeFor(propType));
}
} else if (mXsAttribute != null) {
@@ -612,7 +645,7 @@
logError(mSrcContext,
"Array properties cannot be mapped to xml attributes");
} else {
- mXsAttribute.setType(getBuiltinTypeNameFor(propType));
+ mXsAttribute.setType(getQnameFor(propType));
mBtsProp.setBindingType(getBindingTypeFor(propType));
}
} else {
1.11 +11 -2 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2SchemaTask.java
Index: Java2SchemaTask.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/Java2SchemaTask.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- Java2SchemaTask.java 10 Dec 2003 03:24:03 -0000 1.10
+++ Java2SchemaTask.java 11 Dec 2003 01:49:03 -0000 1.11
@@ -70,6 +70,7 @@
import java.io.File;
import java.io.IOException;
+import java.util.logging.Level;
/**
* Ant task definition for binding in the start-with-java case.
@@ -88,6 +89,7 @@
private Path mClasspath = null;
private String mIncludes = null;
private Path mSrcDir = null;
+ private boolean mVerbose = false;
// =========================================================================
// Task attributes
@@ -159,6 +161,8 @@
mIncludes = includes;
}
+ public void setVerbose(boolean v) { mVerbose = v; }
+
public void setCompileSources(boolean ignoredRightNow) {}
public void setCopySources(boolean ignoredRightNow) {}
@@ -193,8 +197,7 @@
public TylarLoader getTylarLoader() { return null; }
public void compileJavaToBinaries(File classesDir) {}
};
- BindingLogger logger = new SimpleBindingLogger();
- Java2Schema j2b = new Java2Schema(input,logger);
+ Java2Schema j2b = new Java2Schema(input,createLogger());
Tylar tylar = null;
if (mDestDir != null) {
tylar = j2b.bindAsExplodedTylar(mDestDir);
@@ -206,6 +209,12 @@
"see log for details.");
}
log("Java2SchemaTask complete, output at "+tylar.getLocation());
+ }
+
+ private BindingLogger createLogger() {
+ SimpleBindingLogger logger = new SimpleBindingLogger();
+ if (mVerbose) logger.setThresholdLevel(Level.FINEST);
+ return logger;
}
// =========================================================================
1.2 +12 -0 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/SimpleBindingLogger.java
Index: SimpleBindingLogger.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/compile/SimpleBindingLogger.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- SimpleBindingLogger.java 10 Dec 2003 03:24:03 -0000 1.1
+++ SimpleBindingLogger.java 11 Dec 2003 01:49:03 -0000 1.2
@@ -14,6 +14,7 @@
// Variables
private PrintWriter mOut;
+ private Level mThreshold = Level.SEVERE;
// ========================================================================
// Constructors
@@ -30,7 +31,18 @@
// ========================================================================
// BindingLogger implementation
+ /**
+ * Sets the minimum level at which messages will actually be printed out.
+ * Anything of a lower level is discarded. The default is Level.SEVERE.
+ *
+ * @param thresh the new threshold value.
+ */
+ public void setThresholdLevel(Level thresh) {
+ mThreshold = thresh;
+ }
+
public void log(Level level, String message, Throwable error) {
+ if (level.intValue() < mThreshold.intValue()) return;
mOut.print(level.toString());
if (message != null) {
mOut.print(' ');
1.2 +62 -5 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/ExplodedTylar.java
Index: ExplodedTylar.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/ExplodedTylar.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExplodedTylar.java 10 Dec 2003 03:24:03 -0000 1.1
+++ ExplodedTylar.java 11 Dec 2003 01:49:03 -0000 1.2
@@ -1,3 +1,58 @@
+/*
+* The Apache Software License, Version 1.1
+*
+*
+* Copyright (c) 2003 The Apache Software Foundation. All rights
+* reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in
+* the documentation and/or other materials provided with the
+* distribution.
+*
+* 3. The end-user documentation included with the redistribution,
+* if any, must include the following acknowledgment:
+* "This product includes software developed by the
+* Apache Software Foundation (http://www.apache.org/)."
+* Alternately, this acknowledgment may appear in the software itself,
+* if and wherever such third-party acknowledgments normally appear.
+*
+* 4. The names "Apache" and "Apache Software Foundation" must
+* not be used to endorse or promote products derived from this
+* software without prior written permission. For written
+* permission, please contact apache@apache.org.
+*
+* 5. Products derived from this software may not be called "Apache
+* XMLBeans", nor may "Apache" appear in their name, without prior
+* written permission of the Apache Software Foundation.
+*
+* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+* SUCH DAMAGE.
+* ====================================================================
+*
+* This software consists of voluntary contributions made by many
+* individuals on behalf of the Apache Software Foundation and was
+* originally based on software copyright (c) 2000-2003 BEA Systems
+* Inc., <http://www.bea.com/>. For more information on the Apache Software
+* Foundation, please see <http://www.apache.org/>.
+*/
package org.apache.xmlbeans.impl.binding.tylar;
import java.io.File;
@@ -8,6 +63,8 @@
* structure. This is useful for consumers who may need additional control
* over the generated artifacts, e.g. to manually perform compilation of
* generated java source files.
+ *
+ * @author Patrick Calahan <pc...@bea.com>
*/
public interface ExplodedTylar extends Tylar {
@@ -43,14 +100,14 @@
/**
* Jars up the exploded tylar directory into the given file and returns
* a handle to the JarredTylar. The main advantage of using this method
- * over jarring it yourself is that this may save you the cost or reparsing
- * the binding file and the schemas, in the event that you want to
+ * as opposed to jarring it yourself is that you will save you the cost of
+ * reparsing the binding file and the schemas in the event that you want to
* immediately hand the tylar to the runtime.
*
* @param jarfile Destination file for the new jar
* @return A handle to the newly-created tylar
- * @throws java.io.IOException if the specified jarfile already exists or if an
- * error occurs while writing the file.
+ * @throws java.io.IOException if the specified jarfile already exists or if
+ * an error occurs while writing the file.
*/
- public TylarConstants toJar(File jarfile) throws IOException;
+ public Tylar toJar(File jarfile) throws IOException;
}
1.2 +178 -62 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/ExplodedTylarImpl.java
Index: ExplodedTylarImpl.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/ExplodedTylarImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ExplodedTylarImpl.java 10 Dec 2003 03:24:03 -0000 1.1
+++ ExplodedTylarImpl.java 11 Dec 2003 01:49:03 -0000 1.2
@@ -1,30 +1,94 @@
+/*
+* The Apache Software License, Version 1.1
+*
+*
+* Copyright (c) 2003 The Apache Software Foundation. All rights
+* reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in
+* the documentation and/or other materials provided with the
+* distribution.
+*
+* 3. The end-user documentation included with the redistribution,
+* if any, must include the following acknowledgment:
+* "This product includes software developed by the
+* Apache Software Foundation (http://www.apache.org/)."
+* Alternately, this acknowledgment may appear in the software itself,
+* if and wherever such third-party acknowledgments normally appear.
+*
+* 4. The names "Apache" and "Apache Software Foundation" must
+* not be used to endorse or promote products derived from this
+* software without prior written permission. For written
+* permission, please contact apache@apache.org.
+*
+* 5. Products derived from this software may not be called "Apache
+* XMLBeans", nor may "Apache" appear in their name, without prior
+* written permission of the Apache Software Foundation.
+*
+* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+* SUCH DAMAGE.
+* ====================================================================
+*
+* This software consists of voluntary contributions made by many
+* individuals on behalf of the Apache Software Foundation and was
+* originally based on software copyright (c) 2000-2003 BEA Systems
+* Inc., <http://www.bea.com/>. For more information on the Apache Software
+* Foundation, please see <http://www.apache.org/>.
+*/
package org.apache.xmlbeans.impl.binding.tylar;
-import org.apache.xmlbeans.impl.binding.bts.BindingFile;
-import org.apache.xmlbeans.impl.binding.joust.*;
+import java.io.*;
+import java.net.URI;
+import java.net.URLClassLoader;
+import java.net.URL;
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.Collection;
+import org.apache.xml.xmlbeans.bindingConfig.BindingConfigDocument;
import org.apache.xmlbeans.XmlException;
import org.apache.xmlbeans.XmlOptions;
-import org.apache.xml.xmlbeans.bindingConfig.BindingConfigDocument;
+import org.apache.xmlbeans.impl.binding.bts.BindingFile;
+import org.apache.xmlbeans.impl.binding.joust.FileWriterFactory;
+import org.apache.xmlbeans.impl.binding.joust.JavaOutputStream;
+import org.apache.xmlbeans.impl.binding.joust.SourceJavaOutputStream;
+import org.apache.xmlbeans.impl.binding.joust.ValidatingJavaOutputStream;
+import org.apache.xmlbeans.impl.common.JarHelper;
import org.w3.x2001.xmlSchema.SchemaDocument;
-import java.io.*;
-import java.util.Collection;
-import java.util.ArrayList;
-import java.net.URI;
/**
* Concrete implementation of ExplodedTylar - a tylar which exists in an open
* directory structure on disk. Note that this class also implements
* TylarWriter, which allows the compile time to build up the tylar files
* and then hand them directly to the runtime if desired.
+ *
+ * @author Patrick Calahan <pc...@bea.com>
*/
public class ExplodedTylarImpl
- implements TylarConstants, ExplodedTylar, TylarWriter
- {
+ implements TylarConstants, ExplodedTylar, TylarWriter {
// ========================================================================
// Constants
private static final int XML_INDENT = 2;
+ private static final boolean VERBOSE = false;
// ========================================================================
// Variables
@@ -37,32 +101,76 @@
private Collection mSchemaDocuments = null;
// ========================================================================
- // Constructors
+ // Factory methods
+
+ /**
+ * Creates a new tylar from the given directory. The directory must exist
+ * or be creatable. The default JavaOutputStream will be used for codegen.
+ */
+ public static ExplodedTylarImpl create(File dir) throws IOException {
+ return create(dir, createDefaultJoust(dir));
+ }
+
+ /**
+ * Loads a tylar from the given directory. The directory must exist
+ * and contain at least a binding file. The default JavaOutputStream
+ * will be used for codegen.
+ */
+ public static ExplodedTylarImpl load(File dir)
+ throws IOException, XmlException {
+ return load(dir, createDefaultJoust(dir));
+ }
+
+
+ /**
+ * Creates a new tylar from the given directory. The directory must exist
+ * or be creatable.
+ */
+ public static ExplodedTylarImpl create(File dir, JavaOutputStream joust)
+ throws IOException {
+ if (dir.exists()) {
+ if (dir.isFile()) throw new IOException("already a file at '" + dir + "'");
+ } else {
+ if (!dir.mkdirs()) throw new IOException("Failed to create " + dir);
+ }
+ return new ExplodedTylarImpl(dir, null, null, joust);
+ }
/**
- * Constructs a new ExplodedTylarImpl in the given directory. The
- * default JavaOutputStream is used, which simply writes java sources
- * into the 'src' directory of the tylar.
- */
- public ExplodedTylarImpl(File dir) {
- this(dir,null);
- mJoust = new ValidatingJavaOutputStream
- (new SourceJavaOutputStream(new FileWriterFactory(mSourceRoot)));
+ * Loads a tylar from the given directory. The directory must exist
+ * and contain at least a binding file.
+ */
+ public static ExplodedTylarImpl load(File dir, JavaOutputStream joust)
+ throws IOException, XmlException {
+ if (dir.exists()) {
+ if (dir.isFile()) throw new IOException(dir + " is a file");
+ } else {
+ throw new IOException("No such directory " + dir);
+ }
+ BindingFile bf = parseBindingFile(new File(dir, BINDING_FILE));
+ Collection schemas = new ArrayList();
+ parseSchemas(new File(dir, SCHEMA_DIR), schemas);
+ return new ExplodedTylarImpl(dir, bf, schemas, joust);
}
+ // ========================================================================
+ // Constructors
+
/**
* Constructs a new ExplodedTylarImpl in the given directory and using
* the given JavaOutputStream.
*/
- public ExplodedTylarImpl(File dir, JavaOutputStream joust) {
- if (dir.exists() && dir.isFile()) {
- throw new IllegalArgumentException("already a file at '"+dir+"'");
- }
- dir.mkdirs();
+ private ExplodedTylarImpl(File dir, // must exist
+ BindingFile bindingFile, // null ok
+ Collection schemas, // null ok
+ JavaOutputStream joust) // null ok
+ {
mRootDir = dir;
- mSourceRoot = new File(mRootDir,SRC_ROOT);
- mSchemaDir = new File(mRootDir,SCHEMA_DIR);
+ mSourceRoot = new File(mRootDir, SRC_ROOT);
+ mSchemaDir = new File(mRootDir, SCHEMA_DIR);
mJoust = joust;
+ mBindingFile = bindingFile;
+ mSchemaDocuments = schemas;
}
@@ -71,15 +179,14 @@
public void writeBindingFile(BindingFile bf) throws IOException {
mBindingFile = bf;
- writeBindingFile(bf,new File(mRootDir,BINDING_FILE));
+ writeBindingFile(bf, new File(mRootDir, BINDING_FILE));
}
public void writeSchema(SchemaDocument xsd, String schemaFileName)
- throws IOException
- {
+ throws IOException {
if (mSchemaDocuments == null) mSchemaDocuments = new ArrayList();
mSchemaDocuments.add(xsd);
- writeXsd(xsd,new File(mSchemaDir,schemaFileName));
+ writeXsd(xsd, new File(mSchemaDir, schemaFileName));
}
public JavaOutputStream getJavaOutputStream() {
@@ -89,24 +196,20 @@
// ========================================================================
// Tylar implementation
- public BindingFile getBindingFile() throws IOException, XmlException {
- if (mBindingFile == null) {
- mBindingFile = parseBindingFile(new File(mRootDir, BINDING_FILE));
- }
+ public BindingFile getBindingFile() {
return mBindingFile;
}
- public SchemaDocument[] getSchemas() throws IOException, XmlException {
- if (mSchemaDocuments == null) {
- mSchemaDocuments = new ArrayList();
- parseSchemas(mSchemaDir,mSchemaDocuments);
- }
+ public SchemaDocument[] getSchemas() {
+ if (mSchemaDocuments == null) return new SchemaDocument[0];
SchemaDocument[] out = new SchemaDocument[mSchemaDocuments.size()];
mSchemaDocuments.toArray(out);
return out;
}
- public URI getLocation() { return mRootDir.toURI(); }
+ public URI getLocation() {
+ return mRootDir.toURI();
+ }
//not sure we ever need this
public void resetCaches() {
@@ -121,10 +224,14 @@
* Returns the directory on disk in which the tylar is stored. Never
* returns null.
*/
- public File getRootDir() { return mRootDir; }
+ public File getRootDir() {
+ return mRootDir;
+ }
- public TylarConstants toJar(File jarfile) throws IOException {
- throw new RuntimeException("NYI");
+ public Tylar toJar(File jarfile) throws IOException {
+ JarHelper j = new JarHelper();
+ j.jarDir(mRootDir,jarfile);
+ return new JarredTylar(jarfile,mBindingFile,mSchemaDocuments);
}
public File getSourceDir() {
@@ -139,34 +246,46 @@
return mSchemaDir;
}
+ public ClassLoader createClassLoader(ClassLoader parent) {
+ try {
+ return new URLClassLoader(new URL[] {mSourceRoot.toURL()},parent);
+ } catch(MalformedURLException mue){
+ throw new RuntimeException(mue); //FIXME this is bad
+ }
+ }
+
// ========================================================================
// Private methods
+ private static JavaOutputStream createDefaultJoust(File dir) {
+ return new ValidatingJavaOutputStream
+ (new SourceJavaOutputStream(new FileWriterFactory(dir)));
+ }
+
private static void parseSchemas(File schemaDir, Collection out)
- throws IOException, XmlException
- {
+ throws IOException, XmlException {
File[] xsds = schemaDir.listFiles();
- for(int i=0; i<xsds.length; i++) {
+ for (int i = 0; i < xsds.length; i++) {
+ if (VERBOSE) System.out.println("parsing "+xsds[i]);
out.add(parseXsd(xsds[i]));
}
}
private static SchemaDocument parseXsd(File file)
- throws IOException, XmlException
- {
+ throws IOException, XmlException {
FileReader in = null;
try {
in = new FileReader(file);
return SchemaDocument.Factory.parse(in);
- } catch(IOException ioe) {
+ } catch (IOException ioe) {
throw ioe;
- } catch(XmlException xe) {
+ } catch (XmlException xe) {
throw xe;
} finally {
if (in != null) {
try {
in.close();
- } catch(Exception ohwell) {
+ } catch (Exception ohwell) {
ohwell.printStackTrace();
}
}
@@ -174,8 +293,7 @@
}
private static void writeXsd(SchemaDocument xsd, File file)
- throws IOException
- {
+ throws IOException {
FileOutputStream out = null;
try {
file.getParentFile().mkdirs();
@@ -189,7 +307,7 @@
if (out != null) {
try {
out.close();
- } catch(Exception ohwell) {
+ } catch (Exception ohwell) {
ohwell.printStackTrace();
}
}
@@ -197,21 +315,20 @@
}
private static BindingFile parseBindingFile(File file)
- throws IOException, XmlException
- {
+ throws IOException, XmlException {
FileReader in = null;
try {
in = new FileReader(file);
return BindingFile.forDoc(BindingConfigDocument.Factory.parse(in));
- } catch(IOException ioe) {
+ } catch (IOException ioe) {
throw ioe;
- } catch(XmlException xe) {
+ } catch (XmlException xe) {
throw xe;
} finally {
if (in != null) {
try {
in.close();
- } catch(Exception ohwell) {
+ } catch (Exception ohwell) {
ohwell.printStackTrace();
}
}
@@ -219,8 +336,7 @@
}
private static void writeBindingFile(BindingFile bf, File file)
- throws IOException
- {
+ throws IOException {
FileWriter out = null;
try {
file.getParentFile().mkdirs();
@@ -230,13 +346,13 @@
new XmlOptions().setSavePrettyPrint().
setSavePrettyPrintIndent(XML_INDENT));
out.flush();
- } catch(IOException ioe) {
+ } catch (IOException ioe) {
throw ioe;
} finally {
if (out != null) {
try {
out.close();
- } catch(Exception ohwell) {
+ } catch (Exception ohwell) {
ohwell.printStackTrace();
}
}
1.2 +68 -6 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/Tylar.java
Index: Tylar.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/Tylar.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Tylar.java 10 Dec 2003 03:24:03 -0000 1.1
+++ Tylar.java 11 Dec 2003 01:49:03 -0000 1.2
@@ -1,16 +1,70 @@
+/*
+* The Apache Software License, Version 1.1
+*
+*
+* Copyright (c) 2003 The Apache Software Foundation. All rights
+* reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in
+* the documentation and/or other materials provided with the
+* distribution.
+*
+* 3. The end-user documentation included with the redistribution,
+* if any, must include the following acknowledgment:
+* "This product includes software developed by the
+* Apache Software Foundation (http://www.apache.org/)."
+* Alternately, this acknowledgment may appear in the software itself,
+* if and wherever such third-party acknowledgments normally appear.
+*
+* 4. The names "Apache" and "Apache Software Foundation" must
+* not be used to endorse or promote products derived from this
+* software without prior written permission. For written
+* permission, please contact apache@apache.org.
+*
+* 5. Products derived from this software may not be called "Apache
+* XMLBeans", nor may "Apache" appear in their name, without prior
+* written permission of the Apache Software Foundation.
+*
+* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+* SUCH DAMAGE.
+* ====================================================================
+*
+* This software consists of voluntary contributions made by many
+* individuals on behalf of the Apache Software Foundation and was
+* originally based on software copyright (c) 2000-2003 BEA Systems
+* Inc., <http://www.bea.com/>. For more information on the Apache Software
+* Foundation, please see <http://www.apache.org/>.
+*/
package org.apache.xmlbeans.impl.binding.tylar;
+import java.net.URI;
import org.apache.xmlbeans.impl.binding.bts.BindingFile;
-import org.apache.xmlbeans.XmlException;
import org.w3.x2001.xmlSchema.SchemaDocument;
-import java.net.URI;
-import java.io.File;
-import java.io.IOException;
/**
* Abstract representation of a type library archive. This is the interface
* which is used by the binding runtime for retrieving information about a
* tylar.
+ *
+ * @author Patrick Calahan <pc...@bea.com>
*/
public interface Tylar {
@@ -20,12 +74,20 @@
/**
* Returns the binding file for this Tylar.
*/
- public BindingFile getBindingFile() throws IOException, XmlException;
+ public BindingFile getBindingFile();
/**
* Returns the schemas contained in this Tylar.
*/
- public SchemaDocument[] getSchemas() throws IOException, XmlException;
+ public SchemaDocument[] getSchemas();
+
+ /**
+ * Returns a new ClassLoader that can load any class files contained in
+ * this tylar. Returns null if this tylar contains no class resources.
+ *
+ * @param parent The parent for new classloader.
+ */
+ public ClassLoader createClassLoader(ClassLoader parent);
/**
* Returns a URI describing the location of the physical store from
1.2 +59 -2 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarConstants.java
Index: TylarConstants.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarConstants.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TylarConstants.java 10 Dec 2003 03:24:03 -0000 1.1
+++ TylarConstants.java 11 Dec 2003 01:49:03 -0000 1.2
@@ -1,3 +1,58 @@
+/*
+* The Apache Software License, Version 1.1
+*
+*
+* Copyright (c) 2003 The Apache Software Foundation. All rights
+* reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in
+* the documentation and/or other materials provided with the
+* distribution.
+*
+* 3. The end-user documentation included with the redistribution,
+* if any, must include the following acknowledgment:
+* "This product includes software developed by the
+* Apache Software Foundation (http://www.apache.org/)."
+* Alternately, this acknowledgment may appear in the software itself,
+* if and wherever such third-party acknowledgments normally appear.
+*
+* 4. The names "Apache" and "Apache Software Foundation" must
+* not be used to endorse or promote products derived from this
+* software without prior written permission. For written
+* permission, please contact apache@apache.org.
+*
+* 5. Products derived from this software may not be called "Apache
+* XMLBeans", nor may "Apache" appear in their name, without prior
+* written permission of the Apache Software Foundation.
+*
+* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+* SUCH DAMAGE.
+* ====================================================================
+*
+* This software consists of voluntary contributions made by many
+* individuals on behalf of the Apache Software Foundation and was
+* originally based on software copyright (c) 2000-2003 BEA Systems
+* Inc., <http://www.bea.com/>. For more information on the Apache Software
+* Foundation, please see <http://www.apache.org/>.
+*/
package org.apache.xmlbeans.impl.binding.tylar;
import java.io.File;
@@ -6,6 +61,8 @@
* These constants describe the physical structure of the tylar archive.
* The values are subject to change at any time and should not be used
* outside of this package.
+ *
+ * @author Patrick Calahan <pc...@bea.com>
*/
public interface TylarConstants {
@@ -18,7 +75,7 @@
public static final String METAINF = "META-INF";
- public static final String BINDING_FILE = METAINF +SEP+ "binding-file.xml";
+ public static final String BINDING_FILE = METAINF + SEP + "binding-file.xml";
- public static final String SCHEMA_DIR = METAINF +SEP+ "schemas";
+ public static final String SCHEMA_DIR = METAINF + SEP + "schemas";
}
1.2 +59 -2 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarWriter.java
Index: TylarWriter.java
===================================================================
RCS file: /home/cvs/xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarWriter.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TylarWriter.java 10 Dec 2003 03:24:03 -0000 1.1
+++ TylarWriter.java 11 Dec 2003 01:49:03 -0000 1.2
@@ -1,12 +1,69 @@
+/*
+* The Apache Software License, Version 1.1
+*
+*
+* Copyright (c) 2003 The Apache Software Foundation. All rights
+* reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions
+* are met:
+*
+* 1. Redistributions of source code must retain the above copyright
+* notice, this list of conditions and the following disclaimer.
+*
+* 2. Redistributions in binary form must reproduce the above copyright
+* notice, this list of conditions and the following disclaimer in
+* the documentation and/or other materials provided with the
+* distribution.
+*
+* 3. The end-user documentation included with the redistribution,
+* if any, must include the following acknowledgment:
+* "This product includes software developed by the
+* Apache Software Foundation (http://www.apache.org/)."
+* Alternately, this acknowledgment may appear in the software itself,
+* if and wherever such third-party acknowledgments normally appear.
+*
+* 4. The names "Apache" and "Apache Software Foundation" must
+* not be used to endorse or promote products derived from this
+* software without prior written permission. For written
+* permission, please contact apache@apache.org.
+*
+* 5. Products derived from this software may not be called "Apache
+* XMLBeans", nor may "Apache" appear in their name, without prior
+* written permission of the Apache Software Foundation.
+*
+* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+* SUCH DAMAGE.
+* ====================================================================
+*
+* This software consists of voluntary contributions made by many
+* individuals on behalf of the Apache Software Foundation and was
+* originally based on software copyright (c) 2000-2003 BEA Systems
+* Inc., <http://www.bea.com/>. For more information on the Apache Software
+* Foundation, please see <http://www.apache.org/>.
+*/
package org.apache.xmlbeans.impl.binding.tylar;
+import java.io.IOException;
import org.apache.xmlbeans.impl.binding.bts.BindingFile;
import org.apache.xmlbeans.impl.binding.joust.JavaOutputStream;
import org.w3.x2001.xmlSchema.SchemaDocument;
-import java.io.IOException;
/**
- * Interface which is used at compile time for building up a tylar.
+ * Interface which is used at compile time for building a tylar.
+ *
+ * @author Patrick Calahan <pc...@bea.com>
*/
public interface TylarWriter {
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/JarredTylar.java
Index: JarredTylar.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache
* XMLBeans", nor may "Apache" appear in their name, without prior
* written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2000-2003 BEA Systems
* Inc., <http://www.bea.com/>. For more information on the Apache Software
* Foundation, please see <http://www.apache.org/>.
*/
package org.apache.xmlbeans.impl.binding.tylar;
import java.io.*;
import java.net.URI;
import java.net.URLClassLoader;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.jar.JarInputStream;
import java.util.jar.JarEntry;
import java.util.Collection;
import java.util.ArrayList;
import org.apache.xmlbeans.impl.binding.bts.BindingFile;
import org.apache.xmlbeans.XmlException;
import org.apache.xml.xmlbeans.bindingConfig.BindingConfigDocument;
import org.w3.x2001.xmlSchema.SchemaDocument;
/**
* A tylar that has been loaded from a jar file.
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class JarredTylar implements Tylar {
// ========================================================================
// Constants
private static final char[] OTHER_SEPCHARS = {'\\'};
private static final char SEPCHAR = '/';
private static final boolean VERBOSE = false;
private static final String BINDING_FILE =
normalizeEntryName(TylarConstants.BINDING_FILE);
private static final String SCHEMA_DIR =
normalizeEntryName(TylarConstants.SCHEMA_DIR);
// ========================================================================
// Variables
private File mJarFile;
private BindingFile mBindingFile = null;
private Collection mSchemas = null;
// ========================================================================
// Factory methods
/**
* Loads a Tylar directly from the given jar file. This method parses all
* of the tylar's binding artifacts; if it doesn't throw an exception,
* you can be sure that the tylars binding files and schemas are valid.
*
* @param jarFile file containing the tylar
* @return Handle to the tylar
* @throws IOException
*/
public static Tylar load(File jarFile) throws IOException, XmlException {
FileInputStream fin = new FileInputStream(jarFile);
HackJarInputStream in = new HackJarInputStream(fin);
JarEntry entry;
BindingFile bf = null;
Collection schemas = null;
while ((entry = in.getNextJarEntry()) != null) {
if (entry.isDirectory()) continue;
String name = normalizeEntryName(entry.getName());
if (name.equals(BINDING_FILE)) {
if (VERBOSE) System.out.println("parsing binding file "+name);
//FIXME this doesn't always work
// bf = BindingFile.forDoc(BindingConfigDocument.Factory.parse(in));
// so we do this instead
bf = BindingFile.forDoc(BindingConfigDocument.Factory.parse
(getEntryContents(in)));
} else if (name.startsWith(SCHEMA_DIR)) {
if (schemas == null) schemas = new ArrayList();
if (VERBOSE) System.out.println("parsing schema "+name);
//FIXME this doesn't work
// schemas.add(SchemaDocument.Factory.parse(in));
// so we do this instead
schemas.add(new StringReader(getEntryContents(in)));
} else {
if (VERBOSE) {
System.out.println("ignoring unknown jar entry: "+name);
System.out.println(" looking for "+BINDING_FILE+" or "+SCHEMA_DIR);
}
}
in.closeEntry();
}
if (bf == null) {
throw new IOException
(jarFile+" is not a tylar: it does not contain a binding file");
}
in.reallyClose();
return new JarredTylar(jarFile,bf,schemas);
}
public ClassLoader createClassLoader(ClassLoader parent) {
try {
return new URLClassLoader(new URL[] {mJarFile.toURL()},parent);
} catch(MalformedURLException mue){
throw new RuntimeException(mue); //FIXME this is bad
}
}
// ========================================================================
// Constructors
/*package*/ JarredTylar(File jarFile,
BindingFile bf, //can be null
Collection schemas) { //can be null
mJarFile = jarFile;
mBindingFile = bf;
mSchemas = schemas;
}
// ========================================================================
// Tylar implementation
public BindingFile getBindingFile() {
return mBindingFile;
}
public SchemaDocument[] getSchemas() {
if (mSchemas == null) return new SchemaDocument[0];
SchemaDocument[] out = new SchemaDocument[mSchemas.size()];
mSchemas.toArray(out);
return out;
}
public URI getLocation() {
return mJarFile.toURI();
}
// ========================================================================
// Private methods
/**
* Canonicalizes the given zip entry path so that we can look for what
* we want without having to worry about different slashes or
* leading slashes or anything else that can go wrong.
*/
private static final String normalizeEntryName(String name) {
name = name.toLowerCase().trim();
for(int i=0; i<OTHER_SEPCHARS.length; i++) {
name = name.replace(OTHER_SEPCHARS[i],SEPCHAR);
}
if (name.charAt(0) == SEPCHAR) name = name.substring(1);
return name;
}
/**
* This is a temporary hack around a problem I don't fully understand yet.
* For some reason, the SchemaDocument.Factory and BindingDocument.Factory
* parse methods don't deal very well with being handed the raw
* JavaInputStream. Instead, we spoonfeed them by building up the contents
* into a buffer here and then handing it off to them. Probably some
* encoding thing, not sure what is going wrong, but at least this works
* for now.
*
* The trace I get when thing go awry looks something like this:
*
* org.apache.xmlbeans.XmlException: error: Premature end of file.
* at org.apache.xmlbeans.impl.store.Root$SaxLoader.load(Root.java:802)
* at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1075)
* at org.apache.xmlbeans.impl.store.Root.loadXml(Root.java:1061)
* ...
*/
private static String getEntryContents(JarInputStream in) throws IOException {
StringWriter writer = new StringWriter();
byte[] buffer = new byte[2056];
int count = 0;
while ((count = in.read(buffer, 0, buffer.length)) != -1) {
writer.write(new String(buffer, 0, count));
}
return writer.toString();
}
/**
* This is another hack around what I believe is an xbeans bug - it
* closes the stream on us. When we're reading out of a jar, we want
* to parse a whole bunch of files from the same stream - this class
* just intercepts the close call.
*/
private static class HackJarInputStream extends JarInputStream {
HackJarInputStream(InputStream in) throws IOException {
super(in);
}
public void close() {}
public void reallyClose() throws IOException {
super.close();
}
}
}
1.1 xml-xmlbeans/v2/src/binding/org/apache/xmlbeans/impl/binding/tylar/TylarFactory.java
Index: TylarFactory.java
===================================================================
package org.apache.xmlbeans.impl.binding.tylar;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.URI;
import org.apache.xmlbeans.XmlException;
/**
* Singleton Factory for loading Tylars from a URI. Currently, only
* directory and jar tylars are supported.
*
* @author Patrick Calahan <pc...@bea.com>
*/
public class TylarFactory {
// ========================================================================
// Singleton
public static final TylarFactory getInstance() {
return INSTANCE;
}
private static final TylarFactory INSTANCE = new TylarFactory();
private TylarFactory() {
}
// ========================================================================
// Public methods
public Tylar load(URI uri) throws IOException, XmlException {
//FIXME we eventually need to be able to deal with other schemes
File file = new File(uri);
if (!file.exists()) throw new FileNotFoundException(uri.toString());
if (file.isDirectory()) {
return ExplodedTylarImpl.load(file);
} else {
return JarredTylar.load(file);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: xmlbeans-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xmlbeans-cvs-help@xml.apache.org