[jboss-svn-commits] JBoss Common SVN: r2703 - in jbossxb/trunk/src: main/java/org/jboss/xb/builder/runtime and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Fri Jan 25 07:34:05 EST 2008
Author: alex.loubyansky at jboss.com
Date: 2008-01-25 07:34:04 -0500 (Fri, 25 Jan 2008)
New Revision: 2703
Modified:
jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ChildWildcardHandler.java
jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/MapPropertyHandler.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/AbstractMapMetaData.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/MapEntry.java
Log:
JBXB-117 fixes and testcase for the mc
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2008-01-22 23:37:49 UTC (rev 2702)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2008-01-25 12:34:04 UTC (rev 2703)
@@ -1078,6 +1078,9 @@
ParticleBinding particle = new ParticleBinding(elementBinding, child.minOccurs(), child.maxOccurs(), child.unbounded());
model.addParticle(particle);
+ if(childType.isMap())
+ bindMapProperty(null, (ClassInfo) childType, elementTypeBinding.getQName(), (ModelGroupBinding) elementTypeBinding.getParticle().getTerm());
+
DefaultElementInterceptor interceptor = null;
if (typeInfo.isCollection())
interceptor = ChildCollectionInterceptor.SINGLETON;
@@ -1443,28 +1446,11 @@
// the wrapping element is ignored in this case
XmlElementWrapper xmlWrapper = property.getUnderlyingAnnotation(XmlElementWrapper.class);
if (xmlWrapper != null)
- {
+ {
String wrapperNamespace = xmlWrapper.namespace();
String wrapperName = xmlWrapper.name();
- boolean wrapperNillable = xmlWrapper.nillable();
-
QName wrapperQName = generateXmlName(property.getName(), elementForm, wrapperNamespace, wrapperName);
-
- TypeBinding wrapperType = new TypeBinding();
- SequenceBinding seq = new SequenceBinding(schemaBinding);
- seq.setHandler(BuilderParticleHandler.INSTANCE);
- ParticleBinding particle = new ParticleBinding(seq);
- wrapperType.setParticle(particle);
- wrapperType.setHandler(new DefaultElementHandler());
-
- ElementBinding wrapperElement = createElementBinding(propertyType, wrapperType, wrapperQName, false);
- wrapperElement.setNillable(wrapperNillable);
- wrapperElement.setSkip(Boolean.TRUE);
- particle = new ParticleBinding(wrapperElement, 1, 1, false);
- localModel.addParticle(particle);
-
- localModel = seq;
-
+ localModel = bindXmlElementWrapper(propertyType, localModel, xmlWrapper.nillable(), wrapperQName);
if (trace)
log.trace("Added property " + wrapperQName + " for type=" + property.getBeanInfo().getName() + " property="
+ property.getName() + " as a wrapper element");
@@ -1592,11 +1578,14 @@
particle.setMinOccurs(0);
childModel.addParticle(particle);
+ if(childType.isMap())
+ bindMapProperty(property, (ClassInfo) childType, childName, (ModelGroupBinding) childTypeBinding.getParticle().getTerm());
+
DefaultElementInterceptor interceptor = new PropertyInterceptor(property, propertyType);
elementTypeBinding.pushInterceptor(childName, interceptor);
if (trace)
log.trace("Added interceptor " + childName + " for type=" + property.getBeanInfo().getName()
- + " property=" + property.getName() + " interceptor=" + interceptor);
+ + " property=" + property.getName() + " interceptor=" + interceptor + " " + childType.getName());
beanAdapterFactory.addProperty(propertyQName, new NoopPropertyHandler(property, propertyType));
@@ -1685,163 +1674,48 @@
localPropertyType = findActualType((ClassInfo) localPropertyType, parameterizedType,
java.util.Collection.class, 0);
}
- else if (propertyType.isMap() /*&& ((ClassInfo) propertyType).getUnderlyingAnnotation(XmlType.class) == null*/)
+ else if (localPropertyType.isMap())
{
- JBossXmlMapEntry entryElement = property.getUnderlyingAnnotation(JBossXmlMapEntry.class);
- if(entryElement == null)
- entryElement = ((ClassInfo)localPropertyType).getUnderlyingAnnotation(JBossXmlMapEntry.class);
- JBossXmlMapKeyElement keyElement = property.getUnderlyingAnnotation(JBossXmlMapKeyElement.class);
- if(keyElement == null)
- keyElement = ((ClassInfo)localPropertyType).getUnderlyingAnnotation(JBossXmlMapKeyElement.class);
- JBossXmlMapKeyAttribute keyAttribute = property.getUnderlyingAnnotation(JBossXmlMapKeyAttribute.class);
- if(keyAttribute == null)
- keyAttribute = ((ClassInfo)localPropertyType).getUnderlyingAnnotation(JBossXmlMapKeyAttribute.class);
-
- if(keyElement != null || keyAttribute != null)
+ TypeBinding wrapperType = null;
+ if(elements.length > 1)
{
- // further assuming the map is bound
+ wrapperType = resolveTypeBinding(localPropertyType);
+ ElementBinding elementBinding = createElementBinding(localPropertyType, wrapperType, propertyQName, false);
+ elementBinding.setNillable(nillable);
+ elementBinding.setValueAdapter(valueAdapter);
- JBossXmlMapValueElement valueElement = property.getUnderlyingAnnotation(JBossXmlMapValueElement.class);
- if(valueElement == null)
- valueElement = ((ClassInfo)localPropertyType).getUnderlyingAnnotation(JBossXmlMapValueElement.class);
- JBossXmlMapValueAttribute valueAttribute = property.getUnderlyingAnnotation(JBossXmlMapValueAttribute.class);
- if(valueAttribute == null)
- valueAttribute = ((ClassInfo)localPropertyType).getUnderlyingAnnotation(JBossXmlMapValueAttribute.class);
+ // Bind it to the model
+ ParticleBinding particle = new ParticleBinding(elementBinding, 0, 1, isCol);
+ if (required == false)
+ particle.setMinOccurs(0);
- TypeInfo keyType = ((ClassInfo)localPropertyType).getKeyType();
- TypeInfo valueType = ((ClassInfo)localPropertyType).getValueType();
-
- // entry handler
- BeanAdapterFactory entryAdapterFactory = null;
- BeanInfo entryInfo = JBossXBBuilder.configuration.getBeanInfo(DefaultMapEntry.class);
- entryAdapterFactory = createAdapterFactory(DefaultBeanAdapterBuilder.class, entryInfo, null);
- BeanHandler entryHandler = new BeanHandler(entryInfo.getName(), entryAdapterFactory);
-
- TypeBinding entryType = null;
- TypeInfo entryTypeInfo = null;
-
- // bind the entry element if present
- if(entryElement != null && !JBossXmlConstants.DEFAULT.equals(entryElement.name()))
+ targetGroup.addParticle(particle);
+ targetGroup = (ModelGroupBinding) wrapperType.getParticle().getTerm();
+ }
+
+ QName boundQName = bindMapProperty(property, (ClassInfo) localPropertyType, propertyQName, targetGroup);
+ if(boundQName != null)
+ {
+ if(wrapperType != null)
{
- String ns = entryElement.namespace();
- if(JBossXmlConstants.DEFAULT.equals(ns))
- ns = defaultNamespace;
- QName entryName = new QName(ns, entryElement.name());
-
- entryType = new TypeBinding();
- entryType.setSchemaBinding(schemaBinding);
- entryType.setHandler(entryHandler);
-
- entryTypeInfo = JBossXBBuilder.configuration.getTypeInfo(DefaultMapEntry.class);
- ElementBinding entryElementBinding = createElementBinding(entryTypeInfo, entryType, entryName, false);
- ParticleBinding entryParticle = new ParticleBinding(entryElementBinding, 0, -1, true);
- targetGroup.addParticle(entryParticle);
-
- propertyQName = entryName;
-
- if(keyAttribute != null)
+ BeanAdapterFactory wrapperBeanFactory = ((BeanHandler)wrapperType.getHandler()).getBeanAdapterFactory();
+ Map<QName, AbstractPropertyHandler> properties = wrapperBeanFactory.getProperties();
+ if(!properties.containsKey(boundQName))
{
- TypeBinding attributeType = resolveTypeBinding(keyType);
- AttributeHandler attributeHandler = new PropertyHandler(entryInfo.getProperty("key"), keyType);
- String attrNs = keyAttribute.namespace();
- if(JBossXmlConstants.DEFAULT.equals(attrNs))
- attrNs = defaultNamespace;
- AttributeBinding keyBinding = new AttributeBinding(schemaBinding, new QName(attrNs, keyAttribute.name()), attributeType, attributeHandler);
- keyBinding.setRequired(true);
- entryType.addAttribute(keyBinding);
+ propertyHandler = new MapPropertyHandler(JBossXBBuilder.configuration, property, localPropertyType, true);
+ wrapperBeanFactory.addProperty(boundQName, propertyHandler);
}
-
- if(valueAttribute != null)
- {
- TypeBinding attributeType = resolveTypeBinding(valueType);
- AttributeHandler attributeHandler = new PropertyHandler(entryInfo.getProperty("value"), valueType);
- String valueNs = valueAttribute.namespace();
- if(JBossXmlConstants.DEFAULT.equals(valueNs))
- valueNs = defaultNamespace;
- AttributeBinding valueBinding = new AttributeBinding(schemaBinding, new QName(valueNs, valueAttribute.name()), attributeType, attributeHandler);
- valueBinding.setRequired(true);
- entryType.addAttribute(valueBinding);
-
- propertyHandler = new MapPropertyHandler(JBossXBBuilder.configuration, property, localPropertyType);
- }
- else if(valueElement == null)
- {
- CharactersHandler charactersHandler = new ValueHandler(entryInfo.getProperty("value"), valueType);
- entryType.setSimpleType(charactersHandler);
- }
+ propertyHandler = new PropertyHandler(property, localPropertyType);
}
-
- SequenceBinding keyValueSequence = null;
- if(keyElement != null)
+ else
{
- keyValueSequence = new SequenceBinding(schemaBinding);
- if(entryType == null)
- {
- keyValueSequence.setSkip(Boolean.FALSE);
- keyValueSequence.setQName(propertyQName);
- schemaBinding.addGroup(keyValueSequence.getQName(), keyValueSequence);
- ParticleBinding keyValueParticle = new ParticleBinding(keyValueSequence, 0, -1, true);
- targetGroup.addParticle(keyValueParticle);
- keyValueSequence.setHandler(entryHandler);
- }
- else
- {
- ParticleBinding keyValueParticle = new ParticleBinding(keyValueSequence, 1, 1, false);
- entryType.setParticle(keyValueParticle);
- }
-
- // key element
- TypeBinding keyTypeBinding = resolveTypeBinding(keyType);
- String keyNs = keyElement.namespace();
- if(JBossXmlConstants.DEFAULT.equals(keyNs))
- keyNs = defaultNamespace;
- ElementBinding keyElementBinding = createElementBinding(keyType, keyTypeBinding, new QName(keyNs, keyElement.name()), false);
- ParticleBinding particle = new ParticleBinding(keyElementBinding, 1, 1, false);
- keyValueSequence.addParticle(particle);
- PropertyHandler keyHandler = new PropertyHandler(entryInfo.getProperty("key"), keyType);
- entryAdapterFactory.addProperty(keyElementBinding.getQName(), keyHandler);
+ propertyQName = boundQName;
+ propertyHandler = new MapPropertyHandler(JBossXBBuilder.configuration, property, localPropertyType, false);
}
-
- if(valueElement != null)
- {
- TypeBinding valueTypeBinding = resolveTypeBinding(valueType);
- String valueNs = valueElement.namespace();
- if(JBossXmlConstants.DEFAULT.equals(valueNs))
- valueNs = defaultNamespace;
- ElementBinding valueElementBinding = createElementBinding(valueType, valueTypeBinding, new QName(valueNs, valueElement.name()), false);
- ParticleBinding particle = new ParticleBinding(valueElementBinding, 1, 1, false);
- keyValueSequence.addParticle(particle);
- PropertyHandler valueHandler = new PropertyHandler(entryInfo.getProperty("value"), valueType);
- entryAdapterFactory.addProperty(valueElementBinding.getQName(), valueHandler);
- }
-
- // TODO: need to verify correct binding before proceeding
isMap = true;
- propertyHandler = new MapPropertyHandler(JBossXBBuilder.configuration, property, localPropertyType);
}
- else if(entryElement != null && !JBossXmlMapEntry.DEFAULT.class.equals(entryElement.type()))
- {
- if(!JBossXmlConstants.DEFAULT.equals(entryElement.name()))
- {
- String ns = entryElement.namespace();
- if(JBossXmlConstants.DEFAULT.equals(ns))
- ns = propertyQName.getNamespaceURI();
- propertyQName = new QName(ns, entryElement.name());
- }
-
- TypeInfo entryTypeBinding = JBossXBBuilder.configuration.getTypeInfo(entryElement.type());
- ElementBinding entryElementBinding = createElementBinding(entryTypeBinding, propertyQName.getLocalPart(), false);
- ParticleBinding entryParticle = new ParticleBinding(entryElementBinding, 0, -1, true);
- targetGroup.addParticle(entryParticle);
-
- propertyHandler = new MapPropertyHandler(JBossXBBuilder.configuration, property, localPropertyType);
- isMap = true;
- }
else
- {
- // no or incorrect binding
propertyHandler = new PropertyHandler(property, localPropertyType);
- }
}
else
{
@@ -1852,7 +1726,7 @@
// DOM elements are going to be treated as unresolved
// however having the property registered
if (!isMap && !Element.class.getName().equals(propertyType.getName()))
- {
+ {
TypeBinding elementTypeBinding = resolveTypeBinding(localPropertyType);
ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, propertyQName, false);
elementBinding.setNillable(nillable);
@@ -1873,7 +1747,24 @@
}
}
}
+
+ private SequenceBinding bindXmlElementWrapper(TypeInfo propertyType, ModelGroupBinding parentModel, boolean wrapperNillable, QName wrapperQName)
+ {
+ TypeBinding wrapperType = new TypeBinding();
+ SequenceBinding seq = new SequenceBinding(schemaBinding);
+ seq.setHandler(BuilderParticleHandler.INSTANCE);
+ ParticleBinding particle = new ParticleBinding(seq);
+ wrapperType.setParticle(particle);
+ wrapperType.setHandler(new DefaultElementHandler());
+ ElementBinding wrapperElement = createElementBinding(propertyType, wrapperType, wrapperQName, false);
+ wrapperElement.setNillable(wrapperNillable);
+ wrapperElement.setSkip(Boolean.TRUE);
+ particle = new ParticleBinding(wrapperElement, 1, 1, false);
+ parentModel.addParticle(particle);
+ return seq;
+ }
+
private BeanAdapterFactory createAdapterFactory(Class<? extends BeanAdapterBuilder> beanAdapterBuilderClass, BeanInfo beanInfo, MethodInfo factory)
{
try
@@ -2198,4 +2089,169 @@
}
}
}
+
+ private QName bindMapProperty(PropertyInfo prop, ClassInfo propType, QName propertyQName, ModelGroupBinding targetGroup)
+ {
+ QName boundQName = null;
+
+ JBossXmlMapEntry entryElement = null;
+ if(prop != null)
+ entryElement = prop.getUnderlyingAnnotation(JBossXmlMapEntry.class);
+ if(entryElement == null)
+ entryElement = propType.getUnderlyingAnnotation(JBossXmlMapEntry.class);
+
+ JBossXmlMapKeyElement keyElement = null;
+ if(prop != null)
+ keyElement = prop.getUnderlyingAnnotation(JBossXmlMapKeyElement.class);
+ if(keyElement == null)
+ keyElement = propType.getUnderlyingAnnotation(JBossXmlMapKeyElement.class);
+
+ JBossXmlMapKeyAttribute keyAttribute = null;
+ if(prop != null)
+ keyAttribute = prop.getUnderlyingAnnotation(JBossXmlMapKeyAttribute.class);
+ if(keyAttribute == null)
+ keyAttribute = propType.getUnderlyingAnnotation(JBossXmlMapKeyAttribute.class);
+
+ if(keyElement != null || keyAttribute != null)
+ {
+ // further assuming the map is bound
+
+ JBossXmlMapValueElement valueElement = null;
+ if(prop != null)
+ valueElement = prop.getUnderlyingAnnotation(JBossXmlMapValueElement.class);
+ if(valueElement == null)
+ valueElement = propType.getUnderlyingAnnotation(JBossXmlMapValueElement.class);
+
+ JBossXmlMapValueAttribute valueAttribute = null;
+ if(prop != null)
+ valueAttribute = prop.getUnderlyingAnnotation(JBossXmlMapValueAttribute.class);
+ if(valueAttribute == null)
+ valueAttribute = propType.getUnderlyingAnnotation(JBossXmlMapValueAttribute.class);
+
+ TypeInfo keyType = propType.getKeyType();
+ TypeInfo valueType = propType.getValueType();
+
+ // entry handler
+ BeanAdapterFactory entryAdapterFactory = null;
+ BeanInfo entryInfo = JBossXBBuilder.configuration.getBeanInfo(DefaultMapEntry.class);
+ entryAdapterFactory = createAdapterFactory(DefaultBeanAdapterBuilder.class, entryInfo, null);
+ BeanHandler entryHandler = new BeanHandler(entryInfo.getName(), entryAdapterFactory);
+
+ TypeBinding entryType = null;
+ TypeInfo entryTypeInfo = null;
+
+ // bind the entry element if present
+ if(entryElement != null && !JBossXmlConstants.DEFAULT.equals(entryElement.name()))
+ {
+ String ns = entryElement.namespace();
+ if(JBossXmlConstants.DEFAULT.equals(ns))
+ ns = defaultNamespace;
+ QName entryName = new QName(ns, entryElement.name());
+
+ entryType = new TypeBinding();
+ entryType.setSchemaBinding(schemaBinding);
+ entryType.setHandler(entryHandler);
+
+ entryTypeInfo = JBossXBBuilder.configuration.getTypeInfo(DefaultMapEntry.class);
+ ElementBinding entryElementBinding = createElementBinding(entryTypeInfo, entryType, entryName, false);
+ ParticleBinding entryParticle = new ParticleBinding(entryElementBinding, 0, -1, true);
+ targetGroup.addParticle(entryParticle);
+
+ propertyQName = entryName;
+
+ if(keyAttribute != null)
+ {
+ TypeBinding attributeType = resolveTypeBinding(keyType);
+ AttributeHandler attributeHandler = new PropertyHandler(entryInfo.getProperty("key"), keyType);
+ String attrNs = keyAttribute.namespace();
+ if(JBossXmlConstants.DEFAULT.equals(attrNs))
+ attrNs = defaultNamespace;
+ AttributeBinding keyBinding = new AttributeBinding(schemaBinding, new QName(attrNs, keyAttribute.name()), attributeType, attributeHandler);
+ keyBinding.setRequired(true);
+ entryType.addAttribute(keyBinding);
+ }
+
+ if(valueAttribute != null)
+ {
+ TypeBinding attributeType = resolveTypeBinding(valueType);
+ AttributeHandler attributeHandler = new PropertyHandler(entryInfo.getProperty("value"), valueType);
+ String valueNs = valueAttribute.namespace();
+ if(JBossXmlConstants.DEFAULT.equals(valueNs))
+ valueNs = defaultNamespace;
+ AttributeBinding valueBinding = new AttributeBinding(schemaBinding, new QName(valueNs, valueAttribute.name()), attributeType, attributeHandler);
+ valueBinding.setRequired(true);
+ entryType.addAttribute(valueBinding);
+ }
+ else if(valueElement == null)
+ {
+ CharactersHandler charactersHandler = new ValueHandler(entryInfo.getProperty("value"), valueType);
+ entryType.setSimpleType(charactersHandler);
+ }
+ }
+
+ SequenceBinding keyValueSequence = null;
+ if(keyElement != null)
+ {
+ keyValueSequence = new SequenceBinding(schemaBinding);
+ if(entryType == null)
+ {
+ keyValueSequence.setSkip(Boolean.FALSE);
+ keyValueSequence.setQName(propertyQName);
+ schemaBinding.addGroup(keyValueSequence.getQName(), keyValueSequence);
+ ParticleBinding keyValueParticle = new ParticleBinding(keyValueSequence, 0, -1, true);
+ targetGroup.addParticle(keyValueParticle);
+ keyValueSequence.setHandler(entryHandler);
+ }
+ else
+ {
+ ParticleBinding keyValueParticle = new ParticleBinding(keyValueSequence, 1, 1, false);
+ entryType.setParticle(keyValueParticle);
+ }
+
+ // key element
+ TypeBinding keyTypeBinding = resolveTypeBinding(keyType);
+ String keyNs = keyElement.namespace();
+ if(JBossXmlConstants.DEFAULT.equals(keyNs))
+ keyNs = defaultNamespace;
+ ElementBinding keyElementBinding = createElementBinding(keyType, keyTypeBinding, new QName(keyNs, keyElement.name()), false);
+ ParticleBinding particle = new ParticleBinding(keyElementBinding, 1, 1, false);
+ keyValueSequence.addParticle(particle);
+ PropertyHandler keyHandler = new PropertyHandler(entryInfo.getProperty("key"), keyType);
+ entryAdapterFactory.addProperty(keyElementBinding.getQName(), keyHandler);
+ }
+
+ if(valueElement != null)
+ {
+ TypeBinding valueTypeBinding = resolveTypeBinding(valueType);
+ String valueNs = valueElement.namespace();
+ if(JBossXmlConstants.DEFAULT.equals(valueNs))
+ valueNs = defaultNamespace;
+ ElementBinding valueElementBinding = createElementBinding(valueType, valueTypeBinding, new QName(valueNs, valueElement.name()), false);
+ ParticleBinding particle = new ParticleBinding(valueElementBinding, 1, 1, false);
+ keyValueSequence.addParticle(particle);
+ PropertyHandler valueHandler = new PropertyHandler(entryInfo.getProperty("value"), valueType);
+ entryAdapterFactory.addProperty(valueElementBinding.getQName(), valueHandler);
+ }
+
+ // TODO: need to verify correct binding before proceeding
+ boundQName = propertyQName;
+ }
+ else if(entryElement != null && !JBossXmlMapEntry.DEFAULT.class.equals(entryElement.type()))
+ {
+ if(!JBossXmlConstants.DEFAULT.equals(entryElement.name()))
+ {
+ String ns = entryElement.namespace();
+ if(JBossXmlConstants.DEFAULT.equals(ns))
+ ns = propertyQName.getNamespaceURI();
+ propertyQName = new QName(ns, entryElement.name());
+ }
+
+ TypeInfo entryTypeInfo = JBossXBBuilder.configuration.getTypeInfo(entryElement.type());
+ ElementBinding entryElementBinding = createElementBinding(entryTypeInfo, propertyQName.getLocalPart(), false);
+ ParticleBinding entryParticle = new ParticleBinding(entryElementBinding, 0, -1, true);
+ targetGroup.addParticle(entryParticle);
+ boundQName = propertyQName;
+ }
+ return boundQName;
+ }
}
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ChildWildcardHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ChildWildcardHandler.java 2008-01-22 23:37:49 UTC (rev 2702)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ChildWildcardHandler.java 2008-01-25 12:34:04 UTC (rev 2703)
@@ -97,7 +97,7 @@
{
try
{
- ClassInfo classInfo = beanInfo.getClassInfo();
+ ClassInfo classInfo = (ClassInfo) propertyInfo.getType();//beanInfo.getClassInfo();
TypeInfo valueType = classInfo.getTypeInfoFactory().getTypeInfo(o.getClass());
if (classInfo.isAssignableFrom(valueType) == false)
{
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/MapPropertyHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/MapPropertyHandler.java 2008-01-22 23:37:49 UTC (rev 2702)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/MapPropertyHandler.java 2008-01-25 12:34:04 UTC (rev 2703)
@@ -55,37 +55,44 @@
* @param propertyType the property type
* @throws IllegalArgumentException for a null qName or property
*/
- public MapPropertyHandler(Configuration config, PropertyInfo propertyInfo, TypeInfo propertyType)
+ public MapPropertyHandler(Configuration config, PropertyInfo propertyInfo, TypeInfo propertyType, boolean wrapped)
{
super(propertyInfo, propertyType);
- ClassInfo classInfo = (ClassInfo) propertyType;
- if (Modifier.isAbstract(classInfo.getModifiers()))
+ if(wrapped)
{
- mapFactory = HashMapFactory.INSTANCE;
+ mapFactory = null;
}
else
{
- ConstructorInfo constructor = classInfo.getDeclaredConstructor(null);
- if (constructor == null)
+ ClassInfo classInfo = (ClassInfo) propertyType;
+ if (Modifier.isAbstract(classInfo.getModifiers()))
{
- for (ConstructorInfo ctor : classInfo.getDeclaredConstructors())
+ mapFactory = HashMapFactory.INSTANCE;
+ }
+ else
+ {
+ ConstructorInfo constructor = classInfo.getDeclaredConstructor(null);
+ if (constructor == null)
{
- if (ctor.getParameterTypes().length == 0)
+ for (ConstructorInfo ctor : classInfo.getDeclaredConstructors())
{
- log.warn("ClassInfo.getDeclaredConstructor(null) didn't work for " + classInfo.getName()
- + ", found the default ctor in ClassInfo.getDeclaredConstructors()");
- constructor = ctor;
- break;
+ if (ctor.getParameterTypes().length == 0)
+ {
+ log.warn("ClassInfo.getDeclaredConstructor(null) didn't work for " + classInfo.getName()
+ + ", found the default ctor in ClassInfo.getDeclaredConstructors()");
+ constructor = ctor;
+ break;
+ }
}
- }
- if (constructor == null)
- {
- throw new RuntimeException("Default constructor not found for " + classInfo.getName());
+ if (constructor == null)
+ {
+ throw new RuntimeException("Default constructor not found for " + classInfo.getName());
+ }
}
+ mapFactory = new CtorMapFactory(constructor);
}
- mapFactory = new CtorMapFactory(constructor);
}
JBossXmlMapEntry entry = propertyInfo.getUnderlyingAnnotation(JBossXmlMapEntry.class);
@@ -105,39 +112,52 @@
@SuppressWarnings("unchecked")
public void handle(PropertyInfo propertyInfo, TypeInfo propertyType, Object parent, Object child, QName qName)
{
+ if(trace)
+ log.trace("handle entry " + qName + ", property=" + propertyInfo.getName() + ", parent=" + parent + ", child=" + child);
+
BeanAdapter beanAdapter = (BeanAdapter) parent;
Map<Object, Object> m = null;
- try
+ if(mapFactory == null)
{
- if (propertyInfo.getGetter() != null)
- m = (Map<Object, Object>) beanAdapter.get(propertyInfo);
+ // it's wrapped, so the parent expected to be a map
+ m = (Map<Object, Object>) beanAdapter.getValue();
}
- catch (Throwable t)
+ else
{
- throw new RuntimeException("QName " + qName + " error getting map property " + propertyInfo.getName() + " for " + BuilderUtil.toDebugString(parent), t);
- }
-
- // No map so create one
- if (m == null)
- {
try
{
- m = mapFactory.createMap();
+ if (propertyInfo.getGetter() != null)
+ m = (Map<Object, Object>) beanAdapter.get(propertyInfo);
}
catch (Throwable t)
{
- throw new RuntimeException("QName " + qName + " error creating map: " + propertyType.getName(), t);
+ throw new RuntimeException("QName " + qName + " error getting map property " + propertyInfo.getName()
+ + " for " + BuilderUtil.toDebugString(parent), t);
}
- try
+ // No map so create one
+ if (m == null)
{
- beanAdapter.set(propertyInfo, m);
+ try
+ {
+ m = mapFactory.createMap();
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException("QName " + qName + " error creating map: " + propertyType.getName(), t);
+ }
+
+ try
+ {
+ beanAdapter.set(propertyInfo, m);
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException("QName " + qName + " error setting map property " + propertyInfo.getName()
+ + " for " + BuilderUtil.toDebugString(parent) + " with value " + BuilderUtil.toDebugString(m), t);
+ }
}
- catch (Throwable t)
- {
- throw new RuntimeException("QName " + qName + " error setting map property " + propertyInfo.getName() + " for " + BuilderUtil.toDebugString(parent) + " with value " + BuilderUtil.toDebugString(m), t);
- }
}
try
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/AbstractMapMetaData.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/AbstractMapMetaData.java 2008-01-22 23:37:49 UTC (rev 2702)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/AbstractMapMetaData.java 2008-01-25 12:34:04 UTC (rev 2703)
@@ -1,27 +1,28 @@
/*
-* 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.
-*/
+ * 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.mc.support.model;
import java.io.Serializable;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
@@ -29,12 +30,13 @@
import java.util.Set;
import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;
+import org.jboss.test.xb.builder.object.mc.support.model.MapEntry;
+import org.jboss.reflect.spi.ClassInfo;
import org.jboss.reflect.spi.TypeInfo;
-import org.jboss.xb.annotations.JBossXmlChild;
-import org.jboss.xb.annotations.JBossXmlChildren;
-import org.jboss.xb.annotations.JBossXmlNoElements;
+import org.jboss.xb.annotations.JBossXmlMapEntry;
/**
* Map metadata.
@@ -42,19 +44,17 @@
* @author <a href="adrian at jboss.com">Adrian Brock</a>
* @version $Revision: 59429 $
*/
- at XmlType()
- at JBossXmlNoElements
- at JBossXmlChildren
-({
- @JBossXmlChild(name="entry", type=MapEntry.class)
-})
+ at XmlType
+ at JBossXmlMapEntry(name = "entry", type = MapEntry.class)
public class AbstractMapMetaData extends AbstractTypeMetaData
- implements Set<MapEntry>, Serializable
+ implements
+ Map<MetaDataVisitorNode, MetaDataVisitorNode>,
+ Serializable
{
- private static final long serialVersionUID = 1L;
+ private static final long serialVersionUID = 2L;
/** The map */
- private HashMap<MetaDataVisitorNode, MetaDataVisitorNode> map = new HashMap<MetaDataVisitorNode, MetaDataVisitorNode>();
+ private Map<MetaDataVisitorNode, MetaDataVisitorNode> map = new HashMap<MetaDataVisitorNode, MetaDataVisitorNode>();
/** The key type */
protected String keyType;
@@ -84,7 +84,7 @@
*
* @param keyType the key type
*/
- @XmlAttribute(name="keyClass")
+ @XmlAttribute(name = "keyClass")
public void setKeyType(String keyType)
{
this.keyType = keyType;
@@ -105,20 +105,33 @@
*
* @param valueType the value type
*/
- @XmlAttribute(name="valueClass")
+ @XmlAttribute(name = "valueClass")
public void setValueType(String valueType)
{
this.valueType = valueType;
}
- protected Class<? extends Map> expectedMapClass()
- {
- return Map.class;
- }
-
+ @SuppressWarnings("unchecked")
public Object getValue(TypeInfo info, ClassLoader cl) throws Throwable
{
- return null;
+ Map result = getExpectedClass().newInstance();//getTypeInstance(info, cl, getExpectedClass());
+
+ TypeInfo keyTypeInfo = ((ClassInfo) info).getKeyType();// getKeyClassInfo(cl);
+ TypeInfo valueTypeInfo = ((ClassInfo) info).getValueType();//getValueClassInfo(cl);
+
+ if (map.size() > 0)
+ {
+ for (Iterator i = map.entrySet().iterator(); i.hasNext();)
+ {
+ Map.Entry entry = (Map.Entry) i.next();
+ ValueMetaData key = (ValueMetaData) entry.getKey();
+ ValueMetaData value = (ValueMetaData) entry.getValue();
+ Object keyValue = key.getValue(keyTypeInfo, cl);
+ Object valueValue = value.getValue(valueTypeInfo, cl);
+ result.put(keyValue, valueValue);
+ }
+ }
+ return result;
}
public void clear()
@@ -136,7 +149,7 @@
return map.containsValue(value);
}
- public Set<Map.Entry<MetaDataVisitorNode, MetaDataVisitorNode>> entrySet()
+ public Set<Entry<MetaDataVisitorNode, MetaDataVisitorNode>> entrySet()
{
return map.entrySet();
}
@@ -166,9 +179,9 @@
map.putAll(t);
}
- public boolean remove(Object key)
+ public MetaDataVisitorNode remove(Object key)
{
- throw new UnsupportedOperationException();
+ return map.remove(key);
}
public int size()
@@ -181,51 +194,28 @@
return map.values();
}
- public boolean add(MapEntry o)
+ @XmlTransient
+ public Iterator<? extends MetaDataVisitorNode> getChildren()
{
- map.put(o.getKey(), o.getValue());
- return true;
+ ArrayList<MetaDataVisitorNode> children = new ArrayList<MetaDataVisitorNode>(keySet());
+ children.addAll(values());
+ return children.iterator();
}
- public boolean addAll(Collection<? extends MapEntry> c)
+ /**
+ * Create the default map instance
+ *
+ * @return the class instance
+ */
+ @XmlTransient
+ protected Object getDefaultInstance()
{
- for (MapEntry mapEntry : c)
- add(mapEntry);
- return true;
+ return new HashMap<Object, Object>();
}
- public boolean contains(Object o)
+ @XmlTransient
+ protected Class<? extends Map> getExpectedClass()
{
- throw new UnsupportedOperationException();
+ return Map.class;
}
-
- public boolean containsAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- public Iterator<MapEntry> iterator()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean removeAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean retainAll(Collection<?> c)
- {
- throw new UnsupportedOperationException();
- }
-
- public Object[] toArray()
- {
- throw new UnsupportedOperationException();
- }
-
- public <T> T[] toArray(T[] a)
- {
- throw new UnsupportedOperationException();
- }
}
\ No newline at end of file
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/MapEntry.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/MapEntry.java 2008-01-22 23:37:49 UTC (rev 2702)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/MapEntry.java 2008-01-25 12:34:04 UTC (rev 2703)
@@ -23,7 +23,10 @@
import javax.xml.bind.annotation.XmlType;
+import org.jboss.xb.annotations.JBossXmlMapKey;
+import org.jboss.xb.annotations.JBossXmlMapValue;
+
/**
* MapEntry.
*
@@ -39,6 +42,7 @@
/** The value */
private ValueMetaData value;
+ @JBossXmlMapKey
public ValueMetaData getKey()
{
return key;
@@ -49,6 +53,7 @@
this.key = key;
}
+ @JBossXmlMapValue
public ValueMetaData getValue()
{
return value;
More information about the jboss-svn-commits
mailing list