[jboss-svn-commits] JBoss Common SVN: r3778 - in jbossxb/trunk/src: main/java/org/jboss/xb/builder and 8 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Nov 24 17:48:13 EST 2009
Author: alex.loubyansky at jboss.com
Date: 2009-11-24 17:48:12 -0500 (Tue, 24 Nov 2009)
New Revision: 3778
Added:
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Choice.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Sequence.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Top.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/test/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/test/RepeatableTermsUnitTestCase.java
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/repeatableterms/
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/repeatableterms/test/
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/repeatableterms/test/RepeatableTerms_testUnmarshalling.xml
Modified:
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ElementBinding.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ModelGroupBinding.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/TermBinding.java
jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/WildcardBinding.java
jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ArrayWrapperRepeatableParticleHandler.java
Log:
fixes in RepeatableParticleHandler.endRepeatableParticle() callbacks, moved QName from subclasses of TermBinding to TermBinding
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ElementBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ElementBinding.java 2009-11-24 13:47:54 UTC (rev 3777)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ElementBinding.java 2009-11-24 22:48:12 UTC (rev 3778)
@@ -44,7 +44,6 @@
{
protected List<ElementInterceptor> interceptors = Collections.emptyList();
- protected QName qName;
protected TypeBinding typeBinding;
protected boolean nillable;
protected Boolean normalizeSpace;
@@ -54,24 +53,20 @@
public ElementBinding(SchemaBinding schema, QName qName, TypeBinding typeBinding)
{
super(schema);
- this.qName = qName;
this.typeBinding = typeBinding;
-
- if(qName == null)
- {
- throw new JBossXBRuntimeException("Each element must have a non-null QName!");
- }
+ setQName(qName);
}
protected ElementBinding()
{
}
-
- public QName getQName()
+
+ public void setQName(QName qName)
{
- return qName;
+ if(qName == null)
+ throw new JBossXBRuntimeException("Each element must have a non-null QName!");
+ this.qName = qName;
}
-
public List<ElementInterceptor> getInterceptors()
{
return interceptors;
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ModelGroupBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ModelGroupBinding.java 2009-11-24 13:47:54 UTC (rev 3777)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/ModelGroupBinding.java 2009-11-24 22:48:12 UTC (rev 3778)
@@ -37,9 +37,6 @@
{
protected final Logger log = Logger.getLogger(getClass());
- /** The qualifed name for global groups */
- protected QName qName;
-
protected boolean requiredParticle;
protected ParticleHandler handler = DefaultHandlers.MODEL_GROUP_HANDLER;
@@ -48,29 +45,6 @@
super(schema);
}
- /**
- * Get the qName.
- *
- * @return the qName.
- */
- public QName getQName()
- {
- return qName;
- }
-
- /**
- * Set the qName.
- *
- * @param name the qName.
- * @throws IllegalArgumentException for a null qName
- */
- public void setQName(QName name)
- {
- if (name == null)
- throw new IllegalArgumentException("Null name");
- qName = name;
- }
-
public ParticleHandler getHandler()
{
return handler;
@@ -92,9 +66,7 @@
public void addParticle(ParticleBinding particle)
{
if(particle.isRequired())
- {
requiredParticle = true;
- }
}
public abstract Collection<ParticleBinding> getParticles();
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-11-24 13:47:54 UTC (rev 3777)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/SundayContentHandler.java 2009-11-24 22:48:12 UTC (rev 3778)
@@ -179,22 +179,13 @@
{
if(position.ended)
{
- pop();
if(position.particle.isRepeatable())
{
- Position parentPosition = stack.peek();
+ Position parentPosition = stack.peek1();
if(parentPosition.repeatableParticleValue != null)
- {
- // TODO this has to be done for every endRepeatableParticle
- Position notSkippedParent = parentPosition;
- if(parentPosition.particle.getTerm().isSkip())
- notSkippedParent = stack.peek1();
- int i = stack.size() - 2;
- while(notSkippedParent.particle.getTerm().isSkip() && i >= 0)
- notSkippedParent = stack.peek(i--);
- endRepeatableParticle(parentPosition, position.qName, position.particle, notSkippedParent.particle);
- }
+ endRepeatableParticle(parentPosition, position.qName, position.particle, parentPosition.particle);
}
+ pop();
}
else
{
@@ -206,19 +197,19 @@
else
{
if(!position.ended) // could be ended if it's a choice
- endParticle(position, stack.peek1());
+ endParticle(position);
ParticleBinding currentParticle = position.cursor.getCurrentParticle();
- if(position.repeatableParticleValue != null && currentParticle.getTerm().isWildcard())
+ if(position.repeatableParticleValue != null && currentParticle.isRepeatable() && currentParticle.getTerm().isWildcard())
endRepeatableParticle(position, position.qName, currentParticle, position.particle);
- pop();
if(position.particle.isRepeatable())
{
- Position parentPosition = stack.peek();
+ Position parentPosition = stack.peek1();
if(parentPosition.repeatableParticleValue != null)
endRepeatableParticle(parentPosition, position.qName, position.particle, parentPosition.particle);
}
+ pop();
}
}
@@ -328,15 +319,15 @@
}
else
{
- pop();
if(position.particle.isRepeatable())
{
- Position parentPosition = stack.peek();
+ Position parentPosition = stack.peek1();
if(parentPosition.repeatableParticleValue != null)
{
endRepeatableParticle(parentPosition, position.qName, position.particle, parentPosition.particle);
}
}
+ pop();
continue;
}
}
@@ -424,10 +415,10 @@
if(newPosition == null)
{
if(!position.ended)
- endParticle(position, stack.peek1());
+ endParticle(position);
- Position poped = pop();
- if(!poped.particle.isRepeatable() && stack.peek().isElement())
+ pop();
+ if(!position.particle.isRepeatable() && stack.peek().isElement())
{
TermBinding t = groupPosition.getParticle().getTerm();
StringBuffer sb = new StringBuffer(250);
@@ -460,7 +451,7 @@
if(newPosition.getNext() != null && curParticle.isRepeatable())
{
- startRepeatableParticle(stack.peek1(), stack.peek1().o, startName, curParticle);
+ startRepeatableParticle(position, position.o, startName, curParticle);
}
}
else
@@ -658,7 +649,6 @@
int stackIndex = stack.size() - 2;
Position position;
Position parentPosition = stack.peek1();
- ParticleBinding parentParticle = null;
while(true)
{
if(parentPosition.isElement())
@@ -671,15 +661,13 @@
}
position = parentPosition;
-
- parentParticle = parentPosition.particle;
- if(parentParticle.isRepeatable())
+ if(position.particle.isRepeatable())
{
- parentPosition = stack.peek(stackIndex - 1);
- endParticle(position, parentPosition);
+ endParticle(position, stackIndex - 1);
ParticleHandler handler = getHandler(position.particle);
position.reset();
+ parentPosition = stack.peek(stackIndex - 1);
position.o = handler.startParticle(parentPosition.o, position.qName, position.particle, null, nsRegistry);
break;
@@ -691,7 +679,7 @@
break;
parentPosition = stack.peek(--stackIndex);
- endParticle(position, parentPosition);
+ endParticle(position, stackIndex);
}
/* if(!parentParticle.isRepeatable())
@@ -756,11 +744,14 @@
{
if(trace)
log.trace(" start repeatable (" + stack.size() + "): " + particle.getTerm());
+
RepeatableParticleHandler repeatableHandler = particle.getTerm().getRepeatableHandler();
// the way it is now it's never null
Object repeatableContainer = repeatableHandler.startRepeatableParticle(parent, startName, particle);
if(repeatableContainer != null)
{
+ if(parentPosition.repeatableParticleValue != null)
+ throw new IllegalStateException();
parentPosition.repeatableParticleValue = repeatableContainer;
parentPosition.repeatableHandler = repeatableHandler;
}
@@ -777,29 +768,44 @@
parentPosition.repeatableHandler = null;
}
- private void endParticle(Position position, Position parentPosition)
+ private void endParticle(Position position)
{
if(position.ended)
+ throw new JBossXBRuntimeException(position.particle.getTerm() + " has already been ended.");
+
+ ParticleHandler handler = position.handler;
+ Object o = handler.endParticle(position.o, position.qName, position.particle);
+
+ position.ended = true;
+ // model group should always have parent particle
+ //Position parentPosition = getNotSkippedParent();
+ Position parentPosition = stack.peek1();
+ if(parentPosition.o != null)
{
- throw new JBossXBRuntimeException(position.particle.getTerm() + " has already been ended.");
+ if(parentPosition.repeatableParticleValue == null)
+ setParent(handler, parentPosition.o, o, position.qName, position.particle, parentPosition.particle);
+ else
+ parentPosition.repeatableHandler.addTermValue(parentPosition.repeatableParticleValue, o, position.qName, position.particle, parentPosition.particle, handler);
}
+ }
+ private void endParticle(Position position, int parentIdex)
+ {
+ if(position.ended)
+ throw new JBossXBRuntimeException(position.particle.getTerm() + " has already been ended.");
+
ParticleHandler handler = position.handler;
Object o = handler.endParticle(position.o, position.qName, position.particle);
position.ended = true;
-
// model group should always have parent particle
+ Position parentPosition = getNotSkippedParent(parentIdex);
if(parentPosition.o != null)
{
- ParticleBinding parentParticle = getNotSkippedParent().particle;//item.particle;
- if(parentParticle == null)
- parentParticle = parentPosition.particle;
-
if(parentPosition.repeatableParticleValue == null)
- setParent(handler, parentPosition.o, o, position.qName, position.particle, parentParticle);
+ setParent(handler, parentPosition.o, o, position.qName, position.particle, parentPosition.particle);
else
- parentPosition.repeatableHandler.addTermValue(parentPosition.repeatableParticleValue, o, position.qName, position.particle, parentParticle, handler);
+ parentPosition.repeatableHandler.addTermValue(parentPosition.repeatableParticleValue, o, position.qName, position.particle, parentPosition.particle, handler);
}
}
@@ -900,7 +906,20 @@
}
return null;
}
-
+
+ private Position getNotSkippedParent(int i)
+ {
+ Position position = null;
+ while(i >= 0)
+ {
+ position = stack.peek(i--);
+ ParticleBinding particle = position.particle;
+ if(!particle.getTerm().isSkip() || position.repeatableParticleValue != null)
+ return position;
+ }
+ return null;
+ }
+
private void endElement()
{
Position position = stack.peek();
@@ -1171,7 +1190,7 @@
{
ctx.parent = parent;
ctx.particle = particle;
- ctx.parentParticle = parentParticle;
+ ctx.parentParticle = getNotSkippedParent().particle;
o = beforeSetParent.beforeSetParent(o, ctx);
ctx.clear();
}
@@ -1187,31 +1206,24 @@
position.parentType = parentType;
stack.push(position);
if(trace)
- {
- if(particle != null)
- log.trace("pushed " + ((ElementBinding)particle.getTerm()).getQName() + "=" + o);
- else
- log.trace("pushed null particle, o=" + o);
- }
+ log.trace("pushed[" + (stack.size() - 1) + "] " + particle.getTerm().getQName() + "=" + o);
}
private void push(ModelGroupBinding.ModelGroupPosition position, Object o, ParticleHandler handler, TypeBinding parentType)
{
- //StackItem item = new StackItem(qName, cursor);
- //ElementPosition position = cursor;
position.o = o;
position.handler = handler;
position.parentType = parentType;
stack.push(position);
if(trace)
- log.trace("pushed position " + position + ", o=" + o);
+ log.trace("pushed[" + (stack.size() - 1) + "] " + position + ", o=" + o);
}
private Position pop()
{
Position position = stack.pop();
if(trace)
- log.trace("poped " + position.particle.getTerm());
+ log.trace("poped[" + stack.size() + "] " + position.particle.getTerm());
return position;
}
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/TermBinding.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/TermBinding.java 2009-11-24 13:47:54 UTC (rev 3777)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/TermBinding.java 2009-11-24 22:48:12 UTC (rev 3778)
@@ -21,6 +21,8 @@
*/
package org.jboss.xb.binding.sunday.unmarshalling;
+import javax.xml.namespace.QName;
+
import org.jboss.xb.binding.metadata.ClassMetaData;
import org.jboss.xb.binding.metadata.PropertyMetaData;
import org.jboss.xb.binding.metadata.MapEntryMetaData;
@@ -36,7 +38,8 @@
public abstract class TermBinding
{
protected SchemaBinding schema;
-
+ protected QName qName;
+
protected ClassMetaData classMetaData;
protected PropertyMetaData propertyMetaData;
protected MapEntryMetaData mapEntryMetaData;
@@ -60,7 +63,16 @@
{
}
-
+ public QName getQName()
+ {
+ return this.qName;
+ }
+
+ public void setQName(QName name)
+ {
+ qName = name;
+ }
+
public ClassMetaData getClassMetaData()
{
return classMetaData;
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 2009-11-24 13:47:54 UTC (rev 3777)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/binding/sunday/unmarshalling/WildcardBinding.java 2009-11-24 22:48:12 UTC (rev 3778)
@@ -41,7 +41,6 @@
private static final short PC_SKIP = 2;
private static final short PC_STRICT = 1;
- private QName qName;
private SchemaBindingResolver schemaResolver;
private short pc = PC_STRICT;
@@ -56,16 +55,6 @@
super(schema);
}
- public QName getQName()
- {
- return qName;
- }
-
- public void setQName(QName qName)
- {
- this.qName = qName;
- }
-
public SchemaBindingResolver getSchemaResolver()
{
return schemaResolver;
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2009-11-24 13:47:54 UTC (rev 3777)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2009-11-24 22:48:12 UTC (rev 3778)
@@ -1355,7 +1355,7 @@
XmlType propertyXmlType = null;
JBossXmlModelGroup propertyXmlModelGroup = null;
// Setup any new model
- if (propertyType.isCollection())
+ if (propertyType.isCollection() || propertyType.isArray())
{
if (trace)
log.trace("Property " + property.getName() + " is a collection");
@@ -1439,7 +1439,10 @@
choice.setHandler(BuilderParticleHandler.INSTANCE);
ParticleBinding particleBinding = new ParticleBinding(choice);
particleBinding.setMinOccurs(0);
- particleBinding.setMaxOccursUnbounded(true);
+ // WARN normally maxOccursUnbounded should be set to true in this case
+ // but I make an exception for case like in org.jboss.test.xb.builder.repeatableterms.support.Sequence
+ if(propertyType.isCollection() || propertyType.isArray())
+ particleBinding.setMaxOccursUnbounded(true);
localModel.addParticle(particleBinding);
localModel = choice;
@@ -1825,62 +1828,72 @@
}
TypeInfo groupType = property.getType();
- if(groupType.isCollection())
+ boolean repeatable = false;
+ if(groupType.isCollection() || groupType.isArray())
+ {
groupType = ((ClassInfo)groupType).getComponentType();
+ repeatable = true;
+ }
if(createGroup)
{
boolean propOrderMissing = annotation.propOrder().length == 1 && annotation.propOrder()[0].equals("") || annotation.particles().length > 0;
- group = createModelGroup(annotation.kind(), groupType, propOrderMissing, annotation.propOrder());
- if (groupName != null)
+
+ if(annotation.particles().length == 0)
{
- group.setQName(groupName);
- schemaBinding.addGroup(group.getQName(), group);
- }
- }
-
- parentGroup.addParticle(new ParticleBinding(group, 0, 1, property.getType().isCollection()));
-
- if(annotation.particles().length == 0)
- {
- if(createGroup)
- {
- group.setSkip(Boolean.FALSE);
-
// handler for the model group members
BeanInfo groupBeanInfo = JBossXBBuilder.configuration.getBeanInfo(groupType);
BeanAdapterFactory propBeanAdapterFactory = createAdapterFactory(DefaultBeanAdapterBuilder.class, groupBeanInfo, null);
BeanHandler propHandler = new GroupBeanHandler(groupBeanInfo.getName(), propBeanAdapterFactory);
- group.setHandler(propHandler);
String[] memberOrder = annotation.propOrder();
if (memberOrder.length == 0 || memberOrder[0].length() == 0)
{
List<String> propNames = new ArrayList<String>();
for (PropertyInfo prop : groupBeanInfo.getProperties())
+ {
+ if ("class".equals(prop.getName()))
+ continue;
propNames.add(prop.getName());
+ }
memberOrder = propNames.toArray(new String[propNames.size()]);
}
if (trace)
log.trace("Property order for " + annotation.kind() + " property " + property.getName() + ": " + Arrays.asList(memberOrder));
+ group = createModelGroup(annotation.kind(), groupType, memberOrder.length > 1 && propOrderMissing, annotation.propOrder());
+ group.setSkip(Boolean.FALSE);
+ group.setHandler(propHandler);
+
// bind model group members
for (String memberPropName : memberOrder)
{
- if ("class".equals(memberPropName))
- continue;
-
PropertyInfo memberProp = groupBeanInfo.getProperty(memberPropName);
push(groupType, memberPropName);
bindProperty(memberProp, group, propBeanAdapterFactory, memberOrder, false);
pop();
}
}
-
+ else
+ group = createModelGroup(annotation.kind(), groupType, propOrderMissing, annotation.propOrder());
+
+ if (groupName != null)
+ {
+ group.setQName(groupName);
+ schemaBinding.addGroup(group.getQName(), group);
+ }
+
+ if(property.getType().isArray())
+ group.setRepeatableHandler(new ArrayWrapperRepeatableParticleHandler(beanAdapterFactory));
+ }
+
+ parentGroup.addParticle(new ParticleBinding(group, 0, 1, repeatable));
+
+ if(annotation.particles().length == 0)
+ {
if(group.getQName() == null)
throw new JBossXBRuntimeException("To be bound a group must have a non-null QName. Bean " + property.getBeanInfo().getName() + ", property=" + property.getName());
-
beanAdapterFactory.addProperty(group.getQName(), propertyHandler);
}
else
@@ -1914,7 +1927,7 @@
typeBinding.pushInterceptor(memberQName, ChildCollectionInterceptor.SINGLETON);
}
}
-
+
defaultNamespace = overridenDefaultNamespace;
}
@@ -1952,7 +1965,7 @@
wrapperElement.setSkip(Boolean.TRUE);
particle = new ParticleBinding(wrapperElement, annotation.required() ? 1 : 0, 1, propertyType.isCollection() || propertyType.isArray());
parentModel.addParticle(particle);
-
+
if(propertyType.isArray())
wrapperElement.setRepeatableHandler(new ArrayWrapperRepeatableParticleHandler(beanAdapterFactory));
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ArrayWrapperRepeatableParticleHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ArrayWrapperRepeatableParticleHandler.java 2009-11-24 13:47:54 UTC (rev 3777)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ArrayWrapperRepeatableParticleHandler.java 2009-11-24 22:48:12 UTC (rev 3778)
@@ -80,28 +80,31 @@
if(trace)
log.trace("endRepeatableParticle " + elementName);
- AbstractPropertyHandler propertyHandler = beanAdapterFactory.getPropertyHandler(elementName);
+ QName qName = particle.getTerm().getQName();
+ if(qName == null)
+ qName = elementName;
+ AbstractPropertyHandler propertyHandler = beanAdapterFactory.getPropertyHandler(qName);
if (propertyHandler == null)
{
AbstractPropertyHandler wildcardHandler = beanAdapterFactory.getWildcardHandler();
if (wildcardHandler != null && o != null)
{
o = toArray((List<Object>) o, (ArrayInfo) wildcardHandler.getPropertyType());
- wildcardHandler.doHandle(parent, o, elementName);
+ wildcardHandler.doHandle(parent, o, qName);
return;
}
if (particle.getTerm().getSchema().isStrictSchema())
- throw new RuntimeException("QName " + elementName + " unknown property parent=" + BuilderUtil.toDebugString(parent) + " child=" + BuilderUtil.toDebugString(o) + " available=" + beanAdapterFactory.getAvailable());
+ throw new RuntimeException("QName " + qName + " unknown property parent=" + BuilderUtil.toDebugString(parent) + " child=" + BuilderUtil.toDebugString(o) + " available=" + beanAdapterFactory.getAvailable());
if (trace)
- log.trace("QName " + elementName + " unknown property parent=" + BuilderUtil.toDebugString(parent) + " child=" + BuilderUtil.toDebugString(o));
+ log.trace("QName " + qName + " unknown property parent=" + BuilderUtil.toDebugString(parent) + " child=" + BuilderUtil.toDebugString(o));
return;
}
o = toArray((List<Object>) o, (ArrayInfo) propertyHandler.getPropertyType());
- propertyHandler.doHandle(parent, o, elementName);
+ propertyHandler.doHandle(parent, o, qName);
}
public Object startRepeatableParticle(Object parent, QName startName, ParticleBinding particle)
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Choice.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Choice.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Choice.java 2009-11-24 22:48:12 UTC (rev 3778)
@@ -0,0 +1,62 @@
+/*
+* 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.xb.builder.repeatableterms.support;
+
+import javax.xml.bind.annotation.XmlElement;
+
+import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.xb.annotations.JBossXmlModelGroup;
+
+/**
+ * A Choice.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at JBossXmlModelGroup(name="choiceChoice", kind=JBossXmlConstants.MODEL_GROUP_CHOICE)
+public class Choice
+{
+ private String[] choiceChoice1;
+ private String[] choiceChoice2;
+
+ @XmlElement(name="choiceChoice1")
+ public String[] getChoiceChoice1()
+ {
+ return choiceChoice1;
+ }
+
+ public void setChoiceChoice1(String[] choiceChoice1)
+ {
+ this.choiceChoice1 = choiceChoice1;
+ }
+
+ @XmlElement(name="choiceChoice2")
+ public String[] getChoiceChoice2()
+ {
+ return choiceChoice2;
+ }
+
+ public void setChoiceChoice2(String[] choiceChoice2)
+ {
+ this.choiceChoice2 = choiceChoice2;
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Sequence.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Sequence.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Sequence.java 2009-11-24 22:48:12 UTC (rev 3778)
@@ -0,0 +1,54 @@
+/*
+* 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.xb.builder.repeatableterms.support;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElements;
+
+import org.jboss.xb.annotations.JBossXmlConstants;
+import org.jboss.xb.annotations.JBossXmlModelGroup;
+
+/**
+ * A Sequence.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at JBossXmlModelGroup(name="sequenceChoice", kind=JBossXmlConstants.MODEL_GROUP_SEQUENCE)
+public class Sequence
+{
+ private String choice;
+
+ @XmlElements({
+ @XmlElement(name="sequenceChoice1"),
+ @XmlElement(name="sequenceChoice2")
+ })
+ public String getChoice()
+ {
+ return choice;
+ }
+
+ public void setChoice(String choice)
+ {
+ this.choice = choice;
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Top.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Top.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/support/Top.java 2009-11-24 22:48:12 UTC (rev 3778)
@@ -0,0 +1,73 @@
+/*
+* 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.xb.builder.repeatableterms.support;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.XmlType;
+
+
+/**
+ * A Top.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement
+ at XmlType(propOrder={"items", "sequences", "choices"})
+public class Top
+{
+ public String[] items;
+ public Sequence[] sequences;
+ public Choice[] choices;
+
+ @XmlElement(name="item")
+ public String[] getItems()
+ {
+ return items;
+ }
+
+ public void setItems(String[] items)
+ {
+ this.items = items;
+ }
+
+ public Sequence[] getSequences()
+ {
+ return sequences;
+ }
+
+ public void setSequences(Sequence[] sequences)
+ {
+ this.sequences = sequences;
+ }
+
+ public Choice[] getChoices()
+ {
+ return choices;
+ }
+
+ public void setChoices(Choice[] choices)
+ {
+ this.choices = choices;
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/test/RepeatableTermsUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/test/RepeatableTermsUnitTestCase.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/repeatableterms/test/RepeatableTermsUnitTestCase.java 2009-11-24 22:48:12 UTC (rev 3778)
@@ -0,0 +1,131 @@
+/*
+* 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.xb.builder.repeatableterms.test;
+
+import java.util.Collection;
+import java.util.Iterator;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xb.builder.repeatableterms.support.Choice;
+import org.jboss.test.xb.builder.repeatableterms.support.Sequence;
+import org.jboss.test.xb.builder.repeatableterms.support.Top;
+import org.jboss.xb.binding.sunday.unmarshalling.ChoiceBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ElementBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ModelGroupBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.ParticleBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.SchemaBinding;
+import org.jboss.xb.binding.sunday.unmarshalling.TermBinding;
+import org.jboss.xb.builder.JBossXBBuilder;
+
+/**
+ * A RepeatableTermsUnitTestCase.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class RepeatableTermsUnitTestCase extends AbstractBuilderTest
+{
+ public RepeatableTermsUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testUnmarshalling() throws Exception
+ {
+ Top top = unmarshalObject(Top.class);
+
+ String[] items = top.getItems();
+ assertNotNull(items);
+ assertEquals(3, items.length);
+ for(int i = 0; i < items.length; ++i)
+ assertEquals("item" + (i + 1), items[i]);
+
+ Sequence[] sequences = top.getSequences();
+ assertNotNull(sequences);
+
+ Choice[] choices = top.getChoices();
+ assertNotNull(choices);
+ }
+
+ public void testBinding() throws Exception
+ {
+ SchemaBinding schema = JBossXBBuilder.build(Top.class, true);
+
+ ElementBinding top = schema.getElement(new QName("top"));
+ assertNotNull(top);
+ ModelGroupBinding topSequence = (ModelGroupBinding) top.getType().getParticle().getTerm();
+ Collection<ParticleBinding> particles = topSequence.getParticles();
+ assertEquals(3, particles.size());
+
+ Iterator<ParticleBinding> i = particles.iterator();
+ while(i.hasNext())
+ {
+ ParticleBinding particle = i.next();
+ assertTrue(particle.getMaxOccursUnbounded());
+ TermBinding term = particle.getTerm();
+ if(term.isElement())
+ {
+ assertEquals(new QName("item"), ((ElementBinding)term).getQName());
+ }
+ else if(term instanceof ChoiceBinding)
+ {
+ ChoiceBinding choice = (ChoiceBinding) term;
+ Collection<ParticleBinding> choices = choice.getParticles();
+ assertEquals(2, choices.size());
+ Iterator<ParticleBinding> ci = choices.iterator();
+ while(ci.hasNext())
+ {
+ ParticleBinding cp = ci.next();
+ assertTrue(cp.getMaxOccursUnbounded());
+ TermBinding ct = cp.getTerm();
+ assertTrue(ct.isElement());
+ QName name = ((ElementBinding)ct).getQName();
+ assertTrue(name.equals(new QName("choiceChoice1")) || name.equals(new QName("choiceChoice2")));
+ }
+ }
+ else // sequence or unordered sequence
+ {
+ ModelGroupBinding seq = (ModelGroupBinding)term;
+ Collection<ParticleBinding> seqParticles = seq.getParticles();
+ assertEquals(1, seqParticles.size());
+ ParticleBinding choiceP = seqParticles.iterator().next();
+ assertFalse(choiceP.getMaxOccursUnbounded());
+ TermBinding choice = choiceP.getTerm();
+ assertTrue(choice instanceof ChoiceBinding);
+ Collection<ParticleBinding> choices = ((ChoiceBinding)choice).getParticles();
+ assertEquals(2, choices.size());
+ Iterator<ParticleBinding> ci = choices.iterator();
+ while(ci.hasNext())
+ {
+ ParticleBinding cp = ci.next();
+ assertFalse(cp.getMaxOccursUnbounded());
+ TermBinding ct = cp.getTerm();
+ assertTrue(ct.isElement());
+ QName name = ((ElementBinding)ct).getQName();
+ assertTrue(name.equals(new QName("sequenceChoice1")) || name.equals(new QName("sequenceChoice2")));
+ }
+ }
+ }
+ }
+}
Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/repeatableterms/test/RepeatableTerms_testUnmarshalling.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/repeatableterms/test/RepeatableTerms_testUnmarshalling.xml (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/repeatableterms/test/RepeatableTerms_testUnmarshalling.xml 2009-11-24 22:48:12 UTC (rev 3778)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<top>
+ <item>item1</item>
+ <item>item2</item>
+ <item>item3</item>
+
+ <sequenceChoice1>sequenceChoice1_1</sequenceChoice1>
+ <sequenceChoice2>sequenceChoice2_1</sequenceChoice2>
+ <sequenceChoice1>sequenceChoice1_2</sequenceChoice1>
+ <sequenceChoice1>sequenceChoice1_3</sequenceChoice1>
+ <sequenceChoice2>sequenceChoice2_2</sequenceChoice2>
+
+ <choiceChoice1>choiceChoice1_1</choiceChoice1>
+ <choiceChoice1>choiceChoice1_2</choiceChoice1>
+
+ <choiceChoice2>choiceChoice2_1</choiceChoice2>
+ <choiceChoice2>choiceChoice2_2</choiceChoice2>
+
+ <choiceChoice1>choiceChoice1_3</choiceChoice1>
+ <choiceChoice1>choiceChoice1_4</choiceChoice1>
+</top>
More information about the jboss-svn-commits
mailing list