Index: src/test/java/org/exolab/castor/xml/XMLContextTest.java =================================================================== --- src/test/java/org/exolab/castor/xml/XMLContextTest.java (revision 7170) +++ 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 7170) +++ 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 7170) +++ 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/tools/MappingTool.java =================================================================== --- src/main/java/org/exolab/castor/tools/MappingTool.java (revision 7170) +++ src/main/java/org/exolab/castor/tools/MappingTool.java (working copy) @@ -52,9 +52,7 @@ import java.util.Hashtable; import java.util.Properties; -import org.castor.mapping.BindingType; import org.castor.xml.JavaNaming; -import org.castor.xml.JavaNamingImpl; import org.exolab.castor.mapping.FieldDescriptor; import org.exolab.castor.mapping.MappingException; import org.exolab.castor.mapping.loader.CollectionHandlers; @@ -69,11 +67,11 @@ import org.exolab.castor.mapping.xml.types.FieldMappingCollectionType; import org.exolab.castor.util.CommandLineOptions; import org.exolab.castor.util.dialog.ConsoleDialog; -import org.exolab.castor.xml.ClassDescriptorResolverFactory; import org.exolab.castor.xml.Introspector; import org.exolab.castor.xml.Marshaller; import org.exolab.castor.xml.XMLClassDescriptor; import org.exolab.castor.xml.XMLClassDescriptorResolver; +import org.exolab.castor.xml.XMLContext; import org.exolab.castor.xml.XMLFieldDescriptor; /** @@ -89,10 +87,10 @@ private static final String UNDERSCORE = "_"; /** Hashtable of already generated mappings. */ - private final Hashtable _mappings; + private Hashtable _mappings; /** ClassDescriptorResolver for loading compiled descriptors. */ - private final XMLClassDescriptorResolver _resolver; + private XMLClassDescriptorResolver _resolver; /** Introspector to use if _forceIntrospection is enabled. */ private Introspector _introspector = null; @@ -101,7 +99,7 @@ * The internal MappingLoader to use for checking whether or not we can find * the proper accessor methods. */ - private final MappingToolMappingLoader _mappingLoader; + private MappingToolMappingLoader _mappingLoader; /** * Boolean to indicate that we should always perform introspection for each @@ -117,17 +115,15 @@ private JavaNaming _javaNaming; /** + * The XMLContext (mother of all dwelling). + */ + private XMLContext _xmlContext; + + /** * Constructor, builds up the relations. - * - * @param javaNaming - * a JavaNaming methods needs to be specified */ - public MappingTool(final JavaNaming javaNaming) { - _mappings = new Hashtable(); - _resolver = (XMLClassDescriptorResolver) ClassDescriptorResolverFactory - .createClassDescriptorResolver(BindingType.XML); - _javaNaming = javaNaming; - _mappingLoader = new MappingToolMappingLoader(_javaNaming); + public MappingTool() { + super(); } // --MappingTool /** @@ -179,7 +175,8 @@ MappingTool tool; try { - tool = new MappingTool(new JavaNamingImpl()); + tool = new MappingTool(); + tool.setXMLContext(new XMLContext()); tool.addClass(classname); Writer writer = null; @@ -454,11 +451,12 @@ */ public void setForceIntrospection(final boolean force) { _forceIntrospection = force; - if (force) { - if (_introspector == null) { - _introspector = new Introspector(); - } - } +// Joachim: no longer required as the Introspector is taken from XMLContext +// if (force) { +// if (_introspector == null) { +// _introspector = new Introspector(); +// } +// } } // -- setForceInstrospection /** @@ -488,5 +486,18 @@ throw new MappingException(except); } } // -- write + + /** + * To set the XMLContext to be used. + * @param xmlContext the XMLContext to be used + */ + public void setXMLContext(final XMLContext xmlContext) { + _xmlContext = xmlContext; + _mappings = new Hashtable(); + _resolver = _xmlContext.getXMLClassDescriptorResolver(); + _javaNaming = _xmlContext.getJavaNaming(); + _mappingLoader = new MappingToolMappingLoader(_javaNaming); + _introspector = _xmlContext.getIntrospector(); + } } // -- MappingTool Index: src/main/java/org/exolab/castor/xml/XMLMappingLoader.java =================================================================== --- src/main/java/org/exolab/castor/xml/XMLMappingLoader.java (revision 7170) +++ 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(); } //----------------------------------------------------------------------------------- @@ -288,7 +292,7 @@ } if (referenceDesc == null) { - Introspector introspector = new Introspector(); + Introspector introspector = _xmlContext.getIntrospector(); try { referenceDesc = introspector.generateClassDescriptor(type); if (clsMap.getExtends() != null) { @@ -398,7 +402,7 @@ private void createResolver() { _cdResolver = (XMLClassDescriptorResolverImpl) ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML); - _cdResolver.setIntrospection(false); + _cdResolver.setUseIntrospection(false); _cdResolver.setLoadPackageMappings(false); } Index: src/main/java/org/exolab/castor/xml/XMLContext.java =================================================================== --- src/main/java/org/exolab/castor/xml/XMLContext.java (revision 7170) +++ src/main/java/org/exolab/castor/xml/XMLContext.java (working copy) @@ -15,11 +15,46 @@ */ 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.tools.MappingTool; +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.Resolver; +import org.exolab.castor.xml.schema.ScopableResolver; +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.exolab.castor.xml.util.ResolverStrategy; +import org.exolab.castor.xml.util.resolvers.CastorXMLStrategy; +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 +64,65 @@ * @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 ContextManagedValues _contextManagedValues = new ContextManagedValues(); + /** * {@link XMLClassDescriptorResolver} instance used for caching XML-related * class descriptors. */ - private XMLClassDescriptorResolver resolver; + private XMLClassDescriptorResolver _xmlClassDescriptorResolver; + + /** + * The XMLContext knows the one Introspector to be used. + */ + private Introspector _introspector; /** + * The {@link Resolver} to be used by Schema* stuff. + */ + private Resolver _schemaResolver; + + /** + * The XMLClassDescriptor resolver strategy to use. + */ + private ResolverStrategy _resolverStrategy; + + /** + * The {@link MappingLoader} to use. + */ + private MappingLoader _mappingLoader; + + /** + * The 'use introspector' flag. + */ + private Boolean _useIntrospector; + + /** * Creates an instance of {@link XMLContext}, preconfigured with class descriptors * loaded for the given package name. */ public XMLContext() { - resolver = (XMLClassDescriptorResolver) ClassDescriptorResolverFactory + _config = LocalConfiguration.getInstance(); + _xmlClassDescriptorResolver = (XMLClassDescriptorResolver) ClassDescriptorResolverFactory .createClassDescriptorResolver(BindingType.XML); - resolver.setClassLoader(getClass().getClassLoader()); + _xmlClassDescriptorResolver.setClassLoader(getClass().getClassLoader()); + _xmlClassDescriptorResolver.setResolverStrategy(new CastorXMLStrategy()); + _introspector = new Introspector(this); + _schemaResolver = new ScopableResolver(); } /** @@ -52,10 +131,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); + _xmlClassDescriptorResolver.setMappingLoader(mappingLoader); } // /** @@ -71,14 +151,15 @@ // /** * 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. + * @throws ResolverException in case that resolving the Class fails fatally */ - public void addClass(final String className) throws ResolverException { - resolver.addClass(className); + public void addClass(final Class clazz) throws ResolverException { + _xmlClassDescriptorResolver.addClass(clazz); } /** @@ -87,10 +168,11 @@ * 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. + * @throws ResolverException in case that resolving the Class fails fatally */ - public void addClasses(final String[] classNames) throws ResolverException { - resolver.addClasses(classNames); + public void addClasses(final Class[] clazzes) throws ResolverException { + _xmlClassDescriptorResolver.addClasses(clazzes); } /** @@ -103,10 +185,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); + _xmlClassDescriptorResolver.addPackage(packageName); } /** @@ -119,17 +202,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); + _xmlClassDescriptorResolver.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 +225,8 @@ */ public Marshaller createMarshaller() { Marshaller marshaller = new Marshaller(); - marshaller.setResolver(resolver); + marshaller.setXMLContext(this); + marshaller.setResolver(_xmlClassDescriptorResolver); return marshaller; } @@ -153,18 +238,655 @@ */ public Unmarshaller createUnmarshaller() { Unmarshaller unmarshaller = new Unmarshaller(); - unmarshaller.setResolver(resolver); + unmarshaller.setXMLContext(this); + unmarshaller.setResolver(_xmlClassDescriptorResolver); 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 + * To create a MappingTool instance. + * @return the MappingTool instance ready to use */ - public void setResolver(XMLClassDescriptorResolver resolver) { - this.resolver = resolver; + public MappingTool createMappingTool() { + MappingTool mt = new MappingTool(); + mt.setXMLContext(this); + return mt; } + /** + * Sets an application-specific {@link XMLClassDescriptorResolver} instance. + * @param xmlClassDescriptorResolver the resolver to use + */ + public void setResolver(final XMLClassDescriptorResolver xmlClassDescriptorResolver) { + this._xmlClassDescriptorResolver = xmlClassDescriptorResolver; + } + + /** + * 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; + } + + /** + * To set not one property but a complete Map of properties. + * @param properties the Map of properties + */ + 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 (_contextManagedValues._xmlNaming != null) { + return _contextManagedValues._xmlNaming; + } + + String prop = _config.getProperty(Property.Naming, null); + if ((prop == null) || (prop.equalsIgnoreCase("lower"))) { + _contextManagedValues._xmlNaming = new DefaultNaming(); + } else if (prop.equalsIgnoreCase("mixed")) { + DefaultNaming dn = new DefaultNaming(); + dn.setStyle(DefaultNaming.MIXED_CASE_STYLE); + _contextManagedValues._xmlNaming = dn; + } else { + try { + Class cls = null; + if (classLoader != null) { + cls = classLoader.loadClass(prop); + } else { + cls = Class.forName(prop); + } + _contextManagedValues._xmlNaming = (XMLNaming) cls.newInstance(); + } catch (Exception e) { + throw new RuntimeException("Failed to load XMLNaming: " + e); + } + } + return _contextManagedValues._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; + + } + + /** + * A couple of routines to manipulate XMLReader instances. + * + * @author Joachim Grueneis, jgrueneis_at_gmail_dot_com + * @version $Id$ + */ + 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. + * + * @param features the name of feature to set + * @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 (_contextManagedValues._primitiveNodeType != null) { + return _contextManagedValues._primitiveNodeType; + } + + String prop = _config.getProperty(Property.PrimitiveNodeType, null); + if (prop == null) { + return null; + } + _contextManagedValues._primitiveNodeType = NodeType.getNodeType(prop); + return _contextManagedValues._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 (_contextManagedValues._regExpEvalClass == null) { + _contextManagedValues._regExpEvalClass = Class.forName(prop); + } + regex = (RegExpEvaluator) _contextManagedValues._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 + * @throws IOException if instantiation of the serializer fails + */ + 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 + * @throws IOException if instantiation of serializer fails + */ + 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 ContextManagedValues { + /** 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; + } + + /** + * To get the XMLClassdescriptorResolver instance hold in the context. + * @return the XMLClassdescriptorResolver instance hold in the context + */ + public XMLClassDescriptorResolver getXMLClassDescriptorResolver() { + return _xmlClassDescriptorResolver; + } + + /** + * To get the Introspector assigned to this XMLContext. + * @return the Introspector assigned to this XMLContext + */ + public Introspector getIntrospector() { + return _introspector; + } + + /** + * To set the {@link Resolver} for Schema*. + * @param schemaResolver the {@link Resolver} for Schema* + */ + public void setSchemaResolver(final Resolver schemaResolver) { + _schemaResolver = schemaResolver; + } + + /** + * To get the {@link Resolver} to use in Schema*. + * @return get the {@link Resolver} to use in Schema* + */ + public Resolver getSchemaResolver() { + return _schemaResolver; + } + + /** + * To get the configuration value of LOAD_PACKAGE_MAPPING. + * @return configuration value of LOAD_PACKAGE_MAPPING as Boolean + */ + public Boolean getLoadPackageMapping() { + boolean loadPackageMappings = _config.getBoolean( + Property.LOAD_PACKAGE_MAPPING, + Property.DEFAULT_LOAD_PACKAGE_MAPPING); + return Boolean.valueOf(loadPackageMappings); + } + + /** + * To get the XMLClassDescriptor resolver strategy to be used when + * resolving classes into class descriptors. + * @return the ResolverStrategy to use + */ + public ResolverStrategy getResolverStrategy() { + return _resolverStrategy; + } + + /** + * To set the XMLClassDescriptor resolver strategy to be used. + * @param resolverStrategy the ResolverStrategy to use + */ + public void setResolverStrategy(final ResolverStrategy resolverStrategy) { + _resolverStrategy = resolverStrategy; + if (_xmlClassDescriptorResolver != null) { + _xmlClassDescriptorResolver.setResolverStrategy(_resolverStrategy); + } + } + + /** + * To set the {@link MappingLoader} to be used in this Castor session. + * @param mappingLoader the {@link MappingLoader} to use + */ + public void setMappingLoader(final MappingLoader mappingLoader) { + _mappingLoader = mappingLoader; + } + + /** + * To get the {@link MappingLoader} specified to be used in this Castor session. + * @return the {@link MappingLoader} to use + */ + public MappingLoader getMappingLoader() { + return _mappingLoader; + } + + /** + * To set the 'use introspector' flag. + * @param useIntrospector the 'use introspector' flag + */ + public void setUseIntrospector(final Boolean useIntrospector) { + _useIntrospector = useIntrospector; + } + + /** + * The 'use introspector' flag. + * @return the 'use introspector' flag + */ + public Boolean getUseIntrospector() { + return _useIntrospector; + } } - Index: src/main/java/org/exolab/castor/xml/XMLClassDescriptorResolver.java =================================================================== --- src/main/java/org/exolab/castor/xml/XMLClassDescriptorResolver.java (revision 7170) +++ src/main/java/org/exolab/castor/xml/XMLClassDescriptorResolver.java (working copy) @@ -1,217 +1,284 @@ /** * Redistribution and use of this software and associated documentation - * ("Software"), with or without modification, are permitted provided - * that the following conditions are met: - * - * 1. Redistributions of source code must retain copyright - * statements and notices. Redistributions must also contain a - * copy of this document. - * - * 2. Redistributions in binary form must reproduce the - * above copyright notice, this list of conditions and the - * following disclaimer in the documentation and/or other - * materials provided with the distribution. - * - * 3. The name "Exolab" must not be used to endorse or promote - * products derived from this Software without prior written - * permission of Intalio, Inc. For written permission, - * please contact info@exolab.org. - * - * 4. Products derived from this Software may not be called "Exolab" - * nor may "Exolab" appear in their names without prior written - * permission of Intalio, Inc. Exolab is a registered - * trademark of Intalio, Inc. - * - * 5. Due credit should be given to the Exolab Project - * (http://www.exolab.org/). - * - * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT - * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, - * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. - * + * ("Software"), with or without modification, are permitted provided that the + * following conditions are met: + * + * 1. Redistributions of source code must retain copyright statements and + * notices. Redistributions must also contain a copy of this document. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * + * 3. The name "Exolab" must not be used to endorse or promote products derived + * from this Software without prior written permission of Intalio, Inc. For + * written permission, please contact info@exolab.org. + * + * 4. Products derived from this Software may not be called "Exolab" nor may + * "Exolab" appear in their names without prior written permission of Intalio, + * Inc. Exolab is a registered trademark of Intalio, Inc. + * + * 5. Due credit should be given to the Exolab Project (http://www.exolab.org/). + * + * THIS SOFTWARE IS PROVIDED BY INTALIO, INC. AND CONTRIBUTORS ``AS IS'' AND ANY + * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL INTALIO, INC. OR ITS CONTRIBUTORS BE LIABLE FOR + * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * * Copyright 1999 (C) Intalio, Inc. All Rights Reserved. - * - * This file was originally developed by Keith Visco during the - * course of employment at Intalio Inc. - * All portions of this file developed by Keith Visco after Jan 19 2005 are - * Copyright (C) 2005 Keith Visco. All Rights Reserved. * + * This file was originally developed by Keith Visco during the course of + * employment at Intalio Inc. All portions of this file developed by Keith Visco + * after Jan 19 2005 are Copyright (C) 2005 Keith Visco. All Rights Reserved. + * * $Id: ClassDescriptorResolver.java 5951 2006-05-30 22:18:48Z bsnyder $ */ - package org.exolab.castor.xml; import java.util.Iterator; +import org.exolab.castor.xml.util.ResolverStrategy; /** * An interface for finding or "resolving" XMLClassDescriptor classes. * - *
- * Note: - * This interface is used by the marshalling Framework for - * resolving XMLClassDescriptors for non-primitive types. - * There are no guarantees that this class will be called for - * java native classes. + *
Note: This interface is used by the marshalling Framework for + * resolving XMLClassDescriptors for non-primitive types. There are no + * guarantees that this class will be called for java native classes. * * @author Keith Visco - * @version $Revision: 5951 $ $Date: 2005-02-28 17:41:38 -0700 (Mon, 28 Feb 2005) $ + * @version $Revision: 5951 $ $Date: 2005-02-28 17:41:38 -0700 (Mon, 28 Feb + * 2005) $ */ public interface XMLClassDescriptorResolver extends ClassDescriptorResolver { - -// /** -// * Returns the XMLClassDescriptor for the given class -// * @param type the Class to find the XMLClassDescriptor for -// * @return the XMLClassDescriptor for the given class -// **/ -// ClassDescriptor resolve(Class type) throws ResolverException; - + /** - * Returns the XMLClassDescriptor for the given class name + * To set the XMLContext to be used. * - * @param className the class name to find the XMLClassDescriptor for + * @param xmlContext + * the XMLContext to be used + */ + void setXMLContext(final XMLContext xmlContext); + + /** + * Enables or disables introspection. Introspection is enabled by default. + * + * @param enable + * a flag to indicate whether or not introspection is allowed. + */ + void setUseIntrospection(final boolean enable); + + /** + * Sets whether or not to look for and load package specific mapping files + * (".castor.xml"). + * + * @param loadPackageMappings + * a boolean that enables or disables the loading of package + * specific mapping files + */ + void setLoadPackageMappings(final boolean loadPackageMappings); + + /** + * Sets the ClassLoader to use when loading class descriptors. + * + * @param loader + * the ClassLoader to use + */ + void setClassLoader(ClassLoader loader); + + /** + * The resolver strategy to use for class and package resolving. Will set + * the current attributes into the new strategy. + * + * @param resolverStrategy + * the ResolverStrategy to use for resolve calls + */ + void setResolverStrategy(final ResolverStrategy resolverStrategy); + + /** + * To set the Introspector to be used. It is stored as attribute of resolver + * and set as property into the current strategy. + * + * @param introspector + * the Introspector to use + */ + void setIntrospector(final Introspector introspector); + + /** + * Returns the XMLClassDescriptor for the given class name. + * + * @param className + * the class name to find the XMLClassDescriptor for * @return the XMLClassDescriptor for the given class name + * @throws ResolverException in case that resolving fails unrecoverable */ - XMLClassDescriptor resolve(String className) - throws ResolverException; - + XMLClassDescriptor resolve(String className) throws ResolverException; + /** - * Returns the XMLClassDescriptor for the given class name + * Returns the XMLClassDescriptor for the given class name. * - * @param className the class name to find the XMLClassDescriptor for - * @param loader the ClassLoader to use + * @param className + * the class name to find the XMLClassDescriptor for + * @param loader + * the ClassLoader to use * @return the XMLClassDescriptor for the given class name + * @throws ResolverException in case that resolving fails unrecoverable */ - XMLClassDescriptor resolve(String className, ClassLoader loader) - throws ResolverException; - + XMLClassDescriptor resolve(String className, ClassLoader loader) throws ResolverException; + /** - * Returns the first XMLClassDescriptor that matches the given - * XML name and namespaceURI. Null is returned if no descriptor - * can be found. - * - * @param xmlName The class name to find the XMLClassDescriptor for. - * @param loader The ClassLoader to use. + * Returns the first XMLClassDescriptor that matches the given XML name and + * namespaceURI. Null is returned if no descriptor can be found. + * + * @param xmlName + * The class name to find the XMLClassDescriptor for. + * @param namespaceURI + * The namespace URI to identify the XMLClassDescriptor. + * @param loader + * The ClassLoader to use. * @return The XMLClassDescriptor for the given XML name. + * @throws ResolverException in case that resolving fails unrecoverable */ - XMLClassDescriptor resolveByXMLName - (String xmlName, String namespaceURI, ClassLoader loader) - throws ResolverException; + XMLClassDescriptor resolveByXMLName(String xmlName, String namespaceURI, ClassLoader loader) + throws ResolverException; /** - * Returns an enumeration of XMLClassDescriptor objects that - * match the given xml name. - * - * @param xmlName The class name to find the XMLClassDescriptor for. - * @param loader The ClassLoader to use. + * Returns an enumeration of XMLClassDescriptor objects that match the given + * xml name. + * + * @param xmlName + * The class name to find the XMLClassDescriptor for. + * @param namespaceURI + * The namespace URI to identify the XMLClassDescriptor. + * @param loader + * The ClassLoader to use. * @return An Iterator of XMLClassDescriptor objects. + * @throws ResolverException in case that resolving fails unrecoverable */ - Iterator resolveAllByXMLName - (String xmlName, String namespaceURI, ClassLoader loader) - throws ResolverException; - + Iterator resolveAllByXMLName(String xmlName, String namespaceURI, ClassLoader loader) + throws ResolverException; + /** - * Sets the ClassLoader to use when loading class descriptors - * @param loader the ClassLoader to use - **/ - void setClassLoader(ClassLoader loader); - - /** - * 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 - * using the XML code generator (in which case instead of a mapping file class - * descriptor files will be generated). + * 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 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. - * @throws ResolverException If there's an unrecoverable problem with resolving a certain class. - */ - public void addClass(final String className) throws ResolverException; + * @param className + * Name of the class for which the associated descriptor should + * be loaded. + * @throws ResolverException + * If there's an unrecoverable problem with resolving a certain + * class. + */ + void addClass(final String className) throws ResolverException; /** - * Loads the class descriptors for the class instances specified. The use of this method is useful - * when no mapping is used, as happens when the domain classes hase been generated - * using the XML code generator (in which case instead of a mapping file class - * descriptor files will be generated). + * Loads the class descriptors for the class instances specified. The use of + * this method is useful when no mapping is used, as happens when the domain + * classes hase been generated using the XML code generator (in which case + * instead of a mapping file class descriptor files will be generated). * - * @param classNames Names of the classes for which the associated descriptors should be loaded. - * @throws ResolverException If there's an unrecoverable problem with resolving a certain class. - */ - public void addClasses(final String[] classNames) throws ResolverException; - + * @param classNames + * Names of the classes for which the associated descriptors + * should be loaded. + * @throws ResolverException + * If there's an unrecoverable problem with resolving a certain + * class. + */ + void addClasses(final String[] classNames) throws ResolverException; + /** - * 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 have been generated - * using the XML code generator (in which case instead of a mapping file class - * descriptor files will be generated). + * 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 have been generated using the XML code generator (in which case + * instead of a mapping file class descriptor files will be generated). * - * @param clazz Class for which the associated descriptor should be loaded. - * @throws ResolverException If there's an unrecoverable problem with resolving a certain class. - */ - public void addClass(final Class clazz) throws ResolverException; + * @param clazz + * Class for which the associated descriptor should be loaded. + * @throws ResolverException + * If there's an unrecoverable problem with resolving a certain + * class. + */ + void addClass(final Class clazz) throws ResolverException; /** - * Loads the class descriptors for the class instances specified. The use of this method is useful - * when no mapping is used, as happens when the domain classes hase been generated - * using the XML code generator (in which case instead of a mapping file class - * descriptor files will be generated). + * Loads the class descriptors for the class instances specified. The use of + * this method is useful when no mapping is used, as happens when the domain + * classes hase been generated using the XML code generator (in which case + * instead of a mapping file class descriptor files will be generated). * - * @param clazzes Classes for which the associated descriptors should be loaded. - * @throws ResolverException If there's an unrecoverable problem with resolving a certain class. - */ - public void addClasses(final Class[] clazzes) throws ResolverException; + * @param clazzes + * Classes for which the associated descriptors should be loaded. + * @throws ResolverException + * If there's an unrecoverable problem with resolving a certain + * class. + */ + void addClasses(final Class[] clazzes) throws ResolverException; /** - * Loads class descriptors from the package specified. The use of this method is useful - * when no mapping is used, as happens when the domain classes hase been generated - * using the XML code generator (in which case instead of a mapping file class - * descriptor files will be generated). + * Loads class descriptors from the package specified. The use of this + * method is useful when no mapping is used, as happens when the domain + * classes hase been generated using the XML code generator (in which case + * instead of a mapping file class descriptor files will be generated). *

- * Please note that this functionality will work only if you provide the .castor.cdr - * file with your generated classes (as generated by the XML code generator). + * Please note that this functionality will work only if you provide the + * .castor.cdr 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. + * + * @param packageName + * The package name for the (descriptor) classes + * @throws ResolverException + * If there's a problem loading class descriptors for the given + * package. */ - public void addPackage(final String packageName) throws ResolverException; + void addPackage(final String packageName) throws ResolverException; /** - * Loads class descriptors from the packages specified. The use of this method is useful - * when no mapping is used, as happens when the domain classes hase been generated - * using the XML code generator (in which case instead of a mapping file class - * descriptor files will be generated). + * Loads class descriptors from the packages specified. The use of this + * method is useful when no mapping is used, as happens when the domain + * classes hase been generated using the XML code generator (in which case + * instead of a mapping file class descriptor files will be generated). *

- * Please note that this functionality will work only if you provide the .castor.cdr - * files with your generated classes (as generated by the XML code generator). + * Please note that this functionality will work only if you provide the + * .castor.cdr 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. + * + * @param packageNames + * The package names for the (descriptor) classes + * @throws ResolverException + * If there's a problem loading class descriptors for the given + * package. */ - public void addPackages(final String[] packageNames) throws ResolverException; - + void addPackages(final String[] packageNames) throws ResolverException; + /** - * Loads class descriptors from the package specified. The use of this method is useful - * when no mapping is used, as happens when the domain classes hase been generated - * using the XML code generator (in which case instead of a mapping file class - * descriptor files will be generated). + * Loads class descriptors from the package specified. The use of this + * method is useful when no mapping is used, as happens when the domain + * classes hase been generated using the XML code generator (in which case + * instead of a mapping file class descriptor files will be generated). *

- * Please note that this functionality will work only if you provide the .castor.cdr - * file with your generated classes (as generated by the XML code generator). + * Please note that this functionality will work only if you provide the + * .castor.cdr 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. + * + * @param packageName + * The package name for the (descriptor) classes + * @throws ResolverException + * If there's a problem loading class descriptors for the given + * package. * @deprecated Please use e.g. #addPackage(String) instead. */ - void loadClassDescriptors(final String packageName) - throws ResolverException; - -} //-- ClassDescriptorResolver + void loadClassDescriptors(final String packageName) throws ResolverException; + +} // -- ClassDescriptorResolver Index: src/main/java/org/exolab/castor/xml/Introspector.java =================================================================== --- src/main/java/org/exolab/castor/xml/Introspector.java (revision 7170) +++ src/main/java/org/exolab/castor/xml/Introspector.java (working copy) @@ -227,11 +227,13 @@ */ private JavaNaming _javaNaming; + private XMLContext _xmlContext; + /** * Creates a new instance of the Introspector. */ - public Introspector() { - this(null); + public Introspector(final XMLContext xmlContext) { + this(xmlContext, null); } //-- Introspector /** @@ -239,24 +241,28 @@ * * @param classLoader */ - public Introspector(ClassLoader classLoader) { + public Introspector(final XMLContext xmlContext, final ClassLoader classLoader) { super(); _classLoader = classLoader; - init(); + init(xmlContext); } //-- Introspector - private void init() { + private void init(final XMLContext xmlContext) { + _xmlContext = 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 7170) +++ 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,11 @@ public void setProperty(final String name, final String value) { _config.getProperties().setProperty(name, value); } + + public void setXMLContext(final XMLContext xmlContext) { + _xmlContext = xmlContext; + _cdResolver = _xmlContext.getXMLClassDescriptorResolver(); + } } //-- Unmarshaller Index: src/main/java/org/exolab/castor/xml/ValidationContext.java =================================================================== --- src/main/java/org/exolab/castor/xml/ValidationContext.java (revision 7170) +++ 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 @@ -90,9 +92,29 @@ } /** + * To get the {@link XMLContext} to use. + * @return the {@link XMLContext} to use + */ + public XMLContext getXMLContext() { + if (_xmlContext == null) { + _xmlContext = new XMLContext(); + } + return _xmlContext; + } + + /** + * To set which {@link XMLContext} should be used. + * @param xmlContext the {@link XMLContext} to use + */ + 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 +151,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 7170) +++ 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 XMLContext xmlContext, + final Schema schema, + final AttributeSet atts, + final URIResolver uriResolver, + final Locator locator, + final SchemaUnmarshallerState state) + throws XMLException { + super(xmlContext); 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(getXMLContext(), 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(getXMLContext(), atts); } //-- else if (name.equals(SchemaNames.ATTRIBUTE_GROUP)) { - _unmarshaller = new AttributeGroupUnmarshaller(_schema, atts); + _unmarshaller = new AttributeGroupUnmarshaller(getXMLContext(), _schema, atts); } //-- else if (name.equals(SchemaNames.COMPLEX_TYPE)) { _unmarshaller - = new ComplexTypeUnmarshaller(_schema, atts, getResolver()); + = new ComplexTypeUnmarshaller(getXMLContext(), _schema, atts); } //-- else if (name.equals(SchemaNames.SIMPLE_TYPE)) { - _unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + _unmarshaller = new SimpleTypeUnmarshaller(getXMLContext(), _schema, atts); } //-- else if (name.equals(SchemaNames.GROUP)) { - _unmarshaller = new ModelGroupUnmarshaller(_schema, atts, getResolver()); + _unmarshaller = new ModelGroupUnmarshaller(getXMLContext(), _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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/ElementUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.ElementDecl; @@ -107,17 +108,17 @@ //----------------/ /** - * Creates a new ElementUnmarshaller + * Creates a new ElementUnmarshaller. + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final Schema schema, + final AttributeSet atts) + throws XMLException { + super(xmlContext); this._schema = schema; @@ -237,7 +238,7 @@ } else if (minOccurs > 1) _element.setMaxOccurs(minOccurs); - charUnmarshaller = new CharacterUnmarshaller(); + charUnmarshaller = new CharacterUnmarshaller(getXMLContext()); } //-- ElementUnmarshaller //-----------/ @@ -305,7 +306,7 @@ "element definitions."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } else if (SchemaNames.COMPLEX_TYPE.equals(name)) { @@ -326,7 +327,7 @@ foundComplexType = true; unmarshaller - = new ComplexTypeUnmarshaller(_schema, atts, getResolver()); + = new ComplexTypeUnmarshaller(getXMLContext(), _schema, atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { @@ -345,20 +346,17 @@ "'keyref' and 'unique' elements."); foundSimpleType = true; - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(getXMLContext(), _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(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/WildcardUnmarshaller.java (working copy) @@ -47,6 +47,7 @@ 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.AttributeGroup; @@ -106,42 +107,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 XMLContext xmlContext, + final ComplexType complexType, + final Schema schema, + final String element, + final AttributeSet atts) { + this(xmlContext, 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 XMLContext xmlContext, + final Group group, + final Schema schema, + final String element, + final AttributeSet atts) { + this(xmlContext, 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 XMLContext xmlContext, + final AttributeGroup attGroup, + final Schema schema, + final String element, + final AttributeSet atts) { + this(xmlContext, schema, element, atts, new Wildcard(attGroup)); } /** - * Creates a new WildcardUnmarshaller + * Creates a new WildcardUnmarshaller. + * @param xmlContext the XMLContext to get some configuration 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 XMLContext xmlContext, + final Schema schema, + final String element, + final AttributeSet atts, + final Wildcard wildcard) { + super(xmlContext); + _wildcard = wildcard; this._schema = schema; this._element = element; @@ -278,7 +286,7 @@ } //-- if (SchemaNames.ANNOTATION.equals(name)) { - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/AppInfoUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.AppInfo; import org.exolab.castor.xml.schema.SchemaNames; @@ -84,13 +85,15 @@ //----------------/ /** - * Creates a new AppInfoUnmarshaller + * Creates a new AppInfoUnmarshaller. + * @param xmlContext the XMLContext to get some configuration settings from * @param atts the AttributeList **/ - public AppInfoUnmarshaller(AttributeSet atts) - throws XMLException - { - super(); + public AppInfoUnmarshaller( + final XMLContext xmlContext, + final AttributeSet atts) + throws XMLException { + super(xmlContext); _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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/CharacterUnmarshaller.java (working copy) @@ -45,6 +45,7 @@ package org.exolab.castor.xml.schema.reader; +import org.exolab.castor.xml.XMLContext; import org.exolab.castor.xml.XMLException; /** @@ -58,11 +59,13 @@ private StringBuffer sb = null; private String currentName = null; + /** - * Creates a new StringUnmarshaller + * Creates a new StringUnmarshaller. + * @param xmlContext the XMLContext to get some configuration settings from **/ - public CharacterUnmarshaller() { - super(); + public CharacterUnmarshaller(final XMLContext xmlContext) { + super(xmlContext); 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 7170) +++ 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,84 @@ //- Constructors -/ //----------------/ - public SchemaUnmarshaller() - throws XMLException - { - this(null, null, null); + public SchemaUnmarshaller(final XMLContext xmlContext) + throws XMLException { + this(xmlContext, 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); _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 xmlContext +// * @param state +// * @throws XMLException +// */ +// public SchemaUnmarshaller( +// final XMLContext xmlContext, +// final SchemaUnmarshallerState state) +// throws XMLException { +// this(null, parent, null, null); +// _state = state; +// foundSchemaDef = false; +// } //-- SchemaUnmarshaller + + /** + * Called from IncludeUnmarshaller. + * @param xmlContext + * @param include + * @param state + * @param uriResolver + * @throws XMLException + */ + public SchemaUnmarshaller( + final XMLContext xmlContext, + final boolean include, + final SchemaUnmarshallerState state, + final URIResolver uriResolver) + throws XMLException { + + this(xmlContext, 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 XMLContext xmlContext, + final AttributeSet atts) + throws XMLException { + this(xmlContext, atts, null); } - public SchemaUnmarshaller(AttributeSet atts, Resolver resolver, URIResolver uriResolver) - throws XMLException - { - super(); + private SchemaUnmarshaller( + final XMLContext xmlContext, + final AttributeSet atts, + final URIResolver uriResolver) + throws XMLException { + super(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 +435,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 +531,48 @@ //-- if (name.equals(SchemaNames.ANNOTATION)) { - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } //-- else if (name.equals(SchemaNames.ATTRIBUTE)) { - unmarshaller = new AttributeUnmarshaller(_schema,atts, getResolver()); + unmarshaller = new AttributeUnmarshaller(getXMLContext(), _schema,atts); } //-- else if (name.equals(SchemaNames.ATTRIBUTE_GROUP)) { - unmarshaller = new AttributeGroupUnmarshaller(_schema, atts); + unmarshaller = new AttributeGroupUnmarshaller(getXMLContext(), _schema, atts); } //-- else if (name.equals(SchemaNames.COMPLEX_TYPE)) { unmarshaller - = new ComplexTypeUnmarshaller(_schema, atts, _resolver); + = new ComplexTypeUnmarshaller(getXMLContext(), _schema, atts); } //-- else if (name.equals(SchemaNames.ELEMENT)) { unmarshaller - = new ElementUnmarshaller(_schema, atts, _resolver); + = new ElementUnmarshaller(getXMLContext(), _schema, atts); } //-- else if (name.equals(SchemaNames.SIMPLE_TYPE)) { - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(getXMLContext(), _schema, atts); } //-- else if (name.equals(SchemaNames.GROUP)) { - unmarshaller = new ModelGroupUnmarshaller(_schema, atts, _resolver); + unmarshaller = new ModelGroupUnmarshaller(getXMLContext(), _schema, atts); } //-- else if (name.equals(SchemaNames.INCLUDE)) { unmarshaller - = new IncludeUnmarshaller(_schema, atts, _resolver, getURIResolver(),getDocumentLocator(), _state); + = new IncludeUnmarshaller(getXMLContext(), _schema, atts, getURIResolver(),getDocumentLocator(), _state); } //-- else if (name.equals(SchemaNames.IMPORT)) { unmarshaller - = new ImportUnmarshaller(_schema, atts, _resolver, getURIResolver(), getDocumentLocator(), _state); + = new ImportUnmarshaller(getXMLContext(), _schema, atts, getURIResolver(), getDocumentLocator(), _state); } //-- else if (name.equals(SchemaNames.REDEFINE)) { unmarshaller - = new RedefineUnmarshaller(_schema, atts, _resolver, getURIResolver(), getDocumentLocator(), _state); + = new RedefineUnmarshaller(getXMLContext(), _schema, atts, getURIResolver(), getDocumentLocator(), _state); } else { //-- we should throw a new Exception here @@ -532,10 +582,10 @@ 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(getXMLContext(), name); } - unmarshaller.setDocumentLocator(getDocumentLocator()); +// unmarshaller.setDocumentLocator(getDocumentLocator()); } //-- startElement @@ -626,7 +676,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 +687,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 7170) +++ 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/ComplexContentUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.ComplexType; @@ -90,27 +91,31 @@ //----------------/ /** - * Creates a new ComplexContentUnmarshaller + * Creates a new ComplexContentUnmarshaller. + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final ComplexType complexType, + final AttributeSet atts) + throws XMLException { + super(xmlContext); _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 +180,7 @@ foundExtension = true; ExtensionUnmarshaller extension = - new ExtensionUnmarshaller(_complexType, atts, getResolver()); + new ExtensionUnmarshaller(getXMLContext(), _complexType, atts); unmarshaller = extension; } //-- restriction @@ -192,7 +197,7 @@ foundRestriction = true; unmarshaller= - new ComplexContentRestrictionUnmarshaller(_complexType, atts, getResolver()); + new ComplexContentRestrictionUnmarshaller(getXMLContext(), _complexType, atts); } //-- annotation else if (name.equals(SchemaNames.ANNOTATION)) { @@ -205,11 +210,10 @@ "of a 'complexContent' element."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } else illegalElement(name); - 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/AttributeUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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; @@ -95,15 +96,14 @@ //- Constructors -/ //----------------/ - public AttributeUnmarshaller - (Schema schema, AttributeSet atts, Resolver resolver) + public AttributeUnmarshaller( + final XMLContext xmlContext, + final Schema schema, + final AttributeSet atts) { - super(); + super(xmlContext); this._schema = schema; - setResolver(resolver); - - _attribute = new AttributeDecl(schema); //--@ref @@ -232,7 +232,7 @@ "an attribute declaration."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { if (foundSimpleType) @@ -240,7 +240,7 @@ "an attribute declaration."); foundSimpleType = true; - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(getXMLContext(), _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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/ComplexTypeUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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; @@ -108,22 +109,23 @@ //----------------/ /** - * Creates a new ComplexTypeUnmarshaller + * Creates a new ComplexTypeUnmarshaller. + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final Schema schema, + final AttributeSet atts) + throws XMLException { + super(xmlContext); + this._schema = schema; _complexType = schema.createComplexType(); - _complexType.useResolver(resolver); + _complexType.useResolver(getResolver()); //-- handle attributes String attValue = null; @@ -250,7 +252,7 @@ foundAnyAttribute = true; allowAnnotation = true; unmarshaller - = new WildcardUnmarshaller(_complexType, _schema, name, atts, getResolver()); + = new WildcardUnmarshaller(getXMLContext(), _complexType, _schema, name, atts); } //-- attribute declarations @@ -267,7 +269,7 @@ foundAttributes = true; allowAnnotation = false; unmarshaller - = new AttributeUnmarshaller(_schema, atts, getResolver()); + = new AttributeUnmarshaller(getXMLContext(), _schema, atts); } //-- attribute group declarations else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) { @@ -291,7 +293,7 @@ foundAttributes = true; allowAnnotation = false; unmarshaller - = new AttributeGroupUnmarshaller(_schema, atts); + = new AttributeGroupUnmarshaller(getXMLContext(), _schema, atts); } //-- simpleContent else if (SchemaNames.SIMPLE_CONTENT.equals(name)) { @@ -314,7 +316,7 @@ allowAnnotation = false; _complexType.setSimpleContent(true); unmarshaller - = new SimpleContentUnmarshaller(_complexType, atts, getResolver()); + = new SimpleContentUnmarshaller(getXMLContext(), _complexType, atts); } //-- complexContent else if (SchemaNames.COMPLEX_CONTENT.equals(name)) { @@ -338,7 +340,7 @@ _complexType.setComplexContent(true); unmarshaller - = new ComplexContentUnmarshaller(_complexType, atts, getResolver()); + = new ComplexContentUnmarshaller(getXMLContext(), _complexType, atts); } //-- else if ( name.equals(SchemaNames.GROUP) ) @@ -360,7 +362,7 @@ foundModelGroup = true; allowAnnotation = false; unmarshaller - = new ModelGroupUnmarshaller(_schema, atts, getResolver()); + = new ModelGroupUnmarshaller(getXMLContext(), _schema, atts); } //-- ModelGroup declarations (choice, all, sequence) else if ( (SchemaNames.isGroupName(name)) && (name != SchemaNames.GROUP) ) @@ -383,11 +385,11 @@ foundModelGroup = true; allowAnnotation = false; unmarshaller - = new GroupUnmarshaller(_schema, name, atts, getResolver()); + = new GroupUnmarshaller(getXMLContext(), _schema, name, atts); } else if (name.equals(SchemaNames.ANNOTATION)) { if (allowAnnotation) { - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); allowAnnotation = false; foundAnnotation = true; } @@ -402,7 +404,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 7170) +++ 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 XMLContext xmlContext, + final Schema schema, + final AttributeSet atts, + final URIResolver uriResolver, + final Locator locator, + final SchemaUnmarshallerState state) + throws XMLException { + super(xmlContext); 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(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/AnnotationUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.AppInfo; @@ -86,13 +87,14 @@ //----------------/ /** - * Creates a new AnnotationUnmarshaller + * Creates a new AnnotationUnmarshaller. + * @param xmlContext the XMLContext to get some configuration settings from * @param atts the AttributeList **/ - public AnnotationUnmarshaller (AttributeSet atts) + public AnnotationUnmarshaller (final XMLContext xmlContext, final AttributeSet atts) throws XMLException { - super(); + super(xmlContext); _annotation = new Annotation(); @@ -156,10 +158,10 @@ } if (SchemaNames.APPINFO.equals(name)) { - unmarshaller = new AppInfoUnmarshaller(atts); + unmarshaller = new AppInfoUnmarshaller(getXMLContext(), atts); } else if (SchemaNames.DOCUMENTATION.equals(name)) { - unmarshaller = new DocumentationUnmarshaller(atts); + unmarshaller = new DocumentationUnmarshaller(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/ExtensionUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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; @@ -102,19 +103,18 @@ //----------------/ /** - * Creates a new ExtensionUnmarshaller + * Creates a new ExtensionUnmarshaller. + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final ComplexType complexType, + final AttributeSet atts) + throws XMLException { + super(xmlContext); - setResolver(resolver); - _complexType = complexType; _schema = complexType.getSchema(); @@ -209,14 +209,14 @@ //-- if (SchemaNames.ANY_ATTRIBUTE.equals(name)) { unmarshaller - = new WildcardUnmarshaller(_complexType, _schema, name, atts, getResolver()); + = new WildcardUnmarshaller(getXMLContext(), _complexType, _schema, name, atts); } //-- attribute declarations else if (SchemaNames.ATTRIBUTE.equals(name)) { foundAttributes = true; unmarshaller - = new AttributeUnmarshaller(_schema, atts, getResolver()); + = new AttributeUnmarshaller(getXMLContext(), _schema, atts); } //-- attribute group declarations else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) { @@ -232,7 +232,7 @@ foundAttributes = true; unmarshaller - = new AttributeGroupUnmarshaller(_schema, atts); + = new AttributeGroupUnmarshaller(getXMLContext(), _schema, atts); } //-- else if ( name.equals(SchemaNames.GROUP) ) @@ -247,7 +247,7 @@ foundModelGroup = true; unmarshaller - = new ModelGroupUnmarshaller(_schema, atts, getResolver()); + = new ModelGroupUnmarshaller(getXMLContext(), _schema, atts); } else if (SchemaNames.isGroupName(name) && (name != SchemaNames.GROUP) ) { if (foundAttributes) @@ -265,7 +265,7 @@ foundModelGroup = true; unmarshaller - = new GroupUnmarshaller(_schema, name, atts, getResolver()); + = new GroupUnmarshaller(getXMLContext(), _schema, name, atts); } //-- element declarations else if (SchemaNames.ANY_ATTRIBUTE.equals(name)) { @@ -282,11 +282,10 @@ "an 'extension' element."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/ModelGroupUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.Group; @@ -106,16 +107,17 @@ //----------------/ /** - * Creates a new ModelGroupUnmarshaller + * Creates a new ModelGroupUnmarshaller. + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final Schema schema, + final AttributeSet atts) { + super(xmlContext); + this._schema = schema; _group = new ModelGroup(_schema); @@ -248,12 +250,12 @@ "element definitions."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } else if (SchemaNames.isGroupName(name)) { unmarshaller - = new GroupUnmarshaller(_schema, name, atts, getResolver()); + = new GroupUnmarshaller(getXMLContext(), _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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/AttributeGroupUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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; @@ -97,14 +98,17 @@ //----------------/ /** - * Creates a new AttributeGroupUnmarshaller + * Creates a new AttributeGroupUnmarshaller. + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final Schema schema, + final AttributeSet atts) + throws XMLException { + super(xmlContext); this._schema = schema; @@ -199,7 +203,7 @@ foundAnyAttribute = true; allowAnnotation = true; unmarshaller - = new WildcardUnmarshaller(_attributeGroup, _schema, name, atts, getResolver()); + = new WildcardUnmarshaller(getXMLContext(), _attributeGroup, _schema, name, atts); } //-- attribute declarations else if (SchemaNames.ATTRIBUTE.equals(name)) { @@ -209,7 +213,7 @@ error("AttributeGroup references may not have children."); unmarshaller - = new AttributeUnmarshaller(_schema, atts, getResolver()); + = new AttributeUnmarshaller(getXMLContext(), _schema, atts); } //-- element declarations else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) { @@ -217,15 +221,14 @@ if (isRef) error("AttributeGroup references may not have children."); unmarshaller - = new AttributeGroupUnmarshaller(_schema, atts); + = new AttributeGroupUnmarshaller(getXMLContext(), _schema, atts); } else if (name.equals(SchemaNames.ANNOTATION)) { if (!allowAnnotation) outOfOrder(name); - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeRestrictionUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.Facet; @@ -100,14 +101,16 @@ /** * Creates a new RestrictionUnmarshaller + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final SimpleTypeDefinition typeDefinition, + final AttributeSet atts) + throws XMLException { + super(xmlContext); _typeDefinition = typeDefinition; _schema = typeDefinition.getSchema(); @@ -189,7 +192,7 @@ "'restriction' elements."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { if (foundSimpleType) @@ -201,12 +204,12 @@ "elements, must appear before any facets."); foundSimpleType = true; - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(getXMLContext(), _schema, atts); } else if (FacetUnmarshaller.isFacet(name)) { foundFacets = true; - unmarshaller = new FacetUnmarshaller(name, atts); + unmarshaller = new FacetUnmarshaller(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/FacetUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.Facet; @@ -91,12 +92,17 @@ //----------------/ /** - * Creates a new FacetUnmarshaller + * Creates a new FacetUnmarshaller. + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final String name, + final AttributeSet atts) + throws XMLException { + super(xmlContext); _elementName = name; @@ -163,7 +169,7 @@ } if (SchemaNames.ANNOTATION.equals(name)) { - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), 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 7170) +++ 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 XMLContext xmlContext, + final Schema schema, + final AttributeSet atts, + final URIResolver uriResolver, + final Locator locator, + final SchemaUnmarshallerState state) + throws XMLException { + super(xmlContext); + 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(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/SimpleContentUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.ComplexType; @@ -89,19 +90,20 @@ //----------------/ /** - * Creates a new SimpleContentUnmarshaller + * Creates a new SimpleContentUnmarshaller. + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final ComplexType complexType, + final AttributeSet atts) + throws XMLException { + + super(xmlContext); _complexType = complexType; - setResolver(resolver); - } //-- SimpleContentUnmarshaller //-----------/ @@ -164,7 +166,7 @@ foundExtension = true; unmarshaller - = new ExtensionUnmarshaller(_complexType, atts, getResolver()); + = new ExtensionUnmarshaller(getXMLContext(), _complexType, atts); } //-- restriction else if (SchemaNames.RESTRICTION.equals(name)) { @@ -181,7 +183,7 @@ foundRestriction = true; unmarshaller = - new SimpleContentRestrictionUnmarshaller(_complexType,atts,getResolver()); + new SimpleContentRestrictionUnmarshaller(getXMLContext(), _complexType, atts); } //-- annotation else if (name.equals(SchemaNames.ANNOTATION)) { @@ -194,7 +196,7 @@ "of a 'simpleContent' element."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/FieldOrSelectorUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.Annotated; import org.exolab.castor.xml.schema.Annotation; @@ -92,16 +93,19 @@ //----------------/ /** - * Creates a new FieldOrSelectorUnmarshaller + * Creates a new FieldOrSelectorUnmarshaller. * + * @param xmlContext the XMLContext to get some configuration settings from * @param elementName the name of the element being unmarshalled. * @param atts the AttributeList. **/ - public FieldOrSelectorUnmarshaller - (String elementName, AttributeSet atts) + public FieldOrSelectorUnmarshaller( + final XMLContext xmlContext, + final String elementName, + final AttributeSet atts) throws XMLException { - super(); + super(xmlContext); _elementName = elementName; @@ -187,7 +191,7 @@ error("Only one (1) annotation may appear as a child of '" + _elementName + "'."); _foundAnnotation = true; - _unmarshaller = new AnnotationUnmarshaller(atts); + _unmarshaller = new AnnotationUnmarshaller(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeListUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.*; import org.exolab.castor.xml.schema.simpletypes.ListType; @@ -93,13 +94,16 @@ //----------------/ /** - * Creates a new ListUnmarshaller + * Creates a new ListUnmarshaller. + * @param xmlContext the XMLContext to get some configuration settings from * @param atts the AttributeList **/ - SimpleTypeListUnmarshaller(Schema schema, AttributeSet atts) - throws XMLException - { - super(); + SimpleTypeListUnmarshaller( + final XMLContext xmlContext, + final Schema schema, + final AttributeSet atts) + throws XMLException { + super(xmlContext); _schema = schema; _list = new ListType(schema); @@ -204,7 +208,7 @@ "'list' elements."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { if (foundItemType) @@ -216,7 +220,7 @@ "'list' elements."); foundSimpleType = true; - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(getXMLContext(), _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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/ComplexContentRestrictionUnmarshaller.java (working copy) @@ -47,6 +47,7 @@ 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; @@ -100,17 +101,18 @@ //- Constructors -/ //----------------/ /** - * Creates a new RestrictionUnmarshaller + * Creates a new RestrictionUnmarshaller. + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final ComplexType complexType, + final AttributeSet atts) + throws XMLException { + super(xmlContext); + _complexType = complexType; _schema = complexType.getSchema(); _complexType.setDerivationMethod(SchemaNames.RESTRICTION); @@ -217,7 +219,7 @@ "'restriction' elements."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } //-- ModelGroup declarations (choice, all, sequence, group) @@ -233,12 +235,12 @@ foundModelGroup = true; unmarshaller - = new GroupUnmarshaller(_schema, name, atts, getResolver()); + = new GroupUnmarshaller(getXMLContext(), _schema, name, atts); } else if (SchemaNames.ATTRIBUTE.equals(name)) { foundAttribute = true; - unmarshaller = new AttributeUnmarshaller(_schema,atts, getResolver()); + unmarshaller = new AttributeUnmarshaller(getXMLContext(), _schema,atts); } else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) { @@ -249,17 +251,16 @@ "attributeGroups, but not defining ones."); } foundAttributeGroup = true; - unmarshaller = new AttributeGroupUnmarshaller(_schema,atts); + unmarshaller = new AttributeGroupUnmarshaller(getXMLContext(), _schema,atts); } //-- else if (SchemaNames.ANY_ATTRIBUTE.equals(name)) { unmarshaller - = new WildcardUnmarshaller(_complexType, _schema, name, atts, getResolver()); + = new WildcardUnmarshaller(getXMLContext(), _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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/UnionUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.Schema; @@ -99,12 +100,15 @@ /** * Creates a new IdentityConstraintUnmarshaller * + * @param xmlContext the XMLContext to get some configuration settings from * @param atts the AttributeList **/ - public UnionUnmarshaller(Schema schema, AttributeSet atts) - throws XMLException - { - super(); + public UnionUnmarshaller( + final XMLContext xmlContext, + final Schema schema, + final AttributeSet atts) + throws XMLException { + super(xmlContext); if (schema == null) { String err = "'schema' must not be null."; @@ -184,11 +188,11 @@ elementName() + "'."); _foundAnnotation = true; - _unmarshaller = new AnnotationUnmarshaller(atts); + _unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { _foundSimpleType = true; - _unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + _unmarshaller = new SimpleTypeUnmarshaller(getXMLContext(), _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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/SimpleTypeUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.Schema; @@ -97,15 +98,18 @@ //----------------/ /** - * Creates a new SimpleTypeUnmarshaller + * Creates a new SimpleTypeUnmarshaller. + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final Schema schema, + final AttributeSet atts) throws XMLException { - super(); + super(xmlContext); String name = atts.getValue(SchemaNames.NAME_ATTR); @@ -213,7 +217,7 @@ "of 'simpleType'."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } else if (SchemaNames.RESTRICTION.equals(name)) { @@ -229,17 +233,17 @@ foundRestriction = true; unmarshaller - = new SimpleTypeRestrictionUnmarshaller(_simpleTypeDef, atts); + = new SimpleTypeRestrictionUnmarshaller(getXMLContext(), _simpleTypeDef, atts); } else if (SchemaNames.LIST.equals(name)) { foundList = true; Schema schema = _simpleTypeDef.getSchema(); - unmarshaller = new SimpleTypeListUnmarshaller(schema, atts); + unmarshaller = new SimpleTypeListUnmarshaller(getXMLContext(), schema, atts); } else if (SchemaNames.UNION.equals(name)) { foundUnion = true; Schema schema = _simpleTypeDef.getSchema(); - unmarshaller = new UnionUnmarshaller(schema, atts); + unmarshaller = new UnionUnmarshaller(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/GroupUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.Group; @@ -116,17 +117,19 @@ //----------------/ /** - * Creates a new GroupUnmarshaller + * Creates a new GroupUnmarshaller. + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final Schema schema, + final String element, + final AttributeSet atts) { + super(xmlContext); + this._schema = schema; _group = new Group(); @@ -264,19 +267,19 @@ "element definitions."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } else if (SchemaNames.ELEMENT.equals(name)) { foundElement = true; unmarshaller - = new ElementUnmarshaller(_schema, atts, getResolver()); + = new ElementUnmarshaller(getXMLContext(), _schema, atts); } //--group else if (name.equals(SchemaNames.GROUP)) { foundModelGroup = true; unmarshaller - = new ModelGroupUnmarshaller(_schema, atts, getResolver()); + = new ModelGroupUnmarshaller(getXMLContext(), _schema, atts); } //--all, sequence, choice @@ -286,14 +289,14 @@ if (SchemaNames.ALL.equals(name)) foundAll = true; unmarshaller - = new GroupUnmarshaller(_schema, name, atts, getResolver()); + = new GroupUnmarshaller(getXMLContext(), _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(getXMLContext(), _group, _schema, name, atts); } else { @@ -302,7 +305,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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/IdentityConstraintUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.IdentityConstraint; @@ -96,16 +97,18 @@ //----------------/ /** - * Creates a new IdentityConstraintUnmarshaller + * Creates a new IdentityConstraintUnmarshaller. * + * @param xmlContext the XMLContext 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 XMLContext xmlContext, + final String elementName, + final AttributeSet atts) + throws XMLException { + super(xmlContext); _elementName = elementName; @@ -211,7 +214,7 @@ _elementName + "'."); _foundAnnotation = true; - _unmarshaller = new AnnotationUnmarshaller(atts); + _unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } else if (SchemaNames.SELECTOR.equals(name)) { @@ -226,11 +229,11 @@ _foundSelector = true; - _unmarshaller = new FieldOrSelectorUnmarshaller(name, atts); + _unmarshaller = new FieldOrSelectorUnmarshaller(getXMLContext(), name, atts); } else if (SchemaNames.FIELD.equals(name)) { _foundField = true; - _unmarshaller = new FieldOrSelectorUnmarshaller(name, atts); + _unmarshaller = new FieldOrSelectorUnmarshaller(getXMLContext(), 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/UnknownUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages import org.exolab.castor.xml.AttributeSet; import org.exolab.castor.xml.Namespaces; +import org.exolab.castor.xml.XMLContext; import org.exolab.castor.xml.XMLException; /** @@ -71,8 +72,8 @@ //- Constructors -/ //----------------/ - public UnknownUnmarshaller(String name) { - super(); + public UnknownUnmarshaller(final XMLContext xmlContext, final String name) { + super(xmlContext); 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 7170) +++ 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 7170) +++ 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; @@ -62,23 +63,16 @@ **/ public abstract class ComponentReader { - //--------------------/ //- Member Variables -/ //--------------------/ + /** The Castor XML context to use. */ + private XMLContext _xmlContext; + + private Locator _documentLocator; /** - * The document locator - **/ - protected Locator _locator = null; - - /** - * The resolver to be used for resolving id references - **/ - private Resolver _resolver; - - /** - * The resolver to be used for resolving href + * The resolver to be used for resolving href. */ private URIResolver _uriResolver; @@ -86,9 +80,30 @@ //- 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 XMLContext xmlContext) { +// this(); +// if (xmlContext != null) { +// setXMLContext(xmlContext); +// } +// } + + /** + * To hand down a couple of configuration items to all Unmarshaller classes. + * @param xmlContext the XMLContext to use + */ + protected ComponentReader(final XMLContext xmlContext) { + this(); + _xmlContext = xmlContext; + } //-----------/ //- Methods -/ @@ -114,16 +129,12 @@ **/ public void finish() throws XMLException {} - public Locator getDocumentLocator() { - return _locator; - } //-- getLocator - /** * Returns the resolver used for resolving id references. * @return the resolver used for resolving id references. **/ public Resolver getResolver() { - return _resolver; + return _xmlContext.getSchemaResolver(); } //-- getResolver /** @@ -141,7 +152,7 @@ * id references **/ public void setResolver(Resolver resolver) { - _resolver = resolver; + _xmlContext.setSchemaResolver(resolver); } //-- setResolver @@ -188,8 +199,8 @@ throws XMLException { - if (_locator != null) { - err += "\n line: " + _locator.getLineNumber(); + if (getDocumentLocator() != null) { + err += "\n line: " + getDocumentLocator().getLineNumber(); } throw new XMLException(err); @@ -204,8 +215,8 @@ throws XMLException { - if (_locator != null) { - String err = "An error occured at line: " + _locator.getLineNumber(); + if (getDocumentLocator() != null) { + String err = "An error occured at line: " + getDocumentLocator().getLineNumber(); throw new XMLException(err, ex); } throw new XMLException(ex); @@ -222,8 +233,8 @@ String err = "Illegal attribute '" + attName + "' found on element <" + elementName() + ">."; - if (_locator != null) { - err += "\n line: " + _locator.getLineNumber(); + if (getDocumentLocator() != null) { + err += "\n line: " + getDocumentLocator().getLineNumber(); } throw new XMLException(err); @@ -239,8 +250,8 @@ String err = "Illegal element '" + name + "' found as child of <" + elementName() + ">."; - if (_locator != null) { - err += "\n line: " + _locator.getLineNumber(); + if (getDocumentLocator() != null) { + err += "\n line: " + getDocumentLocator().getLineNumber(); } throw new XMLException(err); @@ -269,8 +280,8 @@ String err = "redefintion of element '" + name + "' within element <" + elementName() + ">."; - if (_locator != null) { - err += "\n line: " + _locator.getLineNumber(); + if (getDocumentLocator() != null) { + err += "\n line: " + getDocumentLocator().getLineNumber(); } if (xtraInfo != null) { @@ -313,8 +324,12 @@ } } //-- toInt - public void setDocumentLocator(Locator locator) { - this._locator = locator; + public Locator getDocumentLocator() { + return _documentLocator; + } //-- getDocumentLocator + + public void setDocumentLocator(Locator documentLocator) { + _documentLocator = documentLocator; } //-- setDocumentLocator /** @@ -366,5 +381,20 @@ } //-- 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() { + 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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/DocumentationUnmarshaller.java (working copy) @@ -48,6 +48,7 @@ //-- imported classes and packages 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.Documentation; import org.exolab.castor.xml.schema.SchemaNames; @@ -83,11 +84,12 @@ //----------------/ /** - * Creates a new DocumentationUnmarshaller + * Creates a new DocumentationUnmarshaller. + * @param xmlContext the XMLContext to get some configuration settings from * @param atts the AttributeList **/ - public DocumentationUnmarshaller(AttributeSet atts) { - super(); + public DocumentationUnmarshaller(final XMLContext xmlContext, final AttributeSet atts) { + super(xmlContext); _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 7170) +++ src/main/java/org/exolab/castor/xml/schema/reader/SimpleContentRestrictionUnmarshaller.java (working copy) @@ -47,6 +47,7 @@ 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; @@ -108,16 +109,19 @@ //- Constructors -/ //----------------/ /** - * Creates a new RestrictionUnmarshaller + * Creates a new RestrictionUnmarshaller. + * @param xmlContext the XMLContext to get some configuration settings from * @param complexType the complexType being unmarshalled * @param atts the AttributeList */ public SimpleContentRestrictionUnmarshaller( - ComplexType complexType, AttributeSet atts, Resolver resolver) { + final XMLContext xmlContext, + final ComplexType complexType, + final AttributeSet atts) { - super(); - setResolver(resolver); - _complexType = complexType; + super(xmlContext); + + _complexType = complexType; _complexType.setDerivationMethod(SchemaNames.RESTRICTION); _complexType.setRestriction(true); _schema = complexType.getSchema(); @@ -257,7 +261,7 @@ "'restriction' elements."); foundAnnotation = true; - unmarshaller = new AnnotationUnmarshaller(atts); + unmarshaller = new AnnotationUnmarshaller(getXMLContext(), atts); } else if (SchemaNames.SIMPLE_TYPE.equals(name)) { @@ -274,7 +278,7 @@ "elements, must appear before any attribute elements."); foundSimpleType = true; - unmarshaller = new SimpleTypeUnmarshaller(_schema, atts); + unmarshaller = new SimpleTypeUnmarshaller(getXMLContext(), _schema, atts); } else if (FacetUnmarshaller.isFacet(name)) { @@ -283,7 +287,7 @@ error("A 'facet', as a child of 'restriction' "+ "elements, must appear before any attribute elements."); - unmarshaller = new FacetUnmarshaller(name, atts); + unmarshaller = new FacetUnmarshaller(getXMLContext(), name, atts); if (_simpleTypeDef == null) { SimpleContent content = (SimpleContent)_complexType.getContentType(); _simpleTypeDef = new SimpleTypeDefinition(_schema, content.getTypeName(),_id); @@ -291,7 +295,7 @@ } else if (SchemaNames.ATTRIBUTE.equals(name)) { foundAttribute = true; - unmarshaller = new AttributeUnmarshaller(_schema,atts, getResolver()); + unmarshaller = new AttributeUnmarshaller(getXMLContext(), _schema, atts); } else if (SchemaNames.ATTRIBUTE_GROUP.equals(name)) { @@ -301,17 +305,15 @@ "attributeGroups, but not defining ones."); } foundAttributeGroup = true; - unmarshaller = new AttributeGroupUnmarshaller(_schema,atts); + unmarshaller = new AttributeGroupUnmarshaller(getXMLContext(), _schema, atts); } //-- else if (SchemaNames.ANY_ATTRIBUTE.equals(name)) { unmarshaller - = new WildcardUnmarshaller(_complexType, _schema, name, atts, getResolver()); + = new WildcardUnmarshaller(getXMLContext(), _complexType, _schema, name, atts); } else illegalElement(name); - - 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 7170) +++ 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 7170) +++ 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 7170) +++ 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 7170) +++ 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,22 @@ } } + /** + * 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; + _cdResolver = _xmlContext.getXMLClassDescriptorResolver(); + } } //-- Marshaller Index: src/main/java/org/exolab/castor/xml/XMLNaming.java =================================================================== --- src/main/java/org/exolab/castor/xml/XMLNaming.java (revision 7170) +++ 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/resolvers/CastorXMLStrategy.java =================================================================== --- src/main/java/org/exolab/castor/xml/util/resolvers/CastorXMLStrategy.java (revision 7170) +++ src/main/java/org/exolab/castor/xml/util/resolvers/CastorXMLStrategy.java (working copy) @@ -38,6 +38,7 @@ * @since 1.2 */ public class CastorXMLStrategy implements ResolverStrategy { + /** Logger to be used. */ private static final Log LOG = LogFactory.getLog(CastorXMLStrategy.class); /** The strategy configuration held as map of properties. */ @@ -47,7 +48,6 @@ * CastorXMLStrategy requires a configuration to be set. Within the constructor the * commands building the strategy are instantiated, a command configuration is created * and the descriptor cache. - * @param configuration the strategy configuration to use. */ public CastorXMLStrategy() { _properties = new HashMap(); Index: src/main/java/org/exolab/castor/xml/util/resolvers/ByIntrospection.java =================================================================== --- src/main/java/org/exolab/castor/xml/util/resolvers/ByIntrospection.java (revision 7170) +++ src/main/java/org/exolab/castor/xml/util/resolvers/ByIntrospection.java (working copy) @@ -24,6 +24,7 @@ import org.exolab.castor.xml.MarshalException; import org.exolab.castor.xml.ResolverException; import org.exolab.castor.xml.XMLClassDescriptor; +import org.exolab.castor.xml.XMLContext; import org.exolab.castor.xml.util.ResolverStrategy; /** @@ -72,7 +73,7 @@ return results; } - Introspector introspector = new Introspector(); + Introspector introspector = new XMLContext().getIntrospector(); Class clazz = ResolveHelpers.loadClass(classLoader, className); if (clazz != null) { try { Index: src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorAdapter.java =================================================================== --- src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorAdapter.java (revision 7170) +++ 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/xml/util/XMLClassDescriptorResolverImpl.java =================================================================== --- src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorResolverImpl.java (revision 7170) +++ src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorResolverImpl.java (working copy) @@ -60,12 +60,13 @@ import org.apache.commons.logging.LogFactory; import org.exolab.castor.mapping.ClassDescriptor; import org.exolab.castor.mapping.MappingLoader; -import org.exolab.castor.util.Configuration; import org.exolab.castor.util.LocalConfiguration; import org.exolab.castor.util.Configuration.Property; +import org.exolab.castor.xml.Introspector; import org.exolab.castor.xml.ResolverException; import org.exolab.castor.xml.XMLClassDescriptor; import org.exolab.castor.xml.XMLClassDescriptorResolver; +import org.exolab.castor.xml.XMLContext; import org.exolab.castor.xml.util.resolvers.CastorXMLStrategy; import org.exolab.castor.xml.util.resolvers.ResolveHelpers; @@ -76,15 +77,21 @@ * @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $ */ public class XMLClassDescriptorResolverImpl implements XMLClassDescriptorResolver { + /** The Logger instance to use. */ private static final Log LOG = LogFactory.getLog(XMLClassDescriptorResolverImpl.class); /** + * XMLContext provides the information required. + */ + private XMLContext _xmlContext; + + /** * The strategy to use for all resolve actions. */ private ResolverStrategy _strategy; /** - * The place where all rsolving strategies and their commands put the results into + * The place where all resolving strategies and their commands put the results into * and can be read from. */ private DescriptorCacheImpl _descriptorCache; @@ -101,29 +108,140 @@ * current thread is used. */ private ClassLoader _loader; + + /** + * Should mapping files on package level be read? + */ + private Boolean _loadPackageMappings; + + /** + * Should introspection be used? + */ + private Boolean _useIntrospection; + + /** + * The introspector to be used. + */ + private Introspector _introspector; /** * Creates a new ClassDescriptorResolverImpl. + * It is left empty to avoid cycles at construction. To guarantee + * backward compatibility the backwardInit method will do all + * required initialization if it hadn't happend before. */ public XMLClassDescriptorResolverImpl() { - Configuration config = LocalConfiguration.getInstance(); - boolean loadPackageMappings = config.getBoolean( - Property.LOAD_PACKAGE_MAPPING, - Property.DEFAULT_LOAD_PACKAGE_MAPPING); - - _strategy = new CastorXMLStrategy(); - _strategy.setProperty( - ResolverStrategy.PROPERTY_LOAD_PACKAGE_MAPPINGS, - Boolean.valueOf(loadPackageMappings)); - + super(); _descriptorCache = new DescriptorCacheImpl(); _mappingLoader = null; _loader = null; } //-- ClassDescriptorResolverImpl + + /** + * {@inheritDoc} + */ + public void setXMLContext(final XMLContext xmlContext) { + _xmlContext = xmlContext; + _strategy = _xmlContext.getResolverStrategy(); + _loadPackageMappings = _xmlContext.getLoadPackageMapping(); + _useIntrospection = _xmlContext.getUseIntrospector(); + _introspector = _xmlContext.getIntrospector(); + _mappingLoader = _xmlContext.getMappingLoader(); + if (_strategy != null) { + setAttributesIntoStrategy(); + } + } + + /** + * {@inheritDoc} + */ + public MappingLoader getMappingLoader() { + return _mappingLoader; + } //-- getXMLMappingLoader /** * {@inheritDoc} */ + public void setClassLoader(final ClassLoader loader) { + _loader = loader; + } //-- setClassLoader + + /** + * {@inheritDoc} + */ + public void setUseIntrospection(final boolean enable) { + // used by XMLMappingLoader.createResolver() + _useIntrospection = Boolean.valueOf(enable); + getResolverStrategy().setProperty( + ResolverStrategy.PROPERTY_USE_INTROSPECTION, _useIntrospection); + } //-- setIntrospection + + /** + * {@inheritDoc} + */ + public void setLoadPackageMappings(final boolean loadPackageMappings) { + _loadPackageMappings = Boolean.valueOf(loadPackageMappings); + getResolverStrategy().setProperty( + ResolverStrategy.PROPERTY_LOAD_PACKAGE_MAPPINGS, + _loadPackageMappings); + } //-- setLoadPackageMappings + + /** + * {@inheritDoc} + */ + public void setMappingLoader(final MappingLoader mappingLoader) { + _mappingLoader = mappingLoader; + if (_mappingLoader != null) { + Iterator descriptors = _mappingLoader.descriptorIterator(); + while (descriptors.hasNext()) { + XMLClassDescriptor descriptor = (XMLClassDescriptor) descriptors.next(); + _descriptorCache.addDescriptor(descriptor.getClass().getName(), descriptor); + } + getResolverStrategy().setProperty( + ResolverStrategy.PROPERTY_MAPPING_LOADER, _mappingLoader); + } + } //-- setMappingLoader + + /** + * {@inheritDoc} + */ + public void setIntrospector(final Introspector introspector) { + _introspector = introspector; + getResolverStrategy().setProperty(ResolverStrategy.PROPERTY_INTROSPECTOR, _introspector); + } + + /** + * {@inheritDoc} + */ + public void setResolverStrategy(final ResolverStrategy resolverStrategy) { + _strategy = resolverStrategy; + setAttributesIntoStrategy(); + } + + /** + * XMLClassDescriptorResolver was originally build to collect all required + * information by itself... now with introduction of XMLContext and a more + * IoC like concepts that all information is injected into a class... things + * are different but this methods is there to guarantee backward + * compatibility. + * @return the {@link ResolverStrategy} to use + */ + private ResolverStrategy getResolverStrategy() { + if (_strategy == null) { + _strategy = new CastorXMLStrategy(); + LocalConfiguration config = LocalConfiguration.getInstance(); + boolean loadPackageMappings = config.getBoolean( + Property.LOAD_PACKAGE_MAPPING, + Property.DEFAULT_LOAD_PACKAGE_MAPPING); + _loadPackageMappings = Boolean.valueOf(loadPackageMappings); + setAttributesIntoStrategy(); + } + return _strategy; + } + + /** + * {@inheritDoc} + */ public ClassDescriptor resolve(final Class type) throws ResolverException { if (type == null) { String message = "Type argument must not be null for resolve"; @@ -181,8 +299,8 @@ if (l == null) { l = _loader; } if (l == null) { l = Thread.currentThread().getContextClassLoader(); } - _strategy.setProperty(ResolverStrategy.PROPERTY_CLASS_LOADER, l); - return (XMLClassDescriptor) _strategy.resolveClass(_descriptorCache, className); + getResolverStrategy().setProperty(ResolverStrategy.PROPERTY_CLASS_LOADER, l); + return (XMLClassDescriptor) getResolverStrategy().resolveClass(_descriptorCache, className); } //-- resolve(String, ClassLoader) /** @@ -212,7 +330,7 @@ } // we have more than one result - only an exact match can be the result - for (Iterator i = possibleMatches.iterator(); i.hasNext();) { + for (Iterator i = possibleMatches.iterator(); i.hasNext(); ) { XMLClassDescriptor descriptor = (XMLClassDescriptor) i.next(); if (ResolveHelpers.namespaceEquals(namespaceURI, descriptor.getNameSpaceURI())) { @@ -243,57 +361,6 @@ /** * {@inheritDoc} */ - public MappingLoader getMappingLoader() { - return _mappingLoader; - } //-- getXMLMappingLoader - - /** - * {@inheritDoc} - */ - public void setClassLoader(ClassLoader loader) { - _loader = loader; - } //-- setClassLoader - - /** - * Enables or disables introspection. Introspection is enabled by default. - * - * @param enable a flag to indicate whether or not introspection is allowed. - */ - public void setIntrospection(boolean enable) { - // used by XMLMappingLoader.createResolver() - _strategy.setProperty(ResolverStrategy.PROPERTY_USE_INTROSPECTION, new Boolean(enable)); - } //-- setIntrospection - - /** - * Sets whether or not to look for and load package specific mapping files (".castor.xml"). - * - * @param loadPackageMappings a boolean that enables or disables the loading of package - * specific mapping files - */ - public void setLoadPackageMappings(boolean loadPackageMappings) { - _strategy.setProperty( - ResolverStrategy.PROPERTY_LOAD_PACKAGE_MAPPINGS, - Boolean.valueOf(loadPackageMappings)); - } //-- setLoadPackageMappings - - /** - * {@inheritDoc} - */ - public void setMappingLoader(MappingLoader mappingLoader) { - _mappingLoader = mappingLoader; - if (_mappingLoader != null) { - Iterator descriptors = _mappingLoader.descriptorIterator(); - while (descriptors.hasNext()) { - XMLClassDescriptor descriptor = (XMLClassDescriptor) descriptors.next(); - _descriptorCache.addDescriptor(descriptor.getClass().getName(), descriptor); - } - _strategy.setProperty(ResolverStrategy.PROPERTY_MAPPING_LOADER, _mappingLoader); - } - } //-- setMappingLoader - - /** - * {@inheritDoc} - */ public void addClass(final String className) throws ResolverException { this.resolve(className); } @@ -329,7 +396,13 @@ * {@inheritDoc} */ public void addPackage(final String packageName) throws ResolverException { - _strategy.resolvePackage(_descriptorCache, packageName); + if (packageName == null || packageName.length() == 0) { + String message = "Cannot resolve a null or zero-length package name."; + LOG.warn(message); + throw new IllegalArgumentException(message); + } + + getResolverStrategy().resolvePackage(_descriptorCache, packageName); } /** @@ -350,6 +423,19 @@ LOG.warn(message); throw new UnsupportedOperationException(); } + + /** + * To set all strategy properties to the values of the attributes of this instance. + * Only exception is the class loader property which is always set in the resolve method. + */ + private void setAttributesIntoStrategy() { + _strategy.setProperty( + ResolverStrategy.PROPERTY_LOAD_PACKAGE_MAPPINGS, + _loadPackageMappings); + _strategy.setProperty(ResolverStrategy.PROPERTY_USE_INTROSPECTION, _useIntrospection); + _strategy.setProperty(ResolverStrategy.PROPERTY_MAPPING_LOADER, _mappingLoader); + _strategy.setProperty(ResolverStrategy.PROPERTY_INTROSPECTOR, _introspector); + } /** * Internal cache for XMLClassDescriptors.
@@ -366,9 +452,9 @@ * @author Steven Dolg */ private static class DescriptorCacheImpl implements ResolverStrategy.ResolverResults { - + /** Logger to be used by DescriptorCache. */ private static final Log LOG2 = LogFactory.getLog(DescriptorCacheImpl.class); - + /** Some fixed text to detect errors... */ private static final String INTERNAL_CONTAINER_NAME = "-error-if-this-is-used-"; /** List of class names a descriptor is not available for. */ @@ -428,7 +514,8 @@ } if (LOG2.isDebugEnabled()) { - LOG2.debug("Adding descriptor class for: " + className + " descriptor: " + descriptor); + LOG2.debug("Adding descriptor class for: " + + className + " descriptor: " + descriptor); } _typeMap.put(className, descriptor); @@ -457,7 +544,9 @@ * if no descriptor is stored in this cache. */ public XMLClassDescriptor getDescriptor(final String className) { - if ((className == null) || ("".equals(className)) || (_missingTypes.contains(className))) { + if ((className == null) + || ("".equals(className)) + || (_missingTypes.contains(className))) { return null; } Index: src/main/java/org/exolab/castor/types/AnyNode.java =================================================================== --- src/main/java/org/exolab/castor/types/AnyNode.java (revision 7170) +++ 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 7170) +++ 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 7170) +++ 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: src/doc/release-notes.xml =================================================================== --- src/doc/release-notes.xml (revision 7170) +++ src/doc/release-notes.xml (working copy) @@ -80,6 +80,42 @@ as he still specifies his properties in a single castor.properties file for all moduls.

+

Refactored JavaNaming

+ +

New JavaNaming is an exchangeable service instantiated trough XMLContext + and accessed in a non-static way. +

+ +

Refactored XMLClassDescriptorResolver

+ +

New XMLClassDescriptorResolver internally works with strategy and command + pattern to have the possibility to enhance class resolving for future + implementations (e.g. JAXB support). +

+ +

Refactored XMLContext

+ +

New XMLContext is the information centerpiece and point to start for Castor + XML stuff. It provides: +

+ We head to remove static usages and to a Castor being more loosely linked then + today. +

+ Index: src/doc/contributors.xml =================================================================== --- src/doc/contributors.xml (revision 7170) +++ src/doc/contributors.xml (working copy) @@ -528,6 +528,15 @@ + + jgrueneis@gmail.com + + Field of work is JAXB on top of Castor. Therefor a lot of refactorings + and adoptions in Castor XML are required. + + + + mguillemot@yahoo.fr Contributed a fix for bug 1452. Index: codegen/src/main/java/org/exolab/castor/builder/SourceGenerator.java =================================================================== --- codegen/src/main/java/org/exolab/castor/builder/SourceGenerator.java (revision 7170) +++ 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 7170) +++ 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); } Index: examples/src/main/java/tools/CastorMapper.java =================================================================== --- examples/src/main/java/tools/CastorMapper.java (revision 7170) +++ examples/src/main/java/tools/CastorMapper.java (working copy) @@ -10,6 +10,7 @@ import org.apache.commons.logging.LogFactory; import org.castor.xml.JavaNamingImpl; import org.exolab.castor.tools.MappingTool; +import org.exolab.castor.xml.XMLContext; import myapp.Product; import java.io.*; @@ -27,7 +28,7 @@ public CastorMapper() { try { - tool = new MappingTool(new JavaNamingImpl()); + tool = new XMLContext().createMappingTool(); } catch (Exception e) { log.error (e.getClass().getName(), e);