[jboss-svn-commits] JBoss Common SVN: r2452 - in jbossxb-builder/trunk/src/main/java/org/jboss/xb: builder and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Jul 23 09:12:31 EDT 2007
Author: alex.loubyansky at jboss.com
Date: 2007-07-23 09:12:31 -0400 (Mon, 23 Jul 2007)
New Revision: 2452
Modified:
jbossxb-builder/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlModelGroup.java
jbossxb-builder/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
Log:
extended JBossXmlModelGroup to bind type parameter of a collection to a repeatable choice
Modified: jbossxb-builder/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlModelGroup.java
===================================================================
--- jbossxb-builder/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlModelGroup.java 2007-07-20 08:19:39 UTC (rev 2451)
+++ jbossxb-builder/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlModelGroup.java 2007-07-23 13:12:31 UTC (rev 2452)
@@ -26,6 +26,8 @@
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
+import javax.xml.bind.annotation.XmlElement;
+
/**
* JBossXmlModelGroup binds a Java class to a model group in the schema.
*
@@ -38,7 +40,27 @@
{
String kind() default JBossXmlConstants.MODEL_GROUP_SEQUENCE;
- String name();
+ String name() default JBossXmlConstants.DEFAULT;
+ /**
+ * Used when a model group is bound to a Java class propeties
+ * of which are bound to model group particles
+ *
+ * @return
+ */
String[] propOrder() default {""};
+
+ /**
+ * Used when a model group is bound to a class hierarchy,
+ * i.e. each subclass of the class annotated with JBossXmlModelGroup
+ * is bound to particle of the model group.
+ * Note: most likely the model group is going to be a choice (?)
+ */
+ Particle[] particles() default {};
+
+ @interface Particle
+ {
+ XmlElement element();
+ Class type();
+ }
}
Modified: jbossxb-builder/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
===================================================================
--- jbossxb-builder/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2007-07-20 08:19:39 UTC (rev 2451)
+++ jbossxb-builder/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2007-07-23 13:12:31 UTC (rev 2452)
@@ -945,6 +945,58 @@
typeParticle.setMinOccurs(1);
typeParticle.setMaxOccurs(1);
typeBinding.setParticle(typeParticle);
+
+ if(typeInfo.isCollection())
+ {
+ // if the type is a parameterized collection then
+ // bind its members as items
+ TypeInfo gs = typeInfo.getGenericSuperclass();
+ if (gs instanceof ParameterizedClassInfo)
+ {
+ ParameterizedClassInfo pti = (ParameterizedClassInfo) gs;
+ TypeInfo memberBaseType = pti.getActualTypeArguments()[0];
+
+ JBossXmlModelGroup xmlModelGroup = ((ClassInfo) memberBaseType)
+ .getUnderlyingAnnotation(JBossXmlModelGroup.class);
+ if (xmlModelGroup != null && xmlModelGroup.particles().length > 0)
+ {
+ if(trace)
+ log.trace("Item base type for " + typeInfo.getName() + " is " + memberBaseType.getName() + " and bound to repeatable choice");
+
+ // it's choice by default based on the idea that the
+ // type parameter is a base class for items
+ ModelGroupBinding choiceGroup = new ChoiceBinding(schemaBinding);
+ ParticleBinding choiceParticle = new ParticleBinding(choiceGroup, 0, 1, true);
+ model.addParticle(choiceParticle);
+
+ for(JBossXmlModelGroup.Particle member : xmlModelGroup.particles())
+ {
+ XmlElement element = member.element();
+ QName memberQName = generateXmlName(element.name(), XmlNsForm.QUALIFIED, element.namespace(), null);
+ TypeInfo memberTypeInfo = typeInfo.getTypeInfoFactory().getTypeInfo(member.type());
+
+ boolean isCol = false;
+ if(memberTypeInfo.isCollection())
+ {
+ // TODO here we should properly identify the type of the item (based on a testcase)
+ memberTypeInfo = pti.getActualTypeArguments()[0];
+ isCol = true;
+ }
+
+ TypeBinding memberTypeBinding = resolveTypeBinding(memberTypeInfo);
+ ElementBinding memberElement = createElementBinding(memberTypeInfo, memberTypeBinding, memberQName, false);
+ memberElement.setNillable(true);
+ ParticleBinding memberParticle = new ParticleBinding(memberElement, 0, 1, isCol);
+ choiceGroup.addParticle(memberParticle);
+
+ typeBinding.pushInterceptor(memberQName, ChildCollectionInterceptor.SINGLETON);
+ }
+
+ if(trace)
+ log.trace("choices for " + typeBinding.getQName() + ": " + choiceGroup.getParticles());
+ }
+ }
+ }
// Determine the wildcard handler
AbstractPropertyHandler wildcardHandler = null;
@@ -1007,8 +1059,9 @@
log.trace("Property " + property.getName() + " is bound to " + xmlModelGroup.kind());
localModel = new SequenceBinding(schemaBinding);
- if(xmlModelGroup.name() != null)
+ if(!JBossXmlConstants.DEFAULT.equals(xmlModelGroup.name()))
{
+ // TODO what if it doesn't have a name? should an artificial one be created?
localModel.setQName(new QName(name));
}
More information about the jboss-svn-commits
mailing list