[jboss-svn-commits] JBoss Common SVN: r2194 - in jbossxb/trunk/src: main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime test/java/org/jboss/test/xml
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Dec 7 17:52:51 EST 2006
Author: alex.loubyansky at jboss.com
Date: 2006-12-07 17:52:45 -0500 (Thu, 07 Dec 2006)
New Revision: 2194
Modified:
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/CollectionOverridePropertyUnitTestCase.java
jbossxb/trunk/src/test/java/org/jboss/test/xml/SimpleContentUnitTestCase.java
Log:
JBXB-93 don't give up if a property resolution failed applying the 'array wrapper' pattern to a type. There maybe interceptors that take care of adding children to the parent
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java 2006-12-07 22:42:34 UTC (rev 2193)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/impl/runtime/RtElementHandler.java 2006-12-07 22:52:45 UTC (rev 2194)
@@ -495,37 +495,58 @@
}
}
- Class fieldType;
+ Class fieldType = null;
if(parentClass.isArray())
{
fieldType = parentClass.getComponentType();
}
else
{
- fieldType = FieldInfo.getFieldInfo(parentClass, propName, true).getType();
- if(particle.isRepeatable() && fieldType.isArray())
+ //fieldType = FieldInfo.getFieldInfo(parentClass, propName, true).getType();
+ // this was changed to false because allow overriding of handler.setParent()
+ // with an interceptor.add(). See CollectionOverridePropertyUnitTestCase
+ // In other words, don't treat it as an array wrapper.
+ FieldInfo fieldInfo = FieldInfo.getFieldInfo(parentClass, propName, false);
+ if(fieldInfo != null)
{
- fieldType = fieldType.getComponentType();
+ fieldType = fieldInfo.getType();
+ if (particle.isRepeatable() && fieldType.isArray())
+ {
+ fieldType = fieldType.getComponentType();
+ }
}
+ else if(arrayItem.getInterceptors().isEmpty())
+ {
+ QName typeName = ((ElementBinding)term).getType().getQName();
+ throw new JBossXBRuntimeException(
+ "Couldn't apply 'array wrapper' pattern for element " +
+ elementName + " of type " +
+ (typeName == null ? "anonymous" : typeName.toString()) +
+ ": failed to resolve property " + propName +
+ " and no interceptors applied to override handler.setParent(...)");
+ }
}
- // TODO: review the logic for cases when wrapperType == null
- if(fieldType.isArray())
+ if(fieldType != null)
{
- return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType.getComponentType());
- }
- else if(Collection.class.isAssignableFrom(fieldType))
- {
- if(wrapperType == null)
+ // TODO: review the logic for cases when wrapperType == null
+ if (fieldType.isArray())
{
- return new ValueListInitializer().newValueList(ValueListHandler.FACTORY.child(), Collection.class);
- //o = new ArrayList();
- }
+ return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType.getComponentType());
+ }
+ else if (Collection.class.isAssignableFrom(fieldType))
+ {
+ if (wrapperType == null)
+ {
+ return new ValueListInitializer().newValueList(ValueListHandler.FACTORY.child(), Collection.class);
+ //o = new ArrayList();
+ }
+ }
+ else
+ {
+ return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType);
+ }
}
- else
- {
- return GenericValueContainer.FACTORY.array(wrapperType, propName, fieldType);
- }
}
}
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/CollectionOverridePropertyUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/CollectionOverridePropertyUnitTestCase.java 2006-12-07 22:42:34 UTC (rev 2193)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/CollectionOverridePropertyUnitTestCase.java 2006-12-07 22:52:45 UTC (rev 2194)
@@ -57,8 +57,6 @@
public void testCollectionOverrideProperty() throws Exception
{
- enableTrace("org.jboss.xb");
-
SchemaBinding schema = bind("CollectionOverrideProperty.xsd");
schema.setIgnoreUnresolvedFieldOrClass(false);
@@ -85,26 +83,7 @@
type = schema.getType(new QName(NS, "child-type"));
assertNotNull(type);
type.setClassMetaData(classMetaData);
-/*
- type.setHandler(new ParticleHandler()
- {
- public Object endParticle(Object o, QName elementName, ParticleBinding particle)
- {
- return DefaultHandlers.ELEMENT_HANDLER.endParticle(o, elementName, particle);
- }
- public void setParent(Object parent, Object o, QName elementName, ParticleBinding particle,
- ParticleBinding parentParticle)
- {
- }
-
- public Object startParticle(Object parent, QName elementName, ParticleBinding particle, Attributes attrs,
- NamespaceContext nsCtx)
- {
- return DefaultHandlers.ELEMENT_HANDLER.startParticle(parent, elementName, particle, attrs, nsCtx);
- }
- });
-*/
Parent parent = (Parent) unmarshal("CollectionOverrideProperty.xml", schema, Parent.class);
List list = parent.list;
assertNotNull(list);
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xml/SimpleContentUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xml/SimpleContentUnitTestCase.java 2006-12-07 22:42:34 UTC (rev 2193)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xml/SimpleContentUnitTestCase.java 2006-12-07 22:52:45 UTC (rev 2194)
@@ -28,12 +28,10 @@
import junit.framework.TestSuite;
-import org.jboss.test.xml.CollectionOverridePropertyUnitTestCase.Parent;
import org.jboss.xb.binding.metadata.ClassMetaData;
import org.jboss.xb.binding.sunday.unmarshalling.DefaultElementInterceptor;
import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
/**
* SimpleContentUnitTestCase.
@@ -57,7 +55,7 @@
public void testCollectionOverrideProperty() throws Exception
{
- enableTrace("org.jboss.xb");
+ //enableTrace("org.jboss.xb");
SchemaBinding schema = bind("SimpleContent.xsd");
schema.setIgnoreUnresolvedFieldOrClass(false);
More information about the jboss-svn-commits
mailing list