Index: .project
===================================================================
--- .project (revision 7250)
+++ .project (working copy)
@@ -1,6 +1,6 @@
- * 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.
- */
- public void addPackage(final String packageName) throws ResolverException {
- resolver.addPackage(packageName);
- }
-
- /**
- * 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).
- *
- * @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 {
- resolver.addPackages(packageNames);
- }
-
- /**
- * Creates an instance of a Castor XML specific {@link Mapping} instance.
- * @return a Castor XML specific {@link Mapping} instance.
- */
- public static Mapping createMapping() {
- Mapping mapping = new Mapping();
-// mapping.setBindingType(BindingType.XML);
- return mapping;
- }
-
- /**
- * Creates a new {@link Marshaller} instance to be used for marshalling.
- * @return A new {@link Marshaller} instance.
- */
- public Marshaller createMarshaller() {
- Marshaller marshaller = new Marshaller();
- marshaller.setResolver(resolver);
- return marshaller;
- }
-
- /**
- * Creates a new {@link Unmarshaller} instance to be used for unmarshalling.
- * @return A new {@link Unmarshaller} instance, preconfigured with
- * a {@link XMLClassDescriptorResolver} instance with the class
- * descriptors cached as loaded above.
- */
- public Unmarshaller createUnmarshaller() {
- Unmarshaller unmarshaller = new Unmarshaller();
- unmarshaller.setResolver(resolver);
- return unmarshaller;
- }
-
- /**
- * Sets an application-specific {@link XMLClassDescriptorResolver} instance
- * @param resolver
- */
- public void setResolver(XMLClassDescriptorResolver resolver) {
- this.resolver = resolver;
- }
-
-
-}
-
Index: src/main/java/org/exolab/castor/xml/XMLClassDescriptorResolver.java
===================================================================
--- src/main/java/org/exolab/castor/xml/XMLClassDescriptorResolver.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/XMLClassDescriptorResolver.java (working copy)
@@ -1,217 +1,285 @@
/**
* 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.castor.xml.InternalContext;
+import org.exolab.castor.xml.util.ResolverStrategy;
/**
* An interface for finding or "resolving" XMLClassDescriptor classes.
*
- *
- * 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/UnmarshalHandler.java
===================================================================
--- src/main/java/org/exolab/castor/xml/UnmarshalHandler.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/UnmarshalHandler.java (working copy)
@@ -66,6 +66,7 @@
import org.castor.mapping.BindingType;
import org.castor.util.Base64Decoder;
import org.castor.util.HexDecoder;
+import org.castor.xml.XMLConfiguration;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.ExtendedFieldHandler;
import org.exolab.castor.mapping.FieldHandler;
@@ -166,21 +167,23 @@
*/
private boolean _clearCollections = false;
- /**
- * The Castor configuration.
- */
- private Configuration _config = null;
+ // TODO: Joachim 2007-09-04 remove me
+// /**
+// * The Castor configuration.
+// */
+// private Configuration _config = null;
/**
* The SAX Document Locator.
**/
private Locator _locator = null;
- /**
- * The ClassDescriptorResolver which is used to "resolve"
- * or find ClassDescriptors.
- **/
- private XMLClassDescriptorResolver _cdResolver = null;
+// TODO: Joachim
+// /**
+// * The ClassDescriptorResolver which is used to "resolve"
+// * or find ClassDescriptors.
+// **/
+// private XMLClassDescriptorResolver _cdResolver = null;
/**
* The IDResolver for resolving IDReferences.
@@ -451,15 +454,15 @@
_reuseObjects = reuse;
} //-- setReuseObjects
- /**
- * Sets the ClassDescriptorResolver to use for loading and
- * resolving ClassDescriptors
- *
- * @param cdResolver the ClassDescriptorResolver to use
- **/
- public void setResolver(XMLClassDescriptorResolver cdResolver) {
- this._cdResolver = cdResolver;
- } //-- setResolver
+// /**
+// * Sets the ClassDescriptorResolver to use for loading and
+// * resolving ClassDescriptors
+// *
+// * @param cdResolver the ClassDescriptorResolver to use
+// **/
+// public void setResolver(XMLClassDescriptorResolver cdResolver) {
+// this._cdResolver = cdResolver;
+// } //-- setResolver
/**
* Sets the root (top-level) object to use for unmarshalling into.
@@ -873,7 +876,7 @@
ValidationException last = null;
//-- check unresolved references
- if (_resolveTable != null && !_config.getLenientIdValidation()) {
+ if (_resolveTable != null && !getInternalContext().getLenientIdValidation()) {
Enumeration enumeration = _resolveTable.keys();
while (enumeration.hasMoreElements()) {
Object ref = enumeration.nextElement();
@@ -892,10 +895,12 @@
try {
Validator validator = new Validator();
ValidationContext context = new ValidationContext();
- context.setResolver(_cdResolver);
- context.setConfiguration(_config);
+// context.setResolver(_cdResolver);
+ // TODO: Joachim 2007-09-04 remove me
+// context.setConfiguration(_config);
+ context.setInternalContext(getInternalContext());
validator.validate(state.object, context);
- if (!_config.getLenientIdValidation()) {
+ if (!getInternalContext().getLenientIdValidation()) {
validator.checkUnresolvedIdrefs(context);
}
context.cleanup();
@@ -1457,14 +1462,20 @@
_topClass = _topObject.getClass();
}
}
- if (_cdResolver == null) {
- if (_topClass == null) {
- String err = "The class for the root element '" +
- name + "' could not be found.";
- throw new SAXException(err);
- }
- _cdResolver = (XMLClassDescriptorResolver) ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
- _cdResolver.setClassLoader(_loader);
+// if (_cdResolver == null) {
+// if (_topClass == null) {
+// String err = "The class for the root element '" +
+// name + "' could not be found.";
+// throw new SAXException(err);
+// }
+// _cdResolver = (XMLClassDescriptorResolver) ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
+// _cdResolver.setClassLoader(_loader);
+// }
+ if (getInternalContext().getXMLClassDescriptorResolver() == null) {
+ // Joachim 2007-09-04 check is new
+ String message = "XMLClassDescriptorResolver is not set!";
+ LOG.warn(message);
+ throw new IllegalStateException(message);
}
_topState = new UnmarshalState();
@@ -1789,7 +1800,7 @@
if ((descriptor == null) && (!targetState.wrapper)) {
MarshalFramework.InheritanceMatch[] matches = null;
try {
- matches = searchInheritance(name, namespace, classDesc, _cdResolver);
+ matches = searchInheritance(name, namespace, classDesc); // TODO: Joachim, _cdResolver);
}
catch(MarshalException rx) {
//-- TODO:
@@ -1863,7 +1874,7 @@
count++;
}
- if (descriptor != null && isValidating() && !_config.getLenientSequenceOrder()) {
+ if (descriptor != null && isValidating() && !getInternalContext().getLenientSequenceOrder()) {
try {
classDesc.checkDescriptorForCorrectOrderWithinSequence(descriptor, parentState, name);
} catch (ValidationException e) {
@@ -1901,8 +1912,10 @@
//-- If we are skipping elements that have appeared in the XML but for
//-- which we have no mapping, increase the ignore depth counter and return
- boolean lenientElementStrictnessForIntrospection = Boolean.valueOf(
- _config.getProperty("org.exolab.castor.xml.lenient.introspected.element.strictness", "true")).booleanValue();
+ boolean lenientElementStrictnessForIntrospection =
+ getInternalContext()
+ .getBooleanProperty(XMLConfiguration.LENIENT_INTROSPECTED_ELEMENT_STRICTNESS)
+ .booleanValue();
if (! _strictElements) {
++_ignoreElementDepth;
//-- remove the StateInfo we just added
@@ -2433,19 +2446,20 @@
//- Protected Methods -/
//---------------------/
- /**
- * Sets the current Castor configuration. Currently this
- * Configuration is only used during Validation (which is
- * why this method is currently protected, since it has
- * no effect at this point on the actual configuration of
- * the unmarshaller)
- *
- * Currently, this method should only be called by the
- * Unmarshaller.
- */
- protected void setConfiguration(Configuration config) {
- _config = config;
- } //-- setConfiguration
+ // TODO: Joachim 2007-09-04 remove me
+// /**
+// * Sets the current Castor configuration. Currently this
+// * Configuration is only used during Validation (which is
+// * why this method is currently protected, since it has
+// * no effect at this point on the actual configuration of
+// * the unmarshaller)
+// *
+// * Currently, this method should only be called by the
+// * Unmarshaller.
+// */
+// protected void setConfiguration(Configuration config) {
+// _config = config;
+// } //-- setConfiguration
//-------------------/
//- Private Methods -/
@@ -2536,7 +2550,7 @@
XMLClassDescriptor classDesc = null;
try {
- classDesc = _cdResolver.resolveByXMLName(type, typeNamespaceURI, _loader);
+ classDesc = getInternalContext().getXMLClassDescriptorResolver().resolveByXMLName(type, typeNamespaceURI, _loader);
if (classDesc != null)
return classDesc.getJavaClass().getName();
@@ -2552,7 +2566,7 @@
if ((mappedPackage != null) && (mappedPackage.length() > 0)) {
adjClassName = mappedPackage + "." + className;
}
- classDesc = _cdResolver.resolve(adjClassName, _loader);
+ classDesc = getInternalContext().getXMLClassDescriptorResolver().resolve(adjClassName, _loader);
if (classDesc != null)
return classDesc.getJavaClass().getName();
@@ -2561,7 +2575,7 @@
adjClassName = currentPackage + '.' + className;
}
- classDesc = _cdResolver.resolve(adjClassName, _loader);
+ classDesc = getInternalContext().getXMLClassDescriptorResolver().resolve(adjClassName, _loader);
if (classDesc != null)
return classDesc.getJavaClass().getName();
@@ -2570,7 +2584,7 @@
//-- that was marshalled with a previous Castor. A
//-- bug fix in the XMLMappingLoader prevents old
//-- xsi:type that are missing the "java:"
- classDesc = _cdResolver.resolve(type, _loader);
+ classDesc = getInternalContext().getXMLClassDescriptorResolver().resolve(type, _loader);
if (classDesc != null)
return classDesc.getJavaClass().getName();
}
@@ -2938,7 +2952,7 @@
if (classDesc.getIdentity() == descriptor) {
try {
- _idResolver.bind(attValue, parent, isValidating() && !_config.getLenientIdValidation());
+ _idResolver.bind(attValue, parent, isValidating() && !getInternalContext().getLenientIdValidation());
} catch (ValidationException e) {
throw new SAXException("Duplicate ID " + attValue + " encountered.", e);
}
@@ -3354,15 +3368,16 @@
if (_class.isArray()) return null;
if (isPrimitive(_class)) return null;
- if (_cdResolver == null)
- _cdResolver = (XMLClassDescriptorResolver)
- ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
+// TODO: Joachim
+// if (_cdResolver == null)
+// _cdResolver = (XMLClassDescriptorResolver)
+// ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
XMLClassDescriptor classDesc = null;
try {
- classDesc = (XMLClassDescriptor) _cdResolver.resolve(_class);
+ classDesc = (XMLClassDescriptor) getInternalContext().getXMLClassDescriptorResolver().resolve(_class);
}
catch(ResolverException rx) {
// TODO
@@ -3390,14 +3405,15 @@
(String className, ClassLoader loader)
throws SAXException
{
- if (_cdResolver == null)
- _cdResolver = (XMLClassDescriptorResolver)
- ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
+// TODO: Joachim
+// if (_cdResolver == null)
+// _cdResolver = (XMLClassDescriptorResolver)
+// ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
XMLClassDescriptor classDesc = null;
try {
- classDesc = _cdResolver.resolve(className, loader);
+ classDesc = getInternalContext().getXMLClassDescriptorResolver().resolve(className, loader);
}
catch(ResolverException rx) {
throw new SAXException(rx);
@@ -3424,7 +3440,7 @@
{
try {
- return _cdResolver.resolveByXMLName(name, namespace, loader);
+ return getInternalContext().getXMLClassDescriptorResolver().resolveByXMLName(name, namespace, loader);
}
catch(ResolverException rx) {
throw new SAXException(rx);
Index: src/main/java/org/exolab/castor/xml/Introspector.java
===================================================================
--- src/main/java/org/exolab/castor/xml/Introspector.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/Introspector.java (working copy)
@@ -55,6 +55,8 @@
import java.util.Vector;
import org.castor.xml.JavaNaming;
+import org.castor.xml.XMLConfiguration;
+import org.castor.xml.InternalContext;
import org.exolab.castor.mapping.CollectionHandler;
import org.exolab.castor.mapping.FieldHandler;
import org.exolab.castor.mapping.FieldHandlerFactory;
@@ -86,39 +88,7 @@
*/
public final class Introspector {
-
/**
- * The property name for enabling collection wrapping.
- * The property controls whether or not collections
- * (arrays, vectors, etc) should be wrapped in a container element.
- * For example:
- *
- *
+ * 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.
+ */
+ public void addPackage(final String packageName) throws ResolverException {
+ _xmlClassDescriptorResolver.addPackage(packageName);
+ }
+
+ /**
+ * 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).
+ *
+ * @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 {
+ _xmlClassDescriptorResolver.addPackages(packageNames);
+ }
+
+ /**
+ * 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 propertyName name of the property to set
+ * @param value the value to set to
+ */
+ public void setProperty(final String propertyName, final Object value) {
+ _configuration.put(propertyName, value);
+ }
+
+ /**
+ * 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) {
+ return _configuration.getObject(propertyName);
+ }
+
+ /**
+ * 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
+ * @TODO: Joachim should be synchronized, shouldn't it be??
+ */
+ public XMLNaming getXMLNaming(final ClassLoader classLoader) {
+
+ if (_xmlNaming != null) {
+ return _xmlNaming;
+ }
+
+ String prop = _configuration.getString(XMLConfiguration.XML_NAMING, null);
+ if ((prop == null) || (prop.equalsIgnoreCase("lower"))) {
+ _xmlNaming = new DefaultNaming();
+ } else if (prop.equalsIgnoreCase("mixed")) {
+ DefaultNaming dn = new DefaultNaming();
+ dn.setStyle(DefaultNaming.MIXED_CASE_STYLE);
+ _xmlNaming = dn;
+ } else {
+ try {
+ Class cls = null;
+ if (classLoader != null) {
+ cls = classLoader.loadClass(prop);
+ } else {
+ cls = Class.forName(prop);
+ }
+ _xmlNaming = (XMLNaming) cls.newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException("Failed to load XMLNaming: " + e);
+ }
+ }
+ return _xmlNaming;
+ } //-- getXMLNaming
+
+ /**
+ * The {@link JavaNaming} instance to be used.
+ * @return {@link JavaNaming} instance to be used.
+ */
+ public JavaNaming getJavaNaming() {
+ return _javaNaming;
+ }
+
+ /**
+ * 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) {
+ Parser parser = null;
+ Boolean validation = _configuration.getBoolean(XMLConfiguration.PARSER_VALIDATION);
+ Boolean namespaces = _configuration.getBoolean(XMLConfiguration.NAMESPACES);
+ String parserClassName = _configuration.getString(XMLConfiguration.PARSER);
+ if ((parserClassName == null) || (parserClassName.length() == 0)) {
+ SAXParser saxParser = getSAXParser(validation, namespaces);
+ if (saxParser != null) {
+ try {
+ parser = saxParser.getParser();
+ } catch (SAXException e) {
+ LOG.error(Messages.format("conf.configurationError", e));
+ }
+ }
+ }
+
+ if (parser == null) {
+ if ((parserClassName == null)
+ || (parserClassName.length() == 0)
+ || (parserClassName.equalsIgnoreCase("xerces"))) {
+ parserClassName = "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(parserClassName);
+ parser = (Parser) cls.newInstance();
+ } catch (Exception except) {
+ throw new RuntimeException(Messages
+ .format("conf.failedInstantiateParser", parserClassName, except));
+ }
+
+ if (parser instanceof XMLReader) {
+ XMLReader xmlReader = (XMLReader) parser;
+ new XMLReaderService().setFeaturesOnXmlReader(
+ _configuration.getString(XMLConfiguration.PARSER_FEATURES, features),
+ _configuration.getString(XMLConfiguration.PARSER_FEATURES_DISABLED, ""),
+ validation.booleanValue(),
+ namespaces.booleanValue(),
+ 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.
+ *
+ * @param features the name of feature to set
+ * @return A suitable XML parser
+ */
+ public XMLReader getXMLReader(final String features) {
+ XMLReader reader = null;
+ Boolean validation = _configuration.getBoolean(XMLConfiguration.PARSER_VALIDATION);
+ Boolean namespaces = _configuration.getBoolean(XMLConfiguration.NAMESPACES);
+ String readerClassName = _configuration.getString(XMLConfiguration.PARSER);
+ if ((readerClassName == null) || (readerClassName.length() == 0)) {
+ SAXParser saxParser = getSAXParser(validation, namespaces);
+ if (saxParser != null) {
+ try {
+ reader = saxParser.getXMLReader();
+ } catch (SAXException e) {
+ LOG.error(Messages.format("conf.configurationError", e));
+ }
+ }
+ }
+
+ if (reader == null) {
+ if ((readerClassName == null)
+ || (readerClassName.length() == 0)
+ || (readerClassName.equalsIgnoreCase("xerces"))) {
+ readerClassName = "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(readerClassName);
+ reader = (XMLReader) cls.newInstance();
+ } catch (Exception e) {
+ throw new RuntimeException(
+ Messages.format("conf.failedInstantiateParser", readerClassName, e));
+ }
+ }
+
+ new XMLReaderService().setFeaturesOnXmlReader(
+ _configuration.getString(XMLConfiguration.PARSER_FEATURES, features),
+ _configuration.getString(XMLConfiguration.PARSER_FEATURES_DISABLED, ""),
+ validation.booleanValue(),
+ namespaces.booleanValue(),
+ reader);
+
+ return reader;
+
+ } //-- getXMLReader
+
+ /**
+ * To get a SAXParser instance which is then used to get either
+ * parser or XMLReader.
+ * @param validation validation flag to set into parser factory
+ * @param namespaces namespace flag to set into parser factory
+ * @return the SAXParser for further use
+ */
+ private SAXParser getSAXParser(final Boolean validation, final Boolean namespaces) {
+ SAXParser saxParser = null;
+
+ // If no parser class was specified, check for JAXP
+ // otherwise we default to Xerces.
+ SAXParserFactory factory = SAXParserFactory.newInstance();
+ factory.setNamespaceAware(namespaces.booleanValue());
+ factory.setValidating(validation.booleanValue());
+ try {
+ saxParser = factory.newSAXParser();
+ } catch (ParserConfigurationException pcx) {
+ LOG.error(Messages.format("conf.configurationError", pcx));
+ } catch (org.xml.sax.SAXException sx) {
+ LOG.error(Messages.format("conf.configurationError", sx));
+ }
+ return saxParser;
+ }
+
+ /**
+ * 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 (_primitiveNodeType != null) {
+ return _primitiveNodeType;
+ }
+
+ String prop = _configuration.getString(XMLConfiguration.PRIMITIVE_NODE_TYPE, null);
+ if (prop == null) {
+ return null;
+ }
+ _primitiveNodeType = NodeType.getNodeType(prop);
+ return _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() {
+ if (_regExpEvaluator != null) {
+ return _regExpEvaluator;
+ }
+
+ String regExpEvalClassName = _configuration.getString(XMLConfiguration.REG_EXP_CLASS_NAME);
+ if ((regExpEvalClassName == null) || (regExpEvalClassName.length() == 0)) {
+ _regExpEvaluator = null;
+ } else {
+ try {
+ Class regExpEvalClass = Class.forName(regExpEvalClassName);
+ _regExpEvaluator = (RegExpEvaluator) regExpEvalClass.newInstance();
+ } catch (ClassNotFoundException e) {
+ throw new RuntimeException(
+ Messages.format("conf.failedInstantiateRegExp", regExpEvalClassName, e));
+ } catch (InstantiationException e) {
+ throw new RuntimeException(
+ Messages.format("conf.failedInstantiateRegExp", regExpEvalClassName, e));
+ } catch (IllegalAccessException e) {
+ throw new RuntimeException(
+ Messages.format("conf.failedInstantiateRegExp", regExpEvalClassName, e));
+ }
+ }
+ return _regExpEvaluator;
+ } // -- 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(
+ _configuration.getString(
+ XMLConfiguration.SERIALIZER_FACTORY)).getSerializer();
+ serializer.setOutputFormat(getOutputFormat());
+ return serializer;
+ }
+ /**
+ * Returns the default OutputFormat for use with a Serializer.
+ *
+ * @return the default OutputFormat
+ **/
+ public OutputFormat getOutputFormat() {
+
+ boolean indent = _configuration.getBoolean(XMLConfiguration.USE_INDENTATION, false);
+
+ OutputFormat format = getSerializerFactory(
+ _configuration.getString(
+ XMLConfiguration.SERIALIZER_FACTORY))
+ .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 serializerFactoryName the class name of the serializer factory
+ * @return XMLSerializerFactory to use by Castor
+ */
+ protected XMLSerializerFactory getSerializerFactory(final String serializerFactoryName) {
+ XMLSerializerFactory serializerFactory;
+
+ 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;
+ }
+
+ /**
+ * 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 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;
+ }
+
+ /**
+ * 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 {@link JavaNaming} property.
+ * @param javaNaming the {@link JavaNaming} to use
+ */
+ public void setJavaNaming(final JavaNaming javaNaming) {
+ _javaNaming = javaNaming;
+ }
+
+ /**
+ * To set any boolean property.
+ * @param propertyName name of the property to set
+ * @param value boolean value to set
+ */
+ public void setProperty(final String propertyName, final boolean value) {
+ _configuration.put(propertyName, new Boolean(value));
+ }
+
+ /**
+ * Providing access to Boolean properties of the configuration.
+ * @param propertyName name of the property
+ * @return null if property is not set or whichever value is set
+ */
+ public Boolean getBooleanProperty(final String propertyName) {
+ return _configuration.getBoolean(propertyName);
+ }
+
+ /**
+ * Providing access to String properties of the configuration.
+ * @param propertyName name of the property
+ * @return null if the property is not set or whichever value is set
+ */
+ public String getStringProperty(final String propertyName) {
+ return _configuration.getString(propertyName);
+ }
+
+ /**
+ * To set the class loader to be used in all further marshalling, unmarshalling
+ * and other actions.
+ * @param classLoader the ClassLoader instance to use
+ */
+ public void setClassLoader(final ClassLoader classLoader) {
+ _classLoader = classLoader;
+ }
+
+ /**
+ * To set the {@link XMLClassDescriptorResolver} to be used. Be aware, that the
+ * XMLClassDescriptorResolver instance holds a descriptor cache!! Maybe change it
+ * to have the descriptor cache as part of the context?
+ * @param xmlClassDescriptorResolver the {@link XMLClassDescriptorResolver} to use
+ */
+ public void setXMLClassDescriptorResolver(
+ final XMLClassDescriptorResolver xmlClassDescriptorResolver) {
+ _xmlClassDescriptorResolver = xmlClassDescriptorResolver;
+ }
+
+ /**
+ * To specify which {@link Introspector} is to be used.
+ * @param introspector {@link Introspector} to be used
+ */
+ public void setIntrospector(final Introspector introspector) {
+ _introspector = introspector;
+ }
+
+ /**
+ * To get the ClassLoader to use for loading resources.
+ * @return the ClassLoader to use
+ */
+ public ClassLoader getClassLoader() {
+ return _classLoader;
+ }
+
+ /**
+ * Get lenient id validation flag.
+ * @return lenient id validation flag
+ */
+ public boolean getLenientIdValidation() {
+ Boolean lenientIdValidation =
+ _configuration.getBoolean(XMLConfiguration.LENIENT_ID_VALIDATION);
+ if (lenientIdValidation == null) {
+ String message = "Property lenientIdValidation must not be null";
+ LOG.warn(message);
+ throw new IllegalStateException(message);
+ }
+ return lenientIdValidation.booleanValue();
+ }
+
+ /**
+ * Get lenient sequence order flag.
+ * @return lenient sequence order flag
+ */
+ public boolean getLenientSequenceOrder() {
+ Boolean lenientSequenceOrder =
+ _configuration.getBoolean(XMLConfiguration.LENIENT_SEQUENCE_ORDER);
+ if (lenientSequenceOrder == null) {
+ String message = "Property lenientSequenceOrder must not be null";
+ LOG.warn(message);
+ throw new IllegalStateException(message);
+ }
+ return lenientSequenceOrder.booleanValue();
+ }
+
+ /**
+ * Get load package mapping flag.
+ * @return load package mapping flag
+ */
+ public Boolean getLoadPackageMapping() {
+ return _configuration.getBoolean(XMLConfiguration.LOAD_PACKAGE_MAPPING);
+ }
+
+ /**
+ * To set the load package mapping flag.
+ * @param loadPackageMapping the load package mapping flag
+ */
+ public void setLoadPackageMapping(final Boolean loadPackageMapping) {
+ _configuration.put(XMLConfiguration.LOAD_PACKAGE_MAPPING, loadPackageMapping);
+ }
+
+ /**
+ * To get use-introspection flag.
+ * @return use-introspection flag
+ */
+ public Boolean getUseIntrospector() {
+ return _configuration.getBoolean(XMLConfiguration.USE_INTROSPECTION);
+ }
+
+ /**
+ * To set use-introspection flag.
+ * @param useIntrospector use-introspection flag
+ */
+ public void setUseIntrospector(final Boolean useIntrospector) {
+ _configuration.put(XMLConfiguration.USE_INTROSPECTION, useIntrospector);
+ }
+
+ /**
+ * To get marshalling-validation flag.
+ * @return marshalling-validation flag
+ */
+ public boolean marshallingValidation() {
+ Boolean marshallingValidation =
+ _configuration.getBoolean(XMLConfiguration.MARSHALLING_VALIDATION);
+ if (marshallingValidation == null) {
+ String message = "Property marshallingValidation must not be null";
+ LOG.warn(message);
+ throw new IllegalStateException(message);
+ }
+ return marshallingValidation.booleanValue();
+ }
+
+ /**
+ * To get strict-element flag.
+ * @return strict-element flag
+ */
+ public boolean strictElements() {
+ Boolean strictElements =
+ _configuration.getBoolean(XMLConfiguration.STRICT_ELEMENTS);
+ if (strictElements == null) {
+ String message = "Property strictElements must not be null";
+ LOG.warn(message);
+ throw new IllegalStateException(message);
+ }
+ return strictElements.booleanValue();
+ }
+
+}
Index: src/main/java/org/castor/xml/XMLReaderService.java
===================================================================
--- src/main/java/org/castor/xml/XMLReaderService.java (revision 0)
+++ src/main/java/org/castor/xml/XMLReaderService.java (revision 0)
@@ -0,0 +1,87 @@
+package org.castor.xml;
+
+import java.util.StringTokenizer;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.castor.util.Messages;
+import org.xml.sax.SAXException;
+import org.xml.sax.SAXNotRecognizedException;
+import org.xml.sax.SAXNotSupportedException;
+import org.xml.sax.XMLReader;
+
+/**
+ * A couple of routines to manipulate XMLReader instances. Mostly extracted
+ * from 'old' LocalConfiguration class.
+ *
+ * @author Joachim Grueneis, jgrueneis_at_gmail_dot_com
+ * @version $Id$
+ */
+public class XMLReaderService {
+ /** Logger to be used. */
+ static final Log LOG = LogFactory.getFactory().getInstance(XMLReaderService.class);
+ /** 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 String parserFeatures,
+ final String parserFeaturesToDisable,
+ final boolean validation,
+ final boolean namespaces,
+ final XMLReader xmlReader) {
+ try {
+ xmlReader.setFeature(VALIDATION, validation);
+ xmlReader.setFeature(NAMESPACES, namespaces);
+ enableFeatures(parserFeatures, xmlReader);
+ disableFeatures(parserFeaturesToDisable, 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);
+ }
+ }
+ }
+}
\ No newline at end of file
Index: src/main/java/org/castor/xml/XMLConfiguration.java
===================================================================
--- src/main/java/org/castor/xml/XMLConfiguration.java (revision 7250)
+++ src/main/java/org/castor/xml/XMLConfiguration.java (working copy)
@@ -17,13 +17,9 @@
*/
package org.castor.xml;
-import java.util.Hashtable;
-import java.util.Map;
-
import org.castor.core.CoreConfiguration;
import org.castor.core.util.CastorConfiguration;
import org.castor.core.util.Configuration;
-import org.xml.sax.SAXException;
/**
* Castor configuration of XML modul.
@@ -176,7 +172,7 @@
"org.exolab.castor.parser.namespaces";
/**
- * Property specifying XML namespace to Java package mappings
+ * Property specifying XML namespace to Java package mappings.
*
*
- * 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 setInternalContext(final InternalContext 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).
*
- * <foos>
- * <foo>foo1</foo>
- * <foo>foo2</foo>
- * </foos>
- *
- * instead of the default:
- *
- * <foos>foo1<foos>
- * <foos>foo2</foos>
- *
- *
- *
- * Use this property with a value of true or false in the
- * castor.properties file
- *
- * org.exolab.castor.xml.introspector.wrapCollections=true
- * -or-
- * org.exolab.castor.xml.introspector.wrapCollections=false
- *
- * This property is false by default.
- */
- public static final String WRAP_COLLECTIONS_PROPERTY =
- "org.exolab.castor.xml.introspector.wrapCollections";
-
- /**
* The default FieldHandlerFactory
*/
private FieldHandlerFactory DEFAULT_HANDLER_FACTORY = new DefaultFieldHandlerFactory();
@@ -169,7 +139,7 @@
/**
* The naming conventions to use
**/
- private XMLNaming _naming = null;
+ private XMLNaming _xmlNaming = null;
/**
* The NodeType to use for primitives
@@ -227,6 +197,8 @@
*/
private JavaNaming _javaNaming;
+ private InternalContext _internalContext;
+
/**
* Creates a new instance of the Introspector.
*/
@@ -239,40 +211,27 @@
*
* @param classLoader
*/
- public Introspector(ClassLoader classLoader) {
+ public Introspector(final ClassLoader classLoader) {
super();
_classLoader = classLoader;
init();
} //-- Introspector
private void init() {
-
- LocalConfiguration config = LocalConfiguration.getInstance();
-
- if (_defaultNaming == null) {
- _defaultNaming = config.getXMLNaming(_classLoader);
+ if (_internalContext != null) {
+ _javaNaming = _internalContext.getJavaNaming();
+ _xmlNaming = _internalContext.getXMLNaming();
+ setPrimitiveNodeType(_internalContext.getPrimitiveNodeType());
+ _wrapCollectionsInContainer = _internalContext.getBooleanProperty(XMLConfiguration.WRAP_COLLECTIONS_PROPERTY).booleanValue();
+ _saveMapKeys =
+ _internalContext.getBooleanProperty(XMLConfiguration.SAVE_MAP_KEYS).booleanValue();
}
- _naming = _defaultNaming;
- _javaNaming = config.getJavaNaming();
-
- setPrimitiveNodeType(config.getPrimitiveNodeType());
-
- //-- wrap collections in a container element?
- String wrap = config.getProperty(WRAP_COLLECTIONS_PROPERTY, null);
- if (wrap != null) {
- _wrapCollectionsInContainer = Boolean.valueOf(wrap).booleanValue();
- }
-
- //-- Save Hashtable / Map keys ?
- String saveKeys = config.getProperty(Configuration.Property.SaveMapKeys, null);
- if (saveKeys != null) {
- if ("false".equals(saveKeys) || "off".equals(saveKeys)) {
- _saveMapKeys = false;
- }
- }
-
} //-- init
+ public void setInternalContext(InternalContext internalContext) {
+ _internalContext = internalContext;
+ init();
+ }
/**
* Registers the given "generalized" FieldHandlerFactory with this
@@ -525,7 +484,7 @@
MethodSet methodSet = (MethodSet) enumeration.nextElement();
//-- create XMLFieldDescriptor
- String xmlName = _naming.toXMLName(methodSet.fieldName);
+ String xmlName = _xmlNaming.toXMLName(methodSet.fieldName);
boolean isCollection = false;
@@ -771,7 +730,7 @@
}
String fieldName = field.getName();
- String xmlName = _naming.toXMLName(fieldName);
+ String xmlName = _xmlNaming.toXMLName(fieldName);
//-- Create FieldHandler first, before the XMLFieldDescriptor
//-- in case we need to use a custom handler
@@ -983,9 +942,9 @@
**/
public void setNaming(XMLNaming naming) {
if (naming == null)
- _naming = _defaultNaming;
+ _xmlNaming = _defaultNaming;
else
- _naming = naming;
+ _xmlNaming = naming;
} //-- setNaming
/**
Index: src/main/java/org/exolab/castor/xml/Unmarshaller.java
===================================================================
--- src/main/java/org/exolab/castor/xml/Unmarshaller.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/Unmarshaller.java (working copy)
@@ -45,8 +45,6 @@
package org.exolab.castor.xml;
-
-//-- castor imports
import java.io.PrintWriter;
import java.io.Reader;
import java.util.HashMap;
@@ -57,11 +55,11 @@
import org.apache.commons.logging.LogFactory;
import org.castor.mapping.BindingType;
import org.castor.mapping.MappingUnmarshaller;
+import org.castor.xml.InternalContext;
+import org.castor.xml.XMLConfiguration;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.mapping.MappingLoader;
-import org.exolab.castor.util.Configuration;
-import org.exolab.castor.util.LocalConfiguration;
import org.exolab.castor.util.ObjectFactory;
import org.exolab.castor.xml.location.FileLocation;
import org.exolab.castor.xml.util.DOMEventProducer;
@@ -72,6 +70,7 @@
import org.xml.sax.Parser;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
+
/**
* An unmarshaller to allowing unmarshalling of XML documents to
* Java Objects. The Class must specify
@@ -84,7 +83,7 @@
public class Unmarshaller {
/**
- * Logger from commons-logging
+ * Logger from commons-logging.
*/
private static final Log LOG = LogFactory.getLog(Unmarshaller.class);
@@ -93,13 +92,8 @@
//----------------------------/
/**
- * The class descriptor resolver
+ * The Class that this Unmarshaller was created with.
*/
- private XMLClassDescriptorResolver _cdResolver = null;
-
- /**
- * The Class that this Unmarshaller was created with
- */
private Class _class = null;
/**
@@ -107,17 +101,11 @@
* arrays) should be cleared upon initial use by Castor.
* False by default for backward compatibility.
*/
- private boolean _clearCollections = false;
+ private boolean _clearCollections = false;
/**
- * Castor configuration
+ * A user specified IDResolver for resolving IDREFs.
*/
- private Configuration _config = null;
-
-
- /**
- * A user specified IDResolver for resolving IDREFs
- */
private IDResolver _idResolver = null;
/**
@@ -184,67 +172,101 @@
/**
* An optional factory for unmarshalling objects
*/
- private ObjectFactory _objectFactory;
+ private ObjectFactory _objectFactory;
+
+ /**
+ * The Castor XML context to use at unmarshalling.
+ */
+ private InternalContext _internalContext;
//----------------/
//- Constructors -/
//----------------/
+ public Unmarshaller(final Class clazz) {
+ this(new XMLContext().getInternalContext(), clazz);
+ }
+
/**
- * Creates a new basic Unmarshaller
+ * Creates a new basic Unmarshaller.
*
* When using this constructor it will most likely be
* necessary to use a mapping file or ClassDescriptorResolver
* So that the Unmarshaller can find the classes during the
* unmarshalling process.
*/
- public Unmarshaller() {
- this((Class)null, (ClassLoader)null);
+ public Unmarshaller(final InternalContext internalContext) {
+ this(internalContext, (Class) null, (ClassLoader) null);
} //-- Unmarshaller()
/**
- * Creates a new Unmarshaller with the given Class
+ * Creates a new Unmarshaller with the given Class.
*
* @param c the Class to create the Unmarshaller for, this
* may be null, if the Unmarshaller#setMapping is called
* to load a mapping for the root element of xml document.
*/
- public Unmarshaller(Class c) {
- this(c, null);
+ public Unmarshaller(final InternalContext internalContext, final Class c) {
+ this(internalContext, c, null);
} //-- Unmarshaller(Class)
/**
- * Creates a new Unmarshaller with the given Class
+ * Creates a new Unmarshaller with the given Class.
*
+ * @param internalContext the context to be used, for config, and such...
* @param c the Class to create the Unmarshaller for, this
* may be null, if the Unmarshaller#setMapping is called
* to load a mapping for the root element of xml document.
* @param loader The ClassLoader to use.
*/
- public Unmarshaller(Class c, ClassLoader loader) {
+ public Unmarshaller(final InternalContext internalContext, final Class c, final ClassLoader loader) {
super();
- initConfig();
+
+ _internalContext = internalContext;
+ _validate = _internalContext.marshallingValidation();
+ _ignoreExtraElements = (!_internalContext.strictElements());
+
+ //-- process namespace to package mappings
+ String mappings =
+ _internalContext.getStringProperty(XMLConfiguration.NAMESPACE_PACKAGE_MAPPINGS);
+ if (mappings != null) {
+ StringTokenizer tokens = new StringTokenizer(mappings, ",");
+ while (tokens.hasMoreTokens()) {
+ String token = tokens.nextToken();
+ int sepIdx = token.indexOf('=');
+ if (sepIdx < 0) {
+ continue;
+ }
+ String ns = token.substring(0, sepIdx).trim();
+ String javaPackage = token.substring(sepIdx + 1).trim();
+ addNamespaceToPackageMapping(ns, javaPackage);
+ }
+ }
+
setClass(c);
_loader = loader;
if ((loader == null) && (c != null)) {
_loader = c.getClassLoader();
}
- _cdResolver = (XMLClassDescriptorResolver)
- ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
- _cdResolver.setClassLoader(loader);
+ _internalContext.setClassLoader(_loader);
+
} //-- Unmarshaller(Class)
+ public Unmarshaller(final Mapping mapping) throws MappingException {
+ this(new XMLContext().getInternalContext(), mapping);
+ }
/**
- * Creates a new Unmarshaller with the given Mapping
+ * Creates a new Unmarshaller with the given Mapping.
*
+ * @param internalContext the internal context to use
* @param mapping The Mapping to use.
+ * @throws MappingException in case that Unmarshaller fails to be instantiated
*/
- public Unmarshaller(Mapping mapping)
- throws MappingException
- {
- super();
- initConfig();
+ public Unmarshaller(final InternalContext internalContext, final Mapping mapping)
+ throws MappingException {
+ this(internalContext, null, null);
+// initConfig();
if (mapping != null) {
setMapping(mapping);
this._loader = mapping.getClassLoader();
@@ -253,14 +275,16 @@
/**
- * Creates a new Unmarshaller with the given Object
+ * Creates a new Unmarshaller with the given Object.
*
+ * @param internalContext the internal context to use
* @param root the instance to unmarshal into. This
* may be null, if the Unmarshaller#setMapping is called
* to load a mapping for the root element of xml document.
*/
- public Unmarshaller(Object root) {
- initConfig();
+ public Unmarshaller(final InternalContext internalContext, final Object root) {
+ this(internalContext, null, null);
+// initConfig();
if (root != null) {
final Class clazz = root.getClass();
setClass(clazz);
@@ -268,35 +292,10 @@
}
_instanceObj = root;
} //-- Unmarshaller(Class)
-
- /**
- * Used by constructors to get configuration information
- */
- private void initConfig() {
- _config = LocalConfiguration.getInstance();
- _validate = _config.marshallingValidation();
- _ignoreExtraElements = (!_config.strictElements());
-
- //-- process namespace to package mappings
- String mappings = _config.getProperty(Configuration.Property.NamespacePackages, null);
- if (mappings != null) {
- StringTokenizer tokens = new StringTokenizer(mappings, ",");
- while(tokens.hasMoreTokens()) {
- String token = tokens.nextToken();
- int sepIdx = token.indexOf('=');
- if (sepIdx < 0) continue;
- String ns = token.substring(0,sepIdx).trim();
- String javaPackage = token.substring(sepIdx+1).trim();
- addNamespaceToPackageMapping(ns, javaPackage);
- }
- }
-
-
- } //-- initConfig
/**
* Adds a mapping from the given namespace URI to the given
- * package name
+ * package name.
*
* @param nsURI the namespace URI to map from
* @param packageName the package name to map to
@@ -322,18 +321,12 @@
UnmarshalHandler handler = new UnmarshalHandler(_class);
- if (_cdResolver == null) {
- _cdResolver = (XMLClassDescriptorResolver)
- ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
- _cdResolver.setClassLoader(_loader);
- }
- handler.setResolver(_cdResolver);
handler.setClearCollections(_clearCollections);
handler.setReuseObjects(_reuseObjects);
handler.setValidation(_validate);
handler.setIgnoreExtraAttributes(_ignoreExtraAtts);
handler.setIgnoreExtraElements(_ignoreExtraElements);
- handler.setConfiguration(_config);
+ handler.setInternalContext(_internalContext);
handler.setWhitespacePreserve(_wsPreserve);
// If the object factory has been set, set it on the handler
@@ -504,16 +497,10 @@
_loader = mapping.getClassLoader();
}
- if (_cdResolver == null) {
- _cdResolver = (XMLClassDescriptorResolver) ClassDescriptorResolverFactory
- .createClassDescriptorResolver(BindingType.XML);
-
- _cdResolver.setClassLoader(_loader);
- }
-
MappingUnmarshaller mum = new MappingUnmarshaller();
+ mum.setInternalContext(_internalContext);
MappingLoader resolver = mum.getMappingLoader(mapping, BindingType.XML);
- _cdResolver.setMappingLoader(resolver);
+ _internalContext.getXMLClassDescriptorResolver().setMappingLoader(resolver);
}
/**
@@ -530,26 +517,6 @@
} //-- setReuseObjects
/**
- * Sets the ClassDescriptorResolver to use during unmarshalling
- * @param cdr the ClassDescriptorResolver to use
- * @see #setMapping
- *
- * Note: This method will nullify any Mapping
- * currently being used by this Unmarshaller
- **/
- public void setResolver( XMLClassDescriptorResolver cdr ) {
-
- if (cdr != null)
- _cdResolver = cdr;
- else {
- _cdResolver = (XMLClassDescriptorResolver)
- ClassDescriptorResolverFactory.createClassDescriptorResolver(BindingType.XML);
- _cdResolver.setClassLoader(_loader);
- }
-
- } //-- setResolver
-
- /**
* Sets an optional {@link UnmarshalListener} to receive pre and
* post unmarshal notification for each Object in the tree.
* An UnmarshalListener is often used to allow objects to
@@ -683,15 +650,15 @@
//-- First try XMLReader
try {
- reader = _config.getXMLReader();
+ reader = _internalContext.getXMLReader();
if (entityResolver != null)
reader.setEntityResolver(entityResolver);
- } catch(RuntimeException rx) {
+ } catch (RuntimeException rx) {
LOG.debug("Unable to create SAX XMLReader, attempting SAX Parser.");
}
if (reader == null) {
- parser = _config.getParser();
+ parser = _internalContext.getParser();
if (parser == null)
throw new MarshalException("Unable to create SAX Parser.");
if (entityResolver != null)
@@ -714,10 +681,10 @@
parser.parse(source);
}
}
- catch(java.io.IOException ioe) {
+ catch (java.io.IOException ioe) {
throw new MarshalException(ioe);
}
- catch(org.xml.sax.SAXException sx) {
+ catch (org.xml.sax.SAXException sx) {
convertSAXExceptionToMarshalException(handler, sx);
}
@@ -808,8 +775,10 @@
* @param clazz The root class to be used during unmarshalling.
* @return An {@link Unmarshaller} instance.
*/
- private static Unmarshaller createUnmarshaller(Class clazz) {
- Unmarshaller unmarshaller = new Unmarshaller(clazz);
+ private static Unmarshaller createUnmarshaller(final Class clazz) {
+ XMLContext xmlContext = new XMLContext();
+ Unmarshaller unmarshaller = xmlContext.createUnmarshaller();
+ unmarshaller.setClass(clazz);
// TODO: Should this be at level INFO?
if (LOG.isDebugEnabled()) {
@@ -869,36 +838,58 @@
return unmarshaller.unmarshal(node);
} //-- void unmarshal(Writer)
- /**
- * Set an object factory for the unmarshaller. This
- * factory will be used to construct the objects being
- * unmarshalled.
- * @param objectFactory Factory used for constructing objects
- * during unmarshalling.
- */
- public void setObjectFactory(ObjectFactory objectFactory) {
- this._objectFactory = objectFactory;
- } // -- setObjectFactory
+ /**
+ * Set an object factory for the unmarshaller. This factory will be used to
+ * construct the objects being unmarshalled.
+ *
+ * @param objectFactory
+ * Factory used for constructing objects during unmarshalling.
+ */
+ public void setObjectFactory(final ObjectFactory objectFactory) {
+ this._objectFactory = objectFactory;
+ } // -- setObjectFactory
- /**
- * Returns the value of the given Castor XML-specific property.
- * @param name Qualified name of the CASTOR XML-specific property.
- * @return The current value of the given property.
- * @since 1.1.2
- */
- public String getProperty(final String name) {
- return _config.getProperties().getProperty(name);
- }
+ /**
+ * Returns the value of the given Castor XML-specific property.
+ *
+ * @param name
+ * Qualified name of the CASTOR XML-specific property.
+ * @return The current value of the given property.
+ * @since 1.1.2
+ */
+ public String getProperty(final String name) {
+ Object propertyValue = _internalContext.getProperty(name);
+ if ((propertyValue != null) && !(propertyValue instanceof String)) {
+ String message =
+ "Requested property: " + name
+ + " is not of type String, but: " + propertyValue.getClass()
+ + " throwing IllegalStateException.";
+ LOG.warn(message);
+ throw new IllegalStateException(message);
+ }
+ return (String) propertyValue;
+ }
- /**
+ /**
* Sets a custom value of a given Castor XML-specific property.
- * @param name Name of the Castor XML property
- * @param value Custom value to set.
+ *
+ * @param name
+ * Name of the Castor XML property
+ * @param value
+ * Custom value to set.
* @since 1.1.2
- */
- public void setProperty(final String name, final String value) {
- _config.getProperties().setProperty(name, value);
- }
+ */
+ public void setProperty(final String name, final String value) {
+ _internalContext.setProperty(name, value);
+ }
+
+ /**
+ * To set the internal XML Context to be used.
+ * @param xmlContext the context to be used
+ */
+ public void setInternalContext(final InternalContext xmlContext) {
+ _internalContext = xmlContext;
+ }
} //-- Unmarshaller
Index: src/main/java/org/exolab/castor/xml/ValidationContext.java
===================================================================
--- src/main/java/org/exolab/castor/xml/ValidationContext.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/ValidationContext.java (working copy)
@@ -50,6 +50,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.castor.xml.InternalContext;
import org.exolab.castor.util.Configuration;
import org.exolab.castor.util.LocalConfiguration;
@@ -61,24 +62,24 @@
* @version $Revision$ $Date: 2004-10-06 02:10:17 -0600 (Wed, 06 Oct 2004) $
*/
public class ValidationContext {
-
/** Logger for debugging and error information. */
private static final Log LOG = LogFactory.getLog(ValidationContext.class);
- /** The Castor configuration. */
- private Configuration _config = null;
+ /** The Castor internal context - mother of all dwelling. */
+ private InternalContext _internalContext = null;
+
/** A flag to indicate fail-fast validation. When true, the first error
* encounted will cause a Validation Exception. When false, the validator
* should attempt to validate as much as possible, collecting as many errors
* as possible before throwing a validation exception. */
private boolean _failFast = true;
- /** The ClassDescriptorResolver to be used for loading and resolving
- * ClassDescriptors during validation. */
- private XMLClassDescriptorResolver _resolver = null;
+
/** The List of objects marked as validated. */
private final Set _validated = new HashSet();
+
/** The Set of already encountered IDs (of type <xsd:ID>). */
private final Set _ids = new HashSet();
+
/** The Set of temporary unreseolved IDREFS. */
private final Set _unresolvedIdrefs = new HashSet();
@@ -90,24 +91,28 @@
}
/**
- * Returns the Configuration to use during validation.
- *
- * @return the Configuration to use. Will never be null.
+ * To get the {@link InternalContext} to use.
+ * @return the {@link InternalContext} to use
*/
- public Configuration getConfiguration() {
- if (_config == null) {
- _config = LocalConfiguration.getInstance();
- }
- return _config;
- }
+ public InternalContext getInternalContext() {
+ return _internalContext;
+ }
/**
+ * To set which {@link InternalContext} should be used.
+ * @param internalContext the {@link InternalContext} to use
+ */
+ public void setInternalContext(final InternalContext internalContext) {
+ _internalContext = internalContext;
+ }
+
+ /**
* Returns the ClassDescriptorResolver to use during validation.
*
* @return the ClassDescriptorResolver to use. May be null.
*/
- public XMLClassDescriptorResolver getResolver() {
- return _resolver;
+ public XMLClassDescriptorResolver getClassDescriptorResolver() {
+ return _internalContext.getXMLClassDescriptorResolver();
}
/**
@@ -126,15 +131,6 @@
}
/**
- * Sets the Configuration used during validation.
- *
- * @param config the Configuration to use
- */
- public void setConfiguration(final Configuration config) {
- _config = config;
- }
-
- /**
* Sets the fail-fast flag. Fail-fast is enabled by default. When fail-fast
* is enabled (default or by setting the flag to true) the validation
* process will throw an exception upon the first error encountered. When
@@ -154,15 +150,6 @@
}
/**
- * Sets the ClassDescriptorResolver to use during validation.
- *
- * @param resolver the ClassDescriptorResolver to use.
- */
- public void setResolver(final XMLClassDescriptorResolver resolver) {
- _resolver = resolver;
- }
-
- /**
* Checks whether an object has already been validated.
* @param object The object for which the check should be performed
* @return True if the object specified has already been validated.
@@ -209,7 +196,7 @@
if (!_ids.contains(id)) {
_ids.add(id);
_unresolvedIdrefs.remove(id);
- } else if (!_config.getLenientIdValidation()){
+ } else if (!_internalContext.getLenientIdValidation()){
throw new ValidationException ("ID " + id + " is already used within current document.");
}
}
@@ -251,5 +238,4 @@
_validated.clear();
_unresolvedIdrefs.clear();
}
-
}
Index: src/main/java/org/exolab/castor/xml/MarshalFramework.java
===================================================================
--- src/main/java/org/exolab/castor/xml/MarshalFramework.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/MarshalFramework.java (working copy)
@@ -45,8 +45,11 @@
package org.exolab.castor.xml;
+import java.util.Iterator;
+import java.util.Vector;
+
+import org.castor.xml.InternalContext;
import org.castor.xml.JavaNaming;
-import org.castor.xml.JavaNamingImpl;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.CollectionHandler;
import org.exolab.castor.mapping.FieldDescriptor;
@@ -54,10 +57,7 @@
import org.exolab.castor.mapping.loader.CollectionHandlers;
import org.exolab.castor.util.ReflectionUtil;
-import java.util.Iterator;
-import java.util.Vector;
-
/**
* A core class for common code shared throughout the
* Marshalling Framework
@@ -165,12 +165,12 @@
//-----------------------------/
//- Private variables -/
//-----------------------------/
-
+
/**
- * The {@link JavaNaming} to use at unmarhsalling.
+ * The {@link InternalContext} to use at all un-marshal actions.
* @since 1.1.3
*/
- private JavaNaming _javaNaming;
+ private InternalContext _internalContext;
//-----------------------------/
//- Public methods -/
@@ -180,7 +180,7 @@
* We need some stuff initialized here.
*/
public MarshalFramework() {
- _javaNaming = new JavaNamingImpl();
+ _internalContext = new InternalContext();
}
/**
@@ -188,16 +188,33 @@
* @return the JavaNaming to be used
*/
public JavaNaming getJavaNaming() {
- return _javaNaming;
+ return _internalContext.getJavaNaming();
}
/**
* To set the {@link JavaNaming} instance to be used.
* @param javaNaming the JavaNaming to be used
+ * TODO: joachim remove me if possible!
*/
- public void setJavaNaming(final JavaNaming javaNaming) {
- _javaNaming = javaNaming;
+ private void setJavaNaming(final JavaNaming javaNaming) {
+ _internalContext.setJavaNaming(javaNaming);
}
+
+ /**
+ * To get the {@link InternalContext} to use.
+ * @return the {@link InternalContext} to use
+ */
+ public InternalContext getInternalContext() {
+ return _internalContext;
+ }
+
+ /**
+ * To set the {@link InternalContext} to use.
+ * @param internalContext the {@link InternalContext} to use
+ */
+ public void setInternalContext(final InternalContext internalContext) {
+ _internalContext = internalContext;
+ }
/**
* Returns true if the given Class is a considered a
@@ -457,7 +474,7 @@
*/
protected InheritanceMatch[] searchInheritance(final String name,
final String namespace,
- final XMLClassDescriptor classDesc, final XMLClassDescriptorResolver cdResolver)
+ final XMLClassDescriptor classDesc)
throws MarshalException {
Iterator classDescriptorIterator = null;
@@ -480,11 +497,14 @@
className = pkg + className;
}
}
- cdResolver.resolve(className, classDesc.getClass().getClassLoader());
+ getInternalContext().getXMLClassDescriptorResolver().resolve(
+ className, classDesc.getClass().getClassLoader());
//-- end Not-Yet-Loaded descriptor logic
//-- resolve all by XML name + namespace URI
- classDescriptorIterator = cdResolver.resolveAllByXMLName(name, namespace, null);
+ classDescriptorIterator =
+ getInternalContext().getXMLClassDescriptorResolver().resolveAllByXMLName(
+ name, namespace, null);
}
catch (ResolverException rx) {
Throwable actual = rx.getCause();
Index: src/main/java/org/exolab/castor/xml/schema/SimpleTypesFactory.java
===================================================================
--- src/main/java/org/exolab/castor/xml/schema/SimpleTypesFactory.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/schema/SimpleTypesFactory.java (working copy)
@@ -52,6 +52,8 @@
import java.util.Vector;
import java.util.Hashtable;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.castor.util.Messages;
import org.exolab.castor.util.LocalConfiguration;
import org.exolab.castor.mapping.Mapping;
@@ -75,6 +77,10 @@
* @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
**/
public class SimpleTypesFactory {
+ /**
+ * The Logger instance to use.
+ */
+ private static final Log LOG = LogFactory.getLog(SimpleTypesFactory.class);
//Type Codes:
@@ -426,10 +432,14 @@
TypeList typeList = (TypeList)unmarshaller.unmarshal( new org.xml.sax.InputSource(is) );
//print what we just read (only in debug mode and if we have a logWriter)
- LocalConfiguration config = LocalConfiguration.getInstance();
- if (config.debug() && getLogWriter()!= null) {
- typeList.Print(getLogWriter());
+ // TODO: Joachim 2007-09-04 remove me
+ // LocalConfiguration config = LocalConfiguration.getInstance();
+ if (LOG.isDebugEnabled()) {
+ LOG.debug(typeList.toString());
}
+ //if (config.debug() && getLogWriter()!= null) {
+ // typeList.Print(getLogWriter());
+ //}
//Store the types by name in the typesByName and typesByCode hashtables
//and create for each its associated SimpleType instance.
Index: src/main/java/org/exolab/castor/xml/schema/reader/RedefineUnmarshaller.java
===================================================================
--- src/main/java/org/exolab/castor/xml/schema/reader/RedefineUnmarshaller.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/schema/reader/RedefineUnmarshaller.java (working copy)
@@ -46,6 +46,7 @@
package org.exolab.castor.xml.schema.reader;
//-- imported classes and packages
+import org.castor.xml.InternalContext;
import org.exolab.castor.net.*;
import org.exolab.castor.xml.*;
import org.exolab.castor.xml.schema.*;
@@ -92,16 +93,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 InternalContext internalContext,
+ final Schema schema,
+ final AttributeSet atts,
+ final URIResolver uriResolver,
+ final Locator locator,
+ final SchemaUnmarshallerState state)
+ throws XMLException {
+ super(internalContext);
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 +181,14 @@
//-- Parser Schema
Parser parser = null;
try {
- parser = state.getConfiguration().getParser();
+ parser = getInternalContext().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(getInternalContext(), state);
schemaUnmarshaller.setURIResolver(getURIResolver());
schemaUnmarshaller.setSchema(importedSchema);
Sax2ComponentReader handler = new Sax2ComponentReader(schemaUnmarshaller);
@@ -270,24 +274,24 @@
//--
* Note: This method will nullify any Mapping
@@ -673,9 +665,12 @@
* @see #setMapping
* @see #getResolver
*/
- public void setResolver(XMLClassDescriptorResolver cdr) {
+ public void setResolver(final XMLClassDescriptorResolver cdr) {
- if (cdr != null) _cdResolver = cdr;
+ if (cdr != null) {
+ getInternalContext().setXMLClassDescriptorResolver(cdr);
+// _cdResolver = cdr;
+ }
} //-- setResolver
@@ -962,7 +957,7 @@
name = name.substring(idx+1);
}
//-- remove capitalization
- name = _naming.toXMLName(name);
+ name = getInternalContext().getXMLNaming().toXMLName(name);
}
//-- obtain the class descriptor
@@ -1025,7 +1020,7 @@
String nsURI = descriptor.getNameSpaceURI();
XMLClassDescriptor tmpDesc = null;
try {
- tmpDesc = _cdResolver.resolveByXMLName(name, nsURI, null);
+ tmpDesc = getResolver().resolveByXMLName(name, nsURI, null);
}
catch(ResolverException rx) {
//-- exception not important as we're simply
@@ -1051,7 +1046,7 @@
//-- one
if (atRoot) {
if (_useXSITypeAtRoot) {
- XMLMappingLoader ml = (XMLMappingLoader) _cdResolver.getMappingLoader();
+ XMLMappingLoader ml = (XMLMappingLoader) getResolver().getMappingLoader();
if (ml != null) {
containsDesc = (ml.getDescriptor(_class.getName()) != null);
}
@@ -1179,7 +1174,7 @@
// with the XML name of this class
XMLClassDescriptor xmlElementNameClassDesc = null;
try {
- xmlElementNameClassDesc = _cdResolver.resolveByXMLName(xmlElementName, null, null);
+ xmlElementNameClassDesc = getResolver().resolveByXMLName(xmlElementName, null, null);
}
catch(ResolverException rx) {
//-- exception not important as we're simply
@@ -1194,7 +1189,7 @@
if ((xmlElementName != null) && (xmlElementNameClassDesc != null)) {
// More than one class can map to a given element name
try {
- Iterator classDescriptorIter = _cdResolver.resolveAllByXMLName(xmlElementName, null, null);
+ Iterator classDescriptorIter = getResolver().resolveAllByXMLName(xmlElementName, null, null);
for (; classDescriptorIter.hasNext();) {
xmlElementNameClassDesc = (XMLClassDescriptor) classDescriptorIter.next();
if (_class == xmlElementNameClassDesc.getJavaClass())
@@ -1226,7 +1221,7 @@
// Try to find a field descriptor by inheritance in the parent object
InheritanceMatch[] matches =
- searchInheritance(xmlElementName, null, tempContaining, _cdResolver);
+ searchInheritance(xmlElementName, null, tempContaining); // TODO: Joachim, _cdResolver);
if (matches.length == 1) {
@@ -2135,7 +2130,7 @@
if (_serializer != null) {
if (_format == null) {
- _format = _config.getOutputFormat();
+ _format = getInternalContext().getOutputFormat();
}
_format.setEncoding(encoding);
//-- reset output format, this needs to be done
@@ -2256,7 +2251,7 @@
try {
if (!isPrimitive(_class))
- classDesc = (XMLClassDescriptor) _cdResolver.resolve(_class);
+ classDesc = (XMLClassDescriptor) getResolver().resolve(_class);
}
catch(ResolverException rx) {
Throwable actual = rx.getCause();
@@ -2540,8 +2535,9 @@
//-- we must have a valid element before marshalling
Validator validator = new Validator();
ValidationContext context = new ValidationContext();
- context.setConfiguration(_config);
- context.setResolver(_cdResolver);
+ context.setInternalContext(getInternalContext());
+// context.setConfiguration(_config);
+// context.setResolver(_cdResolver);
validator.validate(object, context);
}
}
@@ -2553,7 +2549,7 @@
* @since 1.1.2
*/
public String getProperty(final String name) {
- return _config.getProperties().getProperty(name);
+ return getInternalContext().getStringProperty(name);
}
/**
@@ -2563,7 +2559,7 @@
* @since 1.1.2
*/
public void setProperty(final String name, final String value) {
- _config.getProperties().setProperty(name, value);
+ getInternalContext().setProperty(name, value);
}
/**
@@ -2668,6 +2664,13 @@
}
}
+ /**
+ * To set the content handler which is used as destination at marshalling.
+ * @param contentHandler the content handler to use as destination at marshalling
+ */
+ public void setContentHandler(final ContentHandler contentHandler) {
+ _handler = contentHandler;
+ }
} //-- Marshaller
Index: src/main/java/org/exolab/castor/xml/XMLNaming.java
===================================================================
--- src/main/java/org/exolab/castor/xml/XMLNaming.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/XMLNaming.java (working copy)
@@ -45,8 +45,7 @@
package org.exolab.castor.xml;
-import org.exolab.castor.util.Configuration;
-import org.exolab.castor.util.LocalConfiguration;
+import org.castor.xml.BackwardCompatibilityContext;
/**
* An abstract class to handing XML naming
@@ -84,12 +83,11 @@
/**
- * Returns the default instance of XMLNaming
+ * Returns the default instance of XMLNaming.
* @see org.exolab.castor.util.Configuration
**/
public static final XMLNaming getInstance() {
- Configuration config = LocalConfiguration.getInstance();
- return config.getXMLNaming();
+ return new BackwardCompatibilityContext().getXMLNaming();
} //-- getInstance
} //-- Naming
Index: src/main/java/org/exolab/castor/xml/util/resolvers/CastorXMLStrategy.java
===================================================================
--- src/main/java/org/exolab/castor/xml/util/resolvers/CastorXMLStrategy.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/util/resolvers/CastorXMLStrategy.java (working copy)
@@ -20,6 +20,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.castor.xml.InternalContext;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.xml.ResolverException;
import org.exolab.castor.xml.XMLClassDescriptor;
@@ -38,6 +39,7 @@
* @since 1.2
*/
public class CastorXMLStrategy implements ResolverStrategy {
+ /** Logger to be used. */
private static final Log LOG = LogFactory.getLog(CastorXMLStrategy.class);
/** The strategy configuration held as map of properties. */
@@ -47,12 +49,11 @@
* CastorXMLStrategy requires a configuration to be set. Within the constructor the
* commands building the strategy are instantiated, a command configuration is created
* and the descriptor cache.
- * @param configuration the strategy configuration to use.
*/
public CastorXMLStrategy() {
_properties = new HashMap();
- } //-- CastorXmlStrategy(Configuration)
-
+ } //-- CastorXmlStrategy()
+
/**
* {@inheritDoc}
*/
Index: src/main/java/org/exolab/castor/xml/util/resolvers/ByPackageMapping.java
===================================================================
--- src/main/java/org/exolab/castor/xml/util/resolvers/ByPackageMapping.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/util/resolvers/ByPackageMapping.java (working copy)
@@ -111,6 +111,7 @@
final Mapping mapping = this.loadMapping(packageName, classLoader);
if (mapping != null) {
MappingUnmarshaller unmarshaller = new MappingUnmarshaller();
+ // TODO: Joachim 2007-09-07 the InternalContext should be set into the unmarshaller!
MappingLoader mappingLoader = unmarshaller.getMappingLoader(mapping, BindingType.XML);
Iterator descriptors = mappingLoader.descriptorIterator();
while (descriptors.hasNext()) {
Index: src/main/java/org/exolab/castor/xml/util/resolvers/ByIntrospection.java
===================================================================
--- src/main/java/org/exolab/castor/xml/util/resolvers/ByIntrospection.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/util/resolvers/ByIntrospection.java (working copy)
@@ -36,14 +36,17 @@
* @since 1.2
*/
public class ByIntrospection extends AbstractResolverClassCommand {
- private static final Log LOG = LogFactory.getLog(ByIntrospection.class);
+ /**
+ * Logger to be used.
+ */
+ private static final Log LOG = LogFactory.getLog(ByIntrospection.class);
/**
* No specific stuff needed.
*/
- public ByIntrospection() {
+ public ByIntrospection() {
super();
- }
+ }
/**
* Creates an XMLClassDescriptor for the given type by using introspection.
@@ -59,7 +62,8 @@
protected Map internalResolve(final String className, final ClassLoader classLoader,
final Map properties) throws ResolverException {
- Boolean useIntrospector = (Boolean)properties.get(ResolverStrategy.PROPERTY_USE_INTROSPECTION);
+ Boolean useIntrospector =
+ (Boolean) properties.get(ResolverStrategy.PROPERTY_USE_INTROSPECTION);
HashMap results = new HashMap();
if (classLoader == null) {
LOG.debug("No class loader available.");
@@ -67,12 +71,19 @@
}
if ((useIntrospector != null) && (!useIntrospector.booleanValue())) {
- // I know the logic is a bit weired... either introspection is explicitly disabled or it is ok!
+ // I know the logic is a bit weired... either introspection is explicitly
+ // disabled or it is ok!
LOG.debug("Introspection is disabled!");
return results;
}
- Introspector introspector = new Introspector();
+ Introspector introspector =
+ (Introspector) properties.get(ResolverStrategy.PROPERTY_INTROSPECTOR);
+ if (introspector == null) {
+ String message = "No Introspector defined in properties!";
+ LOG.warn(message);
+ throw new IllegalStateException(message);
+ }
Class clazz = ResolveHelpers.loadClass(classLoader, className);
if (clazz != null) {
try {
@@ -84,7 +95,8 @@
results.put(clazz.getName(), descriptor);
}
} catch (MarshalException e) {
- String message = "Failed to generate class descriptor for: " + clazz + " with exception: " + e;
+ String message = "Failed to generate class descriptor for: "
+ + clazz + " with exception: " + e;
LOG.warn(message);
throw new ResolverException(message);
}
Index: src/main/java/org/exolab/castor/xml/util/ResolverStrategy.java
===================================================================
--- src/main/java/org/exolab/castor/xml/util/ResolverStrategy.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/util/ResolverStrategy.java (working copy)
@@ -17,6 +17,7 @@
import java.util.Map;
+import org.castor.xml.InternalContext;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.xml.ResolverException;
import org.exolab.castor.xml.XMLClassDescriptor;
@@ -31,24 +32,24 @@
* @since 1.2
*/
public interface ResolverStrategy {
- /** To set the class loader property for resolving */
- public final static String PROPERTY_CLASS_LOADER =
+ /** To set the class loader property for resolving. */
+ String PROPERTY_CLASS_LOADER =
"org.exolab.castor.xml.util.ResolverStrategy.ClassLoader";
- /** To set the use introspection property for resolving */
- public final static String PROPERTY_USE_INTROSPECTION =
+ /** To set the use introspection property for resolving. */
+ String PROPERTY_USE_INTROSPECTION =
"org.exolab.castor.xml.util.ResolverStrategy.useIntrospection";
- /** To set the introspector property for resolving */
- public final static String PROPERTY_INTROSPECTOR =
+ /** To set the introspector property for resolving. */
+ String PROPERTY_INTROSPECTOR =
"org.exolab.castor.xml.util.ResolverStrategy.Introspector";
- /** To set the LoadPackageMappings property for resolving */
- public final static String PROPERTY_LOAD_PACKAGE_MAPPINGS =
+ /** To set the LoadPackageMappings property for resolving. */
+ String PROPERTY_LOAD_PACKAGE_MAPPINGS =
"org.exolab.castor.xml.util.ResolverStrategy.LoadPackageMappings";
- /** To set the mapping loader property for resolving */
- public final static String PROPERTY_MAPPING_LOADER =
+ /** To set the mapping loader property for resolving. */
+ String PROPERTY_MAPPING_LOADER =
"org.exolab.castor.xml.util.ResolverStrategy.MappingLoader";
/**
@@ -57,24 +58,27 @@
* @param key name of the property
* @param value value the property is set to
*/
- public void setProperty(String key, Object value);
+ void setProperty(final String key, final Object value);
/**
* Implementes a strategy how a class is resolved into a list of class descriptors.
*
+ * @param resolverResults to put the resolver reszlts into
* @param className the class to resolve
* @return the ClassDescriptor for the class or null if the class couldn't be resolved
+ * @throws ResolverException in case that resolving fails fatally
*/
- public ClassDescriptor resolveClass(ResolverResults resolverResults, String className)
+ ClassDescriptor resolveClass(final ResolverResults resolverResults, final String className)
throws ResolverException;
/**
* Implementes a strategy how a package is resolved into a list of class descriptors.
*
+ * @param resolverResults to put the resolver reszlts into
* @param packageName the package to resolve
- * @return the ClassDescriptor for the class or null if the class couldn't be resolved
+ * @throws ResolverException in case that resolving fails fatally
*/
- public void resolvePackage(ResolverResults resolverResults, String packageName)
+ void resolvePackage(ResolverResults resolverResults, String packageName)
throws ResolverException;
/**
@@ -103,14 +107,14 @@
*
* @see #INTERNAL_CONTAINER_NAME
*/
- public void addDescriptor(String className, XMLClassDescriptor descriptor);
+ void addDescriptor(String className, XMLClassDescriptor descriptor);
/**
* To add not only a single descriptor but a map of descriptors at once.
*
- * @param descriptor a Map of className (String) and XMLClassDescriptor pairs
+ * @param descriptors a Map of className (String) and XMLClassDescriptor pairs
*/
- public void addAllDescriptors(Map descriptors);
+ void addAllDescriptors(Map descriptors);
/**
* Gets the descriptor that is mapped to the given class name.
@@ -119,6 +123,6 @@
* @return The descriptor mapped to the given name or null
* if no descriptor is stored in this cache.
*/
- public XMLClassDescriptor getDescriptor(String className);
+ XMLClassDescriptor getDescriptor(String className);
}
}
Index: src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorAdapter.java
===================================================================
--- src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorAdapter.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorAdapter.java (working copy)
@@ -44,11 +44,11 @@
*/
package org.exolab.castor.xml.util;
+import org.castor.xml.BackwardCompatibilityContext;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.FieldDescriptor;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.mapping.loader.ClassDescriptorImpl;
-import org.exolab.castor.util.LocalConfiguration;
import org.exolab.castor.xml.NodeType;
import org.exolab.castor.xml.XMLClassDescriptor;
import org.exolab.castor.xml.XMLFieldDescriptor;
@@ -96,7 +96,7 @@
}
if (primitiveNodeType == null) {
- primitiveNodeType = LocalConfiguration.getInstance().getPrimitiveNodeType();
+ primitiveNodeType = new BackwardCompatibilityContext().getPrimitiveNodeType();
}
if (primitiveNodeType == null) {
Index: src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorResolverImpl.java
===================================================================
--- src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorResolverImpl.java (revision 7250)
+++ src/main/java/org/exolab/castor/xml/util/XMLClassDescriptorResolverImpl.java (working copy)
@@ -58,15 +58,13 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
+import org.castor.xml.InternalContext;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.MappingLoader;
-import org.exolab.castor.util.Configuration;
-import org.exolab.castor.util.LocalConfiguration;
-import org.exolab.castor.util.Configuration.Property;
+import org.exolab.castor.xml.Introspector;
import org.exolab.castor.xml.ResolverException;
import org.exolab.castor.xml.XMLClassDescriptor;
import org.exolab.castor.xml.XMLClassDescriptorResolver;
-import org.exolab.castor.xml.util.resolvers.CastorXMLStrategy;
import org.exolab.castor.xml.util.resolvers.ResolveHelpers;
/**
@@ -76,54 +74,112 @@
* @version $Revision$ $Date: 2006-04-25 15:08:23 -0600 (Tue, 25 Apr 2006) $
*/
public class XMLClassDescriptorResolverImpl implements XMLClassDescriptorResolver {
+ /** The Logger instance to use. */
private static final Log LOG = LogFactory.getLog(XMLClassDescriptorResolverImpl.class);
/**
- * The strategy to use for all resolve actions.
+ * XMLContext provides the information required.
*/
- private ResolverStrategy _strategy;
+ private InternalContext _internalContext;
/**
- * The place where all rsolving strategies and their commands put the results into
+ * The place where all resolving strategies and their commands put the results into
* and can be read from.
*/
private DescriptorCacheImpl _descriptorCache;
/**
- * The mapping loader is read from the XMLClassDescriptorResolver and used in the
- * strategy - so we need to keep it.
+ * Creates a new ClassDescriptorResolverImpl.
+ * It is left empty to avoid cycles at construction. To guarantee
+ * backward compatibility the backwardInit method will do all
+ * required initialization if it hadn't happend before.
*/
- private MappingLoader _mappingLoader;
+ public XMLClassDescriptorResolverImpl() {
+ super();
+ _descriptorCache = new DescriptorCacheImpl();
+ } //-- ClassDescriptorResolverImpl
/**
- * The class loader which is used when no other class loader was specified in
- * the resolve call. If this loader is also not set the context loader of the
- * current thread is used.
+ * {@inheritDoc}
*/
- private ClassLoader _loader;
+ public void setInternalContext(final InternalContext internalContext) {
+ _internalContext = internalContext;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public MappingLoader getMappingLoader() {
+ return _internalContext.getMappingLoader(); // _mappingLoader;
+ } //-- getXMLMappingLoader
/**
- * Creates a new ClassDescriptorResolverImpl.
+ * {@inheritDoc}
*/
- public XMLClassDescriptorResolverImpl() {
- Configuration config = LocalConfiguration.getInstance();
- boolean loadPackageMappings = config.getBoolean(
- Property.LOAD_PACKAGE_MAPPING,
- Property.DEFAULT_LOAD_PACKAGE_MAPPING);
-
- _strategy = new CastorXMLStrategy();
- _strategy.setProperty(
- ResolverStrategy.PROPERTY_LOAD_PACKAGE_MAPPINGS,
- Boolean.valueOf(loadPackageMappings));
+ public void setClassLoader(final ClassLoader loader) {
+ _internalContext.setClassLoader(loader);
+// _loader = loader;
+ } //-- setClassLoader
- _descriptorCache = new DescriptorCacheImpl();
- _mappingLoader = null;
- _loader = null;
- } //-- ClassDescriptorResolverImpl
+ /**
+ * {@inheritDoc}
+ */
+ public void setUseIntrospection(final boolean enable) {
+ // used by XMLMappingLoader.createResolver()
+ _internalContext.setUseIntrospector(Boolean.valueOf(enable));
+ } //-- setIntrospection
/**
* {@inheritDoc}
*/
+ public void setLoadPackageMappings(final boolean loadPackageMappings) {
+ _internalContext.setLoadPackageMapping(Boolean.valueOf(loadPackageMappings));
+ } //-- setLoadPackageMappings
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setMappingLoader(final MappingLoader mappingLoader) {
+ _internalContext.setMappingLoader(mappingLoader);
+ if (mappingLoader != null) {
+ Iterator descriptors = mappingLoader.descriptorIterator();
+ while (descriptors.hasNext()) {
+ XMLClassDescriptor descriptor = (XMLClassDescriptor) descriptors.next();
+ _descriptorCache.addDescriptor(descriptor.getJavaClass().getName(), descriptor);
+ }
+ }
+ } //-- setMappingLoader
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setIntrospector(final Introspector introspector) {
+ _internalContext.setIntrospector(introspector);
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void setResolverStrategy(final ResolverStrategy resolverStrategy) {
+ _internalContext.setResolverStrategy(resolverStrategy);
+ }
+
+ /**
+ * XMLClassDescriptorResolver was originally build to collect all required
+ * information by itself... now with introduction of XMLContext and a more
+ * IoC like concepts that all information is injected into a class... things
+ * are different but this methods is there to guarantee backward
+ * compatibility.
+ * @return the {@link ResolverStrategy} to use
+ */
+ private ResolverStrategy getResolverStrategy() {
+ setAttributesIntoStrategy();
+ return _internalContext.getResolverStrategy();
+ }
+
+ /**
+ * {@inheritDoc}
+ */
public ClassDescriptor resolve(final Class type) throws ResolverException {
if (type == null) {
String message = "Type argument must not be null for resolve";
@@ -135,7 +191,7 @@
return _descriptorCache.getDescriptor(type.getName());
}
- ClassLoader l = _loader;
+ ClassLoader l = _internalContext.getClassLoader();
if (l == null) { l = type.getClassLoader(); }
if (l == null) { l = Thread.currentThread().getContextClassLoader(); }
@@ -156,7 +212,7 @@
return _descriptorCache.getDescriptor(className);
}
- ClassLoader l = _loader;
+ ClassLoader l = _internalContext.getClassLoader();
if (l == null) { l = Thread.currentThread().getContextClassLoader(); }
return this.resolve(className, l);
@@ -178,11 +234,11 @@
}
ClassLoader l = loader;
- if (l == null) { l = _loader; }
+ if (l == null) { l = _internalContext.getClassLoader(); }
if (l == null) { l = Thread.currentThread().getContextClassLoader(); }
- _strategy.setProperty(ResolverStrategy.PROPERTY_CLASS_LOADER, l);
- return (XMLClassDescriptor) _strategy.resolveClass(_descriptorCache, className);
+ getResolverStrategy().setProperty(ResolverStrategy.PROPERTY_CLASS_LOADER, l);
+ return (XMLClassDescriptor) getResolverStrategy().resolveClass(_descriptorCache, className);
} //-- resolve(String, ClassLoader)
/**
@@ -212,7 +268,7 @@
}
// we have more than one result - only an exact match can be the result
- for (Iterator i = possibleMatches.iterator(); i.hasNext();) {
+ for (Iterator i = possibleMatches.iterator(); i.hasNext(); ) {
XMLClassDescriptor descriptor = (XMLClassDescriptor) i.next();
if (ResolveHelpers.namespaceEquals(namespaceURI, descriptor.getNameSpaceURI())) {
@@ -243,57 +299,6 @@
/**
* {@inheritDoc}
*/
- public MappingLoader getMappingLoader() {
- return _mappingLoader;
- } //-- getXMLMappingLoader
-
- /**
- * {@inheritDoc}
- */
- public void setClassLoader(ClassLoader loader) {
- _loader = loader;
- } //-- setClassLoader
-
- /**
- * Enables or disables introspection. Introspection is enabled by default.
- *
- * @param enable a flag to indicate whether or not introspection is allowed.
- */
- public void setIntrospection(boolean enable) {
- // used by XMLMappingLoader.createResolver()
- _strategy.setProperty(ResolverStrategy.PROPERTY_USE_INTROSPECTION, new Boolean(enable));
- } //-- setIntrospection
-
- /**
- * Sets whether or not to look for and load package specific mapping files (".castor.xml").
- *
- * @param loadPackageMappings a boolean that enables or disables the loading of package
- * specific mapping files
- */
- public void setLoadPackageMappings(boolean loadPackageMappings) {
- _strategy.setProperty(
- ResolverStrategy.PROPERTY_LOAD_PACKAGE_MAPPINGS,
- Boolean.valueOf(loadPackageMappings));
- } //-- setLoadPackageMappings
-
- /**
- * {@inheritDoc}
- */
- public void setMappingLoader(MappingLoader mappingLoader) {
- _mappingLoader = mappingLoader;
- if (_mappingLoader != null) {
- Iterator descriptors = _mappingLoader.descriptorIterator();
- while (descriptors.hasNext()) {
- XMLClassDescriptor descriptor = (XMLClassDescriptor) descriptors.next();
- _descriptorCache.addDescriptor(descriptor.getClass().getName(), descriptor);
- }
- _strategy.setProperty(ResolverStrategy.PROPERTY_MAPPING_LOADER, _mappingLoader);
- }
- } //-- setMappingLoader
-
- /**
- * {@inheritDoc}
- */
public void addClass(final String className) throws ResolverException {
this.resolve(className);
}
@@ -329,7 +334,13 @@
* {@inheritDoc}
*/
public void addPackage(final String packageName) throws ResolverException {
- _strategy.resolvePackage(_descriptorCache, packageName);
+ if (packageName == null || packageName.length() == 0) {
+ String message = "Cannot resolve a null or zero-length package name.";
+ LOG.warn(message);
+ throw new IllegalArgumentException(message);
+ }
+
+ getResolverStrategy().resolvePackage(_descriptorCache, packageName);
}
/**
@@ -350,6 +361,23 @@
LOG.warn(message);
throw new UnsupportedOperationException();
}
+
+ /**
+ * To set all strategy properties to the values of the attributes of this instance.
+ * Only exception is the class loader property which is always set in the resolve method.
+ */
+ private void setAttributesIntoStrategy() {
+ ResolverStrategy strategy = _internalContext.getResolverStrategy();
+ strategy.setProperty(
+ ResolverStrategy.PROPERTY_LOAD_PACKAGE_MAPPINGS,
+ _internalContext.getLoadPackageMapping());
+ strategy.setProperty(
+ ResolverStrategy.PROPERTY_USE_INTROSPECTION, _internalContext.getUseIntrospector());
+ strategy.setProperty(
+ ResolverStrategy.PROPERTY_MAPPING_LOADER, _internalContext.getMappingLoader());
+ strategy.setProperty(
+ ResolverStrategy.PROPERTY_INTROSPECTOR, _internalContext.getIntrospector());
+ }
/**
* Internal cache for XMLClassDescriptors.
@@ -366,9 +394,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 +456,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);
@@ -447,6 +476,7 @@
if (!descriptorList.contains(descriptor)) {
descriptorList.add(descriptor);
}
+ _missingTypes.remove(className);
} //-- addDescriptor
/**
@@ -457,7 +487,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;
}
@@ -539,7 +571,7 @@
/**
* To add not only a single descriptor but a map of descriptors at once.
*
- * @param descriptor a Map of className (String) and XMLClassDescriptor pairs
+ * @param descriptors a Map of className (String) and XMLClassDescriptor pairs
*/
public void addAllDescriptors(final Map descriptors) {
if ((descriptors == null) || (descriptors.isEmpty())) {
@@ -547,9 +579,9 @@
return;
}
- for (Iterator iter = descriptors.keySet().iterator(); iter.hasNext();) {
+ for (Iterator iter = descriptors.keySet().iterator(); iter.hasNext(); ) {
String clsName = (String) iter.next();
- this.addDescriptor(clsName, (XMLClassDescriptor)descriptors.get(clsName));
+ this.addDescriptor(clsName, (XMLClassDescriptor) descriptors.get(clsName));
}
} //-- addAllDescriptors
} // -- DescriptorCacheImpl
Index: src/main/java/org/exolab/castor/types/AnyNode.java
===================================================================
--- src/main/java/org/exolab/castor/types/AnyNode.java (revision 7250)
+++ src/main/java/org/exolab/castor/types/AnyNode.java (working copy)
@@ -51,7 +51,7 @@
import java.io.StringWriter;
import java.util.Stack;
-import org.exolab.castor.util.LocalConfiguration;
+import org.castor.xml.InternalContext;
import org.exolab.castor.xml.Serializer;
import org.exolab.castor.xml.util.AnyNode2SAX;
@@ -530,17 +530,17 @@
* @return the String representation of this AnyNode.
*/
public String toString() {
- Serializer serializer = LocalConfiguration.getInstance().getSerializer();
+ Serializer serializer = new InternalContext().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/mapping/loader/AbstractMappingLoader.java
===================================================================
--- src/main/java/org/exolab/castor/mapping/loader/AbstractMappingLoader.java (revision 7250)
+++ src/main/java/org/exolab/castor/mapping/loader/AbstractMappingLoader.java (working copy)
@@ -61,6 +61,8 @@
import java.util.Map;
import java.util.Properties;
+
+import org.castor.xml.InternalContext;
import org.castor.util.Messages;
import org.exolab.castor.mapping.ClassDescriptor;
import org.exolab.castor.mapping.CollectionHandler;
@@ -130,8 +132,15 @@
/** Factory method name for type-safe enumerations. */
protected static final String VALUE_OF = "valueOf";
+ /**
+ * The {@link InternalContext} is the centerpiece providing runtime configuration
+ * and state information.
+ */
+ private InternalContext _internalContext;
+
/** Map of field handlers associated by their name. */
private final Map _fieldHandlers = new HashMap();
+
//--------------------------------------------------------------------------
/**
@@ -1202,4 +1211,12 @@
public TypeInfo typeInfo = null;
}
+ public void setInternalContext(final InternalContext internalContext) {
+ _internalContext = internalContext;
+ }
+
+ public InternalContext getInternalContext() {
+ return _internalContext;
+ }
+
}
Index: src/main/java/org/exolab/castor/mapping/loader/AbstractMappingLoader2.java
===================================================================
--- src/main/java/org/exolab/castor/mapping/loader/AbstractMappingLoader2.java (revision 7250)
+++ src/main/java/org/exolab/castor/mapping/loader/AbstractMappingLoader2.java (working copy)
@@ -97,6 +97,13 @@
if (!isAllowRedefinition()) {
throw new MappingException("mapping.duplicateDescriptors", classname);
}
+ for (Iterator iterator = _descriptors.iterator(); iterator.hasNext(); ) {
+ ClassDescriptor d = (ClassDescriptor) iterator.next();
+ if (classname.equals(d.getJavaClass().getName())) {
+ _descriptors.remove(d);
+ }
+ }
+ _descriptors.add(descriptor);
} else {
_descriptors.add(descriptor);
}
Index: src/main/java/org/exolab/castor/mapping/loader/CollectionHandlers.java
===================================================================
--- src/main/java/org/exolab/castor/mapping/loader/CollectionHandlers.java (revision 7250)
+++ src/main/java/org/exolab/castor/mapping/loader/CollectionHandlers.java (working copy)
@@ -53,6 +53,9 @@
import java.util.StringTokenizer;
import java.io.Serializable;
import java.lang.reflect.Method;
+
+import org.castor.core.util.Configuration;
+import org.castor.xml.XMLConfiguration;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.mapping.CollectionHandler;
import org.exolab.castor.util.LocalConfiguration;
@@ -249,8 +252,11 @@
Method method;
allInfo = new Vector();
- LocalConfiguration config = LocalConfiguration.getInstance();
- tokenizer = new StringTokenizer( config.getProperty( "org.exolab.castor.mapping.collections", "" ), ", " );
+ Configuration configuration = XMLConfiguration.newInstance();
+ tokenizer = new StringTokenizer(configuration.getString(XMLConfiguration.COLLECTION_HANDLERS_FOR_JAVA_11_OR_12, ""), ", ");
+// Joachim 2007-09-01 old local configuration is dead!
+// LocalConfiguration config = LocalConfiguration.getInstance();
+// tokenizer = new StringTokenizer( config.getProperty( "org.exolab.castor.mapping.collections", "" ), ", " );
while ( tokenizer.hasMoreTokens() ) {
try {
if ( CollectionHandlers.class.getClassLoader() != null )
Index: src/main/java/org/exolab/castor/util/Configuration.java
===================================================================
--- src/main/java/org/exolab/castor/util/Configuration.java (revision 7250)
+++ src/main/java/org/exolab/castor/util/Configuration.java (working copy)
@@ -107,231 +107,231 @@
* Names of properties used in the configuration file.
*/
public static class Property {
-
- /**
- * Property specifying the type of node to use for
- * primitive values, either "element" or "attribute"
- *
- * org.exolab.castor.xml.introspector.primitive.nodetype
- *
- */
- public static final String PrimitiveNodeType
- = "org.exolab.castor.xml.introspector.primitive.nodetype";
-
-
- /**
- * Property specifying the class name of the XML parser to use.
- *
- * org.exolab.castor.parser
- *
- */
- public static final String Parser = "org.exolab.castor.parser";
-
- /**
- * Property specifying whether to perform document validation by default.
- *
- * org.exolab.castor.SAXParser.validation
- *
- */
- public static final String ParserValidation = "org.exolab.castor.parser.validation";
-
- /**
- * Property specifying whether to support Namespaces by default.
- *
- * org.exolab.castor.SAXParser.namespaces
- *
- */
- public static final String Namespaces = "org.exolab.castor.parser.namespaces";
+//
+// /**
+// * Property specifying the type of node to use for
+// * primitive values, either "element" or "attribute"
+// *
+// * org.exolab.castor.xml.introspector.primitive.nodetype
+// *
+// */
+// public static final String PrimitiveNodeType
+// = "org.exolab.castor.xml.introspector.primitive.nodetype";
+//
+//
+// /**
+// * Property specifying the class name of the XML parser to use.
+// *
+// * org.exolab.castor.parser
+// *
+// */
+// public static final String Parser = "org.exolab.castor.parser";
+//
+// /**
+// * Property specifying whether to perform document validation by default.
+// *
+// * org.exolab.castor.SAXParser.validation
+// *
+// */
+// public static final String ParserValidation = "org.exolab.castor.parser.validation";
+//
+// /**
+// * Property specifying whether to support Namespaces by default.
+// *
+// * org.exolab.castor.SAXParser.namespaces
+// *
+// */
+// public static final String Namespaces = "org.exolab.castor.parser.namespaces";
+//
+//
+// /**
+// * Property specifying Namespace to Package Mappings
+// *
+// * org.exolab.castor.xml.nspackages
+// *
+// */
+// public static final String NamespacePackages = "org.exolab.castor.xml.nspackages";
+//
+//
+// /**
+// * Property specifying the implementation of the naming conventions
+// * to use. Values of this property must be either "mixed", "lower", or
+// * the name of a class which extends org.exolab.castor.xml.XMLNaming.
+// *
+// * org.exolab.castor.xml.naming
+// *
+// *
+// */
+// public static final String Naming = "org.exolab.castor.xml.naming";
+//
+// /**
+// * Property specifying the implementation of the Java naming conventions
+// * to use. Values of this property must be either null or
+// * the name of a class which extends org.castor.xml.JavaNaming.
+// *
+// * org.castor.xml.java_naming
+// *
+// *
+// */
+// public static final String JavaNaming = "org.castor.xml.java_naming";
+//
+// /**
+// * Property specifying whether to use validation in the Marshalling Framework
+// *
+// * org.exolab.castor.marshalling.validation
+// *
+// */
+// public static final String MarshallingValidation = "org.exolab.castor.marshalling.validation";
+//
+// /**
+// * Property specifying whether XML documents should be indented by default.
+// *
+// * org.exolab.castor.indent
+// *
+// */
+// public static final String Indent = "org.exolab.castor.indent";
+//
+// /**
+// * Property specifying additional features for the parser.
+// * This value contains a comma separated list of features that
+// * might or might not be supported by the specified parser.
+// *
+// * org.exolab.castor.sax.features
+// *
+// */
+// public static final String ParserFeatures = "org.exolab.castor.sax.features";
+//
+// /**
+// * Property specifying features to be disbaled on the underlying SAX parser.
+// * This value contains a comma separated list of features to be disabled.
+// *
+// * org.exolab.castor.sax.features-to-disable
+// *
+// */
+// public static final String ParserFeaturesToDisable = "org.exolab.castor.sax.features-to-disable";
+//
+// public static final String ParserFeatureSeparator = ",";
+//
+// /**
+// * Property specifying the regular expression validator
+// * to use. This specified class must implement
+// * org.exolab.castor.xml.validators.RegExpValidator
+// *
+// * org.exolab.castor.regexp
+// *
+// */
+// public static final String RegExp = "org.exolab.castor.regexp";
+//
+// /**
+// * Property specifying whether to run in debug mode.
+// *
+// * org.exolab.castor.debug
+// *
+// */
+// public static final String Debug = "org.exolab.castor.debug";
+//
+// /**
+// * Property specifying whether to apply strictness to elements when
+// * unmarshalling. Default is true which means that elements appearing in the
+// * XML Documnt which cannot be mapped to a class cause a SAXException to be thrown.
+// * If set to false, these 'unknown' elements are ignored
+// *
+// * org.exolab.castor.strictelements
+// *
+// */
+// public static final String StrictElements = "org.exolab.castor.xml.strictelements";
+//
+//
+// /**
+// * Property specifying whether or not to save the "keys" of a Hashtable or
+// * Map during marshalling. By default this is true.
+// *
+// * org.exolab.castor.xml.saveMapKeys
+// *
+// * @since 0.9.5.3
+// */
+// public static final String SaveMapKeys = "org.exolab.castor.xml.saveMapKeys";
+//
+// /**
+// * Property specifying what factory to use for dealing with XML serializers
+// *
+// * org.exolab.castor.xml.serializer.factory
+// *
+// * @since 1.0
+// */
+// public static final String LOAD_PACKAGE_MAPPING = "org.exolab.castor.xml.loadPackageMappings";
+//
+// public static final boolean DEFAULT_LOAD_PACKAGE_MAPPING = true;
+//
+// /**
+// * Property specifying what factoyr to use for dealing with XML serializers
+// *
+// * org.exolab.castor.xml.serializer.factory
+// *
+// * @since 1.0
+// */
+// public static final String SERIALIZER_FACTORY = "org.exolab.castor.xml.serializer.factory";
+//
+// /**
+// * The name of the configuration file.
+// *
+// * castor.properties
+// *
+// */
+// public static final String FileName = "castor.properties";
+//
+// static final String ResourceName = "/org/exolab/castor/castor.properties";
+//
+// public static final String DEFAULT_SERIALIZER_FACTORY = "org.exolab.castor.xml.XercesXMLSerializerFactory";
+//
+// /**
+// * Property specifying whether sequence order validation should be lenient
+// *
+// * org.exolab.castor.xml.lenient.sequence.order=false
+// *
+// */
+// public static final String LenientSequenceOrder = "org.exolab.castor.xml.lenient.sequence.order";
+//
+// /**
+// * Property specifying whether id/href validation should be lenient;
+// * defaults to false
+// *
+// * org.exolab.castor.xml.lenient.id.validation=false
+// *
+// */
+// public static final String LenientIdValidation = "org.exolab.castor.xml.lenient.id.validation";
+//
+// /**
+// * Property specifying whether or not to search for an proxy interface at marshalling.
+// * If property is not empty the objects to be marshalled will be searched if they
+// * implement one of the given interface names. If the interface is implemented the
+// * superclass will be marshalled instead of the class itself.
+// *
+// * org.exolab.castor.xml.proxyInterfaces
+// *
+// * @since 1.2.2
+// */
+// public static final String ProxyInterfaces = "org.exolab.castor.xml.proxyInterfaces";
-
- /**
- * Property specifying Namespace to Package Mappings
- *
- * org.exolab.castor.xml.nspackages
- *
- */
- public static final String NamespacePackages = "org.exolab.castor.xml.nspackages";
-
+// /**
+// * Property specifying whether element strictness for introspected classes/elements
+// * should be lenient (aka allowed); defaults to true
+// *
+// * org.exolab.castor.xml.lenient.introspected.element.strictness=true
+// *
+// * @since 1.1.3
+// */
+// public static final String LENIENT_INTROSPECTED_ELEMENT_STRICTNESS = "org.exolab.castor.xml.lenient.introspected.element.strictness";
- /**
- * Property specifying the implementation of the naming conventions
- * to use. Values of this property must be either "mixed", "lower", or
- * the name of a class which extends org.exolab.castor.xml.XMLNaming.
- *
- * org.exolab.castor.xml.naming
- *
- *
- */
- public static final String Naming = "org.exolab.castor.xml.naming";
-
- /**
- * Property specifying the implementation of the Java naming conventions
- * to use. Values of this property must be either null or
- * the name of a class which extends org.castor.xml.JavaNaming.
- *
- * org.castor.xml.java_naming
- *
- *
- */
- public static final String JavaNaming = "org.castor.xml.java_naming";
-
- /**
- * Property specifying whether to use validation in the Marshalling Framework
- *
- * org.exolab.castor.marshalling.validation
- *
- */
- public static final String MarshallingValidation = "org.exolab.castor.marshalling.validation";
-
- /**
- * Property specifying whether XML documents should be indented by default.
- *
- * org.exolab.castor.indent
- *
- */
- public static final String Indent = "org.exolab.castor.indent";
-
- /**
- * Property specifying additional features for the parser.
- * This value contains a comma separated list of features that
- * might or might not be supported by the specified parser.
- *
- * org.exolab.castor.sax.features
- *
- */
- public static final String ParserFeatures = "org.exolab.castor.sax.features";
-
- /**
- * Property specifying features to be disbaled on the underlying SAX parser.
- * This value contains a comma separated list of features to be disabled.
- *
- * org.exolab.castor.sax.features-to-disable
- *
- */
- public static final String ParserFeaturesToDisable = "org.exolab.castor.sax.features-to-disable";
-
- public static final String ParserFeatureSeparator = ",";
-
- /**
- * Property specifying the regular expression validator
- * to use. This specified class must implement
- * org.exolab.castor.xml.validators.RegExpValidator
- *
- * org.exolab.castor.regexp
- *
- */
- public static final String RegExp = "org.exolab.castor.regexp";
-
- /**
- * Property specifying whether to run in debug mode.
- *
- * org.exolab.castor.debug
- *
- */
- public static final String Debug = "org.exolab.castor.debug";
-
- /**
- * Property specifying whether to apply strictness to elements when
- * unmarshalling. Default is true which means that elements appearing in the
- * XML Documnt which cannot be mapped to a class cause a SAXException to be thrown.
- * If set to false, these 'unknown' elements are ignored
- *
- * org.exolab.castor.strictelements
- *
- */
- public static final String StrictElements = "org.exolab.castor.xml.strictelements";
-
-
- /**
- * Property specifying whether or not to save the "keys" of a Hashtable or
- * Map during marshalling. By default this is true.
- *
- * org.exolab.castor.xml.saveMapKeys
- *
- * @since 0.9.5.3
- */
- public static final String SaveMapKeys = "org.exolab.castor.xml.saveMapKeys";
-
- /**
- * Property specifying what factory to use for dealing with XML serializers
- *
- * org.exolab.castor.xml.serializer.factory
- *
- * @since 1.0
- */
- public static final String LOAD_PACKAGE_MAPPING = "org.exolab.castor.xml.loadPackageMappings";
- public static final boolean DEFAULT_LOAD_PACKAGE_MAPPING = true;
-
- /**
- * Property specifying what factoyr to use for dealing with XML serializers
- *
- * org.exolab.castor.xml.serializer.factory
- *
- * @since 1.0
- */
- public static final String SERIALIZER_FACTORY = "org.exolab.castor.xml.serializer.factory";
-
- /**
- * The name of the configuration file.
- *
- * castor.properties
- *
- */
- public static final String FileName = "castor.properties";
-
- static final String ResourceName = "/org/exolab/castor/castor.properties";
-
- static final String DEFAULT_SERIALIZER_FACTORY = "org.exolab.castor.xml.XercesXMLSerializerFactory";
-
- /**
- * Property specifying whether sequence order validation should be lenient
- *
- * org.exolab.castor.xml.lenient.sequence.order=false
- *
- */
- public static final String LenientSequenceOrder = "org.exolab.castor.xml.lenient.sequence.order";
-
- /**
- * Property specifying whether id/href validation should be lenient;
- * defaults to false
- *
- * org.exolab.castor.xml.lenient.id.validation=false
- *
- */
- public static final String LenientIdValidation = "org.exolab.castor.xml.lenient.id.validation";
-
- /**
- * Property specifying whether or not to search for an proxy interface at marshalling.
- * If property is not empty the objects to be marshalled will be searched if they
- * implement one of the given interface names. If the interface is implemented the
- * superclass will be marshalled instead of the class itself.
- *
- * org.exolab.castor.xml.proxyInterfaces
- *
- * @since 1.2.2
- */
- public static final String ProxyInterfaces = "org.exolab.castor.xml.proxyInterfaces";
-
- /**
- * Property specifying whether element strictness for introspected classes/elements
- * should be lenient (aka allowed); defaults to true
- *
- * org.exolab.castor.xml.lenient.introspected.element.strictness=true
- *
- * @since 1.1.3
- */
- public static final String LENIENT_INTROSPECTED_ELEMENT_STRICTNESS = "org.exolab.castor.xml.lenient.introspected.element.strictness";
-
-
} //-- class: Property
- static class Features
- {
- public static final String Validation = "http://xml.org/sax/features/validation";
- public static final String Namespaces = "http://xml.org/sax/features/namespaces";
- } //-- class: Features
+// static class Features
+// {
+// public static final String Validation = "http://xml.org/sax/features/validation";
+// public static final String Namespaces = "http://xml.org/sax/features/namespaces";
+// } //-- class: Features
// Some static string definitions
@@ -352,94 +352,94 @@
/**
* Protected default constructor
*/
- Configuration() {
+ protected Configuration() {
super();
} //-- Configuration
- /**
- * Returns true if the configuration specifies debugging.
- * Design note: This method should be overloaded by any
- * sub-classes.
- *
- * @return true if the configuration specifies debugging.
- * @see #getDefaultDebug()
- */
- public boolean debug() {
- return getDefaultDebug();
- } //-- debug
+// /**
+// * Returns true if the configuration specifies debugging.
+// * Design note: This method should be overloaded by any
+// * sub-classes.
+// *
+// * @return true if the configuration specifies debugging.
+// * @see #getDefaultDebug()
+// */
+// public boolean debug() {
+// return getDefaultDebug();
+// } //-- debug
- /**
- * Returns true if the default configuration specified debugging.
- *
- * @return true if the configuration specifies debugging.
- */
- public static boolean getDefaultDebug()
- {
- getDefault();
- return _defaultValues.debug;
- } //-- getDefaultDebug
+// /**
+// * Returns true if the default configuration specified debugging.
+// *
+// * @return true if the configuration specifies debugging.
+// */
+// public static boolean getDefaultDebug()
+// {
+// getDefault();
+// return _defaultValues.debug;
+// } //-- getDefaultDebug
- /**
- * Access to the property specifying whether to apply strictness to elements when
- * unmarshalling. Default is true which means that elements appearing in the
- * XML Documnt which cannot be mapped to a class cause a SAXException to be thrown.
- * If set to false, these 'unknown' elements are ignored.
- *
- * Design note: This method should be overloaded by any
- * sub-classes.
- *
- * @return true if element processing should be "strict".
- * @see #getDefaultStrictElements()
- */
- public boolean strictElements() {
- return getDefaultStrictElements();
- } //-- strictElements
+// /**
+// * Access to the property specifying whether to apply strictness to elements when
+// * unmarshalling. Default is true which means that elements appearing in the
+// * XML Documnt which cannot be mapped to a class cause a SAXException to be thrown.
+// * If set to false, these 'unknown' elements are ignored.
+// *
+// * Design note: This method should be overloaded by any
+// * sub-classes.
+// *
+// * @return true if element processing should be "strict".
+// * @see #getDefaultStrictElements()
+// */
+// public boolean strictElements() {
+// return getDefaultStrictElements();
+// } //-- strictElements
- /**
- * Access to the property specifying whether to apply strictness to elements when
- * unmarshalling. Default is true which means that elements appearing in the
- * XML Documnt which cannot be mapped to a class cause a SAXException to be thrown.
- * If set to false, these 'unknown' elements are ignored
- *
- * @return true if element processing should be "strict".
- * @see #strictElements()
- */
- public static boolean getDefaultStrictElements() {
- getDefault();
- return _defaultValues.strictElements;
- } //-- getDefaultStrictElements
+// /**
+// * Access to the property specifying whether to apply strictness to elements when
+// * unmarshalling. Default is true which means that elements appearing in the
+// * XML Documnt which cannot be mapped to a class cause a SAXException to be thrown.
+// * If set to false, these 'unknown' elements are ignored
+// *
+// * @return true if element processing should be "strict".
+// * @see #strictElements()
+// */
+// public static boolean getDefaultStrictElements() {
+// getDefault();
+// return _defaultValues.strictElements;
+// } //-- getDefaultStrictElements
- /**
- * Returns true if the current configuration (user-supplied or default)
- * specifies validation in the marshalling framework.
- *
- * Design note: This method should be overloaded by any
- * sub-classes.
- *
- * @return true if by default validation should be performed during the
- * marshalling and unmarshalling process, otherwise false.
- * @see #getDefaultMarshallingValidation()
- */
- public boolean marshallingValidation() {
- return getDefaultMarshallingValidation();
- } //-- marshallingValidation
+// /**
+// * Returns true if the current configuration (user-supplied or default)
+// * specifies validation in the marshalling framework.
+// *
+// * Design note: This method should be overloaded by any
+// * sub-classes.
+// *
+// * @return true if by default validation should be performed during the
+// * marshalling and unmarshalling process, otherwise false.
+// * @see #getDefaultMarshallingValidation()
+// */
+// public boolean marshallingValidation() {
+// return getDefaultMarshallingValidation();
+// } //-- marshallingValidation
- /**
- * Returns true if the default configuration specifies validation in
- * the marshalling framework.
- *
- * @return true if by default validation should be performed during the
- * marshalling and unmarshalling process, otherwise false.
- *
- * @see #marshallingValidation()
- */
- public static boolean getDefaultMarshallingValidation()
- {
- getDefault();
- return _defaultValues.marshallingValidation;
- } //-- getDefaultMarshallingValidation
+// /**
+// * Returns true if the default configuration specifies validation in
+// * the marshalling framework.
+// *
+// * @return true if by default validation should be performed during the
+// * marshalling and unmarshalling process, otherwise false.
+// *
+// * @see #marshallingValidation()
+// */
+// public static boolean getDefaultMarshallingValidation()
+// {
+// getDefault();
+// return _defaultValues.marshallingValidation;
+// } //-- getDefaultMarshallingValidation
/**
@@ -521,625 +521,626 @@
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.
- *
- * @return True of sequence order validation is lenient.
- * @see #getLenientSequenceOrder()
- */
- public static boolean getDefaultLenientSequenceOrder()
- {
- return Boolean.valueOf(_defaultProps.getProperty(Property.LenientSequenceOrder, "false")).booleanValue();
- }
+// /**
+// * Indicates whether (by default) sequence order validation is lenient.
+// *
+// * @return True of sequence order validation is lenient.
+// * @see #getLenientSequenceOrder()
+// */
+// public static boolean getDefaultLenientSequenceOrder()
+// {
+// return Boolean.valueOf(_defaultProps.getProperty(Property.LenientSequenceOrder, "false")).booleanValue();
+// }
- /**
- * Indicates whether sequence order validation is lenient.
- *
- * Design note: This method should be overloaded by any
- * sub-classes.
- *
- * @return True of sequence order validation is lenient.
- * @see #getDefaultLenientSequenceOrder()
- */
- public boolean getLenientSequenceOrder() {
- return getDefaultLenientSequenceOrder();
- } //-- getParser
+// /**
+// * Indicates whether sequence order validation is lenient.
+// *
+// * Design note: This method should be overloaded by any
+// * sub-classes.
+// *
+// * @return True of sequence order validation is lenient.
+// * @see #getDefaultLenientSequenceOrder()
+// */
+// public boolean getLenientSequenceOrder() {
+// return getDefaultLenientSequenceOrder();
+// } //-- getParser
- /**
- * Indicates whether (by default) id/href validation is lenient.
- *
- * @return True if id/href validation is lenient.
- * @see #getLenientIdValidation()
- */
- public static boolean getDefaultLenientIdValidation()
- {
- return Boolean.valueOf(_defaultProps.getProperty(Property.LenientIdValidation, "false")).booleanValue();
- }
+// /**
+// * Indicates whether (by default) id/href validation is lenient.
+// *
+// * @return True if id/href validation is lenient.
+// * @see #getLenientIdValidation()
+// */
+// public static boolean getDefaultLenientIdValidation()
+// {
+// return Boolean.valueOf(_defaultProps.getProperty(Property.LenientIdValidation, "false")).booleanValue();
+// }
- /**
- * Indicates whether id/href validation is lenient.
- *
- * Design note: This method should be overloaded by any
- * sub-classes.
- *
- * @return True if id/href validation is lenient.
- * @see #getDefaultLenientIdValidation()
- */
- public boolean getLenientIdValidation() {
- return getDefaultLenientIdValidation();
- }
+// /**
+// * Indicates whether id/href validation is lenient.
+// *
+// * Design note: This method should be overloaded by any
+// * sub-classes.
+// *
+// * @return True if id/href validation is lenient.
+// * @see #getDefaultLenientIdValidation()
+// */
+// 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);
-
- 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" ) )
- _defaultValues.marshallingValidation = false;
-
- prop = _defaultProps.getProperty( Property.StrictElements, "" );
- if ( prop.equalsIgnoreCase( "false" ) || prop.equalsIgnoreCase( "off" ) )
- _defaultValues.strictElements = false;
- else
- _defaultValues.strictElements = true;
-
- prop = null;
+ protected static void loadDefaults() {
+// _defaultProps = loadProperties(Property.ResourceName, Property.FileName);
+//
+// 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")) {
+// _defaultValues.marshallingValidation = false;
+// }
+//
+// prop = _defaultProps.getProperty(Property.StrictElements, "");
+// if (prop.equalsIgnoreCase("false") || prop.equalsIgnoreCase("off")) {
+// _defaultValues.strictElements = false;
+// } 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)
{
@@ -1227,12 +1228,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.
@@ -1271,26 +1271,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 7250)
+++ 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.
@@ -124,7 +124,7 @@
/**
* Creates a new instance of LocalConfiguration
*/
- public LocalConfiguration() {
+ private LocalConfiguration() {
super();
load();
//-- Disable for now, not needed yet until we work on
@@ -141,7 +141,7 @@
*
* @return the LocalConfiguration
*/
- public static synchronized LocalConfiguration getInstance() {
+ private static synchronized LocalConfiguration getInstance() {
LocalConfiguration config = null;
URL url = null;
@@ -166,42 +166,42 @@
} //-- getInstance
- /**
- * Returns true if the current configuration has enabled debugging.
- *
- * @return true if the current configuration has enabled debugging,
- * otherwise false.
- */
- public boolean debug()
- {
- getProperties();
- return _values.debug;
-
- } //-- debug
+// /**
+// * Returns true if the current configuration has enabled debugging.
+// *
+// * @return true if the current configuration has enabled debugging,
+// * otherwise false.
+// */
+// public boolean debug()
+// {
+// getProperties();
+// return _values.debug;
+//
+// } //-- debug
- /**
- * Access to the property specifying whether to apply strictness to elements when
- * unmarshalling. Default is true which means that elements appearing in the
- * XML Documnt which cannot be mapped to a class cause a SAXException to be thrown.
- * If set to false, these 'unknown' elements are ignored
- *
- * @return true if element processing should be "strict".
- */
- public boolean strictElements() {
- getProperties();
- return _values.strictElements;
- } //-- strictElements
+// /**
+// * Access to the property specifying whether to apply strictness to elements when
+// * unmarshalling. Default is true which means that elements appearing in the
+// * XML Documnt which cannot be mapped to a class cause a SAXException to be thrown.
+// * If set to false, these 'unknown' elements are ignored
+// *
+// * @return true if element processing should be "strict".
+// */
+// public boolean strictElements() {
+// getProperties();
+// return _values.strictElements;
+// } //-- strictElements
- /**
- * Returns true if the default configuration specified validation in
- * the marshalling framework.
- */
- public boolean marshallingValidation()
- {
- getProperties();
- return _values.marshallingValidation;
-
- } //-- marshallingValidation
+// /**
+// * Returns true if the default configuration specified validation in
+// * the marshalling framework.
+// */
+// public boolean marshallingValidation()
+// {
+// getProperties();
+// return _values.marshallingValidation;
+//
+// } //-- marshallingValidation
/**
* Returns the current properties from the configuration file(s).
@@ -216,401 +216,401 @@
}
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);
- }
+// /**
+// * Indicates whether validation for sequence order should be lenient.
+// *
+// * @return True if sequence order validation should be lenient.
+// */
+// public boolean getLenientSequenceOrder()
+// {
+// return Boolean.valueOf(getProperties().getProperty(Property.LenientSequenceOrder, "false")).booleanValue();
+// }
+//
+// /**
+// * Indicates whether id/href validation should be lenient.
+// *
+// * @return True if id/href validation should be lenient.
+// */
+// public boolean getLenientIdValidation()
+// {
+// return Boolean.valueOf(getProperties().getProperty(Property.LenientIdValidation, "false")).booleanValue();
+// }
/**
- * 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.
- */
- public boolean getLenientSequenceOrder()
- {
- return Boolean.valueOf(getProperties().getProperty(Property.LenientSequenceOrder, "false")).booleanValue();
- }
-
- /**
- * Indicates whether id/href validation should be lenient.
- *
- * @return True if id/href validation should be lenient.
- */
- public boolean getLenientIdValidation()
- {
- return Boolean.valueOf(getProperties().getProperty(Property.LenientIdValidation, "false")).booleanValue();
- }
-
- /**
* Calls {@link #getDefault()} to load the configuration the
* first time and then looks for a local configuration to
* merge in with the defaults. Will not complain about inability
@@ -620,33 +620,33 @@
*/
protected void load()
{
- //-- load default properties
- _props = new Properties(getDefault());
-
- try {
- loadProperties( Property.FileName );
- }
- catch(FileNotFoundException fnfe) {
- //-- Ignore, simply no user supplied castor.properties file.
- //-- If no default castor.properties is found an exception
- //-- will occur in the above call to super.load.
- }
-
- String prop;
- prop = _props.getProperty( Property.Debug, "" );
- if ( prop.equalsIgnoreCase( "true" ) || prop.equalsIgnoreCase( "on" ) )
- _values.debug = true;
- prop = _props.getProperty( Property.MarshallingValidation, "" );
- if ( prop.equalsIgnoreCase( "false" ) || prop.equalsIgnoreCase( "off" ) )
- _values.marshallingValidation = false;
-
- prop = _props.getProperty( Property.StrictElements, "" );
- if ( prop.equalsIgnoreCase( "false" ) || prop.equalsIgnoreCase( "off" ) )
- _values.strictElements = false;
- else
- _values.strictElements = true;
-
- prop = null;
+// //-- load default properties
+// _props = new Properties(getDefault());
+//
+// try {
+// loadProperties( Property.FileName );
+// }
+// catch(FileNotFoundException fnfe) {
+// //-- Ignore, simply no user supplied castor.properties file.
+// //-- If no default castor.properties is found an exception
+// //-- will occur in the above call to super.load.
+// }
+//
+// String prop;
+// prop = _props.getProperty( Property.Debug, "" );
+// if ( prop.equalsIgnoreCase( "true" ) || prop.equalsIgnoreCase( "on" ) )
+// _values.debug = true;
+// prop = _props.getProperty( Property.MarshallingValidation, "" );
+// if ( prop.equalsIgnoreCase( "false" ) || prop.equalsIgnoreCase( "off" ) )
+// _values.marshallingValidation = false;
+//
+// prop = _props.getProperty( Property.StrictElements, "" );
+// if ( prop.equalsIgnoreCase( "false" ) || prop.equalsIgnoreCase( "off" ) )
+// _values.strictElements = false;
+// else
+// _values.strictElements = true;
+//
+// prop = null;
}
/**
@@ -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/main/java/org/exolab/castor/util/ChangeLog2XML.java
===================================================================
--- src/main/java/org/exolab/castor/util/ChangeLog2XML.java (revision 7250)
+++ src/main/java/org/exolab/castor/util/ChangeLog2XML.java (working copy)
@@ -13,7 +13,10 @@
*/
package org.exolab.castor.util;
+import org.castor.xml.XMLConfiguration;
+import org.castor.xml.InternalContext;
import org.exolab.castor.xml.Marshaller;
+import org.exolab.castor.xml.XMLContext;
import org.exolab.castor.util.Configuration;
import org.exolab.castor.util.LocalConfiguration;
@@ -52,8 +55,13 @@
private static final String VERSION_SEPARATOR = "---";
private static final String VERSION_TOKEN = "Version";
-
/**
+ * The {@link InternalContext} holding global state and configuration
+ * information.
+ */
+ private InternalContext _internalContext;
+
+ /**
* Creates a new instance of ChangeLog2XML
*
*/
@@ -62,6 +70,14 @@
}
/**
+ * To set the {@link InternalContext} into the ChangeLog2XML instance.
+ * @param internalContext the context to set
+ */
+ public void setInternalContext(final InternalContext internalContext) {
+ _internalContext = internalContext;
+ }
+
+ /**
* The method which does the parsing of the CHANGELOG file
*
* @param file
@@ -200,18 +216,20 @@
// 2. mapping file for customization
// 3. output file name
+ XMLContext xmlContext = new XMLContext();
+ ChangeLog2XML parser = xmlContext.createChangeLog2XML();
- ChangeLog2XML parser = new ChangeLog2XML();
-
try {
File file = new File(DEFAULT_FILE);
Changelog changelog = parser.parse(file);
file = new File(DEFAULT_OUTPUT);
FileWriter writer = new FileWriter(file);
- LocalConfiguration config = LocalConfiguration.getInstance();
- config.getProperties().setProperty(Configuration.Property.Indent, "true");
- Marshaller marshaller = new Marshaller(writer);
+
+ xmlContext.setProperty(XMLConfiguration.USE_INDENTATION, true);
+ Marshaller marshaller = xmlContext.createMarshaller();
+ marshaller.setWriter(writer);
+
marshaller.setRootElement("changelog");
marshaller.setSuppressXSIType(true);
marshaller.marshal(changelog);
Index: src/main/java/org/castor/xml/InternalContext.java
===================================================================
--- src/main/java/org/castor/xml/InternalContext.java (revision 0)
+++ src/main/java/org/castor/xml/InternalContext.java (revision 0)
@@ -0,0 +1,840 @@
+/*
+ * Copyright 2007 Joachim Grueneis
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.castor.xml;
+
+import java.io.IOException;
+import java.io.OutputStream;
+import java.io.Writer;
+
+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.core.util.Configuration;
+import org.castor.mapping.BindingType;
+import org.castor.mapping.MappingUnmarshaller;
+import org.castor.util.Messages;
+import org.exolab.castor.mapping.Mapping;
+import org.exolab.castor.mapping.MappingException;
+import org.exolab.castor.mapping.MappingLoader;
+import org.exolab.castor.util.RegExpEvaluator;
+import org.exolab.castor.xml.Introspector;
+import org.exolab.castor.xml.NodeType;
+import org.exolab.castor.xml.OutputFormat;
+import org.exolab.castor.xml.ResolverException;
+import org.exolab.castor.xml.Serializer;
+import org.exolab.castor.xml.XMLClassDescriptorResolver;
+import org.exolab.castor.xml.XMLNaming;
+import org.exolab.castor.xml.XMLSerializerFactory;
+import org.exolab.castor.xml.schema.Resolver;
+import org.exolab.castor.xml.util.DefaultNaming;
+import org.exolab.castor.xml.util.ResolverStrategy;
+import org.xml.sax.DocumentHandler;
+import org.xml.sax.Parser;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+/**
+ * The internal context is meant as center piece providing (and keeping) all
+ * information that is required by Marshaller, Unmarshaller, SourceGenerator,
+ * MappingTool, SchemaReader and SchemaWriter. It is created, filled with
+ * initial data and put into all other parts of Castor by {@link XMLContext}.
+ * It is NOT meant to be directly instantiated by user implementations!
+ * For all other objects it provides access to Castor state information
+ * (e.g. known descriptors) and configuration values.
+ *
+ * @author Joachim Grueneis
+ * @since 1.1.2
+ */
+public class InternalContext {
+ /** Logger to be used. */
+ private static final Log LOG = LogFactory.getFactory().getInstance(InternalContext.class);
+
+ /** The configuration to use internally to provide parser, serializer, ... */
+ private org.castor.core.util.Configuration _configuration;
+
+ /**
+ * {@link XMLClassDescriptorResolver} instance used for caching XML-related
+ * class descriptors.
+ */
+ 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 {@link XMLNaming} to be used.
+ */
+ private XMLNaming _xmlNaming;
+
+ /**
+ * The {@link JavaNaming} to be used.
+ */
+ private JavaNaming _javaNaming;
+
+ /**
+ * The class loader to use.
+ */
+ private ClassLoader _classLoader;
+
+ /**
+ * The {@link NodeType} to use for primitives.
+ */
+ private NodeType _primitiveNodeType;
+
+ /**
+ * The {@link RegExpevaluator} to use.
+ */
+ private RegExpEvaluator _regExpEvaluator;
+
+ /**
+ * Creates an instance of {@link InternalContext}. The internal context is meant to
+ * hold the configuration and state informations, but not necessarily retrieving
+ * those values...
+ */
+ public InternalContext() {
+ _configuration = XMLConfiguration.newInstance();
+ _javaNaming = new JavaNamingImpl();
+ }
+
+ /**
+ * Instructs Castor to load class descriptors from the mapping given.
+ * @param mapping Castor XML mapping (file), from which the required class
+ * descriptors will be derived.
+ * @throws MappingException If the {@link Mapping} cannot be loaded and analyzed successfully.
+ */
+ public void addMapping(final Mapping mapping) throws MappingException {
+ MappingUnmarshaller mappingUnmarshaller = new MappingUnmarshaller();
+ mappingUnmarshaller.setInternalContext(this);
+ MappingLoader mappingLoader =
+ mappingUnmarshaller.getMappingLoader(mapping, BindingType.XML);
+ _xmlClassDescriptorResolver.setMappingLoader(mappingLoader);
+ }
+
+ /**
+ * 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 has been generated
+ * using the XML code generator (in which case instead of a mapping file class
+ * descriptor files will be generated).
+ *
+ * @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 Class clazz) throws ResolverException {
+ _xmlClassDescriptorResolver.addClass(clazz);
+ }
+
+ /**
+ * 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 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 Class[] clazzes) throws ResolverException {
+ _xmlClassDescriptorResolver.addClasses(clazzes);
+ }
+
+ /**
+ * 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).
+ *
* org.exolab.castor.xml.nspackages
@@ -313,7 +309,7 @@
*
*/
public static final String STRICT_ELEMENTS = "org.exolab.castor.xml.strictelements";
-
+
/**
* Property specifying whether or not to save the "keys" of a {@link Hashtable} or
* {@link Map} during marshalling. By default this is true.
@@ -410,11 +406,11 @@
/**
* Property specifying whether element strictness for introspected classes/elements
- * should be lenient (aka allowed); defaults to true
+ * should be lenient (aka allowed); defaults to true.
*
* Possible values:
* - false
- * - tre (default)
+ * - true (default)
*
*
* org.exolab.castor.xml.lenient.introspected.element.strictness=true
@@ -425,5 +421,56 @@
public static final String LENIENT_INTROSPECTED_ELEMENT_STRICTNESS =
"org.exolab.castor.xml.lenient.introspected.element.strictness";
+ /**
+ * Property specifying which collections handlers should be used for
+ * Java 1.1 and Java 1.2 run-times.
+ *
+ *
+ * org.exolab.castor.mapping.collections
+ *
+ */
+ public static final String COLLECTION_HANDLERS_FOR_JAVA_11_OR_12 =
+ "org.exolab.castor.mapping.collections";
+ /**
+ * Property specifying if introspection should be used at class resolving.
+ *
+ *
+ * org.castor.xml.class-resolver.use-introspection
+ *
+ */
+ public static final String USE_INTROSPECTION
+ = "org.castor.xml.class-resolver.use-introspection";
+
+ /**
+ * The property name for enabling collection wrapping.
+ * The property controls whether or not collections
+ * (arrays, vectors, etc) should be wrapped in a container element.
+ * For example:
+ *
+ *
+ * <foos>
+ * <foo>foo1</foo>
+ * <foo>foo2</foo>
+ * </foos>
+ *
+ * instead of the default:
+ *
+ * <foos>foo1<foos>
+ * <foos>foo2</foos>
+ *
+ *
+ *
+ * Use this property with a value of true or false in the
+ * castor.properties file
+ *
+ * org.exolab.castor.xml.introspector.wrapCollections=true
+ * -or-
+ * org.exolab.castor.xml.introspector.wrapCollections=false
+ *
+ * This property is false by default.
+ */
+ public static final String WRAP_COLLECTIONS_PROPERTY =
+ "org.exolab.castor.xml.introspector.wrapCollections";
+
}
Index: src/main/java/org/castor/xml/BackwardCompatibilityContext.java
===================================================================
--- src/main/java/org/castor/xml/BackwardCompatibilityContext.java (revision 0)
+++ src/main/java/org/castor/xml/BackwardCompatibilityContext.java (revision 0)
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2007 Joachim Grueneis
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.castor.xml;
+
+import org.castor.mapping.BindingType;
+import org.exolab.castor.xml.ClassDescriptorResolverFactory;
+import org.exolab.castor.xml.Introspector;
+import org.exolab.castor.xml.XMLClassDescriptorResolver;
+import org.exolab.castor.xml.schema.Resolver;
+import org.exolab.castor.xml.schema.ScopableResolver;
+import org.exolab.castor.xml.util.ResolverStrategy;
+import org.exolab.castor.xml.util.resolvers.CastorXMLStrategy;
+
+/**
+ * As the name already expresses: this class is there for backward compatibility
+ * and should be removed from Castor with release 1.4 or such. Normally the
+ * internal context is created by XMLContext exclusivly and then handed down
+ * the call chain... this class is used in all cases which fail to be on a call
+ * chain started with XMLContext.
+ *
+ * @author Joachim Grueneis, jgrueneis_at_gmail_dot_com
+ * @version $Id$
+ */
+public class BackwardCompatibilityContext extends InternalContext {
+ /**
+ * Initializes InternalContext with default values.
+ */
+ public BackwardCompatibilityContext() {
+ setClassLoader(getClass().getClassLoader());
+
+ XMLClassDescriptorResolver cdr = (XMLClassDescriptorResolver) ClassDescriptorResolverFactory
+ .createClassDescriptorResolver(BindingType.XML);
+ cdr.setInternalContext(this);
+ setXMLClassDescriptorResolver(cdr);
+
+ Introspector introspector = new Introspector();
+ introspector.setInternalContext(this);
+ setIntrospector(introspector);
+
+ ResolverStrategy resolverStrategy = new CastorXMLStrategy();
+ setResolverStrategy(resolverStrategy);
+
+ Resolver schemaResolver = new ScopableResolver();
+ setSchemaResolver(schemaResolver);
+ }
+}
Index: src/main/java/org/castor/core/util/Configuration.java
===================================================================
--- src/main/java/org/castor/core/util/Configuration.java (revision 7250)
+++ src/main/java/org/castor/core/util/Configuration.java (working copy)
@@ -66,10 +66,7 @@
* used to load the Configuration class. No parent configuration will be set.
*/
protected Configuration() {
- _applicationClassLoader = getClass().getClassLoader();
- _domainClassLoader = getClass().getClassLoader();
-
- _parent = null;
+ this(null, null);
}
/**
@@ -80,8 +77,8 @@
* @param domain Classloader to be used for all domain objects.
*/
protected Configuration(final ClassLoader app, final ClassLoader domain) {
- _applicationClassLoader = app;
- _domainClassLoader = domain;
+ _applicationClassLoader = (app != null) ? app : getClass().getClassLoader();
+ _domainClassLoader = (domain != null) ? domain : getClass().getClassLoader();
_parent = null;
}
Index: src/main/java/org/castor/mapping/MappingUnmarshaller.java
===================================================================
--- src/main/java/org/castor/mapping/MappingUnmarshaller.java (revision 7250)
+++ src/main/java/org/castor/mapping/MappingUnmarshaller.java (working copy)
@@ -23,6 +23,7 @@
import org.apache.commons.logging.LogFactory;
import org.castor.core.CoreConfiguration;
import org.castor.util.Messages;
+import org.castor.xml.InternalContext;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.mapping.MappingException;
import org.exolab.castor.mapping.MappingLoader;
@@ -57,6 +58,12 @@
/** A flag that indicates of whether or not to allow redefinitions of class
* mappings. */
private boolean _allowRedefinitions = false;
+
+ /**
+ * The {@link InternalContext} holds all 'global' Castor states and access to
+ * configuration.
+ */
+ private InternalContext _internalContext;
//--------------------------------------------------------------------------
@@ -129,6 +136,7 @@
"CastorXmlMapping", bindingType);
loader.setClassLoader(mapping.getClassLoader());
loader.setAllowRedefinitions(_allowRedefinitions);
+ loader.setInternalContext(_internalContext);
loader.loadMapping(mapping.getRoot(), param);
return loader;
}
@@ -251,5 +259,13 @@
}
}
+ /**
+ * To set the internal context.
+ * @param internalContext the {@link InternalContext} to use
+ */
+ public void setInternalContext(final InternalContext internalContext) {
+ _internalContext = internalContext;
+ }
+
//--------------------------------------------------------------------------
}
Index: src/main/resources/org/castor/xml/castor.xml.properties
===================================================================
--- src/main/resources/org/castor/xml/castor.xml.properties (revision 7250)
+++ src/main/resources/org/castor/xml/castor.xml.properties (working copy)
@@ -71,6 +71,18 @@
#
org.exolab.castor.marshalling.validation=true
+# Property specifying whether XML documents (as generated at marshalling)
+# should use indentation or not.
+#
+# Possible values:
+# - false (default)
+# - true
+#
+#
+# org.exolab.castor.indent
+#
+org.exolab.castor.indent=false
+
# Comma separated list of SAX 2 features that should be enabled for the
# default parser.
#
@@ -119,12 +131,65 @@
# unmarshalling. Default is true which means that elements appearing in the
# XML document, which cannot be mapped to a class, cause a {@link SAXException}
# to be thrown. If set to false, these 'unknown' elements are ignored.
-# org.exolab.castor.xml.strictelements=false
+org.exolab.castor.xml.strictelements=false
# Property specifying whether element strictness for introspected
# classes/elements should be lenient (aka allowed); defaults to true
org.exolab.castor.xml.lenient.introspected.element.strictness=true
+<<<<<<< .mine
+# Property specifying whether or not to save the "keys" of a {@link Hashtable} or
+# {@link Map} during marshalling. By default this is true.
+#
+# Possible values:
+# - false
+# - true (default)
+#
+#
+# org.exolab.castor.xml.saveMapKeys
+#
+#
+# @since 0.9.5.3
+#
+org.exolab.castor.xml.saveMapKeys=true
+
+# Property specifying if introspection should be used at class resolving.
+#
+#
+# org.castor.xml.class-resolver.use-introspection
+#
+#
+org.castor.xml.class-resolver.use-introspection=true
+
+# The property name for enabling collection wrapping.
+# The property controls whether or not collections
+# (arrays, vectors, etc) should be wrapped in a container element.
+# For example:
+#
+#
+# <foos>
+# <foo>foo1</foo>
+# <foo>foo2</foo>
+# </foos>
+#
+# instead of the default:
+#
+# <foos>foo1<foos>
+# <foos>foo2</foos>
+#
+#
+#
+# Use this property with a value of true or false in the
+# castor.properties file
+#
+# org.exolab.castor.xml.introspector.wrapCollections=true
+# -or-
+# org.exolab.castor.xml.introspector.wrapCollections=false
+#
+# This property is false by default.
+#
+org.exolab.castor.xml.introspector.wrapCollections=false
+=======
# ******************************************************
# This section defines backwards compatibility switches.
# ******************************************************
@@ -135,3 +200,4 @@
#
org.exolab.castor.xml.saveMapKeys=true
+>>>>>>> .r7249
Index: src/doc/release-notes.xml
===================================================================
--- src/doc/release-notes.xml (revision 7250)
+++ src/doc/release-notes.xml (working copy)
@@ -181,7 +181,43 @@
Having said that this should not change anything for the user of Castor
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: +
When instructing Castor XML during unmarshalling to handle elements 'strict',
Index: xmlctf-framework/src/main/java/org/castor/xmlctf/XMLTestCase.java
===================================================================
--- xmlctf-framework/src/main/java/org/castor/xmlctf/XMLTestCase.java (revision 7250)
+++ xmlctf-framework/src/main/java/org/castor/xmlctf/XMLTestCase.java (working copy)
@@ -57,6 +57,7 @@
import junit.framework.TestCase;
+import org.castor.xml.InternalContext;
import org.castor.xmlctf.util.CTFUtils;
import org.exolab.castor.mapping.Mapping;
import org.exolab.castor.tests.framework.testDescriptor.CallMethod;
@@ -74,6 +75,7 @@
import org.exolab.castor.xml.Marshaller;
import org.exolab.castor.xml.UnmarshalListener;
import org.exolab.castor.xml.Unmarshaller;
+import org.exolab.castor.xml.XMLContext;
import org.xml.sax.InputSource;
/**
@@ -135,6 +137,8 @@
protected final FailureType _failure;
/** Used only to retrieve the classloader. */
protected final CastorTestCase _test;
+ /** The internal Castor XML context. */
+ private final XMLContext _xmlContext;
/**
* Instantiate a new XMLTestCase with the given name.
@@ -161,6 +165,7 @@
_failure = unit.getFailure();
_test = test;
_outputRootFile = test.getOutputRootFile();
+ _xmlContext = new XMLContext();
}
/**
@@ -178,6 +183,7 @@
_skip = tc._skip;
_failure = tc._failure;
_test = tc._test;
+ _xmlContext = new XMLContext();
}
/**
@@ -321,7 +327,9 @@
}
private Marshaller createMarshaler(final File marshalOutput) throws Exception {
- Marshaller marshaller = new Marshaller(new FileWriter(marshalOutput));
+//J Marshaller marshaller = new Marshaller(new FileWriter(marshalOutput));
+ Marshaller marshaller = _xmlContext.createMarshaller();
+ marshaller.setWriter(new FileWriter(marshalOutput));
//-- Configuration for marshaler? Use config from unit test case if available
Configuration config = _unitTest.getConfiguration();
@@ -389,12 +397,19 @@
final Unmarshaller unmar;
if (_mapping != null) {
- unmar = new Unmarshaller(_mapping);
+//J unmar = new Unmarshaller(_mapping);
+ unmar = _xmlContext.createUnmarshaller();
+ unmar.setMapping(_mapping);
} else {
if (_test.getClassLoader() != null) {
- unmar = new Unmarshaller(_rootClass, _test.getClassLoader());
+//J unmar = new Unmarshaller(_rootClass, _test.getClassLoader());
+ unmar = _xmlContext.createUnmarshaller();
+ unmar.setClassLoader(_test.getClassLoader());
+ unmar.setClass(_rootClass);
} else {
- unmar = new Unmarshaller(_rootClass);
+//J unmar = new Unmarshaller(_rootClass);
+ unmar = _xmlContext.createUnmarshaller();
+ unmar.setClass(_rootClass);
}
}
Index: ddlgen/src/test/java/org/castor/ddlgen/test/framework/AbstractGeneratorTest.java
===================================================================
--- ddlgen/src/test/java/org/castor/ddlgen/test/framework/AbstractGeneratorTest.java (revision 7250)
+++ ddlgen/src/test/java/org/castor/ddlgen/test/framework/AbstractGeneratorTest.java (working copy)
@@ -154,6 +154,7 @@
Mapping mapping = new Mapping();
mapping.loadMapping(mappingURL);
new MappingUnmarshaller().loadMappingOnly(mapping);
+ // TODO: Joachim 2007-09-07 the InternalContext should be set into the unmarshaller!
_generator.setMapping(mapping);
_generator.createSchema();
Index: ddlgen/src/main/java/org/castor/ddlgen/Main.java
===================================================================
--- ddlgen/src/main/java/org/castor/ddlgen/Main.java (revision 7250)
+++ ddlgen/src/main/java/org/castor/ddlgen/Main.java (working copy)
@@ -96,6 +96,7 @@
Mapping mapping = new Mapping();
mapping.loadMapping(mappingName);
new MappingUnmarshaller().loadMappingOnly(mapping);
+ // TODO: Joachim 2007-09-07 the InternalContext should be set into the unmarshaller!
generator.setMapping(mapping);
generator.generateDDL(new FileOutputStream(ddlName));
Index: xmlctf/tests/MasterTestSuite/sourcegenerator/Facets/UnwrappedNumbers/TestClassByte.java
===================================================================
--- xmlctf/tests/MasterTestSuite/sourcegenerator/Facets/UnwrappedNumbers/TestClassByte.java (revision 7250)
+++ xmlctf/tests/MasterTestSuite/sourcegenerator/Facets/UnwrappedNumbers/TestClassByte.java (working copy)
@@ -47,6 +47,8 @@
NumberTests instance = new NumberTests();
for (int i = 0; i < badValues.length; i++) {
try {
+ System.out.println("instance under test: " + instance + " of class: " + instance.getClass());
+ System.out.println("bad value: " + badValues[i] + " as byte: " + Byte.parseByte(badValues[i].trim()));
instance.setMybyte(Byte.parseByte(badValues[i].trim()));
instance.validate();
} catch (org.exolab.castor.xml.ValidationException e) {
@@ -71,7 +73,7 @@
// Good, we caught the exception
continue;
}
- LOG.error("Bad value " + badValuesMinMax[i] + " did not fail the test");
+ LOG.error("Bad min/max value " + badValuesMinMax[i] + " did not fail the test");
return false;
}
Index: codegen/src/main/java/org/exolab/castor/builder/SourceGenerator.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/SourceGenerator.java (revision 7250)
+++ codegen/src/main/java/org/exolab/castor/builder/SourceGenerator.java (working copy)
@@ -62,8 +62,12 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.castor.core.exceptions.CastorRuntimeException;
+import org.castor.core.util.Configuration;
+import org.castor.xml.BackwardCompatibilityContext;
import org.castor.xml.JavaNaming;
import org.castor.xml.JavaNamingImpl;
+import org.castor.xml.InternalContext;
+import org.castor.xml.XMLConfiguration;
import org.exolab.castor.builder.binding.BindingException;
import org.exolab.castor.builder.binding.BindingLoader;
import org.exolab.castor.builder.binding.ExtendedBinding;
@@ -80,8 +84,6 @@
import org.exolab.castor.builder.factory.SourceFactory;
import org.exolab.castor.builder.info.ClassInfo;
import org.exolab.castor.mapping.xml.MappingRoot;
-import org.exolab.castor.util.Configuration;
-import org.exolab.castor.util.LocalConfiguration;
import org.exolab.castor.util.NestedIOException;
import org.exolab.castor.util.Version;
import org.exolab.castor.util.dialog.ConsoleDialog;
@@ -141,8 +143,8 @@
//- Instance Variables -/
//----------------------/
- /** Castor configuration. */
- private final Configuration _config;
+ /** Castor internal context - mother of all. */
+ private final InternalContext _internalContext;
/** The XMLBindingComponent used to create Java classes from an XML Schema. */
private final XMLBindingComponent _bindingComponent;
/** Our object used to generate source for a single source file. */
@@ -223,8 +225,9 @@
public SourceGenerator(final FieldInfoFactory infoFactory, final ExtendedBinding binding) {
super();
- _config = LocalConfiguration.getInstance();
- setJavaNaming(new JavaNamingImpl());
+ _internalContext = new BackwardCompatibilityContext();
+
+ setJavaNaming(_internalContext.getJavaNaming());
_dialog = new ConsoleDialog();
_infoFactory = (infoFactory == null) ? new FieldInfoFactory() : infoFactory;
@@ -577,7 +580,7 @@
// -- get default parser from Configuration
Parser parser = null;
try {
- parser = _config.getParser();
+ parser = _internalContext.getParser();
} catch (RuntimeException rte) {
// ignore
}
@@ -589,7 +592,7 @@
SchemaUnmarshaller schemaUnmarshaller = null;
try {
- schemaUnmarshaller = new SchemaUnmarshaller();
+ schemaUnmarshaller = new SchemaUnmarshaller(_internalContext);
} catch (XMLException e) {
//--The default constructor cannot throw exception so this should never happen
//--just log the exception
Index: codegen/src/main/java/org/exolab/castor/builder/BuilderConfiguration.java
===================================================================
--- codegen/src/main/java/org/exolab/castor/builder/BuilderConfiguration.java (revision 7250)
+++ codegen/src/main/java/org/exolab/castor/builder/BuilderConfiguration.java (working copy)
@@ -56,10 +56,10 @@
import java.util.Properties;
import java.util.StringTokenizer;
+import org.castor.core.util.Configuration;
import org.castor.xml.JavaNaming;
import org.castor.xml.JavaNamingImpl;
-import org.exolab.castor.util.Configuration;
-import org.exolab.castor.util.LocalConfiguration;
+import org.castor.xml.XMLConfiguration;
/**
* The configuration for the SourceGenerator.
@@ -581,7 +581,7 @@
protected final synchronized void load() {
if (_defaultProps == null) {
//-- load defaults from JAR
- _defaultProps = Configuration.loadProperties(
+ _defaultProps = org.exolab.castor.util.Configuration.loadProperties(
Property.RESOURCE_NAME, Property.CONFIG_FILENAME_PROPERTY);
//-- load local defaults
@@ -618,12 +618,12 @@
}
}
- Configuration rtconf = LocalConfiguration.getInstance();
+ Configuration rtconf = XMLConfiguration.newInstance();
// Parse XML namespace and package list from both castor.properties and
// castorbuilder.properties
- processNamespacePackageMappings(rtconf.getProperty(Property.NAMESPACE_PACKAGES_OLD, ""));
- processNamespacePackageMappings(rtconf.getProperty(Property.NAMESPACE_PACKAGES, ""));
+ processNamespacePackageMappings(rtconf.getString(Property.NAMESPACE_PACKAGES_OLD, ""));
+ processNamespacePackageMappings(rtconf.getString(Property.NAMESPACE_PACKAGES, ""));
processNamespacePackageMappings(_defaultProps.getProperty(
Property.NAMESPACE_PACKAGES_OLD, ""));
processNamespacePackageMappings(_defaultProps.getProperty(
Index: anttask/src/main/java/org/castor/anttask/CastorCodeGenTask.java
===================================================================
--- anttask/src/main/java/org/castor/anttask/CastorCodeGenTask.java (revision 7250)
+++ anttask/src/main/java/org/castor/anttask/CastorCodeGenTask.java (working copy)
@@ -55,6 +55,8 @@
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.types.FileSet;
+import org.castor.xml.BackwardCompatibilityContext;
+import org.castor.xml.InternalContext;
import org.exolab.castor.builder.SourceGenerator;
import org.exolab.castor.builder.binding.ExtendedBinding;
import org.exolab.castor.builder.factory.FieldInfoFactory;
@@ -101,6 +103,9 @@
//--------------------------------------------------------------------------
+ /** Castor XML context - the mother of all. */
+ private InternalContext _internalContext;
+
/** If processing one schema file, this lists the file. */
private File _schemaFile = null;
@@ -169,7 +174,8 @@
* No-arg constructor.
*/
public CastorCodeGenTask() {
- // Nothing needed
+ super();
+ _internalContext = new BackwardCompatibilityContext();
}
//--------------------------------------------------------------------------
@@ -552,7 +558,7 @@
public void generateSource(final InputSource source, final String packageName) {
Parser parser = null;
try {
- parser = LocalConfiguration.getInstance().getParser();
+ parser = _internalContext.getParser();
} catch (RuntimeException e) {
throw new BuildException("Unable to create SAX parser.", e);
}
@@ -562,7 +568,7 @@
SchemaUnmarshaller schemaUnmarshaller = null;
try {
- schemaUnmarshaller = new SchemaUnmarshaller();
+ schemaUnmarshaller = new SchemaUnmarshaller(_internalContext);
} catch (XMLException e) {
throw new BuildException("Unable to create schema unmarshaller.", e);
}
Index: anttask/src/main/java/org/castor/anttask/CastorDDLGenTask.java
===================================================================
--- anttask/src/main/java/org/castor/anttask/CastorDDLGenTask.java (revision 7250)
+++ anttask/src/main/java/org/castor/anttask/CastorDDLGenTask.java (working copy)
@@ -173,6 +173,7 @@
Mapping mapping = new Mapping();
mapping.loadMapping(filePath);
new MappingUnmarshaller().loadMappingOnly(mapping);
+ // TODO: Joachim 2007-09-07 the InternalContext should be set into the unmarshaller!
ddlgen.setMapping(mapping);
ddlgen.generateDDL(_outputStream);
Index: .checkstyle
===================================================================
--- .checkstyle (revision 7250)
+++ .checkstyle (working copy)
@@ -7,28 +7,37 @@