[jboss-svn-commits] JBoss Common SVN: r2626 - in jbossxb/trunk/src: main/java/org/jboss/xb/builder/runtime and 7 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Oct 10 11:37:35 EDT 2007
Author: alex.loubyansky at jboss.com
Date: 2007-10-10 11:37:34 -0400 (Wed, 10 Oct 2007)
New Revision: 2626
Added:
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapAdapter.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapEntryType.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/Root.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/test/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/element/javatypeadapter/
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/element/javatypeadapter/test/
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapter_testMap.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
Log:
JBXB-111
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2007-10-10 14:53:30 UTC (rev 2625)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2007-10-10 15:37:34 UTC (rev 2626)
@@ -1198,7 +1198,7 @@
if (xmlTypeAdapter != null)
{
valueAdapter = new XBValueAdapter(xmlTypeAdapter.value(), memberTypeInfo.getTypeInfoFactory());
- memberTypeInfo = valueAdapter.getAdaptedType();
+ memberTypeInfo = valueAdapter.getAdaptedTypeInfo();
}
TypeBinding memberTypeBinding = resolveTypeBinding(memberTypeInfo);
@@ -1428,6 +1428,14 @@
}
else
{
+ XBValueAdapter valueAdapter = null;
+ XmlJavaTypeAdapter xmlTypeAdapter = property.getUnderlyingAnnotation(XmlJavaTypeAdapter.class);
+ if (xmlTypeAdapter != null)
+ {
+ valueAdapter = new XBValueAdapter(xmlTypeAdapter.value(), propertyType.getTypeInfoFactory());
+ localPropertyType = valueAdapter.getAdaptedTypeInfo();
+ }
+
ModelGroupBinding targetGroup = localModel;
boolean isCol = false;
AbstractPropertyHandler propertyHandler = null;
@@ -1460,9 +1468,19 @@
// this is to support the Descriptions.class -> DescriptionsImpl.class
else if (localPropertyType.isCollection() && ((ClassInfo) localPropertyType).getUnderlyingAnnotation(XmlType.class) == null)
{
- propertyHandler = new CollectionPropertyHandler(property, localPropertyType);
- isCol = true;
- localPropertyType = findComponentType((ClassInfo) localPropertyType);
+ Type parameterizedType;
+ if(valueAdapter != null)
+ {
+ propertyHandler = new PropertyHandler(property, localPropertyType);
+ parameterizedType = valueAdapter.getAdaptedType();
+ }
+ else
+ {
+ propertyHandler = new CollectionPropertyHandler(property, localPropertyType);
+ parameterizedType = localPropertyType.getType();
+ }
+ isCol = true;
+ localPropertyType = findActualType((ClassInfo) localPropertyType, parameterizedType, java.util.Collection.class, 0);
}
else
{
@@ -1474,14 +1492,6 @@
// however having the property registered
if (!Element.class.getName().equals(propertyType.getName()))
{
- XBValueAdapter valueAdapter = null;
- XmlJavaTypeAdapter xmlTypeAdapter = property.getUnderlyingAnnotation(XmlJavaTypeAdapter.class);
- if (xmlTypeAdapter != null)
- {
- valueAdapter = new XBValueAdapter(xmlTypeAdapter.value(), propertyType.getTypeInfoFactory());
- localPropertyType = valueAdapter.getAdaptedType();
- }
-
TypeBinding elementTypeBinding = resolveTypeBinding(localPropertyType);
ElementBinding elementBinding = createElementBinding(localPropertyType, elementTypeBinding, qName,
false);
@@ -1909,8 +1919,9 @@
{
private final XmlAdapter xmlAdapter;
- private final TypeInfo adaptedType;
-
+ private final TypeInfo adaptedTypeInfo;
+ private final Type adaptedType;
+
public XBValueAdapter(Class<? extends XmlAdapter> adapterImplClass, TypeInfoFactory factory)
{
try
@@ -1922,13 +1933,21 @@
throw new IllegalStateException("Failed to create an instance of " + adapterImplClass.getName(), e);
}
- ClassInfo adapterImplInfo = (ClassInfo) factory.getTypeInfo(adapterImplClass);
- ClassInfo xmlAdapterInfo = adapterImplInfo.getGenericSuperclass();
- adaptedType = xmlAdapterInfo.getActualTypeArguments()[0];
+// ClassInfo adapterImplInfo = (ClassInfo) factory.getTypeInfo(adapterImplClass);
+// ClassInfo xmlAdapterInfo = adapterImplInfo.getGenericSuperclass();
+// TypeInfo type = xmlAdapterInfo.getActualTypeArguments()[0];
+
+ adaptedType = ((ParameterizedType)adapterImplClass.getGenericSuperclass()).getActualTypeArguments()[0];
+ adaptedTypeInfo = factory.getTypeInfo(adaptedType);
}
- public TypeInfo getAdaptedType()
+ public TypeInfo getAdaptedTypeInfo()
{
+ return adaptedTypeInfo;
+ }
+
+ public Type getAdaptedType()
+ {
return adaptedType;
}
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 2007-10-10 14:53:30 UTC (rev 2625)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/runtime/BeanHandler.java 2007-10-10 15:37:34 UTC (rev 2626)
@@ -184,6 +184,12 @@
return;
}
+ // TODO looks like value adapter should be used earlier in the stack
+ if(valueAdapter != null)
+ {
+ o = valueAdapter.cast(o, null/*propertyHandler.getPropertyType().getType()*/);
+ }
+
if(particle.isRepeatable() && o instanceof java.util.Collection)
{
// TODO this is not optimal!
@@ -195,11 +201,6 @@
}
else
{
- // TODO looks like value adapter should be used earlier in the stack
- if(valueAdapter != null)
- {
- o = valueAdapter.cast(o, null/*propertyHandler.getPropertyType().getType()*/);
- }
propertyHandler.doHandle(beanAdapter, o, qName);
}
}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapAdapter.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapAdapter.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapAdapter.java 2007-10-10 15:37:34 UTC (rev 2626)
@@ -0,0 +1,56 @@
+/*
+ * 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.element.javatypeadapter.support;
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+
+/**
+ * A MyHashMapAdapter.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class MyHashMapAdapter extends XmlAdapter<List<MyHashMapEntryType>, Map<Integer, String>>
+{
+ @Override
+ public List<MyHashMapEntryType> marshal(Map<Integer, String> arg0) throws Exception
+ {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Map<Integer, String> unmarshal(List<MyHashMapEntryType> list) throws Exception
+ {
+ Map<Integer, String> map = new HashMap<Integer, String>();
+ for(MyHashMapEntryType entry: list)
+ {
+ map.put(entry.getKey(), entry.getValue());
+ }
+ return map;
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapEntryType.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapEntryType.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/MyHashMapEntryType.java 2007-10-10 15:37:34 UTC (rev 2626)
@@ -0,0 +1,60 @@
+/*
+ * 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.element.javatypeadapter.support;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlValue;
+
+
+/**
+ * A MyHashMapEntryType.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class MyHashMapEntryType
+{
+ private Integer key;
+ private String value;
+
+ @XmlAttribute
+ public Integer getKey()
+ {
+ return key;
+ }
+
+ public void setKey(Integer key)
+ {
+ this.key = key;
+ }
+
+ @XmlValue
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue(String value)
+ {
+ this.value = value;
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/Root.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/Root.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/support/Root.java 2007-10-10 15:37:34 UTC (rev 2626)
@@ -0,0 +1,51 @@
+/*
+ * 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.element.javatypeadapter.support;
+
+import java.util.Map;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+
+/**
+ * A Root.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement
+public class Root
+{
+ private Map map;
+
+ @XmlJavaTypeAdapter(MyHashMapAdapter.class)
+ public Map getMap()
+ {
+ return map;
+ }
+
+ public void setMap(Map map)
+ {
+ this.map = map;
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java 2007-10-10 15:37:34 UTC (rev 2626)
@@ -0,0 +1,54 @@
+/*
+ * 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.element.javatypeadapter.test;
+
+import java.util.Map;
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xb.builder.object.element.javatypeadapter.support.Root;
+
+
+/**
+ * A JavaTypeAdapterUnitTestCase.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class JavaTypeAdapterUnitTestCase extends AbstractBuilderTest
+{
+ public JavaTypeAdapterUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ @SuppressWarnings("unchecked")
+ public void testMap() throws Exception
+ {
+ Root root = unmarshalObject(Root.class);
+ Map<Integer, String> map = root.getMap();
+ assertNotNull(map);
+ assertEquals(3, map.size());
+ assertEquals("value1", map.get(1));
+ assertEquals("value22", map.get(22));
+ assertEquals("value333", map.get(333));
+ }
+}
Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapter_testMap.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapter_testMap.xml (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/element/javatypeadapter/test/JavaTypeAdapter_testMap.xml 2007-10-10 15:37:34 UTC (rev 2626)
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root>
+ <map key="1">value1</map>
+ <map key="22">value22</map>
+ <map key="333">value333</map>
+</root>
More information about the jboss-svn-commits
mailing list