[jboss-svn-commits] JBoss Common SVN: r4858 - in jbossxb/trunk/src: main/java/org/jboss/xb/binding/sunday/unmarshalling and 7 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Oct 7 07:39:33 EDT 2010
Author: alex.loubyansky at jboss.com
Date: 2010-10-07 07:39:32 -0400 (Thu, 07 Oct 2010)
New Revision: 4858
Added:
jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/MutableSchemaResolverWithQNameMapping.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/
jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/
jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/Base.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/NoNsRoot.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/Ns1Root.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/test/
jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMappingTestCase.java
jbossxb/trunk/src/test/resources/org/jboss/test/xml/resolverwithqnamemapping/
jbossxb/trunk/src/test/resources/org/jboss/test/xml/resolverwithqnamemapping/test/
jbossxb/trunk/src/test/resources/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMapping_testNoNsRoot.xml
jbossxb/trunk/src/test/resources/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMapping_testNs1Root.xml
Modified:
jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/AbstractMutableSchemaResolver.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/MultiClassSchemaResolver.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaBindingResolver.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/SundayContentHandler.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/WildcardBinding.java
Log:
JBXB-253
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/AbstractMutableSchemaResolver.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/AbstractMutableSchemaResolver.java 2010-09-30 20:29:59 UTC (rev 4857)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/AbstractMutableSchemaResolver.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -29,6 +29,8 @@
import java.util.HashMap;
import java.util.Map;
+import javax.xml.namespace.QName;
+
import org.jboss.logging.Logger;
import org.jboss.util.xml.JBossEntityResolver;
import org.jboss.xb.binding.JBossXBRuntimeException;
@@ -48,7 +50,7 @@
* @author <a href="alex at jboss.com">Alexey Loubyansky</a>
* @version $Revision: 1.1 $
*/
-public abstract class AbstractMutableSchemaResolver implements MutableSchemaResolver
+public abstract class AbstractMutableSchemaResolver implements MutableSchemaResolverWithQNameMapping
{
private Logger log;
private String baseURI;
@@ -280,7 +282,7 @@
* 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)
+ public SchemaBinding resolve(String nsURI, String localName, String schemaLocation)
{
boolean trace = log.isTraceEnabled();
// Was the schema binding based on the nsURI
@@ -293,8 +295,12 @@
return schema;
}
+ Class<?>[] classes = null;
+ if(localName != null)
+ classes = getClassesForQName(new QName(nsURI, localName));
// Look for a class binding by schemaLocation
- Class<?>[] classes = resolveClassFromSchemaLocation(schemaLocation, trace);
+ if(classes == null)
+ classes = resolveClassFromSchemaLocation(schemaLocation, trace);
if (classes == null)
{
// Next look by namespace
@@ -308,7 +314,7 @@
if( trace )
{
log.trace("found bindingClass, nsURI=" + nsURI +
- ", baseURI=" + baseURI +
+ ", localName=" + localName +
", schemaLocation=" + schemaLocation +
", classes=" + Arrays.asList(classes));
}
@@ -317,32 +323,29 @@
else
{
// Parse the schema
- InputSource is = getInputSource(nsURI, baseURI, schemaLocation);
+ InputSource is = getInputSource(nsURI, null, schemaLocation);
if( trace )
{
String msg = (is == null ? "couldn't find" : "found") +
" schema InputSource, nsURI=" + nsURI +
- ", baseURI=" + baseURI + ", schemaLocation=" +
+ ", localName=" + localName + ", schemaLocation=" +
schemaLocation;
log.trace(msg);
}
if (is != null)
{
- if( baseURI == null )
- baseURI = this.baseURI;
-
Boolean processAnnotationsBoolean = schemaParseAnnotationsByUri.get(nsURI);
boolean processAnnotations = (processAnnotationsBoolean == null) || processAnnotationsBoolean;
try
{
- schema = XsdBinder.bind(is.getByteStream(), null, baseURI, processAnnotations);
+ schema = XsdBinder.bind(is.getByteStream(), null, this.baseURI, processAnnotations);
foundByNS = true;
}
catch(RuntimeException e)
{
String msg = "Failed to parse schema for nsURI="+nsURI
- +", baseURI="+baseURI
+ +", localName="+localName
+", schemaLocation="+schemaLocation;
throw new JBossXBRuntimeException(msg, e);
}
@@ -373,7 +376,7 @@
{
if(validateBinding)
{
- InputSource is = getInputSource(nsURI, baseURI, schemaLocation);
+ InputSource is = getInputSource(nsURI, null, schemaLocation);
if(is != null)
{
SchemaBindingValidator validator = this.validator;
@@ -574,5 +577,7 @@
protected abstract Class<?>[] getClassesForURI(String uri);
protected abstract Class<?>[] getClassesForSchemaLocation(String uri);
+
+ protected abstract Class<?>[] getClassesForQName(QName elementName);
}
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/MultiClassSchemaResolver.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/MultiClassSchemaResolver.java 2010-09-30 20:29:59 UTC (rev 4857)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/MultiClassSchemaResolver.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -24,6 +24,8 @@
import java.util.HashMap;
import java.util.Map;
+import javax.xml.namespace.QName;
+
import org.jboss.logging.Logger;
import org.jboss.util.xml.JBossEntityResolver;
@@ -43,6 +45,8 @@
private Map<String, Class<?>[]> uriToClass = new HashMap<String, Class<?>[]>();
/** SchemaLocation to JBossXBBuilder binding class */
private Map<String, Class<?>[]> schemaLocationToClass = new HashMap<String, Class<?>[]>();
+
+ private Map<QName, Class<?>[]> qNameToClass;
public MultiClassSchemaResolver()
{
@@ -111,4 +115,33 @@
{
return uriToClass.remove(nsUri);
}
+
+ @Override
+ protected Class<?>[] getClassesForQName(QName elementName)
+ {
+ if(qNameToClass == null)
+ return null;
+ return qNameToClass.get(elementName);
+ }
+
+ @Override
+ public void mapQNameToClasses(QName elementName, Class<?>... classes)
+ {
+ if(elementName == null)
+ throw new IllegalArgumentException("QName can't be null.");
+ if(classes == null)
+ throw new IllegalArgumentException("Classes can't be null.");
+
+ if(qNameToClass == null)
+ qNameToClass = new HashMap<QName, Class<?>[]>();
+ qNameToClass.put(elementName, classes);
+ }
+
+ @Override
+ public Class<?>[] removeQNameToClassMapping(QName elementName)
+ {
+ if(qNameToClass == null)
+ return null;
+ return qNameToClass.remove(elementName);
+ }
}
Added: jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/MutableSchemaResolverWithQNameMapping.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/MutableSchemaResolverWithQNameMapping.java (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/resolver/MutableSchemaResolverWithQNameMapping.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -0,0 +1,49 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.resolver;
+
+import javax.xml.namespace.QName;
+
+/**
+ * A MutableSchemaResolverWithQNameMapping.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public interface MutableSchemaResolverWithQNameMapping extends MutableSchemaResolver
+{
+ /**
+ * Maps element name to an array of classes that should be used as the base for the SchemaBinding.
+ *
+ * @param elementName the name of the root element
+ * @param classes the array of classes to build the SchemaBinding from
+ */
+ void mapQNameToClasses(QName elementName, Class<?>... classes);
+
+ /**
+ * Removes element name to class mapping.
+ *
+ * @param elementName the root element name
+ * @return the array of classes used to build the SchemaBinding or null, if the schema location wasn't mapped.
+ */
+ Class<?>[] removeQNameToClassMapping(QName elementName);
+}
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 2010-09-30 20:29:59 UTC (rev 4857)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/DefaultSchemaResolver.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -24,6 +24,8 @@
import java.util.HashMap;
import java.util.Map;
+import javax.xml.namespace.QName;
+
import org.jboss.logging.Logger;
import org.jboss.util.xml.JBossEntityResolver;
import org.jboss.xb.binding.resolver.AbstractMutableSchemaResolver;
@@ -43,7 +45,9 @@
private Map<String, Class<?>> uriToClass = new HashMap<String, Class<?>>();
/** SchemaLocation to JBossXBBuilder binding class */
private Map<String, Class<?>> schemaLocationToClass = new HashMap<String, Class<?>>();
-
+ /** element name to class mapping */
+ private Map<QName, Class<?>> qNameToClass;
+
public DefaultSchemaResolver()
{
super(log);
@@ -210,4 +214,38 @@
Class<?> c = this.removeClassBinding(nsUri);
return c == null ? null : new Class<?>[]{c};
}
+
+ @Override
+ protected Class<?>[] getClassesForQName(QName elementName)
+ {
+ if(qNameToClass == null)
+ return null;
+ Class<?> c = qNameToClass.get(elementName);
+ return c == null ? null : new Class<?>[]{c};
+ }
+
+ @Override
+ public void mapQNameToClasses(QName elementName, Class<?>... classes)
+ {
+ if(elementName == null)
+ throw new IllegalArgumentException("QName can't be null");
+ if(classes.length != 1)
+ throw new IllegalArgumentException("Attempt to map " + classes.length + " classes to " + elementName +
+ ". This implementation supports only single class mappings.");
+ Class<?> c = classes[0];
+ if(c == null)
+ throw new IllegalArgumentException("Class argument can't be null");
+ if(qNameToClass == null)
+ qNameToClass = new HashMap<QName, Class<?>>();
+ qNameToClass.put(elementName, c);
+ }
+
+ @Override
+ public Class<?>[] removeQNameToClassMapping(QName elementName)
+ {
+ if(qNameToClass == null)
+ return null;
+ Class<?> c = qNameToClass.remove(elementName);
+ return c == null ? null : new Class<?>[]{c};
+ }
}
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaBindingResolver.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaBindingResolver.java 2010-09-30 20:29:59 UTC (rev 4857)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaBindingResolver.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -37,14 +37,14 @@
* Returns an instance of SchemaBinding corresponding to the namespace URI.
*
* @param nsUri - namespace URI of the element with the schema reference
- * @param baseURI - an optional baseURI for resolving the schemaLocation.
+ * @param elementName - optional root element name
* @param schemaLocation - the option schema location uri that matches
* nsUri if one exists
* @return an instance of SchemaBinding correspnding to the namespace URI
* or null if the namespace URI is not recognized (though, in this case it
* could also throw an exception)
*/
- SchemaBinding resolve(String nsUri, String baseURI, String schemaLocation);
+ SchemaBinding resolve(String nsUri, String elementName, String schemaLocation);
/**
* This one is used to resolve imported schemas with <xsd:import>
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 2010-09-30 20:29:59 UTC (rev 4857)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SchemaResolverConfig.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -25,8 +25,10 @@
import java.util.Map;
import java.util.Properties;
+import javax.xml.namespace.QName;
+
import org.jboss.logging.Logger;
-import org.jboss.xb.binding.resolver.MutableSchemaResolver;
+import org.jboss.xb.binding.resolver.MutableSchemaResolverWithQNameMapping;
/**
* SchemaResolverConfig.
@@ -41,7 +43,7 @@
private static final Logger log = Logger.getLogger(SchemaResolverConfig.class);
/** The singleton schema resolver */
- protected static MutableSchemaResolver resolver = SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
+ protected static MutableSchemaResolverWithQNameMapping resolver = (MutableSchemaResolverWithQNameMapping) SingletonSchemaResolverFactory.getInstance().getSchemaBindingResolver();
/** The initializers by namespace */
protected Properties schemaInitializers;
@@ -194,4 +196,24 @@
}
}
+ public void setBindingClassesByElementNames(Map<QName, String> bindingClassesByElementName)
+ {
+ if (bindingClassesByElementName != null && bindingClassesByElementName.size() != 0)
+ {
+ ClassLoader loader = Thread.currentThread().getContextClassLoader();
+ for (Iterator<Map.Entry<QName, String>> i = bindingClassesByElementName.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry<QName, String> entry = i.next();
+ try
+ {
+ Class<?> clazz = loader.loadClass(entry.getValue());
+ resolver.mapQNameToClasses(entry.getKey(), clazz);
+ }
+ catch(ClassNotFoundException e)
+ {
+ log.warn("Failed to load class: " + entry.getValue(), e);
+ }
+ }
+ }
+ }
}
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 2010-09-30 20:29:59 UTC (rev 4857)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -173,7 +173,7 @@
if(schemaLocation == null && (namespaceURI == null || namespaceURI.length() == 0))
schemaLocation = localName;
}
- schemaBinding = schemaResolver.resolve(namespaceURI, null, schemaLocation);
+ schemaBinding = schemaResolver.resolve(namespaceURI, localName, schemaLocation);
if(schemaBinding != null)
particle = schemaBinding.getElementParticle(startName);
else
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/WildcardBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/WildcardBinding.java 2010-09-30 20:29:59 UTC (rev 4857)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/WildcardBinding.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -167,7 +167,7 @@
{
// this is wildcard handling
String schemaLocation = attrs == null ? null : Util.getSchemaLocation(attrs, qName.getNamespaceURI());
- SchemaBinding schema = resolver.resolve(qName.getNamespaceURI(), null, schemaLocation);
+ SchemaBinding schema = resolver.resolve(qName.getNamespaceURI(), qName.getLocalPart(), schemaLocation);
if(schema != null)
{
element = schema.getElement(qName);
Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/Base.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/Base.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/Base.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -0,0 +1,23 @@
+package org.jboss.test.xml.resolverwithqnamemapping.support;
+
+public class Base
+{
+
+ private String data;
+
+ public Base()
+ {
+ super();
+ }
+
+ public String getData()
+ {
+ return data;
+ }
+
+ public void setData(String data)
+ {
+ this.data = data;
+ }
+
+}
\ No newline at end of file
Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/NoNsRoot.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/NoNsRoot.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/NoNsRoot.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -0,0 +1,36 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.test.xml.resolverwithqnamemapping.support;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * A DefaultNsRoot.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+public class NoNsRoot extends Base
+{
+
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/Ns1Root.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/Ns1Root.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/support/Ns1Root.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -0,0 +1,39 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.test.xml.resolverwithqnamemapping.support;
+
+import javax.xml.bind.annotation.XmlNsForm;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.xb.annotations.JBossXmlSchema;
+
+/**
+ * A Root.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root", namespace="ns1")
+ at JBossXmlSchema(namespace="ns1", elementFormDefault=XmlNsForm.QUALIFIED)
+public class Ns1Root extends Base
+{
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMappingTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMappingTestCase.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMappingTestCase.java 2010-10-07 11:39:32 UTC (rev 4858)
@@ -0,0 +1,78 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.test.xml.resolverwithqnamemapping.test;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xml.resolverwithqnamemapping.support.NoNsRoot;
+import org.jboss.test.xml.resolverwithqnamemapping.support.Ns1Root;
+import org.jboss.xb.binding.resolver.MultiClassSchemaResolver;
+import org.jboss.xb.binding.resolver.MutableSchemaResolverWithQNameMapping;
+
+/**
+ * A ResolverWithQNameMappingTestCase.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class ResolverWithQNameMappingTestCase extends AbstractBuilderTest
+{
+ private MutableSchemaResolverWithQNameMapping resolver;
+
+ public ResolverWithQNameMappingTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void setUp() throws Exception
+ {
+ super.setUp();
+ resolver = new MultiClassSchemaResolver();
+ }
+
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+ resolver = null;
+ }
+
+ public void testNs1Root() throws Exception
+ {
+ resolver.mapQNameToClasses(new QName("ns1", "root"), Ns1Root.class);
+ Object o = unmarshal("ResolverWithQNameMapping_testNs1Root.xml", resolver);
+ assertNotNull(o);
+ assertTrue(o instanceof Ns1Root);
+ Ns1Root root = (Ns1Root) o;
+ assertEquals("ns1:root", root.getData());
+ }
+
+ public void testNoNsRoot() throws Exception
+ {
+ resolver.mapQNameToClasses(new QName("root"), NoNsRoot.class);
+ Object o = unmarshal("ResolverWithQNameMapping_testNoNsRoot.xml", resolver);
+ assertNotNull(o);
+ assertTrue(o instanceof NoNsRoot);
+ NoNsRoot root = (NoNsRoot) o;
+ assertEquals("nons:root", root.getData());
+ }
+}
Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMapping_testNoNsRoot.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMapping_testNoNsRoot.xml (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMapping_testNoNsRoot.xml 2010-10-07 11:39:32 UTC (rev 4858)
@@ -0,0 +1,3 @@
+<root>
+ <data>nons:root</data>
+</root>
\ No newline at end of file
Added: jbossxb/trunk/src/test/resources/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMapping_testNs1Root.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMapping_testNs1Root.xml (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xml/resolverwithqnamemapping/test/ResolverWithQNameMapping_testNs1Root.xml 2010-10-07 11:39:32 UTC (rev 4858)
@@ -0,0 +1,3 @@
+<root xmlns="ns1">
+ <data>ns1:root</data>
+</root>
\ No newline at end of file
More information about the jboss-svn-commits
mailing list