[jboss-svn-commits] JBoss Common SVN: r2486 - jbossxb-builder/trunk/src/main/java/org/jboss/xb/builder.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Aug 14 10:11:57 EDT 2007


Author: alex.loubyansky at jboss.com
Date: 2007-08-14 10:11:57 -0400 (Tue, 14 Aug 2007)
New Revision: 2486

Modified:
   jbossxb-builder/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
Log:
support for @XmlElementWrapper

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-08-13 13:35:32 UTC (rev 2485)
+++ jbossxb-builder/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java	2007-08-14 14:11:57 UTC (rev 2486)
@@ -41,6 +41,7 @@
 import javax.xml.bind.annotation.XmlAnyElement;
 import javax.xml.bind.annotation.XmlAttribute;
 import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlElementWrapper;
 import javax.xml.bind.annotation.XmlElements;
 import javax.xml.bind.annotation.XmlEnum;
 import javax.xml.bind.annotation.XmlNsForm;
@@ -1430,14 +1431,59 @@
                   propertyHandler = new PropertyHandler(property, localPropertyType);
                }
 
-               TypeBinding elementTypeBinding = resolveTypeBinding(localPropertyType);
-               ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, qName, false);
-               elementBinding.setNillable(nillable);
-               
-               // Bind it to the model
-               ParticleBinding particle = new ParticleBinding(elementBinding, 1, 1, isCol);
-               if (required == false)
-                  particle.setMinOccurs(0);
+               ParticleBinding particle;
+
+               if(propertyType.isCollection() && property.getUnderlyingAnnotation(XmlElementWrapper.class) != null)
+               {
+                  XmlElementWrapper wrapper = property.getUnderlyingAnnotation(XmlElementWrapper.class);
+                  String wrapperOverrideNamespace = wrapper.namespace();
+                  String wrapperOverrideName = wrapper.name();
+                  boolean wrapperNillable = wrapper.nillable();
+
+                  QName childQName = qName;
+                  qName = generateXmlName(property.getName(), elementForm, wrapperOverrideNamespace, wrapperOverrideName);
+
+                  boolean typeIsNew = !typeCache.containsKey(localPropertyType);
+                  TypeBinding elementTypeBinding = resolveTypeBinding(localPropertyType);
+
+                  ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, qName, false);
+                  elementBinding.setNillable(wrapperNillable);
+                  particle = new ParticleBinding(elementBinding, 1, 1, false);
+
+                  if(typeIsNew)
+                  {
+                     // component stuff
+                     ClassInfo typeArg = (ClassInfo) findComponentType(property);
+                     if (typeArg == null)
+                     {
+                        throw new IllegalStateException("Failed to determine component type for collection "
+                              + propertyType.getName());
+                     }
+                     TypeInfo childType = JBossXBBuilder.configuration.getTypeInfo(typeArg.getType());
+
+                     TypeBinding childTypeBinding = resolveTypeBinding(childType);
+                     ElementBinding childElement = createElementBinding(childType, childTypeBinding, childQName, false);
+
+                     // Bind it to the model
+                     ParticleBinding childParticle = new ParticleBinding(childElement, 0, 1, true);
+                     elementBinding.getType().addParticle(childParticle);
+
+                     DefaultElementInterceptor interceptor = ChildCollectionInterceptor.SINGLETON;
+                     elementBinding.getType().pushInterceptor(childQName, interceptor);
+                  }
+               }
+               else
+               {
+                  TypeBinding elementTypeBinding = resolveTypeBinding(localPropertyType);
+                  ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, qName, false);
+                  elementBinding.setNillable(nillable);
+                  
+                  // Bind it to the model
+                  particle = new ParticleBinding(elementBinding, 1, 1, isCol);
+                  if (required == false)
+                     particle.setMinOccurs(0);
+               }
+
                targetGroup.addParticle(particle);
 
                beanAdapterFactory.addProperty(qName, propertyHandler);




More information about the jboss-svn-commits mailing list