| Method from org.apache.xmlbeans.impl.schema.SchemaTypeSystemCompiler Detail: |
public static SchemaTypeSystem compile(SchemaTypeSystemCompiler.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());
}
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());
}
}
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, null, null, null);
// if there is an error and compile didn't recover (stsi==null), throw exception
if (errorWatcher.hasError() && stsi == null)
{
throw new XmlException(errorWatcher.firstError());
}
if (stsi != null && !stsi.isIncomplete() && filer != null)
{
stsi.save(filer);
generateTypes(stsi, filer, options);
}
return stsi;
}
Please do not invoke this method directly as the signature could change unexpectedly.
Use one of
XmlBeans#loadXsd(XmlObject[]) ,
XmlBeans#compileXsd(XmlObject[], SchemaTypeLoader, XmlOptions) ,
or
XmlBeans#compileXmlBeans(String, SchemaTypeSystem, XmlObject[], BindingConfig, SchemaTypeLoader, Filer, XmlOptions) |
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) {
if (linkTo == null)
throw new IllegalArgumentException("Must supply linkTo");
XmlErrorWatcher errorWatcher = new XmlErrorWatcher(outsideErrors);
boolean incremental = system != null;
// construct the state
StscState state = StscState.start();
boolean validate = (options == null || !options.hasOption(XmlOptions.COMPILE_NO_VALIDATION));
try
{
state.setErrorListener(errorWatcher);
state.setBindingConfig(config);
state.setOptions(options);
state.setGivenTypeSystemName(name);
state.setSchemasDir(schemasDir);
if (baseURI != null)
state.setBaseUri(baseURI);
// construct the classpath (you always get the builtin types)
linkTo = SchemaTypeLoaderImpl.build(new SchemaTypeLoader[] { BuiltinSchemaTypeSystem.get(), linkTo }, null, null);
state.setImportingTypeLoader(linkTo);
List validSchemas = new ArrayList(schemas.length);
// load all the xsd files into it
if (validate)
{
XmlOptions validateOptions = new XmlOptions().setErrorListener(errorWatcher);
if (options.hasOption(XmlOptions.VALIDATE_TREAT_LAX_AS_SKIP))
validateOptions.setValidateTreatLaxAsSkip();
for (int i = 0; i < schemas.length; i++)
{
if (schemas[i].validate(validateOptions))
validSchemas.add(schemas[i]);
}
}
else
{
validSchemas.addAll(Arrays.asList(schemas));
}
Schema[] startWith = (Schema[])validSchemas.toArray(new Schema[validSchemas.size()]);
if (incremental)
{
Set namespaces = new HashSet();
startWith = getSchemasToRecompile((SchemaTypeSystemImpl)system, startWith, namespaces);
state.initFromTypeSystem((SchemaTypeSystemImpl)system, namespaces);
}
else
{
state.setDependencies(new SchemaDependencies());
}
// deal with imports and includes
StscImporter.SchemaToProcess[] schemasAndChameleons = StscImporter.resolveImportsAndIncludes(startWith, incremental);
// call the translator so that it may also perform magic
StscTranslator.addAllDefinitions(schemasAndChameleons);
// call the resolver to do its magic
StscResolver.resolveAll();
// call the checker to check both restrictions and defaults
StscChecker.checkAll();
// call the javaizer to do its magic
StscJavaizer.javaizeAllTypes(javaize);
// construct the loader out of the state
state.get().sts().loadFromStscState(state);
// fill in the source-copy map
if (sourcesToCopyMap != null)
sourcesToCopyMap.putAll(state.sourceCopyMap());
if (errorWatcher.hasError())
{
// EXPERIMENTAL: recovery from compilation errors and partial type system
if (state.allowPartial() && state.getRecovered() == errorWatcher.size())
{
// if partial type system allowed and all errors were recovered
state.get().sts().setIncomplete(true);
}
else
{
// if any non-recoverable errors, return null
return null;
}
}
if (system != null)
((SchemaTypeSystemImpl) system).setIncomplete(true);
return state.get().sts();
}
finally
{
StscState.end();
}
}
|
public static boolean generateTypes(SchemaTypeSystem system,
Filer filer,
XmlOptions options) {
// partial type systems not allowed to be saved
if (system instanceof SchemaTypeSystemImpl && ((SchemaTypeSystemImpl)system).isIncomplete())
return false;
boolean success = true;
List types = new ArrayList();
types.addAll(Arrays.asList(system.globalTypes()));
types.addAll(Arrays.asList(system.documentTypes()));
types.addAll(Arrays.asList(system.attributeTypes()));
for (Iterator i = types.iterator(); i.hasNext(); )
{
SchemaType type = (SchemaType)i.next();
if (type.isBuiltinType())
continue;
if (type.getFullJavaName() == null)
continue;
String fjn = type.getFullJavaName();
Writer writer = null;
try
{
// Generate interface class
writer = filer.createSourceFile(fjn);
SchemaTypeCodePrinter.printType(writer, type, options);
}
catch (IOException e)
{
System.err.println("IO Error " + e);
success = false;
}
finally {
try { if (writer != null) writer.close(); } catch (IOException e) {}
}
try
{
// Generate Implementation class
fjn = type.getFullJavaImplName();
writer = filer.createSourceFile(fjn);
SchemaTypeCodePrinter.printTypeImpl(writer, type, options);
}
catch (IOException e)
{
System.err.println("IO Error " + e);
success = false;
}
finally {
try { if (writer != null) writer.close(); } catch (IOException e) {}
}
}
return success;
}
|