[jboss-svn-commits] JBoss Common SVN: r2977 - in jbossxb/trunk/src: main/java/org/jboss/xb/builder/runtime and 3 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Feb 12 05:10:44 EST 2009
Author: alex.loubyansky at jboss.com
Date: 2009-02-12 05:10:43 -0500 (Thu, 12 Feb 2009)
New Revision: 2977
Added:
jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/NonXmlAnyElementDOMElementPropertyHandler.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/support/ElementBeforePrimitive.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementBeforePrimitiveUnitTestCase.java
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementBeforePrimitive.xml
Modified:
jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementPropertiesAndWildcardUnitTestCase.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/NotAnnotatedElementWildcardUnitTestCase.java
Log:
JBXB-178
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2009-02-11 10:19:40 UTC (rev 2976)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2009-02-12 10:10:43 UTC (rev 2977)
@@ -124,6 +124,7 @@
import org.jboss.xb.builder.runtime.DefaultMapEntry;
import org.jboss.xb.builder.runtime.EnumValueAdapter;
import org.jboss.xb.builder.runtime.MapPropertyHandler;
+import org.jboss.xb.builder.runtime.NonXmlAnyElementDOMElementPropertyHandler;
import org.jboss.xb.builder.runtime.PropertyHandler;
import org.jboss.xb.builder.runtime.PropertyInterceptor;
import org.jboss.xb.builder.runtime.PropertyWildcardHandler;
@@ -880,16 +881,6 @@
property.getUnderlyingAnnotation(XmlElementRefs.class) == null)
ignoreXmlAnyElement = true;
}
- else if (property.getType().getName().equals(org.w3c.dom.Element.class.getName()) && !seenXmlAnyElement && wildcardProperty == null)
- {
- if (trace)
- log.trace("Using type=" + beanInfo.getName() + " property=" + property.getName()
- + " as the base wildcard");
- if (wildcardProperty != null)
- throw new RuntimeException("@XmlAnyElement seen on two properties: " + property.getName() + " and "
- + wildcardProperty.getName());
- wildcardProperty = property;
- }
// Is this an attribute
XmlAttribute xmlAttribute = property.getUnderlyingAnnotation(XmlAttribute.class);
@@ -1147,7 +1138,7 @@
push(typeInfo, name);
// Get the property
PropertyInfo property = beanInfo.getProperty(name);
- bindProperty(property, typeBinding, model, beanAdapterFactory, propertyOrder);
+ bindProperty(property, typeBinding, model, beanAdapterFactory, propertyOrder, property == wildcardProperty);
pop();
}
@@ -1294,7 +1285,7 @@
}
private void bindProperty(PropertyInfo property, TypeBinding typeBinding, ModelGroupBinding model,
- BeanAdapterFactory beanAdapterFactory, String[] propertyOrder)
+ BeanAdapterFactory beanAdapterFactory, String[] propertyOrder, boolean wildcardProperty)
{
TypeInfo propertyType = property.getType();
if (trace)
@@ -1365,8 +1356,7 @@
if (xmlElement != null)
{
// A single element annotated
- elements = new XmlElement[]
- {xmlElement};
+ elements = new XmlElement[]{xmlElement};
}
else
{
@@ -1684,9 +1674,36 @@
}
ParticleBinding particle;
- // DOM elements are going to be treated as unresolved
- // however having the property registered
- if (!isMap && !Element.class.getName().equals(propertyType.getName()))
+ if(Element.class.getName().equals(propertyType.getName()))
+ {
+ if(!wildcardProperty)
+ {
+ WildcardBinding wildcard = new WildcardBinding(schemaBinding);
+ wildcard.setProcessContents((short) 2);
+ wildcard.setUnresolvedElementHandler(DOMHandler.INSTANCE);
+ wildcard.setUnresolvedCharactersHandler(DOMHandler.INSTANCE);
+
+ SequenceBinding seq = new SequenceBinding(schemaBinding);
+ seq.addParticle(new ParticleBinding(wildcard, 0, 1, false));
+
+ TypeBinding elementTypeBinding = new TypeBinding();
+ elementTypeBinding.setHandler(new NonXmlAnyElementDOMElementPropertyHandler(property, propertyType));
+ elementTypeBinding.setParticle(new ParticleBinding(seq, 0, 1, true));
+
+ ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding,
+ propertyQName, false);
+ elementBinding.setNillable(nillable);
+ elementBinding.setValueAdapter(valueAdapter);
+
+ // Bind it to the model
+ particle = new ParticleBinding(elementBinding, 1, 1, isCol);
+ if (required == false)
+ particle.setMinOccurs(0);
+
+ targetGroup.addParticle(particle);
+ }
+ }
+ else if (!isMap)
{
TypeBinding elementTypeBinding = resolveTypeBinding(localPropertyType);
ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, propertyQName, false);
Added: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/NonXmlAnyElementDOMElementPropertyHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/NonXmlAnyElementDOMElementPropertyHandler.java (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/NonXmlAnyElementDOMElementPropertyHandler.java 2009-02-12 10:10:43 UTC (rev 2977)
@@ -0,0 +1,51 @@
+/*
+ * 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.builder.runtime;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ParticleHandler;
+import org.xml.sax.Attributes;
+
+/**
+ * A DOMElementPropertyHandler.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class NonXmlAnyElementDOMElementPropertyHandler extends PropertyWildcardHandler implements ParticleHandler
+{
+ public NonXmlAnyElementDOMElementPropertyHandler(PropertyInfo propertyInfo, TypeInfo propertyType)
+ {
+ super(propertyInfo, propertyType);
+ }
+
+ public Object startParticle(Object parent, QName elementName, ParticleBinding particle, Attributes attrs,
+ NamespaceContext nsCtx)
+ {
+ return DOMHandler.INSTANCE.startParticle(parent, elementName, particle, attrs, nsCtx);
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/support/ElementBeforePrimitive.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/support/ElementBeforePrimitive.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/support/ElementBeforePrimitive.java 2009-02-12 10:10:43 UTC (rev 2977)
@@ -0,0 +1,59 @@
+/*
+ * 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.test.xb.builder.object.type.xmlanyelement.support;
+
+import javax.xml.bind.annotation.XmlType;
+
+import org.w3c.dom.Element;
+
+/**
+ * A ElementBeforePrimitive.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlType(propOrder={"dom", "text"})
+public class ElementBeforePrimitive
+{
+ private Element dom;
+ private String text;
+
+ public Element getDom()
+ {
+ return dom;
+ }
+
+ public void setDom(Element dom)
+ {
+ this.dom = dom;
+ }
+
+ public String getText()
+ {
+ return text;
+ }
+
+ public void setText(String text)
+ {
+ this.text = text;
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementBeforePrimitiveUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementBeforePrimitiveUnitTestCase.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementBeforePrimitiveUnitTestCase.java 2009-02-12 10:10:43 UTC (rev 2977)
@@ -0,0 +1,115 @@
+/*
+ * 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.test.xb.builder.object.type.xmlanyelement.test;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.XMLConstants;
+import javax.xml.namespace.QName;
+
+import junit.framework.Test;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xb.builder.object.type.xmlanyelement.support.ElementBeforePrimitive;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SequenceBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TermBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TypeBinding;
+import org.jboss.xb.builder.JBossXBBuilder;
+import org.w3c.dom.Element;
+import org.w3c.dom.NodeList;
+
+/**
+ * A ElementBeforePrimitiveUnitTestCase.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class ElementBeforePrimitiveUnitTestCase extends AbstractBuilderTest
+{
+ public static Test suite()
+ {
+ return suite(ElementBeforePrimitiveUnitTestCase.class);
+ }
+
+ public ElementBeforePrimitiveUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testUnmarshalling() throws Exception
+ {
+ ElementBeforePrimitive o = unmarshalObject(ElementBeforePrimitive.class);
+ Element element = o.getDom();
+ assertNotNull(element);
+ assertEquals("dom", element.getNodeName());
+ NodeList childNodes = element.getChildNodes();
+ assertNotNull(childNodes);
+ assertEquals(2, childNodes.getLength());
+ element = (Element) childNodes.item(0);
+ assertEquals("sweet", element.getNodeName());
+
+ assertEquals("frustration is not professional", o.getText());
+ }
+
+ public void testBinding() throws Exception
+ {
+ SchemaBinding schemaBinding = JBossXBBuilder.build(ElementBeforePrimitive.class);
+ assertNotNull(schemaBinding);
+
+ QName qName = new QName(XMLConstants.NULL_NS_URI, "element-before-primitive");
+ ElementBinding element = schemaBinding.getElement(qName);
+ assertNotNull(element);
+ TypeBinding type = element.getType();
+ assertNotNull(type);
+ ParticleBinding particle = type.getParticle();
+ assertNotNull(particle);
+ TermBinding term = particle.getTerm();
+ assertNotNull(term);
+ assertTrue(term instanceof SequenceBinding);
+
+ Collection<ParticleBinding> particles = ((SequenceBinding)term).getParticles();
+ assertEquals(2, particles.size());
+
+ Iterator<ParticleBinding> i = particles.iterator();
+ particle = i.next();
+ term = particle.getTerm();
+ assertTrue(term.isElement());
+ assertEquals(0, particle.getMinOccurs());
+ assertEquals(1, particle.getMaxOccurs());
+ assertFalse(particle.getMaxOccursUnbounded());
+ element = (ElementBinding) term;
+ assertEquals(new QName("dom"), element.getQName());
+
+ particle = i.next();
+ term = particle.getTerm();
+ assertTrue(term.isElement());
+ assertEquals(0, particle.getMinOccurs());
+ assertEquals(1, particle.getMaxOccurs());
+ assertFalse(particle.getMaxOccursUnbounded());
+ element = (ElementBinding) term;
+ assertEquals(new QName("text"), element.getQName());
+ }
+}
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementPropertiesAndWildcardUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementPropertiesAndWildcardUnitTestCase.java 2009-02-11 10:19:40 UTC (rev 2976)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementPropertiesAndWildcardUnitTestCase.java 2009-02-12 10:10:43 UTC (rev 2977)
@@ -21,6 +21,9 @@
*/
package org.jboss.test.xb.builder.object.type.xmlanyelement.test;
+import java.util.Collection;
+import java.util.Iterator;
+
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
@@ -107,16 +110,60 @@
TermBinding term = particle.getTerm();
assertNotNull(term);
assertTrue(term instanceof SequenceBinding);
- term = assertSingleSequence(term);
- assertTrue(term instanceof WildcardBinding);
+
+
+ Collection<ParticleBinding> particles = ((SequenceBinding)term).getParticles();
+ assertEquals(3, particles.size());
+
+ Iterator<ParticleBinding> i = particles.iterator();
+ particle = i.next();
+ term = particle.getTerm();
+ assertTrue(particle.getTerm().isElement());
+ assertEquals(0, particle.getMinOccurs());
+ assertEquals(1, particle.getMaxOccurs());
+ assertFalse(particle.getMaxOccursUnbounded());
+ element = (ElementBinding) term;
+ assertEquals(new QName("e1"), element.getQName());
+ particles = ((SequenceBinding)element.getType().getParticle().getTerm()).getParticles();
+ assertEquals(1, particles.size());
+ particle = particles.iterator().next();
+ assertWildcardTerm(element.getType(), particle, (short) 2);
+
+ particle = i.next();
+ term = particle.getTerm();
+ assertTrue(particle.getTerm().isElement());
+ assertEquals(0, particle.getMinOccurs());
+ assertEquals(1, particle.getMaxOccurs());
+ assertFalse(particle.getMaxOccursUnbounded());
+ element = (ElementBinding) term;
+ assertEquals(new QName("e2"), element.getQName());
+ particles = ((SequenceBinding)element.getType().getParticle().getTerm()).getParticles();
+ assertEquals(1, particles.size());
+ particle = particles.iterator().next();
+ assertWildcardTerm(element.getType(), particle, (short) 2);
+
+ particle = i.next();
+ assertWildcardTerm(type, particle, (short) 3);
WildcardBinding wildcardBinding = type.getWildcard();
+ ParticleHandler particleHandler = wildcardBinding.getWildcardHandler();
+ assertNotNull(particleHandler);
+ assertTrue(particleHandler instanceof PropertyWildcardHandler);
+ }
+
+ private void assertWildcardTerm(TypeBinding type, ParticleBinding particle, short pc)
+ {
+ TermBinding term;
+ term = particle.getTerm();
+ assertTrue(particle.getTerm().isWildcard());
+ assertEquals(0, particle.getMinOccurs());
+ assertEquals(1, particle.getMaxOccurs());
+ assertFalse(particle.getMaxOccursUnbounded());
+
+ WildcardBinding wildcardBinding = type.getWildcard();
assertNotNull(wildcardBinding);
assertTrue(term == wildcardBinding);
- assertTrue(wildcardBinding.isProcessContentsLax());
+ assertEquals(pc, wildcardBinding.getProcessContents());
assertTrue(DOMHandler.INSTANCE == wildcardBinding.getUnresolvedCharactersHandler());
assertTrue(DOMHandler.INSTANCE == wildcardBinding.getUnresolvedElementHandler());
- ParticleHandler particleHandler = wildcardBinding.getWildcardHandler();
- assertNotNull(particleHandler);
- assertTrue(particleHandler instanceof PropertyWildcardHandler);
}
}
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/NotAnnotatedElementWildcardUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/NotAnnotatedElementWildcardUnitTestCase.java 2009-02-11 10:19:40 UTC (rev 2976)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/type/xmlanyelement/test/NotAnnotatedElementWildcardUnitTestCase.java 2009-02-12 10:10:43 UTC (rev 2977)
@@ -21,6 +21,8 @@
*/
package org.jboss.test.xb.builder.object.type.xmlanyelement.test;
+import java.util.Collection;
+
import javax.xml.XMLConstants;
import javax.xml.namespace.QName;
@@ -30,7 +32,6 @@
import org.jboss.test.xb.builder.object.type.xmlanyelement.support.NotAnnotatedElementWildcard;
import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
-import org.jboss.xb.binding.sunday.unmarshalling.ParticleHandler;
import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
import org.jboss.xb.binding.sunday.unmarshalling.SequenceBinding;
import org.jboss.xb.binding.sunday.unmarshalling.TermBinding;
@@ -38,7 +39,6 @@
import org.jboss.xb.binding.sunday.unmarshalling.WildcardBinding;
import org.jboss.xb.builder.JBossXBBuilder;
import org.jboss.xb.builder.runtime.DOMHandler;
-import org.jboss.xb.builder.runtime.PropertyWildcardHandler;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -89,15 +89,24 @@
assertNotNull(term);
assertTrue(term instanceof SequenceBinding);
term = assertSingleSequence(term);
+
+ assertTrue(term.isElement());
+ element = (ElementBinding) term;
+ assertEquals(new QName("element"), element.getQName());
+ term = element.getType().getParticle().getTerm();
+ assertTrue(term instanceof SequenceBinding);
+ Collection<ParticleBinding> particles = ((SequenceBinding)term).getParticles();
+ assertEquals(1, particles.size());
+ particle = particles.iterator().next();
+ term = particle.getTerm();
+
assertTrue(term instanceof WildcardBinding);
+ type = element.getType();
WildcardBinding wildcardBinding = type.getWildcard();
assertNotNull(wildcardBinding);
assertTrue(term == wildcardBinding);
- assertTrue(wildcardBinding.isProcessContentsLax());
+ assertTrue(wildcardBinding.isProcessContentsSkip());
assertTrue(DOMHandler.INSTANCE == wildcardBinding.getUnresolvedCharactersHandler());
assertTrue(DOMHandler.INSTANCE == wildcardBinding.getUnresolvedElementHandler());
- ParticleHandler particleHandler = wildcardBinding.getWildcardHandler();
- assertNotNull(particleHandler);
- assertTrue(particleHandler instanceof PropertyWildcardHandler);
}
}
Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementBeforePrimitive.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementBeforePrimitive.xml (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/type/xmlanyelement/test/ElementBeforePrimitive.xml 2009-02-12 10:10:43 UTC (rev 2977)
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<element-before-primitive>
+ <dom><sweet/><sweet/></dom>
+ <text>frustration is not professional</text>
+</element-before-primitive>
More information about the jboss-svn-commits
mailing list