[jboss-svn-commits] JBoss Common SVN: r2998 - in jbossxb/trunk/src: test/java/org/jboss/test/xb/builder and 2 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Feb 27 05:46:00 EST 2009
Author: alex.loubyansky at jboss.com
Date: 2009-02-27 05:46:00 -0500 (Fri, 27 Feb 2009)
New Revision: 2998
Added:
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/MultiClassSchemaResolver.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UriToClassMapping.java
Modified:
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaResolverConfig.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/XsdBinder.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/AbstractBuilderTest.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/JBossXBTestDelegate.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/JbxbSchemaBindingAttributeUnitTestCase.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/SchemaBindingInitializerUnitTestCase.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/SchemaIncludeUnitTestCase.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/WildcardWrapperUnitTestCase.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/XOPUnitTestCase.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/XercesBugTestCase.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/minOccurs/Schema1UnitTestCase.java
Log:
JBXB-185 added a new multiple classes to schema resolver and made it the default now
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -43,7 +43,7 @@
* @author Scott.Stark at jboss.org
* @version $Revision$
*/
-public class DefaultSchemaResolver implements SchemaBindingResolver
+public class DefaultSchemaResolver implements SchemaBindingResolver, UriToClassMapping
{
private static Logger log = Logger.getLogger(DefaultSchemaResolver.class);
@@ -53,9 +53,9 @@
/** Namespace to SchemaBinding cache */
private Map<String, SchemaBinding> schemasByUri = Collections.emptyMap();
/** Namespace to JBossXBBuilder binding class */
- private WeakHashMap<String, Class> uriToClass = new WeakHashMap<String, Class>();
+ private WeakHashMap<String, Class<?>> uriToClass = new WeakHashMap<String, Class<?>>();
/** SchemaLocation to JBossXBBuilder binding class */
- private WeakHashMap<String, Class> schemaLocationToClass = new WeakHashMap<String, Class>();
+ private WeakHashMap<String, Class<?>> schemaLocationToClass = new WeakHashMap<String, Class<?>>();
/** Namespace to SchemaBindingInitializer */
private Map<String, SchemaBindingInitializer> schemaInitByUri = Collections.emptyMap();
/** Namespace to processAnnotations flag used with the XsdBinder.bind call */
@@ -228,7 +228,7 @@
* @param reference the schema reference class name
* @throws Exception for any error
*/
- public void addClassBinding(String nsUri, String reference) throws Exception
+ public void addClassBinding(String nsUri, String reference) throws ClassNotFoundException
{
if (reference == null)
throw new IllegalArgumentException("Null reference class");
@@ -507,4 +507,32 @@
return is;
}
+ public void mapUriToClass(String nsUri, String reference) throws ClassNotFoundException
+ {
+ addClassBinding(nsUri, reference);
+ }
+
+ public void mapUriToClass(String nsUri, Class<?> clazz)
+ {
+ addClassBinding(nsUri, clazz);
+ }
+
+ public void mapUriToClasses(String nsUri, String... reference) throws ClassNotFoundException
+ {
+ throw new UnsupportedOperationException("Namespace URI mapping to multiple classes is not supported by this implementation.");
+ }
+
+ public void mapUriToClasses(String nsUri, Class<?>... clazz)
+ {
+ throw new UnsupportedOperationException("Namespace URI mapping to multiple classes is not supported by this implementation.");
+ }
+
+ public Class<?>[] removeUriToClassMapping(String nsUri)
+ {
+ Class<?> clazz = removeClassBinding(nsUri);
+ if(clazz != null)
+ return new Class<?>[]{clazz};
+ return null;
+ }
+
}
Added: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/MultiClassSchemaResolver.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/MultiClassSchemaResolver.java (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/MultiClassSchemaResolver.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -0,0 +1,539 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.xb.binding.sunday.unmarshalling;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import org.jboss.logging.Logger;
+import org.jboss.util.xml.JBossEntityResolver;
+import org.jboss.xb.binding.JBossXBRuntimeException;
+import org.jboss.xb.builder.JBossXBBuilder;
+import org.w3c.dom.ls.LSInput;
+import org.xml.sax.InputSource;
+
+/**
+ * A default SchemaBindingResolver that uses a JBossEntityResolver to locate
+ * the schema xsd.
+ *
+ * @author Scott.Stark at jboss.org
+ * @author alex at jboss.org
+ * @version $Revision: 2913 $
+ */
+public class MultiClassSchemaResolver implements SchemaBindingResolver, UriToClassMapping
+{
+ private static Logger log = Logger.getLogger(MultiClassSchemaResolver.class);
+
+ private String baseURI;
+ private JBossEntityResolver resolver;
+ private boolean cacheResolvedSchemas = true;
+ /** Namespace to SchemaBinding cache */
+ private Map<String, SchemaBinding> schemasByUri = Collections.emptyMap();
+ /** Namespace to JBossXBBuilder binding class */
+ private WeakHashMap<String, Class<?>[]> uriToClass = new WeakHashMap<String, Class<?>[]>();
+ /** SchemaLocation to JBossXBBuilder binding class */
+ private WeakHashMap<String, Class<?>[]> schemaLocationToClass = new WeakHashMap<String, Class<?>[]>();
+ /** Namespace to SchemaBindingInitializer */
+ private Map<String, SchemaBindingInitializer> schemaInitByUri = Collections.emptyMap();
+ /** Namespace to processAnnotations flag used with the XsdBinder.bind call */
+ private Map<String, Boolean> schemaParseAnnotationsByUri = Collections.emptyMap();
+
+ public MultiClassSchemaResolver()
+ {
+ this(new JBossEntityResolver());
+ }
+
+ public MultiClassSchemaResolver(JBossEntityResolver resolver)
+ {
+ this.resolver = resolver;
+ }
+
+ /**
+ * @return true if resolved SchemaBinding's are cached, false otherwise
+ */
+ public boolean isCacheResolvedSchemas()
+ {
+ return cacheResolvedSchemas;
+ }
+
+ /**
+ * Passing in true will make the schema resolver to cache successfully resolved
+ * schemas (which is the default) with namespace URI being the identifier of a schema.
+ * False will flush the cache and make the schema resolver to resolve schemas
+ * on each request.
+ * @param cacheResolvedSchemas
+ */
+ public void setCacheResolvedSchemas(boolean cacheResolvedSchemas)
+ {
+ this.cacheResolvedSchemas = cacheResolvedSchemas;
+ if(!cacheResolvedSchemas)
+ {
+ schemasByUri = Collections.emptyMap();
+ }
+ }
+
+ /**
+ * Registers a location for the namespace URI.<p>
+ *
+ * This location is looked using the JBossEntityResolver, i.e. it is a classpath location
+ *
+ * @param nsUri the namespace location
+ * @param location the classpath location
+ */
+ public void addSchemaLocation(String nsUri, String location)
+ {
+ resolver.registerLocalEntity(nsUri, location);
+ }
+
+
+ /**
+ * Removes a location for the namespace URI.
+ *
+ * @todo actually remove it rather than setting null
+ * @param nsUri the namespace location
+ */
+ public void removeSchemaLocation(String nsUri)
+ {
+ resolver.registerLocalEntity(nsUri, null);
+ }
+
+ /**
+ * Whether to parse annotations for this namespace.
+ *
+ * @param nsUri the namespace
+ * @param value the value of the option
+ */
+ public void addSchemaParseAnnotations(String nsUri, Boolean value)
+ {
+ if (nsUri == null)
+ throw new IllegalArgumentException("Null namespace uri");
+ if (value == null)
+ throw new IllegalArgumentException("Null value");
+ switch(schemaParseAnnotationsByUri.size())
+ {
+ case 0:
+ schemaParseAnnotationsByUri = Collections.singletonMap(nsUri, value);
+ break;
+ case 1:
+ schemaParseAnnotationsByUri = new HashMap<String, Boolean>(schemaParseAnnotationsByUri);
+ default:
+ schemaParseAnnotationsByUri.put(nsUri, value);
+ }
+ }
+
+ /**
+ * Removes the parse annotation configuration for this namespace
+ *
+ * @param nsUri the namespace
+ * @return the previous value
+ */
+ public Boolean removeSchemaParseAnnotations(String nsUri)
+ {
+ if (nsUri == null)
+ throw new IllegalArgumentException("Null namespace uri");
+ return schemaParseAnnotationsByUri.remove(nsUri);
+ }
+
+ /**
+ * Registers a SchemaBindingInitializer for the namespace URI.
+ * When the schema binding that corresponds to the namespace URI
+ * is resolved, the init(SchemaBinding schema) method will be invoked on the
+ * instance of SchemaBindingInitializer with the SchemaBinding returned from the
+ * XsdBinder.bind() method.
+ *
+ * @param nsUri the namespace URI to register the schema initializer for
+ * @param sbiClassName the class name SchemaBindingInitializer
+ * @throws Exception for any error
+ */
+ public void addSchemaInitializer(String nsUri, String sbiClassName) throws Exception
+ {
+ if (sbiClassName == null)
+ throw new IllegalArgumentException("Null class name");
+ Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(sbiClassName);
+ Object object = clazz.newInstance();
+ if (object instanceof SchemaBindingInitializer == false)
+ throw new IllegalArgumentException(clazz.getName() + " is not an instance of " + SchemaBindingInitializer.class.getName());
+ SchemaBindingInitializer sbi = (SchemaBindingInitializer) object;
+ addSchemaInitializer(nsUri, sbi);
+ }
+
+ /**
+ * Registers an instance of SchemaBindingInitializer for the namespace URI.
+ * When the schema binding that corresponds to the namespace URI
+ * is resolved, the init(SchemaBinding schema) method will be invoked on the
+ * instance of SchemaBindingInitializer with the SchemaBinding returned from the
+ * XsdBinder.bind() method.
+ *
+ * @param nsUri the namespace URI to register the schema initializer for
+ * @param sbi an instance of SchemaBindingInitializer
+ */
+ public void addSchemaInitializer(String nsUri, SchemaBindingInitializer sbi)
+ {
+ if (nsUri == null)
+ throw new IllegalArgumentException("Null namespace uri");
+ if (sbi == null)
+ throw new IllegalArgumentException("Null schema binding initializer");
+ switch(schemaInitByUri.size())
+ {
+ case 0:
+ schemaInitByUri = Collections.singletonMap(nsUri, sbi);
+ break;
+ case 1:
+ schemaInitByUri = new HashMap<String, SchemaBindingInitializer>(schemaInitByUri);
+ default:
+ schemaInitByUri.put(nsUri, sbi);
+ }
+ }
+
+ /**
+ * Unregisters and returns the SchemaBindingInitializer for the namespace URI.
+ * @param nsUri the namespace URI to unregister SchemaBindingInitializer for
+ * @return unregistered SchemaBindingInitializer for the namespace URI or null
+ * if there was no SchemaBindingInitialzer registered for the namespace URI
+ */
+ public SchemaBindingInitializer removeSchemaInitializer(String nsUri)
+ {
+ if (nsUri == null)
+ throw new IllegalArgumentException("Null namespace uri");
+ return schemaInitByUri.remove(nsUri);
+ }
+
+ /**
+ * Add an in-memory schema.
+ *
+ * @param nsUri schema namespace
+ * @param reference the schema reference class name
+ * @throws Exception for any error
+ */
+ public void addClassBinding(String nsUri, String... reference) throws ClassNotFoundException
+ {
+ if (reference == null)
+ throw new IllegalArgumentException("Null reference class");
+
+ ClassLoader cl = Thread.currentThread().getContextClassLoader();
+ Class<?>[] classes = new Class<?>[reference.length];
+ for(int i = 0; i < classes.length; ++i)
+ classes[i] = cl.loadClass(reference[i]);
+ addClassBinding(nsUri, classes);
+ }
+
+ public void addClassBinding(String nsUri, Class<?>... clazz)
+ {
+ uriToClass.put(nsUri, clazz);
+ }
+
+ public Class<?>[] removeClassBinding(String nsUri)
+ {
+ return uriToClass.remove(nsUri);
+ }
+
+ public void addClassBindingForLocation(String schemaLocation, Class<?>... clazz)
+ {
+ schemaLocationToClass.put(schemaLocation, clazz);
+ }
+
+ public Class<?>[] removeClassBindingForLocation(String schemaLocation)
+ {
+ return schemaLocationToClass.remove(schemaLocation);
+ }
+
+ public String getBaseURI()
+ {
+ return baseURI;
+ }
+
+ public void setBaseURI(String baseURI)
+ {
+ this.baseURI = baseURI;
+ }
+
+ /**
+ * Uses the JBossEntityResolver.resolveEntity by:
+ *
+ * 1. Using the nsUri as the systemID
+ * 2. Using the schemaLocation as the systemID
+ * 3. If that fails, the baseURI is not null, the xsd is located using URL(baseURL, schemaLocation)
+ * 4. If the baseURI is null, the xsd is located using URL(schemaLocation)
+ */
+ public SchemaBinding resolve(String nsURI, String baseURI, String schemaLocation)
+ {
+ boolean trace = log.isTraceEnabled();
+ // Was the schema binding based on the nsURI
+ boolean foundByNS = false;
+ SchemaBinding schema = schemasByUri.get(nsURI);
+ if(schema != null)
+ {
+ if(trace)
+ log.trace("resolved cached schema, nsURI="+nsURI+", schema: " + schema);
+ return schema;
+ }
+
+ // Look for a class binding by schemaLocation
+ Class<?>[] classes = resolveClassFromSchemaLocation(schemaLocation, trace);
+ if (classes == null)
+ {
+ // Next look by namespace
+ classes = uriToClass.get(nsURI);
+ if(classes != null)
+ foundByNS = true;
+ }
+ if (classes != null)
+ {
+ if( trace )
+ {
+ log.trace("found bindingClass, nsURI="+nsURI
+ +", baseURI="+baseURI
+ +", schemaLocation="+schemaLocation
+ +", classes="+Arrays.asList(classes));
+ }
+ schema = JBossXBBuilder.build(classes);
+ }
+ else
+ {
+ // Parse the schema
+ InputSource is = getInputSource(nsURI, baseURI, schemaLocation);
+ if( trace )
+ {
+ String msg = (is == null ? "couldn't find" : "found") +
+ " schema InputSource, nsURI=" + nsURI +
+ ", baseURI=" + baseURI + ", schemaLocation=" +
+ schemaLocation;
+ log.trace(msg);
+ }
+
+ if (is != null)
+ {
+ if( baseURI == null )
+ baseURI = this.baseURI;
+
+ Boolean processAnnotationsBoolean = schemaParseAnnotationsByUri.get(nsURI);
+ boolean processAnnotations = (processAnnotationsBoolean == null) ? true : processAnnotationsBoolean.booleanValue();
+ try
+ {
+ schema = XsdBinder.bind(is.getByteStream(), null, baseURI, processAnnotations);
+ foundByNS = true;
+ }
+ catch(RuntimeException e)
+ {
+ String msg = "Failed to parse schema for nsURI="+nsURI
+ +", baseURI="+baseURI
+ +", schemaLocation="+schemaLocation;
+ throw new JBossXBRuntimeException(msg, e);
+ }
+ }
+ }
+
+ if(schema != null)
+ {
+ schema.setSchemaResolver(this);
+ SchemaBindingInitializer sbi = schemaInitByUri.get(nsURI);
+ if(sbi != null)
+ {
+ schema = sbi.init(schema);
+ }
+
+ if(schema != null && nsURI.length() > 0 && cacheResolvedSchemas && foundByNS)
+ {
+ if(schemasByUri.isEmpty())
+ {
+ schemasByUri = new HashMap<String, SchemaBinding>();
+ }
+ schemasByUri.put(nsURI, schema);
+ }
+ }
+
+ if(trace)
+ {
+ log.trace("resolved schema: " + schema);
+ }
+
+ return schema;
+ }
+
+ /**
+ * Lookup a binding class by schemaLocation. This first uses the
+ * schemaLocation as is, then parses this as a URI to obtain the
+ * final path component. This allows registration of a binding class
+ * using jboss_5_0.dtd rather than http://www.jboss.org/j2ee/schema/jboss_5_0.xsd
+ *
+ * @param schemaLocation the schema location from the parser
+ * @param trace - logging trace flag
+ * @return the binding class if found.
+ */
+ protected Class<?>[] resolveClassFromSchemaLocation(String schemaLocation, boolean trace)
+ {
+ Class<?>[] classes = schemaLocationToClass.get(schemaLocation);
+ if (classes == null && schemaLocation != null && schemaLocation.length() > 0)
+ {
+ // Parse the schemaLocation as a uri to get the final path component
+ try
+ {
+ URI url = new URI(schemaLocation);
+ String path = url.getPath();
+ if( path == null )
+ path = url.getSchemeSpecificPart();
+ int slash = path.lastIndexOf('/');
+ String filename;
+ if( slash >= 0 )
+ filename = path.substring(slash + 1);
+ else
+ filename = path;
+
+ if(path.length() == 0)
+ return null;
+
+ if (trace)
+ log.trace("Mapped schemaLocation to filename: " + filename);
+ classes = schemaLocationToClass.get(filename);
+ }
+ catch (URISyntaxException e)
+ {
+ if (trace)
+ log.trace("schemaLocation: is not a URI, using systemId as resource", e);
+ }
+ }
+ return classes;
+ }
+
+ public LSInput resolveAsLSInput(String nsURI, String baseURI, String schemaLocation)
+ {
+ LSInput lsInput = null;
+ InputSource is = getInputSource(nsURI, baseURI, schemaLocation);
+ if (is != null)
+ {
+ String publicId = is.getPublicId();
+ String systemId = is.getSystemId();
+ lsInput = new LSInputAdaptor(publicId, systemId, baseURI);
+ lsInput.setCharacterStream(is.getCharacterStream());
+ lsInput.setByteStream(is.getByteStream());
+ lsInput.setEncoding(is.getEncoding());
+ }
+ return lsInput;
+ }
+
+ private InputSource getInputSource(String nsURI, String baseURI, String schemaLocation)
+ {
+ boolean trace = log.isTraceEnabled();
+ InputSource is = null;
+
+ if( trace )
+ log.trace("getInputSource, nsURI="+nsURI+", baseURI="+baseURI+", schemaLocation="+schemaLocation);
+
+ // First try what is requested
+ try
+ {
+ is = resolver.resolveEntity(nsURI, schemaLocation);
+ if (trace)
+ {
+ String msg = (is == null ? "Couldn't resolve" : "Resolved") +
+ " schema using namespace as publicId and schemaLocation as systemId";
+ log.trace(msg);
+ }
+ }
+ catch (Exception e)
+ {
+ if (trace)
+ log.trace("Failed to use nsUri/schemaLocation", e);
+ }
+
+ // Next, try to use the baseURI to resolve the schema location
+ if(baseURI == null)
+ {
+ baseURI = this.baseURI;
+ }
+
+ if (is == null && baseURI != null && schemaLocation != null)
+ {
+ try
+ {
+ URL url = new URL(baseURI);
+ url = new URL(url, schemaLocation);
+ String resolvedSchemaLocation = url.toString();
+ // No point if the schema location was already absolute
+ if (schemaLocation.equals(resolvedSchemaLocation) == false)
+ {
+ is = resolver.resolveEntity(null, url.toString());
+ if( trace && is != null )
+ log.trace("Resolved schema location using baseURI");
+ }
+ }
+ catch (Exception e)
+ {
+ if (trace)
+ log.trace("Failed to use schema location with baseURI", e);
+ }
+ }
+
+ // Finally, just try the namespace as the system id
+ if (is == null && nsURI != null)
+ {
+ try
+ {
+ is = resolver.resolveEntity(null, nsURI);
+ if( trace && is != null )
+ log.trace("Resolved namespace as system id");
+ }
+ catch (Exception e)
+ {
+ if (trace)
+ log.trace("Failed to use namespace as system id", e);
+ }
+ }
+ if( trace )
+ {
+ log.trace("getInputSource, nsURI="+nsURI+", baseURI="
+ +baseURI+", schemaLocation="+schemaLocation+", is="+is);
+ }
+ return is;
+ }
+
+ public void mapUriToClass(String nsUri, String reference) throws ClassNotFoundException
+ {
+ addClassBinding(nsUri, reference);
+ }
+
+ public void mapUriToClass(String nsUri, Class<?> clazz)
+ {
+ addClassBinding(nsUri, clazz);
+ }
+
+ public void mapUriToClasses(String nsUri, String... reference) throws ClassNotFoundException
+ {
+ addClassBinding(nsUri, reference);
+ }
+
+ public void mapUriToClasses(String nsUri, Class<?>... clazz)
+ {
+ addClassBinding(nsUri, clazz);
+ }
+
+ public Class<?>[] removeUriToClassMapping(String nsUri)
+ {
+ return this.removeClassBinding(nsUri);
+ }
+}
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaResolverConfig.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaResolverConfig.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaResolverConfig.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -26,7 +26,6 @@
import java.util.Properties;
import org.jboss.logging.Logger;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
/**
* SchemaResolverConfig.
@@ -41,7 +40,7 @@
private static final Logger log = Logger.getLogger(SchemaResolverConfig.class);
/** The singleton schema resolver */
- protected static DefaultSchemaResolver resolver = (DefaultSchemaResolver) SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+ protected static MultiClassSchemaResolver resolver = (MultiClassSchemaResolver) SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
/** The initializers by namespace */
protected Properties schemaInitializers;
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SingletonSchemaResolverFactory.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -39,7 +39,7 @@
private static final SingletonSchemaResolverFactory singleton = new SingletonSchemaResolverFactory();
/** The resolver */
- private final DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ private final MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
/**
* Get the factory instance
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -948,13 +948,13 @@
private Attributes preprocessAttributes(Attributes attrs)
{
SchemaBindingResolver resolver = schemaResolver == null ? schema.getSchemaResolver() : schemaResolver;
- if(resolver == null || !(resolver instanceof DefaultSchemaResolver))
+ if(resolver == null || !(resolver instanceof UriToClassMapping))
return attrs;
int ind = attrs.getIndex(Constants.NS_JBXB, "schemabinding");
if (ind != -1)
{
- DefaultSchemaResolver defaultResolver = (DefaultSchemaResolver)resolver;
+ UriToClassMapping defaultResolver = (UriToClassMapping)resolver;
String value = attrs.getValue(ind);
java.util.StringTokenizer tokenizer = new java.util.StringTokenizer(value);
while(tokenizer.hasMoreTokens())
@@ -965,7 +965,7 @@
String cls = tokenizer.nextToken();
try
{
- defaultResolver.addClassBinding(uri, cls);
+ defaultResolver.mapUriToClass(uri, cls);
}
catch (Exception e)
{
Added: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UriToClassMapping.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UriToClassMapping.java (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/UriToClassMapping.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.xb.binding.sunday.unmarshalling;
+
+/**
+ * A ClassToSchemaMapping.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public interface UriToClassMapping
+{
+ public void mapUriToClass(String nsUri, String reference) throws ClassNotFoundException;
+
+ public void mapUriToClass(String nsUri, Class<?> clazz);
+
+ public void mapUriToClasses(String nsUri, String... reference) throws ClassNotFoundException;
+
+ public void mapUriToClasses(String nsUri, Class<?>... clazz);
+
+ public Class<?>[] removeUriToClassMapping(String nsUri);
+}
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/XsdBinder.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/XsdBinder.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/XsdBinder.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -95,7 +95,7 @@
*/
public static SchemaBinding bind(String xsdUrl)
{
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
resolver.setBaseURI(xsdUrl);
return bind(xsdUrl, resolver);
}
@@ -116,7 +116,7 @@
public static SchemaBinding bind(InputStream xsdStream, String encoding)
{
- return bind(xsdStream, encoding, new DefaultSchemaResolver());
+ return bind(xsdStream, encoding, new MultiClassSchemaResolver());
}
/**
@@ -141,7 +141,7 @@
*/
public static SchemaBinding bind(InputStream xsdStream, String encoding, String baseURI, boolean processAnnotations)
{
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
resolver.setBaseURI(baseURI);
return bind(xsdStream, encoding, resolver, processAnnotations);
}
@@ -178,7 +178,7 @@
public static SchemaBinding bind(Reader xsdReader, String encoding)
{
- return bind(xsdReader, encoding, new DefaultSchemaResolver());
+ return bind(xsdReader, encoding, new MultiClassSchemaResolver());
}
/**
@@ -190,7 +190,7 @@
*/
public static SchemaBinding bind(Reader xsdReader, String encoding, String baseURI)
{
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
resolver.setBaseURI(baseURI);
return bind(xsdReader, encoding, resolver);
}
@@ -219,7 +219,7 @@
*/
public static SchemaBinding bind(String xsd, String encoding)
{
- return bind(xsd, encoding, new DefaultSchemaResolver());
+ return bind(xsd, encoding, new MultiClassSchemaResolver());
}
/**
@@ -365,7 +365,7 @@
{
if(resolver == null)
{
- resolver = new DefaultSchemaResolver();
+ resolver = new MultiClassSchemaResolver();
}
XSModel model = Util.loadSchema(xsdUrl, resolver);
@@ -376,7 +376,7 @@
{
if(resolver == null)
{
- resolver = new DefaultSchemaResolver();
+ resolver = new MultiClassSchemaResolver();
}
XSModel model = Util.loadSchema(xsdStream, encoding, resolver);
@@ -387,7 +387,7 @@
{
if(resolver == null)
{
- resolver = new DefaultSchemaResolver();
+ resolver = new MultiClassSchemaResolver();
}
XSModel model = Util.loadSchema(xsdReader, encoding, resolver);
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/AbstractBuilderTest.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/AbstractBuilderTest.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/AbstractBuilderTest.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -27,8 +27,8 @@
import org.jboss.test.AbstractTestCaseWithSetup;
import org.jboss.test.AbstractTestDelegate;
import org.jboss.util.UnreachableStatementException;
+import org.jboss.xb.binding.sunday.unmarshalling.MultiClassSchemaResolver;
import org.jboss.xb.binding.sunday.unmarshalling.DefaultHandlers;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
import org.jboss.xb.binding.sunday.unmarshalling.ParticleHandler;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
@@ -96,7 +96,7 @@
protected <T> T unmarshalObjectFromSchema(Class<T> expected) throws Exception
{
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
// TODO this is a mess
String nsURI = "http://www.jboss.org/test/xml/" + rootName;
String packageName = getClass().getPackage().getName();
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/JBossXBTestDelegate.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/JBossXBTestDelegate.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/JBossXBTestDelegate.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -28,7 +28,7 @@
import org.jboss.test.AbstractTestDelegate;
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.MultiClassSchemaResolver;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
import org.jboss.xb.binding.sunday.unmarshalling.SingletonSchemaResolverFactory;
@@ -96,7 +96,7 @@
}
catch (NoSuchMethodException ignored)
{
- defaultResolver = new DefaultSchemaResolver();
+ defaultResolver = new MultiClassSchemaResolver();
}
}
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/JbxbSchemaBindingAttributeUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/JbxbSchemaBindingAttributeUnitTestCase.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/JbxbSchemaBindingAttributeUnitTestCase.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -24,9 +24,8 @@
import org.jboss.test.xb.builder.AbstractBuilderTest;
import org.jboss.test.xml.jbxb.schemabindingattribute.Ns2Root;
import org.jboss.test.xml.jbxb.schemabindingattribute.Root;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.MultiClassSchemaResolver;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
import org.jboss.xb.builder.JBossXBBuilder;
/**
@@ -46,7 +45,7 @@
public void testNested() throws Exception
{
SchemaBinding schema = JBossXBBuilder.build(Root.class);
- schema.setSchemaResolver(new DefaultSchemaResolver());
+ schema.setSchemaResolver(new MultiClassSchemaResolver());
String name = findTestXml();
Object o = unmarshal(name, schema);
assertNotNull(o);
@@ -62,7 +61,7 @@
public void testTop() throws Exception
{
String xml = findTestXml();
- Object o = unmarshal(xml, new DefaultSchemaResolver());
+ Object o = unmarshal(xml, new MultiClassSchemaResolver());
assertNotNull(o);
assertTrue(o instanceof Ns2Root);
}
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/SchemaBindingInitializerUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/SchemaBindingInitializerUnitTestCase.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/SchemaBindingInitializerUnitTestCase.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -28,7 +28,7 @@
import org.jboss.test.xml.initializer.Simple;
import org.jboss.test.xml.initializer.SimpleInitializer;
import org.jboss.xb.binding.JBossXBException;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.MultiClassSchemaResolver;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
/**
@@ -42,7 +42,7 @@
public static SchemaBindingResolver initResolver() throws Exception
{
Class<?> clazz = SchemaBindingInitializerUnitTestCase.class;
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
resolver.addSchemaInitializer(SimpleInitializer.NS, SimpleInitializer.class.getName());
String location = getSchemaLocation(clazz, "SchemaBindingInitializerUnitTestCaseSimple.xsd");
resolver.addSchemaLocation(SimpleInitializer.NS, location);
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/SchemaIncludeUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/SchemaIncludeUnitTestCase.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/SchemaIncludeUnitTestCase.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -25,7 +25,7 @@
import org.jboss.test.BaseTestCase;
import org.jboss.xb.binding.Util;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.MultiClassSchemaResolver;
/**
* SchemaIncludeUnitTestCase.
@@ -37,7 +37,7 @@
{
public void testSimpleInclude() throws Exception
{
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
URL url = getClass().getResource("/xml/SchemaIncludeUnitTestCase.xsd");
assertNotNull(url);
Util.loadSchema(url.toString(), resolver);
@@ -45,7 +45,7 @@
public void testComplexInclude() throws Exception
{
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
URL url = getClass().getResource("/xml/SchemaIncludeUnitTestCase.xsd");
assertNotNull(url);
resolver.addSchemaLocation("urn:jbosstest:schemainclude", url.toString());
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/WildcardWrapperUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/WildcardWrapperUnitTestCase.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/WildcardWrapperUnitTestCase.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -30,7 +30,7 @@
import org.jboss.test.xml.pojoserver.metadata.PropertyMetaData;
import org.jboss.test.xml.pojoserver.metadata.StringValueMetaData;
import org.jboss.test.xml.pojoserver.metadata.ValueMetaData;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.MultiClassSchemaResolver;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
/**
@@ -44,7 +44,7 @@
public static SchemaBindingResolver initResolver() throws Exception
{
Class<?> clazz = WildcardWrapperUnitTestCase.class;
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
resolver.addSchemaInitializer(PropertyInitializer.NS, PropertyInitializer.class.getName());
String location = getSchemaLocation(clazz, "WildcardWrapperUnitTestCase.xsd");
resolver.addSchemaLocation(PropertyInitializer.NS, location);
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/XOPUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/XOPUnitTestCase.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/XOPUnitTestCase.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -24,7 +24,7 @@
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
import org.jboss.xb.binding.sunday.marshalling.MarshallerImpl;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.MultiClassSchemaResolver;
import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
@@ -252,7 +252,7 @@
{
String testXsd = findXML(rootName + ".xsd");
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
String xmimeXsd = getSchemaLocation(getClass(), "xmlmime.xsd");
resolver.addSchemaLocation("http://www.w3.org/2005/05/xmlmime", xmimeXsd);
@@ -608,7 +608,7 @@
" <element name='applxml' xmime:expectedContentTypes='application/xml' type='xmime:base64Binary'/>" +
"</schema>";
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
String xmimeXsd = getSchemaLocation(getClass(), "xmlmime.xsd");
resolver.addSchemaLocation("http://www.w3.org/2005/05/xmlmime", xmimeXsd);
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/XercesBugTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/XercesBugTestCase.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/XercesBugTestCase.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -35,7 +35,7 @@
import org.jboss.test.BaseTestCase;
import org.jboss.xb.binding.Constants;
import org.jboss.xb.binding.Util;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.MultiClassSchemaResolver;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBindingResolver;
import org.jboss.xb.binding.sunday.unmarshalling.XsdBinderTerminatingErrorHandler;
import org.w3c.dom.DOMConfiguration;
@@ -90,7 +90,7 @@
String name = "xml/xerces-bug.xsd";
URL xsdUrl = Thread.currentThread().getContextClassLoader().getResource(name);
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
resolver.setBaseURI(xsdUrl.toString());
XSImplementation impl = getXSImplementation();
XSLoader schemaLoader = impl.createXSLoader(null);
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/minOccurs/Schema1UnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/minOccurs/Schema1UnitTestCase.java 2009-02-25 18:35:13 UTC (rev 2997)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/jbxb/minOccurs/Schema1UnitTestCase.java 2009-02-27 10:46:00 UTC (rev 2998)
@@ -22,21 +22,11 @@
package org.jboss.test.xml.jbxb.minOccurs;
-import java.io.InputStream;
-import java.io.IOException;
import java.net.URL;
-import javax.xml.namespace.QName;
-
-import junit.framework.TestCase;
-import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.XsdBinder;
-import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.DefaultSchemaResolver;
+import org.jboss.xb.binding.sunday.unmarshalling.MultiClassSchemaResolver;
import org.jboss.xb.binding.Unmarshaller;
import org.jboss.xb.binding.UnmarshallerFactory;
-import org.jboss.test.xml.jbxb.defaults.JBean;
import org.jboss.test.xml.AbstractJBossXBTest;
/**
@@ -54,7 +44,7 @@
public void testSchema1() throws Exception
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
resolver.addSchemaLocation("urn:jboss:jbxb-minOccurs-schema1", "xml/jbxb/minOccurs/schema1.xsd");
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
@@ -65,7 +55,7 @@
public void testSchema1v2() throws Exception
{
ClassLoader loader = Thread.currentThread().getContextClassLoader();
- DefaultSchemaResolver resolver = new DefaultSchemaResolver();
+ MultiClassSchemaResolver resolver = new MultiClassSchemaResolver();
resolver.addSchemaLocation("urn:jboss:jbxb-minOccurs-schema1", "xml/jbxb/minOccurs/schema1v2.xsd");
Unmarshaller unmarshaller = UnmarshallerFactory.newInstance().newUnmarshaller();
More information about the jboss-svn-commits
mailing list