Author: kiwiwings
Date: Mon Apr 8 22:54:32 2019
New Revision: 1857143
URL: http://svn.apache.org/viewvc?rev=1857143&view=rev
Log:
(XMLBEANS-536) - provide option for specifying schema src directory
Modified:
xmlbeans/branches/xmlbeans-536/src/typeholder/org/apache/xmlbeans/impl/schema/TypeSystemHolder.java
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/StscImporter.java
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java
xmlbeans/branches/xmlbeans-536/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
xmlbeans/branches/xmlbeans-536/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java
Modified:
xmlbeans/branches/xmlbeans-536/src/typeholder/org/apache/xmlbeans/impl/schema/TypeSystemHolder.java
URL:
http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/typeholder/org/apache/xmlbeans/impl/schema/TypeSystemHolder.java?rev=1857143&r1=1857142&r2=1857143&view=diff
==============================================================================
---
xmlbeans/branches/xmlbeans-536/src/typeholder/org/apache/xmlbeans/impl/schema/TypeSystemHolder.java
(original)
+++
xmlbeans/branches/xmlbeans-536/src/typeholder/org/apache/xmlbeans/impl/schema/TypeSystemHolder.java
Mon Apr 8 22:54:32 2019
@@ -36,8 +36,7 @@ import org.apache.xmlbeans.SchemaTypeSys
// !!! If this scares you, turn back now !!!
//
public final class TypeSystemHolder extends SchemaTypeSystemImpl {
- // TODO: provide parameter-less parent constructor
- private TypeSystemHolder() { super(TypeSystemHolder.class); }
+ private TypeSystemHolder() { }
// the type system
public static final SchemaTypeSystem typeSystem = new TypeSystemHolder();
Modified:
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java
URL:
http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java?rev=1857143&r1=1857142&r2=1857143&view=diff
==============================================================================
---
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java
(original)
+++
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemCompiler.java
Mon Apr 8 22:54:32 2019
@@ -15,35 +15,19 @@
package org.apache.xmlbeans.impl.schema;
-import org.apache.xmlbeans.XmlBeans;
-import org.apache.xmlbeans.SchemaTypeLoader;
-import org.apache.xmlbeans.XmlException;
-import org.apache.xmlbeans.XmlErrorCodes;
-import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlOptions;
-import org.apache.xmlbeans.SchemaTypeSystem;
-import org.apache.xmlbeans.Filer;
-import org.apache.xmlbeans.SchemaType;
-import org.apache.xmlbeans.BindingConfig;
-
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.List;
-import java.util.Set;
-import java.util.Arrays;
-import java.net.URI;
-
-import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument.Schema;
-import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
+import org.apache.xmlbeans.*;
import org.apache.xmlbeans.impl.common.XmlErrorWatcher;
+import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
+import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument.Schema;
-import java.util.Collection;
-import java.util.Iterator;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
+import java.net.URI;
+import java.util.*;
+
+import static
org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl.getContextTypeLoader;
+import static
org.apache.xmlbeans.impl.schema.SchemaTypeSystemImpl.METADATA_PACKAGE_GEN;
public class SchemaTypeSystemCompiler
{
@@ -52,6 +36,7 @@ public class SchemaTypeSystemCompiler
private SchemaTypeSystem existingSystem;
private String name;
private Schema[] schemas;
+ private XmlObject[] inputXmls;
private BindingConfig config;
private SchemaTypeLoader linkTo;
private XmlOptions options;
@@ -60,6 +45,8 @@ public class SchemaTypeSystemCompiler
private URI baseURI;
private Map sourcesToCopyMap;
private File schemasDir;
+ private File classesDir;
+ private Filer filer;
public SchemaTypeSystem getExistingTypeSystem()
{
@@ -171,60 +158,82 @@ public class SchemaTypeSystemCompiler
this.schemasDir = schemasDir;
}
- }
+ public File getClassesDir()
+ {
+ return classesDir;
+ }
- /**
- * Compiles a SchemaTypeSystem. Use XmlBeans.compileXmlBeans() if you can.
- */
- public static SchemaTypeSystem compile(Parameters params)
- {
- return compileImpl(params.getExistingTypeSystem(), params.getName(),
- params.getSchemas(), params.getConfig(), params.getLinkTo(),
- params.getOptions(), params.getErrorListener(), params.isJavaize(),
- params.getBaseURI(), params.getSourcesToCopyMap(),
params.getSchemasDir());
+ public void setClassesDir(File classesDir)
+ {
+ this.classesDir = classesDir;
+ }
+
+ public XmlObject[] getInputXmls() {
+ return inputXmls;
+ }
+
+ public void setInputXmls(XmlObject[] inputXmls) {
+ this.inputXmls = inputXmls;
+ }
+
+ public Filer getFiler() {
+ return filer;
+ }
+
+ public void setFiler(Filer filer) {
+ this.filer = filer;
+ }
}
/**
- * Please do not invoke this method directly as the signature could change
unexpectedly.
- * Use one of
- * {@link XmlBeans#loadXsd(XmlObject[])},
- * {@link XmlBeans#compileXsd(XmlObject[], SchemaTypeLoader, XmlOptions)},
- * or
- * {@link XmlBeans#compileXmlBeans(String, SchemaTypeSystem, XmlObject[],
BindingConfig, SchemaTypeLoader, Filer, XmlOptions)}
+ * Compiles a SchemaTypeSystem. Use XmlBeans.compileXmlBeans() if you can.
*/
- public static SchemaTypeSystemImpl compile(String name, SchemaTypeSystem
existingSTS,
- XmlObject[] input, BindingConfig config, SchemaTypeLoader linkTo,
Filer filer, XmlOptions options)
- throws XmlException
- {
- options = XmlOptions.maskNull(options);
- ArrayList schemas = new ArrayList();
-
- if (input != null)
- {
- for (int i = 0; i < input.length; i++)
- {
- if (input[i] instanceof Schema)
- schemas.add(input[i]);
- else if (input[i] instanceof SchemaDocument &&
((SchemaDocument)input[i]).getSchema() != null)
- schemas.add(((SchemaDocument)input[i]).getSchema());
- else
- throw new XmlException("Thread " +
Thread.currentThread().getName() + ": The " + i + "th supplied input is not a
schema document: its type is " + input[i].schemaType());
+ public static SchemaTypeSystem compile(Parameters params) {
+ final XmlOptions options = XmlOptions.maskNull(params.getOptions());
+ final List<Schema> schemas = new ArrayList<Schema>();
+ if (params.getSchemas() != null) {
+ schemas.addAll(Arrays.asList(params.getSchemas()));
+ }
+
+ final Collection userErrors = (params.getErrorListener() != null)
+ ? params.getErrorListener()
+ : (Collection)options.get(XmlOptions.ERROR_LISTENER);
+ final XmlErrorWatcher errorWatcher = (userErrors instanceof
XmlErrorWatcher)
+ ? (XmlErrorWatcher)userErrors
+ : new XmlErrorWatcher(userErrors);
+
+ if (params.getInputXmls() != null) {
+ int idx = 0;
+ for (XmlObject xo : params.getInputXmls()) {
+ XmlObject xoOrig = xo;
+ if (xo instanceof SchemaDocument) {
+ xo = ((SchemaDocument)xo).getSchema();
+ }
+
+ if (xo instanceof Schema) {
+ schemas.add((Schema) xo);
+ } else {
+ XmlError xe = XmlError.forObject("The supplied input
(index: "+idx+") is not a schema document: its type is " + (xo == null ? "null"
: xo.schemaType()), XmlError.SEVERITY_ERROR, xo);
+ errorWatcher.add(xe);
+ return null;
+ }
+ idx++;
}
}
- Collection userErrors =
(Collection)options.get(XmlOptions.ERROR_LISTENER);
- XmlErrorWatcher errorWatcher = new XmlErrorWatcher(userErrors);
-
- SchemaTypeSystemImpl stsi = compileImpl(existingSTS, name,
- (Schema[])schemas.toArray(new Schema[schemas.size()]),
- config, linkTo, options, errorWatcher, filer!=null, (URI)
options.get(XmlOptions.BASE_URI),
- null, null);
+ final SchemaTypeLoader linkTo = (params.getLinkTo() != null) ?
params.getLinkTo() : getContextTypeLoader();
- // if there is an error and compile didn't recover (stsi==null), throw
exception
- if (errorWatcher.hasError() && stsi == null)
- {
- throw new XmlException(errorWatcher.firstError());
- }
+ final URI baseUri = (params.getBaseURI() != null) ?
params.getBaseURI() : (URI)options.get(XmlOptions.BASE_URI);
+ final Filer filer = params.getFiler();
+ final boolean isJavaize = params.isJavaize() || filer != null;
+
+ final File schemasDir = (params.getSchemasDir() != null) ?
params.getSchemasDir() : new File(METADATA_PACKAGE_GEN);
+
+ SchemaTypeSystemImpl stsi =
compileImpl(params.getExistingTypeSystem(), params.getName(),
+ schemas.toArray(new Schema[0]), params.getConfig(), linkTo,
+ options, errorWatcher, isJavaize,
+ baseUri, params.getSourcesToCopyMap(), schemasDir,
+ params.getClassesDir());
if (stsi != null && !stsi.isIncomplete() && filer != null)
{
@@ -241,7 +250,7 @@ public class SchemaTypeSystemCompiler
/* package */ static SchemaTypeSystemImpl compileImpl( SchemaTypeSystem
system, String name,
Schema[] schemas, BindingConfig config, SchemaTypeLoader linkTo,
XmlOptions options, Collection outsideErrors, boolean javaize,
- URI baseURI, Map sourcesToCopyMap, File schemasDir)
+ URI baseURI, Map sourcesToCopyMap, File schemasDir, File classesDir)
{
if (linkTo == null)
throw new IllegalArgumentException("Must supply linkTo");
@@ -259,6 +268,7 @@ public class SchemaTypeSystemCompiler
state.setOptions(options);
state.setGivenTypeSystemName(name);
state.setSchemasDir(schemasDir);
+ state.setClassesDir(classesDir);
if (baseURI != null)
state.setBaseUri(baseURI);
Modified:
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
URL:
http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java?rev=1857143&r1=1857142&r2=1857143&view=diff
==============================================================================
---
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
(original)
+++
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/SchemaTypeSystemImpl.java
Mon Apr 8 22:54:32 2019
@@ -137,12 +137,7 @@ public class SchemaTypeSystemImpl extend
static final int FLAG_ABSTRACT = 0x40000;
static final int FLAG_ATTRIBUTE_TYPE = 0x80000;
- /**
- * regex to identify the type system holder package namespace
- */
- private static final Pattern packPat =
Pattern.compile("^(.+)(\\.[^.]+){3}$");
-
- /**
+ /**
* This is to support the feature of a separate/private XMLBeans
* distribution that will not colide with the public org apache
* xmlbeans one.
@@ -937,7 +932,7 @@ public class SchemaTypeSystemImpl extend
}
}
- public SchemaTypeSystemImpl(String nameForSystem)
+ public SchemaTypeSystemImpl(String nameForSystem, String schemasDir)
{
// if we have no name, select a random one
if (nameForSystem == null)
@@ -948,7 +943,7 @@ public class SchemaTypeSystemImpl extend
nameForSystem = "s" + new String(HexBin.encode(bytes));
}
- _name = getMetadataPath().replace('/','.') + ".system." +
nameForSystem;
+ _name = schemasDir.replace('/','.') + ".system." + nameForSystem;
_basePackage = nameToPathString(_name);
_classloader = null;
//System.out.println(" _base: " + _basePackage);
@@ -3851,8 +3846,6 @@ public class SchemaTypeSystemImpl extend
* @since XmlBeans 3.0.3
*/
public String getMetadataPath() {
- Matcher m = packPat.matcher(getClass().getName());
- m.find();
- return m.group(1).replace('.','/');
+ return new File(_basePackage).getParentFile().getParent();
}
}
Modified:
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/StscImporter.java
URL:
http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/StscImporter.java?rev=1857143&r1=1857142&r2=1857143&view=diff
==============================================================================
---
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/StscImporter.java
(original)
+++
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/StscImporter.java
Mon Apr 8 22:54:32 2019
@@ -881,8 +881,7 @@ public class StscImporter
if (state.getSchemasDir() == null)
return reader;
- String schemalocation = state.sourceNameForUri(url);
- File targetFile = new File(state.getSchemasDir(), schemalocation);
+ File targetFile = getTargetDir(url, state);
if (targetFile.exists())
return reader;
@@ -912,8 +911,7 @@ public class StscImporter
if (state.getSchemasDir() == null)
return bytes;
- String schemalocation = state.sourceNameForUri(url);
- File targetFile = new File(state.getSchemasDir(), schemalocation);
+ File targetFile = getTargetDir(url, state);
if (targetFile.exists())
return bytes;
@@ -942,9 +940,7 @@ public class StscImporter
//Copy the schema file if it wasn't already copied
if (state.getSchemasDir()!=null)
{
- String schemalocation = state.sourceNameForUri(urlLoc);
-
- File targetFile = new File(state.getSchemasDir(),
schemalocation);
+ File targetFile = getTargetDir(urlLoc, state);
if (forceCopy || !targetFile.exists())
{
try
@@ -981,6 +977,24 @@ public class StscImporter
}
}
+ private static File getTargetDir(String urlLoc, StscState state) {
+ String[] paths = {
+ state.getClassesDir() == null ? null :
state.getClassesDir().getPath(),
+ state.getSchemasDir() == null ? null :
state.getSchemasDir().getPath(),
+ "src",
+ state.sourceNameForUri(urlLoc)
+ };
+
+ File parent = null;
+ for (String path : paths) {
+ if (path != null) {
+ parent = new File(parent, path);
+ }
+ }
+
+ return parent;
+ }
+
private static ByteArrayInputStream copy(InputStream is) throws
IOException
{
byte [] buf = new byte[1024];
Modified:
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java
URL:
http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java?rev=1857143&r1=1857142&r2=1857143&view=diff
==============================================================================
---
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java
(original)
+++
xmlbeans/branches/xmlbeans-536/src/typeimpl/org/apache/xmlbeans/impl/schema/StscState.java
Mon Apr 8 22:54:32 2019
@@ -96,6 +96,7 @@ public class StscState
private Set _mdefNamespaces = buildDefaultMdefNamespaces();
private EntityResolver _entityResolver;
private File _schemasDir;
+ private File _classesDir;
private static Set buildDefaultMdefNamespaces()
{
@@ -473,7 +474,7 @@ public class StscState
if (name == null && _digest != null)
name = "s" + new String(HexBin.encode(_digest));
- _target = new SchemaTypeSystemImpl(name);
+ _target = new SchemaTypeSystemImpl(name, _schemasDir.getPath());
return _target;
}
@@ -1596,4 +1597,12 @@ public class StscState
{
this._schemasDir = _schemasDir;
}
+
+ public File getClassesDir() {
+ return _classesDir;
+ }
+
+ public void setClassesDir(File classesDir) {
+ this._classesDir = classesDir;
+ }
}
Modified:
xmlbeans/branches/xmlbeans-536/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
URL:
http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java?rev=1857143&r1=1857142&r2=1857143&view=diff
==============================================================================
---
xmlbeans/branches/xmlbeans-536/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
(original)
+++
xmlbeans/branches/xmlbeans-536/src/xmlcomp/org/apache/xmlbeans/impl/tool/SchemaCompiler.java
Mon Apr 8 22:54:32 2019
@@ -142,6 +142,7 @@ public class SchemaCompiler
opts.add("extensionParms");
opts.add("allowmdef");
opts.add("catalog");
+ opts.add("schemasDir");
CommandLine cl = new CommandLine(args, flags, opts);
if (cl.getOpt("h") != null || cl.getOpt("help") != null ||
cl.getOpt("usage") != null)
@@ -337,6 +338,12 @@ public class SchemaCompiler
String catString = cl.getOpt("catalog");
+ String schemasDir = cl.getOpt("schemasDir");
+ if (schemasDir == null || schemasDir.isEmpty()) {
+ schemasDir = SchemaTypeSystemImpl.METADATA_PACKAGE_GEN;
+ }
+
+
Parameters params = new Parameters();
params.setBaseDir(baseDir);
params.setXsdFiles(xsdFiles);
@@ -369,6 +376,7 @@ public class SchemaCompiler
params.setMdefNamespaces(mdefNamespaces);
params.setCatalogFile(catString);
params.setSchemaCodePrinter(codePrinter);
+ params.setSchemasDir(schemasDir);
boolean result = compile(params);
@@ -416,6 +424,7 @@ public class SchemaCompiler
private String catalogFile;
private SchemaCodePrinter schemaCodePrinter;
private EntityResolver entityResolver;
+ private String schemasDir;
public File getBaseDir()
{
@@ -754,14 +763,21 @@ public class SchemaCompiler
public void setEntityResolver(EntityResolver entityResolver) {
this.entityResolver = entityResolver;
}
+
+ public String getSchemasDir() {
+ return schemasDir;
+ }
+
+ public void setSchemasDir(String schemasDir) {
+ this.schemasDir = schemasDir;
+ }
}
private static SchemaTypeSystem loadTypeSystem(String name, File[]
xsdFiles, File[] wsdlFiles, URL[] urlFiles, File[] configFiles,
File[] javaFiles, ResourceLoader cpResourceLoader,
boolean download, boolean noUpa, boolean noPvr, boolean noAnn, boolean
noVDoc, boolean noExt,
Set mdefNamespaces, File baseDir, Map sourcesToCopyMap,
- Collection outerErrorListener, File schemasDir, EntityResolver
entResolver, File[] classpath, String javasource)
- {
+ Collection outerErrorListener, File schemasDir, File classesDir,
EntityResolver entResolver, File[] classpath, String javasource) {
XmlErrorWatcher errorListener = new
XmlErrorWatcher(outerErrorListener);
// construct the state (have to initialize early in case of errors)
@@ -937,6 +953,7 @@ public class SchemaCompiler
params.setBaseURI(baseURI);
params.setSourcesToCopyMap(sourcesToCopyMap);
params.setSchemasDir(schemasDir);
+ params.setClassesDir(classesDir);
return SchemaTypeSystemCompiler.compile(params);
} finally {
StscState.end();
@@ -988,8 +1005,7 @@ public class SchemaCompiler
StscState.addInfo(errorListener, "Processing " + count + " schema(s)
in " + name);
}
- public static boolean compile(Parameters params)
- {
+ public static boolean compile(Parameters params) {
File baseDir = params.getBaseDir();
File[] xsdFiles = params.getXsdFiles();
File[] wsdlFiles = params.getWsdlFiles();
@@ -1018,6 +1034,10 @@ public class SchemaCompiler
boolean incrSrcGen = params.isIncrementalSrcGen();
Collection outerErrorListener = params.getErrorListener();
+ if (params.getSchemasDir() == null) {
+ params.setSchemasDir(SchemaTypeSystemImpl.METADATA_PACKAGE_GEN);
+ }
+
String repackage = params.getRepackage();
if (repackage!=null)
@@ -1057,13 +1077,13 @@ public class SchemaCompiler
boolean result = true;
- File schemasDir = IOUtil.createDir(classesDir,
SchemaTypeSystemImpl.METADATA_PACKAGE_GEN + "/src");
+ File schemasDir = new File(params.getSchemasDir());
// build the in-memory type system
XmlErrorWatcher errorListener = new
XmlErrorWatcher(outerErrorListener);
SchemaTypeSystem system = loadTypeSystem(name, xsdFiles, wsdlFiles,
urlFiles, configFiles,
javaFiles, cpResourceLoader, download, noUpa, noPvr, noAnn,
noVDoc, noExt, mdefNamespaces,
- baseDir, sourcesToCopyMap, errorListener, schemasDir,
cmdLineEntRes, classpath, javasource);
+ baseDir, sourcesToCopyMap, errorListener, schemasDir, classesDir,
cmdLineEntRes, classpath, javasource);
if (errorListener.hasError())
result = false;
long finish = System.currentTimeMillis();
Modified:
xmlbeans/branches/xmlbeans-536/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java
URL:
http://svn.apache.org/viewvc/xmlbeans/branches/xmlbeans-536/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java?rev=1857143&r1=1857142&r2=1857143&view=diff
==============================================================================
---
xmlbeans/branches/xmlbeans-536/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java
(original)
+++
xmlbeans/branches/xmlbeans-536/src/xmlpublic/org/apache/xmlbeans/XmlBeans.java
Mon Apr 8 22:54:32 2019
@@ -15,10 +15,12 @@
package org.apache.xmlbeans;
+import org.apache.xmlbeans.impl.common.XmlErrorWatcher;
import org.apache.xmlbeans.impl.schema.BuiltinSchemaTypeSystem;
import org.apache.xmlbeans.impl.schema.PathResourceLoader;
import org.apache.xmlbeans.impl.schema.SchemaTypeLoaderImpl;
import org.apache.xmlbeans.impl.schema.SchemaTypeSystemCompiler;
+import org.apache.xmlbeans.impl.schema.SchemaTypeSystemCompiler.Parameters;
import org.apache.xmlbeans.impl.store.Locale;
import org.w3c.dom.Node;
@@ -27,6 +29,8 @@ import javax.xml.stream.XMLStreamReader;
import java.io.File;
import java.lang.ref.SoftReference;
import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
/**
* Provides an assortment of utilities
@@ -274,8 +278,19 @@ public final class XmlBeans
* @param options Options specifying an error listener and/or validation
behavior.
*/
public static SchemaTypeLoader loadXsd(XmlObject[] schemas, XmlOptions
options) throws XmlException {
- SchemaTypeSystem sts = SchemaTypeSystemCompiler.compile(null, null,
schemas, null, getContextTypeLoader(), null, options);
- return (sts == null) ? null : typeLoaderUnion(sts,
getContextTypeLoader());
+ Parameters params = new Parameters();
+ params.setInputXmls(schemas);
+ params.setOptions(options);
+
+ XmlErrorWatcher xew = setErrorWatcher(params, options);
+
+ SchemaTypeSystem sts = SchemaTypeSystemCompiler.compile(params);
+
+ if (xew.hasError() && sts == null) {
+ throw new XmlException(xew.firstError());
+ }
+
+ return typeLoaderUnion(sts, getContextTypeLoader());
}
@@ -423,7 +438,34 @@ public final class XmlBeans
* @param options Options specifying an error listener and/or validation
behavior.
*/
public static SchemaTypeSystem compileXmlBeans(String name,
SchemaTypeSystem system, XmlObject[] schemas, BindingConfig config,
SchemaTypeLoader typepath, Filer filer, XmlOptions options) throws XmlException
{
- return SchemaTypeSystemCompiler.compile(name, system, schemas, config,
typepath != null ? typepath : getContextTypeLoader(), filer, options);
+ Parameters params = new Parameters();
+ params.setName(name);
+ params.setExistingTypeSystem(system);
+ params.setInputXmls(schemas);
+ params.setConfig(config);
+ params.setLinkTo(typepath);
+ params.setFiler(filer);
+ params.setOptions(options);
+
+ XmlErrorWatcher xew = setErrorWatcher(params, options);
+
+ SchemaTypeSystem sts = SchemaTypeSystemCompiler.compile(params);
+
+ if (xew.hasError() && sts == null) {
+ throw new XmlException(xew.firstError());
+ }
+
+ return sts;
+ }
+
+ @SuppressWarnings("unchecked")
+ private static XmlErrorWatcher setErrorWatcher(Parameters params,
XmlOptions options) {
+ Collection<XmlError> errorListener = (options != null &&
options.hasOption (XmlOptions.ERROR_LISTENER))
+ ? (Collection<XmlError>)options.get(XmlOptions.ERROR_LISTENER)
+ : new ArrayList<XmlError>();
+ XmlErrorWatcher xew = new XmlErrorWatcher(errorListener);
+ params.setErrorListener(xew);
+ return xew;
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]