aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContext.java')
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContext.java303
1 files changed, 159 insertions, 144 deletions
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContext.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContext.java
index db64504..682864d 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContext.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContext.java
@@ -75,13 +75,12 @@ import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.jaxb.compiler.Generator;
import org.eclipse.persistence.jaxb.compiler.MarshalCallback;
-import org.eclipse.persistence.jaxb.compiler.UnmarshalCallback;
-import org.eclipse.persistence.jaxb.javamodel.JavaClass;
-import org.eclipse.persistence.jaxb.javamodel.reflection.AnnotationHelper;
-import org.eclipse.persistence.jaxb.javamodel.reflection.JavaClassImpl;
-import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;
-import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl;
-import org.eclipse.persistence.jaxb.json.JsonSchemaOutputResolver;
+import org.eclipse.persistence.jaxb.compiler.UnmarshalCallback;
+import org.eclipse.persistence.jaxb.javamodel.JavaClass;
+import org.eclipse.persistence.jaxb.javamodel.reflection.AnnotationHelper;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelImpl;
+import org.eclipse.persistence.jaxb.javamodel.reflection.JavaModelInputImpl;
+import org.eclipse.persistence.jaxb.json.JsonSchemaOutputResolver;
import org.eclipse.persistence.jaxb.xmlmodel.JavaType;
import org.eclipse.persistence.jaxb.xmlmodel.XmlBindings;
import org.eclipse.persistence.jaxb.xmlmodel.XmlBindings.JavaTypes;
@@ -439,13 +438,13 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
}
/**
- * INTERNAL:
- * Get the map containing which Class (by name) corresponds to which generated class.
- */
- public HashMap<String, Class> getClassToGeneratedClasses() {
- return contextState.getClassToGeneratedClasses();
- }
-
+ * INTERNAL:
+ * Get the map containing which Class (by name) corresponds to which generated class.
+ */
+ public Map<String, Class> getClassToGeneratedClasses() {
+ return contextState.getClassToGeneratedClasses();
+ }
+
/**
* INTERNAL:
* Set the map containing which Class (by name) corresponds to which generated class.
@@ -463,13 +462,13 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
}
/**
- * INTERNAL:
- * Get the map of which QName corresponds to which declared class.
- */
- public HashMap<QName, Class> getQNamesToDeclaredClasses() {
- return contextState.getQNamesToDeclaredClasses();
- }
-
+ * INTERNAL:
+ * Get the map of which QName corresponds to which declared class.
+ */
+ public Map<QName, Class> getQNamesToDeclaredClasses() {
+ return contextState.getQNamesToDeclaredClasses();
+ }
+
/**
* INTERNAL:
* Get the map of which QName corresponds to which generated class.
@@ -534,13 +533,13 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
* INTERNAL:
* Get the map of which Type corresponds to which QName.
* The keys should be all the boundTypes used to create the JAXBContext.
- * If the JAXBContext was not created with the constructor that takes a Type[] then
- * this Map will be empty.
- */
- public HashMap<java.lang.reflect.Type, QName> getTypeToSchemaType() {
- return contextState.getTypeToSchemaType();
- }
-
+ * If the JAXBContext was not created with the constructor that takes a Type[] then
+ * this Map will be empty.
+ */
+ public Map<java.lang.reflect.Type, QName> getTypeToSchemaType() {
+ return contextState.getTypeToSchemaType();
+ }
+
Map<TypeMappingInfo, Class> getTypeMappingInfoToGeneratedType() {
return contextState.getTypeMappingInfoToGeneratedType();
}
@@ -857,13 +856,13 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
}
}
}
- if (foundMetadata) {
- Class[] classArray = new Class[classes.size()];
- for (int i = 0; i < classes.size(); i++) {
- classArray[i] = (Class) classes.get(i);
- }
- return createContextState(classArray, xmlBindingMap);
- }
+ if (foundMetadata) {
+ Class[] classArray = new Class[classes.size()];
+ for (int i = 0; i < classes.size(); i++) {
+ classArray[i] = classes.get(i);
+ }
+ return createContextState(classArray, xmlBindingMap);
+ }
Exception sessionLoadingException = null;
try {
@@ -922,12 +921,13 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
if (metadataComplete.size() > 0) {
jModel.setMetadataCompletePackageMap(metadataComplete);
}
-
- jModel.setHasXmlBindings(xmlBindings != null || !xmlBindings.isEmpty());
- JavaModelInputImpl inputImpl = new JavaModelInputImpl(classesToBeBound, jModel);
- try {
- Generator generator = new Generator(inputImpl, xmlBindings, loader, defaultTargetNamespace, enableXmlAccessorFactory);
- return createContextState(generator, loader, classesToBeBound, properties);
+
+ jModel.setHasXmlBindings(xmlBindings != null || !xmlBindings.isEmpty());
+ JavaModelInputImpl inputImpl = new JavaModelInputImpl(classesToBeBound, jModel);
+ if (properties != null) enableFacetsIfPropertySetTrue(inputImpl, properties);
+ try {
+ Generator generator = new Generator(inputImpl, xmlBindings, loader, defaultTargetNamespace, enableXmlAccessorFactory);
+ return createContextState(generator, loader, classesToBeBound, properties);
} catch (Exception ex) {
throw new javax.xml.bind.JAXBException(ex.getMessage(), ex);
}
@@ -1078,25 +1078,31 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
if (annotationHelper != null) {
jModel = new JavaModelImpl(loader, annotationHelper);
} else {
- jModel = new JavaModelImpl(loader);
- }
-
- jModel.setHasXmlBindings(xmlBindings != null || !xmlBindings.isEmpty());
- // create Map of package names to metadata complete indicators
- Map<String, Boolean> metadataComplete = new HashMap<String, Boolean>();
- for (String packageName : xmlBindings.keySet()) {
- if (xmlBindings.get(packageName).isXmlMappingMetadataComplete()) {
- metadataComplete.put(packageName, true);
- }
- }
- if (metadataComplete.size() > 0) {
- jModel.setMetadataCompletePackageMap(metadataComplete);
- }
-
- JavaModelInputImpl inputImpl = new JavaModelInputImpl(typesToBeBound, jModel);
- try {
- Generator generator = new Generator(inputImpl, typesToBeBound, inputImpl.getJavaClasses(), null, xmlBindings, classLoader, defaultTargetNamespace, enableXmlAccessorFactory);
- JAXBContextState contextState = createContextState(generator, loader, typesToBeBound, properties);
+ jModel = new JavaModelImpl(loader);
+ }
+
+ if (xmlBindings != null) {
+ jModel.setHasXmlBindings(!xmlBindings.isEmpty());
+ // create Map of package names to metadata complete indicators
+ Map<String, Boolean> metadataComplete = new HashMap<String, Boolean>();
+ for (String packageName : xmlBindings.keySet()) {
+ if (xmlBindings.get(packageName).isXmlMappingMetadataComplete()) {
+ metadataComplete.put(packageName, true);
+ }
+ }
+
+ if (metadataComplete.size() > 0) {
+ jModel.setMetadataCompletePackageMap(metadataComplete);
+ }
+ } else {
+ jModel.setHasXmlBindings(false);
+ }
+
+ JavaModelInputImpl inputImpl = new JavaModelInputImpl(typesToBeBound, jModel);
+ if (properties != null) enableFacetsIfPropertySetTrue(inputImpl, properties);
+ try {
+ Generator generator = new Generator(inputImpl, typesToBeBound, inputImpl.getJavaClasses(), null, xmlBindings, classLoader, defaultTargetNamespace, enableXmlAccessorFactory);
+ JAXBContextState contextState = createContextState(generator, loader, typesToBeBound, properties);
return contextState;
} catch (Exception ex) {
throw new javax.xml.bind.JAXBException(ex.getMessage(), ex);
@@ -1112,14 +1118,13 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
} else {
conversionManager = ConversionManager.getDefaultManager();
}
- proj.convertClassNamesToClasses(conversionManager.getLoader());
- // need to make sure that the java class is set properly on each
- // descriptor when using java classname - req'd for JOT api implementation
- for (Iterator<ClassDescriptor> descriptorIt = proj.getOrderedDescriptors().iterator(); descriptorIt.hasNext();) {
- ClassDescriptor descriptor = descriptorIt.next();
- if (descriptor.getJavaClass() == null) {
- descriptor.setJavaClass(conversionManager.convertClassNameToClass(descriptor.getJavaClassName()));
- }
+ proj.convertClassNamesToClasses(conversionManager.getLoader());
+ // need to make sure that the java class is set properly on each
+ // descriptor when using java classname - req'd for JOT api implementation
+ for (ClassDescriptor descriptor : (Iterable<ClassDescriptor>) proj.getOrderedDescriptors()) {
+ if (descriptor.getJavaClass() == null) {
+ descriptor.setJavaClass(conversionManager.convertClassNameToClass(descriptor.getJavaClassName()));
+ }
}
XMLPlatform platform = new SAXPlatform();
@@ -1195,15 +1200,15 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
protected static class JAXBContextState {
- private XMLContext xmlContext;
- private org.eclipse.persistence.jaxb.compiler.Generator generator;
- private Map<QName, Class> qNameToGeneratedClasses;
- private HashMap<String, Class> classToGeneratedClasses;
- private HashMap<QName, Class> qNamesToDeclaredClasses;
- private HashMap<Type, QName> typeToSchemaType;
- private TypeMappingInfo[] boundTypes;
- private Map<TypeMappingInfo, Class> typeMappingInfoToGeneratedType;
- private Map<Type, TypeMappingInfo> typeToTypeMappingInfo;
+ private XMLContext xmlContext;
+ private org.eclipse.persistence.jaxb.compiler.Generator generator;
+ private Map<QName, Class> qNameToGeneratedClasses;
+ private Map<String, Class> classToGeneratedClasses;
+ private Map<QName, Class> qNamesToDeclaredClasses;
+ private Map<Type, QName> typeToSchemaType;
+ private TypeMappingInfo[] boundTypes;
+ private Map<TypeMappingInfo, Class> typeMappingInfoToGeneratedType;
+ private Map<Type, TypeMappingInfo> typeToTypeMappingInfo;
private Map<TypeMappingInfo, JAXBContext.RootLevelXmlAdapter> typeMappingInfoToJavaTypeAdapters;
private Map properties;
@@ -1235,13 +1240,13 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
protected JAXBContextState(XMLContext context, Generator generator, TypeMappingInfo[] boundTypes, Map properties) {
this(context);
this.generator = generator;
- this.qNameToGeneratedClasses = generator.getMappingsGenerator().getQNamesToGeneratedClasses();
- this.classToGeneratedClasses = generator.getMappingsGenerator().getClassToGeneratedClasses();
- this.qNamesToDeclaredClasses = generator.getMappingsGenerator().getQNamesToDeclaredClasses();
- this.typeMappingInfoToGeneratedType = generator.getAnnotationsProcessor().getTypeMappingInfoToGeneratedClasses();
- this.setTypeMappingInfoToJavaTypeAdapaters(createAdaptersForAdapterClasses(generator.getAnnotationsProcessor().getTypeMappingInfoToAdapterClasses()));
- this.boundTypes = boundTypes;
- if (properties != null) {
+ this.qNameToGeneratedClasses = generator.getMappingsGenerator().getQNamesToGeneratedClasses();
+ this.classToGeneratedClasses = generator.getMappingsGenerator().getClassToGeneratedClasses();
+ this.qNamesToDeclaredClasses = generator.getMappingsGenerator().getQNamesToDeclaredClasses();
+ this.typeMappingInfoToGeneratedType = generator.getAnnotationsProcessor().getTypeMappingInfosToGeneratedClasses();
+ this.setTypeMappingInfoToJavaTypeAdapaters(createAdaptersForAdapterClasses(generator.getAnnotationsProcessor().getTypeMappingInfoToAdapterClasses()));
+ this.boundTypes = boundTypes;
+ if (properties != null) {
this.properties = new HashMap(properties);
}
}
@@ -1307,17 +1312,17 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
return;
}
processed.add(desc);
-
- Vector mappings = desc.getMappings();
-
- for (int i = 0; i < mappings.size(); i++) {
- DatabaseMapping nextMapping = (DatabaseMapping) mappings.get(i);
- Vector fields = nextMapping.getFields();
- updateResolverForFields(fields, nr);
- Descriptor refDesc = (Descriptor) ((DatabaseMapping) nextMapping).getReferenceDescriptor();
- if (refDesc != null && !processed.contains(refDesc)) {
- processXMLDescriptor(processed, refDesc, nr);
- }
+
+ Vector mappings = desc.getMappings();
+
+ for (Object mapping : mappings) {
+ DatabaseMapping nextMapping = (DatabaseMapping) mapping;
+ Vector fields = nextMapping.getFields();
+ updateResolverForFields(fields, nr);
+ Descriptor refDesc = (Descriptor) nextMapping.getReferenceDescriptor();
+ if (refDesc != null && !processed.contains(refDesc)) {
+ processXMLDescriptor(processed, refDesc, nr);
+ }
if (nextMapping instanceof ChoiceObjectMapping) {
Set refClasses = ((ChoiceObjectMapping) nextMapping).getClassToFieldMappings().keySet();
@@ -1327,15 +1332,14 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
processRefClasses(processed, refClasses, nr);
}
}
- }
-
- private void updateResolverForFields(Collection fields, org.eclipse.persistence.internal.oxm.NamespaceResolver nr) {
- Iterator fieldIter = fields.iterator();
- while (fieldIter.hasNext()) {
- Field field = (XMLField) fieldIter.next();
- XPathFragment currentFragment = field.getXPathFragment();
-
- while (currentFragment != null) {
+ }
+
+ private void updateResolverForFields(Collection fields, org.eclipse.persistence.internal.oxm.NamespaceResolver nr) {
+ for (Object field1 : fields) {
+ Field field = (XMLField) field1;
+ XPathFragment currentFragment = field.getXPathFragment();
+
+ while (currentFragment != null) {
String uri = currentFragment.getNamespaceURI();
if (uri != null && nr.resolveNamespaceURI(uri) == null && !uri.equals(nr.getDefaultNamespaceURI())) {
String prefix = currentFragment.getPrefix();
@@ -1346,25 +1350,25 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
}
currentFragment = currentFragment.getNextFragment();
}
- }
- }
-
- private HashMap<String, Class> getClassToGeneratedClasses() {
- return classToGeneratedClasses;
- }
-
+ }
+ }
+
+ private Map<String, Class> getClassToGeneratedClasses() {
+ return classToGeneratedClasses;
+ }
+
private Generator getGenerator() {
return generator;
}
private XMLContext getXMLContext() {
- return this.xmlContext;
- }
-
- private HashMap<java.lang.reflect.Type, QName> getTypeToSchemaType() {
- if (typeToSchemaType == null) {
- initTypeToSchemaType();
- }
+ return this.xmlContext;
+ }
+
+ private Map<java.lang.reflect.Type, QName> getTypeToSchemaType() {
+ if (typeToSchemaType == null) {
+ initTypeToSchemaType();
+ }
return typeToSchemaType;
}
@@ -1381,16 +1385,16 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
}
private Map<TypeMappingInfo, QName> getTypeMappingInfoToSchemaType() {
- if (typeToTypeMappingInfo != null && typeToTypeMappingInfo.size() > 0) {
- return new HashMap<TypeMappingInfo, QName>();
- }
- return generator.getAnnotationsProcessor().getTypeMappingInfoToSchemaType();
- }
-
- private HashMap<QName, Class> getQNamesToDeclaredClasses() {
- return qNamesToDeclaredClasses;
- }
-
+ if (typeToTypeMappingInfo != null && typeToTypeMappingInfo.size() > 0) {
+ return new HashMap<TypeMappingInfo, QName>();
+ }
+ return generator.getAnnotationsProcessor().getTypeMappingInfosToSchemaTypes();
+ }
+
+ private Map<QName, Class> getQNamesToDeclaredClasses() {
+ return qNamesToDeclaredClasses;
+ }
+
/**
* INTERNAL:
* Get the QName which the given Type corresponds to.
@@ -1443,13 +1447,13 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
Type type = null;
if (generator != null) {
- type = generator.getAnnotationsProcessor().getGeneratedClassesToCollectionClasses().get(javaClass);
-
- if (type == null) {
- JavaClass arrayClass = (JavaClass) generator.getAnnotationsProcessor().getGeneratedClassesToArrayClasses().get(javaClass);
- if (arrayClass != null) {
- String arrayClassName = arrayClass.getName();
- try {
+ type = generator.getAnnotationsProcessor().getGeneratedClassesToCollectionClasses().get(javaClass);
+
+ if (type == null) {
+ JavaClass arrayClass = generator.getAnnotationsProcessor().getGeneratedClassesToArrayClasses().get(javaClass);
+ if (arrayClass != null) {
+ String arrayClassName = arrayClass.getName();
+ try {
type = PrivilegedAccessHelper.getClassForName(arrayClassName);
} catch (Exception ex) {
}
@@ -1537,12 +1541,15 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
setPropertyOnMarshaller(JAXBContextProperties.NAMESPACE_PREFIX_MAPPER, marshaller);
setPropertyOnMarshaller(JAXBContextProperties.JSON_INCLUDE_ROOT, marshaller);
setPropertyOnMarshaller(JAXBContextProperties.JSON_VALUE_WRAPPER, marshaller);
- setPropertyOnMarshaller(JAXBContextProperties.JSON_NAMESPACE_SEPARATOR, marshaller);
- setPropertyOnMarshaller(JAXBContextProperties.OBJECT_GRAPH, marshaller);
- setPropertyOnMarshaller(JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME, marshaller);
- }
-
- return marshaller;
+ setPropertyOnMarshaller(JAXBContextProperties.JSON_NAMESPACE_SEPARATOR, marshaller);
+ setPropertyOnMarshaller(JAXBContextProperties.OBJECT_GRAPH, marshaller);
+ setPropertyOnMarshaller(JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME, marshaller);
+ setPropertyOnMarshaller(JAXBContextProperties.BEAN_VALIDATION_MODE, marshaller);
+ setPropertyOnMarshaller(JAXBContextProperties.BEAN_VALIDATION_FACTORY, marshaller);
+ setPropertyOnMarshaller(JAXBContextProperties.BEAN_VALIDATION_GROUPS, marshaller);
+ }
+
+ return marshaller;
}
public JAXBUnmarshaller createUnmarshaller(JAXBContext jaxbContext) throws javax.xml.bind.JAXBException {
@@ -1568,6 +1575,9 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
setPropertyOnUnmarshaller(JAXBContextProperties.OBJECT_GRAPH, unmarshaller);
setPropertyOnUnmarshaller(JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME, unmarshaller);
setPropertyOnUnmarshaller(JAXBContextProperties.UNMARSHALLING_CASE_INSENSITIVE, unmarshaller);
+ setPropertyOnUnmarshaller(JAXBContextProperties.BEAN_VALIDATION_MODE, unmarshaller);
+ setPropertyOnUnmarshaller(JAXBContextProperties.BEAN_VALIDATION_FACTORY, unmarshaller);
+ setPropertyOnUnmarshaller(JAXBContextProperties.BEAN_VALIDATION_GROUPS, unmarshaller);
}
return unmarshaller;
}
@@ -1599,7 +1609,12 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
if (propertyValue != null) {
unmarshaller.setProperty(propertyName, propertyValue);
}
- }
-
- }
+ }
+
+ }
+
+ private static void enableFacetsIfPropertySetTrue(JavaModelInputImpl inputImpl, Map properties) {
+ Object propertyValue = properties.get(JAXBContextProperties.GENERATE_FACETS);
+ if (propertyValue != null) inputImpl.setFacets((Boolean) propertyValue);
+ }
} \ No newline at end of file