Index: src/test/java/org/exolab/castor/xml/XMLContextTest.java =================================================================== --- src/test/java/org/exolab/castor/xml/XMLContextTest.java (revision 7156) +++ src/test/java/org/exolab/castor/xml/XMLContextTest.java (working copy) @@ -37,7 +37,7 @@ public void testXMLContextByMapping() throws Exception { - Mapping mapping = XMLContext.createMapping(); + Mapping mapping = new XMLContext().createMapping(); mapping.loadMapping(new InputSource(getResource(MAPPING_FILE))); XMLContext context = new XMLContext(); Index: src/main/java/org/exolab/castor/dsml/Importer.java =================================================================== --- src/main/java/org/exolab/castor/dsml/Importer.java (revision 7156) +++ src/main/java/org/exolab/castor/dsml/Importer.java (working copy) @@ -58,6 +58,7 @@ import org.castor.util.Messages; import org.exolab.castor.util.Configuration; import org.exolab.castor.util.LocalConfiguration; +import org.exolab.castor.xml.XMLContext; /** @@ -68,9 +69,9 @@ */ public abstract class Importer { + private XMLContext _xmlContext = new XMLContext(); - private Configuration _config = LocalConfiguration.getInstance(); - +// private Configuration _config = LocalConfiguration.getInstance(); private ImportDescriptor _importDesc; @@ -110,14 +111,14 @@ public void importDocument( InputStream stream ) throws ImportExportException { - importDocument( _config.getParser(), new InputSource( stream ) ); + importDocument( _xmlContext.getParser(), new InputSource( stream ) ); } public void importDocument( Reader reader ) throws ImportExportException { - importDocument( _config.getParser(), new InputSource( reader ) ); + importDocument( _xmlContext.getParser(), new InputSource( reader ) ); } @@ -143,14 +144,14 @@ public void readImportDescriptor( InputStream input ) throws IOException, SAXException { - readImportDescriptor( _config.getParser(), new InputSource( input ) ); + readImportDescriptor( _xmlContext.getParser(), new InputSource( input ) ); } public void readImportDescriptor( Reader input ) throws IOException, SAXException { - readImportDescriptor( _config.getParser(), new InputSource( input ) ); + readImportDescriptor( _xmlContext.getParser(), new InputSource( input ) ); } Index: src/main/java/org/exolab/castor/dsml/Exporter.java =================================================================== --- src/main/java/org/exolab/castor/dsml/Exporter.java (revision 7156) +++ src/main/java/org/exolab/castor/dsml/Exporter.java (working copy) @@ -58,6 +58,7 @@ import org.xml.sax.InputSource; import org.exolab.castor.util.Configuration; import org.exolab.castor.util.LocalConfiguration; +import org.exolab.castor.xml.XMLContext; import org.exolab.castor.dsml.SearchDescriptor; import org.exolab.castor.dsml.ImportDescriptor; @@ -71,8 +72,9 @@ public abstract class Exporter { + private XMLContext _xmlContext = new XMLContext(); - private Configuration _config = LocalConfiguration.getInstance(); +// private Configuration _config = LocalConfiguration.getInstance(); private SearchDescriptor _searchDesc; @@ -85,7 +87,7 @@ throws ImportExportException { try { - export( _config.getSerializer( output ), serverSchema, importPolicy ); + export( _xmlContext.getSerializer( output ), serverSchema, importPolicy ); } catch ( IOException except ) { throw new ImportExportException( except ); } @@ -96,7 +98,7 @@ throws ImportExportException { try { - export( _config.getSerializer( output ), serverSchema, importPolicy ); + export( _xmlContext.getSerializer( output ), serverSchema, importPolicy ); } catch ( IOException except ) { throw new ImportExportException( except ); } @@ -135,14 +137,14 @@ public void readSearchDescriptor( InputStream input ) throws IOException, SAXException { - readSearchDescriptor( _config.getParser(), new InputSource( input ) ); + readSearchDescriptor( _xmlContext.getParser(), new InputSource( input ) ); } public void readSearchDescriptor( Reader input ) throws IOException, SAXException { - readSearchDescriptor( _config.getParser(), new InputSource( input ) ); + readSearchDescriptor( _xmlContext.getParser(), new InputSource( input ) ); } Index: src/main/java/org/exolab/castor/xml/XMLMappingLoader.java =================================================================== --- src/main/java/org/exolab/castor/xml/XMLMappingLoader.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/XMLMappingLoader.java (working copy) @@ -119,6 +119,9 @@ private static final String VALUE_OF = "valueOf"; //----------------------------------------------------------------------------------- + + /** The Castor XML context - mother of all. */ + private XMLContext _xmlContext; /** A reference to the internal ClassDescriptorResolver. */ private XMLClassDescriptorResolverImpl _cdResolver; @@ -132,14 +135,15 @@ //----------------------------------------------------------------------------------- /** - * Creates a new XMLMappingLoader + * Creates a new XMLMappingLoader. + * Joachim 2007-08-19: called via ClassLoader from XMLMappingLoaderFactory.getMappingLoader() */ - public XMLMappingLoader(ClassLoader loader) { + public XMLMappingLoader(final ClassLoader loader) { super(loader); - LocalConfiguration config = LocalConfiguration.getInstance(); - _primitiveNodeType = config.getPrimitiveNodeType(); - _naming = config.getXMLNaming(); + _xmlContext = new XMLContext(); + _primitiveNodeType = _xmlContext.getPrimitiveNodeType(); + _naming = _xmlContext.getXMLNaming(); } //----------------------------------------------------------------------------------- Index: src/main/java/org/exolab/castor/xml/XMLContext.java =================================================================== --- src/main/java/org/exolab/castor/xml/XMLContext.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/XMLContext.java (working copy) @@ -15,11 +15,41 @@ */ package org.exolab.castor.xml; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.Map; +import java.util.Properties; +import java.util.StringTokenizer; + +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.parsers.SAXParser; +import javax.xml.parsers.SAXParserFactory; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.castor.mapping.BindingType; import org.castor.mapping.MappingUnmarshaller; +import org.castor.util.Messages; +import org.castor.xml.JavaNaming; +import org.castor.xml.JavaNamingImpl; import org.exolab.castor.mapping.Mapping; import org.exolab.castor.mapping.MappingException; import org.exolab.castor.mapping.MappingLoader; +import org.exolab.castor.util.Configuration; +import org.exolab.castor.util.LocalConfiguration; +import org.exolab.castor.util.RegExpEvaluator; +import org.exolab.castor.util.Configuration.Property; +import org.exolab.castor.xml.schema.reader.SchemaReader; +import org.exolab.castor.xml.schema.writer.SchemaWriter; +import org.exolab.castor.xml.util.DefaultNaming; +import org.xml.sax.DocumentHandler; +import org.xml.sax.InputSource; +import org.xml.sax.Parser; +import org.xml.sax.SAXException; +import org.xml.sax.SAXNotRecognizedException; +import org.xml.sax.SAXNotSupportedException; +import org.xml.sax.XMLReader; /** * Bootstrap class for Castor XML that allows you to load information about the @@ -29,21 +59,37 @@ * @since 1.1.2 */ public class XMLContext { + /** Logger to be used. */ + private static final Log LOG = LogFactory.getFactory().getInstance(XMLContext.class); + /** String representation for TRUE. */ + static final String TRUE_VALUE = "true"; + /** String representation of on. */ + static final String ON_VALUE = "on"; + + /** The configuration to use internally to provide parser, serializer, ... */ + private LocalConfiguration _config; + /** + * Instead of having a big number of attributes at this place they + * are collected in a private member class. + */ + private ContextValues _values = new ContextValues(); + /** * {@link XMLClassDescriptorResolver} instance used for caching XML-related * class descriptors. */ - private XMLClassDescriptorResolver resolver; + private XMLClassDescriptorResolver _resolver; /** * Creates an instance of {@link XMLContext}, preconfigured with class descriptors * loaded for the given package name. */ public XMLContext() { - resolver = (XMLClassDescriptorResolver) ClassDescriptorResolverFactory + _config = LocalConfiguration.getInstance(); + _resolver = (XMLClassDescriptorResolver) ClassDescriptorResolverFactory .createClassDescriptorResolver(BindingType.XML); - resolver.setClassLoader(getClass().getClassLoader()); + _resolver.setClassLoader(getClass().getClassLoader()); } /** @@ -52,10 +98,11 @@ * descriptors will be derived. * @throws MappingException If the {@link Mapping} cannot be loaded and analyzed successfully. */ - public void addMapping(Mapping mapping) throws MappingException { + public void addMapping(final Mapping mapping) throws MappingException { MappingUnmarshaller mappingUnmarshaller = new MappingUnmarshaller(); - MappingLoader mappingLoader = mappingUnmarshaller.getMappingLoader(mapping, BindingType.XML); - resolver.setMappingLoader(mappingLoader); + MappingLoader mappingLoader = + mappingUnmarshaller.getMappingLoader(mapping, BindingType.XML); + _resolver.setMappingLoader(mappingLoader); } // /** @@ -71,14 +118,14 @@ // /** * Loads the class descriptor for the class instance specified. The use of this method is useful - * when no mapping is used, as happens when the domain classes hase been generated + * when no mapping is used, as happens when the domain classes has been generated * using the XML code generator (in which case instead of a mapping file class * descriptor files will be generated). * - * @param className Name of the class for which the associated descriptor should be loaded. + * @param clazz the class for which the associated descriptor should be loaded. */ - public void addClass(final String className) throws ResolverException { - resolver.addClass(className); + public void addClass(final Class clazz) throws ResolverException { + _resolver.addClass(clazz); } /** @@ -87,10 +134,10 @@ * using the XML code generator (in which case instead of a mapping file class * descriptor files will be generated). * - * @param className Name of the class for which the associated descriptor should be loaded. + * @param clazzes the classes for which the associated descriptor should be loaded. */ - public void addClasses(final String[] classNames) throws ResolverException { - resolver.addClasses(classNames); + public void addClasses(final Class[] clazzes) throws ResolverException { + _resolver.addClasses(clazzes); } /** @@ -103,10 +150,11 @@ * file with your generated classes (as generated by the XML code generator). *

* @param packageName The package name for the (descriptor) classes - * @throws ResolverException If there's a problem loading class descriptors for the given package. + * @throws ResolverException + * If there's a problem loading class descriptors for the given package. */ public void addPackage(final String packageName) throws ResolverException { - resolver.addPackage(packageName); + _resolver.addPackage(packageName); } /** @@ -119,17 +167,18 @@ * files with your generated classes (as generated by the XML code generator). *

* @param packageNames The package names for the (descriptor) classes - * @throws ResolverException If there's a problem loading class descriptors for the given package. + * @throws ResolverException + * If there's a problem loading class descriptors for the given package. */ public void addPackages(final String[] packageNames) throws ResolverException { - resolver.addPackages(packageNames); + _resolver.addPackages(packageNames); } /** * Creates an instance of a Castor XML specific {@link Mapping} instance. * @return a Castor XML specific {@link Mapping} instance. */ - public static Mapping createMapping() { + public Mapping createMapping() { Mapping mapping = new Mapping(); // mapping.setBindingType(BindingType.XML); return mapping; @@ -141,7 +190,8 @@ */ public Marshaller createMarshaller() { Marshaller marshaller = new Marshaller(); - marshaller.setResolver(resolver); + marshaller.setXMLContext(this); + marshaller.setResolver(_resolver); return marshaller; } @@ -153,18 +203,533 @@ */ public Unmarshaller createUnmarshaller() { Unmarshaller unmarshaller = new Unmarshaller(); - unmarshaller.setResolver(resolver); + unmarshaller.setXMLContext(this); + unmarshaller.setResolver(_resolver); return unmarshaller; } + + /** + * To create a schema reader instance for reading XSD files. + * @param inputSource the InputSource to read from + * @return the SchemaReader instance created and initialized + */ + public SchemaReader createSchemaReader(final InputSource inputSource) { + SchemaReader sr = new SchemaReader(); + sr.setXMLContext(this); + sr.setInputSource(inputSource); + return sr; + } + + /** + * To create a schema writer instance for writing XSD files. + * @param writer the Writer to write the text representation of the schema to + * @return the SchemaWriter instance created and initialized + * @throws IOException in case that initialization of SchemaWriter fails + */ + public SchemaWriter createSchemaWriter(final Writer writer) throws IOException { + SchemaWriter sw = new SchemaWriter(); + sw.setXMLContext(this); + sw.setDocumentHandler(writer); + return sw; + } /** - * Sets an application-specific {@link XMLClassDescriptorResolver} instance - * @param resolver + * Sets an application-specific {@link XMLClassDescriptorResolver} instance. + * @param resolver the resolver to use */ - public void setResolver(XMLClassDescriptorResolver resolver) { - this.resolver = resolver; + public void setResolver(final XMLClassDescriptorResolver resolver) { + this._resolver = resolver; } + /** + * To set properties for marshalling and unmarshalling behavior. + * @param property name of the property to set + * @param value the value to set to + */ + public void setProperty(final String property, final Object value) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Auto-generated method stub"); + // + } + + /** + * To get the value of a specific property. + * @param propertyName name of the Property + * @return the value (Object) of the property + */ + public Object getProperty(final String propertyName) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Auto-generated method stub"); + // return null; + } + + public void setProperties(final Map properties) { + // TODO Auto-generated method stub + throw new UnsupportedOperationException("Auto-generated method stub"); + // + } + + /** + * Returns the naming conventions to use for the XML framework. + * + * @return the naming conventions to use for the XML framework + */ + public XMLNaming getXMLNaming() { + return getXMLNaming(null); + } + + /** + * Returns the naming conventions to use for the XML framework. + * @param classLoader the class loader to be used when instantiating a new naming instance + * @return the naming conventions to use for the XML framework + */ + public XMLNaming getXMLNaming(final ClassLoader classLoader) { + + if (_values._xmlNaming != null) { + return _values._xmlNaming; + } + + String prop = _config.getProperty(Property.Naming, null); + if ((prop == null) || (prop.equalsIgnoreCase("lower"))) { + _values._xmlNaming = new DefaultNaming(); + } else if (prop.equalsIgnoreCase("mixed")) { + DefaultNaming dn = new DefaultNaming(); + dn.setStyle(DefaultNaming.MIXED_CASE_STYLE); + _values._xmlNaming = dn; + } else { + try { + Class cls = null; + if (classLoader != null) { + cls = classLoader.loadClass(prop); + } else { + cls = Class.forName(prop); + } + _values._xmlNaming = (XMLNaming) cls.newInstance(); + } catch (Exception e) { + throw new RuntimeException("Failed to load XMLNaming: " + e); + } + } + return _values._xmlNaming; + } //-- getXMLNaming + + /** + * The {@link JavaNaming} instance to be used. + * @return {@link JavaNaming} instance to be used. + */ + public JavaNaming getJavaNaming() { + return new JavaNamingImpl(); + } + + /** + * Return an XML document parser implementing the feature list + * specified in the configuration file. + * + * @return A suitable XML parser + */ + public Parser getParser() + { + return getParser(null); + } + + + /** + * Returns an XML document parser implementing the requested + * set of features. The feature list is a comma separated list + * of features that parser may or may not support. No errors are + * generated for unsupported features. If the feature list is not + * null, it overrides the default feature list specified in the + * configuration file, including validation and Namespaces. + * + * @param features The requested feature list, null for the + * defaults + * @return A suitable XML parser + */ + public Parser getParser(final String features) { + String prop; + Parser parser; + + // -- validation? + prop = _config.getProperties().getProperty(Property.ParserValidation, "false"); + boolean validation = (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")); + + // -- namespaces? + prop = _config.getProperties().getProperty(Property.Namespaces, "false"); + boolean namespaces = (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")); + + // -- which parser? + prop = _config.getProperties().getProperty(Property.Parser); + if ((prop == null) || (prop.length() == 0)) { + // If no parser class was specified, check for JAXP + // otherwise we default to Xerces. + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(namespaces); + factory.setValidating(validation); + try { + SAXParser saxParser = factory.newSAXParser(); + return saxParser.getParser(); + } catch (ParserConfigurationException pcx) { + LOG.error(Messages.format("conf.configurationError", pcx)); + } catch (org.xml.sax.SAXException sx) { + LOG.error(Messages.format("conf.configurationError", sx)); + } + + } + + if ((prop == null) || (prop.length() == 0) || (prop.equalsIgnoreCase("xerces"))) { + prop = "org.apache.xerces.parsers.SAXParser"; + } + + // If a parser class was specified, we try to create it and + // complain about creation error. + try { + Class cls; + + cls = Class.forName(prop); + parser = (Parser) cls.newInstance(); + } catch (Exception except) { + throw new RuntimeException(Messages + .format("conf.failedInstantiateParser", prop, except)); + } + + if (parser instanceof XMLReader) { + XMLReader xmlReader = (XMLReader) parser; + new XMLReaderService().setFeaturesOnXmlReader(_config.getProperties(), features, validation, namespaces, xmlReader); + } + + return parser; + + } + + public class XMLReaderService { + /** To set validation feature of XMLReader. */ + private static final String VALIDATION = "http://xml.org/sax/features/validation"; + /** To set namespaces feature of XMLReader. */ + private static final String NAMESPACES = "http://xml.org/sax/features/namespaces"; + + /** + * Sets features on XML reader instance. + * @param properties the Properties to read parser features from + * @param defaultFeatures any default features to use + * @param validation Whether to enable validation or not. + * @param namespaces Whether to enable namespace support for not. + * @param xmlReader The XMLReader instance to configure. + */ + protected void setFeaturesOnXmlReader( + final Properties properties, + final String defaultFeatures, + final boolean validation, + final boolean namespaces, + final XMLReader xmlReader) { + try { + xmlReader.setFeature(VALIDATION, validation); + xmlReader.setFeature(NAMESPACES, namespaces); + String features = properties.getProperty(Property.ParserFeatures, defaultFeatures); + enableFeatures(features, xmlReader); + String featuresToDisable = + Configuration.getDefault().getProperty(Property.ParserFeaturesToDisable, ""); + disableFeatures(featuresToDisable, xmlReader); + } catch (SAXException except) { + LOG.error(Messages.format("conf.configurationError", except)); + } + } + + /** + * Enables selected features on the XMLReader instance. + * @param features Features to enable + * @param xmlReader XMLReader instance to be configured. + * @throws SAXNotRecognizedException If the feature is not recognized by the XMLReader. + * @throws SAXNotSupportedException If the feature is not supported by the XMLReader. + */ + private void enableFeatures(final String features, final XMLReader xmlReader) + throws SAXNotRecognizedException, SAXNotSupportedException { + StringTokenizer token; + if (features != null) { + token = new StringTokenizer(features, ", "); + while (token.hasMoreTokens()) { + xmlReader.setFeature(token.nextToken(), true); + } + } + } + + /** + * Disables selected features on the XMLReader instance. + * @param features Features to disable + * @param xmlReader XMLReader instance to be configured. + * @throws SAXNotRecognizedException If the feature is not recognized by the XMLReader. + * @throws SAXNotSupportedException If the feature is not supported by the XMLReader. + */ + private void disableFeatures(final String features, final XMLReader xmlReader) + throws SAXNotRecognizedException, SAXNotSupportedException { + StringTokenizer token; + if (features != null) { + token = new StringTokenizer(features, ", "); + while (token.hasMoreTokens()) { + xmlReader.setFeature(token.nextToken(), false); + } + } + } + } //-- XmlReaderService + /** + * Returns an XML document parser implementing the requested set of + * features. The feature list is a comma separated list of features that + * parser may or may not support. No errors are generated for unsupported + * features. If the feature list is not null, it overrides the default + * feature list specified in the configuration file, including validation + * and Namespaces. + * + * @return A suitable XML parser + */ + public XMLReader getXMLReader() { + return getXMLReader(null); + + } //-- getXMLReader + + /** + * Returns an XML document parser implementing the requested + * set of features. The feature list is a comma separated list + * of features that parser may or may not support. No errors are + * generated for unsupported features. If the feature list is not + * null, it overrides the default feature list specified in the + * configuration file, including validation and Namespaces. + * + * @return A suitable XML parser + */ + public XMLReader getXMLReader(final String features) { + + String prop; + XMLReader reader = null; + + // -- validation? + prop = _config.getProperties().getProperty(Property.ParserValidation, "false"); + boolean validation = (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")); + + // -- namespaces? + prop = _config.getProperties().getProperty(Property.Namespaces, "false"); + boolean namespaces = (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")); + + + // -- which parser? + prop = _config.getProperties().getProperty(Property.Parser); + if ((prop == null) || (prop.length() == 0)) { + // If no parser class was specified, check for JAXP + // otherwise we default to Xerces. + SAXParserFactory factory = SAXParserFactory.newInstance(); + factory.setNamespaceAware(namespaces); + factory.setValidating(validation); + try { + SAXParser saxParser = factory.newSAXParser(); + reader = saxParser.getXMLReader(); + } catch (ParserConfigurationException pcx) { + LOG.error(Messages.format("conf.configurationError", pcx)); + } catch (org.xml.sax.SAXException sx) { + LOG.error(Messages.format("conf.configurationError", sx)); + } + + } + + if (reader == null) { + if ((prop == null) + || (prop.length() == 0) + || (prop.equalsIgnoreCase("xerces"))) { + prop = "org.apache.xerces.parsers.SAXParser"; + } + + + // If a parser class was specified, we try to create it and + // complain about creation error. + try { + Class cls; + + cls = Class.forName(prop); + reader = (XMLReader) cls.newInstance(); + } catch (Exception e) { + throw new RuntimeException( + Messages.format("conf.failedInstantiateParser", prop, e)); + } + } + + new XMLReaderService().setFeaturesOnXmlReader(_config.getProperties(), features, + validation, namespaces, reader); + + return reader; + + } //-- getXMLReader + + + /** + * Returns the NodeType to use for Java primitives. + * A null value will be returned if no NodeType was specified, + * indicating the default NodeType should be used. + * + * @return the NodeType assigned to Java primitives, or null + * if no NodeType was specified. + **/ + public NodeType getPrimitiveNodeType() { + + if (_values._primitiveNodeType != null) { + return _values._primitiveNodeType; + } + + String prop = _config.getProperty(Property.PrimitiveNodeType, null); + if (prop == null) { + return null; + } + _values._primitiveNodeType = NodeType.getNodeType(prop); + return _values._primitiveNodeType; + } //-- getPrimitiveNodeType + + /** + * Returns a new instance of the specified Regular Expression + * Evaluator, or null if no validator was specified. + * + * @return the regular expression evaluator, + * + **/ + public RegExpEvaluator getRegExpEvaluator() { + + String prop = _config.getProperties().getProperty(Property.RegExp); + + RegExpEvaluator regex = null; + + if (prop == null) { + return null; + } + try { + if (_values._regExpEvalClass == null) { + _values._regExpEvalClass = Class.forName(prop); + } + regex = (RegExpEvaluator) _values._regExpEvalClass.newInstance(); + } catch (Exception e) { + throw new RuntimeException(Messages.format("conf.failedInstantiateRegExp", prop, e)); + } + + return regex; + } // -- getRegExpEvaluator + + /** + * Returns a default serializer for producing an XML document. The caller + * can specify an alternative output format, may reuse this serializer + * across several streams, and may serialize both DOM and SAX events. If + * such control is not required, it is recommended to call one of the other + * two methods. + * + * @return A suitable serializer + */ + public Serializer getSerializer() { + Serializer serializer = getSerializerFactory(_config.getProperties()).getSerializer(); + serializer.setOutputFormat(getOutputFormat()); + return serializer; + } + + /** + * Returns the default OutputFormat for use with a Serializer. + * + * @return the default OutputFormat + **/ + public OutputFormat getOutputFormat() { + + boolean indent = false; + + String prop = _config.getProperty(Property.Indent, ""); + + //-- get default indentation + indent = (prop.equalsIgnoreCase(TRUE_VALUE) || prop.equalsIgnoreCase(ON_VALUE)); + + OutputFormat format = getSerializerFactory(_config.getProperties()).getOutputFormat(); + format.setMethod(OutputFormat.XML); + format.setIndenting(indent); + + // There is a bad interaction between the indentation and the + // setPreserveSpace option. The indentated output is strangely indented. + if (!indent) { + format.setPreserveSpace(true); + } + + return format; + } //-- getOutputFormat + + /** + * Returns the currently configured XMLSerializerFactory instance. + * @param props Property set to use. + * @return XMLSerializerFactory to use by Castor + */ + protected XMLSerializerFactory getSerializerFactory(final Properties props) { + XMLSerializerFactory serializerFactory; + String serializerFactoryName = + props.getProperty(Property.SERIALIZER_FACTORY, Property.DEFAULT_SERIALIZER_FACTORY); + + try { + serializerFactory = (XMLSerializerFactory) + Class.forName(serializerFactoryName).newInstance(); + } catch (Exception except) { + throw new RuntimeException( + Messages.format("conf.failedInstantiateSerializerFactory", + serializerFactoryName, except)); + } + return serializerFactory; + } + + /** + * Returns a default serializer for producing an XML document to + * the designated output stream using the default serialization + * format. + * + * @param output The output stream + * @return A suitable serializer + */ + public DocumentHandler getSerializer(final OutputStream output) throws IOException { + Serializer serializer; + DocumentHandler docHandler; + + serializer = getSerializer(); + serializer.setOutputByteStream(output); + docHandler = serializer.asDocumentHandler(); + if (docHandler == null) { + throw new RuntimeException(Messages.format("conf.serializerNotSaxCapable", serializer + .getClass().getName())); + } + return docHandler; + } + + + /** + * Returns a default serializer for producing an XML document to the + * designated output stream using the default serialization format. + * + * @param output + * The output stream + * @return A suitable serializer + */ + public DocumentHandler getSerializer(final Writer output) throws IOException { + Serializer serializer; + DocumentHandler docHandler; + + serializer = getSerializer(); + serializer.setOutputCharStream(output); + docHandler = serializer.asDocumentHandler(); + if (docHandler == null) { + throw new RuntimeException(Messages.format("conf.serializerNotSaxCapable", serializer + .getClass().getName())); + } + return docHandler; + } + + /** + * This class exists to split those attributes required for XMLContext itself + * from those that XMLContext manages. + */ + private class ContextValues { + /** The primitive NodeType to use (Element or Attribute). */ + public NodeType _primitiveNodeType = null; + + /** The Java naming to use. */ + public JavaNaming _javaNaming = null; + + /** The XML naming to use. */ + public XMLNaming _xmlNaming = null; + + /** The class to use for regular expression evaluation. */ + public Class _regExpEvalClass = null; + } } - Index: src/main/java/org/exolab/castor/xml/Introspector.java =================================================================== --- src/main/java/org/exolab/castor/xml/Introspector.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/Introspector.java (working copy) @@ -227,6 +227,8 @@ */ private JavaNaming _javaNaming; + private XMLContext _xmlContext; + /** * Creates a new instance of the Introspector. */ @@ -246,17 +248,21 @@ } //-- Introspector private void init() { + _xmlContext = new XMLContext(); + _javaNaming = _xmlContext.getJavaNaming(); + _naming = _xmlContext.getXMLNaming(); + setPrimitiveNodeType(_xmlContext.getPrimitiveNodeType()); LocalConfiguration config = LocalConfiguration.getInstance(); - if (_defaultNaming == null) { - _defaultNaming = config.getXMLNaming(_classLoader); - } - _naming = _defaultNaming; - _javaNaming = config.getJavaNaming(); +// if (_defaultNaming == null) { +// _defaultNaming = config.getXMLNaming(_classLoader); +// } +// _naming = _defaultNaming; +// _javaNaming = config.getJavaNaming(); +// +// setPrimitiveNodeType(config.getPrimitiveNodeType()); - setPrimitiveNodeType(config.getPrimitiveNodeType()); - //-- wrap collections in a container element? String wrap = config.getProperty(WRAP_COLLECTIONS_PROPERTY, null); if (wrap != null) { Index: src/main/java/org/exolab/castor/xml/Unmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/Unmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/Unmarshaller.java (working copy) @@ -184,7 +184,10 @@ /** * An optional factory for unmarshalling objects */ - private ObjectFactory _objectFactory; + private ObjectFactory _objectFactory; + + /** The Castor XML context to use are unmarshalling. */ + private XMLContext _xmlContext = new XMLContext(); //----------------/ //- Constructors -/ @@ -683,7 +686,7 @@ //-- First try XMLReader try { - reader = _config.getXMLReader(); + reader = _xmlContext.getXMLReader(); if (entityResolver != null) reader.setEntityResolver(entityResolver); } catch(RuntimeException rx) { @@ -691,7 +694,7 @@ } if (reader == null) { - parser = _config.getParser(); + parser = _xmlContext.getParser(); if (parser == null) throw new MarshalException("Unable to create SAX Parser."); if (entityResolver != null) @@ -899,6 +902,10 @@ public void setProperty(final String name, final String value) { _config.getProperties().setProperty(name, value); } + + public void setXMLContext(final XMLContext xmlContext) { + _xmlContext = xmlContext; + } } //-- Unmarshaller Index: src/main/java/org/exolab/castor/xml/ValidationContext.java =================================================================== --- src/main/java/org/exolab/castor/xml/ValidationContext.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/ValidationContext.java (working copy) @@ -65,6 +65,8 @@ /** Logger for debugging and error information. */ private static final Log LOG = LogFactory.getLog(ValidationContext.class); + /** The Castor XML context - mother of all dwelling. */ + private XMLContext _xmlContext = null; /** The Castor configuration. */ private Configuration _config = null; /** A flag to indicate fail-fast validation. When true, the first error @@ -89,10 +91,22 @@ super(); } + public XMLContext getXMLContext() { + if (_xmlContext == null) { + _xmlContext = new XMLContext(); + } + return _xmlContext; + } + + public void setXMLContext(final XMLContext xmlContext) { + _xmlContext = xmlContext; + } + /** * Returns the Configuration to use during validation. * * @return the Configuration to use. Will never be null. + * @deprecated */ public Configuration getConfiguration() { if (_config == null) { @@ -129,6 +143,7 @@ * Sets the Configuration used during validation. * * @param config the Configuration to use + * @deprecated */ public void setConfiguration(final Configuration config) { _config = config; Index: src/main/java/org/exolab/castor/xml/schema/reader/RedefineUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/RedefineUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/RedefineUnmarshaller.java (working copy) @@ -92,16 +92,19 @@ * The XML Schema imported */ - public RedefineUnmarshaller - (Schema schema, AttributeSet atts, Resolver resolver, URIResolver uriResolver, Locator locator, SchemaUnmarshallerState state) - throws XMLException - { - super(); + public RedefineUnmarshaller( + final ComponentReader parent, + final Schema schema, + final AttributeSet atts, + final URIResolver uriResolver, + final Locator locator, + final SchemaUnmarshallerState state) + throws XMLException { + super(parent); if (schema == null) { String err = SchemaNames.REDEFINE + " must be used with an existing parent XML Schema."; throw new SchemaException(err); } - setResolver(resolver); setURIResolver(uriResolver); URILocation uri = null; @@ -177,14 +180,14 @@ //-- Parser Schema Parser parser = null; try { - parser = state.getConfiguration().getParser(); + parser = getXMLContext().getParser(); } catch(RuntimeException rte) {} if (parser == null) { throw new SchemaException("Error failed to create parser for import"); } //-- Create Schema object and setup unmarshaller - SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(state); + SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(this, state); schemaUnmarshaller.setURIResolver(getURIResolver()); schemaUnmarshaller.setSchema(importedSchema); Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller); @@ -270,24 +273,24 @@ //-- if (name.equals(SchemaNames.ANNOTATION)) { - _unmarshaller = new AnnotationUnmarshaller(atts); + _unmarshaller = new AnnotationUnmarshaller(this, atts); } //-- else if (name.equals(SchemaNames.ATTRIBUTE_GROUP)) { - _unmarshaller = new AttributeGroupUnmarshaller(_schema, atts); + _unmarshaller = new AttributeGroupUnmarshaller(this, _schema, atts); } //-- else if (name.equals(SchemaNames.COMPLEX_TYPE)) { _unmarshaller - = new ComplexTypeUnmarshaller(_schema, atts, getResolver()); + = new ComplexTypeUnmarshaller(this, _schema, atts); } //-- else if (name.equals(SchemaNames.SIMPLE_TYPE)) { - _unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + _unmarshaller = new SimpleTypeUnmarshaller(this, _schema, atts); } //-- else if (name.equals(SchemaNames.GROUP)) { - _unmarshaller = new ModelGroupUnmarshaller(_schema, atts, getResolver()); + _unmarshaller = new ModelGroupUnmarshaller(this, _schema, atts); } else { //--Exception here Index: src/main/java/org/exolab/castor/xml/schema/reader/ElementUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/ElementUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/ElementUnmarshaller.java (working copy) @@ -107,17 +107,17 @@ //----------------/ /** - * Creates a new ElementUnmarshaller + * Creates a new ElementUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param schema the Schema to which the Element belongs * @param atts the AttributeList - * @param resolver the resolver being used for reference resolving **/ - public ElementUnmarshaller - (final Schema schema, final AttributeSet atts, final Resolver resolver) - throws XMLException - { - super(); - setResolver(resolver); + public ElementUnmarshaller( + final ComponentReader parent, + final Schema schema, + final AttributeSet atts) + throws XMLException { + super(parent); this._schema = schema; @@ -237,7 +237,7 @@ } else if (minOccurs > 1) _element.setMaxOccurs(minOccurs); - charUnmarshaller = new CharacterUnmarshaller(); + charUnmarshaller = new CharacterUnmarshaller(this); } //-- ElementUnmarshaller //-----------/ @@ -305,7 +305,7 @@ "element definitions."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else if (SchemaNames.COMPLEX_TYPE.equals(name)) { @@ -326,7 +326,7 @@ foundComplexType = true; unmarshaller - = new ComplexTypeUnmarshaller(_schema, atts, getResolver()); + = new ComplexTypeUnmarshaller(this, _schema, atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { @@ -345,20 +345,17 @@ "'keyref' and 'unique' elements."); foundSimpleType = true; - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(this, _schema, atts); } else if (SchemaNames.KEY.equals(name) || SchemaNames.KEYREF.equals(name) || SchemaNames.UNIQUE.equals(name)) { foundIdentityConstraint = true; - unmarshaller = new IdentityConstraintUnmarshaller(name, atts); + unmarshaller = new IdentityConstraintUnmarshaller(this, name, atts); } else illegalElement(name); - unmarshaller.setResolver(getResolver()); - unmarshaller.setDocumentLocator(getDocumentLocator()); - } //-- startElement /** Index: src/main/java/org/exolab/castor/xml/schema/reader/WildcardUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/WildcardUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/WildcardUnmarshaller.java (working copy) @@ -106,42 +106,49 @@ //----------------/ //- Constructors -/ //----------------/ - public WildcardUnmarshaller - (ComplexType complexType, Schema schema, String element, AttributeSet atts, Resolver resolver) - { - super(); - _wildcard = new Wildcard(complexType); - init(schema, element, atts, resolver); + public WildcardUnmarshaller( + final ComponentReader parent, + final ComplexType complexType, + final Schema schema, + final String element, + final AttributeSet atts) { + this(parent, schema, element, atts, new Wildcard(complexType)); } - public WildcardUnmarshaller - (Group group, Schema schema, String element, AttributeSet atts, Resolver resolver) - { - super(); - _wildcard = new Wildcard(group); - init(schema, element, atts, resolver); + public WildcardUnmarshaller( + final ComponentReader parent, + final Group group, + final Schema schema, + final String element, + final AttributeSet atts) { + this(parent, schema, element, atts, new Wildcard(group)); } - public WildcardUnmarshaller - (AttributeGroup attGroup, Schema schema, String element, AttributeSet atts, Resolver resolver) - { - super(); - _wildcard = new Wildcard(attGroup); - init(schema, element, atts, resolver); + public WildcardUnmarshaller( + final ComponentReader parent, + final AttributeGroup attGroup, + final Schema schema, + final String element, + final AttributeSet atts) { + this(parent, schema, element, atts, new Wildcard(attGroup)); } /** - * Creates a new WildcardUnmarshaller + * Creates a new WildcardUnmarshaller. + * @param parent the parent ComponentReader to get the settings from * @param schema the Schema to which the Wildcard belongs * @param element the name of the element * @param atts the AttributeList - * @param resolver the resolver being used for reference resolving **/ - public void init - (Schema schema, String element, AttributeSet atts, Resolver resolver) - { - setResolver(resolver); + private WildcardUnmarshaller( + final ComponentReader parent, + final Schema schema, + final String element, + final AttributeSet atts, + final Wildcard wildcard) { + super(parent); + _wildcard = wildcard; this._schema = schema; this._element = element; @@ -278,7 +285,7 @@ } //-- if (SchemaNames.ANNOTATION.equals(name)) { - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else { Index: src/main/java/org/exolab/castor/xml/schema/reader/AppInfoUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/AppInfoUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/AppInfoUnmarshaller.java (working copy) @@ -84,13 +84,13 @@ //----------------/ /** - * Creates a new AppInfoUnmarshaller + * Creates a new AppInfoUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param atts the AttributeList **/ - public AppInfoUnmarshaller(AttributeSet atts) - throws XMLException - { - super(); + public AppInfoUnmarshaller(final ComponentReader parent, final AttributeSet atts) + throws XMLException { + super(parent); _appInfo = new AppInfo(); _appInfo.setSource(atts.getValue(SchemaNames.SOURCE_ATTR)); Index: src/main/java/org/exolab/castor/xml/schema/reader/CharacterUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/CharacterUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/CharacterUnmarshaller.java (working copy) @@ -58,11 +58,13 @@ private StringBuffer sb = null; private String currentName = null; + /** - * Creates a new StringUnmarshaller + * Creates a new StringUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from **/ - public CharacterUnmarshaller() { - super(); + public CharacterUnmarshaller(final ComponentReader parent) { + super(parent); sb = new StringBuffer(); } //-- CharacterUnmarshaller Index: src/main/java/org/exolab/castor/xml/schema/reader/SchemaUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/SchemaUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/SchemaUnmarshaller.java (working copy) @@ -46,18 +46,33 @@ package org.exolab.castor.xml.schema.reader; //-- imported classes and packages -import org.exolab.castor.xml.*; -import org.exolab.castor.xml.util.AttributeSetImpl; -import org.exolab.castor.xml.schema.*; -import org.exolab.castor.net.URIResolver; -import org.exolab.castor.net.util.URIResolverImpl; - +import java.io.InputStream; import java.util.Enumeration; import java.util.HashMap; import java.util.Properties; import java.util.StringTokenizer; -import java.io.InputStream; +import org.exolab.castor.net.URIResolver; +import org.exolab.castor.net.util.URIResolverImpl; +import org.exolab.castor.xml.AttributeSet; +import org.exolab.castor.xml.Namespaces; +import org.exolab.castor.xml.XMLContext; +import org.exolab.castor.xml.XMLException; +import org.exolab.castor.xml.schema.Annotation; +import org.exolab.castor.xml.schema.AttributeDecl; +import org.exolab.castor.xml.schema.AttributeGroupDecl; +import org.exolab.castor.xml.schema.ComplexType; +import org.exolab.castor.xml.schema.ElementDecl; +import org.exolab.castor.xml.schema.Form; +import org.exolab.castor.xml.schema.ModelGroup; +import org.exolab.castor.xml.schema.RedefineSchema; +import org.exolab.castor.xml.schema.Resolver; +import org.exolab.castor.xml.schema.Schema; +import org.exolab.castor.xml.schema.SchemaException; +import org.exolab.castor.xml.schema.SchemaNames; +import org.exolab.castor.xml.schema.ScopableResolver; +import org.exolab.castor.xml.schema.SimpleType; +import org.exolab.castor.xml.util.AttributeSetImpl; /** * @author Keith Visco @@ -104,7 +119,7 @@ /** * The ID Resolver **/ - Resolver _resolver = null; +// Resolver _resolver = null; Schema _schema = null; @@ -125,49 +140,87 @@ //- Constructors -/ //----------------/ - public SchemaUnmarshaller() - throws XMLException - { - this(null, null, null); + public SchemaUnmarshaller(final XMLContext xmlContext) + throws XMLException { + this(xmlContext, null, null, null); foundSchemaDef = false; } //-- SchemaUnmarshaller - public SchemaUnmarshaller(SchemaUnmarshallerState state) - throws XMLException - { - this(null, null, null); + public SchemaUnmarshaller( + final XMLContext xmlContext, + final SchemaUnmarshallerState state) + throws XMLException { + this(xmlContext, null, null, null); _state = state; foundSchemaDef = false; } //-- SchemaUnmarshaller - public SchemaUnmarshaller(boolean include, SchemaUnmarshallerState state, URIResolver uriResolver) - throws XMLException - { - this(null, null, uriResolver); + /** + * Called from ImportUnmarshaller and RedefineUnmarshaller. + * @param parent + * @param state + * @throws XMLException + */ + public SchemaUnmarshaller( + final ComponentReader parent, + final SchemaUnmarshallerState state) + throws XMLException { + this(null, parent, null, null); _state = state; + foundSchemaDef = false; + } //-- SchemaUnmarshaller + + /** + * Called from IncludeUnmarshaller. + * @param parent + * @param include + * @param state + * @param uriResolver + * @throws XMLException + */ + public SchemaUnmarshaller( + final ComponentReader parent, + final boolean include, + final SchemaUnmarshallerState state, + final URIResolver uriResolver) + throws XMLException { + + this(null, parent, null, uriResolver); + _state = state; _include = include; foundSchemaDef = false; } //--backward compatibility - public SchemaUnmarshaller(AttributeSet atts, Resolver resolver) - throws XMLException - { - this(atts, resolver, null); + public SchemaUnmarshaller( + final ComponentReader parent, + final AttributeSet atts) + throws XMLException { + this(null, parent, atts, null); } - public SchemaUnmarshaller(AttributeSet atts, Resolver resolver, URIResolver uriResolver) - throws XMLException - { - super(); + private SchemaUnmarshaller( + final XMLContext xmlContext, + final ComponentReader parent, + final AttributeSet atts, + final URIResolver uriResolver) + throws XMLException { + super(parent); + if (xmlContext != null) { + setXMLContext(xmlContext); + } _schema = new Schema(); //--initialize the schema to ensure that the default namespace //--is not set _schema.removeNamespace(""); - setResolver(resolver); - if (uriResolver == null) - uriResolver = new URIResolverImpl(); - setURIResolver(uriResolver); + if (getResolver() == null) { + setResolver(new ScopableResolver()); + } + if (uriResolver == null) { + setURIResolver(new URIResolverImpl()); + } else { + setURIResolver(uriResolver); + } foundSchemaDef = true; _state = new SchemaUnmarshallerState(); init(atts); @@ -385,11 +438,11 @@ } //-- handleRemapping - public void setResolver(Resolver resolver) { - if (resolver == null) resolver = new ScopableResolver(); - super.setResolver(resolver); - _resolver = resolver; - } //-- setResolver +// public void setResolver(Resolver resolver) { +// if (resolver == null) resolver = new ScopableResolver(); +// super.setResolver(resolver); +// _resolver = resolver; +// } //-- setResolver /** @@ -481,48 +534,48 @@ //-- if (name.equals(SchemaNames.ANNOTATION)) { - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } //-- else if (name.equals(SchemaNames.ATTRIBUTE)) { - unmarshaller = new AttributeUnmarshaller(_schema,atts, getResolver()); + unmarshaller = new AttributeUnmarshaller(this, _schema,atts); } //-- else if (name.equals(SchemaNames.ATTRIBUTE_GROUP)) { - unmarshaller = new AttributeGroupUnmarshaller(_schema, atts); + unmarshaller = new AttributeGroupUnmarshaller(this, _schema, atts); } //-- else if (name.equals(SchemaNames.COMPLEX_TYPE)) { unmarshaller - = new ComplexTypeUnmarshaller(_schema, atts, _resolver); + = new ComplexTypeUnmarshaller(this, _schema, atts); } //-- else if (name.equals(SchemaNames.ELEMENT)) { unmarshaller - = new ElementUnmarshaller(_schema, atts, _resolver); + = new ElementUnmarshaller(this, _schema, atts); } //-- else if (name.equals(SchemaNames.SIMPLE_TYPE)) { - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(this, _schema, atts); } //-- else if (name.equals(SchemaNames.GROUP)) { - unmarshaller = new ModelGroupUnmarshaller(_schema, atts, _resolver); + unmarshaller = new ModelGroupUnmarshaller(this, _schema, atts); } //-- else if (name.equals(SchemaNames.INCLUDE)) { unmarshaller - = new IncludeUnmarshaller(_schema, atts, _resolver, getURIResolver(),getDocumentLocator(), _state); + = new IncludeUnmarshaller(this, _schema, atts, getURIResolver(),getDocumentLocator(), _state); } //-- else if (name.equals(SchemaNames.IMPORT)) { unmarshaller - = new ImportUnmarshaller(_schema, atts, _resolver, getURIResolver(), getDocumentLocator(), _state); + = new ImportUnmarshaller(this, _schema, atts, getURIResolver(), getDocumentLocator(), _state); } //-- else if (name.equals(SchemaNames.REDEFINE)) { unmarshaller - = new RedefineUnmarshaller(_schema, atts, _resolver, getURIResolver(), getDocumentLocator(), _state); + = new RedefineUnmarshaller(this, _schema, atts, getURIResolver(), getDocumentLocator(), _state); } else { //-- we should throw a new Exception here @@ -532,7 +585,7 @@ System.out.print(name); System.out.print("> elements are either currently unsupported "); System.out.println("or non-valid schema elements."); - unmarshaller = new UnknownUnmarshaller(name); + unmarshaller = new UnknownUnmarshaller(this, name); } unmarshaller.setDocumentLocator(getDocumentLocator()); @@ -626,7 +679,7 @@ complexType = ((ComplexTypeUnmarshaller)unmarshaller).getComplexType(); _schema.addComplexType(complexType); if (complexType.getName() != null) { - _resolver.addResolvable(complexType.getReferenceId(), complexType); + getResolver().addResolvable(complexType.getReferenceId(), complexType); } else { System.out.println("warning: top-level complexType with no name."); @@ -637,7 +690,7 @@ SimpleType simpleType = null; simpleType = ((SimpleTypeUnmarshaller)unmarshaller).getSimpleType(); _schema.addSimpleType(simpleType); - _resolver.addResolvable(simpleType.getReferenceId(), simpleType); + getResolver().addResolvable(simpleType.getReferenceId(), simpleType); } //-- else if (name.equals(SchemaNames.ELEMENT)) { Index: src/main/java/org/exolab/castor/xml/schema/reader/SchemaUnmarshallerState.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/SchemaUnmarshallerState.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/SchemaUnmarshallerState.java (working copy) @@ -60,8 +60,9 @@ */ class SchemaUnmarshallerState { - - private Configuration _config = null; + // TODO: Joachim 2007-08-15 the config shouldn't be in this place + /** @deprecated */ +// private Configuration _config = null; private Hashtable _processed = null; @@ -117,12 +118,12 @@ * * @see #setConfiguration */ - Configuration getConfiguration() { - if (_config == null) { - _config = LocalConfiguration.getInstance(); - } - return _config; - } //-- setConfiguraiton +// Configuration getConfiguration() { +// if (_config == null) { +// _config = LocalConfiguration.getInstance(); +// } +// return _config; +// } //-- setConfiguraiton /** * Returns the schema corresponding to the given schemaLocation @@ -140,8 +141,8 @@ * * @param config the Configuration to set */ - void setConfiguration(Configuration config) { - _config = config; - } //-- setConfiguraiton +// void setConfiguration(Configuration config) { +// _config = config; +// } //-- setConfiguraiton } //-- SchemaUnmarshallerState Index: src/main/java/org/exolab/castor/xml/schema/reader/ComplexContentUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/ComplexContentUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/ComplexContentUnmarshaller.java (working copy) @@ -90,27 +90,31 @@ //----------------/ /** - * Creates a new ComplexContentUnmarshaller + * Creates a new ComplexContentUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param complexType the complexType we are unmarshalling * @param atts the AttributeList - * @param resolver the resolver being used for reference resolving **/ - public ComplexContentUnmarshaller - (ComplexType complexType, AttributeSet atts, Resolver resolver) - throws XMLException - { + public ComplexContentUnmarshaller( + final ComponentReader parent, + final ComplexType complexType, + final AttributeSet atts) + throws XMLException { + super(parent); _complexType = complexType; - //-- read contentType + //-- read contentType String content = atts.getValue(SchemaNames.MIXED); - if (content != null) { - if (content.equals("true")) - _complexType.setContentType(ContentType.valueOf("mixed")); - if (content.equals("false")) - _complexType.setContentType(ContentType.valueOf("elementOnly")); - } + if (content != null) { + if (content.equals("true")) { + _complexType.setContentType(ContentType.valueOf("mixed")); + } + if (content.equals("false")) { + _complexType.setContentType(ContentType.valueOf("elementOnly")); + } + } } //-- ComplexContentUnmarshaller @@ -175,7 +179,7 @@ foundExtension = true; ExtensionUnmarshaller extension = - new ExtensionUnmarshaller(_complexType, atts, getResolver()); + new ExtensionUnmarshaller(this, _complexType, atts); unmarshaller = extension; } //-- restriction @@ -192,7 +196,7 @@ foundRestriction = true; unmarshaller= - new ComplexContentRestrictionUnmarshaller(_complexType, atts, getResolver()); + new ComplexContentRestrictionUnmarshaller(this, _complexType, atts); } //-- annotation else if (name.equals(SchemaNames.ANNOTATION)) { @@ -205,10 +209,11 @@ "of a 'complexContent' element."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else illegalElement(name); + unmarshaller.setXMLContext(getXMLContext()); unmarshaller.setDocumentLocator(getDocumentLocator()); } //-- startElement Index: src/main/java/org/exolab/castor/xml/schema/reader/AttributeUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/AttributeUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/AttributeUnmarshaller.java (working copy) @@ -95,15 +95,14 @@ //- Constructors -/ //----------------/ - public AttributeUnmarshaller - (Schema schema, AttributeSet atts, Resolver resolver) + public AttributeUnmarshaller( + final ComponentReader parent, + final Schema schema, + final AttributeSet atts) { - super(); + super(parent); this._schema = schema; - setResolver(resolver); - - _attribute = new AttributeDecl(schema); //--@ref @@ -232,7 +231,7 @@ "an attribute declaration."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { if (foundSimpleType) @@ -240,7 +239,7 @@ "an attribute declaration."); foundSimpleType = true; - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(this, _schema, atts); } else { illegalElement(name); Index: src/main/java/org/exolab/castor/xml/schema/reader/ComplexTypeUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/ComplexTypeUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/ComplexTypeUnmarshaller.java (working copy) @@ -108,22 +108,23 @@ //----------------/ /** - * Creates a new ComplexTypeUnmarshaller + * Creates a new ComplexTypeUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param schema the Schema to which the ComplexType belongs * @param atts the AttributeList - * @param resolver the resolver being used for reference resolving **/ - public ComplexTypeUnmarshaller - (Schema schema, AttributeSet atts, Resolver resolver) - throws XMLException - { - super(); - setResolver(resolver); + public ComplexTypeUnmarshaller( + final ComponentReader parent, + final Schema schema, + final AttributeSet atts) + throws XMLException { + super(parent); + this._schema = schema; _complexType = schema.createComplexType(); - _complexType.useResolver(resolver); + _complexType.useResolver(getResolver()); //-- handle attributes String attValue = null; @@ -250,7 +251,7 @@ foundAnyAttribute = true; allowAnnotation = true; unmarshaller - = new WildcardUnmarshaller(_complexType, _schema, name, atts, getResolver()); + = new WildcardUnmarshaller(this, _complexType, _schema, name, atts); } //-- attribute declarations @@ -267,7 +268,7 @@ foundAttributes = true; allowAnnotation = false; unmarshaller - = new AttributeUnmarshaller(_schema, atts, getResolver()); + = new AttributeUnmarshaller(this, _schema, atts); } //-- attribute group declarations else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) { @@ -291,7 +292,7 @@ foundAttributes = true; allowAnnotation = false; unmarshaller - = new AttributeGroupUnmarshaller(_schema, atts); + = new AttributeGroupUnmarshaller(this, _schema, atts); } //-- simpleContent else if (SchemaNames.SIMPLE_CONTENT.equals(name)) { @@ -314,7 +315,7 @@ allowAnnotation = false; _complexType.setSimpleContent(true); unmarshaller - = new SimpleContentUnmarshaller(_complexType, atts, getResolver()); + = new SimpleContentUnmarshaller(this, _complexType, atts); } //-- complexContent else if (SchemaNames.COMPLEX_CONTENT.equals(name)) { @@ -338,7 +339,7 @@ _complexType.setComplexContent(true); unmarshaller - = new ComplexContentUnmarshaller(_complexType, atts, getResolver()); + = new ComplexContentUnmarshaller(this, _complexType, atts); } //-- else if ( name.equals(SchemaNames.GROUP) ) @@ -360,7 +361,7 @@ foundModelGroup = true; allowAnnotation = false; unmarshaller - = new ModelGroupUnmarshaller(_schema, atts, getResolver()); + = new ModelGroupUnmarshaller(this, _schema, atts); } //-- ModelGroup declarations (choice, all, sequence) else if ( (SchemaNames.isGroupName(name)) && (name != SchemaNames.GROUP) ) @@ -383,11 +384,11 @@ foundModelGroup = true; allowAnnotation = false; unmarshaller - = new GroupUnmarshaller(_schema, name, atts, getResolver()); + = new GroupUnmarshaller(this, _schema, name, atts); } else if (name.equals(SchemaNames.ANNOTATION)) { if (allowAnnotation) { - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); allowAnnotation = false; foundAnnotation = true; } @@ -402,7 +403,6 @@ } else illegalElement(name); - unmarshaller.setDocumentLocator(getDocumentLocator()); } //-- startElement /** Index: src/main/java/org/exolab/castor/xml/schema/reader/ImportUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/ImportUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/ImportUnmarshaller.java (working copy) @@ -55,12 +55,15 @@ { - public ImportUnmarshaller - (Schema schema, AttributeSet atts, Resolver resolver, URIResolver uriResolver, Locator locator, SchemaUnmarshallerState state) - throws XMLException - { - super(); - setResolver(resolver); + public ImportUnmarshaller( + final ComponentReader parent, + final Schema schema, + final AttributeSet atts, + final URIResolver uriResolver, + final Locator locator, + final SchemaUnmarshallerState state) + throws XMLException { + super(parent); setURIResolver(uriResolver); URILocation uri = null; @@ -177,14 +180,14 @@ //-- Parser Schema Parser parser = null; try { - parser = state.getConfiguration().getParser(); + parser = getXMLContext().getParser(); } catch(RuntimeException rte) {} if (parser == null) { throw new SchemaException("Error failed to create parser for import"); } //-- Create Schema object and setup unmarshaller - SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(state); + SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(this, state); schemaUnmarshaller.setURIResolver(getURIResolver()); schemaUnmarshaller.setSchema(importedSchema); Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller); Index: src/main/java/org/exolab/castor/xml/schema/reader/AnnotationUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/AnnotationUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/AnnotationUnmarshaller.java (working copy) @@ -86,13 +86,14 @@ //----------------/ /** - * Creates a new AnnotationUnmarshaller + * Creates a new AnnotationUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param atts the AttributeList **/ - public AnnotationUnmarshaller (AttributeSet atts) + public AnnotationUnmarshaller (final ComponentReader parent, final AttributeSet atts) throws XMLException { - super(); + super(parent); _annotation = new Annotation(); @@ -156,10 +157,10 @@ } if (SchemaNames.APPINFO.equals(name)) { - unmarshaller = new AppInfoUnmarshaller(atts); + unmarshaller = new AppInfoUnmarshaller(this, atts); } else if (SchemaNames.DOCUMENTATION.equals(name)) { - unmarshaller = new DocumentationUnmarshaller(atts); + unmarshaller = new DocumentationUnmarshaller(this, atts); } else illegalElement(name); Index: src/main/java/org/exolab/castor/xml/schema/reader/ExtensionUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/ExtensionUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/ExtensionUnmarshaller.java (working copy) @@ -102,19 +102,18 @@ //----------------/ /** - * Creates a new ExtensionUnmarshaller + * Creates a new ExtensionUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param complexType the ComplexType being unmarshalled * @param atts the AttributeList - * @param resolver the resolver being used for reference resolving **/ - public ExtensionUnmarshaller - (ComplexType complexType, AttributeSet atts, Resolver resolver) - throws XMLException - { - super(); + public ExtensionUnmarshaller ( + final ComponentReader parent, + final ComplexType complexType, + final AttributeSet atts) + throws XMLException { + super(parent); - setResolver(resolver); - _complexType = complexType; _schema = complexType.getSchema(); @@ -209,14 +208,14 @@ //-- if (SchemaNames.ANY_ATTRIBUTE.equals(name)) { unmarshaller - = new WildcardUnmarshaller(_complexType, _schema, name, atts, getResolver()); + = new WildcardUnmarshaller(this, _complexType, _schema, name, atts); } //-- attribute declarations else if (SchemaNames.ATTRIBUTE.equals(name)) { foundAttributes = true; unmarshaller - = new AttributeUnmarshaller(_schema, atts, getResolver()); + = new AttributeUnmarshaller(this, _schema, atts); } //-- attribute group declarations else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) { @@ -232,7 +231,7 @@ foundAttributes = true; unmarshaller - = new AttributeGroupUnmarshaller(_schema, atts); + = new AttributeGroupUnmarshaller(this, _schema, atts); } //-- else if ( name.equals(SchemaNames.GROUP) ) @@ -247,7 +246,7 @@ foundModelGroup = true; unmarshaller - = new ModelGroupUnmarshaller(_schema, atts, getResolver()); + = new ModelGroupUnmarshaller(this, _schema, atts); } else if (SchemaNames.isGroupName(name) && (name != SchemaNames.GROUP) ) { if (foundAttributes) @@ -265,7 +264,7 @@ foundModelGroup = true; unmarshaller - = new GroupUnmarshaller(_schema, name, atts, getResolver()); + = new GroupUnmarshaller(this, _schema, name, atts); } //-- element declarations else if (SchemaNames.ANY_ATTRIBUTE.equals(name)) { @@ -282,11 +281,10 @@ "an 'extension' element."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else illegalElement(name); - unmarshaller.setDocumentLocator(getDocumentLocator()); } //-- startElement /** Index: src/main/java/org/exolab/castor/xml/schema/reader/ModelGroupUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/ModelGroupUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/ModelGroupUnmarshaller.java (working copy) @@ -106,16 +106,17 @@ //----------------/ /** - * Creates a new ModelGroupUnmarshaller + * Creates a new ModelGroupUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param schema the Schema to which the ModelGroup belongs * @param atts the AttributeList - * @param resolver the resolver being used for reference resolving **/ - public ModelGroupUnmarshaller - (Schema schema, AttributeSet atts, Resolver resolver) - { - super(); - setResolver(resolver); + public ModelGroupUnmarshaller( + final ComponentReader parent, + final Schema schema, + final AttributeSet atts) { + super(parent); + this._schema = schema; _group = new ModelGroup(_schema); @@ -248,12 +249,12 @@ "element definitions."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else if (SchemaNames.isGroupName(name)) { unmarshaller - = new GroupUnmarshaller(_schema, name, atts, getResolver()); + = new GroupUnmarshaller(this, _schema, name, atts); } else { StringBuffer err = new StringBuffer("illegal element <"); Index: src/main/java/org/exolab/castor/xml/schema/reader/AttributeGroupUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/AttributeGroupUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/AttributeGroupUnmarshaller.java (working copy) @@ -97,14 +97,15 @@ //----------------/ /** - * Creates a new AttributeGroupUnmarshaller + * Creates a new AttributeGroupUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param schema the Schema to which the AttributeGroup belongs * @param atts the AttributeList **/ - public AttributeGroupUnmarshaller(Schema schema, AttributeSet atts) - throws XMLException - { - super(); + public AttributeGroupUnmarshaller( + final ComponentReader parent, final Schema schema, final AttributeSet atts) + throws XMLException { + super(parent); this._schema = schema; @@ -199,7 +200,7 @@ foundAnyAttribute = true; allowAnnotation = true; unmarshaller - = new WildcardUnmarshaller(_attributeGroup, _schema, name, atts, getResolver()); + = new WildcardUnmarshaller(this, _attributeGroup, _schema, name, atts); } //-- attribute declarations else if (SchemaNames.ATTRIBUTE.equals(name)) { @@ -209,7 +210,7 @@ error("AttributeGroup references may not have children."); unmarshaller - = new AttributeUnmarshaller(_schema, atts, getResolver()); + = new AttributeUnmarshaller(this, _schema, atts); } //-- element declarations else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) { @@ -217,15 +218,14 @@ if (isRef) error("AttributeGroup references may not have children."); unmarshaller - = new AttributeGroupUnmarshaller(_schema, atts); + = new AttributeGroupUnmarshaller(this, _schema, atts); } else if (name.equals(SchemaNames.ANNOTATION)) { if (!allowAnnotation) outOfOrder(name); - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else illegalElement(name); - unmarshaller.setDocumentLocator(getDocumentLocator()); } //-- startElement /** Index: src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeRestrictionUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeRestrictionUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeRestrictionUnmarshaller.java (working copy) @@ -100,14 +100,16 @@ /** * Creates a new RestrictionUnmarshaller + * @param parent the parent ComponentReader to get some configuration settings from * @param typeDefinition the SimpleType being unmarshalled * @param atts the AttributeList **/ - public SimpleTypeRestrictionUnmarshaller - (SimpleTypeDefinition typeDefinition, AttributeSet atts) - throws XMLException - { - super(); + public SimpleTypeRestrictionUnmarshaller( + final ComponentReader parent, + final SimpleTypeDefinition typeDefinition, + final AttributeSet atts) + throws XMLException { + super(parent); _typeDefinition = typeDefinition; _schema = typeDefinition.getSchema(); @@ -189,7 +191,7 @@ "'restriction' elements."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { if (foundSimpleType) @@ -201,12 +203,12 @@ "elements, must appear before any facets."); foundSimpleType = true; - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(this, _schema, atts); } else if (FacetUnmarshaller.isFacet(name)) { foundFacets = true; - unmarshaller = new FacetUnmarshaller(name, atts); + unmarshaller = new FacetUnmarshaller(this, name, atts); } else illegalElement(name); Index: src/main/java/org/exolab/castor/xml/schema/reader/FacetUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/FacetUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/FacetUnmarshaller.java (working copy) @@ -91,12 +91,17 @@ //----------------/ /** - * Creates a new FacetUnmarshaller + * Creates a new FacetUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param name the name of the Facet * @param atts the AttributeList **/ - public FacetUnmarshaller (String name, AttributeSet atts) throws XMLException { - super(); + public FacetUnmarshaller ( + final ComponentReader parent, + final String name, + final AttributeSet atts) + throws XMLException { + super(parent); _elementName = name; @@ -163,7 +168,7 @@ } if (SchemaNames.ANNOTATION.equals(name)) { - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else illegalElement(name); Index: src/main/java/org/exolab/castor/xml/schema/reader/IncludeUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/IncludeUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/IncludeUnmarshaller.java (working copy) @@ -65,13 +65,16 @@ { - public IncludeUnmarshaller - (Schema schema, AttributeSet atts, Resolver resolver, URIResolver uriResolver, - Locator locator, SchemaUnmarshallerState state) - throws XMLException - { - super(); - setResolver(resolver); + public IncludeUnmarshaller( + final ComponentReader parent, + final Schema schema, + final AttributeSet atts, + final URIResolver uriResolver, + final Locator locator, + final SchemaUnmarshallerState state) + throws XMLException { + super(parent); + setURIResolver(uriResolver); URILocation uri = null; //-- Get schemaLocation @@ -137,13 +140,13 @@ return; Parser parser = null; try { - parser = state.getConfiguration().getParser(); + parser = getXMLContext().getParser(); } catch(RuntimeException rte) {} if (parser == null) { throw new SchemaException("Error failed to create parser for include"); } - SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(true, state, getURIResolver()); + SchemaUnmarshaller schemaUnmarshaller = new SchemaUnmarshaller(this, true, state, getURIResolver()); if (state.cacheIncludedSchemas) schemaUnmarshaller.setSchema(includedSchema); Index: src/main/java/org/exolab/castor/xml/schema/reader/SimpleContentUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/SimpleContentUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/SimpleContentUnmarshaller.java (working copy) @@ -89,19 +89,20 @@ //----------------/ /** - * Creates a new SimpleContentUnmarshaller + * Creates a new SimpleContentUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param complexType the complexType we are unmarshalling * @param atts the AttributeList - * @param resolver the resolver being used for reference resolving **/ - public SimpleContentUnmarshaller - (ComplexType complexType, AttributeSet atts, Resolver resolver) - throws XMLException - { + public SimpleContentUnmarshaller( + final ComponentReader parent, + final ComplexType complexType, + final AttributeSet atts) + throws XMLException { + + super(parent); _complexType = complexType; - setResolver(resolver); - } //-- SimpleContentUnmarshaller //-----------/ @@ -164,7 +165,7 @@ foundExtension = true; unmarshaller - = new ExtensionUnmarshaller(_complexType, atts, getResolver()); + = new ExtensionUnmarshaller(this, _complexType, atts); } //-- restriction else if (SchemaNames.RESTRICTION.equals(name)) { @@ -181,7 +182,7 @@ foundRestriction = true; unmarshaller = - new SimpleContentRestrictionUnmarshaller(_complexType,atts,getResolver()); + new SimpleContentRestrictionUnmarshaller(this, _complexType, atts); } //-- annotation else if (name.equals(SchemaNames.ANNOTATION)) { @@ -194,7 +195,7 @@ "of a 'simpleContent' element."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else illegalElement(name); Index: src/main/java/org/exolab/castor/xml/schema/reader/FieldOrSelectorUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/FieldOrSelectorUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/FieldOrSelectorUnmarshaller.java (working copy) @@ -92,16 +92,19 @@ //----------------/ /** - * Creates a new FieldOrSelectorUnmarshaller + * Creates a new FieldOrSelectorUnmarshaller. * * @param elementName the name of the element being unmarshalled. * @param atts the AttributeList. + * @param parent the parent ComponentReader to get some configuration settings from **/ - public FieldOrSelectorUnmarshaller - (String elementName, AttributeSet atts) + public FieldOrSelectorUnmarshaller( + final ComponentReader parent, + final String elementName, + final AttributeSet atts) throws XMLException { - super(); + super(parent); _elementName = elementName; @@ -187,7 +190,7 @@ error("Only one (1) annotation may appear as a child of '" + _elementName + "'."); _foundAnnotation = true; - _unmarshaller = new AnnotationUnmarshaller(atts); + _unmarshaller = new AnnotationUnmarshaller(this, atts); } else illegalElement(name); Index: src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeListUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeListUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeListUnmarshaller.java (working copy) @@ -93,13 +93,16 @@ //----------------/ /** - * Creates a new ListUnmarshaller + * Creates a new ListUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param atts the AttributeList **/ - SimpleTypeListUnmarshaller(Schema schema, AttributeSet atts) - throws XMLException - { - super(); + SimpleTypeListUnmarshaller( + final ComponentReader parent, + final Schema schema, + final AttributeSet atts) + throws XMLException { + super(parent); _schema = schema; _list = new ListType(schema); @@ -204,7 +207,7 @@ "'list' elements."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { if (foundItemType) @@ -216,7 +219,7 @@ "'list' elements."); foundSimpleType = true; - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(this, _schema, atts); } else illegalElement(name); Index: src/main/java/org/exolab/castor/xml/schema/reader/ComplexContentRestrictionUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/ComplexContentRestrictionUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/ComplexContentRestrictionUnmarshaller.java (working copy) @@ -100,17 +100,18 @@ //- Constructors -/ //----------------/ /** - * Creates a new RestrictionUnmarshaller + * Creates a new RestrictionUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param complexType the complexType being unmarshalled * @param atts the AttributeList */ - public ComplexContentRestrictionUnmarshaller - (ComplexType complexType, AttributeSet atts, Resolver resolver) - throws XMLException - { - super(); - setResolver(resolver); - _complexType = complexType; + public ComplexContentRestrictionUnmarshaller( + final ComponentReader parent, + final ComplexType complexType, + final AttributeSet atts) + throws XMLException { + super(parent); + _complexType = complexType; _schema = complexType.getSchema(); _complexType.setDerivationMethod(SchemaNames.RESTRICTION); @@ -217,7 +218,7 @@ "'restriction' elements."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } //-- ModelGroup declarations (choice, all, sequence, group) @@ -233,12 +234,12 @@ foundModelGroup = true; unmarshaller - = new GroupUnmarshaller(_schema, name, atts, getResolver()); + = new GroupUnmarshaller(this, _schema, name, atts); } else if (SchemaNames.ATTRIBUTE.equals(name)) { foundAttribute = true; - unmarshaller = new AttributeUnmarshaller(_schema,atts, getResolver()); + unmarshaller = new AttributeUnmarshaller(this, _schema,atts); } else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) { @@ -249,17 +250,16 @@ "attributeGroups, but not defining ones."); } foundAttributeGroup = true; - unmarshaller = new AttributeGroupUnmarshaller(_schema,atts); + unmarshaller = new AttributeGroupUnmarshaller(this, _schema,atts); } //-- else if (SchemaNames.ANY_ATTRIBUTE.equals(name)) { unmarshaller - = new WildcardUnmarshaller(_complexType, _schema, name, atts, getResolver()); + = new WildcardUnmarshaller(this, _complexType, _schema, name, atts); } else illegalElement(name); - unmarshaller.setDocumentLocator(getDocumentLocator()); } //-- startElement /** Index: src/main/java/org/exolab/castor/xml/schema/reader/UnionUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/UnionUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/UnionUnmarshaller.java (working copy) @@ -99,12 +99,15 @@ /** * Creates a new IdentityConstraintUnmarshaller * + * @param parent the parent ComponentReader to get some configuration settings from * @param atts the AttributeList **/ - public UnionUnmarshaller(Schema schema, AttributeSet atts) - throws XMLException - { - super(); + public UnionUnmarshaller( + final ComponentReader parent, + final Schema schema, + final AttributeSet atts) + throws XMLException { + super(parent); if (schema == null) { String err = "'schema' must not be null."; @@ -184,11 +187,11 @@ elementName() + "'."); _foundAnnotation = true; - _unmarshaller = new AnnotationUnmarshaller(atts); + _unmarshaller = new AnnotationUnmarshaller(this, atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { _foundSimpleType = true; - _unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + _unmarshaller = new SimpleTypeUnmarshaller(this, _schema, atts); } else illegalElement(name); Index: src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeUnmarshaller.java (working copy) @@ -97,15 +97,18 @@ //----------------/ /** - * Creates a new SimpleTypeUnmarshaller + * Creates a new SimpleTypeUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param schema the Schema to which the SimpleType belongs * @param atts the AttributeList **/ - public SimpleTypeUnmarshaller - (Schema schema, AttributeSet atts) + public SimpleTypeUnmarshaller( + final ComponentReader parent, + final Schema schema, + final AttributeSet atts) throws XMLException { - super(); + super(parent); String name = atts.getValue(SchemaNames.NAME_ATTR); @@ -213,7 +216,7 @@ "of 'simpleType'."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else if (SchemaNames.RESTRICTION.equals(name)) { @@ -229,17 +232,17 @@ foundRestriction = true; unmarshaller - = new SimpleTypeRestrictionUnmarshaller(_simpleTypeDef, atts); + = new SimpleTypeRestrictionUnmarshaller(this, _simpleTypeDef, atts); } else if (SchemaNames.LIST.equals(name)) { foundList = true; Schema schema = _simpleTypeDef.getSchema(); - unmarshaller = new SimpleTypeListUnmarshaller(schema, atts); + unmarshaller = new SimpleTypeListUnmarshaller(this, schema, atts); } else if (SchemaNames.UNION.equals(name)) { foundUnion = true; Schema schema = _simpleTypeDef.getSchema(); - unmarshaller = new UnionUnmarshaller(schema, atts); + unmarshaller = new UnionUnmarshaller(this, schema, atts); } else illegalElement(name); Index: src/main/java/org/exolab/castor/xml/schema/reader/GroupUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/GroupUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/GroupUnmarshaller.java (working copy) @@ -116,17 +116,19 @@ //----------------/ /** - * Creates a new GroupUnmarshaller + * Creates a new GroupUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param schema the Schema to which the Group belongs * @param element the element name for this type of group * @param atts the AttributeList - * @param resolver the resolver being used for reference resolving **/ - public GroupUnmarshaller - (Schema schema, String element, AttributeSet atts, Resolver resolver) - { - super(); - setResolver(resolver); + public GroupUnmarshaller( + final ComponentReader parent, + final Schema schema, + final String element, + final AttributeSet atts) { + super(parent); + this._schema = schema; _group = new Group(); @@ -264,19 +266,19 @@ "element definitions."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else if (SchemaNames.ELEMENT.equals(name)) { foundElement = true; unmarshaller - = new ElementUnmarshaller(_schema, atts, getResolver()); + = new ElementUnmarshaller(this, _schema, atts); } //--group else if (name.equals(SchemaNames.GROUP)) { foundModelGroup = true; unmarshaller - = new ModelGroupUnmarshaller(_schema, atts, getResolver()); + = new ModelGroupUnmarshaller(this, _schema, atts); } //--all, sequence, choice @@ -286,14 +288,14 @@ if (SchemaNames.ALL.equals(name)) foundAll = true; unmarshaller - = new GroupUnmarshaller(_schema, name, atts, getResolver()); + = new GroupUnmarshaller(this, _schema, name, atts); } //--any else if (SchemaNames.ANY.equals(name)) { if (foundAll) error(" can not appear as a child of a element"); unmarshaller - = new WildcardUnmarshaller(_group, _schema, name, atts, getResolver()); + = new WildcardUnmarshaller(this, _group, _schema, name, atts); } else { @@ -302,7 +304,6 @@ err.append("> found in ."); throw new SchemaException(err.toString()); } - unmarshaller.setDocumentLocator(getDocumentLocator()); } //-- startElement Index: src/main/java/org/exolab/castor/xml/schema/reader/IdentityConstraintUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/IdentityConstraintUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/IdentityConstraintUnmarshaller.java (working copy) @@ -96,16 +96,18 @@ //----------------/ /** - * Creates a new IdentityConstraintUnmarshaller + * Creates a new IdentityConstraintUnmarshaller. * + * @param parent the parent ComponentReader to get some configuration settings from * @param elementName the resolver being used for reference resolving * @param atts the AttributeList **/ - public IdentityConstraintUnmarshaller - (String elementName, AttributeSet atts) - throws XMLException - { - super(); + public IdentityConstraintUnmarshaller( + final ComponentReader parent, + final String elementName, + final AttributeSet atts) + throws XMLException { + super(parent); _elementName = elementName; @@ -211,7 +213,7 @@ _elementName + "'."); _foundAnnotation = true; - _unmarshaller = new AnnotationUnmarshaller(atts); + _unmarshaller = new AnnotationUnmarshaller(this, atts); } else if (SchemaNames.SELECTOR.equals(name)) { @@ -226,11 +228,11 @@ _foundSelector = true; - _unmarshaller = new FieldOrSelectorUnmarshaller(name, atts); + _unmarshaller = new FieldOrSelectorUnmarshaller(this, name, atts); } else if (SchemaNames.FIELD.equals(name)) { _foundField = true; - _unmarshaller = new FieldOrSelectorUnmarshaller(name, atts); + _unmarshaller = new FieldOrSelectorUnmarshaller(this, name, atts); } else illegalElement(name); Index: src/main/java/org/exolab/castor/xml/schema/reader/UnknownUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/UnknownUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/UnknownUnmarshaller.java (working copy) @@ -71,8 +71,8 @@ //- Constructors -/ //----------------/ - public UnknownUnmarshaller(String name) { - super(); + public UnknownUnmarshaller(final ComponentReader parent, final String name) { + super(parent); this.name = name; } //-- UnknownUnmarshaller Index: src/main/java/org/exolab/castor/xml/schema/reader/SchemaReader.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/SchemaReader.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/SchemaReader.java (working copy) @@ -45,39 +45,45 @@ package org.exolab.castor.xml.schema.reader; +import java.io.IOException; import java.io.Reader; -import java.io.IOException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.exolab.castor.net.URIException; import org.exolab.castor.net.URILocation; import org.exolab.castor.net.URIResolver; -import org.exolab.castor.util.Configuration; -import org.exolab.castor.util.LocalConfiguration; import org.exolab.castor.util.NestedIOException; - +import org.exolab.castor.xml.XMLContext; +import org.exolab.castor.xml.XMLException; import org.exolab.castor.xml.schema.Schema; -import org.exolab.castor.xml.XMLException; - +import org.xml.sax.EntityResolver; +import org.xml.sax.ErrorHandler; import org.xml.sax.InputSource; -import org.xml.sax.EntityResolver; import org.xml.sax.Parser; import org.xml.sax.SAXException; import org.xml.sax.SAXParseException; -import org.xml.sax.ErrorHandler; /** - * A class for reading XML Schemas + * A class for reading XML Schemas. * * @author Keith Visco * @version $Revision$ $Date: 2004-10-05 14:27:10 -0600 (Tue, 05 Oct 2004) $ **/ public class SchemaReader { + /** The Logger to use. */ + private static final Log LOG = LogFactory.getLog(SchemaReader.class); /** + * The Castor XML Context... mother of all. + */ + private XMLContext _xmlContext; + + /** * The Castor Configuration */ - private Configuration _config = null; +// private Configuration _config = null; /** * XML Parser instance @@ -119,35 +125,38 @@ /** - * Creates a new SchemaReader + * Old fashion style to create a SchemaReader instance. + * + * @throws IOException + * if no Parser is available */ - private SchemaReader() - throws IOException - { - //-- get default parser from Configuration - - _config = LocalConfiguration.getInstance(); - + private void init() throws IOException { + // -- get default parser from Configuration + _xmlContext = new XMLContext(); + Parser parser = null; - - parser = _config.getParser(); + parser = _xmlContext.getParser(); + if (parser == null) { - throw new IOException("fatal error: unable to create SAX parser."); + String message = "fatal error: unable to create SAX parser."; + LOG.warn(message); + throw new IOException(message); } _parser = parser; - } //-- SchemaReader + } // -- SchemaReader /** * Creates a new SchemaReader for the given InputSource - * - * @param source the InputSource to read the Schema from. - **/ + * + * @param source + * the InputSource to read the Schema from. + */ public SchemaReader(InputSource source) throws IOException { - this(); + init(); if (source == null) throw new IllegalArgumentException("InputSource cannot be null"); @@ -165,7 +174,7 @@ public SchemaReader(Reader reader, String filename) throws IOException { - this(); + init(); if (reader == null) { String err = "The argument 'reader' must not be null."; @@ -186,7 +195,7 @@ public SchemaReader(String url) throws IOException { - this(); + init(); if (url == null) { String err = "The argument 'url' must not be null."; throw new IllegalArgumentException(err); @@ -196,6 +205,42 @@ } //-- SchemaReader /** + * New style how to create a SchemaReader instance, requiring that XMLContext + * and InputSource are set before calling {@link read}. + */ + public SchemaReader() { + super(); + } + + /** + * To set the XMLContext to be used. Also resets the parser as it depends + * of the XMLContext. + * @param xmlContext the XMLContext to be used + */ + public void setXMLContext(final XMLContext xmlContext) { + this._xmlContext = xmlContext; + + Parser p = _xmlContext.getParser(); + if (p != null) { + _parser = p; + } + } + + /** + * A different way to create a SchemaReader by using an empty constructor and + * setting the InputSource afterwards. + * @param inputSource the InputSource to read the schema from + */ + public void setInputSource(final InputSource inputSource) { + if (inputSource == null) { + String message = "InputSource must not be null"; + LOG.warn(message); + throw new IllegalArgumentException(message); + } + _source = inputSource; + } + + /** * Reads the Schema from the source and returns the Schema * object model. * @@ -206,16 +251,27 @@ * * @return the new Schema created from the source of this SchemaReader **/ - public Schema read() throws IOException - { - if (_schema != null) return _schema; + public Schema read() throws IOException { + if (_schema != null) { + return _schema; + } + if (_parser == null) { + String message = "Required Parser was not specified"; + LOG.warn(message); + throw new IllegalStateException(message); + } + if (_source == null) { + String message = "Required Source was not specified"; + LOG.warn(message); + throw new IllegalStateException(message); + } SchemaUnmarshaller schemaUnmarshaller = null; try { SchemaUnmarshallerState state = new SchemaUnmarshallerState(); - state.setConfiguration(_config); +// Joachim state.setConfiguration(_config); state.cacheIncludedSchemas = _cacheIncludedSchemas; - schemaUnmarshaller = new SchemaUnmarshaller(state); + schemaUnmarshaller = new SchemaUnmarshaller(_xmlContext, state); if (_uriResolver != null) schemaUnmarshaller.setURIResolver(_uriResolver); @@ -364,5 +420,4 @@ throw new NestedIOException(except); } //-- handleException - } //-- SchemaReader Index: src/main/java/org/exolab/castor/xml/schema/reader/ComponentReader.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/ComponentReader.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/ComponentReader.java (working copy) @@ -49,6 +49,7 @@ import org.exolab.castor.net.URIResolver; import org.exolab.castor.xml.AttributeSet; import org.exolab.castor.xml.Namespaces; +import org.exolab.castor.xml.XMLContext; import org.exolab.castor.xml.XMLException; import org.exolab.castor.xml.schema.Resolver; import org.xml.sax.Locator; @@ -66,7 +67,9 @@ //--------------------/ //- Member Variables -/ //--------------------/ - + /** The Castor XML context to use. */ + private XMLContext _xmlContext; + /** * The document locator **/ @@ -86,9 +89,32 @@ //- Constructors -/ //----------------/ - public ComponentReader() { + private ComponentReader() { super(); } //-- ComponentReader + + /** + * A constructor for derived classes which allows to hand down some settings + * which are used by every ComponentReader. + * @param parent the parent ComponentReader to read settings from + */ + protected ComponentReader(final ComponentReader parent) { + this(); + if (parent != null) { + setXMLContext(parent.getXMLContext()); + setResolver(parent.getResolver()); + setDocumentLocator(parent.getDocumentLocator()); + } + } + + /** + * For those cases the sub class is a leaf class which is not instantiated + * within a ComponentReader. + * @param xmlContext the XMLContext to use + */ + protected ComponentReader(final XMLContext xmlContext) { + setXMLContext(xmlContext); + } //-----------/ //- Methods -/ @@ -366,5 +392,23 @@ } //-- startElement + /** + * To set the Castor XML context to be used. + * @param xmlContext the Castor XML context to be used + */ + public void setXMLContext(final XMLContext xmlContext) { + _xmlContext = xmlContext; + } + + /** + * To get the Castor XML context used. + * @return the Castor XML context used + */ + public XMLContext getXMLContext() { + if (_xmlContext == null) { + _xmlContext = new XMLContext(); + } + return _xmlContext; + } } //-- ComponentReader Index: src/main/java/org/exolab/castor/xml/schema/reader/DocumentationUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/DocumentationUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/DocumentationUnmarshaller.java (working copy) @@ -83,11 +83,12 @@ //----------------/ /** - * Creates a new DocumentationUnmarshaller + * Creates a new DocumentationUnmarshaller. + * @param parent the parent ComponentReader to get some configuration settings from * @param atts the AttributeList **/ - public DocumentationUnmarshaller(AttributeSet atts) { - super(); + public DocumentationUnmarshaller(final ComponentReader parent, final AttributeSet atts) { + super(parent); _documentation = new Documentation(); Index: src/main/java/org/exolab/castor/xml/schema/reader/SimpleContentRestrictionUnmarshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/reader/SimpleContentRestrictionUnmarshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/reader/SimpleContentRestrictionUnmarshaller.java (working copy) @@ -108,16 +108,18 @@ //- Constructors -/ //----------------/ /** - * Creates a new RestrictionUnmarshaller + * Creates a new RestrictionUnmarshaller. * @param complexType the complexType being unmarshalled * @param atts the AttributeList */ public SimpleContentRestrictionUnmarshaller( - ComplexType complexType, AttributeSet atts, Resolver resolver) { + final ComponentReader parent, + final ComplexType complexType, + final AttributeSet atts) { - super(); - setResolver(resolver); - _complexType = complexType; + super(parent); + + _complexType = complexType; _complexType.setDerivationMethod(SchemaNames.RESTRICTION); _complexType.setRestriction(true); _schema = complexType.getSchema(); @@ -257,7 +259,7 @@ "'restriction' elements."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(this, atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { @@ -274,7 +276,7 @@ "elements, must appear before any attribute elements."); foundSimpleType = true; - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(this, _schema, atts); } else if (FacetUnmarshaller.isFacet(name)) { @@ -283,7 +285,7 @@ error("A 'facet', as a child of 'restriction' "+ "elements, must appear before any attribute elements."); - unmarshaller = new FacetUnmarshaller(name, atts); + unmarshaller = new FacetUnmarshaller(this, name, atts); if (_simpleTypeDef == null) { SimpleContent content = (SimpleContent)_complexType.getContentType(); _simpleTypeDef = new SimpleTypeDefinition(_schema, content.getTypeName(),_id); @@ -291,7 +293,7 @@ } else if (SchemaNames.ATTRIBUTE.equals(name)) { foundAttribute = true; - unmarshaller = new AttributeUnmarshaller(_schema,atts, getResolver()); + unmarshaller = new AttributeUnmarshaller(this, _schema, atts); } else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) { @@ -301,16 +303,17 @@ "attributeGroups, but not defining ones."); } foundAttributeGroup = true; - unmarshaller = new AttributeGroupUnmarshaller(_schema,atts); + unmarshaller = new AttributeGroupUnmarshaller(this, _schema, atts); } //-- else if (SchemaNames.ANY_ATTRIBUTE.equals(name)) { unmarshaller - = new WildcardUnmarshaller(_complexType, _schema, name, atts, getResolver()); + = new WildcardUnmarshaller(this, _complexType, _schema, name, atts); } else illegalElement(name); + unmarshaller.setXMLContext(getXMLContext()); unmarshaller.setDocumentLocator(getDocumentLocator()); } //-- startElement Index: src/main/java/org/exolab/castor/xml/schema/writer/SchemaWriter.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/writer/SchemaWriter.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/writer/SchemaWriter.java (working copy) @@ -45,27 +45,61 @@ package org.exolab.castor.xml.schema.writer; +import java.io.IOException; import java.io.Writer; -import java.io.IOException; import java.util.Enumeration; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.exolab.castor.types.AnyNode; -import org.exolab.castor.util.LocalConfiguration; -import org.exolab.castor.xml.schema.*; +import org.exolab.castor.xml.Namespaces; +import org.exolab.castor.xml.Serializer; +import org.exolab.castor.xml.XMLContext; +import org.exolab.castor.xml.schema.Annotated; +import org.exolab.castor.xml.schema.Annotation; +import org.exolab.castor.xml.schema.AppInfo; +import org.exolab.castor.xml.schema.AttributeDecl; +import org.exolab.castor.xml.schema.AttributeGroup; +import org.exolab.castor.xml.schema.AttributeGroupDecl; +import org.exolab.castor.xml.schema.AttributeGroupReference; +import org.exolab.castor.xml.schema.BlockList; +import org.exolab.castor.xml.schema.ComplexType; +import org.exolab.castor.xml.schema.ContentModelGroup; +import org.exolab.castor.xml.schema.ContentType; +import org.exolab.castor.xml.schema.Documentation; +import org.exolab.castor.xml.schema.ElementDecl; +import org.exolab.castor.xml.schema.Facet; +import org.exolab.castor.xml.schema.FinalList; +import org.exolab.castor.xml.schema.Form; +import org.exolab.castor.xml.schema.Group; +import org.exolab.castor.xml.schema.IdentityConstraint; +import org.exolab.castor.xml.schema.IdentityField; +import org.exolab.castor.xml.schema.IdentitySelector; +import org.exolab.castor.xml.schema.KeyRef; +import org.exolab.castor.xml.schema.ModelGroup; +import org.exolab.castor.xml.schema.RedefineSchema; +import org.exolab.castor.xml.schema.Schema; +import org.exolab.castor.xml.schema.SchemaNames; +import org.exolab.castor.xml.schema.SimpleContent; +import org.exolab.castor.xml.schema.SimpleType; +import org.exolab.castor.xml.schema.Structure; +import org.exolab.castor.xml.schema.Union; +import org.exolab.castor.xml.schema.Wildcard; +import org.exolab.castor.xml.schema.XMLType; import org.exolab.castor.xml.schema.simpletypes.ListType; import org.exolab.castor.xml.util.AnyNode2SAX; -import org.exolab.castor.xml.Namespaces; -import org.exolab.castor.xml.Serializer; - import org.xml.sax.DocumentHandler; import org.xml.sax.SAXException; import org.xml.sax.helpers.AttributeListImpl; /** - * A class for serializing Schema models + * A class for serializing Schema models. * @author Keith Visco * @version $Revision$ $Date: 2006-04-05 13:16:42 -0600 (Wed, 05 Apr 2006) $ **/ public class SchemaWriter { + /** The Logger to use. */ + private static final Log LOG = LogFactory.getLog(SchemaWriter.class); //------------------------/ //- Schema element names -/ @@ -77,7 +111,7 @@ private static final String ANNOTATION = "annotation"; /** - * AppInfo element name + * AppInfo element name. */ private static final String APPINFO = "appinfo"; @@ -160,30 +194,34 @@ * @deprecated **/ public static boolean enable = false; + + /** Castor XML context - mother of all dwelling. */ + private XMLContext _xmlContext = null; /** - * Creates a new SchemaWriter for the given Writer + * Creates a new SchemaWriter for the given Writer. * * @param writer the Writer to serialize to + * @throws IOException in case taht wrapping the Writer fails **/ - public SchemaWriter(Writer writer) - throws IOException - { + public SchemaWriter(final Writer writer) + throws IOException { + _xmlContext = new XMLContext(); + Serializer serializer = _xmlContext.getSerializer(); - Serializer serializer = LocalConfiguration.getInstance().getSerializer(); - - if (serializer == null) + if (serializer == null) { throw new IOException("Unable to obtain serailizer"); + } - serializer.setOutputCharStream( writer ); + serializer.setOutputCharStream(writer); DocumentHandler handler = serializer.asDocumentHandler(); - if ( handler == null ) { + if (handler == null) { String err = "The following serializer is not SAX capable: "; err += serializer.getClass().getName(); err += "; cannot proceed."; - throw new IOException( err ); + throw new IOException(err); } _handler = handler; @@ -191,23 +229,79 @@ } //-- SchemaWriter /** - * Creates a new SchemaWriter for the given DocumentHandler + * Creates a new SchemaWriter for the given DocumentHandler. * * @param handler the DocumentHandler to send events to **/ - public SchemaWriter(DocumentHandler handler) { + public SchemaWriter(final DocumentHandler handler) { - if (handler == null) + if (handler == null) { throw new IllegalArgumentException("DocumentHandler must not be null."); + } _handler = handler; } //-- SchemaWriter + /** + * A constructor to create an empty uninitialized SchemaWriter via XMLContext. + */ + public SchemaWriter() { + super(); + } + + /** + * To set the XMLContext to be used for the SchemaWriter. + * @param xmlContext the XMLContext to be used + */ + public void setXMLContext(final XMLContext xmlContext) { + _xmlContext = xmlContext; + } + + /** + * To set the DocumentHandler to a Writer - which is wrapped by a serializer. + * @param writer the Writer to use for output + * @throws IOException in case the Writer cannot be used for DocumentHandler + */ + public void setDocumentHandler(final Writer writer) throws IOException { + Serializer serializer = _xmlContext.getSerializer(); - public void write(Schema schema) - throws SAXException - { + if (serializer == null) { + String message = "Unable to obtain serailizer"; + LOG.warn(message); + throw new IOException(message); + } + + serializer.setOutputCharStream(writer); + + DocumentHandler handler = serializer.asDocumentHandler(); + + if (handler == null) { + String err = "The following serializer is not SAX capable: "; + err += serializer.getClass().getName(); + err += "; cannot proceed."; + LOG.warn(err); + throw new IOException(err); + } + + _handler = handler; + } + + /** + * To directly set a DocumentHandler. + * @param documentHandler set the DocumentHandler + */ + public void setDocumentHandler(final DocumentHandler documentHandler) { + if (documentHandler == null) { + String message = "DocumentHandler must not be null."; + LOG.warn(message); + throw new IllegalArgumentException(message); + } + _handler = documentHandler; + } + + public void write(final Schema schema) + throws SAXException { if (schema == null) throw new IllegalArgumentException("Schema must not be null."); Index: src/main/java/org/exolab/castor/xml/schema/util/XMLInstance2Schema.java =================================================================== --- src/main/java/org/exolab/castor/xml/schema/util/XMLInstance2Schema.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/schema/util/XMLInstance2Schema.java (working copy) @@ -51,12 +51,11 @@ import java.io.Reader; import java.io.Writer; -import org.exolab.castor.util.Configuration; -import org.exolab.castor.util.LocalConfiguration; -import org.exolab.castor.xml.schema.*; +import org.exolab.castor.util.NestedIOException; +import org.exolab.castor.xml.XMLContext; +import org.exolab.castor.xml.schema.Order; +import org.exolab.castor.xml.schema.Schema; import org.exolab.castor.xml.schema.writer.SchemaWriter; -import org.exolab.castor.util.NestedIOException; - import org.xml.sax.InputSource; import org.xml.sax.Parser; @@ -68,6 +67,8 @@ **/ public class XMLInstance2Schema { + private XMLContext _xmlContext = new XMLContext(); + private Order _defaultGroup = Order.seq; /** @@ -118,8 +119,7 @@ handler.setDefaultGroupOrder(_defaultGroup); try { - Configuration config = LocalConfiguration.getInstance(); - Parser parser = config.getParser(); + Parser parser = _xmlContext.getParser(); if (parser == null) { throw new IOException("fatal error: unable to create SAX parser."); } Index: src/main/java/org/exolab/castor/xml/validators/PatternValidator.java =================================================================== --- src/main/java/org/exolab/castor/xml/validators/PatternValidator.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/validators/PatternValidator.java (working copy) @@ -259,7 +259,7 @@ * the ValidationContext */ private void initEvaluator(final ValidationContext context) { - _regex = context.getConfiguration().getRegExpEvaluator(); + _regex = context.getXMLContext().getRegExpEvaluator(); if (_regex == null) { _regex = new DefaultRegExpEvaluator(); } Index: src/main/java/org/exolab/castor/xml/Marshaller.java =================================================================== --- src/main/java/org/exolab/castor/xml/Marshaller.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/Marshaller.java (working copy) @@ -290,6 +290,9 @@ * one of them the superclass will be marshalled instead of the class itself. */ private final Set _proxyInterfaces = new HashSet(); + /** The XML context to use - mother of all. */ + private XMLContext _xmlContext = new XMLContext(); + /** * Creates a new Marshaller with the given DocumentHandler. * @@ -357,7 +360,7 @@ private void configureSerializer(Writer out) throws IOException { - _serializer = _config.getSerializer(); + _serializer = _xmlContext.getSerializer(); if (_serializer == null) throw new RuntimeException("Unable to obtain serializer"); @@ -454,7 +457,7 @@ if (_serializer != null) { if (_format == null) { - _format = _config.getOutputFormat(); + _format = _xmlContext.getOutputFormat(); } _format.setDoctype(publicId, systemId); //-- reset output format, this needs to be done @@ -528,7 +531,7 @@ if (_serializer != null) { if (_format == null) { - _format = _config.getOutputFormat(); + _format = _xmlContext.getOutputFormat(); } _format.setOmitXMLDeclaration( ! asDocument ); _format.setOmitDocumentType( ! asDocument ); @@ -2135,7 +2138,7 @@ if (_serializer != null) { if (_format == null) { - _format = _config.getOutputFormat(); + _format = _xmlContext.getOutputFormat(); } _format.setEncoding(encoding); //-- reset output format, this needs to be done @@ -2668,6 +2671,21 @@ } } + /** + * To set the content handler which is used as destination at marshalling. + * @param contentHandler the content handler to use as destination at marshalling + */ + public void setContentHandler(final ContentHandler contentHandler) { + _handler = contentHandler; + } + + /** + * To set the XML Context that the {@link Marshaller} should use. + * @param xmlContext the XML Context that the {@link Marshaller} should use + */ + public void setXMLContext(final XMLContext xmlContext) { + _xmlContext = xmlContext; + } } //-- Marshaller Index: src/main/java/org/exolab/castor/xml/XMLNaming.java =================================================================== --- src/main/java/org/exolab/castor/xml/XMLNaming.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/XMLNaming.java (working copy) @@ -84,12 +84,11 @@ /** - * Returns the default instance of XMLNaming + * Returns the default instance of XMLNaming. * @see org.exolab.castor.util.Configuration **/ public static final XMLNaming getInstance() { - Configuration config = LocalConfiguration.getInstance(); - return config.getXMLNaming(); + return new XMLContext().getXMLNaming(); } //-- getInstance } //-- Naming Index: src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorAdapter.java =================================================================== --- src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorAdapter.java (revision 7156) +++ src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorAdapter.java (working copy) @@ -51,6 +51,7 @@ import org.exolab.castor.util.LocalConfiguration; import org.exolab.castor.xml.NodeType; import org.exolab.castor.xml.XMLClassDescriptor; +import org.exolab.castor.xml.XMLContext; import org.exolab.castor.xml.XMLFieldDescriptor; import org.exolab.castor.xml.XMLNaming; @@ -96,7 +97,7 @@ } if (primitiveNodeType == null) { - primitiveNodeType = LocalConfiguration.getInstance().getPrimitiveNodeType(); + primitiveNodeType = new XMLContext().getPrimitiveNodeType(); } if (primitiveNodeType == null) { Index: src/main/java/org/exolab/castor/types/AnyNode.java =================================================================== --- src/main/java/org/exolab/castor/types/AnyNode.java (revision 7156) +++ src/main/java/org/exolab/castor/types/AnyNode.java (working copy) @@ -53,6 +53,7 @@ import org.exolab.castor.util.LocalConfiguration; import org.exolab.castor.xml.Serializer; +import org.exolab.castor.xml.XMLContext; import org.exolab.castor.xml.util.AnyNode2SAX; /** @@ -530,17 +531,17 @@ * @return the String representation of this AnyNode. */ public String toString() { - Serializer serializer = LocalConfiguration.getInstance().getSerializer(); + Serializer serializer = new XMLContext().getSerializer(); if (serializer == null) { throw new RuntimeException("Unable to obtain serializer"); } StringWriter writer = new StringWriter(); - serializer.setOutputCharStream( writer ); + serializer.setOutputCharStream(writer); try { - AnyNode2SAX.fireEvents(this,serializer.asDocumentHandler()); + AnyNode2SAX.fireEvents(this, serializer.asDocumentHandler()); } catch (java.io.IOException ioe) { return privateToString(); } catch (org.xml.sax.SAXException saxe) { Index: src/main/java/org/exolab/castor/util/Configuration.java =================================================================== --- src/main/java/org/exolab/castor/util/Configuration.java (revision 7156) +++ src/main/java/org/exolab/castor/util/Configuration.java (working copy) @@ -282,7 +282,7 @@ static final String ResourceName = "/org/exolab/castor/castor.properties"; - static final String DEFAULT_SERIALIZER_FACTORY = "org.exolab.castor.xml.XercesXMLSerializerFactory"; + public static final String DEFAULT_SERIALIZER_FACTORY = "org.exolab.castor.xml.XercesXMLSerializerFactory"; /** * Property specifying whether sequence order validation should be lenient @@ -509,66 +509,66 @@ return getDefault().getProperty( name, defValue ); } //-- getDefaultProperty - /** - * Returns the currently configured naming conventions to use - * for the XML framework - * - * Design note: This method should be overloaded by any - * sub-classes. - * - * @return the currently configured naming conventions to use - * for the XML framework - * @see #getDefaultXMLNaming() - */ - public XMLNaming getXMLNaming() { - return getDefaultXMLNaming(); - } //-- getXMLNaming - - - /** - * Returns the default naming conventions to use for the XML framework - * - * @return the default naming conventions to use for the XML framework - */ - public static XMLNaming getDefaultXMLNaming() { - - if (_defaultValues.naming != null) return _defaultValues.naming; - - String prop = getDefaultProperty( Property.Naming, null); - if ((prop == null) || (prop.equalsIgnoreCase("lower"))) { - _defaultValues.naming = new DefaultNaming(); - } - else if (prop.equalsIgnoreCase("mixed")) { - DefaultNaming dn = new DefaultNaming(); - dn.setStyle(DefaultNaming.MIXED_CASE_STYLE); - _defaultValues.naming = dn; - } - else { - try { - Class cls = Class.forName(prop); - _defaultValues.naming = (XMLNaming) cls.newInstance(); - } - catch (Exception except) { - throw new RuntimeException("Failed to load XMLNaming: " + - except); - } - } - return _defaultValues.naming; - } //-- getNaming - - /** - * Return an XML parser implementing the feature list specified - * in the configuration file. - * - * Design note: This method should be overloaded by any - * sub-classes. - * - * @return a suitable XML parser - * @see #getDefaultParser() - */ - public Parser getParser() { - return getDefaultParser(); - } //-- getParser +// /** +// * Returns the currently configured naming conventions to use +// * for the XML framework +// * +// * Design note: This method should be overloaded by any +// * sub-classes. +// * +// * @return the currently configured naming conventions to use +// * for the XML framework +// * @see #getDefaultXMLNaming() +// */ +// public XMLNaming getXMLNaming() { +// return getDefaultXMLNaming(); +// } //-- getXMLNaming +// +// +// /** +// * Returns the default naming conventions to use for the XML framework +// * +// * @return the default naming conventions to use for the XML framework +// */ +// public static XMLNaming getDefaultXMLNaming() { +// +// if (_defaultValues.naming != null) return _defaultValues.naming; +// +// String prop = getDefaultProperty( Property.Naming, null); +// if ((prop == null) || (prop.equalsIgnoreCase("lower"))) { +// _defaultValues.naming = new DefaultNaming(); +// } +// else if (prop.equalsIgnoreCase("mixed")) { +// DefaultNaming dn = new DefaultNaming(); +// dn.setStyle(DefaultNaming.MIXED_CASE_STYLE); +// _defaultValues.naming = dn; +// } +// else { +// try { +// Class cls = Class.forName(prop); +// _defaultValues.naming = (XMLNaming) cls.newInstance(); +// } +// catch (Exception except) { +// throw new RuntimeException("Failed to load XMLNaming: " + +// except); +// } +// } +// return _defaultValues.naming; +// } //-- getNaming +// +// /** +// * Return an XML parser implementing the feature list specified +// * in the configuration file. +// * +// * Design note: This method should be overloaded by any +// * sub-classes. +// * +// * @return a suitable XML parser +// * @see #getDefaultParser() +// */ +// public Parser getParser() { +// return getDefaultParser(); +// } //-- getParser /** * Indicates whether (by default) sequence order validation is lenient. @@ -617,517 +617,518 @@ public boolean getLenientIdValidation() { return getDefaultLenientIdValidation(); } +// +// /** +// * Return an XML document parser implementing the feature list +// * specified in the default configuration file. +// * +// * @return a suitable XML parser +// * @see #getParser() +// */ +// public static Parser getDefaultParser() +// { +// return getDefaultParser( null ); +// } //-- getDefaultParser +// +// +// /** +// * Returns an XML document parser implementing the requested +// * set of features. The feature list is a comma separated list +// * of features that parser may or may not support. No errors are +// * generated for unsupported features. If the feature list is not +// * null, it overrides the default feature list specified in the +// * configuration file, including validation and Namespaces. +// * +// * @param features The requested feature list, null for the +// * defaults +// * @return A suitable XML parser +// */ +// public static Parser getDefaultParser( String features ) +// { +// String prop; +// Parser parser; +// +// //-- validation? +// prop = getDefault().getProperty( Property.ParserValidation, "false" ); +// boolean validation = ( prop.equalsIgnoreCase( "true" ) || +// prop.equalsIgnoreCase( "on" ) ); +// +// //-- namespaces? +// prop = getDefault().getProperty( Property.Namespaces, "false" ); +// boolean namespaces = ( prop.equalsIgnoreCase( "true" ) || +// prop.equalsIgnoreCase( "on" ) ); +// +// +// //-- which parser? +// prop = getDefault().getProperty( Property.Parser ); +// if (( prop == null ) || (prop.length() == 0)) { +// // If no parser class was specified, check for JAXP +// // otherwise we default to Xerces. +// SAXParserFactory factory = SAXParserFactory.newInstance(); +// factory.setNamespaceAware(namespaces); +// factory.setValidating(validation); +// try { +// SAXParser saxParser = factory.newSAXParser(); +// return saxParser.getParser(); +// } +// catch(ParserConfigurationException pcx) { +// LOG.error(Messages.format("conf.configurationError", pcx)); +// } +// catch(org.xml.sax.SAXException sx) { +// LOG.error(Messages.format("conf.configurationError", sx)); +// } +// +// } +// +// +// if ((prop == null) || +// (prop.length() == 0) || +// (prop.equalsIgnoreCase("xerces"))) +// { +// prop = "org.apache.xerces.parsers.SAXParser"; +// } +// +// +// // If a parser class was specified, we try to create it and +// // complain about creation error. +// try { +// Class cls; +// +// cls = Class.forName( prop ); +// parser = (Parser) cls.newInstance(); +// } catch ( Exception except ) { +// throw new RuntimeException( Messages.format( "conf.failedInstantiateParser", +// prop, except ) ); +// } +// +// if (parser instanceof XMLReader) { +// XMLReader xmlReader = (XMLReader) parser; +// setFeaturesOnXmlReader(getDefault(), features, validation, namespaces, xmlReader); +// } +// +// return parser; +// } +// +// /** +// * Sets features on XML reader instance. +// * @param features +// * @param validation Whether to enable validation or not. +// * @param namespaces Whether to enable namespace support for not. +// * @param xmlReader The XMLReader instance to configure. +// */ +// protected static void setFeaturesOnXmlReader(final Properties properties, +// String features, +// final boolean validation, +// final boolean namespaces, +// final XMLReader xmlReader) { +// try { +// xmlReader.setFeature(Features.Validation, validation); +// xmlReader.setFeature(Features.Namespaces, namespaces); +// features = properties.getProperty(Property.ParserFeatures, features); +// enableFeatures(features, xmlReader); +// String featuresToDisable = getDefault().getProperty(Property.ParserFeaturesToDisable, ""); +// disableFeatures(featuresToDisable, xmlReader); +// } catch (SAXException except) { +// LOG.error(Messages.format("conf.configurationError", except)); +// } +// } +// +// /** +// * Enables selected features on the XMLReader instance +// * @param features Features to enable +// * @param xmlReader XMLReader instance to be configured. +// * @throws SAXNotRecognizedException If the feature is not recognized by the XMLReader. +// * @throws SAXNotSupportedException If the feature is not supported by the XMLReader. +// */ +// private static void enableFeatures(final String features, final XMLReader xmlReader) +// throws SAXNotRecognizedException, SAXNotSupportedException { +// StringTokenizer token; +// if (features != null) { +// token = new StringTokenizer(features, ", "); +// while (token.hasMoreTokens()) { +// xmlReader.setFeature(token.nextToken(), true); +// } +// } +// } +// +// /** +// * Disables selected features on the XMLReader instance +// * @param features Features to disable +// * @param xmlReader XMLReader instance to be configured. +// * @throws SAXNotRecognizedException If the feature is not recognized by the XMLReader. +// * @throws SAXNotSupportedException If the feature is not supported by the XMLReader. +// */ +// private static void disableFeatures(String features, final XMLReader xmlReader) +// throws SAXNotRecognizedException, SAXNotSupportedException { +// StringTokenizer token; +// if (features != null) { +// token = new StringTokenizer(features, ", "); +// while (token.hasMoreTokens()) { +// xmlReader.setFeature(token.nextToken(), false); +// } +// } +// } +// +// /** +// * Returns the currently configured NodeType to use for Java +// * primitives. A null value will be returned if no NodeType was +// * specified, indicating the default NodeType should be used. +// * +// * Design note: This method should be overloaded by any +// * sub-classes. +// * +// * @return the NodeType assigned to Java primitives, or null +// * if no NodeType was specified. +// * @see #getDefaultPrimitiveNodeType() +// */ +// public NodeType getPrimitiveNodeType() { +// return getDefaultPrimitiveNodeType(); +// } //-- getPrimitiveNodeType +// +// +// /** +// * Returns the NodeType to use for Java primitives. +// * A null value will be returned if no NodeType was specified, +// * indicating the default NodeType should be used. +// * +// * @return the NodeType assigned to Java primitives, or null +// * if no NodeType was specified. +// * +// * @see #getPrimitiveNodeType() +// */ +// public static NodeType getDefaultPrimitiveNodeType() { +// +// if (_defaultValues.primitiveNodeType != null) +// return _defaultValues.primitiveNodeType; +// +// String prop = getDefaultProperty(Property.PrimitiveNodeType, null); +// if (prop == null) return null; +// +// _defaultValues.primitiveNodeType = NodeType.getNodeType(prop); +// return _defaultValues.primitiveNodeType; +// } //-- getDefaultPrimitiveNodeType +// +// +// /** +// * Returns an XML document parser implementing the requested +// * set of features. The feature list is a comma separated list +// * of features that parser may or may not support. No errors are +// * generated for unsupported features. If the feature list is not +// * null, it overrides the default feature list specified in the +// * configuration file, including validation and Namespaces. +// * +// * @return A suitable XML parser +// */ +// public XMLReader getXMLReader() +// { +// return getDefaultXMLReader( null ) ; +// +// } //-- getXMLReader +// +// /** +// * Returns an XML document parser implementing the requested +// * set of features. The feature list is a comma separated list +// * of features that parser may or may not support. No errors are +// * generated for unsupported features. If the feature list is not +// * null, it overrides the default feature list specified in the +// * configuration file, including validation and Namespaces. +// * +// * @return A suitable XML parser +// */ +// public static XMLReader getDefaultXMLReader() +// { +// return getDefaultXMLReader( null ) ; +// } //-- getDefaultXMLReader +// +// /** +// * Returns an XML document parser implementing the requested +// * set of features. The feature list is a comma separated list +// * of features that parser may or may not support. No errors are +// * generated for unsupported features. If the feature list is not +// * null, it overrides the default feature list specified in the +// * configuration file, including validation and Namespaces. +// * +// * @param features The requested feature list, null for the +// * defaults +// * @return A suitable XML parser +// */ +// public static XMLReader getDefaultXMLReader( String features ) +// { +// String prop; +// XMLReader reader = null; +// +// //-- validation? +// prop = getDefault().getProperty( Property.ParserValidation, "false" ); +// boolean validation = ( prop.equalsIgnoreCase( "true" ) || +// prop.equalsIgnoreCase( "on" ) ); +// +// //-- namespaces? +// prop = getDefault().getProperty( Property.Namespaces, "false" ); +// boolean namespaces = ( prop.equalsIgnoreCase( "true" ) || +// prop.equalsIgnoreCase( "on" ) ); +// +// +// //-- which parser? +// prop = getDefault().getProperty( Property.Parser ); +// if (( prop == null ) || (prop.length() == 0)) { +// // If no parser class was specified, check for JAXP +// // otherwise we default to Xerces. +// SAXParserFactory factory = SAXParserFactory.newInstance(); +// factory.setNamespaceAware(namespaces); +// factory.setValidating(validation); +// try { +// SAXParser saxParser = factory.newSAXParser(); +// reader = saxParser.getXMLReader(); +// } catch(ParserConfigurationException pcx) { +// LOG.error(Messages.format("conf.configurationError", pcx)); +// } catch(org.xml.sax.SAXException sx) { +// LOG.error(Messages.format("conf.configurationError", sx)); +// } +// +// } +// +// if (reader == null) { +// if ((prop == null) || +// (prop.length() == 0) || +// (prop.equalsIgnoreCase("xerces"))) +// { +// prop = "org.apache.xerces.parsers.SAXParser"; +// } +// +// // If a parser class was specified, we try to create it and +// // complain about creation error. +// try { +// Class cls; +// cls = Class.forName( prop ); +// reader = (XMLReader) cls.newInstance(); +// } catch ( Exception except ) { +// throw new RuntimeException( Messages.format( "conf.failedInstantiateParser", +// prop, except ) ); +// } +// } +// +// StringTokenizer token; +// setFeaturesOnXmlReader(getDefault(), features, validation, namespaces, reader); +// return reader; +// } //-- getDefaultXMLReader +// +// /** +// * Returns a new instance of the specified Regular Expression +// * Evaluator, or null if no validator was specified +// * +// * @return the regular expression evaluator, +// * @see #getDefaultRegExpEvaluator() +// */ +// public RegExpEvaluator getRegExpEvaluator() { +// return getDefaultRegExpEvaluator(); +// } //-- getRegExpEvaluator +// +// /** +// * Returns a new instance of the specified Regular Expression +// * Evaluator, or null if no validator was specified +// * +// * @return the regular expression evaluator, +// * +// * @see #getRegExpEvaluator() +// */ +// public static RegExpEvaluator getDefaultRegExpEvaluator() { +// +// String prop = getDefault().getProperty( Property.RegExp ); +// if ( prop == null ) return null; +// +// RegExpEvaluator regex = null; +// +// try { +// Class cls = _defaultValues.regExpEvalClass; +// if (cls == null) cls = Class.forName( prop ); +// regex = (RegExpEvaluator) cls.newInstance(); +// } +// catch ( Exception except ) { +// throw new RuntimeException( Messages.format( "conf.failedInstantiateRegExp", +// prop, except ) ); +// } +// +// return regex; +// } //-- getRegExpEvaluator +// +// /** +// * Returns a serializer for producing an XML instance document. +// * The caller can specify an alternative output format, may reuse +// * this serializer across several streams, and may serialize both +// * DOM and SAX events. +// * +// * Design note: This method should be overloaded by any +// * sub-classes. +// * +// * @return A suitable serializer +// * @see #getDefaultSerializer() +// */ +// public abstract Serializer getSerializer(); +// +// /** +// * Returns a default serializer for producing an XML document. +// * The caller can specify an alternative output format, may reuse +// * this serializer across several streams, and may serialize both +// * DOM and SAX events. If such control is not required, it is +// * recommended to call one of the other two methods. +// * +// * @return A suitable serializer +// * @see #getSerializer() +// */ +// public static Serializer getDefaultSerializer() { +// Serializer serializer = getSerializerFactory(getDefault()).getSerializer(); +// serializer.setOutputFormat(getDefaultOutputFormat()); +// return serializer; +// } +// +// /** +// * Returns the currently configured OutputFormat for use with a Serializer. +// * +// * Design note: This method should be overloaded by any +// * sub-classes. +// * +// * @return the currently configured OutputFormat. +// * @see #getDefaultOutputFormat() +// */ +// public abstract OutputFormat getOutputFormat(); +// +// /** +// * Returns the default OutputFormat for use with a Serializer. +// * +// * @return the default OutputFormat +// **/ +// public static OutputFormat getDefaultOutputFormat() { +// +// boolean indent = false; +// +// String prop = getDefault().getProperty( Property.Indent, "" ); +// +// //-- get default indentation +// indent = ( prop.equalsIgnoreCase( TRUE_VALUE ) || +// prop.equalsIgnoreCase( ON_VALUE ) ); +// +// OutputFormat format = getSerializerFactory(getDefault()).getOutputFormat(); +// format.setMethod(OutputFormat.XML); +// format.setIndenting(indent); +// +// // There is a bad interaction between the indentation and the +// // setPreserveSpace option. The indentated output is strangely indented. +// if (!indent) +// format.setPreserveSpace(true); +// +// return format; +// } //-- getOutputFormat +// +// +// /** +// * Returns a serializer for producing an XML document to +// * the designated output stream using the default serialization +// * format. +// * +// * Design note: This method should be overloaded by any +// * sub-classes. +// * +// * @param output the output stream +// * @return A suitable serializer +// */ +// public abstract DocumentHandler getSerializer( OutputStream output ) +// throws IOException; +// +// /** +// * Returns a default serializer for producing an XML document to +// * the designated output stream using the default serialization +// * format. +// * +// * @param output the output stream +// * @return A suitable serializer +// */ +// public static DocumentHandler getDefaultSerializer( OutputStream output ) +// throws IOException +// { +// Serializer serializer; +// DocumentHandler docHandler; +// +// serializer = getDefaultSerializer(); +// serializer.setOutputByteStream( output ); +// docHandler = serializer.asDocumentHandler(); +// if ( docHandler == null ) +// throw new RuntimeException( Messages.format( "conf.serializerNotSaxCapable", +// serializer.getClass().getName() ) ); +// return docHandler; +// } +// +// +// /** +// * Returns a serializer for producing an XML instance document to +// * the designated output stream using the default serialization +// * format. +// * +// * Design note: This method should be overloaded by any +// * sub-classes. +// * +// * @param output the Writer to write data to. +// * @return A suitable serializer +// */ +// public abstract DocumentHandler getSerializer( Writer output ) +// throws IOException; +// +// /** +// * Returns a default serializer for producing an XML document to +// * the designated output stream using the default serialization +// * format. +// * +// * @param output the Writer to write data to. +// * @return A suitable serializer +// */ +// public static DocumentHandler getDefaultSerializer( Writer output ) +// throws IOException +// { +// Serializer serializer; +// DocumentHandler docHandler; +// +// serializer = getDefaultSerializer(); +// serializer.setOutputCharStream( output ); +// docHandler = serializer.asDocumentHandler(); +// if ( docHandler == null ) +// throw new RuntimeException( Messages.format( "conf.serializerNotSaxCapable", +// serializer.getClass().getName() ) ); +// return docHandler; +// } /** - * Return an XML document parser implementing the feature list - * specified in the default configuration file. - * - * @return a suitable XML parser - * @see #getParser() - */ - public static Parser getDefaultParser() - { - return getDefaultParser( null ); - } //-- getDefaultParser - - - /** - * Returns an XML document parser implementing the requested - * set of features. The feature list is a comma separated list - * of features that parser may or may not support. No errors are - * generated for unsupported features. If the feature list is not - * null, it overrides the default feature list specified in the - * configuration file, including validation and Namespaces. - * - * @param features The requested feature list, null for the - * defaults - * @return A suitable XML parser - */ - public static Parser getDefaultParser( String features ) - { - String prop; - Parser parser; - - //-- validation? - prop = getDefault().getProperty( Property.ParserValidation, "false" ); - boolean validation = ( prop.equalsIgnoreCase( "true" ) || - prop.equalsIgnoreCase( "on" ) ); - - //-- namespaces? - prop = getDefault().getProperty( Property.Namespaces, "false" ); - boolean namespaces = ( prop.equalsIgnoreCase( "true" ) || - prop.equalsIgnoreCase( "on" ) ); - - - //-- which parser? - prop = getDefault().getProperty( Property.Parser ); - if (( prop == null ) || (prop.length() == 0)) { - // If no parser class was specified, check for JAXP - // otherwise we default to Xerces. - SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setNamespaceAware(namespaces); - factory.setValidating(validation); - try { - SAXParser saxParser = factory.newSAXParser(); - return saxParser.getParser(); - } - catch(ParserConfigurationException pcx) { - LOG.error(Messages.format("conf.configurationError", pcx)); - } - catch(org.xml.sax.SAXException sx) { - LOG.error(Messages.format("conf.configurationError", sx)); - } - - } - - - if ((prop == null) || - (prop.length() == 0) || - (prop.equalsIgnoreCase("xerces"))) - { - prop = "org.apache.xerces.parsers.SAXParser"; - } - - - // If a parser class was specified, we try to create it and - // complain about creation error. - try { - Class cls; - - cls = Class.forName( prop ); - parser = (Parser) cls.newInstance(); - } catch ( Exception except ) { - throw new RuntimeException( Messages.format( "conf.failedInstantiateParser", - prop, except ) ); - } - - if (parser instanceof XMLReader) { - XMLReader xmlReader = (XMLReader) parser; - setFeaturesOnXmlReader(getDefault(), features, validation, namespaces, xmlReader); - } - - return parser; - } - - /** - * Sets features on XML reader instance. - * @param features - * @param validation Whether to enable validation or not. - * @param namespaces Whether to enable namespace support for not. - * @param xmlReader The XMLReader instance to configure. - */ - protected static void setFeaturesOnXmlReader(final Properties properties, - String features, - final boolean validation, - final boolean namespaces, - final XMLReader xmlReader) { - try { - xmlReader.setFeature(Features.Validation, validation); - xmlReader.setFeature(Features.Namespaces, namespaces); - features = properties.getProperty(Property.ParserFeatures, features); - enableFeatures(features, xmlReader); - String featuresToDisable = getDefault().getProperty(Property.ParserFeaturesToDisable, ""); - disableFeatures(featuresToDisable, xmlReader); - } catch (SAXException except) { - LOG.error(Messages.format("conf.configurationError", except)); - } - } - - /** - * Enables selected features on the XMLReader instance - * @param features Features to enable - * @param xmlReader XMLReader instance to be configured. - * @throws SAXNotRecognizedException If the feature is not recognized by the XMLReader. - * @throws SAXNotSupportedException If the feature is not supported by the XMLReader. - */ - private static void enableFeatures(final String features, final XMLReader xmlReader) - throws SAXNotRecognizedException, SAXNotSupportedException { - StringTokenizer token; - if (features != null) { - token = new StringTokenizer(features, ", "); - while (token.hasMoreTokens()) { - xmlReader.setFeature(token.nextToken(), true); - } - } - } - - /** - * Disables selected features on the XMLReader instance - * @param features Features to disable - * @param xmlReader XMLReader instance to be configured. - * @throws SAXNotRecognizedException If the feature is not recognized by the XMLReader. - * @throws SAXNotSupportedException If the feature is not supported by the XMLReader. - */ - private static void disableFeatures(String features, final XMLReader xmlReader) - throws SAXNotRecognizedException, SAXNotSupportedException { - StringTokenizer token; - if (features != null) { - token = new StringTokenizer(features, ", "); - while (token.hasMoreTokens()) { - xmlReader.setFeature(token.nextToken(), false); - } - } - } - - /** - * Returns the currently configured NodeType to use for Java - * primitives. A null value will be returned if no NodeType was - * specified, indicating the default NodeType should be used. - * - * Design note: This method should be overloaded by any - * sub-classes. - * - * @return the NodeType assigned to Java primitives, or null - * if no NodeType was specified. - * @see #getDefaultPrimitiveNodeType() - */ - public NodeType getPrimitiveNodeType() { - return getDefaultPrimitiveNodeType(); - } //-- getPrimitiveNodeType - - - /** - * Returns the NodeType to use for Java primitives. - * A null value will be returned if no NodeType was specified, - * indicating the default NodeType should be used. - * - * @return the NodeType assigned to Java primitives, or null - * if no NodeType was specified. - * - * @see #getPrimitiveNodeType() - */ - public static NodeType getDefaultPrimitiveNodeType() { - - if (_defaultValues.primitiveNodeType != null) - return _defaultValues.primitiveNodeType; - - String prop = getDefaultProperty(Property.PrimitiveNodeType, null); - if (prop == null) return null; - - _defaultValues.primitiveNodeType = NodeType.getNodeType(prop); - return _defaultValues.primitiveNodeType; - } //-- getDefaultPrimitiveNodeType - - - /** - * Returns an XML document parser implementing the requested - * set of features. The feature list is a comma separated list - * of features that parser may or may not support. No errors are - * generated for unsupported features. If the feature list is not - * null, it overrides the default feature list specified in the - * configuration file, including validation and Namespaces. - * - * @return A suitable XML parser - */ - public XMLReader getXMLReader() - { - return getDefaultXMLReader( null ) ; - - } //-- getXMLReader - - /** - * Returns an XML document parser implementing the requested - * set of features. The feature list is a comma separated list - * of features that parser may or may not support. No errors are - * generated for unsupported features. If the feature list is not - * null, it overrides the default feature list specified in the - * configuration file, including validation and Namespaces. - * - * @return A suitable XML parser - */ - public static XMLReader getDefaultXMLReader() - { - return getDefaultXMLReader( null ) ; - } //-- getDefaultXMLReader - - /** - * Returns an XML document parser implementing the requested - * set of features. The feature list is a comma separated list - * of features that parser may or may not support. No errors are - * generated for unsupported features. If the feature list is not - * null, it overrides the default feature list specified in the - * configuration file, including validation and Namespaces. - * - * @param features The requested feature list, null for the - * defaults - * @return A suitable XML parser - */ - public static XMLReader getDefaultXMLReader( String features ) - { - String prop; - XMLReader reader = null; - - //-- validation? - prop = getDefault().getProperty( Property.ParserValidation, "false" ); - boolean validation = ( prop.equalsIgnoreCase( "true" ) || - prop.equalsIgnoreCase( "on" ) ); - - //-- namespaces? - prop = getDefault().getProperty( Property.Namespaces, "false" ); - boolean namespaces = ( prop.equalsIgnoreCase( "true" ) || - prop.equalsIgnoreCase( "on" ) ); - - - //-- which parser? - prop = getDefault().getProperty( Property.Parser ); - if (( prop == null ) || (prop.length() == 0)) { - // If no parser class was specified, check for JAXP - // otherwise we default to Xerces. - SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setNamespaceAware(namespaces); - factory.setValidating(validation); - try { - SAXParser saxParser = factory.newSAXParser(); - reader = saxParser.getXMLReader(); - } catch(ParserConfigurationException pcx) { - LOG.error(Messages.format("conf.configurationError", pcx)); - } catch(org.xml.sax.SAXException sx) { - LOG.error(Messages.format("conf.configurationError", sx)); - } - - } - - if (reader == null) { - if ((prop == null) || - (prop.length() == 0) || - (prop.equalsIgnoreCase("xerces"))) - { - prop = "org.apache.xerces.parsers.SAXParser"; - } - - // If a parser class was specified, we try to create it and - // complain about creation error. - try { - Class cls; - cls = Class.forName( prop ); - reader = (XMLReader) cls.newInstance(); - } catch ( Exception except ) { - throw new RuntimeException( Messages.format( "conf.failedInstantiateParser", - prop, except ) ); - } - } - - StringTokenizer token; - setFeaturesOnXmlReader(getDefault(), features, validation, namespaces, reader); - return reader; - } //-- getDefaultXMLReader - - /** - * Returns a new instance of the specified Regular Expression - * Evaluator, or null if no validator was specified - * - * @return the regular expression evaluator, - * @see #getDefaultRegExpEvaluator() - */ - public RegExpEvaluator getRegExpEvaluator() { - return getDefaultRegExpEvaluator(); - } //-- getRegExpEvaluator - - /** - * Returns a new instance of the specified Regular Expression - * Evaluator, or null if no validator was specified - * - * @return the regular expression evaluator, - * - * @see #getRegExpEvaluator() - */ - public static RegExpEvaluator getDefaultRegExpEvaluator() { - - String prop = getDefault().getProperty( Property.RegExp ); - if ( prop == null ) return null; - - RegExpEvaluator regex = null; - - try { - Class cls = _defaultValues.regExpEvalClass; - if (cls == null) cls = Class.forName( prop ); - regex = (RegExpEvaluator) cls.newInstance(); - } - catch ( Exception except ) { - throw new RuntimeException( Messages.format( "conf.failedInstantiateRegExp", - prop, except ) ); - } - - return regex; - } //-- getRegExpEvaluator - - /** - * Returns a serializer for producing an XML instance document. - * The caller can specify an alternative output format, may reuse - * this serializer across several streams, and may serialize both - * DOM and SAX events. - * - * Design note: This method should be overloaded by any - * sub-classes. - * - * @return A suitable serializer - * @see #getDefaultSerializer() - */ - public abstract Serializer getSerializer(); - - /** - * Returns a default serializer for producing an XML document. - * The caller can specify an alternative output format, may reuse - * this serializer across several streams, and may serialize both - * DOM and SAX events. If such control is not required, it is - * recommended to call one of the other two methods. - * - * @return A suitable serializer - * @see #getSerializer() - */ - public static Serializer getDefaultSerializer() { - Serializer serializer = getSerializerFactory(getDefault()).getSerializer(); - serializer.setOutputFormat(getDefaultOutputFormat()); - return serializer; - } - - /** - * Returns the currently configured OutputFormat for use with a Serializer. - * - * Design note: This method should be overloaded by any - * sub-classes. - * - * @return the currently configured OutputFormat. - * @see #getDefaultOutputFormat() - */ - public abstract OutputFormat getOutputFormat(); - - /** - * Returns the default OutputFormat for use with a Serializer. - * - * @return the default OutputFormat - **/ - public static OutputFormat getDefaultOutputFormat() { - - boolean indent = false; - - String prop = getDefault().getProperty( Property.Indent, "" ); - - //-- get default indentation - indent = ( prop.equalsIgnoreCase( TRUE_VALUE ) || - prop.equalsIgnoreCase( ON_VALUE ) ); - - OutputFormat format = getSerializerFactory(getDefault()).getOutputFormat(); - format.setMethod(OutputFormat.XML); - format.setIndenting(indent); - - // There is a bad interaction between the indentation and the - // setPreserveSpace option. The indentated output is strangely indented. - if (!indent) - format.setPreserveSpace(true); - - return format; - } //-- getOutputFormat - - - /** - * Returns a serializer for producing an XML document to - * the designated output stream using the default serialization - * format. - * - * Design note: This method should be overloaded by any - * sub-classes. - * - * @param output the output stream - * @return A suitable serializer - */ - public abstract DocumentHandler getSerializer( OutputStream output ) - throws IOException; - - /** - * Returns a default serializer for producing an XML document to - * the designated output stream using the default serialization - * format. - * - * @param output the output stream - * @return A suitable serializer - */ - public static DocumentHandler getDefaultSerializer( OutputStream output ) - throws IOException - { - Serializer serializer; - DocumentHandler docHandler; - - serializer = getDefaultSerializer(); - serializer.setOutputByteStream( output ); - docHandler = serializer.asDocumentHandler(); - if ( docHandler == null ) - throw new RuntimeException( Messages.format( "conf.serializerNotSaxCapable", - serializer.getClass().getName() ) ); - return docHandler; - } - - - /** - * Returns a serializer for producing an XML instance document to - * the designated output stream using the default serialization - * format. - * - * Design note: This method should be overloaded by any - * sub-classes. - * - * @param output the Writer to write data to. - * @return A suitable serializer - */ - public abstract DocumentHandler getSerializer( Writer output ) - throws IOException; - - /** - * Returns a default serializer for producing an XML document to - * the designated output stream using the default serialization - * format. - * - * @param output the Writer to write data to. - * @return A suitable serializer - */ - public static DocumentHandler getDefaultSerializer( Writer output ) - throws IOException - { - Serializer serializer; - DocumentHandler docHandler; - - serializer = getDefaultSerializer(); - serializer.setOutputCharStream( output ); - docHandler = serializer.asDocumentHandler(); - if ( docHandler == null ) - throw new RuntimeException( Messages.format( "conf.serializerNotSaxCapable", - serializer.getClass().getName() ) ); - return docHandler; - } - - /** * Called by {@link #getDefault} to load the configuration the * first time. Will not complain about inability to load * configuration file from one of the default directories, but if * it cannot find the JAR's configuration file, will throw a * run time exception. */ - protected static void loadDefaults() - { - _defaultProps = loadProperties( Property.ResourceName, Property.FileName); + protected static void loadDefaults() { + _defaultProps = loadProperties(Property.ResourceName, Property.FileName); - String prop; - prop = _defaultProps.getProperty( Property.Debug, "" ); - if ( prop.equalsIgnoreCase( "true" ) || prop.equalsIgnoreCase( "on" ) ) + String prop; + prop = _defaultProps.getProperty(Property.Debug, ""); + if (prop.equalsIgnoreCase("true") || prop.equalsIgnoreCase("on")) { _defaultValues.debug = true; - prop = _defaultProps.getProperty( Property.MarshallingValidation, "" ); - if ( prop.equalsIgnoreCase( "false" ) || prop.equalsIgnoreCase( "off" ) ) + } + prop = _defaultProps.getProperty(Property.MarshallingValidation, ""); + if (prop.equalsIgnoreCase("false") || prop.equalsIgnoreCase("off")) { _defaultValues.marshallingValidation = false; + } - prop = _defaultProps.getProperty( Property.StrictElements, "" ); - if ( prop.equalsIgnoreCase( "false" ) || prop.equalsIgnoreCase( "off" ) ) + prop = _defaultProps.getProperty(Property.StrictElements, ""); + if (prop.equalsIgnoreCase("false") || prop.equalsIgnoreCase("off")) { _defaultValues.strictElements = false; - else + } else { _defaultValues.strictElements = true; + } prop = null; } /** * Load the configuration will not complain about inability to load - * configuration file from one of the default directories, but if - * it cannot find the JAR's configuration file, will throw a - * run time exception. + * configuration file from one of the default directories, but if it cannot + * find the JAR's configuration file, will throw a run time exception. */ public static Properties loadProperties(String resourceName, String fileName) { @@ -1215,12 +1216,11 @@ return properties; } - - - /** - * Inner class to hold values of the configuration - */ - static class ConfigValues { + + /** + * Inner class to hold values of the configuration + */ + static class ConfigValues { /** * True if the configuration specified debugging. @@ -1259,26 +1259,26 @@ Class regExpEvalClass = null; } //-- class: ConfigValues - - /** - * Returns the currently configured XMLSerializerFactory instance. - * @param props Property set to use. - * @return XMLSerializerFactory to use by Castor - */ - static protected XMLSerializerFactory getSerializerFactory(Properties props) { - XMLSerializerFactory serializerFactory; - String serializerFactoryName = - props.getProperty(Property.SERIALIZER_FACTORY, Property.DEFAULT_SERIALIZER_FACTORY); - - try { - serializerFactory = (XMLSerializerFactory) - Class.forName(serializerFactoryName).newInstance(); - } catch (Exception except) { - throw new RuntimeException( - Messages.format("conf.failedInstantiateSerializerFactory", - serializerFactoryName, except)); - } - return serializerFactory; - } +// +// /** +// * Returns the currently configured XMLSerializerFactory instance. +// * @param props Property set to use. +// * @return XMLSerializerFactory to use by Castor +// */ +// static protected XMLSerializerFactory getSerializerFactory(Properties props) { +// XMLSerializerFactory serializerFactory; +// String serializerFactoryName = +// props.getProperty(Property.SERIALIZER_FACTORY, Property.DEFAULT_SERIALIZER_FACTORY); +// +// try { +// serializerFactory = (XMLSerializerFactory) +// Class.forName(serializerFactoryName).newInstance(); +// } catch (Exception except) { +// throw new RuntimeException( +// Messages.format("conf.failedInstantiateSerializerFactory", +// serializerFactoryName, except)); +// } +// return serializerFactory; +// } } //-- Configuration Index: src/main/java/org/exolab/castor/util/LocalConfiguration.java =================================================================== --- src/main/java/org/exolab/castor/util/LocalConfiguration.java (revision 7156) +++ src/main/java/org/exolab/castor/util/LocalConfiguration.java (working copy) @@ -99,7 +99,7 @@ * The Jakarta * Commons Logging instance used for all logging. */ - private static final Log _log = LogFactory.getFactory().getInstance(LocalConfiguration.class); + private static final Log LOG = LogFactory.getFactory().getInstance(LocalConfiguration.class); /** * The properties loaded from the local configuration file. @@ -216,381 +216,381 @@ } return _props; } +// +// /** +// * Returns the naming conventions to use for the XML framework +// * +// * @return the naming conventions to use for the XML framework +// */ +// public XMLNaming getXMLNaming() { +// return getXMLNaming(null); +// } +// +// /** +// * Returns the naming conventions to use for the XML framework +// * +// * @return the naming conventions to use for the XML framework +// */ +// public XMLNaming getXMLNaming(ClassLoader classLoader) { +// +// if (_values.naming != null) return _values.naming; +// +// String prop = getProperty( Property.Naming, null); +// if ((prop == null) || (prop.equalsIgnoreCase("lower"))) { +// _values.naming = new DefaultNaming(); +// } +// else if (prop.equalsIgnoreCase("mixed")) { +// DefaultNaming dn = new DefaultNaming(); +// dn.setStyle(DefaultNaming.MIXED_CASE_STYLE); +// _values.naming = dn; +// } +// else { +// try { +// Class cls = null; +// if (classLoader != null) { +// cls = classLoader.loadClass(prop); +// } else { +// cls = Class.forName(prop); +// } +// _values.naming = (XMLNaming) cls.newInstance(); +// } +// catch (Exception except) { +// throw new RuntimeException("Failed to load XMLNaming: " + +// except); +// } +// } +// return _values.naming; +// } //-- getXMLNaming +// +// /** +// * The {@link JavaNaming} instance to be used. +// * @return {@link JavaNaming} instance to be used. +// */ +// public JavaNaming getJavaNaming() { +// return new JavaNamingImpl(); +// } +// +// /** +// * Return an XML document parser implementing the feature list +// * specified in the configuration file. +// * +// * @return A suitable XML parser +// */ +// public Parser getParser() +// { +// return getParser( null ); +// } +// +// +// /** +// * Returns an XML document parser implementing the requested +// * set of features. The feature list is a comma separated list +// * of features that parser may or may not support. No errors are +// * generated for unsupported features. If the feature list is not +// * null, it overrides the default feature list specified in the +// * configuration file, including validation and Namespaces. +// * +// * @param features The requested feature list, null for the +// * defaults +// * @return A suitable XML parser +// */ +// public Parser getParser(final String features) +// { +// String prop; +// Parser parser; +// +// //-- validation? +// prop = getProperties().getProperty( Property.ParserValidation, "false" ); +// boolean validation = ( prop.equalsIgnoreCase( "true" ) || +// prop.equalsIgnoreCase( "on" ) ); +// +// //-- namespaces? +// prop = getProperties().getProperty( Property.Namespaces, "false" ); +// boolean namespaces = ( prop.equalsIgnoreCase( "true" ) || +// prop.equalsIgnoreCase( "on" ) ); +// +// +// //-- which parser? +// prop = getProperties().getProperty( Property.Parser ); +// if (( prop == null ) || (prop.length() == 0)) { +// // If no parser class was specified, check for JAXP +// // otherwise we default to Xerces. +// SAXParserFactory factory = SAXParserFactory.newInstance(); +// factory.setNamespaceAware(namespaces); +// factory.setValidating(validation); +// try { +// SAXParser saxParser = factory.newSAXParser(); +// return saxParser.getParser(); +// } +// catch(ParserConfigurationException pcx) { +// _log.error( Messages.format( "conf.configurationError", pcx ) ); +// } +// catch(org.xml.sax.SAXException sx) { +// _log.error( Messages.format( "conf.configurationError", sx ) ); +// } +// +// } +// +// if ((prop == null) || +// (prop.length() == 0) || +// (prop.equalsIgnoreCase("xerces"))) +// { +// prop = "org.apache.xerces.parsers.SAXParser"; +// } +// +// +// // If a parser class was specified, we try to create it and +// // complain about creation error. +// try { +// Class cls; +// +// cls = Class.forName( prop ); +// parser = (Parser) cls.newInstance(); +// } catch ( Exception except ) { +// throw new RuntimeException( Messages.format( "conf.failedInstantiateParser", +// prop, except ) ); +// } +// +// if (parser instanceof XMLReader) { +// XMLReader xmlReader = (XMLReader) parser; +// setFeaturesOnXmlReader(getProperties(), features, validation, namespaces, xmlReader); +// } +// +// return parser; +// +// } +// +// /** +// * Returns an XML document parser implementing the requested +// * set of features. The feature list is a comma separated list +// * of features that parser may or may not support. No errors are +// * generated for unsupported features. If the feature list is not +// * null, it overrides the default feature list specified in the +// * configuration file, including validation and Namespaces. +// * +// * @return A suitable XML parser +// */ +// public XMLReader getXMLReader() +// { +// return getXMLReader( null ) ; +// +// } //-- getXMLReader +// +// /** +// * Returns an XML document parser implementing the requested +// * set of features. The feature list is a comma separated list +// * of features that parser may or may not support. No errors are +// * generated for unsupported features. If the feature list is not +// * null, it overrides the default feature list specified in the +// * configuration file, including validation and Namespaces. +// * +// * @return A suitable XML parser +// */ +// public XMLReader getXMLReader( String features ) +// { +// +// String prop; +// XMLReader reader = null; +// +// //-- validation? +// prop = getProperties().getProperty( Property.ParserValidation, "false" ); +// boolean validation = ( prop.equalsIgnoreCase( "true" ) || +// prop.equalsIgnoreCase( "on" ) ); +// +// //-- namespaces? +// prop = getProperties().getProperty( Property.Namespaces, "false" ); +// boolean namespaces = ( prop.equalsIgnoreCase( "true" ) || +// prop.equalsIgnoreCase( "on" ) ); +// +// +// //-- which parser? +// prop = getProperties().getProperty( Property.Parser ); +// if (( prop == null ) || (prop.length() == 0)) { +// // If no parser class was specified, check for JAXP +// // otherwise we default to Xerces. +// SAXParserFactory factory = SAXParserFactory.newInstance(); +// factory.setNamespaceAware(namespaces); +// factory.setValidating(validation); +// try { +// SAXParser saxParser = factory.newSAXParser(); +// reader = saxParser.getXMLReader(); +// } +// catch(ParserConfigurationException pcx) { +// _log.error( Messages.format( "conf.configurationError", pcx ) ); +// } +// catch(org.xml.sax.SAXException sx) { +// _log.error( Messages.format( "conf.configurationError", sx ) ); +// } +// +// } +// +// if (reader == null) { +// if ((prop == null) || +// (prop.length() == 0) || +// (prop.equalsIgnoreCase("xerces"))) +// { +// prop = "org.apache.xerces.parsers.SAXParser"; +// } +// +// +// // If a parser class was specified, we try to create it and +// // complain about creation error. +// try { +// Class cls; +// +// cls = Class.forName( prop ); +// reader = (XMLReader) cls.newInstance(); +// } catch ( Exception except ) { +// throw new RuntimeException( Messages.format( "conf.failedInstantiateParser", +// prop, except ) ); +// } +// } +// +// setFeaturesOnXmlReader(getProperties(), features, validation, namespaces, reader); +// +// return reader; +// +// } //-- getXMLReader +// +// +// /** +// * Returns the NodeType to use for Java primitives. +// * A null value will be returned if no NodeType was specified, +// * indicating the default NodeType should be used. +// * +// * @return the NodeType assigned to Java primitives, or null +// * if no NodeType was specified. +// **/ +// public NodeType getPrimitiveNodeType() { +// +// if (_values.primitiveNodeType != null) +// return _values.primitiveNodeType; +// +// String prop = getProperty(Property.PrimitiveNodeType, null); +// if (prop == null) return null; +// _values.primitiveNodeType = NodeType.getNodeType(prop); +// return _values.primitiveNodeType; +// } //-- getPrimitiveNodeType +// +// /** +// * Returns a new instance of the specified Regular Expression +// * Evaluator, or null if no validator was specified +// * +// * @return the regular expression evaluator, +// * +// **/ +// public RegExpEvaluator getRegExpEvaluator() { +// +// String prop = getProperties().getProperty( Property.RegExp ); +// +// RegExpEvaluator regex = null; +// +// if ( prop == null ) return null; +// try { +// if (_values.regExpEvalClass == null) { +// _values.regExpEvalClass = Class.forName( prop ); +// } +// regex = (RegExpEvaluator) _values.regExpEvalClass.newInstance(); +// } +// catch ( Exception except ) { +// throw new RuntimeException( Messages.format( "conf.failedInstantiateRegExp", +// prop, except ) ); +// } +// +// return regex; +// } //-- getRegExpEvaluator +// +// /** +// * Returns a default serializer for producing an XML document. +// * The caller can specify an alternative output format, may reuse +// * this serializer across several streams, and may serialize both +// * DOM and SAX events. If such control is not required, it is +// * recommended to call one of the other two methods. +// * +// * @return A suitable serializer +// */ +// public Serializer getSerializer() { +// Serializer serializer = getSerializerFactory(_props).getSerializer(); +// serializer.setOutputFormat(getOutputFormat()); +// return serializer; +// } +// +// /** +// * Returns the default OutputFormat for use with a Serializer. +// * +// * @return the default OutputFormat +// **/ +// public OutputFormat getOutputFormat() { +// +// boolean indent = false; +// +// String prop = _props.getProperty( Property.Indent, "" ); +// +// //-- get default indentation +// indent = ( prop.equalsIgnoreCase( TRUE_VALUE ) || +// prop.equalsIgnoreCase( ON_VALUE ) ); +// +// OutputFormat format = getSerializerFactory(_props).getOutputFormat(); +// format.setMethod(OutputFormat.XML); +// format.setIndenting(indent); +// +// // There is a bad interaction between the indentation and the +// // setPreserveSpace option. The indentated output is strangely indented. +// if (!indent) +// format.setPreserveSpace(true); +// +// return format; +// } //-- getOutputFormat +// +// +// /** +// * Returns a default serializer for producing an XML document to +// * the designated output stream using the default serialization +// * format. +// * +// * @param output The output stream +// * @return A suitable serializer +// */ +// public DocumentHandler getSerializer( OutputStream output ) +// throws IOException +// { +// Serializer serializer; +// DocumentHandler docHandler; +// +// serializer = getSerializer(); +// serializer.setOutputByteStream( output ); +// docHandler = serializer.asDocumentHandler(); +// if ( docHandler == null ) +// throw new RuntimeException( Messages.format( "conf.serializerNotSaxCapable", +// serializer.getClass().getName() ) ); +// return docHandler; +// } +// +// +// /** +// * Returns a default serializer for producing an XML document to +// * the designated output stream using the default serialization +// * format. +// * +// * @param output The output stream +// * @return A suitable serializer +// */ +// public DocumentHandler getSerializer( Writer output ) +// throws IOException +// { +// Serializer serializer; +// DocumentHandler docHandler; +// +// serializer = getSerializer(); +// serializer.setOutputCharStream( output ); +// docHandler = serializer.asDocumentHandler(); +// if ( docHandler == null ) +// throw new RuntimeException( Messages.format( "conf.serializerNotSaxCapable", +// serializer.getClass().getName() ) ); +// return docHandler; +// } /** - * Returns the naming conventions to use for the XML framework - * - * @return the naming conventions to use for the XML framework - */ - public XMLNaming getXMLNaming() { - return getXMLNaming(null); - } - - /** - * Returns the naming conventions to use for the XML framework - * - * @return the naming conventions to use for the XML framework - */ - public XMLNaming getXMLNaming(ClassLoader classLoader) { - - if (_values.naming != null) return _values.naming; - - String prop = getProperty( Property.Naming, null); - if ((prop == null) || (prop.equalsIgnoreCase("lower"))) { - _values.naming = new DefaultNaming(); - } - else if (prop.equalsIgnoreCase("mixed")) { - DefaultNaming dn = new DefaultNaming(); - dn.setStyle(DefaultNaming.MIXED_CASE_STYLE); - _values.naming = dn; - } - else { - try { - Class cls = null; - if (classLoader != null) { - cls = classLoader.loadClass(prop); - } else { - cls = Class.forName(prop); - } - _values.naming = (XMLNaming) cls.newInstance(); - } - catch (Exception except) { - throw new RuntimeException("Failed to load XMLNaming: " + - except); - } - } - return _values.naming; - } //-- getXMLNaming - - /** - * The {@link JavaNaming} instance to be used. - * @return {@link JavaNaming} instance to be used. - */ - public JavaNaming getJavaNaming() { - return new JavaNamingImpl(); - } - - /** - * Return an XML document parser implementing the feature list - * specified in the configuration file. - * - * @return A suitable XML parser - */ - public Parser getParser() - { - return getParser( null ); - } - - - /** - * Returns an XML document parser implementing the requested - * set of features. The feature list is a comma separated list - * of features that parser may or may not support. No errors are - * generated for unsupported features. If the feature list is not - * null, it overrides the default feature list specified in the - * configuration file, including validation and Namespaces. - * - * @param features The requested feature list, null for the - * defaults - * @return A suitable XML parser - */ - public Parser getParser(final String features) - { - String prop; - Parser parser; - - //-- validation? - prop = getProperties().getProperty( Property.ParserValidation, "false" ); - boolean validation = ( prop.equalsIgnoreCase( "true" ) || - prop.equalsIgnoreCase( "on" ) ); - - //-- namespaces? - prop = getProperties().getProperty( Property.Namespaces, "false" ); - boolean namespaces = ( prop.equalsIgnoreCase( "true" ) || - prop.equalsIgnoreCase( "on" ) ); - - - //-- which parser? - prop = getProperties().getProperty( Property.Parser ); - if (( prop == null ) || (prop.length() == 0)) { - // If no parser class was specified, check for JAXP - // otherwise we default to Xerces. - SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setNamespaceAware(namespaces); - factory.setValidating(validation); - try { - SAXParser saxParser = factory.newSAXParser(); - return saxParser.getParser(); - } - catch(ParserConfigurationException pcx) { - _log.error( Messages.format( "conf.configurationError", pcx ) ); - } - catch(org.xml.sax.SAXException sx) { - _log.error( Messages.format( "conf.configurationError", sx ) ); - } - - } - - if ((prop == null) || - (prop.length() == 0) || - (prop.equalsIgnoreCase("xerces"))) - { - prop = "org.apache.xerces.parsers.SAXParser"; - } - - - // If a parser class was specified, we try to create it and - // complain about creation error. - try { - Class cls; - - cls = Class.forName( prop ); - parser = (Parser) cls.newInstance(); - } catch ( Exception except ) { - throw new RuntimeException( Messages.format( "conf.failedInstantiateParser", - prop, except ) ); - } - - if (parser instanceof XMLReader) { - XMLReader xmlReader = (XMLReader) parser; - setFeaturesOnXmlReader(getProperties(), features, validation, namespaces, xmlReader); - } - - return parser; - - } - - /** - * Returns an XML document parser implementing the requested - * set of features. The feature list is a comma separated list - * of features that parser may or may not support. No errors are - * generated for unsupported features. If the feature list is not - * null, it overrides the default feature list specified in the - * configuration file, including validation and Namespaces. - * - * @return A suitable XML parser - */ - public XMLReader getXMLReader() - { - return getXMLReader( null ) ; - - } //-- getXMLReader - - /** - * Returns an XML document parser implementing the requested - * set of features. The feature list is a comma separated list - * of features that parser may or may not support. No errors are - * generated for unsupported features. If the feature list is not - * null, it overrides the default feature list specified in the - * configuration file, including validation and Namespaces. - * - * @return A suitable XML parser - */ - public XMLReader getXMLReader( String features ) - { - - String prop; - XMLReader reader = null; - - //-- validation? - prop = getProperties().getProperty( Property.ParserValidation, "false" ); - boolean validation = ( prop.equalsIgnoreCase( "true" ) || - prop.equalsIgnoreCase( "on" ) ); - - //-- namespaces? - prop = getProperties().getProperty( Property.Namespaces, "false" ); - boolean namespaces = ( prop.equalsIgnoreCase( "true" ) || - prop.equalsIgnoreCase( "on" ) ); - - - //-- which parser? - prop = getProperties().getProperty( Property.Parser ); - if (( prop == null ) || (prop.length() == 0)) { - // If no parser class was specified, check for JAXP - // otherwise we default to Xerces. - SAXParserFactory factory = SAXParserFactory.newInstance(); - factory.setNamespaceAware(namespaces); - factory.setValidating(validation); - try { - SAXParser saxParser = factory.newSAXParser(); - reader = saxParser.getXMLReader(); - } - catch(ParserConfigurationException pcx) { - _log.error( Messages.format( "conf.configurationError", pcx ) ); - } - catch(org.xml.sax.SAXException sx) { - _log.error( Messages.format( "conf.configurationError", sx ) ); - } - - } - - if (reader == null) { - if ((prop == null) || - (prop.length() == 0) || - (prop.equalsIgnoreCase("xerces"))) - { - prop = "org.apache.xerces.parsers.SAXParser"; - } - - - // If a parser class was specified, we try to create it and - // complain about creation error. - try { - Class cls; - - cls = Class.forName( prop ); - reader = (XMLReader) cls.newInstance(); - } catch ( Exception except ) { - throw new RuntimeException( Messages.format( "conf.failedInstantiateParser", - prop, except ) ); - } - } - - setFeaturesOnXmlReader(getProperties(), features, validation, namespaces, reader); - - return reader; - - } //-- getXMLReader - - - /** - * Returns the NodeType to use for Java primitives. - * A null value will be returned if no NodeType was specified, - * indicating the default NodeType should be used. - * - * @return the NodeType assigned to Java primitives, or null - * if no NodeType was specified. - **/ - public NodeType getPrimitiveNodeType() { - - if (_values.primitiveNodeType != null) - return _values.primitiveNodeType; - - String prop = getProperty(Property.PrimitiveNodeType, null); - if (prop == null) return null; - _values.primitiveNodeType = NodeType.getNodeType(prop); - return _values.primitiveNodeType; - } //-- getPrimitiveNodeType - - /** - * Returns a new instance of the specified Regular Expression - * Evaluator, or null if no validator was specified - * - * @return the regular expression evaluator, - * - **/ - public RegExpEvaluator getRegExpEvaluator() { - - String prop = getProperties().getProperty( Property.RegExp ); - - RegExpEvaluator regex = null; - - if ( prop == null ) return null; - try { - if (_values.regExpEvalClass == null) { - _values.regExpEvalClass = Class.forName( prop ); - } - regex = (RegExpEvaluator) _values.regExpEvalClass.newInstance(); - } - catch ( Exception except ) { - throw new RuntimeException( Messages.format( "conf.failedInstantiateRegExp", - prop, except ) ); - } - - return regex; - } //-- getRegExpEvaluator - - /** - * Returns a default serializer for producing an XML document. - * The caller can specify an alternative output format, may reuse - * this serializer across several streams, and may serialize both - * DOM and SAX events. If such control is not required, it is - * recommended to call one of the other two methods. - * - * @return A suitable serializer - */ - public Serializer getSerializer() { - Serializer serializer = getSerializerFactory(_props).getSerializer(); - serializer.setOutputFormat(getOutputFormat()); - return serializer; - } - - /** - * Returns the default OutputFormat for use with a Serializer. - * - * @return the default OutputFormat - **/ - public OutputFormat getOutputFormat() { - - boolean indent = false; - - String prop = _props.getProperty( Property.Indent, "" ); - - //-- get default indentation - indent = ( prop.equalsIgnoreCase( TRUE_VALUE ) || - prop.equalsIgnoreCase( ON_VALUE ) ); - - OutputFormat format = getSerializerFactory(_props).getOutputFormat(); - format.setMethod(OutputFormat.XML); - format.setIndenting(indent); - - // There is a bad interaction between the indentation and the - // setPreserveSpace option. The indentated output is strangely indented. - if (!indent) - format.setPreserveSpace(true); - - return format; - } //-- getOutputFormat - - - /** - * Returns a default serializer for producing an XML document to - * the designated output stream using the default serialization - * format. - * - * @param output The output stream - * @return A suitable serializer - */ - public DocumentHandler getSerializer( OutputStream output ) - throws IOException - { - Serializer serializer; - DocumentHandler docHandler; - - serializer = getSerializer(); - serializer.setOutputByteStream( output ); - docHandler = serializer.asDocumentHandler(); - if ( docHandler == null ) - throw new RuntimeException( Messages.format( "conf.serializerNotSaxCapable", - serializer.getClass().getName() ) ); - return docHandler; - } - - - /** - * Returns a default serializer for producing an XML document to - * the designated output stream using the default serialization - * format. - * - * @param output The output stream - * @return A suitable serializer - */ - public DocumentHandler getSerializer( Writer output ) - throws IOException - { - Serializer serializer; - DocumentHandler docHandler; - - serializer = getSerializer(); - serializer.setOutputCharStream( output ); - docHandler = serializer.asDocumentHandler(); - if ( docHandler == null ) - throw new RuntimeException( Messages.format( "conf.serializerNotSaxCapable", - serializer.getClass().getName() ) ); - return docHandler; - } - - /** * Indicates whether validation for sequence order should be lenient. * * @return True if sequence order validation should be lenient. @@ -669,8 +669,8 @@ URL url = getClass().getResource("/" + fileOrResourceName); if (url != null) { _resourceUrl = url.toString(); - if(_log.isDebugEnabled()) { - _log.debug ("Trying to load configuration file from " + _resourceUrl); + if(LOG.isDebugEnabled()) { + LOG.debug ("Trying to load configuration file from " + _resourceUrl); } _props.load( url.openStream() ); //-- debug information Index: codegen/src/main/java/org/exolab/castor/builder/SourceGenerator.java =================================================================== --- codegen/src/main/java/org/exolab/castor/builder/SourceGenerator.java (revision 7156) +++ codegen/src/main/java/org/exolab/castor/builder/SourceGenerator.java (working copy) @@ -87,6 +87,7 @@ import org.exolab.castor.util.dialog.ConsoleDialog; import org.exolab.castor.xml.Marshaller; import org.exolab.castor.xml.ValidationException; +import org.exolab.castor.xml.XMLContext; import org.exolab.castor.xml.XMLException; import org.exolab.castor.xml.schema.AttributeDecl; import org.exolab.castor.xml.schema.ComplexType; @@ -141,6 +142,8 @@ //- Instance Variables -/ //----------------------/ + /** Castor XML Context - mother of all. */ + private final XMLContext _xmlContext; /** Castor configuration. */ private final Configuration _config; /** The XMLBindingComponent used to create Java classes from an XML Schema. */ @@ -223,8 +226,9 @@ public SourceGenerator(final FieldInfoFactory infoFactory, final ExtendedBinding binding) { super(); + _xmlContext = new XMLContext(); _config = LocalConfiguration.getInstance(); - setJavaNaming(new JavaNamingImpl()); + setJavaNaming(_xmlContext.getJavaNaming()); _dialog = new ConsoleDialog(); _infoFactory = (infoFactory == null) ? new FieldInfoFactory() : infoFactory; @@ -577,7 +581,7 @@ // -- get default parser from Configuration Parser parser = null; try { - parser = _config.getParser(); + parser = _xmlContext.getParser(); } catch (RuntimeException rte) { // ignore } @@ -589,7 +593,7 @@ SchemaUnmarshaller schemaUnmarshaller = null; try { - schemaUnmarshaller = new SchemaUnmarshaller(); + schemaUnmarshaller = new SchemaUnmarshaller(_xmlContext); } catch (XMLException e) { //--The default constructor cannot throw exception so this should never happen //--just log the exception Index: anttask/src/main/java/org/castor/anttask/CastorCodeGenTask.java =================================================================== --- anttask/src/main/java/org/castor/anttask/CastorCodeGenTask.java (revision 7156) +++ anttask/src/main/java/org/castor/anttask/CastorCodeGenTask.java (working copy) @@ -59,6 +59,7 @@ import org.exolab.castor.builder.binding.ExtendedBinding; import org.exolab.castor.builder.factory.FieldInfoFactory; import org.exolab.castor.util.LocalConfiguration; +import org.exolab.castor.xml.XMLContext; import org.exolab.castor.xml.XMLException; import org.exolab.castor.xml.schema.Schema; import org.exolab.castor.xml.schema.reader.Sax2ComponentReader; @@ -101,6 +102,9 @@ //-------------------------------------------------------------------------- + /** Castor XML context - the mother of all. */ + private XMLContext _xmlContext; + /** If processing one schema file, this lists the file. */ private File _schemaFile = null; @@ -169,7 +173,8 @@ * No-arg constructor. */ public CastorCodeGenTask() { - // Nothing needed + super(); + _xmlContext = new XMLContext(); } //-------------------------------------------------------------------------- @@ -552,7 +557,7 @@ public void generateSource(final InputSource source, final String packageName) { Parser parser = null; try { - parser = LocalConfiguration.getInstance().getParser(); + parser = _xmlContext.getParser(); } catch (RuntimeException e) { throw new BuildException("Unable to create SAX parser.", e); } @@ -562,7 +567,7 @@ SchemaUnmarshaller schemaUnmarshaller = null; try { - schemaUnmarshaller = new SchemaUnmarshaller(); + schemaUnmarshaller = new SchemaUnmarshaller(_xmlContext); } catch (XMLException e) { throw new BuildException("Unable to create schema unmarshaller.", e); }