[jboss-svn-commits] JBoss Common SVN: r2896 - in jbossxb/trunk/src: main/java/org/jboss/xb/builder and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Aug 7 09:30:38 EDT 2008
Author: alex.loubyansky at jboss.com
Date: 2008-08-07 09:30:38 -0400 (Thu, 07 Aug 2008)
New Revision: 2896
Modified:
jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlAdaptedType.java
jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlConstants.java
jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/Cardinality.java
jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/package-info.java
Log:
JBXB-125
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlAdaptedType.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlAdaptedType.java 2008-08-05 15:01:29 UTC (rev 2895)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlAdaptedType.java 2008-08-07 13:30:38 UTC (rev 2896)
@@ -45,7 +45,7 @@
String name() default JBossXmlConstants.DEFAULT;
/** The type */
- Class<?> type();
+ Class<?> type() default JBossXmlConstants.DEFAULT.class;
/** The value adapter */
Class<? extends ValueAdapter> valueAdapter();
Modified: jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlConstants.java
===================================================================
--- jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlConstants.java 2008-08-05 15:01:29 UTC (rev 2895)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/annotations/JBossXmlConstants.java 2008-08-07 13:30:38 UTC (rev 2896)
@@ -37,4 +37,9 @@
String MODEL_GROUP_CHOICE = "choice";
String MODEL_GROUP_ALL = "all";
+
+ class DEFAULT
+ {
+ private 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-08-05 15:01:29 UTC (rev 2895)
+++ jbossxb/trunk/src/main/java/org/jboss/xb/builder/JBossXBNoSchemaBuilder.java 2008-08-07 13:30:38 UTC (rev 2896)
@@ -88,6 +88,7 @@
import org.jboss.xb.annotations.JBossXmlPreserveWhitespace;
import org.jboss.xb.annotations.JBossXmlSchema;
import org.jboss.xb.annotations.JBossXmlType;
+import org.jboss.xb.binding.JBossXBRuntimeException;
import org.jboss.xb.binding.SimpleTypeBindings;
import org.jboss.xb.binding.sunday.unmarshalling.AllBinding;
import org.jboss.xb.binding.sunday.unmarshalling.AttributeBinding;
@@ -557,29 +558,25 @@
*/
public TypeBinding generateAdaptedType(JBossXmlAdaptedType adaptedType)
{
+ if(adaptedType.type() == JBossXmlConstants.DEFAULT.class)
+ throw new JBossXBRuntimeException("@JBossXmlAdaptedType used in package-info.java must specify type element.");
+
// Determine the parameters
String overrideNamespace = adaptedType.namespace();
String overrideName = adaptedType.name();
Class<?> type = adaptedType.type();
- Class<? extends ValueAdapter> adapter = adaptedType.valueAdapter();
try
{
-
TypeInfo typeInfo = JBossXBBuilder.configuration.getTypeInfo(type);
- BeanInfo adapterInfo = JBossXBBuilder.configuration.getBeanInfo(adapter);
- ValueAdapter valueAdapter = (ValueAdapter) adapterInfo.newInstance();
-
QName qName = generateXmlName(typeInfo, XmlNsForm.QUALIFIED, overrideNamespace, overrideName);
TypeInfo parentType = typeInfo.getTypeInfoFactory().getTypeInfo(String.class);
TypeBinding parent = getSimpleType(parentType);
-
TypeBinding typeBinding = new TypeBinding(qName, parent);
- typeBinding.setValueAdapter(valueAdapter);
- if (trace)
- log.trace("Created adapted type=" + typeInfo.getName() + " typeBinding=" + typeBinding + " adapter=" + adapter.getName());
+ adaptType(typeBinding, adaptedType);
+
typeCache.put(typeInfo, typeBinding);
schemaBinding.addType(typeBinding);
@@ -587,6 +584,33 @@
}
catch (Throwable t)
{
+ throw new RuntimeException("Unable to adapt type " + type.getName() + " with " + adaptedType.valueAdapter().getName(), t);
+ }
+ }
+
+ /**
+ * Generate an adapted type
+ *
+ * @param adaptedType the information about the adaption
+ * @return the type binding
+ */
+ public void adaptType(TypeBinding adaptedType, JBossXmlAdaptedType annotation)
+ {
+ // Determine the parameters
+ Class<?> type = annotation.type();
+ Class<? extends ValueAdapter> adapter = annotation.valueAdapter();
+ try
+ {
+ BeanInfo adapterInfo = JBossXBBuilder.configuration.getBeanInfo(adapter);
+
+ ValueAdapter valueAdapter = (ValueAdapter) adapterInfo.newInstance();
+
+ adaptedType.setValueAdapter(valueAdapter);
+ if (trace)
+ log.trace("adapted typeBinding=" + adaptedType + " adapter=" + adapter.getName());
+ }
+ catch (Throwable t)
+ {
throw new RuntimeException("Unable to adapt type " + type.getName() + " with " + adapter.getName(), t);
}
}
@@ -753,6 +777,7 @@
// Create the binding
TypeBinding typeBinding = null;
+
if (root)
{
QName qName = generateXmlName(typeInfo, XmlNsForm.QUALIFIED, overrideNamespace, overrideName);
@@ -766,6 +791,14 @@
// Push into the cache early to avoid recursion
typeCache.put(typeInfo, typeBinding);
+ JBossXmlAdaptedType adaptedType = typeInfo.getUnderlyingAnnotation(JBossXmlAdaptedType.class);
+ if(adaptedType != null)
+ {
+ if(adaptedType.type() != JBossXmlConstants.DEFAULT.class)
+ throw new JBossXBRuntimeException("@JBossXmlAdaptedType on a type must not specify type element: " + typeInfo.getName());
+ adaptType(typeBinding, adaptedType);
+ }
+
// Determine any factory method
MethodInfo factory = null;
if (factoryMethod != null && factoryMethod.length() > 0)
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/Cardinality.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/Cardinality.java 2008-08-05 15:01:29 UTC (rev 2895)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/Cardinality.java 2008-08-07 13:30:38 UTC (rev 2896)
@@ -23,14 +23,19 @@
import java.io.Serializable;
+import javax.xml.bind.annotation.XmlType;
+
import org.jboss.util.JBossObject;
import org.jboss.util.JBossStringBuilder;
+import org.jboss.xb.annotations.JBossXmlAdaptedType;
/**
* Cardinality def.
*
* @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
*/
+ at XmlType()
+ at JBossXmlAdaptedType(valueAdapter=CardinalityValueAdapter.class)
public class Cardinality extends JBossObject implements Serializable
{
private static final long serialVersionUID = 2L;
Modified: jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/package-info.java
===================================================================
--- jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/package-info.java 2008-08-05 15:01:29 UTC (rev 2895)
+++ jbossxb/trunk/src/test/java/org/jboss/test/xb/builder/object/mc/support/model/package-info.java 2008-08-07 13:30:38 UTC (rev 2896)
@@ -21,7 +21,7 @@
*/
@JBossXmlAdaptedTypes
({
- @JBossXmlAdaptedType(type=Cardinality.class, valueAdapter=CardinalityValueAdapter.class),
+ //@JBossXmlAdaptedType(type=Cardinality.class, valueAdapter=CardinalityValueAdapter.class),
@JBossXmlAdaptedType(type=ControllerMode.class, valueAdapter=ControllerModeValueAdapter.class),
@JBossXmlAdaptedType(type=ControllerState.class, valueAdapter=ControllerStateValueAdapter.class)
})
More information about the jboss-svn-commits
mailing list