[jboss-svn-commits] JBoss Common SVN: r2699 - 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
Mon Jan 14 15:05:16 EST 2008
Author: alex.loubyansky at jboss.com
Date: 2008-01-14 15:05:16 -0500 (Mon, 14 Jan 2008)
New Revision: 2699
Added:
jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapEntry.java
jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapKeyAttribute.java
jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapKeyElement.java
jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapValueAttribute.java
jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapValueElement.java
jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/DefaultMapEntry.java
jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/MapPropertyHandler.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/support/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/support/Root.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntryUnitTestCase.java
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyAttributeValueEntryContent.xml
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyValueAttributes.xml
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyValueSequence.xml
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testWrappedKeyValueSequence.xml
Modified:
jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BeanHandler.java
jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BuilderParticleHandler.java
jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ValueHandler.java
Log:
JBXB-117 basic things
Added: jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapEntry.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapEntry.java (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapEntry.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,102 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * A JBossXmlMapEntry. Binds Java maps to XSD structures.
+ * The annotation can be used on a type which implements java.util.Map
+ * or property of type that implements java.util.Map.
+ *
+ * Some of the possible bindings:
+ *
+ * <h1>sequence of key and value elements</h1>
+ * <pre>
+ * <key>key1</key><value>value1</value>
+ * <key>key2</key><value>value2</value>
+ *
+ * <tt>@JBossXmlMapKeyElement(name="key")</tt>
+ * <tt>@JBossXmlMapValueElement(name="value")</tt>
+ * public Map getMap(){ return map; }
+ * </pre>
+ *
+ * <h1>sequence of key and value elements wrapped inside entry element</h1>
+ * <pre>
+ * <entry>
+ * <key>key1</key>
+ * <value>value1</value>
+ * </entry>
+ * <entry>
+ * <key>key2</key>
+ * <value>value2</value>
+ * </entry>
+ *
+ * <tt>@JBossXmlMapEntry(name="entry")</tt>
+ * <tt>@JBossXmlMapKeyElemenet(name="key")</tt>
+ * <tt>@JBossXmlMapValueElement(name="value")</tt>
+ * public Map getMap(){ return map; }
+ * </pre>
+ *
+ * <h1>key and value attributes in entry element</h1>
+ * <pre>
+ * <entry key='key1' value='value1'/>
+ * <entry key='key2' value='value2'/>
+ *
+ * <tt>@JBossXmlMapEntry(name="entry")</tt>
+ * <tt>@JBossXmlMapKeyAttribute(name="key")</tt>
+ * <tt>@JBossXmlMapValueAttribute(name="value")</tt>
+ * public Map getMap(){ return map; }
+ * </pre>
+ *
+ * <h1>key is an attribute and the value is the value of entry element</h1>
+ * <pre>
+ * <entry key='key1'>value1</entry>
+ * <entry key='key2'>value2</entry>
+ *
+ * /**
+ * * value binding is not specified, it's supposed to be the value of entry element
+ * */
+ * <tt>@JBossXmlMapEntry(name="entry")</tt>
+ * <tt>@JBossXmlMapKeyAttribute(name="key")</tt>
+ * public Map getMap(){ return map; }
+ * </pre>
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface JBossXmlMapEntry
+{
+ String name() default JBossXmlConstants.DEFAULT;
+
+ String namespace() default JBossXmlConstants.DEFAULT;
+
+ Class type() default DEFAULT.class;
+
+ class DEFAULT {};
+}
Added: jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapKeyAttribute.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapKeyAttribute.java (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapKeyAttribute.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * A JBossXmlMapKeyAttribute.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface JBossXmlMapKeyAttribute
+{
+ String name();
+ String namespace() default JBossXmlConstants.DEFAULT;
+}
Added: jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapKeyElement.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapKeyElement.java (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapKeyElement.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * A JBossXmlMapKeyElement.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface JBossXmlMapKeyElement
+{
+ String name();
+ String namespace() default JBossXmlConstants.DEFAULT;
+}
Added: jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapValueAttribute.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapValueAttribute.java (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapValueAttribute.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * A JBossXmlMapValueAttribute.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface JBossXmlMapValueAttribute
+{
+ String name();
+ String namespace() default JBossXmlConstants.DEFAULT;
+}
Added: jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapValueElement.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapValueElement.java (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlMapValueElement.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+/**
+ * A JBossXmlMapValueElement.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at Target({ElementType.TYPE, ElementType.METHOD, ElementType.FIELD})
+ at Retention(RetentionPolicy.RUNTIME)
+public @interface JBossXmlMapValueElement
+{
+ String name();
+ String namespace() default JBossXmlConstants.DEFAULT;
+}
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-08 19:35:20 UTC (rev 2698)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -77,6 +77,11 @@
import org.jboss.xb.annotations.JBossXmlGroup;
import org.jboss.xb.annotations.JBossXmlGroupText;
import org.jboss.xb.annotations.JBossXmlGroupWildcard;
+import org.jboss.xb.annotations.JBossXmlMapEntry;
+import org.jboss.xb.annotations.JBossXmlMapKeyAttribute;
+import org.jboss.xb.annotations.JBossXmlMapKeyElement;
+import org.jboss.xb.annotations.JBossXmlMapValueAttribute;
+import org.jboss.xb.annotations.JBossXmlMapValueElement;
import org.jboss.xb.annotations.JBossXmlModelGroup;
import org.jboss.xb.annotations.JBossXmlNoElements;
import org.jboss.xb.annotations.JBossXmlNsPrefix;
@@ -110,7 +115,9 @@
import org.jboss.xb.builder.runtime.CollectionPropertyHandler;
import org.jboss.xb.builder.runtime.CollectionPropertyWildcardHandler;
import org.jboss.xb.builder.runtime.DOMHandler;
+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.NoopPropertyHandler;
import org.jboss.xb.builder.runtime.PropertyHandler;
import org.jboss.xb.builder.runtime.PropertyInterceptor;
@@ -765,17 +772,7 @@
// Create the handler
BeanInfo beanInfo = JBossXBBuilder.configuration.getBeanInfo(typeInfo);
- BeanAdapterFactory beanAdapterFactory = null;
- try
- {
- BeanInfo beanAdapterBuilderInfo = JBossXBBuilder.configuration.getBeanInfo(beanAdapterBuilderClass);
- BeanAdapterBuilder beanAdapterBuilder = (BeanAdapterBuilder) beanAdapterBuilderInfo.newInstance();
- beanAdapterFactory = beanAdapterBuilder.newFactory(beanInfo, factory);
- }
- catch (Throwable t)
- {
- throw new RuntimeException("Error creating BeanAdapterFactory for " + beanAdapterBuilderClass.getName(), t);
- }
+ BeanAdapterFactory beanAdapterFactory = createAdapterFactory(beanAdapterBuilderClass, beanInfo, factory);
BeanHandler handler = new BeanHandler(beanInfo.getName(), beanAdapterFactory);
typeBinding.setHandler(handler);
if (trace)
@@ -1286,21 +1283,7 @@
// handler for the model group members
BeanInfo propBeanInfo = JBossXBBuilder.configuration.getBeanInfo(propClassInfo);
- BeanAdapterFactory propBeanAdapterFactory = null;
- try
- {
- // TODO this has to use its own adapter class and the factory method
- BeanInfo propBeanAdapterBuilderInfo = JBossXBBuilder.configuration
- .getBeanInfo(DefaultBeanAdapterBuilder.class);
- BeanAdapterBuilder propBeanAdapterBuilder = (BeanAdapterBuilder) propBeanAdapterBuilderInfo
- .newInstance();
- propBeanAdapterFactory = propBeanAdapterBuilder.newFactory(propBeanInfo, null);
- }
- catch (Throwable t)
- {
- throw new RuntimeException("Error creating BeanAdapterFactory for "
- + DefaultBeanAdapterBuilder.class.getName(), t);
- }
+ BeanAdapterFactory propBeanAdapterFactory = createAdapterFactory(DefaultBeanAdapterBuilder.class, propBeanInfo, null);
BeanHandler propHandler = new BeanHandler(propBeanInfo.getName(), propBeanAdapterFactory);
propertyGroup.setHandler(propHandler);
@@ -1546,7 +1529,7 @@
}
// Determine the name
- QName qName = generateXmlName(property.getName(), elementForm, overrideNamespace, overrideName);
+ QName propertyQName = generateXmlName(property.getName(), elementForm, overrideNamespace, overrideName);
// Create the element
JBossXmlGroup jbossXmlGroup = null;
@@ -1563,7 +1546,7 @@
TypeBinding elementTypeBinding = new TypeBinding();
elementTypeBinding.setSchemaBinding(schemaBinding);
elementTypeBinding.setHandler(BuilderParticleHandler.INSTANCE);
- ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, qName, false);
+ ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, propertyQName, false);
// Bind it to the model
ParticleBinding particle = new ParticleBinding(elementBinding, 1, 1, false);
@@ -1615,7 +1598,7 @@
log.trace("Added interceptor " + childName + " for type=" + property.getBeanInfo().getName()
+ " property=" + property.getName() + " interceptor=" + interceptor);
- beanAdapterFactory.addProperty(qName, new NoopPropertyHandler(property, propertyType));
+ beanAdapterFactory.addProperty(propertyQName, new NoopPropertyHandler(property, propertyType));
JBossXmlGroupWildcard groupWildcard = ((ClassInfo) propertyType)
.getUnderlyingAnnotation(JBossXmlGroupWildcard.class);
@@ -1659,12 +1642,12 @@
ModelGroupBinding targetGroup = localModel;
boolean isCol = false;
+ boolean isMap = false;
AbstractPropertyHandler propertyHandler = null;
// a collection may be bound as a value of a complex type
// and this is checked with the XmlType annotation
- if (propertyType.isCollection()
- && ((ClassInfo) propertyType).getUnderlyingAnnotation(XmlType.class) == null)
+ if (propertyType.isCollection() && ((ClassInfo) propertyType).getUnderlyingAnnotation(XmlType.class) == null)
{
isCol = true;
propertyHandler = new CollectionPropertyHandler(property, propertyType);
@@ -1702,6 +1685,137 @@
localPropertyType = findActualType((ClassInfo) localPropertyType, parameterizedType,
java.util.Collection.class, 0);
}
+ else if (propertyType.isMap() && ((ClassInfo) propertyType).getUnderlyingAnnotation(XmlType.class) == null)
+ {
+ JBossXmlMapKeyElement keyElement = property.getUnderlyingAnnotation(JBossXmlMapKeyElement.class);
+ JBossXmlMapKeyAttribute keyAttribute = property.getUnderlyingAnnotation(JBossXmlMapKeyAttribute.class);
+
+ if(keyElement != null || keyAttribute != null)
+ {
+ // further assuming the map is bound
+
+ JBossXmlMapEntry entryElement = property.getUnderlyingAnnotation(JBossXmlMapEntry.class);
+ JBossXmlMapValueElement valueElement = property.getUnderlyingAnnotation(JBossXmlMapValueElement.class);
+ JBossXmlMapValueAttribute valueAttribute = property.getUnderlyingAnnotation(JBossXmlMapValueAttribute.class);
+
+ TypeInfo keyType = ((ClassInfo)propertyType).getKeyType();
+ TypeInfo valueType = ((ClassInfo)propertyType).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);
+
+ propertyHandler = new MapPropertyHandler(property, localPropertyType);
+ }
+ 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
+ isMap = true;
+ propertyHandler = new MapPropertyHandler(property, localPropertyType);
+ }
+ else
+ {
+ // no or incorrect binding
+ propertyHandler = new PropertyHandler(property, localPropertyType);
+ }
+ }
else
{
propertyHandler = new PropertyHandler(property, localPropertyType);
@@ -1710,10 +1824,10 @@
ParticleBinding particle;
// DOM elements are going to be treated as unresolved
// however having the property registered
- if (!Element.class.getName().equals(propertyType.getName()))
+ if (!isMap && !Element.class.getName().equals(propertyType.getName()))
{
TypeBinding elementTypeBinding = resolveTypeBinding(localPropertyType);
- ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, qName, false);
+ ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, propertyQName, false);
elementBinding.setNillable(nillable);
elementBinding.setValueAdapter(valueAdapter);
@@ -1725,14 +1839,29 @@
targetGroup.addParticle(particle);
}
- beanAdapterFactory.addProperty(qName, propertyHandler);
+ beanAdapterFactory.addProperty(propertyQName, propertyHandler);
if (trace)
- log.trace("Added property " + qName + " for type=" + property.getBeanInfo().getName() + " property="
+ log.trace("Added property " + propertyQName + " for type=" + property.getBeanInfo().getName() + " property="
+ property.getName() + " handler=" + propertyHandler);
}
}
}
+ private BeanAdapterFactory createAdapterFactory(Class<? extends BeanAdapterBuilder> beanAdapterBuilderClass, BeanInfo beanInfo, MethodInfo factory)
+ {
+ try
+ {
+ BeanInfo adapterBuilderInfo = JBossXBBuilder.configuration.getBeanInfo(beanAdapterBuilderClass);
+ BeanAdapterBuilder adapterBuilder = (BeanAdapterBuilder) adapterBuilderInfo.newInstance();
+ return adapterBuilder.newFactory(beanInfo, factory);
+ }
+ catch (Throwable t)
+ {
+ throw new RuntimeException("Error creating BeanAdapterFactory for "
+ + beanAdapterBuilderClass.getName(), t);
+ }
+ }
+
/**
* Create an array
*
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BeanHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BeanHandler.java 2008-01-08 19:35:20 UTC (rev 2698)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BeanHandler.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -184,7 +184,7 @@
return;
}
- if(particle.isRepeatable() && propertyHandler instanceof CollectionPropertyHandler)
+ if(particle.isRepeatable() && !(propertyHandler instanceof PropertyHandler))
{
// TODO this is not optimal!
// repeatable particles are collected into java.util.Collection
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BuilderParticleHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BuilderParticleHandler.java 2008-01-08 19:35:20 UTC (rev 2698)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BuilderParticleHandler.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -25,6 +25,7 @@
import javax.xml.namespace.QName;
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.ParticleHandler;
import org.jboss.xb.binding.sunday.unmarshalling.TermBinding;
@@ -53,20 +54,31 @@
{
TermBinding term = particle.getTerm();
TermBinding parentTerm = parentParticle.getTerm();
- if (term.isModelGroup() == false && parentTerm instanceof ElementBinding)
+ if (term.isModelGroup() == false)
{
- ElementBinding elementBinding = (ElementBinding) parentTerm;
- if (parent != null && parent instanceof ArrayWrapper)
+ ParticleHandler particleHandler = null;
+ if(parentTerm.isElement())
{
- ArrayWrapper wrapper = (ArrayWrapper) parent;
- wrapper.add(o);
- wrapper.setChildParticle(particle);
- wrapper.setParentParticle(parentParticle);
- return;
+ particleHandler = ((ElementBinding)parentTerm).getType().getHandler();
}
-
- ParticleHandler particleHandler = elementBinding.getType().getHandler();
- particleHandler.setParent(parent, o, elementName, particle, parentParticle);
+ else if (!parentTerm.isSkip() && parentTerm.isModelGroup())
+ {
+ particleHandler = ((ModelGroupBinding)parentTerm).getHandler();
+ }
+
+ if(particleHandler != null)
+ {
+ if (parent != null && parent instanceof ArrayWrapper)
+ {
+ ArrayWrapper wrapper = (ArrayWrapper) parent;
+ wrapper.add(o);
+ wrapper.setChildParticle(particle);
+ wrapper.setParentParticle(parentParticle);
+ return;
+ }
+
+ particleHandler.setParent(parent, o, elementName, particle, parentParticle);
+ }
}
}
Added: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/DefaultMapEntry.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/DefaultMapEntry.java (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/DefaultMapEntry.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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;
+
+
+/**
+ * A DefaultMapEntry.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class DefaultMapEntry
+{
+ private Object key;
+ private Object value;
+
+ /**
+ * Get the key.
+ *
+ * @return the key.
+ */
+ public Object getKey()
+ {
+ return key;
+ }
+
+ /**
+ * Set the key.
+ *
+ * @param key The key to set.
+ */
+ public void setKey(Object key)
+ {
+ this.key = key;
+ }
+
+ /**
+ * Get the value.
+ *
+ * @return the value.
+ */
+ public Object getValue()
+ {
+ return value;
+ }
+
+ /**
+ * Set the value.
+ *
+ * @param value The value to set.
+ */
+ public void setValue(Object value)
+ {
+ this.value = value;
+ }
+}
Added: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/MapPropertyHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/MapPropertyHandler.java (rev 0)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/MapPropertyHandler.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,171 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, 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 java.lang.reflect.Modifier;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.xml.namespace.QName;
+
+import org.jboss.beans.info.spi.PropertyInfo;
+import org.jboss.reflect.spi.ClassInfo;
+import org.jboss.reflect.spi.ConstructorInfo;
+import org.jboss.reflect.spi.TypeInfo;
+import org.jboss.xb.spi.BeanAdapter;
+
+/**
+ * MapPropertyHandler.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class MapPropertyHandler extends AbstractPropertyHandler
+{
+ private final MapFactory mapFactory;
+
+ /**
+ * Create a new MapPropertyHandler.
+ *
+ * @param propertyInfo the property
+ * @param propertyType the property type
+ * @throws IllegalArgumentException for a null qName or property
+ */
+ public MapPropertyHandler(PropertyInfo propertyInfo, TypeInfo propertyType)
+ {
+ super(propertyInfo, propertyType);
+
+ ClassInfo classInfo = (ClassInfo) propertyType;
+ if (Modifier.isAbstract(classInfo.getModifiers()))
+ {
+ mapFactory = new HashMapFactory();
+ }
+ else
+ {
+ ConstructorInfo constructor = classInfo.getDeclaredConstructor(null);
+ if (constructor == null)
+ {
+ for (ConstructorInfo ctor : classInfo.getDeclaredConstructors())
+ {
+ 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());
+ }
+ }
+ mapFactory = new CtorMapFactory(constructor);
+ }
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public void handle(PropertyInfo propertyInfo, TypeInfo propertyType, Object parent, Object child, QName qName)
+ {
+ BeanAdapter beanAdapter = (BeanAdapter) parent;
+
+ Map<Object, Object> m = null;
+ try
+ {
+ if (propertyInfo.getGetter() != null)
+ m = (Map<Object, Object>) beanAdapter.get(propertyInfo);
+ }
+ catch (Throwable t)
+ {
+ 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();
+ }
+ 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);
+ }
+ }
+
+ if(!(child instanceof DefaultMapEntry))
+ throw new IllegalStateException("Only the DefaultMapEntry is supported at the moment: " + child);
+
+ DefaultMapEntry entry = (DefaultMapEntry) child;
+
+ // Now add
+ try
+ {
+ m.put(entry.getKey(), entry.getValue());
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("QName " + qName + " error adding " + BuilderUtil.toDebugString(child) + " to map " + BuilderUtil.toDebugString(m), e);
+ }
+ }
+
+ private static interface MapFactory
+ {
+ Map<Object, Object> createMap() throws Throwable;
+ }
+
+ private static class HashMapFactory implements MapFactory
+ {
+ @SuppressWarnings("unchecked")
+ public Map<Object, Object> createMap()
+ {
+ return new HashMap<Object, Object>();
+ }
+ }
+
+ private static class CtorMapFactory implements MapFactory
+ {
+ private final ConstructorInfo ctor;
+
+ CtorMapFactory(ConstructorInfo ctor)
+ {
+ this.ctor = ctor;
+ }
+
+ @SuppressWarnings("unchecked")
+ public Map<Object, Object> createMap() throws Throwable
+ {
+ return (Map) ctor.newInstance(null);
+ }
+ }
+}
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ValueHandler.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ValueHandler.java 2008-01-08 19:35:20 UTC (rev 2698)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/ValueHandler.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -49,12 +49,15 @@
/** The property info */
private PropertyInfo propertyInfo;
+ /** value type info */
+ private TypeInfo valueTypeInfo;
+
/** The wrapper type */
private BeanInfo beanInfo;
/** The wrapper property */
private String property;
-
+
/**
* Create a new AbstractPropertyHandler
*
@@ -66,9 +69,29 @@
if (propertyInfo == null)
throw new IllegalArgumentException("Null propertyInfo");
this.propertyInfo = propertyInfo;
+ this.valueTypeInfo = propertyInfo.getType();
}
+
+
/**
+ * Create a new ValueHandler.
+ *
+ * @param propertyInfo the property
+ * @param valueTypeInfo the type of the property to cast the value to before setting
+ */
+ public ValueHandler(PropertyInfo propertyInfo, TypeInfo valueTypeInfo)
+ {
+ if (propertyInfo == null)
+ throw new IllegalArgumentException("Null propertyInfo");
+ this.propertyInfo = propertyInfo;
+ this.valueTypeInfo = valueTypeInfo;
+ if(valueTypeInfo == null)
+ this.valueTypeInfo = propertyInfo.getType();
+ }
+
+
+ /**
* Create a new AbstractPropertyHandler
*
* @param propertyInfo the property
@@ -85,6 +108,7 @@
if (property == null)
throw new IllegalArgumentException("Null property");
this.propertyInfo = propertyInfo;
+ this.valueTypeInfo = propertyInfo.getType();
this.beanInfo = beanInfo;
this.property = property;
}
@@ -106,8 +130,7 @@
log.trace("QName " + qName + " handle " + BuilderUtil.toDebugString(value) + " to " + BuilderUtil.toDebugString(owner));
try
{
- TypeInfo typeInfo = propertyInfo.getType();
- value = typeInfo.convertValue(value, false);
+ value = valueTypeInfo.convertValue(value, false);
if (beanInfo != null)
{
ClassInfo classInfo = beanInfo.getClassInfo();
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/support/Root.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/support/Root.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/support/Root.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jbossxmlmapentry.support;
+
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.jboss.xb.annotations.JBossXmlMapEntry;
+import org.jboss.xb.annotations.JBossXmlMapKeyAttribute;
+import org.jboss.xb.annotations.JBossXmlMapKeyElement;
+import org.jboss.xb.annotations.JBossXmlMapValueAttribute;
+import org.jboss.xb.annotations.JBossXmlMapValueElement;
+
+
+/**
+ * A Root.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement
+public class Root
+{
+ private Map<String, Integer> stringToInteger;
+
+ @JBossXmlMapKeyElement(name = "key")
+ @JBossXmlMapValueElement(name = "value")
+ public Map<String, Integer> getKeyValueSequence()
+ {
+ return this.stringToInteger;
+ }
+
+ public void setKeyValueSequence(Map<String, Integer> value)
+ {
+ this.stringToInteger = value;
+ }
+
+ @JBossXmlMapEntry(name = "wrapped-key-value")
+ @JBossXmlMapKeyElement(name = "key")
+ @JBossXmlMapValueElement(name = "value")
+ public Map<String, Integer> getWrappedKeyValueSequence()
+ {
+ return this.stringToInteger;
+ }
+
+ public void setWrappedKeyValueSequence(Map<String, Integer> value)
+ {
+ this.stringToInteger = value;
+ }
+
+ @JBossXmlMapEntry(name = "key-value-attr")
+ @JBossXmlMapKeyAttribute(name = "key")
+ @JBossXmlMapValueAttribute(name = "value")
+ public Map<String, Integer> getKeyValueAttributes()
+ {
+ return this.stringToInteger;
+ }
+
+ public void setKeyValueAttributes(Map<String, Integer> value)
+ {
+ this.stringToInteger = value;
+ }
+
+ @JBossXmlMapEntry(name = "key-attr-value-entry-content")
+ @JBossXmlMapKeyAttribute(name = "key")
+ public Map<String, Integer> getKeyAttributeValueEntryContent()
+ {
+ return this.stringToInteger;
+ }
+
+ public void setKeyAttributeValueEntryContent(Map<String, Integer> value)
+ {
+ this.stringToInteger = value;
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntryUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntryUnitTestCase.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntryUnitTestCase.java 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,76 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file 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.jbossxmlmapentry.test;
+
+import java.util.Map;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xb.builder.object.jbossxmlmapentry.support.Root;
+
+
+/**
+ * A JBossXmlMapEntryUnitTestCase.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JBossXmlMapEntryUnitTestCase extends AbstractBuilderTest
+{
+
+ public JBossXmlMapEntryUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testKeyValueSequence() throws Exception
+ {
+ Root root = unmarshalObject(Root.class);
+ assertMap(root.getKeyValueSequence());
+ }
+
+ public void testWrappedKeyValueSequence() throws Exception
+ {
+ Root root = unmarshalObject(Root.class);
+ assertMap(root.getWrappedKeyValueSequence());
+ }
+
+ public void testKeyValueAttributes() throws Exception
+ {
+ Root root = unmarshalObject(Root.class);
+ assertMap(root.getKeyValueAttributes());
+ }
+
+ public void testKeyAttributeValueEntryContent() throws Exception
+ {
+ Root root = unmarshalObject(Root.class);
+ assertMap(root.getKeyAttributeValueEntryContent());
+ }
+
+ private void assertMap(Map<String, Integer> map)
+ {
+ assertNotNull(map);
+ assertEquals(3, map.size());
+ assertEquals(new Integer(1), map.get("key1"));
+ assertEquals(new Integer(22), map.get("key2"));
+ assertEquals(new Integer(333), map.get("key3"));
+ }
+}
Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyAttributeValueEntryContent.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyAttributeValueEntryContent.xml (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyAttributeValueEntryContent.xml 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root>
+ <key-attr-value-entry-content key="key1">1</key-attr-value-entry-content>
+ <key-attr-value-entry-content key="key2">22</key-attr-value-entry-content>
+ <key-attr-value-entry-content key="key3">333</key-attr-value-entry-content>
+</root>
Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyValueAttributes.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyValueAttributes.xml (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyValueAttributes.xml 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root>
+ <key-value-attr key="key1" value="1"/>
+ <key-value-attr key="key2" value="22"/>
+ <key-value-attr key="key3" value="333"/>
+</root>
Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyValueSequence.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyValueSequence.xml (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testKeyValueSequence.xml 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root>
+ <key>key1</key><value>1</value>
+ <key>key2</key><value>22</value>
+ <key>key3</key><value>333</value>
+</root>
Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testWrappedKeyValueSequence.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testWrappedKeyValueSequence.xml (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/jbossxmlmapentry/test/JBossXmlMapEntry_testWrappedKeyValueSequence.xml 2008-01-14 20:05:16 UTC (rev 2699)
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root>
+ <wrapped-key-value>
+ <key>key1</key><value>1</value>
+ </wrapped-key-value>
+ <wrapped-key-value>
+ <key>key2</key><value>22</value>
+ </wrapped-key-value>
+ <wrapped-key-value>
+ <key>key3</key><value>333</value>
+ </wrapped-key-value>
+</root>
More information about the jboss-svn-commits
mailing list