aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContextFactory.java')
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContextFactory.java180
1 files changed, 88 insertions, 92 deletions
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContextFactory.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContextFactory.java
index e44b0c2..e183ecf 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContextFactory.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContextFactory.java
@@ -1,8 +1,8 @@
-/*******************************************************************************
- * Copyright (c) 1998, 2013 Oracle and/or its affiliates. All rights reserved.
- * 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.
+/*******************************************************************************
+ * Copyright (c) 1998, 2014 Oracle and/or its affiliates. All rights reserved.
+ * 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.
@@ -138,21 +138,21 @@ public class JAXBContextFactory {
* also be aware of classes reachable from the types in the array. The
* preferred means of creating a Type aware JAXBContext is to create the
* JAXBContext with an array of TypeMappingInfo objects.
- */
- public static javax.xml.bind.JAXBContext createContext(Type[] typesToBeBound, Map properties, ClassLoader classLoader) throws JAXBException {
- Map<Type, TypeMappingInfo> typeToTypeMappingInfo = new HashMap<Type, TypeMappingInfo>();
- TypeMappingInfo[] typeMappingInfo = new TypeMappingInfo[typesToBeBound.length];
- for(int i = 0; i < typesToBeBound.length; i++) {
- TypeMappingInfo tmi = new TypeMappingInfo();
- tmi.setType(typesToBeBound[i]);
- typeToTypeMappingInfo.put(typesToBeBound[i], tmi);
- typeMappingInfo[i] = tmi;
- }
-
- JAXBContext context = (JAXBContext)createContext(typeMappingInfo, properties, classLoader);
- context.setTypeToTypeMappingInfo(typeToTypeMappingInfo);
-
- return context;
+ */
+ public static javax.xml.bind.JAXBContext createContext(Type[] typesToBeBound, Map properties, ClassLoader classLoader) throws JAXBException {
+ Map<Type, TypeMappingInfo> typeToTypeMappingInfo = new HashMap<Type, TypeMappingInfo>();
+ TypeMappingInfo[] typeMappingInfos = new TypeMappingInfo[typesToBeBound.length];
+ for(int i = 0; i < typesToBeBound.length; i++) {
+ TypeMappingInfo tmi = new TypeMappingInfo();
+ tmi.setType(typesToBeBound[i]);
+ typeToTypeMappingInfo.put(typesToBeBound[i], tmi);
+ typeMappingInfos[i] = tmi;
+ }
+
+ JAXBContext context = (JAXBContext)createContext(typeMappingInfos, properties, classLoader);
+ context.setTypeToTypeMappingInfo(typeToTypeMappingInfo);
+
+ return context;
}
/**
@@ -213,47 +213,45 @@ public class JAXBContextFactory {
Map<String, Object> metadataFiles = null;
try {
metadataFiles = (Map<String, Object>) value;
- } catch (ClassCastException x) {
- throw org.eclipse.persistence.exceptions.JAXBException.incorrectValueParameterTypeForOxmXmlKey();
- }
- if (metadataFiles != null) {
- for(Entry<String, Object> entry : metadataFiles.entrySet()) {
- String key = null;
- List<XmlBindings> xmlBindings = new ArrayList<XmlBindings>();
- try {
- key = entry.getKey();
- if (key == null) {
- throw org.eclipse.persistence.exceptions.JAXBException.nullMapKey();
- }
- } catch (ClassCastException cce) {
- throw org.eclipse.persistence.exceptions.JAXBException.incorrectKeyParameterType();
- }
- Object metadataSource = entry.getValue();
- if (metadataSource == null) {
- throw org.eclipse.persistence.exceptions.JAXBException.nullMetadataSource(key);
- }
- if(metadataSource instanceof List) {
- for(Object next: (List)metadataSource) {
- XmlBindings binding = getXmlBindings(next, classLoader, properties);
- if(binding != null) {
- xmlBindings.add(binding);
- }
- }
- } else {
- XmlBindings binding = getXmlBindings(metadataSource, classLoader, properties);
- if(binding != null) {
- xmlBindings.add(binding);
- }
- }
- if (xmlBindings != null) {
- bindings.put(key, xmlBindings);
- }
- }
- }
- // handle List<Object>
- } else if (value instanceof List) {
- for (Object metadataSource : (List) value) {
- if (metadataSource == null) {
+ } catch (ClassCastException x) {
+ throw org.eclipse.persistence.exceptions.JAXBException.incorrectValueParameterTypeForOxmXmlKey();
+ }
+ for(Entry<String, Object> entry : metadataFiles.entrySet()) {
+ String key = null;
+ List<XmlBindings> xmlBindings = new ArrayList<XmlBindings>();
+ try {
+ key = entry.getKey();
+ if (key == null) {
+ throw org.eclipse.persistence.exceptions.JAXBException.nullMapKey();
+ }
+ } catch (ClassCastException cce) {
+ throw org.eclipse.persistence.exceptions.JAXBException.incorrectKeyParameterType();
+ }
+ Object metadataSource = entry.getValue();
+ if (metadataSource == null) {
+ throw org.eclipse.persistence.exceptions.JAXBException.nullMetadataSource(key);
+ }
+ if(metadataSource instanceof List) {
+ for(Object next: (List)metadataSource) {
+ XmlBindings binding = getXmlBindings(next, classLoader, properties);
+ if(binding != null) {
+ xmlBindings.add(binding);
+ }
+ }
+ } else {
+ XmlBindings binding = getXmlBindings(metadataSource, classLoader, properties);
+ if(binding != null) {
+ xmlBindings.add(binding);
+ }
+ }
+ if (xmlBindings != null) {
+ bindings.put(key, xmlBindings);
+ }
+ }
+ // handle List<Object>
+ } else if (value instanceof List) {
+ for (Object metadataSource : (List) value) {
+ if (metadataSource == null) {
throw org.eclipse.persistence.exceptions.JAXBException.nullMetadataSource();
}
bindings = processBindingFile(bindings, metadataSource, classLoader, properties);
@@ -277,29 +275,28 @@ public class JAXBContextFactory {
* @param originalBindings Map of bindings to be updated
* @param bindingHandle handle to bindings file
* @param classLoader
- * @return
- */
- private static Map<String, List<XmlBindings>> processBindingFile(Map<String, List<XmlBindings>> originalBindings, Object bindingHandle, ClassLoader classLoader, Map<String, Object> properties) {
- Map<String, List<XmlBindings>> bindingMap = originalBindings;
- XmlBindings binding = getXmlBindings(bindingHandle, classLoader, properties);
- if (binding != null) {
- String key = binding.getPackageName();
- if (key.equals(XMLProcessor.DEFAULT)) {
- throw org.eclipse.persistence.exceptions.JAXBException.packageNotSetForBindingException();
- }
- List<XmlBindings> existingBindings = bindingMap.get(key);
- if(existingBindings != null) {
- existingBindings.add(binding);
- } else {
- existingBindings = new ArrayList<XmlBindings>();
- existingBindings.add(binding);
- bindingMap.put(key, existingBindings);
- }
- }
- return bindingMap;
- }
-
- /**
+ * @return
+ */
+ private static Map<String, List<XmlBindings>> processBindingFile(Map<String, List<XmlBindings>> originalBindings, Object bindingHandle, ClassLoader classLoader, Map<String, Object> properties) {
+ XmlBindings binding = getXmlBindings(bindingHandle, classLoader, properties);
+ if (binding != null) {
+ String key = binding.getPackageName();
+ if (key.equals(XMLProcessor.DEFAULT)) {
+ throw org.eclipse.persistence.exceptions.JAXBException.packageNotSetForBindingException();
+ }
+ List<XmlBindings> existingBindings = originalBindings.get(key);
+ if(existingBindings != null) {
+ existingBindings.add(binding);
+ } else {
+ existingBindings = new ArrayList<XmlBindings>();
+ existingBindings.add(binding);
+ originalBindings.put(key, existingBindings);
+ }
+ }
+ return originalBindings;
+ }
+
+ /**
* Convenience method for creating an XmlBindings object based on a given Object. The method
* will load the eclipselink metadata model and unmarshal the Object. This assumes that the
* Object represents the eclipselink-oxm.xml metadata file to be unmarshalled.
@@ -307,14 +304,13 @@ public class JAXBContextFactory {
* @param metadata assumed to be one of: File, InputSource, InputStream, Reader, Source
*/
private static XmlBindings getXmlBindings(Object metadata, ClassLoader classLoader, Map<String, Object> properties) {
- JAXBContext jaxbContext = CompilerHelper.getXmlBindingsModelContext();
- InputStream openedStream = null;
-
- try{
-
- Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
- unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_XML);
- unmarshaller.setProperty(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE, true);
+ JAXBContext jaxbContext = CompilerHelper.getXmlBindingsModelContext();
+ InputStream openedStream = null;
+
+ try {
+ Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
+ unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_XML);
+ unmarshaller.setProperty(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE, true);
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, false);
unmarshaller.setEventHandler(new DefaultValidationEventHandler());
if (metadata instanceof MetadataSource){