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 @@
//--
@@ -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.
New JavaNaming is an exchangeable service instantiated trough XMLContext + and accessed in a non-static way. +
+ +New XMLClassDescriptorResolver internally works with strategy and command + pattern to have the possibility to enhance class resolving for future + implementations (e.g. JAXB support). +
+ +New XMLContext is the information centerpiece and point to start for Castor + XML stuff. It provides: +