aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/AnnotationsProcessor.java')
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/AnnotationsProcessor.java4566
1 files changed, 2304 insertions, 2262 deletions
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/AnnotationsProcessor.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/AnnotationsProcessor.java
index eed443d..1fe5aea 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/AnnotationsProcessor.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/compiler/AnnotationsProcessor.java
@@ -3,11 +3,11 @@
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v1.0 and Eclipse Distribution License v. 1.0
* which accompanies this distribution.
- * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
- * and the Eclipse Distribution License is available at
- * http://www.eclipse.org/org/documents/edl-v10.php.
- *
- * Contributors:
+ * The Eclipse Public License is available at http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ * http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
* Oracle - initial API and implementation from Oracle TopLink
******************************************************************************/
package org.eclipse.persistence.jaxb.compiler;
@@ -27,13 +27,12 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Map.Entry;
-import java.util.Set;
-
-import javax.xml.bind.JAXBElement;
-import javax.xml.bind.Marshaller;
-import javax.xml.bind.Unmarshaller;
-import javax.xml.bind.annotation.XmlAccessorOrder;
+import java.util.Map.Entry;
+import java.util.Set;
+
+import javax.xml.bind.Marshaller;
+import javax.xml.bind.Unmarshaller;
+import javax.xml.bind.annotation.XmlAccessorOrder;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyAttribute;
import javax.xml.bind.annotation.XmlAnyElement;
@@ -90,14 +89,30 @@ import org.eclipse.persistence.internal.libraries.asm.Label;
import org.eclipse.persistence.internal.libraries.asm.Type;
import org.eclipse.persistence.internal.oxm.Constants;
import org.eclipse.persistence.internal.oxm.Namespace;
-import org.eclipse.persistence.internal.oxm.XMLConversionManager;
-import org.eclipse.persistence.internal.oxm.XPathFragment;
-import org.eclipse.persistence.internal.oxm.mappings.Field;
-import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
-import org.eclipse.persistence.jaxb.TypeMappingInfo;
-import org.eclipse.persistence.jaxb.javamodel.AnnotationProxy;
-import org.eclipse.persistence.jaxb.javamodel.Helper;
-import org.eclipse.persistence.jaxb.javamodel.JavaAnnotation;
+import org.eclipse.persistence.internal.oxm.XMLConversionManager;
+import org.eclipse.persistence.internal.oxm.XPathFragment;
+import org.eclipse.persistence.internal.oxm.mappings.Field;
+import org.eclipse.persistence.jaxb.compiler.facets.DecimalMaxFacet;
+import org.eclipse.persistence.jaxb.compiler.facets.DecimalMinFacet;
+import org.eclipse.persistence.jaxb.compiler.facets.DigitsFacet;
+import org.eclipse.persistence.jaxb.compiler.facets.MaxFacet;
+import org.eclipse.persistence.jaxb.compiler.facets.MinFacet;
+import org.eclipse.persistence.jaxb.compiler.facets.PatternFacet;
+import org.eclipse.persistence.jaxb.compiler.facets.PatternListFacet;
+import org.eclipse.persistence.jaxb.compiler.facets.SizeFacet;
+import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
+import org.eclipse.persistence.jaxb.TypeMappingInfo;
+import javax.validation.constraints.DecimalMax;
+import javax.validation.constraints.DecimalMin;
+import javax.validation.constraints.Digits;
+import javax.validation.constraints.Max;
+import javax.validation.constraints.Min;
+import javax.validation.constraints.NotNull;
+import javax.validation.constraints.Pattern;
+import javax.validation.constraints.Size;
+import org.eclipse.persistence.jaxb.javamodel.AnnotationProxy;
+import org.eclipse.persistence.jaxb.javamodel.Helper;
+import org.eclipse.persistence.jaxb.javamodel.JavaAnnotation;
import org.eclipse.persistence.jaxb.javamodel.JavaClass;
import org.eclipse.persistence.jaxb.javamodel.JavaConstructor;
import org.eclipse.persistence.jaxb.javamodel.JavaField;
@@ -162,18 +177,18 @@ import org.eclipse.persistence.oxm.annotations.XmlWriteTransformers;
* <li>Centralize processing which is common to both Schema Generation and
* Mapping Generation tasks</li>
* <p>
- * This class does the initial processing of the JAXB 2.0 Generation. It
- * generates meta data that can be used by the later Schema Generation and
- * Mapping Generation steps.
- *
- * @see org.eclipse.persistence.jaxb.compiler.Generator
- * @author mmacivor
- * @since Oracle TopLink 11.1.1.0.0
- */
-public class AnnotationsProcessor {
- static final String JAVAX_ACTIVATION_DATAHANDLER = "javax.activation.DataHandler";
- static final String JAVAX_MAIL_INTERNET_MIMEMULTIPART = "javax.mail.internet.MimeMultipart";
- private static final String JAVAX_XML_BIND_JAXBELEMENT = "javax.xml.bind.JAXBElement";
+ * This class does the initial processing of the JAXB 2.0 Generation. It
+ * generates meta data that can be used by the later Schema Generation and
+ * Mapping Generation steps.
+ *
+ * @see org.eclipse.persistence.jaxb.compiler.Generator
+ * @author mmacivor
+ * @since Oracle TopLink 11.1.1.0.0
+ */
+public final class AnnotationsProcessor {
+ static final String JAVAX_ACTIVATION_DATAHANDLER = "javax.activation.DataHandler";
+ static final String JAVAX_MAIL_INTERNET_MIMEMULTIPART = "javax.mail.internet.MimeMultipart";
+ private static final String JAVAX_XML_BIND_JAXBELEMENT = "javax.xml.bind.JAXBElement";
private static final String JAVAX_XML_BIND_ANNOTATION = "javax.xml.bind.annotation";
private static final String OXM_ANNOTATIONS = "org.eclipse.persistence.oxm.annotations";
private static final String TYPE_METHOD_NAME = "type";
@@ -197,114 +212,114 @@ public class AnnotationsProcessor {
private static final String GET_STR = "get";
private static final String SET_STR = "set";
private static final Character DOT_CHR = '.';
- private static final Character DOLLAR_SIGN_CHR = '$';
- private static final Character SLASH_CHR = '/';
-
- private ArrayList<JavaClass> typeInfoClasses;
- private HashMap<String, PackageInfo> packageToPackageInfoMappings;
- private HashMap<String, MarshalCallback> marshalCallbacks;
- private HashMap<String, QName> userDefinedSchemaTypes;
- private HashMap<String, TypeInfo> typeInfo;
- private ArrayList<QName> typeQNames;
- private HashMap<String, UnmarshalCallback> unmarshalCallbacks;
- private HashMap<String, HashMap<QName, ElementDeclaration>> elementDeclarations;
- private HashMap<String, ElementDeclaration> xmlRootElements;
- private List<ElementDeclaration> localElements;
- private HashMap<String, JavaMethod> factoryMethods;
- private Map<String, org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry> xmlRegistries;
- private List<String> objectFactoryClassNames;
- private List<JavaClass> classesToProcessPropertyTypes;
+ private static final Character DOLLAR_SIGN_CHR = '$';
+ private static final Character SLASH_CHR = '/';
+
+ private List<JavaClass> typeInfoClasses;
+ private Map<String, PackageInfo> packageToPackageInfoMappings;
+ private Map<String, MarshalCallback> marshalCallbacks;
+ private Map<String, QName> userDefinedSchemaTypes;
+ private Map<String, TypeInfo> typeInfos;
+ private List<QName> typeQNames;
+ private Map<String, UnmarshalCallback> unmarshalCallbacks;
+ private Map<String, Map<QName, ElementDeclaration>> elementDeclarations;
+ private Map<String, ElementDeclaration> xmlRootElements;
+ private List<ElementDeclaration> localElements;
+ private Map<String, JavaMethod> factoryMethods;
+ private Map<String, org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry> xmlRegistries;
+ private List<String> objectFactoryClassNames;
+ private List<JavaClass> classesToProcessPropertyTypes;
private Map<String, Class> arrayClassesToGeneratedClasses;
- private Map<Class, JavaClass> generatedClassesToArrayClasses;
- private Map<java.lang.reflect.Type, Class> collectionClassesToGeneratedClasses;
- private Map<Class, java.lang.reflect.Type> generatedClassesToCollectionClasses;
-
- private Map<JavaClass, List<TypeMappingInfo>> javaClassToTypeMappingInfos;
- private Map<TypeMappingInfo, Class> typeMappingInfoToGeneratedClasses;
- private Map<TypeMappingInfo, Class> typeMappingInfoToAdapterClasses;
- private Map<TypeMappingInfo, QName> typeMappingInfoToSchemaType;
-
- private Helper helper;
- private String defaultTargetNamespace;
+ private Map<Class, JavaClass> generatedClassesToArrayClasses;
+ private Map<java.lang.reflect.Type, Class> collectionClassesToGeneratedClasses;
+ private Map<Class, java.lang.reflect.Type> generatedClassesToCollectionClasses;
+ private Map<JavaClass, List<TypeMappingInfo>> javaClassToTypeMappingInfos;
+ private Map<TypeMappingInfo, Class> typeMappingInfosToGeneratedClasses;
+ private Map<TypeMappingInfo, Class> typeMappingInfoToAdapterClasses;
+ private Map<TypeMappingInfo, QName> typeMappingInfosToSchemaTypes;
+
+ private Helper helper;
+ private String defaultTargetNamespace;
private JAXBMetadataLogger logger;
private boolean isDefaultNamespaceAllowed;
- private boolean xmlAccessorFactorySupport;
-
- private boolean hasSwaRef;
-
- private List<String> referencedByTransformer;
- private boolean hasXmlBindings = false;
-
- public AnnotationsProcessor(Helper helper) {
- this.helper = helper;
- isDefaultNamespaceAllowed = true;
- hasSwaRef = false;
- }
+ private boolean xmlAccessorFactorySupport;
+
+ private boolean hasSwaRef;
+
+ private List<String> referencedByTransformer;
+ private boolean hasXmlBindings = false;
+ private boolean facets;
+
+ public AnnotationsProcessor(Helper helper) {
+ this.helper = helper;
+ this.facets = helper.isFacets();
+ isDefaultNamespaceAllowed = true;
+ hasSwaRef = false;
+ }
/**
* This event is called when annotation processing is completed,
* and provides a chance to deference anything that is no longer
* needed (to reduce the memory footprint of this object).
*/
- void postInitialize() {
- typeInfoClasses = null;
- packageToPackageInfoMappings = null;
- typeInfo = null;
- typeQNames = null;
- elementDeclarations = null;
- xmlRootElements = null;
+ void postInitialize() {
+ typeInfoClasses = null;
+ packageToPackageInfoMappings = null;
+ typeInfos = null;
+ typeQNames = null;
+ elementDeclarations = null;
+ xmlRootElements = null;
localElements = null;
factoryMethods = null;
xmlRegistries = null;
- objectFactoryClassNames = null;
- classesToProcessPropertyTypes = null;
- javaClassToTypeMappingInfos = null;
- typeMappingInfoToGeneratedClasses = null;
- typeMappingInfoToAdapterClasses = null;
- helper = null;
- logger = null;
+ objectFactoryClassNames = null;
+ classesToProcessPropertyTypes = null;
+ javaClassToTypeMappingInfos = null;
+ typeMappingInfosToGeneratedClasses = null;
+ typeMappingInfoToAdapterClasses = null;
+ helper = null;
+ logger = null;
referencedByTransformer = null;
}
-
- /**
- * Generate TypeInfo instances for a given array of JavaClasses.
- *
- * @param classes
- */
- void processClassesAndProperties(JavaClass[] classes, TypeMappingInfo[] typeMappingInfos) {
- init(classes, typeMappingInfos);
- preBuildTypeInfo(classes);
- classes = postBuildTypeInfo(classes);
- processPropertyTypes(this.typeInfoClasses.toArray(new JavaClass[this.typeInfoClasses.size()]));
- finalizeProperties();
- createElementsForTypeMappingInfo();
- processJavaClasses(null);
- }
-
- public void createElementsForTypeMappingInfo() {
- if (this.javaClassToTypeMappingInfos != null && !this.javaClassToTypeMappingInfos.isEmpty()) {
- Set<JavaClass> classes = this.javaClassToTypeMappingInfos.keySet();
- for (JavaClass nextClass : classes) {
- List<TypeMappingInfo> nextInfos = this.javaClassToTypeMappingInfos.get(nextClass);
+
+ /**
+ * Generate TypeInfo instances for a given array of JavaClasses.
+ *
+ * @param classes
+ */
+ void processClassesAndProperties(JavaClass[] classes, TypeMappingInfo[] typeMappingInfos) {
+ init(classes, typeMappingInfos);
+ preBuildTypeInfo(classes);
+ postBuildTypeInfo(classes);
+ processPropertyTypes(this.typeInfoClasses.toArray(new JavaClass[this.typeInfoClasses.size()]));
+ finalizeProperties();
+ createElementsForTypeMappingInfo();
+ checkForCallbackMethods();
+ }
+
+ public void createElementsForTypeMappingInfo() {
+ if (javaClassToTypeMappingInfos != null && !javaClassToTypeMappingInfos.isEmpty()) {
+ Set<JavaClass> classes = this.javaClassToTypeMappingInfos.keySet();
+ for (JavaClass nextClass : classes) {
+ List<TypeMappingInfo> nextInfos = this.javaClassToTypeMappingInfos.get(nextClass);
for(TypeMappingInfo nextInfo:nextInfos) {
if (nextInfo != null) {
- boolean xmlAttachmentRef = false;
- String xmlMimeType = null;
- java.lang.annotation.Annotation[] annotations = getAnnotations(nextInfo);
- Class adapterClass = this.typeMappingInfoToAdapterClasses.get(nextInfo);
- Class declJavaType = null;
- if (adapterClass != null) {
- declJavaType = CompilerHelper.getTypeFromAdapterClass(adapterClass);
- }
- if (annotations != null) {
- for (int j = 0; j < annotations.length; j++) {
- java.lang.annotation.Annotation nextAnnotation = annotations[j];
- if (nextAnnotation != null) {
- if (nextAnnotation instanceof XmlMimeType) {
- XmlMimeType javaAnnotation = (XmlMimeType) nextAnnotation;
+ boolean xmlAttachmentRef = false;
+ String xmlMimeType = null;
+ java.lang.annotation.Annotation[] annotations = getAnnotations(nextInfo);
+ Class adapterClass = typeMappingInfoToAdapterClasses.get(nextInfo);
+ Class declJavaType = null;
+ if (adapterClass != null) {
+ declJavaType = CompilerHelper.getTypeFromAdapterClass(adapterClass);
+ }
+ if (annotations != null) {
+ for (Annotation nextAnnotation : annotations) {
+ if (nextAnnotation != null) {
+ if (nextAnnotation instanceof XmlMimeType) {
+ XmlMimeType javaAnnotation = (XmlMimeType) nextAnnotation;
xmlMimeType = javaAnnotation.value();
} else if (nextAnnotation instanceof XmlAttachmentRef) {
xmlAttachmentRef = true;
@@ -313,28 +328,28 @@ public class AnnotationsProcessor {
}
}
}
- }
- }
-
- QName qname = null;
-
- String nextClassName = nextClass.getQualifiedName();
-
+ }
+ }
+
+ QName qname;
+
+ String nextClassName = nextClass.getQualifiedName();
+
if (declJavaType != null) {
- nextClassName = declJavaType.getCanonicalName();
- }
-
- if (typeMappingInfoToGeneratedClasses != null) {
- Class generatedClass = typeMappingInfoToGeneratedClasses.get(nextInfo);
- if (generatedClass != null) {
- nextClassName = generatedClass.getCanonicalName();
- }
- }
-
- TypeInfo nextTypeInfo = typeInfo.get(nextClassName);
- if (nextTypeInfo != null) {
- qname = new QName(nextTypeInfo.getClassNamespace(), nextTypeInfo.getSchemaTypeName());
- } else {
+ nextClassName = declJavaType.getCanonicalName();
+ }
+
+ if (typeMappingInfosToGeneratedClasses != null) {
+ Class generatedClass = typeMappingInfosToGeneratedClasses.get(nextInfo);
+ if (generatedClass != null) {
+ nextClassName = generatedClass.getCanonicalName();
+ }
+ }
+
+ TypeInfo nextTypeInfo = typeInfos.get(nextClassName);
+ if (nextTypeInfo != null) {
+ qname = new QName(nextTypeInfo.getClassNamespace(), nextTypeInfo.getSchemaTypeName());
+ } else {
qname = getUserDefinedSchemaTypes().get(nextClassName);
if (qname == null) {
if (nextClassName.equals(ClassConstants.APBYTE.getName()) || nextClassName.equals(Image.class.getName()) || nextClassName.equals(Source.class.getName()) || nextClassName.equals("javax.activation.DataHandler")) {
@@ -352,37 +367,37 @@ public class AnnotationsProcessor {
qname = (QName) XMLConversionManager.getDefaultJavaTypes().get(theClass);
}
}
- }
-
- if (qname != null) {
- typeMappingInfoToSchemaType.put(nextInfo, qname);
- }
-
- if (nextInfo.getXmlTagName() != null) {
+ }
+
+ if (qname != null) {
+ typeMappingInfosToSchemaTypes.put(nextInfo, qname);
+ }
+
+ if (nextInfo.getXmlTagName() != null) {
ElementDeclaration element = new ElementDeclaration(nextInfo.getXmlTagName(), nextClass, nextClass.getQualifiedName(), false);
element.setTypeMappingInfo(nextInfo);
element.setXmlMimeType(xmlMimeType);
element.setXmlAttachmentRef(xmlAttachmentRef);
element.setNillable(nextInfo.isNillable());
- if (declJavaType != null) {
- element.setJavaType(helper.getJavaClass(declJavaType));
- }
- Class generatedClass = typeMappingInfoToGeneratedClasses.get(nextInfo);
- if (generatedClass != null) {
- element.setJavaType(helper.getJavaClass(generatedClass));
- }
+ if (declJavaType != null) {
+ element.setJavaType(helper.getJavaClass(declJavaType));
+ }
+ Class generatedClass = typeMappingInfosToGeneratedClasses.get(nextInfo);
+ if (generatedClass != null) {
+ element.setJavaType(helper.getJavaClass(generatedClass));
+ }
if (nextInfo.getElementScope() == TypeMappingInfo.ElementScope.Global) {
ElementDeclaration currentElement = this.getGlobalElements().get(element.getElementName());
if (currentElement == null) {
addGlobalElement(element.getElementName(), element);
- } else {
- // if(currentElement.getTypeMappingInfo() == null) {
- // the global element that exists came from an annotation
-
- //} else {
- this.localElements.add(element);
- //}
+ } else {
+ // if(currentElement.getTypeMappingInfo() == null) {
+ // the global element that exists came from an annotation
+
+ //} else {
+ this.localElements.add(element);
+ //}
}
} else {
this.localElements.add(element);
@@ -404,33 +419,33 @@ public class AnnotationsProcessor {
/**
* Returns an array of Annotations for a given TypeMappingInfo. This array
* will either be populated from the TypeMappingInfo's array of annotations,
- * or based on an xml-element if present. The xml-element will take
- * precedence over the annotation array; if there is an xml-element the
- * Array of Annotations will be ignored.
- *
- * @param tmInfo
- * @return
- */
+ * or based on an xml-element if present. The xml-element will take
+ * precedence over the annotation array; if there is an xml-element the
+ * Array of Annotations will be ignored.
+ *
+ * @param tmInfo
+ * @return
+ */
private java.lang.annotation.Annotation[] getAnnotations(TypeMappingInfo tmInfo) {
if (tmInfo.getXmlElement() != null) {
ClassLoader loader = helper.getClassLoader();
// create a single ConversionManager for that will be shared by the
// proxy objects
ConversionManager cMgr = new ConversionManager();
- cMgr.setLoader(loader);
-
- // unmarshal the node into an XmlElement
- org.eclipse.persistence.jaxb.xmlmodel.XmlElement xElt = (org.eclipse.persistence.jaxb.xmlmodel.XmlElement) CompilerHelper.getXmlElement(tmInfo.getXmlElement(), loader);
- List annotations = new ArrayList();
- // where applicable, a given dynamic proxy will contain a Map of
- // method name/return value entries
- Map<String, Object> components = null;
- // handle @XmlElement: set 'type' method
- if (!(xElt.getType().equals("javax.xml.bind.annotation.XmlElement.DEFAULT"))) {
- components = new HashMap();
- components.put(TYPE_METHOD_NAME, xElt.getType());
- annotations.add(AnnotationProxy.getProxy(components, XmlElement.class, loader, cMgr));
- }
+ cMgr.setLoader(loader);
+
+ // unmarshal the node into an XmlElement
+ org.eclipse.persistence.jaxb.xmlmodel.XmlElement xElt = CompilerHelper.getXmlElement(tmInfo.getXmlElement(), loader);
+ List annotations = new ArrayList();
+ // where applicable, a given dynamic proxy will contain a Map of
+ // method name/return value entries
+ Map<String, Object> components = null;
+ // handle @XmlElement: set 'type' method
+ if (!(xElt.getType().equals("javax.xml.bind.annotation.XmlElement.DEFAULT"))) {
+ components = new HashMap<String, Object>();
+ components.put(TYPE_METHOD_NAME, xElt.getType());
+ annotations.add(AnnotationProxy.getProxy(components, XmlElement.class, loader, cMgr));
+ }
// handle @XmlList
if (xElt.isXmlList()) {
annotations.add(AnnotationProxy.getProxy(components, XmlList.class, loader, cMgr));
@@ -438,19 +453,19 @@ public class AnnotationsProcessor {
// handle @XmlAttachmentRef
if (xElt.isXmlAttachmentRef()) {
annotations.add(AnnotationProxy.getProxy(components, XmlAttachmentRef.class, loader, cMgr));
- }
- // handle @XmlMimeType: set 'value' method
- if (xElt.getXmlMimeType() != null) {
- components = new HashMap();
- components.put(VALUE_METHOD_NAME, xElt.getXmlMimeType());
- annotations.add(AnnotationProxy.getProxy(components, XmlMimeType.class, loader, cMgr));
- }
- // handle @XmlJavaTypeAdapter: set 'type' and 'value' methods
- if (xElt.getXmlJavaTypeAdapter() != null) {
- components = new HashMap();
- components.put(TYPE_METHOD_NAME, xElt.getXmlJavaTypeAdapter().getType());
- components.put(VALUE_METHOD_NAME, xElt.getXmlJavaTypeAdapter().getValue());
- annotations.add(AnnotationProxy.getProxy(components, XmlJavaTypeAdapter.class, loader, cMgr));
+ }
+ // handle @XmlMimeType: set 'value' method
+ if (xElt.getXmlMimeType() != null) {
+ components = new HashMap<String, Object>();
+ components.put(VALUE_METHOD_NAME, xElt.getXmlMimeType());
+ annotations.add(AnnotationProxy.getProxy(components, XmlMimeType.class, loader, cMgr));
+ }
+ // handle @XmlJavaTypeAdapter: set 'type' and 'value' methods
+ if (xElt.getXmlJavaTypeAdapter() != null) {
+ components = new HashMap<String, Object>();
+ components.put(TYPE_METHOD_NAME, xElt.getXmlJavaTypeAdapter().getType());
+ components.put(VALUE_METHOD_NAME, xElt.getXmlJavaTypeAdapter().getValue());
+ annotations.add(AnnotationProxy.getProxy(components, XmlJavaTypeAdapter.class, loader, cMgr));
}
// return the newly created array of dynamic proxy objects
return (java.lang.annotation.Annotation[]) annotations.toArray(new java.lang.annotation.Annotation[annotations.size()]);
@@ -464,13 +479,13 @@ public class AnnotationsProcessor {
* Initialize maps, lists, etc. Typically called prior to processing a set
* of classes via preBuildTypeInfo, postBuildTypeInfo, processJavaClasses.
*/
- void init(JavaClass[] classes, TypeMappingInfo[] typeMappingInfos) {
- typeInfoClasses = new ArrayList<JavaClass>();
- referencedByTransformer = new ArrayList<String>();
- typeInfo = new HashMap<String, TypeInfo>();
- typeQNames = new ArrayList<QName>();
- classesToProcessPropertyTypes = new ArrayList<JavaClass>();
- objectFactoryClassNames = new ArrayList<String>();
+ void init(JavaClass[] classes, TypeMappingInfo[] typeMappingInfos) {
+ typeInfoClasses = new ArrayList<JavaClass>();
+ referencedByTransformer = new ArrayList<String>();
+ typeInfos = new HashMap<String, TypeInfo>();
+ typeQNames = new ArrayList<QName>();
+ classesToProcessPropertyTypes = new ArrayList<JavaClass>();
+ objectFactoryClassNames = new ArrayList<String>();
userDefinedSchemaTypes = new HashMap<String, QName>();
if (packageToPackageInfoMappings == null) {
packageToPackageInfoMappings = new HashMap<String, PackageInfo>();
@@ -480,16 +495,16 @@ public class AnnotationsProcessor {
this.xmlRootElements = new HashMap<String, ElementDeclaration>();
arrayClassesToGeneratedClasses = new HashMap<String, Class>();
- collectionClassesToGeneratedClasses = new HashMap<java.lang.reflect.Type, Class>();
- generatedClassesToArrayClasses = new HashMap<Class, JavaClass>();
- generatedClassesToCollectionClasses = new HashMap<Class, java.lang.reflect.Type>();
- typeMappingInfoToGeneratedClasses = new HashMap<TypeMappingInfo, Class>();
- typeMappingInfoToSchemaType = new HashMap<TypeMappingInfo, QName>();
- elementDeclarations = new HashMap<String, HashMap<QName, ElementDeclaration>>();
- HashMap globalElements = new HashMap<QName, ElementDeclaration>();
- elementDeclarations.put(XmlElementDecl.GLOBAL.class.getName(), globalElements);
- localElements = new ArrayList<ElementDeclaration>();
-
+ collectionClassesToGeneratedClasses = new HashMap<java.lang.reflect.Type, Class>();
+ generatedClassesToArrayClasses = new HashMap<Class, JavaClass>();
+ generatedClassesToCollectionClasses = new HashMap<Class, java.lang.reflect.Type>();
+ typeMappingInfosToGeneratedClasses = new HashMap<TypeMappingInfo, Class>();
+ typeMappingInfosToSchemaTypes = new HashMap<TypeMappingInfo, QName>();
+ elementDeclarations = new HashMap<String, Map<QName, ElementDeclaration>>();
+ Map globalElements = new HashMap<QName, ElementDeclaration>();
+ elementDeclarations.put(XmlElementDecl.GLOBAL.class.getName(), globalElements);
+ localElements = new ArrayList<ElementDeclaration>();
+
javaClassToTypeMappingInfos = new HashMap<JavaClass, List<TypeMappingInfo>>();
if (typeMappingInfos != null) {
for (int i = 0; i < typeMappingInfos.length; i++) {
@@ -518,20 +533,20 @@ public class AnnotationsProcessor {
/**
* Process class level annotations only. It is assumed that a call to init()
- * has been made prior to calling this method. After the types created via
- * this method have been modified (if necessary) postBuildTypeInfo and
- * processJavaClasses should be called to finish processing.
- *
- * @param javaClasses
- * @return
- */
- public Map<String, TypeInfo> preBuildTypeInfo(JavaClass[] javaClasses) {
- for (JavaClass javaClass : javaClasses) {
- String qualifiedName = javaClass.getQualifiedName();
- TypeInfo info = typeInfo.get(qualifiedName);
- if (javaClass == null || javaClass.isArray()|| (info!=null && info.isPreBuilt()) || !shouldGenerateTypeInfo(javaClass) || isXmlRegistry(javaClass) ) {
- continue;
- }
+ * has been made prior to calling this method. After the types created via
+ * this method have been modified (if necessary) postBuildTypeInfo and
+ * processJavaClasses should be called to finish processing.
+ *
+ * @param javaClasses
+ * @return
+ */
+ public Map<String, TypeInfo> preBuildTypeInfo(JavaClass[] javaClasses) {
+ for (JavaClass javaClass : javaClasses) {
+ String qualifiedName = javaClass.getQualifiedName();
+ TypeInfo info = typeInfos.get(qualifiedName);
+ if (javaClass == null || javaClass.isArray()|| (info!=null && info.isPreBuilt()) || !shouldGenerateTypeInfo(javaClass) || isXmlRegistry(javaClass) ) {
+ continue;
+ }
if (javaClass.isEnum()) {
@@ -551,28 +566,28 @@ public class AnnotationsProcessor {
processXmlExtensible(javaClass, info);
// handle @XmlInlineBinaryData
- if (helper.isAnnotationPresent(javaClass, XmlInlineBinaryData.class)) {
- info.setInlineBinaryData(true);
- }
-
- // handle @NamedObjectGraph
- processNamedObjectGraphs(javaClass, info);
-
+ if (helper.isAnnotationPresent(javaClass, XmlInlineBinaryData.class)) {
+ info.setInlineBinaryData(true);
+ }
+
+ // handle @NamedObjectGraph
+ processNamedObjectGraphs(javaClass, info);
+
// handle @XmlRootElement
processXmlRootElement(javaClass, info);
// handle @XmlSeeAlso
processXmlSeeAlso(javaClass, info);
-
- PackageInfo packageInfo = getPackageInfoForPackage(javaClass);
- if(packageInfo != null && packageInfo.getPackageLevelAdaptersByClass().size() > 0){
- for(String adapterClass :packageInfo.getPackageLevelAdaptersByClass().keySet()){
- JavaClass boundType = packageInfo.getPackageLevelAdaptersByClass().get(adapterClass);
- info.getPackageLevelAdaptersByClass().put(adapterClass, boundType);
- }
- }
- NamespaceInfo namespaceInfo = packageInfo.getNamespaceInfo();
- // handle @XmlType
+
+ PackageInfo packageInfo = getPackageInfoForPackage(javaClass);
+ if(packageInfo != null && packageInfo.getPackageLevelAdaptersByClass().size() > 0){
+ for(String adapterClass :packageInfo.getPackageLevelAdaptersByClass().keySet()){
+ JavaClass boundType = packageInfo.getPackageLevelAdaptersByClass().get(adapterClass);
+ info.getPackageLevelAdaptersByClass().put(adapterClass, boundType);
+ }
+ }
+ NamespaceInfo namespaceInfo = packageInfo.getNamespaceInfo();
+ // handle @XmlType
preProcessXmlType(javaClass, info, namespaceInfo);
// handle @XmlAccessorType
@@ -580,13 +595,13 @@ public class AnnotationsProcessor {
// handle @XmlAccessorOrder
preProcessXmlAccessorOrder(javaClass, info, namespaceInfo);
-
- // handle package level @XmlJavaTypeAdapters
- processPackageLevelAdapters(javaClass, info);
-
- // handle Accessor Factory
- processAccessorFactory(javaClass, info);
-
+
+ // handle package level @XmlJavaTypeAdapters
+ processPackageLevelAdapters(javaClass, info);
+
+ // handle Accessor Factory
+ processAccessorFactory(javaClass, info);
+
// handle class level @XmlJavaTypeAdapters
processClassLevelAdapters(javaClass, info);
@@ -622,29 +637,27 @@ public class AnnotationsProcessor {
if (helper.isAnnotationPresent(javaClass, XmlDiscriminatorValue.class)) {
XmlDiscriminatorValue xmlDiscriminatorValue = (XmlDiscriminatorValue) helper.getAnnotation(javaClass, XmlDiscriminatorValue.class);
info.setXmlDiscriminatorValue(xmlDiscriminatorValue.value());
- }
-
- typeInfoClasses.add(javaClass);
- typeInfo.put(info.getJavaClassName(), info);
- }
- return typeInfo;
- }
-
- private void processNamedObjectGraphs(JavaClass javaClass, TypeInfo info) {
- ArrayList<XmlNamedObjectGraph> objectGraphs = new ArrayList<XmlNamedObjectGraph>();
- if(helper.isAnnotationPresent(javaClass, XmlNamedObjectGraphs.class)) {
- XmlNamedObjectGraphs graphs = (XmlNamedObjectGraphs)helper.getAnnotation(javaClass, XmlNamedObjectGraphs.class);
- for(XmlNamedObjectGraph next: graphs.value()) {
- objectGraphs.add(next);
- }
- }
- if(helper.isAnnotationPresent(javaClass, XmlNamedObjectGraph.class)) {
- objectGraphs.add((XmlNamedObjectGraph)helper.getAnnotation(javaClass, XmlNamedObjectGraph.class));
- }
-
- for(XmlNamedObjectGraph next:objectGraphs) {
- org.eclipse.persistence.jaxb.xmlmodel.XmlNamedObjectGraph namedGraph = new org.eclipse.persistence.jaxb.xmlmodel.XmlNamedObjectGraph();
- namedGraph.setName(next.name());
+ }
+
+ typeInfoClasses.add(javaClass);
+ typeInfos.put(info.getJavaClassName(), info);
+ }
+ return typeInfos;
+ }
+
+ private void processNamedObjectGraphs(JavaClass javaClass, TypeInfo info) {
+ List<XmlNamedObjectGraph> objectGraphs = new ArrayList<XmlNamedObjectGraph>();
+ if(helper.isAnnotationPresent(javaClass, XmlNamedObjectGraphs.class)) {
+ XmlNamedObjectGraphs graphs = (XmlNamedObjectGraphs)helper.getAnnotation(javaClass, XmlNamedObjectGraphs.class);
+ Collections.addAll(objectGraphs, graphs.value());
+ }
+ if(helper.isAnnotationPresent(javaClass, XmlNamedObjectGraph.class)) {
+ objectGraphs.add((XmlNamedObjectGraph)helper.getAnnotation(javaClass, XmlNamedObjectGraph.class));
+ }
+
+ for(XmlNamedObjectGraph next:objectGraphs) {
+ org.eclipse.persistence.jaxb.xmlmodel.XmlNamedObjectGraph namedGraph = new org.eclipse.persistence.jaxb.xmlmodel.XmlNamedObjectGraph();
+ namedGraph.setName(next.name());
for(XmlNamedAttributeNode nextNode:next.attributeNodes()) {
org.eclipse.persistence.jaxb.xmlmodel.XmlNamedAttributeNode namedNode = new org.eclipse.persistence.jaxb.xmlmodel.XmlNamedAttributeNode();
@@ -710,64 +723,61 @@ public class AnnotationsProcessor {
info.setPackageLevelXmlAccessorFactory(pInfo.getAccessorFactory());
}
}
-
- /**
- * Process any additional classes (i.e. inner classes, @XmlSeeAlso,
- *
- * @XmlRegistry, etc.) for a given set of JavaClasses, then complete
- * building all of the required TypeInfo objects. This method
- * is typically called after init and preBuildTypeInfo have
- * been called.
- *
- * @param javaClasses
- * @return updated array of JavaClasses, made up of the original classes
- * plus any additional ones
- */
- public JavaClass[] postBuildTypeInfo(JavaClass[] javaClasses) {
- if (javaClasses.length == 0) {
- return javaClasses;
- }
- ArrayList<JavaClass> originalList = new ArrayList<JavaClass>(javaClasses.length);
- for(JavaClass next:javaClasses) {
- originalList.add(next);
- }
- // create type info instances for any additional classes
- javaClasses = processAdditionalClasses(javaClasses);
- preBuildTypeInfo(javaClasses);
- buildTypeInfo(javaClasses);
- updateGlobalElements(javaClasses);
- if(javaClasses.length > originalList.size()) {
- ArrayList<JavaClass> newClasses = new ArrayList(javaClasses.length - originalList.size());
- for(JavaClass next:javaClasses) {
- if(!(originalList.contains(next))) {
- newClasses.add(next);
+
+ /**
+ * Process any additional classes (i.e. inner classes, @XmlSeeAlso,
+ *
+ * @XmlRegistry, etc.) for a given set of JavaClasses, then complete
+ * building all of the required TypeInfo objects. This method
+ * is typically called after init and preBuildTypeInfo have
+ * been called.
+ *
+ * @param javaClasses
+ * @return updated array of JavaClasses, made up of the original classes
+ * plus any additional ones
+ */
+ public JavaClass[] postBuildTypeInfo(JavaClass[] javaClasses) {
+ if (javaClasses.length == 0) {
+ return javaClasses;
+ }
+ List<JavaClass> originalList = Arrays.asList(javaClasses);
+ // create type info instances for any additional classes
+ javaClasses = processAdditionalClasses(javaClasses);
+ preBuildTypeInfo(javaClasses);
+ buildTypeInfo(javaClasses);
+ updateGlobalElements(javaClasses);
+ if(javaClasses.length > originalList.size()) {
+ List<JavaClass> newClasses = new ArrayList<JavaClass>(javaClasses.length - originalList.size());
+ for(JavaClass next:javaClasses) {
+ if(!(originalList.contains(next))) {
+ newClasses.add(next);
}
}
postBuildTypeInfo(newClasses.toArray(new JavaClass[newClasses.size()]));
}
return javaClasses;
}
-
- /**
- * INTERNAL:
- *
- * Complete building TypeInfo objects for a given set of JavaClass
- * instances. This method assumes that init, preBuildTypeInfo, and
- * postBuildTypeInfo have been called.
- *
- * @param allClasses
- * @return
- */
+
+ /**
+ * INTERNAL:
+ *
+ * Complete building TypeInfo objects for a given set of JavaClass
+ * instances. This method assumes that init, preBuildTypeInfo, and
+ * postBuildTypeInfo have been called.
+ *
+ * @param allClasses
+ * @return
+ */
private Map<String, TypeInfo> buildTypeInfo(JavaClass[] allClasses) {
for (JavaClass javaClass : allClasses) {
if (javaClass == null) {
- continue;
- }
-
- TypeInfo info = typeInfo.get(javaClass.getQualifiedName());
- if (info == null || info.isPostBuilt()) {
- continue;
- }
+ continue;
+ }
+
+ TypeInfo info = typeInfos.get(javaClass.getQualifiedName());
+ if (info == null || info.isPostBuilt()) {
+ continue;
+ }
info.setPostBuilt(true);
// handle factory methods
@@ -779,24 +789,24 @@ public class AnnotationsProcessor {
if(transformer == TypeInfo.DEFAULT_NAME_TRANSFORMER){
XMLNameTransformer nsInfoXmlNameTransformer = packageInfo.getXmlNameTransformer();
- if (nsInfoXmlNameTransformer != null) {
- info.setXmlNameTransformer(nsInfoXmlNameTransformer);
- } else if (helper.isAnnotationPresent(javaClass, XmlNameTransformer.class)) {
- XmlNameTransformer nameTranformer = (XmlNameTransformer) helper.getAnnotation(javaClass, XmlNameTransformer.class);
- Class nameTransformerClass = nameTranformer.value();
- try {
- info.setXmlNameTransformer((XMLNameTransformer) nameTransformerClass.newInstance());
- } catch (InstantiationException ex) {
+ if (nsInfoXmlNameTransformer != null) {
+ info.setXmlNameTransformer(nsInfoXmlNameTransformer);
+ } else if (helper.isAnnotationPresent(javaClass, XmlNameTransformer.class)) {
+ XmlNameTransformer xmlNameTransformer = (XmlNameTransformer) helper.getAnnotation(javaClass, XmlNameTransformer.class);
+ Class nameTransformerClass = xmlNameTransformer.value();
+ try {
+ info.setXmlNameTransformer((XMLNameTransformer) nameTransformerClass.newInstance());
+ } catch (InstantiationException ex) {
throw JAXBException.exceptionWithNameTransformerClass(nameTransformerClass.getName(), ex);
} catch (IllegalAccessException ex) {
- throw JAXBException.exceptionWithNameTransformerClass(nameTransformerClass.getName(), ex);
- }
- } else if (helper.isAnnotationPresent(javaClass.getPackage(), XmlNameTransformer.class)) {
- XmlNameTransformer nameTranformer = (XmlNameTransformer) helper.getAnnotation(javaClass.getPackage(), XmlNameTransformer.class);
- Class nameTransformerClass = nameTranformer.value();
- try {
- info.setXmlNameTransformer((XMLNameTransformer) nameTransformerClass.newInstance());
- } catch (InstantiationException ex) {
+ throw JAXBException.exceptionWithNameTransformerClass(nameTransformerClass.getName(), ex);
+ }
+ } else if (helper.isAnnotationPresent(javaClass.getPackage(), XmlNameTransformer.class)) {
+ XmlNameTransformer xmlNameTransformer = (XmlNameTransformer) helper.getAnnotation(javaClass.getPackage(), XmlNameTransformer.class);
+ Class nameTransformerClass = xmlNameTransformer.value();
+ try {
+ info.setXmlNameTransformer((XMLNameTransformer) nameTransformerClass.newInstance());
+ } catch (InstantiationException ex) {
throw JAXBException.exceptionWithNameTransformerClass(nameTransformerClass.getName(), ex);
} catch (IllegalAccessException ex) {
throw JAXBException.exceptionWithNameTransformerClass(nameTransformerClass.getName(), ex);
@@ -817,13 +827,13 @@ public class AnnotationsProcessor {
}
// process schema type name
- processTypeQName(javaClass, info, packageInfo.getNamespaceInfo());
-
- // handle superclass if necessary
- JavaClass superClass = (JavaClass) javaClass.getSuperclass();
- processReferencedClass(superClass);
- processPropertiesSuperClass(javaClass, info);
-
+ processTypeQName(javaClass, info, packageInfo.getNamespaceInfo());
+
+ // handle superclass if necessary
+ JavaClass superClass = javaClass.getSuperclass();
+ processReferencedClass(superClass);
+ processPropertiesSuperClass(javaClass, info);
+
// add properties
info.setProperties(getPropertiesForClass(javaClass, info));
@@ -832,159 +842,156 @@ public class AnnotationsProcessor {
// handle @XmlAccessorOrder
postProcessXmlAccessorOrder(info, packageInfo);
+
+ validatePropOrderForInfo(info);
+ }
+ return typeInfos;
+ }
+
+ private TypeInfo processReferencedClass(JavaClass referencedClass){
+ if (shouldGenerateTypeInfo(referencedClass)) {
+ TypeInfo existingInfo = typeInfos.get(referencedClass.getQualifiedName());
+ if (existingInfo == null || !existingInfo.isPreBuilt()) {
+ PackageInfo pInfo = getPackageInfoForPackage(referencedClass);
+ JavaClass adapterClass = pInfo.getPackageLevelAdaptersByClass().get(referencedClass);
+ if (adapterClass == null) {
+ CompilerHelper.addClassToClassLoader(referencedClass, helper.getClassLoader());
+ JavaClass[] jClassArray = new JavaClass[] { referencedClass };
+ buildNewTypeInfo(jClassArray);
+ }
+ return typeInfos.get(referencedClass.getQualifiedName());
+ } else {
+ if (!existingInfo.isPostBuilt()) {
+ PackageInfo pInfo = getPackageInfoForPackage(referencedClass);
+ JavaClass adapterClass = pInfo.getPackageLevelAdaptersByClass().get(referencedClass);
+ if (adapterClass == null) {
+ CompilerHelper.addClassToClassLoader(referencedClass, helper.getClassLoader());
+ JavaClass[] javaClasses = new JavaClass[] { referencedClass };
+ javaClasses = postBuildTypeInfo(javaClasses);
+ for(JavaClass next:javaClasses) {
+ processPropertyTypes(next);
+ }
+ }
+ }
+ return existingInfo;
+ }
+ }
+ return null;
+ }
+
+ /*
+ * Get virtual property and XmlID information from parent and set it on info if available
+ */
+ public void processPropertiesSuperClass(JavaClass cls, TypeInfo info) {
+ JavaClass superClass = cls.getSuperclass();
+ if (superClass == null) {
+ return;
+ }
+ TypeInfo superClassInfo = this.typeInfos.get(superClass.getQualifiedName());
+ if(superClassInfo != null) {
+ processPropertiesSuperClass(superClass, superClassInfo);
+ classesToProcessPropertyTypes.add(superClass);
+ if(superClassInfo.getXmlVirtualAccessMethods() != null && info.getXmlVirtualAccessMethods() == null) {
+ info.setXmlVirtualAccessMethods(superClassInfo.getXmlVirtualAccessMethods());
+ }
+ if(superClassInfo.isIDSet()){
+ info.setIDProperty(superClassInfo.getIDProperty());
+ }
+ }
+ }
- validatePropOrderForInfo(info);
- }
- return typeInfo;
- }
-
- private TypeInfo processReferencedClass(JavaClass referencedClass){
- if (shouldGenerateTypeInfo(referencedClass)) {
- TypeInfo existingInfo = typeInfo.get(referencedClass.getQualifiedName());
- if(existingInfo == null || !existingInfo.isPreBuilt()){
- PackageInfo pInfo = getPackageInfoForPackage(referencedClass);
- JavaClass adapterClass = pInfo.getPackageLevelAdaptersByClass().get(referencedClass);
- if(adapterClass == null){
- CompilerHelper.addClassToClassLoader(referencedClass, helper.getClassLoader());
- JavaClass[] jClassArray = new JavaClass[] { referencedClass };
- buildNewTypeInfo(jClassArray);
- }
- return typeInfo.get(referencedClass.getQualifiedName());
- }else{
- if(existingInfo !=null && !existingInfo.isPostBuilt()){
- PackageInfo pInfo = getPackageInfoForPackage(referencedClass);
- JavaClass adapterClass = pInfo.getPackageLevelAdaptersByClass().get(referencedClass);
- if(adapterClass == null){
- CompilerHelper.addClassToClassLoader(referencedClass, helper.getClassLoader());
- JavaClass[] javaClasses = new JavaClass[] { referencedClass };
- javaClasses = postBuildTypeInfo(javaClasses);
- for(JavaClass next:javaClasses) {
- processPropertyTypes(next);
- }
- }
- }
- return existingInfo;
- }
- }
- return null;
- }
-
- /*
- * Get virtual property and XmlID information from parent and set it on info if available
- */
- public void processPropertiesSuperClass(JavaClass cls, TypeInfo info) {
- JavaClass superClass = (JavaClass) cls.getSuperclass();
- if(superClass == null) {
- return;
- }
- TypeInfo superClassInfo = this.typeInfo.get(superClass.getQualifiedName());
- if(superClassInfo != null) {
- processPropertiesSuperClass(superClass, superClassInfo);
- classesToProcessPropertyTypes.add(superClass);
- if(superClassInfo.getXmlVirtualAccessMethods() != null && info.getXmlVirtualAccessMethods() == null) {
- info.setXmlVirtualAccessMethods(superClassInfo.getXmlVirtualAccessMethods());
- }
- if(superClassInfo.isIDSet()){
- info.setIDProperty(superClassInfo.getIDProperty());
- }
- }
- }
-
- /**
- * Perform any final generation and/or validation operations on TypeInfo
- * properties.
- *
- */
- public void finalizeProperties() {
-
- for (TypeInfo tInfo: getTypeInfo().values()) {
- // don't need to validate props on a transient class at this point
- if (tInfo.isTransient()) {
- continue;
- }
- JavaClass jClass = tInfo.getJavaClass();
- String[] propOrder = tInfo.getPropOrder();
- boolean hasPropOrder = propOrder.length > 0 && !(propOrder.length == 1 && propOrder[0].equals(Constants.EMPTY_STRING));
- // If a property is marked transient, ensure it doesn't exist in the propOrder
- List<String> propOrderList = Arrays.asList(tInfo.getPropOrder());
- ArrayList<Property> propsList = tInfo.getPropertyList();
- for (int i = 0; i < propsList.size(); i++) {
- Property p = propsList.get(i);
- if (p.isTransient() && propOrderList.contains(p.getPropertyName())) {
- throw org.eclipse.persistence.exceptions.JAXBException.transientInProporder(p.getPropertyName());
- }
- if(hasPropOrder && !p.isAttribute() && !p.isTransient() && !p.isInverseReference()){
- if (!propOrderList.contains(p.getPropertyName())) {
- throw JAXBException.missingPropertyInPropOrder(p.getPropertyName(), tInfo.getJavaClassName());
- }
- }
- }
-
- if (!jClass.isInterface() && !tInfo.isEnumerationType() && !jClass.isAbstract()) {
- if (tInfo.getFactoryMethodName() == null && tInfo.getObjectFactoryClassName() == null) {
- JavaConstructor zeroArgConstructor = jClass.getDeclaredConstructor(new JavaClass[] {});
+ /**
+ * Perform any final generation and/or validation operations on TypeInfo
+ * properties.
+ *
+ */
+ public void finalizeProperties() {
+
+ for (TypeInfo tInfo: getTypeInfos().values()) {
+ // don't need to validate props on a transient class at this point
+ if (tInfo.isTransient()) {
+ continue;
+ }
+ JavaClass jClass = tInfo.getJavaClass();
+ String[] propOrder = tInfo.getPropOrder();
+ boolean hasPropOrder = propOrder.length > 0 && !(propOrder.length == 1 && propOrder[0].equals(Constants.EMPTY_STRING));
+ // If a property is marked transient, ensure it doesn't exist in the propOrder
+ List<String> propOrderList = Arrays.asList(tInfo.getPropOrder());
+ List<Property> propsList = tInfo.getPropertyList();
+ for (Property p : propsList) {
+ if (p.isTransient() && propOrderList.contains(p.getPropertyName())) {
+ throw JAXBException.transientInProporder(p.getPropertyName());
+ }
+ if (hasPropOrder && !p.isAttribute() && !p.isTransient() && !p.isInverseReference()) {
+ if (!propOrderList.contains(p.getPropertyName())) {
+ throw JAXBException.missingPropertyInPropOrder(p.getPropertyName(), tInfo.getJavaClassName());
+ }
+ }
+ }
+
+ if (!jClass.isInterface() && !tInfo.isEnumerationType() && !jClass.isAbstract()) {
+ if (tInfo.getFactoryMethodName() == null && tInfo.getObjectFactoryClassName() == null) {
+ JavaConstructor zeroArgConstructor = jClass.getDeclaredConstructor(new JavaClass[] {});
if (zeroArgConstructor == null) {
- if (tInfo.isSetXmlJavaTypeAdapter()) {
- tInfo.setTransient(true);
- } else {
- if(!referencedByTransformer.contains(jClass.getName())){
- throw org.eclipse.persistence.exceptions.JAXBException.factoryMethodOrConstructorRequired(jClass.getName());
- }
- }
- }
- }
+ if (tInfo.isSetXmlJavaTypeAdapter()) {
+ tInfo.setTransient(true);
+ } else {
+ if(!referencedByTransformer.contains(jClass.getName())){
+ throw org.eclipse.persistence.exceptions.JAXBException.factoryMethodOrConstructorRequired(jClass.getName());
+ }
+ }
+ }
+ }
}
// validate XmlValue
if (tInfo.getXmlValueProperty() != null) {
validateXmlValueFieldOrProperty(jClass, tInfo.getXmlValueProperty());
}
- // Keep a list of "any" properties to verify if multiples exist
- // that they have different element wrappers
- List<Property> anyElementProperties = new ArrayList<Property>();
-
- for (Property property : tInfo.getPropertyList()) {
- // Check that @XmlAttribute references a Java type that maps to text in XML
- if (property.isAttribute()) {
- validateXmlAttributeFieldOrProperty(tInfo, property);
- }
- JavaClass typeClass = property.getActualType();
-
- if(property.isChoice()){
- Collection<Property> choiceProps = property.getChoiceProperties();
- Iterator<Property> choicePropsIter = choiceProps.iterator();
- while(choicePropsIter.hasNext()){
- Property nextChoiceProp = choicePropsIter.next();
- JavaClass nextChoicePropTypeClass = nextChoiceProp.getActualType();
- TypeInfo targetInfo = typeInfo.get(nextChoicePropTypeClass.getQualifiedName());
- finalizeProperty(property, targetInfo, nextChoicePropTypeClass, jClass);
- }
- }else{
- TypeInfo targetInfo = typeInfo.get(typeClass.getQualifiedName());
- finalizeProperty(property, targetInfo, typeClass, jClass);
- }
-
- // only one XmlValue is allowed per class, and if there is one
- // only XmlAttributes are allowed
- if (tInfo.isSetXmlValueProperty()) {
+ // Keep a list of "any" properties to verify if multiples exist
+ // that they have different element wrappers
+ List<Property> anyElementProperties = new ArrayList<Property>();
+
+ for (Property property : tInfo.getPropertyList()) {
+ // Check that @XmlAttribute references a Java type that maps to text in XML
+ if (property.isAttribute()) {
+ validateXmlAttributeFieldOrProperty(tInfo, property);
+ }
+ JavaClass propertyClass = property.getActualType();
+
+ if (property.isChoice()) {
+ Collection<Property> choiceProps = property.getChoiceProperties();
+ for (Property nextChoiceProp : choiceProps) {
+ JavaClass nextChoicePropTypeClass = nextChoiceProp.getActualType();
+ TypeInfo targetInfo = typeInfos.get(nextChoicePropTypeClass.getQualifiedName());
+ finalizeProperty(property, targetInfo, nextChoicePropTypeClass, jClass);
+ }
+ } else {
+ TypeInfo targetInfo = typeInfos.get(propertyClass.getQualifiedName());
+ finalizeProperty(property, targetInfo, propertyClass, jClass);
+ }
+
+ // only one XmlValue is allowed per class, and if there is one
+ // only XmlAttributes are allowed
+ if (tInfo.isSetXmlValueProperty()) {
if (property.isXmlValue() && !(tInfo.getXmlValueProperty().getPropertyName().equals(property.getPropertyName()))) {
throw JAXBException.xmlValueAlreadySet(property.getPropertyName(), tInfo.getXmlValueProperty().getPropertyName(), jClass.getName());
}
if (!property.isXmlValue() && !property.isAttribute() && !property.isInverseReference() && !property.isTransient()) {
- throw JAXBException.propertyOrFieldShouldBeAnAttribute(property.getPropertyName());
- }
- }
-
-
- // handle XmlElementRef(s) - validate and build the required
- // ElementDeclaration object
- if (property.isReference()) {
- processReferenceProperty(property, tInfo, jClass);
- }
-
- if (property.isSwaAttachmentRef() && !this.hasSwaRef) {
- this.hasSwaRef = true;
- }
+ throw JAXBException.propertyOrFieldShouldBeAnAttribute(property.getPropertyName());
+ }
+ }
+
+
+ // handle XmlElementRef(s) - validate and build the required
+ // ElementDeclaration object
+ if (property.isReference()) {
+ processReferenceProperty(property, tInfo, jClass);
+ }
+
+ if (property.isSwaAttachmentRef() && !this.hasSwaRef) {
+ this.hasSwaRef = true;
+ }
// there can only be one XmlID per type info
if (property.isXmlId() && tInfo.getIDProperty() != null && !(tInfo.getIDProperty().getPropertyName().equals(property.getPropertyName()))) {
@@ -1022,59 +1029,59 @@ public class AnnotationsProcessor {
throw JAXBException.invalidElementWrapper(property.getPropertyName());
}
}
-
- // handle XmlTransformation - validate transformer class/method
- if (property.isXmlTransformation()) {
- processXmlTransformationProperty(property);
- }
- // validate XmlJoinNodes
- if (property.isSetXmlJoinNodes()) {
- TypeInfo targetInfo = typeInfo.get(typeClass.getQualifiedName());
-
- // the target class must have an associated TypeInfo
- if (targetInfo == null) {
- throw JAXBException.invalidXmlJoinNodeReferencedClass(property.getPropertyName(), typeClass.getQualifiedName());
- }
- // validate each referencedXmlPath - target TypeInfo should
- // have XmlID/XmlKey property with matching XmlPath
- if (targetInfo.getIDProperty() == null && targetInfo.getXmlKeyProperties() == null) {
- throw JAXBException.noKeyOrIDPropertyOnJoinTarget(jClass.getQualifiedName(), property.getPropertyName(), typeClass.getQualifiedName());
- }
- }
- }
- }
- }
-
- private void finalizeProperty(Property property, TypeInfo targetInfo, JavaClass typeClass, JavaClass jClass){
- if (targetInfo != null && targetInfo.isTransient() && property.getXmlElements() == null) {
- property.setTransientType(true);
- }
-
- // validate XmlIDREF
- if (property.isXmlIdRef()) {
- // the target class must have an associated TypeInfo unless
- // it is Object
- if (targetInfo == null && !typeClass.getQualifiedName().equals(JAVA_LANG_OBJECT)) {
- throw JAXBException.invalidIDREFClass(jClass.getQualifiedName(), property.getPropertyName(), typeClass.getQualifiedName());
- }
- // if the property is an XmlIDREF, the target must have an
- // XmlID set
- if (targetInfo != null && targetInfo.getIDProperty() == null) {
- throw JAXBException.invalidIdRef(property.getPropertyName(), typeClass.getQualifiedName());
- }
- }
- }
-
- /**
- * Process a given TypeInfo instance's properties.
- *
- * @param info
- */
- private void processTypeInfoProperties(JavaClass javaClass, TypeInfo info) {
- ArrayList<Property> properties = info.getPropertyList();
- for (Property property : properties) {
- // handle @XmlID
- processXmlID(property, javaClass, info);
+
+ // handle XmlTransformation - validate transformer class/method
+ if (property.isXmlTransformation()) {
+ validateXmlTransformationProperty(property);
+ }
+ // validate XmlJoinNodes
+ if (property.isSetXmlJoinNodes()) {
+ TypeInfo targetInfo = typeInfos.get(propertyClass.getQualifiedName());
+
+ // the target class must have an associated TypeInfo
+ if (targetInfo == null) {
+ throw JAXBException.invalidXmlJoinNodeReferencedClass(property.getPropertyName(), propertyClass.getQualifiedName());
+ }
+ // validate each referencedXmlPath - target TypeInfo should
+ // have XmlID/XmlKey property with matching XmlPath
+ if (targetInfo.getIDProperty() == null && targetInfo.getXmlKeyProperties() == null) {
+ throw JAXBException.noKeyOrIDPropertyOnJoinTarget(jClass.getQualifiedName(), property.getPropertyName(), propertyClass.getQualifiedName());
+ }
+ }
+ }
+ }
+ }
+
+ private void finalizeProperty(Property property, TypeInfo targetInfo, JavaClass typeClass, JavaClass jClass){
+ if (targetInfo != null && targetInfo.isTransient() && property.getXmlElements() == null) {
+ property.setTransientType(true);
+ }
+
+ // validate XmlIDREF
+ if (property.isXmlIdRef()) {
+ // the target class must have an associated TypeInfo unless
+ // it is Object
+ if (targetInfo == null && !typeClass.getQualifiedName().equals(JAVA_LANG_OBJECT)) {
+ throw JAXBException.invalidIDREFClass(jClass.getQualifiedName(), property.getPropertyName(), typeClass.getQualifiedName());
+ }
+ // if the property is an XmlIDREF, the target must have an
+ // XmlID set
+ if (targetInfo != null && targetInfo.getIDProperty() == null) {
+ throw JAXBException.invalidIdRef(property.getPropertyName(), typeClass.getQualifiedName());
+ }
+ }
+ }
+
+ /**
+ * Process a given TypeInfo instance's properties.
+ *
+ * @param info
+ */
+ private void processTypeInfoProperties(JavaClass javaClass, TypeInfo info) {
+ List<Property> properties = info.getPropertyList();
+ for (Property property : properties) {
+ // handle @XmlID
+ processXmlID(property, javaClass, info);
// handle @XmlIDREF - validate these properties after processing of
// all types is completed
@@ -1085,75 +1092,54 @@ public class AnnotationsProcessor {
processReferencedClass(property.getValueType());
}
}
- }
-
- void processPropertyTypes(JavaClass[] classes) {
- for (JavaClass next : classes) {
- processPropertyTypes(next);
- classesToProcessPropertyTypes.remove(next);
- }
- for (int i =0; i< classesToProcessPropertyTypes.size(); i++){
- JavaClass next = classesToProcessPropertyTypes.get(i);
- processPropertyTypes(next);
- }
- }
-
- private void processPropertyTypes(JavaClass next){
-
- TypeInfo info = getTypeInfo().get(next.getQualifiedName());
- if (info != null) {
-
- for (Property property : info.getPropertyList()) {
-
- if (property.isXmlLocation()) {
- info.setLocationAware(true);
- }
-
- if (property.isTransient()) {
- continue;
- }
- JavaClass type = property.getActualType();
-
- if(property.isReference()) {
- processReferencePropertyTypes(property, info, next);
- }
-
-
- if (property.isChoice()) {
-
- processChoiceProperty(property, info, next, type);
- for (Property choiceProp : property.getChoiceProperties()) {
- type = choiceProp.getActualType();
- processReferencedClass(type);
- }
- }else{
- processReferencedClass(type);
- }
- }
- }
-
- }
-
- /**
- * This method was initially designed to handle processing one or more
- * JavaClass instances. Over time its functionality has been broken apart
- * and handled in different methods. Its sole purpose now is to check for
- * callback methods.
- *
- * @param classes
- * this paramater can and should be null as it is not used
- */
- public void processJavaClasses(JavaClass[] classes) {
- checkForCallbackMethods();
- }
-
- /**
- * Process any additional classes, such as inner classes, @XmlRegistry or
- * from @XmlSeeAlso.
- *
- * @param classes
- * @return
- */
+ }
+
+ void processPropertyTypes(JavaClass[] classes) {
+ for (JavaClass next : classes) {
+ processPropertyTypes(next);
+ classesToProcessPropertyTypes.remove(next);
+ }
+ for (int i =0; i< classesToProcessPropertyTypes.size(); i++) { // throws cme when using foreach
+ JavaClass next = classesToProcessPropertyTypes.get(i);
+ processPropertyTypes(next);
+ }
+ }
+
+ private void processPropertyTypes(JavaClass next){
+
+ TypeInfo info = getTypeInfos().get(next.getQualifiedName());
+ if (info != null) {
+ for (Property property : info.getPropertyList()) {
+ if (property.isXmlLocation())
+ info.setLocationAware(true);
+ if (property.isTransient())
+ continue;
+
+ JavaClass type = property.getActualType();
+ if (property.isReference()) {
+ processReferencePropertyTypes(property, info, next);
+ }
+ if (property.isChoice()) {
+ processChoiceProperty(property, info, next, type);
+ for (Property choiceProp : property.getChoiceProperties()) {
+ type = choiceProp.getActualType();
+ processReferencedClass(type);
+ }
+ } else {
+ processReferencedClass(type);
+ }
+ }
+ }
+
+ }
+
+ /**
+ * Process any additional classes, such as inner classes, @XmlRegistry or
+ * from @XmlSeeAlso.
+ *
+ * @param classes
+ * @return
+ */
private JavaClass[] processAdditionalClasses(JavaClass[] classes) {
ArrayList<JavaClass> extraClasses = new ArrayList<JavaClass>();
ArrayList<JavaClass> classesToProcess = new ArrayList<JavaClass>();
@@ -1171,13 +1157,13 @@ public class AnnotationsProcessor {
for (JavaClass javaClass : extraClasses) {
processClass(javaClass, classesToProcess);
}
-
- return classesToProcess.toArray(new JavaClass[classesToProcess.size()]);
- }
-
- private void processAdditionalClasses(JavaClass cls, TypeMappingInfo tmi, ArrayList<JavaClass> extraClasses, ArrayList<JavaClass> classesToProcess) {
- Class xmlElementType = null;
- JavaClass javaClass = cls;
+
+ return classesToProcess.toArray(new JavaClass[classesToProcess.size()]);
+ }
+
+ private void processAdditionalClasses(JavaClass cls, TypeMappingInfo tmi, ArrayList<JavaClass> extraClasses, ArrayList<JavaClass> classesToProcess) {
+ Class xmlElementType = null;
+ JavaClass javaClass = cls;
if (tmi != null) {
Class adapterClass = this.typeMappingInfoToAdapterClasses.get(tmi);
if (adapterClass != null) {
@@ -1187,33 +1173,29 @@ public class AnnotationsProcessor {
// look for marshal method
for (Object nextMethod : adapterJavaClass.getDeclaredMethods()) {
JavaMethod method = (JavaMethod) nextMethod;
- if (method.getName().equals("marshal")) {
- JavaClass returnType = method.getReturnType();
- if (!returnType.getQualifiedName().equals(newType.getQualifiedName())) {
- newType = (JavaClass) returnType;
- break;
- }
- }
+ if (method.getName().equals("marshal")) {
+ JavaClass returnType = method.getReturnType();
+ if (!returnType.getQualifiedName().equals(newType.getQualifiedName())) {
+ newType = returnType;
+ break;
+ }
+ }
}
if (!helper.isBuiltInJavaType(javaClass)) {
extraClasses.add(javaClass);
}
javaClass = newType;
- }
- java.lang.annotation.Annotation[] annotations = getAnnotations(tmi);
- if (annotations != null) {
- for (int j = 0; j < annotations.length; j++) {
- java.lang.annotation.Annotation nextAnnotation = annotations[j];
-
- if (nextAnnotation != null) {
- if (nextAnnotation instanceof XmlElement) {
- XmlElement javaAnnotation = (XmlElement) nextAnnotation;
- if (javaAnnotation.type() != XmlElement.DEFAULT.class) {
- xmlElementType = javaAnnotation.type();
- }
- }
- }
- }
+ }
+ java.lang.annotation.Annotation[] annotations = getAnnotations(tmi);
+ if (annotations != null) {
+ for (Annotation nextAnnotation : annotations) {
+ if (nextAnnotation != null && nextAnnotation instanceof XmlElement) {
+ XmlElement javaAnnotation = (XmlElement) nextAnnotation;
+ if (javaAnnotation.type() != XmlElement.DEFAULT.class) {
+ xmlElementType = javaAnnotation.type();
+ }
+ }
+ }
}
}
@@ -1228,46 +1210,46 @@ public class AnnotationsProcessor {
extraClasses.add(javaClass.getComponentType());
}
Class generatedClass;
- if (null == tmi) {
- generatedClass = arrayClassesToGeneratedClasses.get(javaClass.getName());
- } else {
- generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfoToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
- }
- if (generatedClass == null) {
- generatedClass = generateWrapperForArrayClass(javaClass, tmi, xmlElementType, extraClasses);
+ if (null == tmi) {
+ generatedClass = arrayClassesToGeneratedClasses.get(javaClass.getName());
+ } else {
+ generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfosToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
+ }
+ if (generatedClass == null) {
+ generatedClass = generateWrapperForArrayClass(javaClass, tmi, xmlElementType, extraClasses);
extraClasses.add(helper.getJavaClass(generatedClass));
- arrayClassesToGeneratedClasses.put(javaClass.getName(), generatedClass);
- }
- generatedClassesToArrayClasses.put(generatedClass, javaClass);
- typeMappingInfoToGeneratedClasses.put(tmi, generatedClass);
-
- } else if (helper.isCollectionType(javaClass)) {
- JavaClass componentClass;
- Collection args = javaClass.getActualTypeArguments();
- if (args.size() >0) {
- componentClass = (JavaClass) args.iterator().next();
- if (!componentClass.isPrimitive()) {
- extraClasses.add(componentClass);
+ arrayClassesToGeneratedClasses.put(javaClass.getName(), generatedClass);
+ }
+ generatedClassesToArrayClasses.put(generatedClass, javaClass);
+ typeMappingInfosToGeneratedClasses.put(tmi, generatedClass);
+
+ } else if (helper.isCollectionType(javaClass)) {
+ JavaClass componentClass;
+ Collection args = javaClass.getActualTypeArguments();
+ if (!args.isEmpty()) {
+ componentClass = (JavaClass) args.iterator().next();
+ if (!componentClass.isPrimitive()) {
+ extraClasses.add(componentClass);
}
} else {
- componentClass = helper.getJavaClass(Object.class);
- }
-
- Class generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfoToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
- if (generatedClass == null) {
- generatedClass = generateCollectionValue(javaClass, tmi, xmlElementType, extraClasses);
- extraClasses.add(helper.getJavaClass(generatedClass));
- }
- typeMappingInfoToGeneratedClasses.put(tmi, generatedClass);
- } else if (helper.isMapType(javaClass)) {
- JavaClass keyClass;
- JavaClass valueClass;
- Collection args = javaClass.getActualTypeArguments();
- Iterator argsIter = args.iterator();
- if (args.size() > 1) {
- keyClass = (JavaClass) argsIter.next();
- if (!helper.isBuiltInJavaType(keyClass)) {
- extraClasses.add(keyClass);
+ componentClass = helper.getJavaClass(Object.class);
+ }
+
+ Class generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfosToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
+ if (generatedClass == null) {
+ generatedClass = generateCollectionValue(javaClass, tmi, xmlElementType, extraClasses);
+ extraClasses.add(helper.getJavaClass(generatedClass));
+ }
+ typeMappingInfosToGeneratedClasses.put(tmi, generatedClass);
+ } else if (helper.isMapType(javaClass)) {
+ JavaClass keyClass;
+ JavaClass valueClass;
+ Collection args = javaClass.getActualTypeArguments();
+ Iterator argsIter = args.iterator();
+ if (!args.isEmpty()) {
+ keyClass = (JavaClass) argsIter.next();
+ if (!helper.isBuiltInJavaType(keyClass)) {
+ extraClasses.add(keyClass);
}
valueClass = (JavaClass) argsIter.next();
if (!helper.isBuiltInJavaType(valueClass)) {
@@ -1275,53 +1257,53 @@ public class AnnotationsProcessor {
}
} else {
keyClass = helper.getJavaClass(Object.class);
- valueClass = helper.getJavaClass(Object.class);
- }
-
- Class generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfoToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
- if (generatedClass == null) {
- generatedClass = generateWrapperForMapClass(javaClass, keyClass, valueClass, tmi);
- extraClasses.add(helper.getJavaClass(generatedClass));
- }
- typeMappingInfoToGeneratedClasses.put(tmi, generatedClass);
- } else {
- // process @XmlRegistry, @XmlSeeAlso and inner classes
- processClass(javaClass, classesToProcess);
- }
- }
-
- /**
- * Adds additional classes to the given List, from inner classes,
- *
- * @XmlRegistry or @XmlSeeAlso.
- *
- * @param javaClass
- * @param classesToProcess
- */
+ valueClass = helper.getJavaClass(Object.class);
+ }
+
+ Class generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfosToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
+ if (generatedClass == null) {
+ generatedClass = generateWrapperForMapClass(javaClass, keyClass, valueClass, tmi);
+ extraClasses.add(helper.getJavaClass(generatedClass));
+ }
+ typeMappingInfosToGeneratedClasses.put(tmi, generatedClass);
+ } else {
+ // process @XmlRegistry, @XmlSeeAlso and inner classes
+ processClass(javaClass, classesToProcess);
+ }
+ }
+
+ /**
+ * Adds additional classes to the given List, from inner classes,
+ *
+ * @XmlRegistry or @XmlSeeAlso.
+ *
+ * @param javaClass
+ * @param classesToProcess
+ */
private void processClass(JavaClass javaClass, ArrayList<JavaClass> classesToProcess) {
if (shouldGenerateTypeInfo(javaClass)) {
if (isXmlRegistry(javaClass)) {
this.processObjectFactory(javaClass, classesToProcess);
- } else {
- classesToProcess.add(javaClass);
- // handle @XmlSeeAlso
- TypeInfo info = typeInfo.get(javaClass.getQualifiedName());
- if (info != null && info.isSetXmlSeeAlso()) {
- for (String jClassName : info.getXmlSeeAlso()) {
- classesToProcess.add(helper.getJavaClass(jClassName));
+ } else {
+ classesToProcess.add(javaClass);
+ // handle @XmlSeeAlso
+ TypeInfo info = typeInfos.get(javaClass.getQualifiedName());
+ if (info != null && info.isSetXmlSeeAlso()) {
+ for (String jClassName : info.getXmlSeeAlso()) {
+ classesToProcess.add(helper.getJavaClass(jClassName));
}
}
}
}
}
- /**
- * Process an @XmlSeeAlso annotation. TypeInfo instances will be created for
- * each class listed.
- *
- * @param javaClass
- */
- private void processXmlSeeAlso(JavaClass javaClass, TypeInfo info) {
+ /**
+ * Process an @XmlSeeAlso annotation. TypeInfo instances will be created for
+ * each class listed.
+ *
+ * @param javaClass
+ */
+ private void processXmlSeeAlso(JavaClass javaClass, TypeInfo info) {
// reflectively load @XmlSeeAlso class to avoid dependency
Class xmlSeeAlsoClass = null;
Method valueMethod = null;
@@ -1339,24 +1321,24 @@ public class AnnotationsProcessor {
try {
values = (Class[]) PrivilegedAccessHelper.invokeMethod(valueMethod, seeAlso, new Object[] {});
} catch (Exception ex) {
- }
-
- if (values != null) {
- List<String> seeAlsoClassNames = new ArrayList<String>();
- for (Class next : values) {
- seeAlsoClassNames.add(next.getName());
- }
+ }
+
+ if (values != null) {
+ List<String> seeAlsoClassNames = new ArrayList<String>();
+ for (Class next : values) {
+ seeAlsoClassNames.add(next.getName());
+ }
info.setXmlSeeAlso(seeAlsoClassNames);
}
}
}
-
- /**
- * Process any factory methods.
- *
- * @param javaClass
- * @param info
- */
+
+ /**
+ * Process any factory methods.
+ *
+ * @param javaClass
+ * @param info
+ */
private void processFactoryMethods(JavaClass javaClass, TypeInfo info) {
JavaMethod factoryMethod = this.factoryMethods.get(javaClass.getRawName());
if (factoryMethod != null) {
@@ -1374,13 +1356,13 @@ public class AnnotationsProcessor {
}
}
}
-
- /**
- * Process any package-level @XmlJavaTypeAdapters.
- *
- * @param javaClass
- * @param info
- */
+
+ /**
+ * Process any package-level @XmlJavaTypeAdapters.
+ *
+ * @param javaClass
+ * @param info
+ */
private void processPackageLevelAdapters(JavaClass javaClass, TypeInfo info) {
JavaPackage pack = javaClass.getPackage();
if (helper.isAnnotationPresent(pack, XmlJavaTypeAdapters.class)) {
@@ -1406,13 +1388,13 @@ public class AnnotationsProcessor {
getLogger().logWarning(JAXBMetadataLogger.INVALID_BOUND_TYPE, new Object[] { boundType, adapterClass });
}
}
-
- /**
- * Process any class-level @XmlJavaTypeAdapters.
- *
- * @param javaClass
- * @param info
- */
+
+ /**
+ * Process any class-level @XmlJavaTypeAdapters.
+ *
+ * @param javaClass
+ * @param info
+ */
private void processClassLevelAdapters(JavaClass javaClass, TypeInfo info) {
if (helper.isAnnotationPresent(javaClass, XmlJavaTypeAdapter.class)) {
XmlJavaTypeAdapter adapter = (XmlJavaTypeAdapter) helper.getAnnotation(javaClass, XmlJavaTypeAdapter.class);
@@ -1428,13 +1410,13 @@ public class AnnotationsProcessor {
info.setXmlJavaTypeAdapter(xja);
}
}
-
- /**
- * Process any @XmlSchemaType(s).
- *
- * @param javaClass
- * @param info
- */
+
+ /**
+ * Process any @XmlSchemaType(s).
+ *
+ * @param javaClass
+ * @param info
+ */
private void processSchemaTypes(JavaClass javaClass, TypeInfo info) {
JavaPackage pack = javaClass.getPackage();
if (helper.isAnnotationPresent(pack, XmlSchemaTypes.class)) {
@@ -1447,13 +1429,13 @@ public class AnnotationsProcessor {
processSchemaType((XmlSchemaType) helper.getAnnotation(pack, XmlSchemaType.class));
}
}
-
- /**
- * Process @XmlRootElement annotation on a given JavaClass.
- *
- * @param javaClass
- * @param info
- */
+
+ /**
+ * Process @XmlRootElement annotation on a given JavaClass.
+ *
+ * @param javaClass
+ * @param info
+ */
private void processXmlRootElement(JavaClass javaClass, TypeInfo info) {
if (helper.isAnnotationPresent(javaClass, XmlRootElement.class)) {
XmlRootElement rootElemAnnotation = (XmlRootElement) helper.getAnnotation(javaClass, XmlRootElement.class);
@@ -1463,13 +1445,13 @@ public class AnnotationsProcessor {
info.setXmlRootElement(xmlRE);
}
}
-
- /**
- * Process @XmlExtensible annotation on a given JavaClass.
- *
- * @param javaClass
- * @param info
- */
+
+ /**
+ * Process @XmlExtensible annotation on a given JavaClass.
+ *
+ * @param javaClass
+ * @param info
+ */
private void processXmlExtensible(JavaClass javaClass, TypeInfo info) {
if (helper.isAnnotationPresent(javaClass, XmlVirtualAccessMethods.class)) {
XmlVirtualAccessMethods extAnnotation = (XmlVirtualAccessMethods) helper.getAnnotation(javaClass, XmlVirtualAccessMethods.class);
@@ -1482,55 +1464,55 @@ public class AnnotationsProcessor {
}
/**
- * Process @XmlType annotation on a given JavaClass and update the TypeInfo
- * for pre-processing. Note that if no @XmlType annotation is present we
- * still create a new XmlType an set it on the TypeInfo.
- *
- * @param javaClass
- * @param info
- * @param packageNamespace
- */
- private void preProcessXmlType(JavaClass javaClass, TypeInfo info, NamespaceInfo packageNamespace) {
- org.eclipse.persistence.jaxb.xmlmodel.XmlType xmlType = new org.eclipse.persistence.jaxb.xmlmodel.XmlType();
- if (helper.isAnnotationPresent(javaClass, XmlType.class)) {
- XmlType typeAnnotation = (XmlType) helper.getAnnotation(javaClass, XmlType.class);
- // set name
- xmlType.setName(typeAnnotation.name());
- // set namespace
- xmlType.setNamespace(typeAnnotation.namespace());
- // set propOrder
- String[] propOrder = typeAnnotation.propOrder();
- // handle case where propOrder is an empty array
- if (propOrder != null) {
- xmlType.getPropOrder();
- }
- for (String prop : propOrder) {
- xmlType.getPropOrder().add(prop);
- }
- // set factoryClass
- Class factoryClass = typeAnnotation.factoryClass();
- if (factoryClass == DEFAULT.class) {
- xmlType.setFactoryClass("javax.xml.bind.annotation.XmlType.DEFAULT");
- } else {
- xmlType.setFactoryClass(factoryClass.getCanonicalName());
- }
- // set factoryMethodName
- xmlType.setFactoryMethod(typeAnnotation.factoryMethod());
- } else {
- // set defaults
- xmlType.setNamespace(packageNamespace.getNamespace());
- }
- info.setXmlType(xmlType);
- }
-
- /**
- * Process XmlType for a given TypeInfo. Here we assume that the TypeInfo
- * has an XmlType set - typically via preProcessXmlType or XmlProcessor
- * override.
- *
- * @param javaClass
- * @param info
- * @param packageNamespace
+ * Process @XmlType annotation on a given JavaClass and update the TypeInfo
+ * for pre-processing. Note that if no @XmlType annotation is present we
+ * still create a new XmlType an set it on the TypeInfo.
+ *
+ * @param javaClass
+ * @param info
+ * @param packageNamespace
+ */
+ private void preProcessXmlType(JavaClass javaClass, TypeInfo info, NamespaceInfo packageNamespace) {
+ org.eclipse.persistence.jaxb.xmlmodel.XmlType xmlType = new org.eclipse.persistence.jaxb.xmlmodel.XmlType(); // 14 xmlType=XmlType - default settings: name=null, namespace=null, factoryClass=null, factoryMethod=null, propOrder=null.
+ if (helper.isAnnotationPresent(javaClass, XmlType.class)) {
+ XmlType typeAnnotation = (XmlType) helper.getAnnotation(javaClass, XmlType.class); // 15 typeAnnotation=com.sun.proxy.$Proxy6"@javax.xml.bind.annotation.XmlType(factoryMethod=, name=OneClass, propOrder=[car], factoryClass=class javax.xml.bind.annotation.XmlType$DEFAULT, namespace=##default)"
+ // set name
+ xmlType.setName(typeAnnotation.name()); // 16 XmlType - name="OneClass
+ // set namespace
+ xmlType.setNamespace(typeAnnotation.namespace()); // 17 xmlType - namespace="##default"
+ // set propOrder
+ String[] propOrder = typeAnnotation.propOrder(); // 18 propOrder = ["car"]
+ // initializes xmlType.propOrder to an empty ArrayList
+ if (propOrder != null) {
+ xmlType.getPropOrder(); // 19 OK, so this only initializes xmlType.propOrder to an empty ArrayList
+ }
+ for (String prop : propOrder) {
+ xmlType.getPropOrder().add(prop); // 20 - puts "car" into xmlType.propOrder
+ }
+ // set factoryClass
+ Class factoryClass = typeAnnotation.factoryClass(); // 21 factoryClass=java.lang.Class"class javax.xml.bind.annotation.XmlType$DEFAULT"
+ if (factoryClass == DEFAULT.class) {
+ xmlType.setFactoryClass("javax.xml.bind.annotation.XmlType.DEFAULT"); // 22
+ } else {
+ xmlType.setFactoryClass(factoryClass.getCanonicalName());
+ }
+ // set factoryMethodName
+ xmlType.setFactoryMethod(typeAnnotation.factoryMethod()); // 23 defaults to factoryMethod=""
+ } else {
+ // set defaults
+ xmlType.setNamespace(packageNamespace.getNamespace());
+ }
+ info.setXmlType(xmlType); // 24
+ }
+
+ /**
+ * Process XmlType for a given TypeInfo. Here we assume that the TypeInfo
+ * has an XmlType set - typically via preProcessXmlType or XmlProcessor
+ * override.
+ *
+ * @param javaClass
+ * @param info
+ * @param packageNamespace
*/
private void postProcessXmlType(JavaClass javaClass, TypeInfo info, PackageInfo packageNamespace) {
// assumes that the TypeInfo has an XmlType set from
@@ -1589,13 +1571,13 @@ public class AnnotationsProcessor {
}
}
- /**
- * Process @XmlAccessorType annotation on a given JavaClass and update the
- * TypeInfo for pre-processing.
- *
- * @param javaClass
- * @param info
- * @param packageNamespace
+ /**
+ * Process @XmlAccessorType annotation on a given JavaClass and update the
+ * TypeInfo for pre-processing.
+ *
+ * @param javaClass
+ * @param info
+ * @param packageNamespace
*/
private void preProcessXmlAccessorType(JavaClass javaClass, TypeInfo info, NamespaceInfo packageNamespace) {
org.eclipse.persistence.jaxb.xmlmodel.XmlAccessType xmlAccessType;
@@ -1606,22 +1588,22 @@ public class AnnotationsProcessor {
}
}
- /**
- * Post process XmlAccessorType. In some cases, such as @XmlSeeAlso classes,
- * the access type may not have been set
- *
- * @param info
- */
- private void postProcessXmlAccessorType(TypeInfo info, PackageInfo packageNamespace) {
+ /**
+ * Post process XmlAccessorType. In some cases, such as @XmlSeeAlso classes,
+ * the access type may not have been set
+ *
+ * @param info
+ */
+ private void postProcessXmlAccessorType(TypeInfo info, PackageInfo packageNamespace) {
if (!info.isSetXmlAccessType()) {
// Check for super class
- JavaClass next = helper.getJavaClass(info.getJavaClassName()).getSuperclass();
- while (next != null && !(next.getName().equals(JAVA_LANG_OBJECT))) {
- processReferencedClass(next);
- TypeInfo parentInfo = this.typeInfo.get(next.getName());
- if (parentInfo != null && parentInfo.isSetXmlAccessType()) {
- info.setXmlAccessType(parentInfo.getXmlAccessType());
- break;
+ JavaClass next = helper.getJavaClass(info.getJavaClassName()).getSuperclass();
+ while (next != null && !(next.getName().equals(JAVA_LANG_OBJECT))) {
+ processReferencedClass(next);
+ TypeInfo parentInfo = this.typeInfos.get(next.getName());
+ if (parentInfo != null && parentInfo.isSetXmlAccessType()) {
+ info.setXmlAccessType(parentInfo.getXmlAccessType());
+ break;
}
next = next.getSuperclass();
}
@@ -1633,13 +1615,13 @@ public class AnnotationsProcessor {
}
}
- /**
- * Process package and class @XmlAccessorOrder. Class level annotation
- * overrides a package level annotation.
- *
- * @param javaClass
- * @param info
- * @param packageNamespace
+ /**
+ * Process package and class @XmlAccessorOrder. Class level annotation
+ * overrides a package level annotation.
+ *
+ * @param javaClass
+ * @param info
+ * @param packageNamespace
*/
private void preProcessXmlAccessorOrder(JavaClass javaClass, TypeInfo info, NamespaceInfo packageNamespace) {
XmlAccessorOrder order = null;
@@ -1651,108 +1633,177 @@ public class AnnotationsProcessor {
}
/**
- * Post process XmlAccessorOrder. This method assumes that the given
- * TypeInfo has already had its order set (via annotations in
- * preProcessXmlAccessorOrder or via xml metadata override in XMLProcessor).
- *
- * @param javaClass
- * @param info
- */
- private void postProcessXmlAccessorOrder(TypeInfo info, PackageInfo packageNamespace) {
- if (!info.isSetXmlAccessOrder()) {
+ * Post process XmlAccessorOrder. This method assumes that the given
+ * TypeInfo has already had its order set (via annotations in
+ * preProcessXmlAccessorOrder or via xml metadata override in XMLProcessor).
+ *
+ * @param info
+ * @param packageNamespace
+ */
+ private void postProcessXmlAccessorOrder(TypeInfo info, PackageInfo packageNamespace) {
+ if (!info.isSetXmlAccessOrder()) {
// use value in package-info.java as last resort - will default if
// not set
info.setXmlAccessOrder(org.eclipse.persistence.jaxb.xmlmodel.XmlAccessOrder.fromValue(packageNamespace.getAccessOrder().name()));
}
info.orderProperties();
}
-
- /**
- * Process @XmlElement annotation on a given property.
- *
- * @param property
- */
- private void processXmlElement(Property property, TypeInfo info) {
+
+ /**
+ * Process @XmlElement annotation on a given property.
+ *
+ * @param property
+ */
+ private void processXmlElement(Property property, TypeInfo info) {
if (helper.isAnnotationPresent(property.getElement(), XmlElement.class)) {
XmlElement element = (XmlElement) helper.getAnnotation(property.getElement(), XmlElement.class);
property.setIsRequired(element.required());
property.setNillable(element.nillable());
if (element.type() != XmlElement.DEFAULT.class && !(property.isSwaAttachmentRef())) {
property.setOriginalType(property.getType());
- if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
- property.setGenericType(helper.getJavaClass(element.type()));
- } else {
- JavaClass originalType = property.getType();
- JavaClass newType =helper.getJavaClass(element.type());
- if(!originalType.getName().equals(newType.getName())){
- property.setTyped(true);
- property.setSchemaType((QName) helper.getXMLToJavaTypeMap().get(newType.getName()));
- }
- property.setType(newType);
- }
- property.setHasXmlElementType(true);
+ if (helper.isCollectionType(property.getType()) || property.getType().isArray()) {
+ property.setGenericType(helper.getJavaClass(element.type()));
+ } else {
+ JavaClass originalType = property.getType();
+ JavaClass newType =helper.getJavaClass(element.type());
+ if(!originalType.getName().equals(newType.getName())){
+ property.setTyped(true);
+ property.setSchemaType((QName) helper.getXMLToJavaTypeMap().get(newType.getName()));
+ }
+ property.setType(newType);
+ }
+ property.setHasXmlElementType(true);
}
// handle default value
- if (!element.defaultValue().equals(ELEMENT_DECL_DEFAULT)) {
- property.setDefaultValue(element.defaultValue());
- }
- }
- }
-
- /**
- * Process @XmlID annotation on a given property
- *
- * @param property
- * @param info
- */
+ if (!element.defaultValue().equals(ELEMENT_DECL_DEFAULT)) {
+ property.setDefaultValue(element.defaultValue());
+ }
+
+ if (facets) addFacets(property);
+ }
+ }
+
+ private void addFacets(Property property) {
+ final JavaHasAnnotations element = property.getElement();
+ if (helper.isAnnotationPresent(element, DecimalMin.class)) {
+ DecimalMin a = (DecimalMin) helper.getAnnotation(element, DecimalMin.class);
+ DecimalMinFacet facet = new DecimalMinFacet(a.value(), a.inclusive());
+ property.addFacet(facet);
+ }
+ if (helper.isAnnotationPresent(element, DecimalMax.class)) {
+ DecimalMax a = (DecimalMax) helper.getAnnotation(element, DecimalMax.class);
+ DecimalMaxFacet facet = new DecimalMaxFacet(a.value(), a.inclusive());
+ property.addFacet(facet);
+ }
+ if (helper.isAnnotationPresent(element, Digits.class)) {
+ Digits a = (Digits) helper.getAnnotation(element, Digits.class);
+ DigitsFacet facet = new DigitsFacet(a.integer(), a.fraction());
+ property.addFacet(facet);
+ }
+ if (helper.isAnnotationPresent(element, Max.class)) {
+ Max a = (Max) helper.getAnnotation(element, Max.class);
+ MaxFacet facet = new MaxFacet(a.value());
+ property.addFacet(facet);
+ }
+ if (helper.isAnnotationPresent(element, Min.class)) {
+ Min a = (Min) helper.getAnnotation(element, Min.class);
+ MinFacet facet = new MinFacet(a.value());
+ property.addFacet(facet);
+ }
+ if (helper.isAnnotationPresent(element, NotNull.class)) {
+ property.setNotNullAnnotated(true);
+ }
+ if (helper.isAnnotationPresent(element, Pattern.class)) {
+ Pattern a = (Pattern) helper.getAnnotation(element, Pattern.class);
+ PatternFacet facet = new PatternFacet(a.regexp(), a.flags());
+ property.addFacet(facet);
+ }
+ /* Example:
+ @Pattern.List({
+ @Pattern(regexp = "first_expression", message = "first.Pattern.message"),
+ @Pattern(regexp = "second_expression", message = "second.Pattern.message"),
+ @Pattern(regexp = "third_expression", message = "third.Pattern.message")
+ }) */
+ if (helper.isAnnotationPresent(element, Pattern.List.class)) {
+ Pattern.List a = (Pattern.List) helper.getAnnotation(element, Pattern.List.class);
+ PatternListFacet facet = new PatternListFacet(new ArrayList<PatternFacet>());
+ for (Pattern pat : a.value()) {
+ PatternFacet pf = new PatternFacet(pat.regexp(), pat.flags());
+ facet.addPattern(pf);
+ }
+ property.addFacet(facet);
+ }
+ if (helper.isAnnotationPresent(element, Size.class)) {
+ Size a = (Size) helper.getAnnotation(element, Size.class);
+ final int min = a.min();
+ final int max = a.max();
+ if (min != 0 || max != Integer.MAX_VALUE) { // Fixes generation of an empty facet.
+ if ("java.lang.String".equals(property.getType().getName())) { // @Size serves for both length facet and occurs restriction.
+ SizeFacet facet = new SizeFacet(min, max); // For minLength, maxLength.
+ property.addFacet(facet);
+ } else { // For minOccurs, maxOccurs.
+ if (min > 0) property.setMinOccurs(min); // 0 is default minBoundary.
+ if (max < Integer.MAX_VALUE) property.setMaxOccurs(max); // 2^31 is default maxBoundary.
+ }
+ }
+ }
+ }
+
+ /**
+ * Process @XmlID annotation on a given property
+ *
+ * @param property
+ * @param info
+ */
private void processXmlID(Property property, JavaClass javaClass, TypeInfo info) {
if (helper.isAnnotationPresent(property.getElement(), XmlID.class)) {
property.setIsXmlId(true);
info.setIDProperty(property);
}
}
-
- /**
- * Process @XmlIDREF on a given property.
- *
- * @param property
- */
- private void processXmlIDREF(Property property) {
+
+ /**
+ * Process @XmlIDREF on a given property.
+ *
+ * @param property
+ */
+ private void processXmlIDREF(Property property) {
if (helper.isAnnotationPresent(property.getElement(), XmlIDREF.class)) {
property.setIsXmlIdRef(true);
}
}
-
- /**
- * Process @XmlJavaTypeAdapter on a given property.
- *
- * @param property
- * @param propertyType
- */
- private void processXmlJavaTypeAdapter(Property property, TypeInfo info, JavaClass javaClass) {
- JavaClass adapterClass = null;
+
+ /**
+ * Process @XmlJavaTypeAdapter on a given property.
+ *
+ * @param property
+ * @param info
+ * @param javaClass
+ */
+ private void processXmlJavaTypeAdapter(Property property, TypeInfo info, JavaClass javaClass) {
+ JavaClass adapterClass = null;
JavaClass ptype = property.getActualType();
if (helper.isAnnotationPresent(property.getElement(), XmlJavaTypeAdapter.class)) {
XmlJavaTypeAdapter adapter = (XmlJavaTypeAdapter) helper.getAnnotation(property.getElement(), XmlJavaTypeAdapter.class);
org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter xja = new org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter();
xja.setValue(adapter.value().getName());
- xja.setType(adapter.type().getName());
- property.setXmlJavaTypeAdapter(xja);
- } else {
- TypeInfo ptypeInfo = typeInfo.get(ptype.getQualifiedName());
- org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter xmlJavaTypeAdapter;
- if (ptypeInfo == null && shouldGenerateTypeInfo(ptype)) {
- if (helper.isAnnotationPresent(ptype, XmlJavaTypeAdapter.class)) {
- XmlJavaTypeAdapter adapter = (XmlJavaTypeAdapter) helper.getAnnotation(ptype, XmlJavaTypeAdapter.class);
- org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter xja = new org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter();
- xja.setValue(adapter.value().getName());
- String boundType = adapter.type().getName();
- if (boundType == null || boundType.equals("javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter.DEFAULT")) {
- boundType = ptype.getRawName();
- }
- xja.setType(adapter.type().getName());
- property.setXmlJavaTypeAdapter(xja);
- }
+ xja.setType(adapter.type().getName());
+ property.setXmlJavaTypeAdapter(xja);
+ } else {
+ TypeInfo ptypeInfo = typeInfos.get(ptype.getQualifiedName());
+ org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter xmlJavaTypeAdapter;
+ if (ptypeInfo == null && shouldGenerateTypeInfo(ptype)) {
+ if (helper.isAnnotationPresent(ptype, XmlJavaTypeAdapter.class)) {
+ XmlJavaTypeAdapter adapter = (XmlJavaTypeAdapter) helper.getAnnotation(ptype, XmlJavaTypeAdapter.class);
+ org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter xja = new org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter();
+ xja.setValue(adapter.value().getName());
+ /*String boundType = adapter.type().getName();
+ if (boundType == null || boundType.equals("javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter.DEFAULT")) {
+ boundType = ptype.getRawName();
+ } value from boundType is not used - fix if you know what it should do. */
+ xja.setType(adapter.type().getName());
+ property.setXmlJavaTypeAdapter(xja);
+ }
}
if (ptypeInfo != null) {
if (null != (xmlJavaTypeAdapter = ptypeInfo.getXmlJavaTypeAdapter())) {
@@ -1776,13 +1827,13 @@ public class AnnotationsProcessor {
}
}
- /**
- * Store a QName (if necessary) based on a given TypeInfo's schema type
- * name.
- *
- * @param javaClass
- * @param info
- */
+ /**
+ * Store a QName (if necessary) based on a given TypeInfo's schema type
+ * name.
+ *
+ * @param javaClass
+ * @param info
+ */
private void processTypeQName(JavaClass javaClass, TypeInfo info, NamespaceInfo packageNamespace) {
if(info.isTransient()) {
return;
@@ -1825,26 +1876,26 @@ public class AnnotationsProcessor {
public ArrayList<Property> getPropertiesForClass(JavaClass cls, TypeInfo info) {
ArrayList<Property> returnList = new ArrayList<Property>();
- if (!info.isTransient()) {
- JavaClass superClass = cls.getSuperclass();
- if (null != superClass) {
- TypeInfo superClassInfo = typeInfo.get(superClass.getQualifiedName());
- ArrayList<Property> superClassProperties;
- while (superClassInfo != null && superClassInfo.isTransient()) {
- if (info.getXmlAccessType() == XmlAccessType.FIELD) {
- superClassProperties = getFieldPropertiesForClass(superClass, superClassInfo, false);
- } else if (info.getXmlAccessType() == XmlAccessType.PROPERTY) {
- superClassProperties = getPropertyPropertiesForClass(superClass, superClassInfo, false);
- } else if (info.getXmlAccessType() == XmlAccessType.PUBLIC_MEMBER) {
+ if (!info.isTransient()) {
+ JavaClass superClass = cls.getSuperclass();
+ if (null != superClass) {
+ TypeInfo superClassInfo = typeInfos.get(superClass.getQualifiedName());
+ ArrayList<Property> superClassProperties;
+ while (superClassInfo != null && superClassInfo.isTransient()) {
+ if (info.getXmlAccessType() == XmlAccessType.FIELD) {
+ superClassProperties = getFieldPropertiesForClass(superClass, superClassInfo, false);
+ } else if (info.getXmlAccessType() == XmlAccessType.PROPERTY) {
+ superClassProperties = getPropertyPropertiesForClass(superClass, superClassInfo, false);
+ } else if (info.getXmlAccessType() == XmlAccessType.PUBLIC_MEMBER) {
superClassProperties = getPublicMemberPropertiesForClass(superClass, superClassInfo);
} else {
- superClassProperties = getNoAccessTypePropertiesForClass(superClass, superClassInfo);
- }
- superClass = superClass.getSuperclass();
- superClassInfo = typeInfo.get(superClass.getQualifiedName());
- for(Property next:superClassProperties) {
- next.setIsSuperClassProperty(true);
- }
+ superClassProperties = getNoAccessTypePropertiesForClass(superClass, superClassInfo);
+ }
+ superClass = superClass.getSuperclass();
+ superClassInfo = typeInfos.get(superClass.getQualifiedName());
+ for(Property next:superClassProperties) {
+ next.setIsSuperClassProperty(true);
+ }
returnList.addAll(0, superClassProperties);
}
}
@@ -1873,89 +1924,88 @@ public class AnnotationsProcessor {
public ArrayList<Property> getFieldPropertiesForClass(JavaClass cls, TypeInfo info, boolean onlyPublic, boolean onlyExplicit) {
ArrayList<Property> properties = new ArrayList<Property>();
if (cls == null) {
- return properties;
- }
-
- for (Iterator<JavaField> fieldIt = cls.getDeclaredFields().iterator(); fieldIt.hasNext();) {
- Property property = null;
- JavaField nextField = fieldIt.next();
- int modifiers = nextField.getModifiers();
-
- if (!Modifier.isTransient(modifiers) && ((Modifier.isPublic(nextField.getModifiers()) && onlyPublic) || !onlyPublic ||hasJAXBAnnotations(nextField))) {
- if (!Modifier.isStatic(modifiers)) {
- if ((onlyExplicit && hasJAXBAnnotations(nextField)) || !onlyExplicit) {
- try {
- property = buildNewProperty(info, cls, nextField, nextField.getName(), nextField.getResolvedType());
- properties.add(property);
- } catch(JAXBException ex) {
- if(ex.getErrorCode() != JAXBException.INVALID_INTERFACE || !helper.isAnnotationPresent(nextField, XmlTransient.class)) {
- throw ex;
- }
- }
- }
- } else {
- try {
- property = buildNewProperty(info, cls, nextField, nextField.getName(), nextField.getResolvedType());
- if (helper.isAnnotationPresent(nextField, XmlAttribute.class)) {
- Object value = ((JavaFieldImpl) nextField).get(null);
- if (value != null) {
- String stringValue = (String) XMLConversionManager.getDefaultXMLManager().convertObject(value, String.class, property.getSchemaType());
- property.setFixedValue(stringValue);
- }
- }
- property.setWriteOnly(true);
- if(!hasJAXBAnnotations(nextField)) {
- property.setTransient(true);
- }
- properties.add(property);
+ return properties;
+ }
+
+ for (JavaField javaField : (Iterable<JavaField>) cls.getDeclaredFields()) {
+ Property property = null;
+ int modifiers = javaField.getModifiers();
+
+ if (!Modifier.isTransient(modifiers) && ((Modifier.isPublic(javaField.getModifiers()) && onlyPublic) || !onlyPublic || hasJAXBAnnotations(javaField))) {
+ if (!Modifier.isStatic(modifiers)) {
+ if ((onlyExplicit && hasJAXBAnnotations(javaField)) || !onlyExplicit) {
+ try {
+ property = buildNewProperty(info, cls, javaField, javaField.getName(), javaField.getResolvedType());
+ properties.add(property);
+ } catch (JAXBException ex) {
+ if (ex.getErrorCode() != JAXBException.INVALID_INTERFACE || !helper.isAnnotationPresent(javaField, XmlTransient.class)) {
+ throw ex;
+ }
+ }
+ }
+ } else {
+ try {
+ property = buildNewProperty(info, cls, javaField, javaField.getName(), javaField.getResolvedType());
+ if (helper.isAnnotationPresent(javaField, XmlAttribute.class)) {
+ Object value = ((JavaFieldImpl) javaField).get(null);
+ if (value != null) {
+ String stringValue = (String) XMLConversionManager.getDefaultXMLManager().convertObject(value, String.class, property.getSchemaType());
+ property.setFixedValue(stringValue);
+ }
+ }
+ property.setWriteOnly(true);
+ if (!hasJAXBAnnotations(javaField)) {
+ property.setTransient(true);
+ }
+ properties.add(property);
} catch (ClassCastException e) {
- // do Nothing
- } catch (IllegalAccessException e) {
- // do Nothing
- } catch(JAXBException ex) {
- if(ex.getErrorCode() != JAXBException.INVALID_INTERFACE || !helper.isAnnotationPresent(nextField, XmlTransient.class)) {
- throw ex;
- }
- }
- }
- }
-
- if (helper.isAnnotationPresent(nextField, XmlTransient.class)) {
- if(property != null){
- property.setTransient(true);
- }
- }
- }
- return properties;
- }
-
- /*
- * Create a new Property Object and process the annotations that are common
- * to fields and methods
- */
- Property buildNewProperty(TypeInfo info, JavaClass cls, JavaHasAnnotations javaHasAnnotations, String propertyName, JavaClass ptype) {
- Property property = null;
- if (helper.isAnnotationPresent(javaHasAnnotations, XmlElements.class)) {
- property = buildChoiceProperty(javaHasAnnotations);
- } else if (helper.isAnnotationPresent(javaHasAnnotations, XmlElementRef.class) || helper.isAnnotationPresent(javaHasAnnotations, XmlElementRefs.class)) {
-
- findAndProcessObjectFactory(cls);
-
- property = buildReferenceProperty(info, javaHasAnnotations, propertyName, ptype);
- if (helper.isAnnotationPresent(javaHasAnnotations, XmlAnyElement.class)) {
- XmlAnyElement anyElement = (XmlAnyElement) helper.getAnnotation(javaHasAnnotations, XmlAnyElement.class);
+ // do Nothing
+ } catch (IllegalAccessException e) {
+ // do Nothing
+ } catch (JAXBException ex) {
+ if (ex.getErrorCode() != JAXBException.INVALID_INTERFACE || !helper.isAnnotationPresent(javaField, XmlTransient.class)) {
+ throw ex;
+ }
+ }
+ }
+ }
+
+ if (helper.isAnnotationPresent(javaField, XmlTransient.class)) {
+ if (property != null) {
+ property.setTransient(true);
+ }
+ }
+ }
+ return properties;
+ }
+
+ /*
+ * Create a new Property Object and process the annotations that are common
+ * to fields and methods
+ */
+ Property buildNewProperty(TypeInfo info, JavaClass cls, JavaHasAnnotations javaHasAnnotations, String propertyName, JavaClass ptype) {
+ Property property = null;
+ if (helper.isAnnotationPresent(javaHasAnnotations, XmlElements.class)) {
+ property = buildChoiceProperty(javaHasAnnotations);
+ } else if (helper.isAnnotationPresent(javaHasAnnotations, XmlElementRef.class) || helper.isAnnotationPresent(javaHasAnnotations, XmlElementRefs.class)) {
+
+ findAndProcessObjectFactory(cls);
+
+ property = buildReferenceProperty(info, javaHasAnnotations, propertyName, ptype);
+ if (helper.isAnnotationPresent(javaHasAnnotations, XmlAnyElement.class)) {
+ XmlAnyElement anyElement = (XmlAnyElement) helper.getAnnotation(javaHasAnnotations, XmlAnyElement.class);
property.setIsAny(true);
if (anyElement.value() != null) {
property.setDomHandlerClassName(anyElement.value().getName());
}
property.setLax(anyElement.lax());
- info.setAnyElementPropertyName(propertyName);
- }
- } else if (helper.isAnnotationPresent(javaHasAnnotations, XmlAnyElement.class)) {
- findAndProcessObjectFactory(cls);
- XmlAnyElement anyElement = (XmlAnyElement) helper.getAnnotation(javaHasAnnotations, XmlAnyElement.class);
- property = new Property(helper);
- property.setIsAny(true);
+ info.setAnyElementPropertyName(propertyName);
+ }
+ } else if (helper.isAnnotationPresent(javaHasAnnotations, XmlAnyElement.class)) {
+ findAndProcessObjectFactory(cls);
+ XmlAnyElement anyElement = (XmlAnyElement) helper.getAnnotation(javaHasAnnotations, XmlAnyElement.class);
+ property = new Property(helper);
+ property.setIsAny(true);
if (anyElement.value() != null) {
property.setDomHandlerClassName(anyElement.value().getName());
}
@@ -1970,60 +2020,60 @@ public class AnnotationsProcessor {
property.setElement(javaHasAnnotations);
// if there is a TypeInfo for ptype check it for transient, otherwise
- // check the class
- if (helper.isCollectionType(ptype)) {
- JavaClass componentType = helper.getJavaClass(Object.class);
-
- Collection typeArgs = ptype.getActualTypeArguments();
- if(typeArgs.size() > 0) {
- componentType = (JavaClass) typeArgs.iterator().next();
- }
- updatePropertyType(property, ptype, componentType);
- }else{
- updatePropertyType(property, ptype, ptype);
- }
-
- if(helper.isAnnotationPresent(javaHasAnnotations, XmlVariableNode.class)){
- XmlVariableNode variableNode = (XmlVariableNode) helper.getAnnotation(javaHasAnnotations, XmlVariableNode.class);
- if(variableNode.type() != XmlVariableNode.DEFAULT.class){
- property.setVariableClassName(variableNode.type().getName());
-
- JavaClass componentType = helper.getJavaClass(variableNode.type());
-
- if(helper.isCollectionType(ptype)){
- property.setGenericType(componentType);
- }else{
- property.setType(componentType);
- }
-
- }
- if(!variableNode.value().equals("##default")){
- property.setVariableAttributeName(variableNode.value());
- }
- property.setVariableNodeAttribute(variableNode.attribute());
- }
-
-
- if((ptype.isArray() && !areEquals(ptype, byte[].class)) || (helper.isCollectionType(ptype) && !helper.isAnnotationPresent(javaHasAnnotations, XmlList.class)) ){
- property.setNillable(true);
- }
- processPropertyAnnotations(info, cls, javaHasAnnotations, property);
-
- if (helper.isAnnotationPresent(javaHasAnnotations, XmlPath.class)) {
- XmlPath xmlPath = (XmlPath) helper.getAnnotation(javaHasAnnotations, XmlPath.class);
- property.setXmlPath(xmlPath.value());
- Field tempField = new XMLField(xmlPath.value());
- boolean isAttribute = tempField.getLastXPathFragment().isAttribute();
- property.setIsAttribute(isAttribute);
+ // check the class
+ if (helper.isCollectionType(ptype)) {
+ JavaClass componentType = helper.getJavaClass(Object.class);
+
+ Collection typeArgs = ptype.getActualTypeArguments();
+ if(!typeArgs.isEmpty()) {
+ componentType = (JavaClass) typeArgs.iterator().next();
+ }
+ updatePropertyType(property, ptype, componentType);
+ }else{
+ updatePropertyType(property, ptype, ptype);
+ }
+
+ if(helper.isAnnotationPresent(javaHasAnnotations, XmlVariableNode.class)){
+ XmlVariableNode variableNode = (XmlVariableNode) helper.getAnnotation(javaHasAnnotations, XmlVariableNode.class);
+ if(variableNode.type() != XmlVariableNode.DEFAULT.class){
+ property.setVariableClassName(variableNode.type().getName());
+
+ JavaClass componentType = helper.getJavaClass(variableNode.type());
+
+ if(helper.isCollectionType(ptype)){
+ property.setGenericType(componentType);
+ }else{
+ property.setType(componentType);
+ }
+
+ }
+ if(!variableNode.value().equals("##default")){
+ property.setVariableAttributeName(variableNode.value());
+ }
+ property.setVariableNodeAttribute(variableNode.attribute());
+ }
+
+
+ if((ptype.isArray() && !areEquals(ptype, byte[].class)) || (helper.isCollectionType(ptype) && !helper.isAnnotationPresent(javaHasAnnotations, XmlList.class)) ){
+ property.setNillable(true);
+ }
+ processPropertyAnnotations(info, cls, javaHasAnnotations, property);
+
+ if (helper.isAnnotationPresent(javaHasAnnotations, XmlPath.class)) {
+ XmlPath xmlPath = (XmlPath) helper.getAnnotation(javaHasAnnotations, XmlPath.class);
+ property.setXmlPath(xmlPath.value());
+ Field tempField = new XMLField(xmlPath.value());
+ boolean isAttribute = tempField.getLastXPathFragment().isAttribute();
+ property.setIsAttribute(isAttribute);
// set schema name
String schemaName = XMLProcessor.getNameFromXPath(xmlPath.value(), property.getPropertyName(), isAttribute);
- QName qName;
- NamespaceInfo nsInfo = getPackageInfoForPackage(cls).getNamespaceInfo();
- if(isAttribute){
- if (nsInfo.isAttributeFormQualified()) {
- qName = new QName(nsInfo.getNamespace(), schemaName);
- } else {
- qName = new QName(schemaName);
+ QName qName;
+ NamespaceInfo nsInfo = getPackageInfoForPackage(cls).getNamespaceInfo();
+ if(isAttribute){
+ if (nsInfo.isAttributeFormQualified()) {
+ qName = new QName(nsInfo.getNamespace(), schemaName);
+ } else {
+ qName = new QName(schemaName);
}
}else{
if (nsInfo.isElementFormQualified()) {
@@ -2047,13 +2097,13 @@ public class AnnotationsProcessor {
String predicatePath = currentPath;
TypeInfo targetInfo = info;
if(fragment.getNextFragment() == null) {
- //if this is the last fragment, and there's no text after, then this is
- //complex. May need to add the attribute property to the target type.
- processReferencedClass(ptype);
- TypeInfo predicateTypeInfo = typeInfo.get(ptype.getQualifiedName());
- if(predicateTypeInfo != null) {
- targetInfo = predicateTypeInfo;
- predicatePath = "";
+ //if this is the last fragment, and there's no text after, then this is
+ //complex. May need to add the attribute property to the target type.
+ processReferencedClass(ptype);
+ TypeInfo predicateTypeInfo = typeInfos.get(ptype.getQualifiedName());
+ if(predicateTypeInfo != null) {
+ targetInfo = predicateTypeInfo;
+ predicatePath = "";
}
}
Property predicateProperty = new Property(helper);
@@ -2080,13 +2130,13 @@ public class AnnotationsProcessor {
} else {
currentPath += fragment.getXPath();
}
- currentPath += "/";
- fragment = fragment.getNextFragment();
- }
-
- } else {
- property.setSchemaName(getQNameForProperty(property, propertyName, javaHasAnnotations, getPackageInfoForPackage(cls).getNamespaceInfo(), info));
- }
+ currentPath += "/";
+ fragment = fragment.getNextFragment();
+ }
+
+ } else {
+ property.setSchemaName(getQNameForProperty(property, propertyName, javaHasAnnotations, getPackageInfoForPackage(cls).getNamespaceInfo(), info));
+ }
ptype = property.getActualType();
if (ptype.isPrimitive()) {
@@ -2097,76 +2147,75 @@ public class AnnotationsProcessor {
property.setIsRequired(true);
}
}
-
- // apply class level adapters - don't override property level adapter
- if (!property.isSetXmlJavaTypeAdapter()) {
- TypeInfo refClassInfo = getTypeInfo().get(ptype.getQualifiedName());
- if (refClassInfo != null && refClassInfo.isSetXmlJavaTypeAdapter()) {
- org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter xmlJavaTypeAdapter = null;
- try {
+
+ // apply class level adapters - don't override property level adapter
+ if (!property.isSetXmlJavaTypeAdapter()) {
+ TypeInfo refClassInfo = getTypeInfos().get(ptype.getQualifiedName());
+ if (refClassInfo != null && refClassInfo.isSetXmlJavaTypeAdapter()) {
+ org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter xmlJavaTypeAdapter = null;
+ try {
xmlJavaTypeAdapter = refClassInfo.getXmlJavaTypeAdapter();
property.setXmlJavaTypeAdapter(refClassInfo.getXmlJavaTypeAdapter());
} catch (JAXBException e) {
throw JAXBException.invalidTypeAdapterClass(xmlJavaTypeAdapter.getValue(), cls.getName());
}
}
- }
-
- if(property.isXmlTransformation()){
- referencedByTransformer.add(property.getType().getName());
- }
- return property;
- }
-
-
- private void updatePropertyType(Property property, JavaClass ptype, JavaClass componentType){
- TypeInfo componentTypeInfo = typeInfo.get(componentType);
- if((componentTypeInfo != null && !componentTypeInfo.isTransient()) || !helper.isAnnotationPresent(componentType, XmlTransient.class)){
- property.setType(ptype);
- }else{
+ }
+
+ if(property.isXmlTransformation()){
+ referencedByTransformer.add(property.getType().getName());
+ }
+ return property;
+ }
+
+
+ private void updatePropertyType(Property property, JavaClass ptype, JavaClass componentType){
+ TypeInfo componentTypeInfo = typeInfos.get(componentType);
+ if((componentTypeInfo != null && !componentTypeInfo.isTransient()) || !helper.isAnnotationPresent(componentType, XmlTransient.class)){
+ property.setType(ptype);
+ }else{
JavaClass parent = componentType.getSuperclass();
while (parent != null) {
if (parent.getName().equals(JAVA_LANG_OBJECT)) {
property.setTransientType(true);
property.setType(ptype);
break;
- }
- // if there is a TypeInfo for parent check it for transient,
- // otherwise check the class
- TypeInfo parentTypeInfo = typeInfo.get(parent.getQualifiedName());
- if ((parentTypeInfo != null && !parentTypeInfo.isTransient()) || !helper.isAnnotationPresent(parent, XmlTransient.class)) {
- property.setType(parent);
- break;
+ }
+ // if there is a TypeInfo for parent check it for transient,
+ // otherwise check the class
+ TypeInfo parentTypeInfo = typeInfos.get(parent.getQualifiedName());
+ if ((parentTypeInfo != null && !parentTypeInfo.isTransient()) || !helper.isAnnotationPresent(parent, XmlTransient.class)) {
+ property.setType(parent);
+ break;
}
parent = parent.getSuperclass();
- }
- }
- }
-
- /**
- * Build a new 'choice' property. Here, we flag a new property as a 'choice'
- * and create/set an XmlModel XmlElements object based on the @XmlElements
- * annotation.
- *
- * Validation and building of the XmlElement properties will be done during
- * finalizeProperties in the processChoiceProperty method.
- *
- * @param javaHasAnnotations
- * @return
- */
+ }
+ }
+ }
+
+ /**
+ * Build a new 'choice' property. Here, we flag a new property as a 'choice'
+ * and create/set an XmlModel XmlElements object based on the @XmlElements
+ * annotation.
+ *
+ * Validation and building of the XmlElement properties will be done during
+ * finalizeProperties in the processChoiceProperty method.
+ *
+ * @param javaHasAnnotations
+ * @return
+ */
private Property buildChoiceProperty(JavaHasAnnotations javaHasAnnotations) {
Property choiceProperty = new Property(helper);
choiceProperty.setChoice(true);
boolean isIdRef = helper.isAnnotationPresent(javaHasAnnotations, XmlIDREF.class);
choiceProperty.setIsXmlIdRef(isIdRef);
- // build an XmlElement to set on the Property
- org.eclipse.persistence.jaxb.xmlmodel.XmlElements xmlElements = new org.eclipse.persistence.jaxb.xmlmodel.XmlElements();
- XmlElement[] elements = ((XmlElements) helper.getAnnotation(javaHasAnnotations, XmlElements.class)).value();
- for (int i = 0; i < elements.length; i++) {
- XmlElement next = elements[i];
- org.eclipse.persistence.jaxb.xmlmodel.XmlElement xmlElement = new org.eclipse.persistence.jaxb.xmlmodel.XmlElement();
- xmlElement.setDefaultValue(next.defaultValue());
- xmlElement.setName(next.name());
+ // build an XmlElement to set on the Property
+ org.eclipse.persistence.jaxb.xmlmodel.XmlElements xmlElements = new org.eclipse.persistence.jaxb.xmlmodel.XmlElements();
+ XmlElement[] elements = ((XmlElements) helper.getAnnotation(javaHasAnnotations, XmlElements.class)).value();
+ for (XmlElement next : elements) {
+ org.eclipse.persistence.jaxb.xmlmodel.XmlElement xmlElement = new org.eclipse.persistence.jaxb.xmlmodel.XmlElement();
+ xmlElement.setDefaultValue(next.defaultValue());
+ xmlElement.setName(next.name());
xmlElement.setNamespace(next.namespace());
xmlElement.setNillable(next.nillable());
xmlElement.setRequired(next.required());
@@ -2250,13 +2299,13 @@ public class AnnotationsProcessor {
/**
* Complete creation of a 'choice' property. Here, a Property is created for
- * each XmlElement in the XmlElements list. Validation is performed as well.
- * Each created Property is added to the owning Property's list of choice
- * properties.
- *
- * @param choiceProperty
- * @param info
- * @param cls
+ * each XmlElement in the XmlElements list. Validation is performed as well.
+ * Each created Property is added to the owning Property's list of choice
+ * properties.
+ *
+ * @param choiceProperty
+ * @param info
+ * @param cls
* @param propertyType
*/
private void processChoiceProperty(Property choiceProperty, TypeInfo info, JavaClass cls, JavaClass propertyType) {
@@ -2272,13 +2321,13 @@ public class AnnotationsProcessor {
XmlPath[] paths = null;
if (helper.isAnnotationPresent(choiceProperty.getElement(), XmlPaths.class)) {
- XmlPaths pathAnnotation = (XmlPaths) helper.getAnnotation(choiceProperty.getElement(), XmlPaths.class);
- paths = pathAnnotation.value();
- }
- ArrayList<Property> choiceProperties = new ArrayList<Property>();
- for (int i = 0; i < choiceProperty.getXmlElements().getXmlElement().size(); i++) {
- org.eclipse.persistence.jaxb.xmlmodel.XmlElement next = choiceProperty.getXmlElements().getXmlElement().get(i);
- Property choiceProp = new Property(helper);
+ XmlPaths pathAnnotation = (XmlPaths) helper.getAnnotation(choiceProperty.getElement(), XmlPaths.class);
+ paths = pathAnnotation.value();
+ }
+ List<Property> choiceProperties = new ArrayList<Property>();
+ for (int i = 0; i < choiceProperty.getXmlElements().getXmlElement().size(); i++) {
+ org.eclipse.persistence.jaxb.xmlmodel.XmlElement next = choiceProperty.getXmlElements().getXmlElement().get(i);
+ Property choiceProp = new Property(helper);
String name;
String namespace;
@@ -2316,18 +2365,18 @@ public class AnnotationsProcessor {
}
}
- // if the property has xml-idref, the target type of each
- // xml-element in the list must have an xml-id property
- if (choiceProperty.isXmlIdRef()) {
-
- JavaClass nextCls = helper.getJavaClass(next.getType());
- processReferencedClass(nextCls);
- TypeInfo tInfo = typeInfo.get(next.getType());
-
-
- if (tInfo == null || !tInfo.isIDSet()) {
- throw JAXBException.invalidXmlElementInXmlElementsList(propertyName, name);
- }
+ // if the property has xml-idref, the target type of each
+ // xml-element in the list must have an xml-id property
+ if (choiceProperty.isXmlIdRef()) {
+
+ JavaClass nextCls = helper.getJavaClass(next.getType());
+ processReferencedClass(nextCls);
+ TypeInfo tInfo = typeInfos.get(next.getType());
+
+
+ if (tInfo == null || !tInfo.isIDSet()) {
+ throw JAXBException.invalidXmlElementInXmlElementsList(propertyName, name);
+ }
}
QName qName = null;
@@ -2367,34 +2416,34 @@ public class AnnotationsProcessor {
} else {
choiceProp.setType(pType);
}
- }
- }
- }
-
- choiceProp.setSchemaName(qName);
- choiceProp.setSchemaType(getSchemaTypeFor(choiceProp.getType()));
- choiceProp.setIsXmlIdRef(choiceProperty.isXmlIdRef());
- choiceProp.setXmlElementWrapper(choiceProperty.getXmlElementWrapper());
- choiceProperties.add(choiceProp);
- processReferencedClass(choiceProp.getType());
- TypeInfo newInfo = typeInfo.get(choiceProp.getType().getQualifiedName());
- if (newInfo != null && newInfo.isTransient()) {
- throw JAXBException.invalidReferenceToTransientClass(info.getJavaClassName(), choiceProperty.getPropertyName(), newInfo.getJavaClassName());
- }
- }
- choiceProperty.setChoiceProperties(choiceProperties);
- }
-
+ }
+ }
+ }
+
+ choiceProp.setSchemaName(qName);
+ choiceProp.setSchemaType(getSchemaTypeFor(choiceProp.getType()));
+ choiceProp.setIsXmlIdRef(choiceProperty.isXmlIdRef());
+ choiceProp.setXmlElementWrapper(choiceProperty.getXmlElementWrapper());
+ choiceProperties.add(choiceProp);
+ processReferencedClass(choiceProp.getType());
+ TypeInfo newInfo = typeInfos.get(choiceProp.getType().getQualifiedName());
+ if (newInfo != null && newInfo.isTransient()) {
+ throw JAXBException.invalidReferenceToTransientClass(info.getJavaClassName(), choiceProperty.getPropertyName(), newInfo.getJavaClassName());
+ }
+ }
+ choiceProperty.setChoiceProperties(choiceProperties);
+ }
+
/**
* Build a reference property. Here we will build a list of XML model
* XmlElementRef objects, based on the @XmlElement(s) annotation, to store
- * on the Property. Processing of the elements and validation will be
- * performed during the finalize property phase via the
- * processReferenceProperty method.
- *
- * @param info
- * @param javaHasAnnotations
- * @param propertyName
+ * on the Property. Processing of the elements and validation will be
+ * performed during the finalize property phase via the
+ * processReferenceProperty method.
+ *
+ * @param info
+ * @param javaHasAnnotations
+ * @param propertyName
* @param ptype
* @return
*/
@@ -2415,54 +2464,54 @@ public class AnnotationsProcessor {
List<org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef> eltRefs = new ArrayList<org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef>();
for (XmlElementRef nextRef : elementRefs) {
org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef eltRef = new org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef();
- eltRef.setName(nextRef.name());
- eltRef.setNamespace(nextRef.namespace());
- eltRef.setType(nextRef.type().getName());
- property.setIsRequired(true);
- try{
- Method requireMethod = PrivilegedAccessHelper.getMethod(XmlElementRef.class, "required", new Class[0], true);
- if(requireMethod != null){
- Boolean val = (Boolean)PrivilegedAccessHelper.invokeMethod(requireMethod, nextRef);
- property.setIsRequired(val);
- }
- } catch (Exception exception){
- }
- eltRefs.add(eltRef);
+ eltRef.setName(nextRef.name());
+ eltRef.setNamespace(nextRef.namespace());
+ eltRef.setType(nextRef.type().getName());
+ property.setIsRequired(true);
+ try{
+ Method requireMethod = PrivilegedAccessHelper.getMethod(XmlElementRef.class, "required", new Class[0], true);
+ if(requireMethod != null){
+ Boolean val = (Boolean)PrivilegedAccessHelper.invokeMethod(requireMethod, nextRef);
+ property.setIsRequired(val);
+ }
+ } catch (Exception exception){
+ }
+ eltRefs.add(eltRef);
}
property.setIsReference(true);
property.setXmlElementRefs(eltRefs);
return property;
}
-
- /**
- * Build a reference property.
- *
- * @param property
- * @param info
- * @param javaHasAnnotations
- * @return
- */
- private Property processReferenceProperty(Property property, TypeInfo info, JavaClass cls) {
-
- for (org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef nextRef : property.getXmlElementRefs()) {
- JavaClass type = property.getType();
- String typeName = type.getQualifiedName();
- if (helper.isCollectionType(property.getType())) {
- if (type.hasActualTypeArguments()) {
- type = property.getGenericType();
+
+ /**
+ * Build a reference property.
+ *
+ * @param property
+ * @param info
+ * @param cls
+ * @return
+ */
+ private Property processReferenceProperty(Property property, TypeInfo info, JavaClass cls) {
+
+ for (org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef nextRef : property.getXmlElementRefs()) {
+ JavaClass type = property.getType();
+ String typeName;
+ if (helper.isCollectionType(property.getType())) {
+ if (type.hasActualTypeArguments()) {
+ type = property.getGenericType();
typeName = type.getQualifiedName();
}
}
if (!(nextRef.getType().equals("javax.xml.bind.annotation.XmlElementRef.DEFAULT") || nextRef.getType().equals("javax.xml.bind.annotation.XmlElementRef$DEFAULT"))) {
- typeName = nextRef.getType();
- type = helper.getJavaClass(typeName);
- }
-
- boolean missingReference = true;
- for (Entry<String, ElementDeclaration> entry : xmlRootElements.entrySet()) {
- ElementDeclaration entryValue = entry.getValue();
+ typeName = nextRef.getType();
+ type = helper.getJavaClass(typeName);
+ }
+
+ boolean missingReference = true;
+ for (Entry<String, ElementDeclaration> entry : xmlRootElements.entrySet()) {
+ ElementDeclaration entryValue = entry.getValue();
if (!(areEquals(type, Object.class)) && type.isAssignableFrom(entryValue.getJavaType())) {
addReferencedElement(property, entryValue);
missingReference = false;
@@ -2475,13 +2524,13 @@ public class AnnotationsProcessor {
namespace = EMPTY_STRING;
}
QName qname = new QName(namespace, name);
- JavaClass scopeClass = cls;
- ElementDeclaration referencedElement = null;
- while (!(scopeClass.getName().equals(JAVA_LANG_OBJECT))) {
- HashMap<QName, ElementDeclaration> elements = getElementDeclarationsForScope(scopeClass.getName());
- if (elements != null) {
- referencedElement = elements.get(qname);
- }
+ JavaClass scopeClass = cls;
+ ElementDeclaration referencedElement = null;
+ while (!(scopeClass.getName().equals(JAVA_LANG_OBJECT))) {
+ Map<QName, ElementDeclaration> elements = getElementDeclarationsForScope(scopeClass.getName());
+ if (elements != null) {
+ referencedElement = elements.get(qname);
+ }
if (referencedElement != null) {
break;
}
@@ -2496,29 +2545,29 @@ public class AnnotationsProcessor {
throw org.eclipse.persistence.exceptions.JAXBException.invalidElementRef(property.getPropertyName(), cls.getName());
}
}
- }
- return property;
- }
-
- private void processReferencePropertyTypes(Property property, TypeInfo info, JavaClass theClass) {
- for (org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef nextRef : property.getXmlElementRefs()) {
- JavaClass type = property.getType();
+ }
+ return property;
+ }
+
+ private void processReferencePropertyTypes(Property property, TypeInfo info, JavaClass theClass) {
+ for (org.eclipse.persistence.jaxb.xmlmodel.XmlElementRef nextRef : property.getXmlElementRefs()) {
+ JavaClass type = property.getType();
String typeName = type.getQualifiedName();
if (helper.isCollectionType(property.getType())) {
if (type.hasActualTypeArguments()) {
type = property.getGenericType();
- typeName = type.getQualifiedName();
- }
- }
-
- if(JAVAX_XML_BIND_JAXBELEMENT.equals(typeName)){
- Collection args = type.getActualTypeArguments();
- if(args.size() > 0){
- JavaClass theType = (JavaClass) args.iterator().next();
- processReferencedClass(theType);
- }
- }
-
+ typeName = type.getQualifiedName();
+ }
+ }
+
+ if(JAVAX_XML_BIND_JAXBELEMENT.equals(typeName)){
+ Collection args = type.getActualTypeArguments();
+ if(args.size() > 0){
+ JavaClass theType = (JavaClass) args.iterator().next();
+ processReferencedClass(theType);
+ }
+ }
+
// for DEFAULT, if from XML the type will be
// "XmlElementRef.DEFAULT",
// and from annotations the value will be "XmlElementref$DEFAULT"
@@ -2527,87 +2576,87 @@ public class AnnotationsProcessor {
type = helper.getJavaClass(typeName);
}
processReferencedClass(type);
- }
- }
-
- private void processPropertyAnnotations(TypeInfo info, JavaClass cls, JavaHasAnnotations javaHasAnnotations, Property property) {
- // Check for mixed context
- if (helper.isAnnotationPresent(javaHasAnnotations, XmlMixed.class)) {
- info.setMixed(true);
- property.setMixedContent(true);
- findAndProcessObjectFactory(cls);
- }
- if (helper.isAnnotationPresent(javaHasAnnotations, XmlContainerProperty.class)) {
- XmlContainerProperty container = (XmlContainerProperty) helper.getAnnotation(javaHasAnnotations, XmlContainerProperty.class);
- property.setInverseReferencePropertyName(container.value());
- property.setInverseReferencePropertyGetMethodName(container.getMethodName());
- property.setInverseReferencePropertySetMethodName(container.setMethodName());
- } else if (helper.isAnnotationPresent(javaHasAnnotations, XmlInverseReference.class)) {
- XmlInverseReference inverseReference = (XmlInverseReference) helper.getAnnotation(javaHasAnnotations, XmlInverseReference.class);
- property.setInverseReferencePropertyName(inverseReference.mappedBy());
-
- TypeInfo targetInfo = this.getTypeInfo().get(property.getActualType().getName());
- if (targetInfo != null && targetInfo.getXmlAccessType() == XmlAccessType.PROPERTY) {
- String propName = property.getPropertyName();
- propName = Character.toUpperCase(propName.charAt(0)) + propName.substring(1);
+ }
+ }
+
+ private void processPropertyAnnotations(TypeInfo info, JavaClass cls, JavaHasAnnotations propertyElement, Property property) {
+ // Check for mixed context
+ if (helper.isAnnotationPresent(propertyElement, XmlMixed.class)) {
+ info.setMixed(true);
+ property.setMixedContent(true);
+ findAndProcessObjectFactory(cls);
+ }
+ if (helper.isAnnotationPresent(propertyElement, XmlContainerProperty.class)) {
+ XmlContainerProperty container = (XmlContainerProperty) helper.getAnnotation(propertyElement, XmlContainerProperty.class);
+ property.setInverseReferencePropertyName(container.value());
+ property.setInverseReferencePropertyGetMethodName(container.getMethodName());
+ property.setInverseReferencePropertySetMethodName(container.setMethodName());
+ } else if (helper.isAnnotationPresent(propertyElement, XmlInverseReference.class)) {
+ XmlInverseReference inverseReference = (XmlInverseReference) helper.getAnnotation(propertyElement, XmlInverseReference.class);
+ property.setInverseReferencePropertyName(inverseReference.mappedBy());
+
+ TypeInfo targetInfo = this.getTypeInfos().get(property.getActualType().getName());
+ if (targetInfo != null && targetInfo.getXmlAccessType() == XmlAccessType.PROPERTY) {
+ String propName = property.getPropertyName();
+ propName = Character.toUpperCase(propName.charAt(0)) + propName.substring(1);
property.setInverseReferencePropertyGetMethodName(GET_STR + propName);
- property.setInverseReferencePropertySetMethodName(SET_STR + propName);
- }
-
- property.setInverseReference(true, helper.isAnnotationPresent(javaHasAnnotations, XmlElement.class));
- }
-
- processXmlJavaTypeAdapter(property, info, cls);
- if (helper.isAnnotationPresent(property.getElement(), XmlAttachmentRef.class) && areEquals(property.getActualType(), JAVAX_ACTIVATION_DATAHANDLER)) {
- property.setIsSwaAttachmentRef(true);
- property.setSchemaType(Constants.SWA_REF_QNAME);
- }
+ property.setInverseReferencePropertySetMethodName(SET_STR + propName);
+ }
+
+ property.setInverseReference(true, helper.isAnnotationPresent(propertyElement, XmlElement.class));
+ }
+
+ processXmlJavaTypeAdapter(property, info, cls);
+ if (helper.isAnnotationPresent(propertyElement, XmlAttachmentRef.class) && areEquals(property.getActualType(), JAVAX_ACTIVATION_DATAHANDLER)) {
+ property.setIsSwaAttachmentRef(true);
+ property.setSchemaType(Constants.SWA_REF_QNAME);
+ }
processXmlElement(property, info);
// JavaClass ptype = property.getActualType();
if (!(property.isSwaAttachmentRef()) && isMtomAttachment(property)) {
- property.setIsMtomAttachment(true);
- property.setSchemaType(Constants.BASE_64_BINARY_QNAME);
- }
- if (helper.isAnnotationPresent(property.getElement(), XmlMimeType.class)) {
- property.setMimeType(((XmlMimeType) helper.getAnnotation(property.getElement(), XmlMimeType.class)).value());
- }
- // set indicator for inlining binary data - setting this to true on a
- // non-binary data type won't have any affect
- if (helper.isAnnotationPresent(property.getElement(), XmlInlineBinaryData.class) || info.isBinaryDataToBeInlined()) {
- property.setisInlineBinaryData(true);
- }
-
- // Get schema-type info if specified and set it on the property for
- // later use:
- if (helper.isAnnotationPresent(property.getElement(), XmlSchemaType.class)) {
- XmlSchemaType schemaType = (XmlSchemaType) helper.getAnnotation(property.getElement(), XmlSchemaType.class);
- QName schemaTypeQname = new QName(schemaType.namespace(), schemaType.name());
- property.setSchemaType(schemaTypeQname);
- }
-
- if (helper.isAnnotationPresent(property.getElement(), XmlAttribute.class)) {
- property.setIsAttribute(true);
- property.setIsRequired(((XmlAttribute) helper.getAnnotation(property.getElement(), XmlAttribute.class)).required());
- }
-
- if (helper.isAnnotationPresent(property.getElement(), XmlAnyAttribute.class)) {
- if (info.isSetAnyAttributePropertyName() && !info.getAnyAttributePropertyName().equals(property.getPropertyName())) {
- throw org.eclipse.persistence.exceptions.JAXBException.multipleAnyAttributeMapping(cls.getName());
- }
+ property.setIsMtomAttachment(true);
+ property.setSchemaType(Constants.BASE_64_BINARY_QNAME);
+ }
+ if (helper.isAnnotationPresent(propertyElement, XmlMimeType.class)) {
+ property.setMimeType(((XmlMimeType) helper.getAnnotation(propertyElement, XmlMimeType.class)).value());
+ }
+ // set indicator for inlining binary data - setting this to true on a
+ // non-binary data type won't have any affect
+ if (helper.isAnnotationPresent(propertyElement, XmlInlineBinaryData.class) || info.isBinaryDataToBeInlined()) {
+ property.setisInlineBinaryData(true);
+ }
+
+ // Get schema-type info if specified and set it on the property for
+ // later use:
+ if (helper.isAnnotationPresent(propertyElement, XmlSchemaType.class)) {
+ XmlSchemaType schemaType = (XmlSchemaType) helper.getAnnotation(propertyElement, XmlSchemaType.class);
+ QName schemaTypeQname = new QName(schemaType.namespace(), schemaType.name());
+ property.setSchemaType(schemaTypeQname);
+ }
+
+ if (helper.isAnnotationPresent(propertyElement, XmlAttribute.class)) {
+ property.setIsAttribute(true);
+ property.setIsRequired(((XmlAttribute) helper.getAnnotation(propertyElement, XmlAttribute.class)).required());
+ }
+
+ if (helper.isAnnotationPresent(propertyElement, XmlAnyAttribute.class)) {
+ if (info.isSetAnyAttributePropertyName() && !info.getAnyAttributePropertyName().equals(property.getPropertyName())) {
+ throw org.eclipse.persistence.exceptions.JAXBException.multipleAnyAttributeMapping(cls.getName());
+ }
if (!helper.isMapType(property.getType())) {
throw org.eclipse.persistence.exceptions.JAXBException.anyAttributeOnNonMap(property.getPropertyName());
}
property.setIsAnyAttribute(true);
info.setAnyAttributePropertyName(property.getPropertyName());
- }
-
- // Make sure XmlElementWrapper annotation is on a collection or array
- if (helper.isAnnotationPresent(property.getElement(), XmlElementWrapper.class)) {
- XmlElementWrapper wrapper = (XmlElementWrapper) helper.getAnnotation(property.getElement(), XmlElementWrapper.class);
- org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper xmlEltWrapper = new org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper();
-
- String wrapperName = wrapper.name();
+ }
+
+ // Make sure XmlElementWrapper annotation is on a collection or array
+ if (helper.isAnnotationPresent(propertyElement, XmlElementWrapper.class)) {
+ XmlElementWrapper wrapper = (XmlElementWrapper) helper.getAnnotation(propertyElement, XmlElementWrapper.class);
+ org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper xmlEltWrapper = new org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper();
+
+ String wrapperName = wrapper.name();
if (wrapperName.equals(XMLProcessor.DEFAULT)) {
wrapperName = info.getXmlNameTransformer().transformElementName(property.getPropertyName());
}
@@ -2615,67 +2664,67 @@ public class AnnotationsProcessor {
xmlEltWrapper.setNamespace(wrapper.namespace());
xmlEltWrapper.setNillable(wrapper.nillable());
xmlEltWrapper.setRequired(wrapper.required());
- property.setXmlElementWrapper(xmlEltWrapper);
- }
-
- if (helper.isAnnotationPresent(property.getElement(), XmlList.class)) {
- // Make sure XmlList annotation is on a collection or array
- if (!helper.isCollectionType(property.getType()) && !property.getType().isArray()) {
- throw JAXBException.invalidList(property.getPropertyName());
- }
- property.setIsXmlList(true);
- }
-
- if (helper.isAnnotationPresent(property.getElement(), XmlValue.class)) {
- property.setIsXmlValue(true);
- info.setXmlValueProperty(property);
- }
-
- if (helper.isAnnotationPresent(property.getElement(), XmlReadOnly.class)) {
- property.setReadOnly(true);
- }
- if (helper.isAnnotationPresent(property.getElement(), XmlWriteOnly.class)) {
- property.setWriteOnly(true);
- }
- if (helper.isAnnotationPresent(property.getElement(), XmlCDATA.class)) {
- property.setCdata(true);
- }
- if (helper.isAnnotationPresent(property.getElement(), XmlAccessMethods.class)) {
- XmlAccessMethods accessMethods = (XmlAccessMethods) helper.getAnnotation(property.getElement(), XmlAccessMethods.class);
- if (!(accessMethods.getMethodName().equals(EMPTY_STRING))) {
- property.setGetMethodName(accessMethods.getMethodName());
+ property.setXmlElementWrapper(xmlEltWrapper);
+ }
+
+ if (helper.isAnnotationPresent(propertyElement, XmlList.class)) {
+ // Make sure XmlList annotation is on a collection or array
+ if (!helper.isCollectionType(property.getType()) && !property.getType().isArray()) {
+ throw JAXBException.invalidList(property.getPropertyName());
}
+ property.setIsXmlList(true);
+ }
+
+ if (helper.isAnnotationPresent(propertyElement, XmlValue.class)) {
+ property.setIsXmlValue(true);
+ info.setXmlValueProperty(property);
+ }
+
+ if (helper.isAnnotationPresent(propertyElement, XmlReadOnly.class)) {
+ property.setReadOnly(true);
+ }
+ if (helper.isAnnotationPresent(propertyElement, XmlWriteOnly.class)) {
+ property.setWriteOnly(true);
+ }
+ if (helper.isAnnotationPresent(propertyElement, XmlCDATA.class)) {
+ property.setCdata(true);
+ }
+ if (helper.isAnnotationPresent(propertyElement, XmlAccessMethods.class)) {
+ XmlAccessMethods accessMethods = (XmlAccessMethods) helper.getAnnotation(propertyElement, XmlAccessMethods.class);
+ if (!(accessMethods.getMethodName().equals(EMPTY_STRING))) {
+ property.setGetMethodName(accessMethods.getMethodName());
+ }
if (!(accessMethods.setMethodName().equals(EMPTY_STRING))) {
property.setSetMethodName(accessMethods.setMethodName());
}
if (!(property.isMethodProperty())) {
property.setMethodProperty(true);
}
- }
-
- // handle user properties
- if (helper.isAnnotationPresent(property.getElement(), XmlProperties.class)) {
- XmlProperties xmlProperties = (XmlProperties) helper.getAnnotation(property.getElement(), XmlProperties.class);
- Map<Object, Object> propertiesMap = createUserPropertiesMap(xmlProperties.value());
- property.setUserProperties(propertiesMap);
- } else if (helper.isAnnotationPresent(property.getElement(), XmlProperty.class)) {
- XmlProperty xmlProperty = (XmlProperty) helper.getAnnotation(property.getElement(), XmlProperty.class);
- Map<Object, Object> propertiesMap = createUserPropertiesMap(new XmlProperty[] { xmlProperty });
- property.setUserProperties(propertiesMap);
- }
- // handle XmlKey
- if (helper.isAnnotationPresent(property.getElement(), XmlKey.class)) {
- info.addXmlKeyProperty(property);
- }
- // handle XmlJoinNode(s)
+ }
+
+ // handle user properties
+ if (helper.isAnnotationPresent(propertyElement, XmlProperties.class)) {
+ XmlProperties xmlProperties = (XmlProperties) helper.getAnnotation(propertyElement, XmlProperties.class);
+ Map<Object, Object> propertiesMap = createUserPropertiesMap(xmlProperties.value());
+ property.setUserProperties(propertiesMap);
+ } else if (helper.isAnnotationPresent(propertyElement, XmlProperty.class)) {
+ XmlProperty xmlProperty = (XmlProperty) helper.getAnnotation(propertyElement, XmlProperty.class);
+ Map<Object, Object> propertiesMap = createUserPropertiesMap(new XmlProperty[] { xmlProperty });
+ property.setUserProperties(propertiesMap);
+ }
+ // handle XmlKey
+ if (helper.isAnnotationPresent(propertyElement, XmlKey.class)) {
+ info.addXmlKeyProperty(property);
+ }
+ // handle XmlJoinNode(s)
processXmlJoinNodes(property);
- processXmlNullPolicy(property);
-
- // Handle XmlLocation
- JavaHasAnnotations elem = property.getElement();
- if (helper.isAnnotationPresent(elem, XmlLocation.class) || helper.isAnnotationPresent(elem, CompilerHelper.XML_LOCATION_ANNOTATION_CLASS) || helper.isAnnotationPresent(elem, CompilerHelper.INTERNAL_XML_LOCATION_ANNOTATION_CLASS)) {
- if (!helper.getJavaClass(Constants.LOCATOR_CLASS).isAssignableFrom(property.getType())) {
- throw JAXBException.invalidXmlLocation(property.getPropertyName(), property.getType().getName());
+ processXmlNullPolicy(property);
+
+ // Handle XmlLocation
+ JavaHasAnnotations elem = propertyElement;
+ if (helper.isAnnotationPresent(elem, XmlLocation.class) || helper.isAnnotationPresent(elem, CompilerHelper.XML_LOCATION_ANNOTATION_CLASS) || helper.isAnnotationPresent(elem, CompilerHelper.INTERNAL_XML_LOCATION_ANNOTATION_CLASS)) {
+ if (!helper.getJavaClass(Constants.LOCATOR_CLASS).isAssignableFrom(property.getType())) {
+ throw JAXBException.invalidXmlLocation(property.getPropertyName(), property.getType().getName());
}
property.setXmlLocation(true);
}
@@ -2683,18 +2732,18 @@ public class AnnotationsProcessor {
/**
* Process XmlJoinNode(s) for a given Property. An
- * org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNode(s) will be
- * created/populated using the annotation, and set on the Property for later
- * processing.
- *
- * It is assumed that for a single join node XmlJoinNode will be used, and
- * for multiple join nodes XmlJoinNodes will be used.
- *
- * @param property
- * Property that may contain @XmlJoinNodes/@XmlJoinNode
- */
- private void processXmlJoinNodes(Property property) {
- List<org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode> xmlJoinNodeList;
+ * org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNode(s) will be
+ * created/populated using the annotation, and set on the Property for later
+ * processing.
+ *
+ * It is assumed that for a single join node XmlJoinNode will be used, and
+ * for multiple join nodes XmlJoinNodes will be used.
+ *
+ * @param property
+ * Property that may contain @XmlJoinNodes/@XmlJoinNode
+ */
+ private void processXmlJoinNodes(Property property) {
+ List<org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode> xmlJoinNodeList;
org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode xmlJoinNode;
org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes xmlJoinNodes;
// handle XmlJoinNodes
@@ -2727,16 +2776,16 @@ public class AnnotationsProcessor {
/**
* Responsible for validating transformer settings on a given property.
* Validates that for field transformers either a transformer class OR
- * method name is set (not both) and that an xml-path is set. Validates that
- * for attribute transformers either a transformer class OR method name is
- * set (not both).
- *
- * @param property
- */
- private void processXmlTransformationProperty(Property property) {
- if (property.isSetXmlTransformation()) {
- XmlTransformation xmlTransformation = property.getXmlTransformation();
- // validate transformer(s)
+ * method name is set (not both) and that an xml-path is set. Validates that
+ * for attribute transformers either a transformer class OR method name is
+ * set (not both).
+ *
+ * @param property
+ */
+ private void validateXmlTransformationProperty(Property property) {
+ if (property.isSetXmlTransformation()) {
+ XmlTransformation xmlTransformation = property.getXmlTransformation();
+ // validate transformer(s)
if (xmlTransformation.isSetXmlReadTransformer()) {
// validate read transformer
XmlReadTransformer readTransformer = xmlTransformation.getXmlReadTransformer();
@@ -2779,13 +2828,13 @@ public class AnnotationsProcessor {
}
}
- /**
- * Compares a JavaModel JavaClass to a Class. Equality is based on the raw
- * name of the JavaClass compared to the canonical name of the Class.
- *
- * @param src
- * @param tgt
- * @return
+ /**
+ * Compares a JavaModel JavaClass to a Class. Equality is based on the raw
+ * name of the JavaClass compared to the canonical name of the Class.
+ *
+ * @param src
+ * @param tgt
+ * @return
*/
protected boolean areEquals(JavaClass src, Class tgt) {
if (src == null || tgt == null) {
@@ -2797,21 +2846,21 @@ public class AnnotationsProcessor {
private void processXmlNullPolicy(Property property) {
if (helper.isAnnotationPresent(property.getElement(), XmlNullPolicy.class)) {
XmlNullPolicy nullPolicy = (XmlNullPolicy) helper.getAnnotation(property.getElement(), XmlNullPolicy.class);
- org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy policy = new org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy();
- policy.setEmptyNodeRepresentsNull(nullPolicy.emptyNodeRepresentsNull());
- policy.setIsSetPerformedForAbsentNode(nullPolicy.isSetPerformedForAbsentNode());
- policy.setXsiNilRepresentsNull(Boolean.valueOf(nullPolicy.xsiNilRepresentsNull()));
- policy.setNullRepresentationForXml(org.eclipse.persistence.jaxb.xmlmodel.XmlMarshalNullRepresentation.valueOf(nullPolicy.nullRepresentationForXml().toString()));
- property.setNullPolicy(policy);
-
+ org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy policy = new org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy();
+ policy.setEmptyNodeRepresentsNull(nullPolicy.emptyNodeRepresentsNull());
+ policy.setIsSetPerformedForAbsentNode(nullPolicy.isSetPerformedForAbsentNode());
+ policy.setXsiNilRepresentsNull(nullPolicy.xsiNilRepresentsNull());
+ policy.setNullRepresentationForXml(org.eclipse.persistence.jaxb.xmlmodel.XmlMarshalNullRepresentation.valueOf(nullPolicy.nullRepresentationForXml().toString()));
+ property.setNullPolicy(policy);
+
} else if (helper.isAnnotationPresent(property.getElement(), XmlIsSetNullPolicy.class)) {
- XmlIsSetNullPolicy nullPolicy = (XmlIsSetNullPolicy) helper.getAnnotation(property.getElement(), XmlIsSetNullPolicy.class);
- org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy policy = new org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy();
- policy.setEmptyNodeRepresentsNull(nullPolicy.emptyNodeRepresentsNull());
- policy.setXsiNilRepresentsNull(Boolean.valueOf(nullPolicy.xsiNilRepresentsNull()));
- policy.setNullRepresentationForXml(org.eclipse.persistence.jaxb.xmlmodel.XmlMarshalNullRepresentation.valueOf(nullPolicy.nullRepresentationForXml().toString()));
- policy.setIsSetMethodName(nullPolicy.isSetMethodName());
- for (XmlParameter next : nullPolicy.isSetParameters()) {
+ XmlIsSetNullPolicy nullPolicy = (XmlIsSetNullPolicy) helper.getAnnotation(property.getElement(), XmlIsSetNullPolicy.class);
+ org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy policy = new org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy();
+ policy.setEmptyNodeRepresentsNull(nullPolicy.emptyNodeRepresentsNull());
+ policy.setXsiNilRepresentsNull(nullPolicy.xsiNilRepresentsNull());
+ policy.setNullRepresentationForXml(org.eclipse.persistence.jaxb.xmlmodel.XmlMarshalNullRepresentation.valueOf(nullPolicy.nullRepresentationForXml().toString()));
+ policy.setIsSetMethodName(nullPolicy.isSetMethodName());
+ for (XmlParameter next : nullPolicy.isSetParameters()) {
org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy.IsSetParameter param = new org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy.IsSetParameter();
param.setValue(next.value());
param.setType(next.type().getName());
@@ -2821,15 +2870,15 @@ public class AnnotationsProcessor {
}
}
- /**
- * Compares a JavaModel JavaClass to a Class. Equality is based on the raw
- * name of the JavaClass compared to the canonical name of the Class.
- *
- * @param src
- * @param tgt
- * @return
- */
- protected boolean areEquals(JavaClass src, String tgtCanonicalName) {
+ /**
+ * Compares a JavaModel JavaClass to a Class. Equality is based on the raw
+ * name of the JavaClass compared to the canonical name of the Class.
+ *
+ * @param src
+ * @param tgtCanonicalName
+ * @return
+ */
+ protected boolean areEquals(JavaClass src, String tgtCanonicalName) {
if (src == null || tgtCanonicalName == null) {
return false;
}
@@ -2849,34 +2898,34 @@ public class AnnotationsProcessor {
// First collect all the getters and setters
ArrayList<JavaMethod> propertyMethods = new ArrayList<JavaMethod>();
for (JavaMethod next : new ArrayList<JavaMethod>(cls.getDeclaredMethods())) {
- if(!next.isSynthetic()){
- if (((next.getName().startsWith(GET_STR) && next.getName().length() > 3) || (next.getName().startsWith(IS_STR) && next.getName().length() > 2)) && next.getParameterTypes().length == 0 && next.getReturnType() != helper.getJavaClass(java.lang.Void.class)) {
- int modifiers = next.getModifiers();
-
- if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers) && ((onlyPublic && Modifier.isPublic(next.getModifiers())) || !onlyPublic || hasJAXBAnnotations(next))) {
- propertyMethods.add(next);
- }
- } else if (next.getName().startsWith(SET_STR) && next.getName().length() > 3 && next.getParameterTypes().length == 1) {
- int modifiers = next.getModifiers();
- if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers) && ((onlyPublic && Modifier.isPublic(next.getModifiers())) || !onlyPublic || hasJAXBAnnotations(next))) {
- propertyMethods.add(next);
- }
- }
- }
- }
- // Next iterate over the getters and find their setter methods, add
- // whichever one is
+ if(!next.isSynthetic()){
+ if (((next.getName().startsWith(GET_STR) && next.getName().length() > 3) || (next.getName().startsWith(IS_STR) && next.getName().length() > 2)) && next.getParameterTypes().length == 0 && next.getReturnType() != helper.getJavaClass(java.lang.Void.class)) {
+ int modifiers = next.getModifiers();
+
+ if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers) && ((onlyPublic && Modifier.isPublic(next.getModifiers())) || !onlyPublic || hasJAXBAnnotations(next))) {
+ propertyMethods.add(next);
+ }
+ } else if (next.getName().startsWith(SET_STR) && next.getName().length() > 3 && next.getParameterTypes().length == 1) {
+ int modifiers = next.getModifiers();
+ if (!Modifier.isStatic(modifiers) && !Modifier.isTransient(modifiers) && ((onlyPublic && Modifier.isPublic(next.getModifiers())) || !onlyPublic || hasJAXBAnnotations(next))) {
+ propertyMethods.add(next);
+ }
+ }
+ }
+ }
+ // Next iterate over the getters and find their setter methods, add
+ // whichever one is
// annotated to the properties list. If neither is, use the getter
-
- // keep track of property names to avoid processing the same property
- // twice (for getter and setter)
- ArrayList<String> propertyNames = new ArrayList<String>();
- for (int i = 0; i < propertyMethods.size(); i++) {
- boolean isPropertyTransient = false;
- JavaMethod nextMethod = propertyMethods.get(i);
- String propertyName = EMPTY_STRING;
-
- JavaMethod getMethod;
+
+ // keep track of property names to avoid processing the same property
+ // twice (for getter and setter)
+ List<String> propertyNames = new ArrayList<String>();
+ for (JavaMethod propertyMethod1 : propertyMethods) {
+ boolean isPropertyTransient = false;
+ JavaMethod nextMethod = propertyMethod1;
+ String propertyName = EMPTY_STRING;
+
+ JavaMethod getMethod;
JavaMethod setMethod;
JavaMethod propertyMethod = null;
@@ -2894,31 +2943,31 @@ public class AnnotationsProcessor {
// character, if necessary
propertyName = Introspector.decapitalize(propertyName);
- JavaClass[] paramTypes = { (JavaClass) getMethod.getReturnType() };
- setMethod = cls.getDeclaredMethod(setMethodName, paramTypes);
-
- if(setMethod == null) {
- //if there's no locally declared set method, check for an inherited
- //set method
- setMethod = cls.getMethod(setMethodName, paramTypes);
- }
- if(setMethod == null && !(hasJAXBAnnotations(getMethod))) {
- //if there's no corresponding setter, and not explicitly
- //annotated, don't process
- isPropertyTransient = true;
- }
-
- if (setMethod != null && hasJAXBAnnotations(setMethod)) {
- // use the set method if it exists and is annotated
- boolean isTransient = helper.isAnnotationPresent(setMethod, XmlTransient.class);
+ JavaClass[] paramTypes = { (JavaClass) getMethod.getReturnType() };
+ setMethod = cls.getDeclaredMethod(setMethodName, paramTypes);
+
+ if (setMethod == null) {
+ //if there's no locally declared set method, check for an inherited
+ //set method
+ setMethod = cls.getMethod(setMethodName, paramTypes);
+ }
+ if (setMethod == null && !(hasJAXBAnnotations(getMethod))) {
+ //if there's no corresponding setter, and not explicitly
+ //annotated, don't process
+ isPropertyTransient = true;
+ }
+
+ if (setMethod != null && hasJAXBAnnotations(setMethod)) {
+ // use the set method if it exists and is annotated
+ boolean isTransient = helper.isAnnotationPresent(setMethod, XmlTransient.class);
boolean isLocation = helper.isAnnotationPresent(setMethod, XmlLocation.class) ||
- helper.isAnnotationPresent(setMethod, CompilerHelper.XML_LOCATION_ANNOTATION_CLASS) ||
- helper.isAnnotationPresent(setMethod, CompilerHelper.INTERNAL_XML_LOCATION_ANNOTATION_CLASS);
- propertyMethod = setMethod;
- if(isTransient) {
- isPropertyTransient = true;
- // XmlLocation can also be transient
- if (isLocation) {
+ helper.isAnnotationPresent(setMethod, CompilerHelper.XML_LOCATION_ANNOTATION_CLASS) ||
+ helper.isAnnotationPresent(setMethod, CompilerHelper.INTERNAL_XML_LOCATION_ANNOTATION_CLASS);
+ propertyMethod = setMethod;
+ if (isTransient) {
+ isPropertyTransient = true;
+ // XmlLocation can also be transient
+ if (isLocation) {
propertyMethod = setMethod;
info.setLocationAware(true);
}
@@ -2926,13 +2975,13 @@ public class AnnotationsProcessor {
} else if ((onlyExplicit && hasJAXBAnnotations(getMethod)) || !onlyExplicit) {
boolean isTransient = helper.isAnnotationPresent(getMethod, XmlTransient.class);
boolean isLocation = helper.isAnnotationPresent(getMethod, XmlLocation.class) ||
- helper.isAnnotationPresent(setMethod, CompilerHelper.XML_LOCATION_ANNOTATION_CLASS) ||
- helper.isAnnotationPresent(setMethod, CompilerHelper.INTERNAL_XML_LOCATION_ANNOTATION_CLASS);
- propertyMethod = getMethod;
- if(isTransient) {
- isPropertyTransient = true;
- // XmlLocation can also be transient
- if (isLocation) {
+ helper.isAnnotationPresent(setMethod, CompilerHelper.XML_LOCATION_ANNOTATION_CLASS) ||
+ helper.isAnnotationPresent(setMethod, CompilerHelper.INTERNAL_XML_LOCATION_ANNOTATION_CLASS);
+ propertyMethod = getMethod;
+ if (isTransient) {
+ isPropertyTransient = true;
+ // XmlLocation can also be transient
+ if (isLocation) {
propertyMethod = getMethod;
info.setLocationAware(true);
}
@@ -2943,28 +2992,28 @@ public class AnnotationsProcessor {
} else {
propertyName = nextMethod.getName().substring(3);
setMethod = nextMethod;
-
- String getMethodName = GET_STR + propertyName;
-
- getMethod = cls.getDeclaredMethod(getMethodName, new JavaClass[] {});
- if (getMethod == null) {
- // try is instead of get
- getMethodName = IS_STR + propertyName;
- getMethod = cls.getDeclaredMethod(getMethodName, new JavaClass[] {});
- }
-
- //may look for get method on parent class
- if(getMethod == null) {
- //look for inherited getMethod
- getMethod = cls.getMethod(GET_STR + propertyName, new JavaClass[]{});
- if(getMethod == null) {
- getMethod = cls.getMethod(IS_STR + propertyName, new JavaClass[]{});
- }
- }
- if(getMethod == null && !(hasJAXBAnnotations(setMethod))) {
- isPropertyTransient = true;
- }
- if (getMethod != null && hasJAXBAnnotations(getMethod)) {
+
+ String getMethodName = GET_STR + propertyName;
+
+ getMethod = cls.getDeclaredMethod(getMethodName, new JavaClass[] { });
+ if (getMethod == null) {
+ // try is instead of get
+ getMethodName = IS_STR + propertyName;
+ getMethod = cls.getDeclaredMethod(getMethodName, new JavaClass[] { });
+ }
+
+ //may look for get method on parent class
+ if (getMethod == null) {
+ //look for inherited getMethod
+ getMethod = cls.getMethod(GET_STR + propertyName, new JavaClass[] { });
+ if (getMethod == null) {
+ getMethod = cls.getMethod(IS_STR + propertyName, new JavaClass[] { });
+ }
+ }
+ if (getMethod == null && !(hasJAXBAnnotations(setMethod))) {
+ isPropertyTransient = true;
+ }
+ if (getMethod != null && hasJAXBAnnotations(getMethod)) {
// use the set method if it exists and is annotated
boolean isTransient = helper.isAnnotationPresent(getMethod, XmlTransient.class);
boolean isLocation = helper.isAnnotationPresent(getMethod, XmlLocation.class) ||
@@ -3008,43 +3057,43 @@ public class AnnotationsProcessor {
ptype = (JavaClass) getMethod.getReturnType();
} else {
ptype = setMethod.getParameterTypes()[0];
- }
-
- if (!propertyNames.contains(propertyName)) {
- try {
- Property property = buildNewProperty(info, cls, propertyMethod, propertyName, ptype);
- propertyNames.add(propertyName);
- property.setTransient(isPropertyTransient);
-
- if (getMethod != null) {
- property.setOriginalGetMethodName(getMethod.getName());
- if (property.getGetMethodName() == null) {
- property.setGetMethodName(getMethod.getName());
- }
- }
- if (setMethod != null) {
- property.setOriginalSetMethodName(setMethod.getName());
- if (property.getSetMethodName() == null) {
- property.setSetMethodName(setMethod.getName());
- }
- }
- property.setMethodProperty(true);
-
- //boolean isTransient = helper.isAnnotationPresent(property.getElement(), XmlTransient.class);
- //boolean isLocation = helper.isAnnotationPresent(property.getElement(), XmlLocation.class) ||
- // helper.isAnnotationPresent(setMethod, CompilerHelper.XML_LOCATION_ANNOTATION_CLASS) ||
- // helper.isAnnotationPresent(setMethod, CompilerHelper.INTERNAL_XML_LOCATION_ANNOTATION_CLASS);
- //if (!isTransient || (isTransient && isLocation)) {
- properties.add(property);
- //}
- } catch(JAXBException ex) {
- if(ex.getErrorCode() != JAXBException.INVALID_INTERFACE || !isPropertyTransient) {
- throw ex;
- }
- }
- }
- }
-
+ }
+
+ if (!propertyNames.contains(propertyName)) {
+ try {
+ Property property = buildNewProperty(info, cls, propertyMethod, propertyName, ptype);
+ propertyNames.add(propertyName);
+ property.setTransient(isPropertyTransient);
+
+ if (getMethod != null) {
+ property.setOriginalGetMethodName(getMethod.getName());
+ if (property.getGetMethodName() == null) {
+ property.setGetMethodName(getMethod.getName());
+ }
+ }
+ if (setMethod != null) {
+ property.setOriginalSetMethodName(setMethod.getName());
+ if (property.getSetMethodName() == null) {
+ property.setSetMethodName(setMethod.getName());
+ }
+ }
+ property.setMethodProperty(true);
+
+ //boolean isTransient = helper.isAnnotationPresent(property.getElement(), XmlTransient.class);
+ //boolean isLocation = helper.isAnnotationPresent(property.getElement(), XmlLocation.class) ||
+ // helper.isAnnotationPresent(setMethod, CompilerHelper.XML_LOCATION_ANNOTATION_CLASS) ||
+ // helper.isAnnotationPresent(setMethod, CompilerHelper.INTERNAL_XML_LOCATION_ANNOTATION_CLASS);
+ //if (!isTransient || (isTransient && isLocation)) {
+ properties.add(property);
+ //}
+ } catch (JAXBException ex) {
+ if (ex.getErrorCode() != JAXBException.INVALID_INTERFACE || !isPropertyTransient) {
+ throw ex;
+ }
+ }
+ }
+ }
+
properties = removeSuperclassProperties(cls, properties);
// default to alphabetical ordering
@@ -3059,13 +3108,13 @@ public class AnnotationsProcessor {
// Check for any get() methods that are overridden in the subclass.
// If we find any, remove the property, because it is already defined on
- // the superclass.
- JavaClass superClass = cls.getSuperclass();
- if (null != superClass) {
- TypeInfo superClassInfo = typeInfo.get(superClass.getQualifiedName());
- if (superClassInfo != null && !superClassInfo.isTransient()) {
- for (Property prop : properties) {
- for (Property superProp : superClassInfo.getProperties().values()) {
+ // the superclass.
+ JavaClass superClass = cls.getSuperclass();
+ if (null != superClass) {
+ TypeInfo superClassInfo = typeInfos.get(superClass.getQualifiedName());
+ if (superClassInfo != null && !superClassInfo.isTransient()) {
+ for (Property prop : properties) {
+ for (Property superProp : superClassInfo.getProperties().values()) {
if (superProp.getGetMethodName() != null && superProp.getGetMethodName().equals(prop.getGetMethodName()) && !superProp.isTransient()) {
revisedProperties.remove(prop);
}
@@ -3115,36 +3164,34 @@ public class AnnotationsProcessor {
return publicMethodProperties;
} else {
// add any non-duplicate method properties to the collection.
- // - in the case of a collision if one is annotated use it,
- // otherwise
- // use the field.
- HashMap<String, Property> fieldPropertyMap = getPropertyMapFromArrayList(publicFieldProperties);
- for (int i = 0; i < publicMethodProperties.size(); i++) {
- Property next = (Property) publicMethodProperties.get(i);
- Property fieldProp = fieldPropertyMap.get(next.getPropertyName());
- if ( fieldProp == null) {
- publicFieldProperties.add(next);
- } else if (fieldProp.isTransient()){
- //bug 346461 - if a public field is transient and the public methods are not
- // then use the method
- publicFieldProperties.remove(fieldProp);
- publicFieldProperties.add(next);
- }
- }
- return publicFieldProperties;
- }
- }
-
- public HashMap<String, Property> getPropertyMapFromArrayList(ArrayList<Property> props) {
- HashMap propMap = new HashMap(props.size());
-
- Iterator propIter = props.iterator();
- while (propIter.hasNext()) {
- Property next = (Property) propIter.next();
- propMap.put(next.getPropertyName(), next);
- }
- return propMap;
- }
+ // - in the case of a collision if one is annotated use it,
+ // otherwise
+ // use the field.
+ HashMap<String, Property> fieldPropertyMap = getPropertyMapFromArrayList(publicFieldProperties);
+ for (Property publicMethodProperty : publicMethodProperties) {
+ Property next = (Property) publicMethodProperty;
+ Property fieldProp = fieldPropertyMap.get(next.getPropertyName());
+ if (fieldProp == null) {
+ publicFieldProperties.add(next);
+ } else if (fieldProp.isTransient()) {
+ //bug 346461 - if a public field is transient and the public methods are not
+ // then use the method
+ publicFieldProperties.remove(fieldProp);
+ publicFieldProperties.add(next);
+ }
+ }
+ return publicFieldProperties;
+ }
+ }
+
+ public HashMap<String, Property> getPropertyMapFromArrayList(ArrayList<Property> props) {
+ HashMap propMap = new HashMap(props.size());
+
+ for (Object next : props) {
+ propMap.put(((Property)next).getPropertyName(), next);
+ }
+ return propMap;
+ }
public ArrayList getNoAccessTypePropertiesForClass(JavaClass cls, TypeInfo info) {
ArrayList<Property> list = new ArrayList<Property>();
@@ -3186,15 +3233,15 @@ public class AnnotationsProcessor {
return list;
}
- /**
- * Use name, namespace and type information to setup a user-defined schema
- * type. This method will typically be called when processing an
- *
- * @XmlSchemaType(s) annotation or xml-schema-type(s) metadata.
- *
- * @param name
- * @param namespace
- * @param jClassQualifiedName
+ /**
+ * Use name, namespace and type information to setup a user-defined schema
+ * type. This method will typically be called when processing an
+ *
+ * @XmlSchemaType(s) annotation or xml-schema-type(s) metadata.
+ *
+ * @param name
+ * @param namespace
+ * @param jClassQualifiedName
*/
public void processSchemaType(String name, String namespace, String jClassQualifiedName) {
this.userDefinedSchemaTypes.put(jClassQualifiedName, new QName(namespace, name));
@@ -3217,62 +3264,61 @@ public class AnnotationsProcessor {
Class restrictionClass = String.class;
QName restrictionBase = getSchemaTypeFor(helper.getJavaClass(restrictionClass));
- if (helper.isAnnotationPresent(javaClass, XmlEnum.class)) {
- XmlEnum xmlEnum = (XmlEnum) helper.getAnnotation(javaClass, XmlEnum.class);
- restrictionClass = xmlEnum.value();
- JavaClass restrictionJavaClass= helper.getJavaClass(restrictionClass);
- boolean restrictionIsEnum = helper.isAnnotationPresent(restrictionJavaClass, XmlEnum.class);
-
- if(!restrictionIsEnum){
- if(helper.isBuiltInJavaType(restrictionJavaClass)){
- restrictionBase = getSchemaTypeFor(helper.getJavaClass(restrictionClass));
- }else{
- TypeInfo restrictionInfo = typeInfo.get(restrictionJavaClass.getQualifiedName());
- if(restrictionInfo == null){
- JavaClass[] jClasses = new JavaClass[] { restrictionJavaClass };
- buildNewTypeInfo(jClasses);
- restrictionInfo = typeInfo.get(restrictionJavaClass.getQualifiedName());
- }else if(restrictionInfo != null && !restrictionInfo.isPostBuilt()){
- postBuildTypeInfo(new JavaClass[] { restrictionJavaClass });
- }
-
- Property xmlValueProp =restrictionInfo.getXmlValueProperty();
- if(xmlValueProp != null){
- restrictionJavaClass = xmlValueProp.getActualType();
- restrictionBase = getSchemaTypeFor(restrictionJavaClass);
- restrictionClass = helper.getClassForJavaClass(restrictionJavaClass);
- }
- }
- }else{
- while (restrictionIsEnum) {
-
- TypeInfo restrictionTypeInfo = processReferencedClass(restrictionJavaClass);
- restrictionBase = new QName(restrictionTypeInfo.getClassNamespace(), restrictionTypeInfo.getSchemaTypeName());
-
- xmlEnum = (XmlEnum) helper.getAnnotation(restrictionJavaClass, XmlEnum.class);
- restrictionClass = xmlEnum.value();
- restrictionJavaClass= helper.getJavaClass(restrictionClass);
- restrictionIsEnum = helper.isAnnotationPresent(restrictionJavaClass, XmlEnum.class);
- }
- }
- }
- info.setRestrictionBase(restrictionBase);
-
- for (Iterator<JavaField> fieldIt = javaClass.getDeclaredFields().iterator(); fieldIt.hasNext();) {
- JavaField field = fieldIt.next();
- if (field.isEnumConstant()) {
- Object enumValue = field.getName();
- if (helper.isAnnotationPresent(field, XmlEnumValue.class)) {
- enumValue = ((XmlEnumValue) helper.getAnnotation(field, XmlEnumValue.class)).value();
- }
- if(restrictionClass != null){
- try{
- enumValue = XMLConversionManager.getDefaultXMLManager().convertObject(enumValue, restrictionClass);
- }catch(ConversionException e){
- throw org.eclipse.persistence.exceptions.JAXBException.invalidEnumValue(enumValue, restrictionClass.getName(), e);
- }
-
- }
+ if (helper.isAnnotationPresent(javaClass, XmlEnum.class)) {
+ XmlEnum xmlEnum = (XmlEnum) helper.getAnnotation(javaClass, XmlEnum.class);
+ restrictionClass = xmlEnum.value();
+ JavaClass restrictionJavaClass= helper.getJavaClass(restrictionClass);
+ boolean restrictionIsEnum = helper.isAnnotationPresent(restrictionJavaClass, XmlEnum.class);
+
+ if(!restrictionIsEnum){
+ if(helper.isBuiltInJavaType(restrictionJavaClass)){
+ restrictionBase = getSchemaTypeFor(helper.getJavaClass(restrictionClass));
+ }else{
+ TypeInfo restrictionInfo = typeInfos.get(restrictionJavaClass.getQualifiedName());
+ if(restrictionInfo == null){
+ JavaClass[] jClasses = new JavaClass[] { restrictionJavaClass };
+ buildNewTypeInfo(jClasses);
+ restrictionInfo = typeInfos.get(restrictionJavaClass.getQualifiedName());
+ }else if(!restrictionInfo.isPostBuilt()){
+ postBuildTypeInfo(new JavaClass[] { restrictionJavaClass });
+ }
+
+ Property xmlValueProp = restrictionInfo.getXmlValueProperty();
+ if(xmlValueProp != null){
+ restrictionJavaClass = xmlValueProp.getActualType();
+ restrictionBase = getSchemaTypeFor(restrictionJavaClass);
+ restrictionClass = helper.getClassForJavaClass(restrictionJavaClass);
+ }
+ }
+ }else{
+ while (restrictionIsEnum) {
+
+ TypeInfo restrictionTypeInfo = processReferencedClass(restrictionJavaClass);
+ restrictionBase = new QName(restrictionTypeInfo.getClassNamespace(), restrictionTypeInfo.getSchemaTypeName());
+
+ xmlEnum = (XmlEnum) helper.getAnnotation(restrictionJavaClass, XmlEnum.class);
+ restrictionClass = xmlEnum.value();
+ restrictionJavaClass= helper.getJavaClass(restrictionClass);
+ restrictionIsEnum = helper.isAnnotationPresent(restrictionJavaClass, XmlEnum.class);
+ }
+ }
+ }
+ info.setRestrictionBase(restrictionBase);
+
+ for (JavaField field : (Iterable<JavaField>) javaClass.getDeclaredFields()) {
+ if (field.isEnumConstant()) {
+ Object enumValue = field.getName();
+ if (helper.isAnnotationPresent(field, XmlEnumValue.class)) {
+ enumValue = ((XmlEnumValue) helper.getAnnotation(field, XmlEnumValue.class)).value();
+ }
+ if (restrictionClass != null) {
+ try {
+ enumValue = XMLConversionManager.getDefaultXMLManager().convertObject(enumValue, restrictionClass);
+ } catch (ConversionException e) {
+ throw JAXBException.invalidEnumValue(enumValue, restrictionClass.getName(), e);
+ }
+
+ }
info.addJavaFieldToXmlEnumValuePair(field.getName(), enumValue);
}
}
@@ -3288,13 +3334,13 @@ public class AnnotationsProcessor {
public QName getSchemaTypeOrNullFor(JavaClass javaClass) {
if (javaClass == null) {
return null;
- }
-
- // check user defined types first
- QName schemaType = (QName) userDefinedSchemaTypes.get(javaClass.getQualifiedName());
- if (schemaType == null) {
- schemaType = (QName) helper.getXMLToJavaTypeMap().get(javaClass.getRawName());
- }
+ }
+
+ // check user defined types first
+ QName schemaType = userDefinedSchemaTypes.get(javaClass.getQualifiedName());
+ if (schemaType == null) {
+ schemaType = (QName) helper.getXMLToJavaTypeMap().get(javaClass.getRawName());
+ }
return schemaType;
}
@@ -3316,14 +3362,13 @@ public class AnnotationsProcessor {
packageNamespace = namespaceMapping;
} else if (namespaceMapping.equals(XMLProcessor.DEFAULT)) {
packageNamespace = this.defaultTargetNamespace;
- }
- info.setNamespace(packageNamespace);
- XmlNs[] xmlns = xmlSchema.xmlns();
- for (int i = 0; i < xmlns.length; i++) {
- XmlNs next = xmlns[i];
- info.getNamespaceResolver().put(next.prefix(), next.namespaceURI());
- }
- info.setAttributeFormQualified(xmlSchema.attributeFormDefault() == XmlNsForm.QUALIFIED);
+ }
+ info.setNamespace(packageNamespace);
+ XmlNs[] xmlns = xmlSchema.xmlns();
+ for (XmlNs next : xmlns) {
+ info.getNamespaceResolver().put(next.prefix(), next.namespaceURI());
+ }
+ info.setAttributeFormQualified(xmlSchema.attributeFormDefault() == XmlNsForm.QUALIFIED);
info.setElementFormQualified(xmlSchema.elementFormDefault() == XmlNsForm.QUALIFIED);
// reflectively load XmlSchema class to avoid dependency
@@ -3336,46 +3381,47 @@ public class AnnotationsProcessor {
location = null;
} else if (location.equals(EMPTY_STRING)) {
location = null;
- }
- }
- info.setLocation(location);
- } catch (Exception ex) {
- }
-
- } else {
- info.setNamespace(defaultTargetNamespace);
- }
- if (!info.isElementFormQualified() ){
- isDefaultNamespaceAllowed = false;
- }
- return info;
- }
-
- public HashMap<String, TypeInfo> getTypeInfo() {
- return typeInfo;
- }
-
- public ArrayList<JavaClass> getTypeInfoClasses() {
- return typeInfoClasses;
- }
-
- public HashMap<String, QName> getUserDefinedSchemaTypes() {
- return userDefinedSchemaTypes;
- }
-
+ }
+ }
+ info.setLocation(location);
+ } catch (Exception ignored) {
+ // ignored
+ }
+
+ } else {
+ info.setNamespace(defaultTargetNamespace);
+ }
+ if (!info.isElementFormQualified() ){
+ isDefaultNamespaceAllowed = false;
+ }
+ return info;
+ }
+
+ public Map<String, TypeInfo> getTypeInfos() {
+ return typeInfos;
+ }
+
+ public List<JavaClass> getTypeInfoClasses() {
+ return typeInfoClasses;
+ }
+
+ public Map<String, QName> getUserDefinedSchemaTypes() {
+ return userDefinedSchemaTypes;
+ }
+
public QName getQNameForProperty(Property property, String defaultName, JavaHasAnnotations element, NamespaceInfo namespaceInfo, TypeInfo info) {
String uri = info.getClassNamespace();
- String name = XMLProcessor.DEFAULT;
- String namespace = XMLProcessor.DEFAULT;
- QName qName = null;
-
- if(property.isMap()){
- isDefaultNamespaceAllowed = false;
- }
-
- if (helper.isAnnotationPresent(element, XmlAttribute.class)) {
- XmlAttribute xmlAttribute = (XmlAttribute) helper.getAnnotation(element, XmlAttribute.class);
- name = xmlAttribute.name();
+ String name = XMLProcessor.DEFAULT;
+ String namespace = XMLProcessor.DEFAULT;
+ QName qName = null;
+
+ if(property.isMap()){
+ isDefaultNamespaceAllowed = false;
+ }
+
+ if (helper.isAnnotationPresent(element, XmlAttribute.class)) {
+ XmlAttribute xmlAttribute = (XmlAttribute) helper.getAnnotation(element, XmlAttribute.class);
+ name = xmlAttribute.name();
namespace = xmlAttribute.namespace();
if (name.equals(XMLProcessor.DEFAULT)) {
@@ -3390,25 +3436,25 @@ public class AnnotationsProcessor {
if (!namespace.equals(XMLProcessor.DEFAULT)) {
qName = new QName(namespace, name);
isDefaultNamespaceAllowed = false;
- } else {
- if (namespaceInfo.isAttributeFormQualified()) {
- qName = new QName(uri, name);
- isDefaultNamespaceAllowed = false;
- } else {
- qName = new QName(name);
- }
+ } else {
+ if (namespaceInfo.isAttributeFormQualified()) {
+ qName = new QName(uri, name);
+ isDefaultNamespaceAllowed = false;
+ } else {
+ qName = new QName(name);
+ }
}
} else {
if (helper.isAnnotationPresent(element, XmlElement.class)) {
XmlElement xmlElement = (XmlElement) helper.getAnnotation(element, XmlElement.class);
name = xmlElement.name();
- namespace = xmlElement.namespace();
- }
- if (property.isMap() && helper.isAnnotationPresent(element, XmlElementWrapper.class)) {
- XmlElementWrapper xmlElementWrapper = (XmlElementWrapper) helper.getAnnotation(element, XmlElementWrapper.class);
- name = xmlElementWrapper.name();
- namespace = xmlElementWrapper.namespace();
- }
+ namespace = xmlElement.namespace();
+ }
+ if (property.isMap() && helper.isAnnotationPresent(element, XmlElementWrapper.class)) {
+ XmlElementWrapper xmlElementWrapper = (XmlElementWrapper) helper.getAnnotation(element, XmlElementWrapper.class);
+ name = xmlElementWrapper.name();
+ namespace = xmlElementWrapper.namespace();
+ }
if (name.equals(XMLProcessor.DEFAULT)) {
name = defaultName;
@@ -3433,20 +3479,20 @@ public class AnnotationsProcessor {
}
}
}
- return qName;
- }
-
- public HashMap<String, PackageInfo> getPackageToPackageInfoMappings() {
- return packageToPackageInfoMappings;
- }
-
- /**
- * Add a package name/NamespaceInfo entry to the map. This method will
- * lazy-load the map if necessary.
- *
- * @return
- */
- public void addPackageToNamespaceMapping(String packageName, NamespaceInfo nsInfo) {
+ return qName;
+ }
+
+ public Map<String, PackageInfo> getPackageToPackageInfoMappings() {
+ return packageToPackageInfoMappings;
+ }
+
+ /**
+ * Add a package name/NamespaceInfo entry to the map. This method will
+ * lazy-load the map if necessary.
+ *
+ * @return
+ */
+ public void addPackageToNamespaceMapping(String packageName, NamespaceInfo nsInfo) {
if (packageToPackageInfoMappings == null) {
packageToPackageInfoMappings = new HashMap<String, PackageInfo>();
}
@@ -3461,13 +3507,13 @@ public class AnnotationsProcessor {
public void addPackageToPackageInfoMapping(String packageName, PackageInfo packageInfo) {
if(packageToPackageInfoMappings == null) {
packageToPackageInfoMappings = new HashMap<String, PackageInfo>();
- }
- packageToPackageInfoMappings.put(packageName, packageInfo);
- }
-
- public PackageInfo getPackageInfoForPackage(JavaClass javaClass) {
- String packageName = javaClass.getPackageName();
- PackageInfo packageInfo = packageToPackageInfoMappings.get(packageName);
+ }
+ packageToPackageInfoMappings.put(packageName, packageInfo);
+ }
+
+ public PackageInfo getPackageInfoForPackage(JavaClass javaClass) {
+ String packageName = javaClass.getPackageName();
+ PackageInfo packageInfo = packageToPackageInfoMappings.get(packageName);
if (packageInfo == null) {
packageInfo = getPackageInfoForPackage(javaClass.getPackage(), packageName);
}
@@ -3477,13 +3523,13 @@ public class AnnotationsProcessor {
public PackageInfo getPackageInfoForPackage(JavaPackage pack, String packageName) {
PackageInfo packageInfo = packageToPackageInfoMappings.get(packageName);
if (packageInfo == null) {
- XmlSchema xmlSchema = (XmlSchema) helper.getAnnotation(pack, XmlSchema.class);
- packageInfo = new PackageInfo();
- NamespaceInfo namespaceInfo = processNamespaceInformation(xmlSchema);
-
- packageInfo.setNamespaceInfo(namespaceInfo);
-
- // if it's still null, generate based on package name
+ XmlSchema xmlSchema = (XmlSchema) helper.getAnnotation(pack, XmlSchema.class);
+ packageInfo = new PackageInfo();
+ NamespaceInfo namespaceInfo = processNamespaceInformation(xmlSchema);
+
+ packageInfo.setNamespaceInfo(namespaceInfo);
+
+ // if it's still null, generate based on package name
if (namespaceInfo.getNamespace() == null) {
namespaceInfo.setNamespace(EMPTY_STRING);
}
@@ -3496,13 +3542,13 @@ public class AnnotationsProcessor {
packageInfo.setAccessOrder(XmlAccessOrder.fromValue(xmlAccessorOrder.value().name()));
}
if (CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS != null && helper.isAnnotationPresent(pack, CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS)) {
- Annotation xmlAccessorFactory = helper.getAnnotation(pack, CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS);
- Class xmlAccessorFactoryClass = null;
- try {
- xmlAccessorFactoryClass = (Class)PrivilegedAccessHelper.invokeMethod(CompilerHelper.ACCESSOR_FACTORY_VALUE_METHOD, xmlAccessorFactory, new Object[]{});
- packageInfo.setAccessorFactory(new AccessorFactoryWrapper(PrivilegedAccessHelper.newInstanceFromClass(xmlAccessorFactoryClass)));
- } catch (Exception ex) {
- throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
+ Annotation xmlAccessorFactory = helper.getAnnotation(pack, CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS);
+ Class xmlAccessorFactoryClass = null;
+ try {
+ xmlAccessorFactoryClass = (Class)PrivilegedAccessHelper.invokeMethod(CompilerHelper.ACCESSOR_FACTORY_VALUE_METHOD, xmlAccessorFactory, new Object[]{});
+ packageInfo.setAccessorFactory(new AccessorFactoryWrapper(PrivilegedAccessHelper.newInstanceFromClass(xmlAccessorFactoryClass)));
+ } catch (Exception ex) {
+ throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
}
}else if (CompilerHelper.INTERNAL_ACCESSOR_FACTORY_ANNOTATION_CLASS != null && helper.isAnnotationPresent(pack, CompilerHelper.INTERNAL_ACCESSOR_FACTORY_ANNOTATION_CLASS)) {
Annotation xmlAccessorFactory = helper.getAnnotation(pack, CompilerHelper.INTERNAL_ACCESSOR_FACTORY_ANNOTATION_CLASS);
@@ -3510,13 +3556,13 @@ public class AnnotationsProcessor {
try {
xmlAccessorFactoryClass = (Class)PrivilegedAccessHelper.invokeMethod(CompilerHelper.INTERNAL_ACCESSOR_FACTORY_VALUE_METHOD, xmlAccessorFactory, new Object[]{});
packageInfo.setAccessorFactory(new AccessorFactoryWrapper(PrivilegedAccessHelper.newInstanceFromClass(xmlAccessorFactoryClass)));
- } catch (Exception ex) {
- throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
- }
- }
- packageToPackageInfoMappings.put(packageName, packageInfo);
- }
- return packageInfo;
+ } catch (Exception ex) {
+ throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
+ }
+ }
+ packageToPackageInfoMappings.put(packageName, packageInfo);
+ }
+ return packageInfo;
}
public NamespaceInfo findInfoForNamespace(String namespace) {
@@ -3525,21 +3571,21 @@ public class AnnotationsProcessor {
if(nextUri == null) {
nextUri = Constants.EMPTY_STRING;
}
- if(namespace == null) {
- namespace = Constants.EMPTY_STRING;
- }
-
- if(nextUri.equals(namespace)) {
- return next.getNamespaceInfo();
- }
- }
- return null;
- }
-
- private void checkForCallbackMethods() {
- JavaClass unmarshallerCls = helper.getJavaClass(Unmarshaller.class);
- JavaClass marshallerCls = helper.getJavaClass(Marshaller.class);
- JavaClass objectCls = helper.getJavaClass(Object.class);
+ if(namespace == null) {
+ namespace = Constants.EMPTY_STRING;
+ }
+
+ if(nextUri.equals(namespace)) {
+ return next.getNamespaceInfo();
+ }
+ }
+ return null;
+ }
+
+ void checkForCallbackMethods() {
+ JavaClass unmarshallerCls = helper.getJavaClass(Unmarshaller.class);
+ JavaClass marshallerCls = helper.getJavaClass(Marshaller.class);
+ JavaClass objectCls = helper.getJavaClass(Object.class);
JavaClass[] unmarshalParams = new JavaClass[] { unmarshallerCls, objectCls };
JavaClass[] marshalParams = new JavaClass[] { marshallerCls };
@@ -3594,51 +3640,51 @@ public class AnnotationsProcessor {
}
marshalCallbacks.put(next.getQualifiedName(), marshalCallback);
}
- }
- }
-
- public HashMap<String, MarshalCallback> getMarshalCallbacks() {
- return this.marshalCallbacks;
- }
-
- public HashMap<String, UnmarshalCallback> getUnmarshalCallbacks() {
- return this.unmarshalCallbacks;
- }
-
- private void findAndProcessObjectFactory(JavaClass cls){
- //need to make sure objectfactory gets processed.
- try{
- String className =cls.getPackageName() + ".ObjectFactory";
- findAndProcessObjectFactory(className);
- }catch(JAXBException e){}
- }
-
- void findAndProcessObjectFactory(String objectFactoryClassName){
- //need to make sure objectfactory gets processed.
- try{
- if(objectFactoryClassNames.contains(objectFactoryClassName)){
- return;
- }
- JavaClass javaClass = helper.getJavaClass(objectFactoryClassName);
- if (isXmlRegistry(javaClass)) {
- JavaClass[] processed = this.processObjectFactory(javaClass, new ArrayList());
- preBuildTypeInfo(processed);
- buildTypeInfo(processed);
- updateGlobalElements(processed);
- }
- }catch(JAXBException e){}
- }
-
- public JavaClass[] processObjectFactory(JavaClass objectFactoryClass, ArrayList<JavaClass> classes) {
-
- String className = objectFactoryClass.getName();
- if(objectFactoryClassNames.contains(className)){
- return new JavaClass[0];
- }
- objectFactoryClassNames.add(className);
- // if there is an xml-registry from XML for this JavaClass, create a map
- // of method names to XmlElementDecl objects to simplify processing
- // later on in this method
+ }
+ }
+
+ public Map<String, MarshalCallback> getMarshalCallbacks() {
+ return this.marshalCallbacks;
+ }
+
+ public Map<String, UnmarshalCallback> getUnmarshalCallbacks() {
+ return this.unmarshalCallbacks;
+ }
+
+ private void findAndProcessObjectFactory(JavaClass cls){
+ //need to make sure objectfactory gets processed.
+ try {
+ String className =cls.getPackageName() + ".ObjectFactory";
+ findAndProcessObjectFactory(className);
+ } catch (JAXBException ignored) { /* ignored */}
+ }
+
+ void findAndProcessObjectFactory(String objectFactoryClassName){
+ //need to make sure objectfactory gets processed.
+ try {
+ if(objectFactoryClassNames.contains(objectFactoryClassName)){
+ return;
+ }
+ JavaClass javaClass = helper.getJavaClass(objectFactoryClassName);
+ if (isXmlRegistry(javaClass)) {
+ JavaClass[] processed = this.processObjectFactory(javaClass, new ArrayList<JavaClass>());
+ preBuildTypeInfo(processed);
+ buildTypeInfo(processed);
+ updateGlobalElements(processed);
+ }
+ } catch (JAXBException ignored){ /* ignored */ }
+ }
+
+ public JavaClass[] processObjectFactory(JavaClass objectFactoryClass, List<JavaClass> classes) {
+
+ String className = objectFactoryClass.getName();
+ if(objectFactoryClassNames.contains(className)){
+ return new JavaClass[0];
+ }
+ objectFactoryClassNames.add(className);
+ // if there is an xml-registry from XML for this JavaClass, create a map
+ // of method names to XmlElementDecl objects to simplify processing
+ // later on in this method
Map<String, org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl> elemDecls = new HashMap<String, org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl>();
org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry xmlReg = xmlRegistries.get(objectFactoryClass.getQualifiedName());
if (xmlReg != null) {
@@ -3654,45 +3700,45 @@ public class AnnotationsProcessor {
PackageInfo packageInfo = getPackageInfoForPackage(objectFactoryClass);
while (methodsIter.hasNext()) {
JavaMethod next = (JavaMethod) methodsIter.next();
- if (next.getName().startsWith(CREATE)) {
- JavaClass type = next.getReturnType();
- if (JAVAX_XML_BIND_JAXBELEMENT.equals(type.getName())) {
- Object[] actualTypeArguments = type.getActualTypeArguments().toArray();
- if (actualTypeArguments.length == 0) {
- type = helper.OBJECT_CLASS;
- } else {
- type = (JavaClass) actualTypeArguments[0];
- }
- type = processXmlElementDecl(type, next, packageInfo, elemDecls);
- }else if (helper.JAXBELEMENT_CLASS.isAssignableFrom(type)) {
- this.factoryMethods.put(type.getRawName(), next);
- type = processXmlElementDecl(type, next, packageInfo, elemDecls);
- } else {
- this.factoryMethods.put(type.getRawName(), next);
- }
- if (!helper.isBuiltInJavaType(type) && !helper.classExistsInArray(type, classes)) {
- classes.add(type);
+ if (next.getName().startsWith(CREATE)) {
+ JavaClass type = next.getReturnType();
+ if (JAVAX_XML_BIND_JAXBELEMENT.equals(type.getName())) {
+ Object[] actualTypeArguments = type.getActualTypeArguments().toArray();
+ if (actualTypeArguments.length == 0) {
+ type = helper.OBJECT_CLASS;
+ } else {
+ type = (JavaClass) actualTypeArguments[0];
+ }
+ type = processXmlElementDecl(type, next, packageInfo, elemDecls);
+ }else if (helper.JAXBELEMENT_CLASS.isAssignableFrom(type)) {
+ this.factoryMethods.put(type.getRawName(), next);
+ type = processXmlElementDecl(type, next, packageInfo, elemDecls);
+ } else {
+ this.factoryMethods.put(type.getRawName(), next);
+ }
+ if (!helper.isBuiltInJavaType(type) && !helper.classExistsInArray(type, classes)) {
+ classes.add(type);
}
}
- }
-
- if (classes.size() > 0) {
- classesToProcessPropertyTypes.addAll(classes);
- return classes.toArray(new JavaClass[classes.size()]);
- } else {
- return new JavaClass[0];
- }
- }
-
- private JavaClass processXmlElementDecl(JavaClass type, JavaMethod next, PackageInfo packageInfo, Map<String, org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl> elemDecls){
- JavaClass returnType = type;
- // if there's an XmlElementDecl for this method from XML, use it
- // - otherwise look for an annotation
- org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl xmlEltDecl = elemDecls.get(next.getName());
- if (( xmlEltDecl != null) || helper.isAnnotationPresent(next, XmlElementDecl.class)) {
- QName qname;
- QName substitutionHead = null;
- String url;
+ }
+
+ if (classes.size() > 0) {
+ classesToProcessPropertyTypes.addAll(classes);
+ return classes.toArray(new JavaClass[classes.size()]);
+ } else {
+ return new JavaClass[0];
+ }
+ }
+
+ private JavaClass processXmlElementDecl(JavaClass type, JavaMethod next, PackageInfo packageInfo, Map<String, org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl> elemDecls){
+ JavaClass returnType = type;
+ // if there's an XmlElementDecl for this method from XML, use it
+ // - otherwise look for an annotation
+ org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry.XmlElementDecl xmlEltDecl = elemDecls.get(next.getName());
+ if (( xmlEltDecl != null) || helper.isAnnotationPresent(next, XmlElementDecl.class)) {
+ QName qname;
+ QName substitutionHead = null;
+ String url;
String localName;
String defaultValue = null;
Class scopeClass = javax.xml.bind.annotation.XmlElementDecl.GLOBAL.class;
@@ -3738,13 +3784,13 @@ public class AnnotationsProcessor {
substitutionHead = new QName(subHeadNamespace, subHeadLocal);
}
if (!(elementDecl.defaultValue().length() == 1 && elementDecl.defaultValue().startsWith(ELEMENT_DECL_DEFAULT))) {
- defaultValue = elementDecl.defaultValue();
- }
- }
-
- if (XMLProcessor.DEFAULT.equals(url)) {
- url = packageInfo.getNamespace();
- }
+ defaultValue = elementDecl.defaultValue();
+ }
+ }
+
+ if (XMLProcessor.DEFAULT.equals(url)) {
+ url = packageInfo.getNamespace();
+ }
if(Constants.EMPTY_STRING.equals(url)) {
isDefaultNamespaceAllowed = false;
qname = new QName(localName);
@@ -3772,57 +3818,57 @@ public class AnnotationsProcessor {
if (helper.isAnnotationPresent(next, XmlJavaTypeAdapter.class)) {
XmlJavaTypeAdapter typeAdapter = (XmlJavaTypeAdapter) helper.getAnnotation(next, XmlJavaTypeAdapter.class);
Class typeAdapterClass = typeAdapter.value();
- declaration.setJavaTypeAdapterClass(typeAdapterClass);
-
- Class declJavaType = CompilerHelper.getTypeFromAdapterClass(typeAdapterClass);
- JavaClass adaptedType = helper.getJavaClass(declJavaType);
- declaration.setJavaType(adaptedType);
- declaration.setAdaptedJavaType(type);
- returnType = adaptedType;
+ declaration.setJavaTypeAdapterClass(typeAdapterClass);
+
+ Class declJavaType = CompilerHelper.getTypeFromAdapterClass(typeAdapterClass);
+ JavaClass adaptedType = helper.getJavaClass(declJavaType);
+ declaration.setJavaType(adaptedType);
+ declaration.setAdaptedJavaType(type);
+ returnType = adaptedType;
}
if (helper.isAnnotationPresent(next, XmlMimeType.class)) {
XmlMimeType mimeType = (XmlMimeType)helper.getAnnotation(next, XmlMimeType.class);
declaration.setXmlMimeType(mimeType.value());
}
- if (helper.isAnnotationPresent(next, XmlAttachmentRef.class)) {
- declaration.setXmlAttachmentRef(true);
- }
- HashMap<QName, ElementDeclaration> elements = getElementDeclarationsForScope(scopeClass.getName());
- if (elements == null) {
- elements = new HashMap<QName, ElementDeclaration>();
- this.elementDeclarations.put(scopeClass.getName(), elements);
- }
- if(elements.containsKey(qname)){
- throw JAXBException.duplicateElementName(qname);
- }
-
- elements.put(qname, declaration);
- }
- return returnType;
- }
-
- /**
- * Lazy load and return the map of global elements.
- *
- * @return
- */
- public HashMap<QName, ElementDeclaration> getGlobalElements() {
- return this.elementDeclarations.get(XmlElementDecl.GLOBAL.class.getName());
- }
-
+ if (helper.isAnnotationPresent(next, XmlAttachmentRef.class)) {
+ declaration.setXmlAttachmentRef(true);
+ }
+ Map<QName, ElementDeclaration> elements = getElementDeclarationsForScope(scopeClass.getName());
+ if (elements == null) {
+ elements = new HashMap<QName, ElementDeclaration>();
+ this.elementDeclarations.put(scopeClass.getName(), elements);
+ }
+ if(elements.containsKey(qname)){
+ throw JAXBException.duplicateElementName(qname);
+ }
+
+ elements.put(qname, declaration);
+ }
+ return returnType;
+ }
+
+ /**
+ * Lazy load and return the map of global elements.
+ *
+ * @return
+ */
+ public Map<QName, ElementDeclaration> getGlobalElements() {
+ return this.elementDeclarations.get(XmlElementDecl.GLOBAL.class.getName());
+ }
+
public void updateGlobalElements(JavaClass[] classesToProcess) {
// Once all the global element declarations have been created, make sure
// that any ones that have
// a substitution head set are added to the list of substitutable
// elements on the declaration for that
// head.
-
- // Look for XmlRootElement declarations
- for (JavaClass javaClass : classesToProcess) {
- TypeInfo info = typeInfo.get(javaClass.getQualifiedName());
- if (info == null) {
- continue;
- }
+
+ // Look for XmlRootElement declarations
+ for (JavaClass javaClass : classesToProcess) {
+ TypeInfo info = typeInfos.get(javaClass.getQualifiedName());
+ if (info == null) {
+ continue;
+ }
if (!info.isTransient() && info.isSetXmlRootElement()) {
org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement xmlRE = info.getXmlRootElement();
NamespaceInfo namespaceInfo;
@@ -3860,15 +3906,13 @@ public class AnnotationsProcessor {
declaration.setIsXmlRootElement(true);
addGlobalElement(rootElemName, declaration);
this.xmlRootElements.put(javaClass.getQualifiedName(), declaration);
- }
- }
-
- Iterator<QName> elementQnames = this.getGlobalElements().keySet().iterator();
- while (elementQnames.hasNext()) {
- QName next = elementQnames.next();
- ElementDeclaration nextDeclaration = this.getGlobalElements().get(next);
- QName substitutionHead = nextDeclaration.getSubstitutionHead();
- while (substitutionHead != null) {
+ }
+ }
+
+ for (QName next : this.getGlobalElements().keySet()) {
+ ElementDeclaration nextDeclaration = this.getGlobalElements().get(next);
+ QName substitutionHead = nextDeclaration.getSubstitutionHead();
+ while (substitutionHead != null) {
ElementDeclaration rootDeclaration = this.getGlobalElements().get(substitutionHead);
rootDeclaration.addSubstitutableElement(nextDeclaration);
if (rootDeclaration.getSubstitutionHead() != null && rootDeclaration.getSubstitutionHead().equals(substitutionHead)) {
@@ -3898,19 +3942,18 @@ public class AnnotationsProcessor {
* annotations.
*/
private boolean hasJAXBAnnotations(JavaHasAnnotations elem) {
- if(elem == null){
- return false;
- }
- Collection annotations = elem.getAnnotations();
- if (annotations == null || annotations.size() == 0) {
- return false;
- }
- Iterator annotationsIter = annotations.iterator();
- while (annotationsIter.hasNext()) {
- String nextName = ((JavaAnnotation) annotationsIter.next()).getName();
- if (nextName.startsWith(JAVAX_XML_BIND_ANNOTATION)
- || nextName.startsWith(OXM_ANNOTATIONS)
- || nextName.equals(CompilerHelper.XML_LOCATION_ANNOTATION_NAME)
+ if(elem == null){
+ return false;
+ }
+ List annotations = (List<JavaAnnotation>) elem.getAnnotations();
+ if (annotations == null || annotations.isEmpty()) {
+ return false;
+ }
+ for (Object annotation : annotations) {
+ String nextName = ((JavaAnnotation) annotation).getName();
+ if (nextName.startsWith(JAVAX_XML_BIND_ANNOTATION)
+ || nextName.startsWith(OXM_ANNOTATIONS)
+ || nextName.equals(CompilerHelper.XML_LOCATION_ANNOTATION_NAME)
|| nextName.equals(CompilerHelper.INTERNAL_XML_LOCATION_ANNOTATION_NAME)) {
return true;
}
@@ -3941,13 +3984,13 @@ public class AnnotationsProcessor {
private void validateXmlValueFieldOrProperty(JavaClass cls, Property property) {
JavaClass ptype = property.getActualType();
- String propName = property.getPropertyName();
- JavaClass parent = cls.getSuperclass();
- while (parent != null && !(parent.getQualifiedName().equals(JAVA_LANG_OBJECT))) {
- TypeInfo parentTypeInfo = typeInfo.get(parent.getQualifiedName());
- if(hasElementMappedProperties(parentTypeInfo)) {
- throw JAXBException.propertyOrFieldCannotBeXmlValue(propName);
- }
+ String propName = property.getPropertyName();
+ JavaClass parent = cls.getSuperclass();
+ while (parent != null && !(parent.getQualifiedName().equals(JAVA_LANG_OBJECT))) {
+ TypeInfo parentTypeInfo = typeInfos.get(parent.getQualifiedName());
+ if(hasElementMappedProperties(parentTypeInfo)) {
+ throw JAXBException.propertyOrFieldCannotBeXmlValue(propName);
+ }
parent = parent.getSuperclass();
}
@@ -3969,26 +4012,26 @@ public class AnnotationsProcessor {
return false;
}
- private void validateXmlAttributeFieldOrProperty(TypeInfo tInfo, Property property) {
- // Check that @XmlAttribute references a Java type that maps to text in XML
- JavaClass ptype = property.getActualType();
- TypeInfo refInfo = typeInfo.get(ptype.getQualifiedName());
- if (refInfo != null) {
- if (!refInfo.isPostBuilt()) {
- postBuildTypeInfo(new JavaClass[] { ptype });
+ private void validateXmlAttributeFieldOrProperty(TypeInfo tInfo, Property property) {
+ // Check that @XmlAttribute references a Java type that maps to text in XML
+ JavaClass ptype = property.getActualType();
+ TypeInfo refInfo = typeInfos.get(ptype.getQualifiedName());
+ if (refInfo != null) {
+ if (!refInfo.isPostBuilt()) {
+ postBuildTypeInfo(new JavaClass[] { ptype });
}
if (!refInfo.isEnumerationType()) {
JavaClass parent = ptype.getSuperclass();
boolean hasMapped = false;
while (parent != null) {
hasMapped = hasTextMapping(refInfo);
- if (hasMapped || parent.getQualifiedName().equals(JAVA_LANG_OBJECT)) {
- break;
- }
- refInfo = typeInfo.get(parent.getQualifiedName());
- parent = parent.getSuperclass();
- }
- if (!hasMapped) {
+ if (hasMapped || parent.getQualifiedName().equals(JAVA_LANG_OBJECT)) {
+ break;
+ }
+ refInfo = typeInfos.get(parent.getQualifiedName());
+ parent = parent.getSuperclass();
+ }
+ if (!hasMapped) {
String propName = property.getPropertyName();
String typeName = tInfo.getJavaClassName();
String refTypeName = refInfo.getJavaClassName();
@@ -4000,29 +4043,29 @@ public class AnnotationsProcessor {
private boolean hasTextMapping(TypeInfo tInfo) {
Collection<Property> props = tInfo.getProperties().values();
- for (Property property : props) {
- if (property.isAttribute()) {
- JavaClass ptype = property.getActualType();
- TypeInfo refInfo = typeInfo.get(ptype.getQualifiedName());
- if (refInfo != null && refInfo != tInfo) {
- return hasTextMapping(refInfo);
- }
+ for (Property property : props) {
+ if (property.isAttribute()) {
+ JavaClass ptype = property.getActualType();
+ TypeInfo refInfo = typeInfos.get(ptype.getQualifiedName());
+ if (refInfo != null && refInfo != tInfo) {
+ return hasTextMapping(refInfo);
+ }
}
}
boolean hasXmlId = (tInfo.getIDProperty() != null && !tInfo.getIDProperty().isTransient());
- boolean hasXmlValue = (tInfo.getXmlValueProperty() != null && !tInfo.getXmlValueProperty().isTransient());
- if (hasXmlValue) {
- // Ensure there is an @XmlValue property and nothing else
- hasXmlValue = CompilerHelper.isSimpleType(tInfo);
- }
-
- return (hasXmlValue || hasXmlId);
- }
-
- private Class generateWrapperForMapClass(JavaClass mapClass, JavaClass keyClass, JavaClass valueClass, TypeMappingInfo typeMappingInfo) {
- String packageName = JAXB_DEV;
- NamespaceResolver combinedNamespaceResolver = new NamespaceResolver();
+ boolean hasXmlValue = (tInfo.getXmlValueProperty() != null && !tInfo.getXmlValueProperty().isTransient());
+ if (hasXmlValue) {
+ // Ensure there is an @XmlValue property and nothing else
+ hasXmlValue = CompilerHelper.isSimpleType(tInfo);
+ }
+
+ return (hasXmlValue || hasXmlId);
+ }
+
+ private Class generateWrapperForMapClass(JavaClass mapClass, JavaClass keyClass, JavaClass valueClass, TypeMappingInfo typeMappingInfo) {
+ String packageName = JAXB_DEV;
+ NamespaceResolver combinedNamespaceResolver = new NamespaceResolver();
if (!helper.isBuiltInJavaType(keyClass)) {
String keyPackageName = keyClass.getPackageName();
packageName = packageName + DOT_CHR + keyPackageName;
@@ -4103,45 +4146,45 @@ public class AnnotationsProcessor {
String fieldSig = L + mapType.getInternalName() + "<L" + internalKeyName + ";L" + internalValueName + ";>;";
FieldVisitor fv = cw.visitField(Opcodes.ACC_PUBLIC, "entry", L + mapType.getInternalName() + SEMI_COLON, fieldSig, null);
AnnotationVisitor av = fv.visitAnnotation(Type.getDescriptor(XmlElement.class), true);
- if (typeMappingInfo != null) {
- Annotation[] annotations = typeMappingInfo.getAnnotations();
- if (annotations != null) {
- for (int i = 0; i < annotations.length; i++) {
- Annotation nextAnnotation = annotations[i];
- if (nextAnnotation != null && !(nextAnnotation instanceof XmlElement) && !(nextAnnotation instanceof XmlJavaTypeAdapter)) {
- String annotationClassName = nextAnnotation.annotationType().getName();
- av = fv.visitAnnotation(L + annotationClassName.replace(DOT_CHR, SLASH_CHR) + SEMI_COLON, true);
- for (Method next : nextAnnotation.annotationType().getDeclaredMethods()) {
- try {
- Object nextValue = next.invoke(nextAnnotation, new Object[] {});
- if (nextValue instanceof Class) {
- Type nextType = Type.getType(L + ((Class) nextValue).getName().replace(DOT_CHR, SLASH_CHR) + SEMI_COLON);
- nextValue = nextType;
- }
- av.visit(next.getName(), nextValue);
- } catch (InvocationTargetException ex) {
- // ignore the invocation target exception here.
- } catch (IllegalAccessException ex) {
- }
- }
- av.visitEnd();
+ if (typeMappingInfo != null) {
+ Annotation[] annotations = typeMappingInfo.getAnnotations();
+ if (annotations != null) {
+ for (Annotation nextAnnotation : annotations) {
+ if (nextAnnotation != null && !(nextAnnotation instanceof XmlElement) && !(nextAnnotation instanceof XmlJavaTypeAdapter)) {
+ String annotationClassName = nextAnnotation.annotationType().getName();
+ av = fv.visitAnnotation(L + annotationClassName.replace(DOT_CHR, SLASH_CHR) + SEMI_COLON, true);
+ for (Method next : nextAnnotation.annotationType().getDeclaredMethods()) {
+ try {
+ Object nextValue = next.invoke(nextAnnotation, new Object[] { });
+ if (nextValue instanceof Class) {
+ Type nextType = Type.getType(L + ((Class) nextValue).getName().replace(DOT_CHR, SLASH_CHR) + SEMI_COLON);
+ nextValue = nextType;
+ }
+ av.visit(next.getName(), nextValue);
+ } catch (InvocationTargetException ignored) {
+ // ignore the invocation target exception here.
+ } catch (IllegalAccessException ignored) {
+ // ignore the illegal access exception here.
+ }
+ }
+ av.visitEnd();
}
}
- }
- }
- fv.visitEnd();
-
- MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "org/eclipse/persistence/internal/jaxb/many/MapValue", "<init>", "()V", false);
- mv.visitInsn(Opcodes.RETURN);
- mv.visitMaxs(1, 1);
- mv.visitEnd();
-
- // Write: @XmlTransitent public void setItem(???)
- String methodSig = "(L" + mapType.getInternalName() + "<L" + internalKeyName + ";L" + internalValueName + ";>;)V";
- mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setItem", "(L" + mapType.getInternalName() + ";)V", methodSig, null);
- // TODO: Verify that we really want to put @XmlTranient on setItem
+ }
+ }
+ fv.visitEnd();
+
+ MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null);
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "org/eclipse/persistence/internal/jaxb/many/MapValue", "<init>", "()V");
+ mv.visitInsn(Opcodes.RETURN);
+ mv.visitMaxs(1, 1);
+ mv.visitEnd();
+
+ // Write: @XmlTransient public void setItem(???)
+ String methodSig = "(L" + mapType.getInternalName() + "<L" + internalKeyName + ";L" + internalValueName + ";>;)V";
+ mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setItem", "(L" + mapType.getInternalName() + ";)V", methodSig, null);
+ // TODO: Verify that we really want to put @XmlTranient on setItem
// method
mv.visitAnnotation("Ljavax/xml/bind/annotation/XmlTransient;", true);
Label l0 = new Label();
@@ -4288,17 +4331,17 @@ public class AnnotationsProcessor {
if (typeMappingInfo != null && xmlElementType != null) {
componentClass = helper.getJavaClass(xmlElementType);
- } else{
- Collection args = collectionClass.getActualTypeArguments();
- if(args.size() >0 ){
- componentClass = ((JavaClass) args.toArray()[0]);
- }else{
- componentClass = helper.getJavaClass(Object.class);
- }
- }
-
- boolean multiDimensional = false;
- if (componentClass.isPrimitive()) {
+ } else{
+ Collection args = collectionClass.getActualTypeArguments();
+ if(args.size() >0 ){
+ componentClass = ((JavaClass) args.toArray()[0]);
+ }else{
+ componentClass = helper.getJavaClass(Object.class);
+ }
+ }
+
+ boolean multiDimensional = false;
+ if (componentClass.isPrimitive()) {
Class primitiveClass = getPrimitiveClass(componentClass.getRawName());
componentClass = helper.getJavaClass(getObjectClass(primitiveClass));
} else if(helper.getJavaClass(Collection.class).isAssignableFrom(componentClass)) {
@@ -4415,72 +4458,72 @@ public class AnnotationsProcessor {
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, Type.getInternalName(superType), "<init>", "()V", false);
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(1, 1);
- mv.visitEnd();
-
- if(!componentType.isPrimitive() && ArrayValue.class.isAssignableFrom(superType)){
-
- //@Override
- //public Object getItem() {
- // if(null == adaptedValue) {
- // return null;
- // }
- // int len = adaptedValue.size();
- // Float[] array = new Float[len];
- // adaptedValue.toArray(array);
- // return array;
- // }
- mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getItem", "()Ljava/lang/Object;", null, null);
- mv.visitCode();
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitFieldInsn(Opcodes.GETFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
- Label l0 = new Label();
- mv.visitJumpInsn(Opcodes.IFNONNULL, l0);
- mv.visitInsn(Opcodes.ACONST_NULL);
- mv.visitInsn(Opcodes.ARETURN);
- mv.visitLabel(l0);
- mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitFieldInsn(Opcodes.GETFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
- mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "size", "()I", true);
- mv.visitVarInsn(Opcodes.ISTORE, 1);
- mv.visitVarInsn(Opcodes.ILOAD, 1);
- mv.visitTypeInsn(Opcodes.ANEWARRAY, componentClassNameSeparatedBySlash);
- mv.visitVarInsn(Opcodes.ASTORE, 2);
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitFieldInsn(Opcodes.GETFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
- mv.visitVarInsn(Opcodes.ALOAD, 2);
- mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;", true);
- mv.visitInsn(Opcodes.POP);
-
- mv.visitVarInsn(Opcodes.ALOAD, 2);
- mv.visitInsn(Opcodes.ARETURN);
- mv.visitMaxs(2, 3);
- mv.visitEnd();
-
-
- //@Override
- //public void setItem(Object array) {
- // Float[] floatArray = (Float[])array;
- // adaptedValue = (Collection<T>) Arrays.asList(floatArray);
- //}
- mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setItem", "(Ljava/lang/Object;)V", null, null);
- mv.visitCode();
- mv.visitVarInsn(Opcodes.ALOAD, 1);
- mv.visitTypeInsn(Opcodes.CHECKCAST, "[L"+componentClassNameSeparatedBySlash+";");
- mv.visitVarInsn(Opcodes.ASTORE, 2);
- mv.visitVarInsn(Opcodes.ALOAD, 0);
- mv.visitVarInsn(Opcodes.ALOAD, 2);
- mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/Arrays", "asList", "([Ljava/lang/Object;)Ljava/util/List;", false);
- mv.visitFieldInsn(Opcodes.PUTFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
- mv.visitInsn(Opcodes.RETURN);
- mv.visitMaxs(2, 3);
- mv.visitEnd();
- }
-
-
- // @XmlElement(name="item", nillable=true)
- // public Collection<COMPONENT_TYPE> getAdaptedValue() {
- // return super.getAdaptedValue();
+ mv.visitEnd();
+
+ if(!componentType.isPrimitive() && ArrayValue.class.isAssignableFrom(superType)){
+
+ //@Override
+ //public Object getItem() {
+ // if(null == adaptedValue) {
+ // return null;
+ // }
+ // int len = adaptedValue.size();
+ // Float[] array = new Float[len];
+ // adaptedValue.toArray(array);
+ // return array;
+ // }
+ mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "getItem", "()Ljava/lang/Object;", null, null);
+ mv.visitCode();
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitFieldInsn(Opcodes.GETFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
+ Label l0 = new Label();
+ mv.visitJumpInsn(Opcodes.IFNONNULL, l0);
+ mv.visitInsn(Opcodes.ACONST_NULL);
+ mv.visitInsn(Opcodes.ARETURN);
+ mv.visitLabel(l0);
+ mv.visitFrame(Opcodes.F_SAME, 0, null, 0, null);
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitFieldInsn(Opcodes.GETFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
+ mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "size", "()I", true);
+ mv.visitVarInsn(Opcodes.ISTORE, 1);
+ mv.visitVarInsn(Opcodes.ILOAD, 1);
+ mv.visitTypeInsn(Opcodes.ANEWARRAY, componentClassNameSeparatedBySlash);
+ mv.visitVarInsn(Opcodes.ASTORE, 2);
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitFieldInsn(Opcodes.GETFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
+ mv.visitVarInsn(Opcodes.ALOAD, 2);
+ mv.visitMethodInsn(Opcodes.INVOKEINTERFACE, "java/util/Collection", "toArray", "([Ljava/lang/Object;)[Ljava/lang/Object;");
+ mv.visitInsn(Opcodes.POP);
+
+ mv.visitVarInsn(Opcodes.ALOAD, 2);
+ mv.visitInsn(Opcodes.ARETURN);
+ mv.visitMaxs(2, 3);
+ mv.visitEnd();
+
+
+ //@Override
+ //public void setItem(Object array) {
+ // Float[] floatArray = (Float[])array;
+ // adaptedValue = (Collection<T>) Arrays.asList(floatArray);
+ //}
+ mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "setItem", "(Ljava/lang/Object;)V", null, null);
+ mv.visitCode();
+ mv.visitVarInsn(Opcodes.ALOAD, 1);
+ mv.visitTypeInsn(Opcodes.CHECKCAST, "[L"+componentClassNameSeparatedBySlash+";");
+ mv.visitVarInsn(Opcodes.ASTORE, 2);
+ mv.visitVarInsn(Opcodes.ALOAD, 0);
+ mv.visitVarInsn(Opcodes.ALOAD, 2);
+ mv.visitMethodInsn(Opcodes.INVOKESTATIC, "java/util/Arrays", "asList", "([Ljava/lang/Object;)Ljava/util/List;", false);
+ mv.visitFieldInsn(Opcodes.PUTFIELD, classNameSeparatedBySlash, "adaptedValue", "Ljava/util/Collection;");
+ mv.visitInsn(Opcodes.RETURN);
+ mv.visitMaxs(2, 3);
+ mv.visitEnd();
+ }
+
+
+ // @XmlElement(name="item", nillable=true)
+ // public Collection<COMPONENT_TYPE> getAdaptedValue() {
+ // return super.getAdaptedValue();
// }
// OR
// @XmlValue
@@ -4593,12 +4636,11 @@ public class AnnotationsProcessor {
private Class generateClassFromBytes(String className, byte[] classBytes) {
JaxbClassLoader loader = (JaxbClassLoader) helper.getClassLoader();
Class generatedClass = loader.generateClass(className, classBytes);
- return generatedClass;
- }
-
- // Made static final for performance reasons.
- /**
- * Inner class used for ordering a list of Properties alphabetically by
+ return generatedClass;
+ }
+
+ /**
+ * Inner class used for ordering a list of Properties alphabetically by
* property name.
*
*/
@@ -4606,19 +4648,19 @@ public class AnnotationsProcessor {
public int compare(Property p1, Property p2) {
return p1.getPropertyName().compareTo(p2.getPropertyName());
}
- }
-
- private String getNextAvailableClassName(String suggestedName) {
+ }
+
+ private String getNextAvailableClassName(String suggestedName) {
int counter = 1;
return getNextAvailableClassName(suggestedName, suggestedName, counter);
}
-
- private String getNextAvailableClassName(String suggestedBaseName, String suggestedName, int counter) {
-
- Iterator<Class> iter = typeMappingInfoToGeneratedClasses.values().iterator();
- while (iter.hasNext()) {
- Class nextClass = iter.next();
- if (nextClass.getName().equals(suggestedName)) {
+
+ private String getNextAvailableClassName(String suggestedBaseName, String suggestedName, int counter) {
+
+ Iterator<Class> iter = typeMappingInfosToGeneratedClasses.values().iterator();
+ while (iter.hasNext()) {
+ Class nextClass = iter.next();
+ if (nextClass.getName().equals(suggestedName)) {
counter = counter + 1;
return getNextAvailableClassName(suggestedBaseName, suggestedBaseName + counter, counter);
}
@@ -4650,67 +4692,67 @@ public class AnnotationsProcessor {
return generatedClassesToArrayClasses;
}
- /**
- * Convenience method for returning all of the TypeInfo objects for a given
- * package name.
- *
- * This method is inefficient as we need to iterate over the entire typeinfo
- * map for each call. We should eventually store the TypeInfos in a Map
- * based on package name, i.e.:
- *
- * Map<String, Map<String, TypeInfo>>
- *
- * @param packageName
- * @return List of TypeInfo objects for a given package name
- */
- public Map<String, TypeInfo> getTypeInfosForPackage(String packageName) {
- Map<String, TypeInfo> typeInfos = new HashMap<String, TypeInfo>();
- ArrayList<JavaClass> jClasses = getTypeInfoClasses();
- for (JavaClass jClass : jClasses) {
- if (jClass.getPackageName().equals(packageName)) {
- String key = jClass.getQualifiedName();
- typeInfos.put(key, typeInfo.get(key));
- }
- }
- return typeInfos;
+ /**
+ * Convenience method for returning all of the TypeInfo objects for a given
+ * package name.
+ *
+ * This method is inefficient as we need to iterate over the entire typeinfo
+ * map for each call. We should eventually store the TypeInfos in a Map
+ * based on package name, i.e.:
+ *
+ * Map<String, Map<String, TypeInfo>>
+ *
+ * @param packageName
+ * @return List of TypeInfo objects for a given package name
+ */
+ public Map<String, TypeInfo> getTypeInfosForPackage(String packageName) {
+ Map<String, TypeInfo> typeInfos = new HashMap<String, TypeInfo>();
+ List<JavaClass> jClasses = getTypeInfoClasses();
+ for (JavaClass jClass : jClasses) {
+ if (jClass.getPackageName().equals(packageName)) {
+ String key = jClass.getQualifiedName();
+ typeInfos.put(key, this.typeInfos.get(key));
+ }
+ }
+ return typeInfos;
}
- /**
- * Set namespace override info from XML bindings file. This will typically
- * be called from the XMLProcessor.
- *
- * @param packageToNamespaceMappings
- */
- public void setPackageToNamespaceMappings(HashMap<String, NamespaceInfo> packageToNamespaceMappings) {
- //this.packageToNamespaceMappings = packageToNamespaceMappings;
- }
-
- public void setPackageToPackageInfoMappings(HashMap<String, PackageInfo> packageToPackageInfoMappings) {
- this.packageToPackageInfoMappings = packageToPackageInfoMappings;
- }
+ /**
+ * Set namespace override info from XML bindings file. This will typically
+ * be called from the XMLProcessor.
+ *
+ * @param packageToNamespaceMappings
+ */
+ public void setPackageToNamespaceMappings(HashMap<String, NamespaceInfo> packageToNamespaceMappings) {
+ //this.packageToNamespaceMappings = packageToNamespaceMappings;
+ }
+
+ public void setPackageToPackageInfoMappings(HashMap<String, PackageInfo> packageToPackageInfoMappings) {
+ this.packageToPackageInfoMappings = packageToPackageInfoMappings;
+ }
public SchemaTypeInfo addClass(JavaClass javaClass) {
if (javaClass == null) {
return null;
} else if (helper.isAnnotationPresent(javaClass, XmlTransient.class)) {
- return null;
- }
-
- if (typeInfo == null) {
- // this is the first class. Initialize all the properties
- this.typeInfoClasses = new ArrayList<JavaClass>();
- this.typeInfo = new HashMap<String, TypeInfo>();
- this.typeQNames = new ArrayList<QName>();
- this.userDefinedSchemaTypes = new HashMap<String, QName>();
- this.packageToPackageInfoMappings = new HashMap<String, PackageInfo>();
- }
-
- JavaClass[] jClasses = new JavaClass[] { javaClass };
- buildNewTypeInfo(jClasses);
- TypeInfo info = typeInfo.get(javaClass.getQualifiedName());
-
- PackageInfo packageInfo;
- String packageName = javaClass.getPackageName();
+ return null;
+ }
+
+ if (typeInfos == null) {
+ // this is the first class. Initialize all the properties
+ this.typeInfoClasses = new ArrayList<JavaClass>();
+ this.typeInfos = new HashMap<String, TypeInfo>();
+ this.typeQNames = new ArrayList<QName>();
+ this.userDefinedSchemaTypes = new HashMap<String, QName>();
+ this.packageToPackageInfoMappings = new HashMap<String, PackageInfo>();
+ }
+
+ JavaClass[] jClasses = new JavaClass[] { javaClass };
+ buildNewTypeInfo(jClasses);
+ TypeInfo info = typeInfos.get(javaClass.getQualifiedName());
+
+ PackageInfo packageInfo;
+ String packageName = javaClass.getPackageName();
packageInfo = this.packageToPackageInfoMappings.get(packageName);
SchemaTypeInfo schemaInfo = new SchemaTypeInfo();
@@ -4741,13 +4783,13 @@ public class AnnotationsProcessor {
return schemaInfo;
}
- /**
- * Convenience method which class pre and postBuildTypeInfo for a given set
- * of JavaClasses.
- *
- * @param javaClasses
- */
- public void buildNewTypeInfo(JavaClass[] javaClasses) {
+ /**
+ * Convenience method which class pre and postBuildTypeInfo for a given set
+ * of JavaClasses.
+ *
+ * @param javaClasses
+ */
+ public void buildNewTypeInfo(JavaClass[] javaClasses) {
preBuildTypeInfo(javaClasses);
javaClasses = postBuildTypeInfo(javaClasses);
for(JavaClass next:javaClasses) {
@@ -4755,17 +4797,17 @@ public class AnnotationsProcessor {
}
}
- /**
- * Pre-process a descriptor customizer. Here, the given JavaClass is checked
- * for the existence of an @XmlCustomizer annotation.
- *
- * Note that the post processing of the descriptor customizers will take
- * place in MappingsGenerator's generateProject method, after the
- * descriptors and mappings have been generated.
- *
- * @param jClass
- * @param tInfo
- * @see XmlCustomizer
+ /**
+ * Pre-process a descriptor customizer. Here, the given JavaClass is checked
+ * for the existence of an @XmlCustomizer annotation.
+ *
+ * Note that the post processing of the descriptor customizers will take
+ * place in MappingsGenerator's generateProject method, after the
+ * descriptors and mappings have been generated.
+ *
+ * @param jClass
+ * @param tInfo
+ * @see XmlCustomizer
* @see MappingsGenerator
*/
private void preProcessCustomizer(JavaClass jClass, TypeInfo tInfo) {
@@ -4774,25 +4816,25 @@ public class AnnotationsProcessor {
tInfo.setXmlCustomizer(xmlCustomizer.value().getName());
}
}
-
- /**
- * Lazy load the metadata logger.
- *
- * @return
- */
- private JAXBMetadataLogger getLogger() {
+
+ /**
+ * Lazy load the metadata logger.
+ *
+ * @return
+ */
+ private JAXBMetadataLogger getLogger() {
if (logger == null) {
logger = new JAXBMetadataLogger();
}
return logger;
}
-
- /**
- * Return the Helper object set on this processor.
- *
- * @return
- */
- Helper getHelper() {
+
+ /**
+ * Return the Helper object set on this processor.
+ *
+ * @return
+ */
+ Helper getHelper() {
return this.helper;
}
@@ -4801,50 +4843,50 @@ public class AnnotationsProcessor {
}
public List<ElementDeclaration> getLocalElements() {
- return this.localElements;
- }
-
- public Map<TypeMappingInfo, Class> getTypeMappingInfoToGeneratedClasses() {
- return this.typeMappingInfoToGeneratedClasses;
- }
-
- public Map<TypeMappingInfo, Class> getTypeMappingInfoToAdapterClasses() {
+ return this.localElements;
+ }
+
+ public Map<TypeMappingInfo, Class> getTypeMappingInfosToGeneratedClasses() {
+ return this.typeMappingInfosToGeneratedClasses;
+ }
+
+ public Map<TypeMappingInfo, Class> getTypeMappingInfoToAdapterClasses() {
return this.typeMappingInfoToAdapterClasses;
}
-
- /**
- * Add an XmlRegistry to ObjectFactory class name pair to the map.
- *
- * @param factoryClassName
- * ObjectFactory class name
- * @param xmlReg
- * org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry instance
- */
- public void addXmlRegistry(String factoryClassName, org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry xmlReg) {
- this.xmlRegistries.put(factoryClassName, xmlReg);
+
+ /**
+ * Add an XmlRegistry to ObjectFactory class name pair to the map.
+ *
+ * @param factoryClassName
+ * ObjectFactory class name
+ * @param xmlReg
+ * org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry instance
+ */
+ public void addXmlRegistry(String factoryClassName, org.eclipse.persistence.jaxb.xmlmodel.XmlRegistry xmlReg) {
+ this.xmlRegistries.put(factoryClassName, xmlReg);
}
- /**
- * Convenience method for determining if a given JavaClass should be
- * processed as an ObjectFactory class.
- *
- * @param javaClass
- * @return true if the JavaClass is annotated with @XmlRegistry or the map
- * of XmlRegistries contains a key equal to the JavaClass' qualified
- * name
- */
- private boolean isXmlRegistry(JavaClass javaClass) {
- if (javaClass == null) {
+ /**
+ * Convenience method for determining if a given JavaClass should be
+ * processed as an ObjectFactory class.
+ *
+ * @param javaClass
+ * @return true if the JavaClass is annotated with @XmlRegistry or the map
+ * of XmlRegistries contains a key equal to the JavaClass' qualified
+ * name
+ */
+ private boolean isXmlRegistry(JavaClass javaClass) {
+ if (javaClass == null) {
return false;
}
- return (helper.isAnnotationPresent(javaClass, XmlRegistry.class) || xmlRegistries.get(javaClass.getQualifiedName()) != null);
- }
-
- public Map<TypeMappingInfo, QName> getTypeMappingInfoToSchemaType() {
- return this.typeMappingInfoToSchemaType;
- }
-
- String getDefaultTargetNamespace() {
+ return (helper.isAnnotationPresent(javaClass, XmlRegistry.class) || xmlRegistries.get(javaClass.getQualifiedName()) != null);
+ }
+
+ public Map<TypeMappingInfo, QName> getTypeMappingInfosToSchemaTypes() {
+ return this.typeMappingInfosToSchemaTypes;
+ }
+
+ String getDefaultTargetNamespace() {
return this.defaultTargetNamespace;
}
@@ -4853,21 +4895,21 @@ public class AnnotationsProcessor {
}
public void setDefaultNamespaceAllowed(boolean isDefaultNamespaceAllowed) {
- this.isDefaultNamespaceAllowed = isDefaultNamespaceAllowed;
- }
-
- HashMap<QName, ElementDeclaration> getElementDeclarationsForScope(String scopeClassName) {
- return this.elementDeclarations.get(scopeClassName);
- }
-
+ this.isDefaultNamespaceAllowed = isDefaultNamespaceAllowed;
+ }
+
+ Map<QName, ElementDeclaration> getElementDeclarationsForScope(String scopeClassName) {
+ return this.elementDeclarations.get(scopeClassName);
+ }
+
private void addGlobalElement(QName key, ElementDeclaration declaration){
- getGlobalElements().put(key, declaration);
- classesToProcessPropertyTypes.add(declaration.getJavaType());
- }
-
- private Map<Object, Object> createUserPropertiesMap(XmlProperty[] properties) {
- Map<Object, Object> propMap = new HashMap<Object, Object>();
- for (XmlProperty prop : properties) {
+ getGlobalElements().put(key, declaration);
+ classesToProcessPropertyTypes.add(declaration.getJavaType());
+ }
+
+ private Map<Object, Object> createUserPropertiesMap(XmlProperty[] properties) {
+ Map<Object, Object> propMap = new HashMap<Object, Object>();
+ for (XmlProperty prop : properties) {
Object pvalue = prop.value();
if (!(prop.valueType() == String.class)) {
pvalue = XMLConversionManager.getDefaultXMLManager().convertObject(prop.value(), prop.valueType());
@@ -4877,15 +4919,15 @@ public class AnnotationsProcessor {
return propMap;
}
- /**
- * Indicates if a given Property represents an MTOM attachment. Will return
- * true if the given Property's actual type is one of:
- *
- * - DataHandler - byte[] - Byte[] - Image - Source - MimeMultipart
- *
- * @param property
- * @return
- */
+ /**
+ * Indicates if a given Property represents an MTOM attachment. Will return
+ * true if the given Property's actual type is one of:
+ *
+ * - DataHandler - byte[] - Byte[] - Image - Source - MimeMultipart
+ *
+ * @param property
+ * @return
+ */
public boolean isMtomAttachment(Property property) {
JavaClass ptype = property.getActualType();
return (areEquals(ptype, JAVAX_ACTIVATION_DATAHANDLER) || areEquals(ptype, byte[].class) || areEquals(ptype, Image.class) || areEquals(ptype, Source.class) || areEquals(ptype, JAVAX_MAIL_INTERNET_MIMEMULTIPART));
@@ -4895,38 +4937,38 @@ public class AnnotationsProcessor {
return this.hasSwaRef;
}
- public void setHasSwaRef(boolean swaRef) {
- this.hasSwaRef = swaRef;
- }
-
- public List getReferencedByTransformer(){
- return referencedByTransformer;
- }
-
- /**
- * Indicates whether this AnnotationsProcessor has been configured to enable
- * processing of XmlAccessorFactory annotations.
- *
- * @see com.sun.xml.bind.XmlAccessorFactory
- */
- public boolean isXmlAccessorFactorySupport() {
+ public void setHasSwaRef(boolean swaRef) {
+ this.hasSwaRef = swaRef;
+ }
+
+ public List getReferencedByTransformer(){
+ return referencedByTransformer;
+ }
+
+ /**
+ * Indicates whether this AnnotationsProcessor has been configured to enable
+ * processing of XmlAccessorFactory annotations.
+ *
+ * @see com.sun.xml.bind.XmlAccessorFactory
+ */
+ public boolean isXmlAccessorFactorySupport() {
return xmlAccessorFactorySupport;
}
-
- /**
- * Sets whether this AnnotationsProcessor should process XmlAccessorFactory annotations.
- *
- * @see com.sun.xml.bind.XmlAccessorFactory
- */
- public void setXmlAccessorFactorySupport(boolean value) {
+
+ /**
+ * Sets whether this AnnotationsProcessor should process XmlAccessorFactory annotations.
+ *
+ * @see com.sun.xml.bind.XmlAccessorFactory
+ */
+ public void setXmlAccessorFactorySupport(boolean value) {
this.xmlAccessorFactorySupport = value;
}
- public void setHasXmlBindings(boolean b) {
- this.hasXmlBindings = true;
- }
-
- public boolean hasXmlBindings() {
- return this.hasXmlBindings;
- }
-}
+ public void setHasXmlBindings(boolean b) {
+ this.hasXmlBindings = true;
+ }
+
+ public boolean hasXmlBindings() {
+ return this.hasXmlBindings;
+ }
+} \ No newline at end of file