[jboss-svn-commits] JBoss Common SVN: r4082 - in jbossxb/trunk/src: test/java/org/jboss/test/xb/builder/object/attribute and 6 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Mar 4 03:52:09 EST 2010
Author: alex.loubyansky at jboss.com
Date: 2010-03-04 03:52:08 -0500 (Thu, 04 Mar 2010)
New Revision: 4082
Added:
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/Root.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/StringWrapper.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/StringWrapperAdapter.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/test/
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/attribute/javatypeadapter/
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/attribute/javatypeadapter/test/
jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/attribute/javatypeadapter/test/JavaTypeAdapter_testAdaptedAttribute.xml
Modified:
jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
Log:
JBXB-240
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2010-03-04 07:17:14 UTC (rev 4081)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2010-03-04 08:52:08 UTC (rev 4082)
@@ -986,6 +986,15 @@
TypeInfo attributeTypeInfo = property.getType();
if (jbossXmlAttribute != null && jbossXmlAttribute.type() != Object.class)
attributeTypeInfo = attributeTypeInfo.getTypeInfoFactory().getTypeInfo(jbossXmlAttribute.type());
+
+ XBValueAdapter valueAdapter = null;
+ XmlJavaTypeAdapter xmlTypeAdapter = property.getUnderlyingAnnotation(XmlJavaTypeAdapter.class);
+ if (xmlTypeAdapter != null)
+ {
+ valueAdapter = new XBValueAdapter(xmlTypeAdapter.value(), attributeTypeInfo.getTypeInfoFactory());
+ attributeTypeInfo = valueAdapter.getAdaptedTypeInfo();
+ }
+
TypeBinding attributeType = resolveTypeBinding(attributeTypeInfo);
// Create the attribute handler
@@ -1000,8 +1009,10 @@
attributeHandler = new PropertyHandler(property, attributeTypeInfo);
- // Create the attributre and bind it to the type
+ // Create the attribute and bind it to the type
AttributeBinding attribute = new AttributeBinding(schemaBinding, qName, attributeType, attributeHandler);
+ if(valueAdapter != null)
+ attribute.setValueAdapter(valueAdapter);
attribute.setRequired(xmlAttribute.required());
typeBinding.addAttribute(attribute);
JBossXmlPreserveWhitespace preserveSpace = property.getUnderlyingAnnotation(JBossXmlPreserveWhitespace.class);
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/Root.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/Root.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/Root.java 2010-03-04 08:52:08 UTC (rev 4082)
@@ -0,0 +1,50 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.attribute.javatypeadapter.support;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+/**
+ * A RootWithStringWrapperAttribute.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+ at XmlRootElement(name="root")
+public class Root
+{
+ private StringWrapper attr;
+
+ @XmlAttribute()
+ @XmlJavaTypeAdapter(value = StringWrapperAdapter.class)
+ public StringWrapper getAttr()
+ {
+ return attr;
+ }
+
+ public void setAttr(StringWrapper attr)
+ {
+ this.attr = attr;
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/StringWrapper.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/StringWrapper.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/StringWrapper.java 2010-03-04 08:52:08 UTC (rev 4082)
@@ -0,0 +1,48 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.attribute.javatypeadapter.support;
+
+/**
+ * A StringWrapper.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class StringWrapper
+{
+ private String value;
+
+ public StringWrapper(String value)
+ {
+ this.value = value;
+ }
+
+ 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/attribute/javatypeadapter/support/StringWrapperAdapter.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/StringWrapperAdapter.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/support/StringWrapperAdapter.java 2010-03-04 08:52:08 UTC (rev 4082)
@@ -0,0 +1,46 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2009, 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.attribute.javatypeadapter.support;
+
+import javax.xml.bind.annotation.adapters.XmlAdapter;
+
+
+/**
+ * A StringWrapperAdapter.
+ *
+ * @author <a href="alex at jboss.com">Alexey Loubyansky</a>
+ * @version $Revision: 1.1 $
+ */
+public class StringWrapperAdapter extends XmlAdapter<String, StringWrapper>
+{
+ @Override
+ public String marshal(StringWrapper v) throws Exception
+ {
+ return v == null ? null : v.getValue();
+ }
+
+ @Override
+ public StringWrapper unmarshal(String v) throws Exception
+ {
+ return v == null ? null : new StringWrapper(v);
+ }
+}
Added: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java (rev 0)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/attribute/javatypeadapter/test/JavaTypeAdapterUnitTestCase.java 2010-03-04 08:52:08 UTC (rev 4082)
@@ -0,0 +1,50 @@
+/*
+ * 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.attribute.javatypeadapter.test;
+
+
+import org.jboss.test.xb.builder.AbstractBuilderTest;
+import org.jboss.test.xb.builder.object.attribute.javatypeadapter.support.Root;
+import org.jboss.test.xb.builder.object.attribute.javatypeadapter.support.StringWrapper;
+
+
+/**
+ * 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);
+ }
+
+ public void testAdaptedAttribute() throws Exception
+ {
+ Root root = unmarshalObject(Root.class);
+ StringWrapper attr = root.getAttr();
+ assertNotNull(attr);
+ assertEquals("val", attr.getValue());
+ }
+}
Added: jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/attribute/javatypeadapter/test/JavaTypeAdapter_testAdaptedAttribute.xml
===================================================================
--- jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/attribute/javatypeadapter/test/JavaTypeAdapter_testAdaptedAttribute.xml (rev 0)
+++ jbossxb/trunk/src/test/resources/org/jboss/test/xb/builder/object/attribute/javatypeadapter/test/JavaTypeAdapter_testAdaptedAttribute.xml 2010-03-04 08:52:08 UTC (rev 4082)
@@ -0,0 +1,3 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<root attr="val"/>
More information about the jboss-svn-commits
mailing list