aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarcel Valovy2014-04-03 08:17:56 (EDT)
committerTomas Kraus2014-05-05 09:36:58 (EDT)
commitbf6100856b60f5c4703eb7fb5e0a4b05174b09cb (patch)
tree440491b418e2224b65744dca7f448a8703ddb836
parentca004013038d6a7b914feb39ae2da798e6e09cb7 (diff)
downloadeclipselink.runtime-bf6100856b60f5c4703eb7fb5e0a4b05174b09cb.zip
eclipselink.runtime-bf6100856b60f5c4703eb7fb5e0a4b05174b09cb.tar.gz
eclipselink.runtime-bf6100856b60f5c4703eb7fb5e0a4b05174b09cb.tar.bz2
Signed-off-by: Marcel Valovy <marcel.valovy@oracle.com>
Bug 331241 - Enhancement Request: Case insensitive unmarshalling - Added a new feature to unmarshalling: An option to turn on/off case insensitive unmarshalling on JAXB Context or on Unmarshaller. - By default the feature is turned off. - Collisions may occur when case insensitive unmarshalling is turned on. They are logged and basically the second occurrence replaces the first one. - Turning on case insensitive unmarshalling means overhead, not a significant one though.
-rw-r--r--foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/Unmarshaller.java8
-rw-r--r--foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XMLUnmarshaller.java62
-rw-r--r--foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XPathFragment.java62
-rw-r--r--foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XPathNode.java226
-rw-r--r--foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/record/UnmarshalRecordImpl.java205
-rw-r--r--moxy/eclipselink.moxy.test/antbuild.xml2
-rw-r--r--moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/casesensitivity/customer.xml5
-rw-r--r--moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/casesensitivity/loremIpsum.xml23
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBPerformanceTestSuite.java36
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite4.java5
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/Customer.java84
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityPerfTestCase.java111
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityTestCase.java134
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/correctCase/CustomerImpl.java93
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/correctCase/LoremIpsum.java41
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/otherCase/CustomerImpl.java94
-rw-r--r--moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/otherCase/LoremIpsum.java41
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContext.java36
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContextProperties.java64
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBUnmarshaller.java56
-rw-r--r--moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/UnmarshallerProperties.java64
21 files changed, 1183 insertions, 269 deletions
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/Unmarshaller.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/Unmarshaller.java
index bd7d317..4c342d0 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/Unmarshaller.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/Unmarshaller.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012, 2013 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 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.
@@ -9,6 +9,7 @@
*
* Contributors:
* Blaise Doughan - 2.5 - initial implementation
+ * Marcel Valovy - 2.6.0 - added case insensitive unmarshalling property
******************************************************************************/
package org.eclipse.persistence.internal.oxm;
@@ -174,6 +175,11 @@ public abstract class Unmarshaller<
public abstract boolean isAutoDetectMediaType();
/**
+ * Return whether this Unmarshaller should perform case insensitive unmarshalling.
+ */
+ public abstract boolean isCaseInsensitive();
+
+ /**
* Determine if the @XMLRootElement should be marshalled when present.
* Ignored unmarshalling XML.
* @return
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XMLUnmarshaller.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XMLUnmarshaller.java
index 16bbf63..99388ba 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XMLUnmarshaller.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XMLUnmarshaller.java
@@ -1,17 +1,18 @@
-/*******************************************************************************
- * Copyright (c) 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) 2013, 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.
- *
- * Contributors:
- * Blaise Doughan - 2.6 - initial implementation
- ******************************************************************************/
-package org.eclipse.persistence.internal.oxm;
-
+ *
+ * Contributors:
+ * Blaise Doughan - 2.6 - initial implementation
+ * Marcel Valovy - 2.6.0 - added case insensitive unmarshalling
+ ******************************************************************************/
+package org.eclipse.persistence.internal.oxm;
+
import java.io.File;
import java.io.InputStream;
import java.io.Reader;
@@ -144,12 +145,13 @@ public class XMLUnmarshaller<
private String valueWrapper = Constants.VALUE_WRAPPER;
private char namespaceSeparator = Constants.DOT;
private String attributePrefix;
- private boolean includeRoot = true;
- private NamespaceResolver namespaceResolver;
- private boolean autoDetectMediaType = false;
- private Object unmarshalAttributeGroup;
- private boolean wrapperAsCollectionName = false;
-
+ private boolean includeRoot = true;
+ private NamespaceResolver namespaceResolver;
+ private boolean autoDetectMediaType = false;
+ private boolean caseInsensitive = false;
+ private Object unmarshalAttributeGroup;
+ private boolean wrapperAsCollectionName = false;
+
static {
try {
staxSourceClass = PrivilegedAccessHelper.getClassForName(STAX_SOURCE_CLASS_NAME);
@@ -776,13 +778,25 @@ public class XMLUnmarshaller<
* by setMediaType)
*/
public void setAutoDetectMediaType(boolean autoDetectMediaType) {
- this.autoDetectMediaType = autoDetectMediaType;
- }
-
-
-
- /**
- * Name of the NamespaceResolver to be used during unmarshal
+ this.autoDetectMediaType = autoDetectMediaType;
+ }
+
+ /**
+ * Return if this Unmarshaller should perform case insensitive unmarshalling.
+ */
+ public boolean isCaseInsensitive(){
+ return caseInsensitive;
+ }
+
+ /**
+ * Set true to make this Unmarshaller perform case insensitive unmarshalling.
+ */
+ public void setCaseInsensitive(boolean caseInsensitive) {
+ this.caseInsensitive = caseInsensitive;
+ }
+
+ /**
+ * Name of the NamespaceResolver to be used during unmarshal
* Ignored unmarshalling XML.
* @since 2.4
*/
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XPathFragment.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XPathFragment.java
index f519c9a..8640ee5 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XPathFragment.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XPathFragment.java
@@ -10,12 +10,14 @@
* Contributors:
* Oracle - initial API and implementation from Oracle TopLink
******************************************************************************/
-package org.eclipse.persistence.internal.oxm;
-
-import java.nio.charset.Charset;
-import java.util.StringTokenizer;
-
-import javax.xml.namespace.QName;
+package org.eclipse.persistence.internal.oxm;
+
+import java.nio.charset.Charset;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.StringTokenizer;
+
+import javax.xml.namespace.QName;
import org.eclipse.persistence.internal.oxm.mappings.Field;
@@ -60,12 +62,15 @@ public class XPathFragment <
private QName leafElementType;
private boolean generatedPrefix = false;
private XPathPredicate predicate;
-
- private boolean namespaceAware;
- private char namespaceSeparator;
-
-
- public XPathFragment() {
+
+ private boolean namespaceAware;
+ private char namespaceSeparator;
+
+ private Set<String> attributeCollisionSet;
+ private Set<String> nonAttributeCollisionSet;
+
+
+ public XPathFragment() {
setNamespaceAware(true);
namespaceSeparator = Constants.COLON;
}
@@ -412,7 +417,32 @@ public class XPathFragment <
private void resetShortName(){
shortName = null;
- prefixBytes = null;
- localNameBytes = null;
- }
-}
+ prefixBytes = null;
+ localNameBytes = null;
+ }
+
+ /**
+ * INTERNAL:
+ * Gets auxiliary set for determining collisions during case insensitive unmarshalling.
+ *
+ * @param isAttribute Determine if retrieving an element or an attribute collision set.
+ * @return
+ * Set containing localNames of attributes or elements of an XPathFragment.
+ */
+ public Set<String> getChildrenCollisionSet(boolean isAttribute) {
+ return isAttribute ? getAttributeCollisionSet() : getNonAttributeCollisionSet();
+ }
+
+ private Set<String> getAttributeCollisionSet() {
+ if (attributeCollisionSet == null)
+ attributeCollisionSet = new HashSet<String>();
+ return attributeCollisionSet;
+ }
+
+ private Set<String> getNonAttributeCollisionSet() {
+ if (nonAttributeCollisionSet == null)
+ nonAttributeCollisionSet = new HashSet<String>();
+ return nonAttributeCollisionSet;
+ }
+
+}
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XPathNode.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XPathNode.java
index adedf82..c433acb 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XPathNode.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/XPathNode.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.
@@ -15,13 +15,12 @@ package org.eclipse.persistence.internal.oxm;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-
-import org.eclipse.persistence.internal.core.sessions.CoreAbstractSession;
-import org.eclipse.persistence.internal.oxm.XPathFragment;
-import org.eclipse.persistence.internal.oxm.mappings.Mapping;
-import org.eclipse.persistence.internal.oxm.record.MarshalContext;
-import org.eclipse.persistence.internal.oxm.record.MarshalRecord;
+import java.util.Map;
+
+import org.eclipse.persistence.internal.core.sessions.CoreAbstractSession;
+import org.eclipse.persistence.internal.oxm.mappings.Mapping;
+import org.eclipse.persistence.internal.oxm.record.MarshalContext;
+import org.eclipse.persistence.internal.oxm.record.MarshalRecord;
import org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext;
import org.eclipse.persistence.core.queries.CoreAttributeGroup;
@@ -52,22 +51,26 @@ public class XPathNode {
private XPathFragment xPathFragment;
private XPathNode parent;
private List<XPathNode> attributeChildren;
- private List<XPathNode> nonAttributeChildren;
- private List<XPathNode> selfChildren;
- private Map<XPathFragment, XPathNode> attributeChildrenMap;
- private Map<XPathFragment, XPathNode> nonAttributeChildrenMap;
- private MappingNodeValue anyAttributeNodeValue;
- private XPathNode anyAttributeNode;
- private XPathNode textNode;
+ private List<XPathNode> nonAttributeChildren;
+ private List<XPathNode> selfChildren;
+ private Map<XPathFragment, XPathNode> attributeChildrenMap;
+ private Map<String, XPathNode> attributeChildrenLookupTable;
+ private boolean isAttributeChildrenLookupTableFilled = false;
+ private Map<XPathFragment, XPathNode> nonAttributeChildrenMap;
+ private Map<String, XPathNode> nonAttributeChildrenLookupTable;
+ private boolean isNonAttributeChildrenLookupTableFilled = false;
+ private MappingNodeValue anyAttributeNodeValue;
+ private XPathNode anyAttributeNode;
+ private XPathNode textNode;
private XPathNode anyNode;
private boolean hasTypeChild;
- private boolean hasPredicateSiblings;
- private boolean hasPredicateChildren;
- private NullCapableValue nullCapableValue;
-
- public XPathFragment getXPathFragment() {
- return xPathFragment;
- }
+ private boolean hasPredicateSiblings;
+ private boolean hasPredicateChildren;
+ private NullCapableValue nullCapableValue;
+
+ public XPathFragment getXPathFragment() {
+ return xPathFragment;
+ }
public void setXPathFragment(XPathFragment xPathFragment) {
this.xPathFragment = xPathFragment;
@@ -82,44 +85,44 @@ public class XPathNode {
this.unmarshalNodeValue = nodeValue;
if (null != nodeValue) {
nodeValue.setXPathNode(this);
- isMarshalOnlyNodeValue = nodeValue.isMarshalOnlyNodeValue();
- }
- }
-
- public NodeValue getUnmarshalNodeValue() {
- return unmarshalNodeValue;
- }
-
- public void setUnmarshalNodeValue(NodeValue nodeValue) {
- if (null != nodeValue) {
- nodeValue.setXPathNode(this);
+ isMarshalOnlyNodeValue = nodeValue.isMarshalOnlyNodeValue();
+ }
+ }
+
+ public NodeValue getUnmarshalNodeValue() {
+ return unmarshalNodeValue;
+ }
+
+ public void setUnmarshalNodeValue(NodeValue nodeValue) {
+ if (null != nodeValue) {
+ nodeValue.setXPathNode(this);
}
this.unmarshalNodeValue = nodeValue;
}
- public NodeValue getMarshalNodeValue() {
- return marshalNodeValue;
- }
-
- public void setMarshalNodeValue(NodeValue nodeValue) {
- if (null != nodeValue) {
- nodeValue.setXPathNode(this);
+ public NodeValue getMarshalNodeValue() {
+ return marshalNodeValue;
+ }
+
+ public void setMarshalNodeValue(NodeValue nodeValue) {
+ if (null != nodeValue) {
+ nodeValue.setXPathNode(this);
}
- this.marshalNodeValue = nodeValue;
- isMarshalOnlyNodeValue = marshalNodeValue.isMarshalOnlyNodeValue();
- }
-
- public NullCapableValue getNullCapableValue() {
- return nullCapableValue;
- }
-
- public void setNullCapableValue(NullCapableValue nullCapableValue) {
- this.nullCapableValue = nullCapableValue;
- }
-
- public XPathNode getParent() {
- return parent;
- }
+ this.marshalNodeValue = nodeValue;
+ isMarshalOnlyNodeValue = marshalNodeValue.isMarshalOnlyNodeValue();
+ }
+
+ public NullCapableValue getNullCapableValue() {
+ return nullCapableValue;
+ }
+
+ public void setNullCapableValue(NullCapableValue nullCapableValue) {
+ this.nullCapableValue = nullCapableValue;
+ }
+
+ public XPathNode getParent() {
+ return parent;
+ }
public void setParent(XPathNode parent) {
this.parent = parent;
@@ -142,12 +145,39 @@ public class XPathNode {
}
public Map<XPathFragment, XPathNode> getAttributeChildrenMap() {
- return this.attributeChildrenMap;
- }
-
- public void setAnyAttributeNodeValue(MappingNodeValue nodeValue) {
- this.anyAttributeNodeValue = nodeValue;
- }
+ return this.attributeChildrenMap;
+ }
+
+ public boolean isChildrenLookupTableFilled(boolean isAttribute) {
+ return isAttribute ? isAttributeChildrenLookupTableFilled : isNonAttributeChildrenLookupTableFilled;
+ }
+
+ public void setChildrenLookupTableFilled(boolean isAttribute) {
+ if (isAttribute)
+ this.isAttributeChildrenLookupTableFilled = true;
+ else
+ this.isNonAttributeChildrenLookupTableFilled = true;
+ }
+
+ public Map<String, XPathNode> getChildrenLookupTable(boolean isAttribute) {
+ return isAttribute ? getAttributeChildrenLookupTable() : getNonAttributeChildrenLookupTable();
+ }
+
+ private Map<String, XPathNode> getAttributeChildrenLookupTable() {
+ if (attributeChildrenLookupTable == null)
+ attributeChildrenLookupTable = new HashMap<String, XPathNode>();
+ return attributeChildrenLookupTable;
+ }
+
+ private Map<String, XPathNode> getNonAttributeChildrenLookupTable() {
+ if (nonAttributeChildrenLookupTable == null)
+ nonAttributeChildrenLookupTable = new HashMap<String, XPathNode>();
+ return nonAttributeChildrenLookupTable;
+ }
+
+ public void setAnyAttributeNodeValue(MappingNodeValue nodeValue) {
+ this.anyAttributeNodeValue = nodeValue;
+ }
public MappingNodeValue getAnyAttributeNodeValue() {
return this.anyAttributeNodeValue;
@@ -318,17 +348,17 @@ public class XPathNode {
if(!children.contains(xPathNode)) {
children.add(xPathNode);
}
- childrenMap.put(anXPathFragment, xPathNode);
- }
- }
-
- if (aNodeValue.isOwningNode(anXPathFragment)) {
- if(aNodeValue.isMarshalNodeValue()) {
- xPathNode.setMarshalNodeValue(aNodeValue);
- }
- if(aNodeValue.isUnmarshalNodeValue() && xPathNode.getUnmarshalNodeValue() == null) {
- xPathNode.setUnmarshalNodeValue(aNodeValue);
- }
+ childrenMap.put(anXPathFragment, xPathNode);
+ }
+ }
+
+ if (aNodeValue.isOwningNode(anXPathFragment)) {
+ if(aNodeValue.isMarshalNodeValue()) {
+ xPathNode.setMarshalNodeValue(aNodeValue);
+ }
+ if(aNodeValue.isUnmarshalNodeValue() && xPathNode.getUnmarshalNodeValue() == null) {
+ xPathNode.setUnmarshalNodeValue(aNodeValue);
+ }
} else {
XPathFragment nextFragment = anXPathFragment.getNextFragment();
xPathNode.addChild(nextFragment, aNodeValue, namespaceResolver);
@@ -336,13 +366,13 @@ public class XPathNode {
return xPathNode;
}
- private void setHasPredicateSiblings(boolean b) {
- this.hasPredicateSiblings = b;
- }
-
- public boolean hasPredicateSiblings() {
- return this.hasPredicateSiblings;
- }
+ private void setHasPredicateSiblings(boolean b) {
+ this.hasPredicateSiblings = b;
+ }
+
+ public boolean hasPredicateSiblings() {
+ return this.hasPredicateSiblings;
+ }
public boolean marshal(MarshalRecord marshalRecord, Object object, CoreAbstractSession session, NamespaceResolver namespaceResolver, Marshaller marshaller, MarshalContext marshalContext, XPathFragment rootFragment) {
if ((null == marshalNodeValue) || isMarshalOnlyNodeValue) {
@@ -399,13 +429,13 @@ public class XPathNode {
}
}
return marshalContext.marshal(marshalNodeValue, xPathFragment, marshalRecord, object, session, namespaceResolver, rootFragment);
- }
- }
-
- public boolean startElement(MarshalRecord marshalRecord, XPathFragment anXPathFragment, Object object, CoreAbstractSession session, NamespaceResolver namespaceResolver, ObjectBuilder compositeObjectBuilder, Object compositeObject) {
- if (null == anXPathFragment) {
- return false;
- }
+ }
+ }
+
+ public boolean startElement(MarshalRecord marshalRecord, XPathFragment anXPathFragment, Object object, CoreAbstractSession session, NamespaceResolver namespaceResolver, ObjectBuilder compositeObjectBuilder, Object compositeObject) {
+ if (null == anXPathFragment) {
+ return false;
+ }
marshalRecord.openStartElement(anXPathFragment, namespaceResolver);
boolean hasValue = false;
@@ -428,14 +458,14 @@ public class XPathNode {
}
marshalRecord.closeStartElement();
return hasValue;
- }
-
- /**
- * Marshal any 'self' mapped attributes.
- *
- * @param marshalRecord
- * @param object
- * @param session
+ }
+
+ /**
+ * Marshal any 'self' mapped attributes.
+ *
+ * @param marshalRecord
+ * @param object
+ * @param session
* @param namespaceResolver
* @param marshaller
* @return
diff --git a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/record/UnmarshalRecordImpl.java b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/record/UnmarshalRecordImpl.java
index e0a3c3e..a88b3b6 100644
--- a/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/record/UnmarshalRecordImpl.java
+++ b/foundation/org.eclipse.persistence.core/src/org/eclipse/persistence/internal/oxm/record/UnmarshalRecordImpl.java
@@ -1,17 +1,18 @@
-/*******************************************************************************
- * 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.
- *
- * Contributors:
- * Oracle - initial API and implementation from Oracle TopLink
- ******************************************************************************/
-package org.eclipse.persistence.internal.oxm.record;
-
+ *
+ * Contributors:
+ * Oracle - initial API and implementation from Oracle TopLink
+ * Marcel Valovy - 2.6.0 - added case insensitive unmarshalling
+ ******************************************************************************/
+package org.eclipse.persistence.internal.oxm.record;
+
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -57,12 +58,13 @@ import org.eclipse.persistence.internal.oxm.mappings.Mapping;
import org.eclipse.persistence.internal.oxm.mappings.TransformationMapping;
import org.eclipse.persistence.internal.oxm.record.namespaces.StackUnmarshalNamespaceResolver;
import org.eclipse.persistence.internal.oxm.record.namespaces.UnmarshalNamespaceResolver;
-import org.eclipse.persistence.internal.oxm.unmapped.UnmappedContentHandler;
-import org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass;
-import org.eclipse.persistence.internal.sessions.AbstractSession;
-import org.w3c.dom.Document;
-import org.xml.sax.Attributes;
-import org.xml.sax.ErrorHandler;
+import org.eclipse.persistence.internal.oxm.unmapped.UnmappedContentHandler;
+import org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass;
+import org.eclipse.persistence.internal.sessions.AbstractSession;
+import org.eclipse.persistence.sessions.coordination.CommandProcessor;
+import org.w3c.dom.Document;
+import org.xml.sax.Attributes;
+import org.xml.sax.ErrorHandler;
import org.xml.sax.Locator;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
@@ -1211,16 +1213,23 @@ public class UnmarshalRecordImpl<TRANSFORMATION_RECORD extends TransformationRec
xPathFragment.setNamespaceURI(null);
} else {
xPathFragment.setLocalName(localName);
- xPathFragment.setNamespaceURI(namespaceURI);
- }
-
- XPathNode resultNode = null;
- Map nonAttributeChildrenMap = xPathNode.getNonAttributeChildrenMap();
- if (null != nonAttributeChildrenMap) {
- resultNode = (XPathNode)nonAttributeChildrenMap.get(xPathFragment);
- XPathNode nonPredicateNode = null;
- if(resultNode != null && resultNode.hasPredicateSiblings()) {
- nonPredicateNode = resultNode;
+ xPathFragment.setNamespaceURI(namespaceURI);
+ }
+
+ Map<XPathFragment, XPathNode> nonAttributeChildrenMap = xPathNode.getNonAttributeChildrenMap();
+
+ if (null != nonAttributeChildrenMap) {
+ XPathNode resultNode;
+
+ if (unmarshaller.isCaseInsensitive()){
+ resultNode = getNodeFromLookupTable(nonAttributeChildrenMap, false);
+ } else {
+ resultNode = nonAttributeChildrenMap.get(xPathFragment);
+ }
+
+ XPathNode nonPredicateNode = null;
+ if(resultNode != null && resultNode.hasPredicateSiblings()) {
+ nonPredicateNode = resultNode;
resultNode = null;
}
if (null == resultNode) {
@@ -1240,24 +1249,24 @@ public class UnmarshalRecordImpl<TRANSFORMATION_RECORD extends TransformationRec
indexMap.put(xPathFragment, newIndex);
XPathFragment predicateFragment = new XPathFragment();
predicateFragment.setNamespaceAware(isNamespaceAware());
- predicateFragment.setNamespaceURI(xPathFragment.getNamespaceURI());
- predicateFragment.setLocalName(xPathFragment.getLocalName());
- predicateFragment.setIndexValue(newIndex);
- resultNode = (XPathNode)nonAttributeChildrenMap.get(predicateFragment);
- if (null == resultNode) {
- predicateFragment.setIndexValue(-1);
- if(attributes != null){
+ predicateFragment.setNamespaceURI(xPathFragment.getNamespaceURI());
+ predicateFragment.setLocalName(xPathFragment.getLocalName());
+ predicateFragment.setIndexValue(newIndex);
+ resultNode = nonAttributeChildrenMap.get(predicateFragment);
+ if (null == resultNode) {
+ predicateFragment.setIndexValue(-1);
+ if(attributes != null){
for(int x = 0, length = attributes.getLength(); x<length; x++) {
XPathFragment conditionFragment = new XPathFragment();
conditionFragment.setLocalName(attributes.getLocalName(x));
conditionFragment.setNamespaceURI(attributes.getURI(x));
- conditionFragment.setAttribute(true);
- XPathPredicate condition = new XPathPredicate(conditionFragment, attributes.getValue(x));
- predicateFragment.setPredicate(condition);
- resultNode = (XPathNode) nonAttributeChildrenMap.get(predicateFragment);
- if(null != resultNode) {
- break;
- }
+ conditionFragment.setAttribute(true);
+ XPathPredicate condition = new XPathPredicate(conditionFragment, attributes.getValue(x));
+ predicateFragment.setPredicate(condition);
+ resultNode = nonAttributeChildrenMap.get(predicateFragment);
+ if(null != resultNode) {
+ break;
+ }
}
}
//if json, check for text wrapper before handing off to the any
@@ -1312,25 +1321,101 @@ public class UnmarshalRecordImpl<TRANSFORMATION_RECORD extends TransformationRec
}
}
return null;
- }
-
- public NodeValue getAttributeChildNodeValue(String namespace, String localName) {
- Map attributeChildrenMap = xPathNode.getAttributeChildrenMap();
- if (attributeChildrenMap != null) {
- xPathFragment.setLocalName(localName);
- xPathFragment.setNamespaceURI(namespace);
-
- XPathNode node = (XPathNode)attributeChildrenMap.get(xPathFragment);
- if (node != null) {
- return node.getUnmarshalNodeValue();
- }
- }
- return null;
- }
-
- public SAXFragmentBuilder getFragmentBuilder() {
- if(this.fragmentBuilder == null){
- fragmentBuilder = new SAXFragmentBuilder(this);
+ }
+
+ public NodeValue getAttributeChildNodeValue(String namespace, String localName) {
+ Map<XPathFragment, XPathNode> attributeChildrenMap = xPathNode.getAttributeChildrenMap();
+ if (attributeChildrenMap != null) {
+ XPathNode resultNode;
+ xPathFragment.setLocalName(localName);
+ xPathFragment.setNamespaceURI(namespace);
+
+ if (unmarshaller.isCaseInsensitive()){
+ resultNode = getNodeFromLookupTable(attributeChildrenMap, true);
+ } else {
+ resultNode = attributeChildrenMap.get(xPathFragment);
+ }
+
+ if (resultNode != null) {
+ return resultNode.getUnmarshalNodeValue();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * INTERNAL:
+ * Retrieves the XPathNode by searching in the auxiliary case insensitive lookup table.
+ *
+ * @param childrenMap Original Map for construction of the auxiliary table.
+ * @param isAttribute Determine if searching for an element or an attribute.
+ * @return XPathNode object reference, which is also present in the original children map.
+ * @since 2.6.0
+ */
+ private XPathNode getNodeFromLookupTable(Map<XPathFragment, XPathNode> childrenMap, boolean isAttribute) {
+ Map<String, XPathNode> lookupTable = xPathNode.getChildrenLookupTable(isAttribute);
+
+ if(!xPathNode.isChildrenLookupTableFilled(isAttribute)){
+ this.fillLookupTable(childrenMap, lookupTable);
+ xPathNode.setChildrenLookupTableFilled(isAttribute);
+ }
+
+ String lowerCaseFragment = xPathFragment.getLocalName().toLowerCase();
+ if (!xPathFragment.getChildrenCollisionSet(isAttribute).add(lowerCaseFragment))
+ handleCollision(lowerCaseFragment, false);
+ return lookupTable.get(lowerCaseFragment);
+ }
+
+ /**
+ * INTERNAL:
+ * Creates an auxiliary lookup table containing lower-cased localNames of XPathFragments.
+ *
+ * Does NOT pass the Turkey test.
+ *
+ * For future development: Handle ISO-8859-9 encoding.
+ * if (encoding.equals("ISO-8859-9")) {
+ * String auxLocalName = entry.getKey().getLocalName().toLowerCase(Locale.forLanguageTag("tr-TR"));
+ * }
+ *
+ * @param childrenMap Table from which the data is acquired.
+ * @param lookupTable Table to which the lower-cased data is stored.
+ * @since 2.6.0
+ */
+ private void fillLookupTable(Map<XPathFragment, XPathNode> childrenMap, Map<String, XPathNode> lookupTable) {
+ String lookupName;
+ for (Map.Entry<XPathFragment, XPathNode> entry : childrenMap.entrySet()) {
+ lookupName = entry.getKey().getLocalName().toLowerCase();
+ if (lookupTable.put(lookupName, entry.getValue()) != null){
+ handleCollision(lookupName, true);
+ }
+ }
+ }
+
+ /**
+ * INTERNAL:
+ * Handles collisions, i.e. fragments or fields with the same name, different case.
+ *
+ * @param lookupName Lookup variant of the localName.
+ * @param onXPathNode true - the collision occurred on XPathNode (case for Java fields),
+ * false - the collision occurred on XPathFragment (case for XML elements/attributes).
+ * @since 2.6.0
+ */
+ private void handleCollision(String lookupName, boolean onXPathNode) {
+ StringBuilder sb = new StringBuilder()
+ .append(">\nUnmarshalRecordImpl.handleCollision() -->\tCOLLISION on ")
+ .append(
+ onXPathNode
+ ? "XPathNode fields by case insensitive localName \""
+ : "XPathFragments by case insensitive localName \""
+ ).append(lookupName).append("\".");
+
+// session.setLogLevel(SessionLog.WARNING); // for debugging
+ ((AbstractSession) session).logMessage(CommandProcessor.LOG_WARNING, sb.toString());
+ }
+
+ public SAXFragmentBuilder getFragmentBuilder() {
+ if(this.fragmentBuilder == null){
+ fragmentBuilder = new SAXFragmentBuilder(this);
}
return fragmentBuilder;
}
diff --git a/moxy/eclipselink.moxy.test/antbuild.xml b/moxy/eclipselink.moxy.test/antbuild.xml
index 78b6aad..e7233bc 100644
--- a/moxy/eclipselink.moxy.test/antbuild.xml
+++ b/moxy/eclipselink.moxy.test/antbuild.xml
@@ -35,6 +35,7 @@
* rbarkhouse - 06 Apr 2011 - Separate JavadocAnnotationExamples from JAXBTestSuite
* dmahar - Jan 2012 - remove update-package-names targets
* bdoughan - Sep 2012 - Added RESTful tests and necessary dependencies
+* mvalovy - Mar 2014 - Added JAXBPerformanceTestSuite
#******************************************************************************/-->
<project name="eclipselink.moxy.test" default="test" basedir=".">
@@ -371,6 +372,7 @@
<include name="org/eclipse/persistence/testing/jaxb/JAXBTestSuite2.java"/>
<include name="org/eclipse/persistence/testing/jaxb/JAXBTestSuite3.java"/>
<include name="org/eclipse/persistence/testing/jaxb/JAXBTestSuite4.java"/>
+ <!--<include name="org/eclipse/persistence/testing/jaxb/JAXBPerformanceTestSuite.java"/>-->
<include name="org/eclipse/persistence/testing/jaxb/listofobjects/JAXBListOfObjectsSuite.java"/>
<include name="org/eclipse/persistence/testing/jaxb/annotations/AnnotationsTestSuite.java"/>
<include name="org/eclipse/persistence/testing/jaxb/externalizedmetadata/ExternalizedMetadataTestSuite.java"/>
diff --git a/moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/casesensitivity/customer.xml b/moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/casesensitivity/customer.xml
new file mode 100644
index 0000000..bd28a25
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/casesensitivity/customer.xml
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<customerImpl age="24" id="1234007">
+ <personalName>cafeBabe</personalName>
+ <persoNalNaMe>collisionBabe</persoNalNaMe> <!-- collision -->
+</customerImpl> \ No newline at end of file
diff --git a/moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/casesensitivity/loremIpsum.xml b/moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/casesensitivity/loremIpsum.xml
new file mode 100644
index 0000000..034ba57
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/resource/org/eclipse/persistence/testing/jaxb/casesensitivity/loremIpsum.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<loremIpsum Lorem="101" ipsum="102" dolor="103" sit="104" amet="105">
+
+ <!-- element integers -->
+ <consectetur>201</consectetur>
+ <adipiscing>202</adipiscing>
+ <elit>203</elit>
+ <Phasellus>204</Phasellus>
+ <condimentum>206</condimentum>
+ <tellus>207</tellus>
+ <tincidunt>208</tincidunt>
+ <magna>209</magna>
+ <Fusce>210</Fusce>
+ <cursus>211</cursus>
+
+ <!-- element Strings -->
+ <diam>301</diam>
+ <id>302</id>
+ <pulvinar>303</pulvinar>
+ <Mauris>304</Mauris>
+ <iaculis>305</iaculis>
+
+</loremIpsum>
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBPerformanceTestSuite.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBPerformanceTestSuite.java
new file mode 100644
index 0000000..4681a84
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBPerformanceTestSuite.java
@@ -0,0 +1,36 @@
+/*******************************************************************************
+ * Copyright (c) 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.
+ *
+ * Contributors:
+ * Marcel Valovy - 2.6.0 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.persistence.testing.jaxb.casesensitivity.JAXBCaseInsensitivityPerfTestCase;
+
+public class JAXBPerformanceTestSuite extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite("JAXB20 Performance Test Suite");
+
+ suite.addTestSuite(JAXBCaseInsensitivityPerfTestCase.class);
+
+ return suite;
+
+ }
+
+ public static void main(String[] args) {
+ String[] arguments = {"-c", "org.eclipse.persistence.testing.jaxb.JAXBPerformanceTestSuite"};
+ junit.textui.TestRunner.main(arguments);
+ }
+
+} \ No newline at end of file
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite4.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite4.java
index 2c8b3b6..8d1664c 100644
--- a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite4.java
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/JAXBTestSuite4.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 1998, 2012 Oracle and/or its affiliates. All rights reserved.
+ * 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.
@@ -12,6 +12,7 @@
******************************************************************************/
package org.eclipse.persistence.testing.jaxb;
+import org.eclipse.persistence.testing.jaxb.casesensitivity.JAXBCaseInsensitivityTestCase;
import org.eclipse.persistence.testing.jaxb.collections.CollectionsTestSuite;
import org.eclipse.persistence.testing.jaxb.defaultvalue.DefaultValueTestSuite;
import org.eclipse.persistence.testing.jaxb.employee.JAXBEmployeeNSTestCases;
@@ -81,6 +82,8 @@ public class JAXBTestSuite4 {
suite.addTestSuite(TypeAttributeInheritanceTestCases.class);
suite.addTestSuite(OtherRootTestCases.class);
suite.addTest(TypeVariableTestSuite.suite());
+
+ suite.addTestSuite(JAXBCaseInsensitivityTestCase.class);
return suite;
}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/Customer.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/Customer.java
new file mode 100644
index 0000000..e950eb8
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/Customer.java
@@ -0,0 +1,84 @@
+/*******************************************************************************
+ * Copyright (c) 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.
+ *
+ * Contributors:
+ * Marcel Valovy - 2.6.0 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.casesensitivity;
+
+import javax.xml.bind.annotation.XmlTransient;
+
+/**
+ * This class serves as a bridge between {@link org.eclipse.persistence.testing.jaxb.casesensitivity.correctCase.CustomerImpl}
+ * and {@link org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl}.
+ * <p>Provides uniform bridged <i>equals()<i/> and <i>hashCode()<i/> methods.</p>
+ *
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ */
+@XmlTransient
+public abstract class Customer {
+
+ /**
+ * Getter for customer's id.
+ * A part of bridge allowing to compare camel case implementation and upper case implementation of Customer.
+ *
+ * @return id
+ */
+ public abstract int getIdBridge();
+
+ /**
+ * Getter for customer's age.
+ * A part of bridge allowing to compare camel case implementation and upper case implementation of Customer.
+ *
+ * @return id
+ */
+ public abstract int getAgeBridge();
+
+ /**
+ * Getter for customer's name.
+ * A part of bridge allowing to compare camel case implementation and upper case implementation of Customer.
+ *
+ * @return id
+ */
+ public abstract String getNameBridge();
+
+ /**
+ * Bridge for {@link org.eclipse.persistence.testing.jaxb.casesensitivity.correctCase.CustomerImpl#equals(Object)} and
+ * {@link org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl#equals(Object)}
+ *
+ * @param o CustomerImpl object.
+ * @return true if the CustomerImpl classes' attributes match the same values.
+ */
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || this.getClass().getSuperclass() != o.getClass().getSuperclass()) return false;
+
+ Customer customer = (Customer) o;
+
+ if (getIdBridge() != customer.getIdBridge()) return false;
+ if (getAgeBridge() != customer.getAgeBridge()) return false;
+ if (getNameBridge() != null ? !getNameBridge().equals(customer.getNameBridge()) : customer.getNameBridge() != null)
+ return false;
+
+ return true;
+ }
+
+ /**
+ * Bridge for {@link org.eclipse.persistence.testing.jaxb.casesensitivity.correctCase.CustomerImpl#hashCode()} and
+ * {@link org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl#hashCode()}
+ *
+ * @return hashCode
+ */
+ public int hashCode() {
+ int result = getNameBridge() != null ? getNameBridge().hashCode() : 0;
+ result = 31 * result + getAgeBridge();
+ result = 31 * result + getIdBridge();
+ return result;
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityPerfTestCase.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityPerfTestCase.java
new file mode 100644
index 0000000..eb866bf
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityPerfTestCase.java
@@ -0,0 +1,111 @@
+/*******************************************************************************
+ * Copyright (c) 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.
+ *
+ * Contributors:
+ * Marcel Valovy - 2.6.0 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.casesensitivity;
+
+import org.eclipse.persistence.jaxb.JAXBContextFactory;
+import org.eclipse.persistence.jaxb.JAXBContextProperties;
+import org.eclipse.persistence.jaxb.UnmarshallerProperties;
+import org.eclipse.persistence.testing.jaxb.casesensitivity.correctCase.LoremIpsum;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Performance test case which compares case sensitive unmarshalling against case insensitive unmarshalling.
+ *
+ * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=331241">EclipseLink Forum, Bug 331241.</a>
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ */
+public class JAXBCaseInsensitivityPerfTestCase extends junit.framework.TestCase {
+
+ private static final File FILE = new File("org/eclipse/persistence/testing/jaxb/casesensitivity/loremIpsum.xml");
+
+ private static final int WARM_UP = 10000;
+ private static final int LAPS = 100000;
+
+ private Unmarshaller unmOtherCaseInsensitive;
+ private Unmarshaller unmCorrectCaseSensitive;
+
+ @Test
+ public void testMain() throws Exception {
+
+ ci: {
+ // Warm up the code
+ for (int i = 0; i < WARM_UP; ++i)
+ unmarshalOtherCaseInsensitive();
+
+ // Time it
+ final long start = System.nanoTime();
+ for(int i=0; i < LAPS; i++)
+ unmarshalOtherCaseInsensitive();
+ final long elapsed = System.nanoTime() - start;
+ System.out.println("Case insensitive: \n\t" + LAPS+" iterations took " + TimeUnit.NANOSECONDS.toMillis(elapsed) + "ms.");
+ }
+
+ cs: {
+ // Warm up the code
+ for (int i = 0; i < WARM_UP; ++i)
+ unmarshalCorrectCaseSensitive();
+
+ // Time it
+ final long start = System.nanoTime();
+ for(int i=0; i < LAPS; i++)
+ unmarshalCorrectCaseSensitive();
+ final long elapsed = System.nanoTime() - start;
+ System.out.println("Case sensitive: \n\t" + LAPS+" iterations took " + TimeUnit.NANOSECONDS.toMillis(elapsed) + "ms.");
+ }
+
+ }
+
+ private LoremIpsum unmarshalCorrectCaseSensitive() throws JAXBException {
+
+ LoremIpsum loremCorrectCase
+ = (LoremIpsum) unmCorrectCaseSensitive.unmarshal(FILE);
+
+ return loremCorrectCase;
+ }
+
+ private org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.LoremIpsum unmarshalOtherCaseInsensitive() throws JAXBException {
+
+ org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.LoremIpsum loremOtherCase
+ = (org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.LoremIpsum) unmOtherCaseInsensitive.unmarshal(FILE);
+
+ return loremOtherCase;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+
+ /* Create and assign case-sensitive unmarshaller */
+ JAXBContext ctxCorrectCaseSensitive = JAXBContextFactory.createContext(new Class[]{LoremIpsum.class}, null);
+ unmCorrectCaseSensitive = ctxCorrectCaseSensitive.createUnmarshaller();
+
+ /* Create and assign case-insensitive unmarshaller */
+ JAXBContext ctxOtherCaseInsensitive = JAXBContextFactory.createContext(new Class[]{ org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.LoremIpsum.class}, null);
+ unmOtherCaseInsensitive = ctxOtherCaseInsensitive.createUnmarshaller();
+ unmOtherCaseInsensitive.setProperty(UnmarshallerProperties.UNMARSHALLING_CASE_INSENSITIVE, Boolean.TRUE);
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ unmCorrectCaseSensitive = unmOtherCaseInsensitive = null;
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityTestCase.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityTestCase.java
new file mode 100644
index 0000000..eda968e
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/JAXBCaseInsensitivityTestCase.java
@@ -0,0 +1,134 @@
+/*******************************************************************************
+ * Copyright (c) 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.
+ *
+ * Contributors:
+ * Marcel Valovy - 2.6.0 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.casesensitivity;
+
+import org.eclipse.persistence.jaxb.JAXBContextFactory;
+import org.eclipse.persistence.jaxb.JAXBContextProperties;
+import org.eclipse.persistence.jaxb.UnmarshallerProperties;
+import org.eclipse.persistence.testing.jaxb.casesensitivity.correctCase.CustomerImpl;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * Tests the functionality correctness of the case insensitive unmarshalling feature.
+ *
+ * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=331241">EclipseLink Forum, Bug 331241.</a>
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ */
+public class JAXBCaseInsensitivityTestCase extends junit.framework.TestCase {
+
+ private static final File FILE = new File("org/eclipse/persistence/testing/jaxb/casesensitivity/customer.xml");
+ private static final Class[] CAMEL_CASE_CUSTOMER = new Class[]{CustomerImpl.class};
+ private static final Class[] UPPER_CASE_CUSTOMER = new Class[]{org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl.class};
+ private static final boolean DEBUG = false;
+
+ private CustomerImpl baseCustomer;
+ private Unmarshaller unmarshallerCorrectCaseInsensitive;
+ private Unmarshaller unmarshallerOtherCaseInsensitive;
+ private Unmarshaller unmarshallerCorrectCaseSensitive;
+ private Unmarshaller unmarshallerOtherCaseSensitive;
+
+ @Test
+ public void testMain() throws Exception {
+
+ if (DEBUG) System.out.println("Case-insensitive unmarshalling test.");
+ assertTrue(unmarshalOtherCaseInsensitive().equals(baseCustomer));
+ CustomerImpl ciCorrect = unmarshalCorrectCaseInsensitive();
+ assertTrue(ciCorrect.equals(baseCustomer));
+ assertTrue(null == ciCorrect.getPersonalName());
+ if (DEBUG) System.out.println("Collision handled correctly.");
+
+
+ if (DEBUG) System.out.println("Case-sensitive unmarshalling test.");
+ assertFalse(unmarshalOtherCaseSensitive().equals(baseCustomer));
+ assertTrue(unmarshalCorrectCaseSensitive().equals(baseCustomer));
+ }
+
+ /* Case-insensitive part */
+ private CustomerImpl unmarshalCorrectCaseInsensitive() throws JAXBException {
+
+ CustomerImpl correctCaseCustomer = (CustomerImpl) unmarshallerCorrectCaseInsensitive.unmarshal(FILE);
+ if (DEBUG) System.out.println(correctCaseCustomer);
+
+ return correctCaseCustomer;
+ }
+
+ private org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl unmarshalOtherCaseInsensitive() throws JAXBException {
+
+ org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl otherCaseCustomer
+ = (org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl) unmarshallerOtherCaseInsensitive.unmarshal(FILE);
+ if (DEBUG) System.out.println(otherCaseCustomer);
+
+ return otherCaseCustomer;
+ }
+
+ /* Case-sensitive part */
+ private CustomerImpl unmarshalCorrectCaseSensitive() throws JAXBException {
+
+ CustomerImpl correctCaseCustomer = (CustomerImpl) unmarshallerCorrectCaseSensitive.unmarshal(FILE);
+ if (DEBUG) System.out.println(correctCaseCustomer);
+
+ return correctCaseCustomer;
+ }
+
+ private org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl unmarshalOtherCaseSensitive() throws JAXBException {
+
+ org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl otherCaseCustomer
+ = (org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase.CustomerImpl) unmarshallerOtherCaseSensitive.unmarshal(FILE);
+ if (DEBUG) System.out.println(otherCaseCustomer);
+
+ return otherCaseCustomer;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ baseCustomer = new CustomerImpl();
+ baseCustomer.setId(1234007);
+ baseCustomer.setAge(24);
+ baseCustomer.setPersoNalNaMe("collisionBabe");
+ baseCustomer.setPersonalName("cafeBabe");
+
+ /* Create and assign case-insensitive unmarshallers */
+ Map<String, Boolean> properties = new HashMap<String, Boolean>();
+ properties.put(JAXBContextProperties.UNMARSHALLING_CASE_INSENSITIVE, Boolean.TRUE);
+ JAXBContext ctxCorrectCaseInsensitive = JAXBContextFactory.createContext(CAMEL_CASE_CUSTOMER, properties);
+ JAXBContext ctxOtherCaseInsensitive = JAXBContextFactory.createContext(UPPER_CASE_CUSTOMER, null); /* we set CI by setProperty() */
+
+ unmarshallerCorrectCaseInsensitive = ctxCorrectCaseInsensitive.createUnmarshaller();
+ unmarshallerOtherCaseInsensitive = ctxOtherCaseInsensitive.createUnmarshaller();
+ unmarshallerOtherCaseInsensitive.setProperty(UnmarshallerProperties.UNMARSHALLING_CASE_INSENSITIVE, Boolean.TRUE);
+
+ /* Create and assign case-sensitive unmarshallers */
+ properties.put(JAXBContextProperties.UNMARSHALLING_CASE_INSENSITIVE, Boolean.FALSE);
+ JAXBContext ctxCorrectCaseSensitive = JAXBContextFactory.createContext(CAMEL_CASE_CUSTOMER, properties);
+
+ /* Test that the property can be turned off by using case insensitive context and altering its property */
+ unmarshallerOtherCaseSensitive = ctxOtherCaseInsensitive.createUnmarshaller();
+ unmarshallerOtherCaseSensitive.setProperty(UnmarshallerProperties.UNMARSHALLING_CASE_INSENSITIVE, Boolean.FALSE);
+ unmarshallerCorrectCaseSensitive = ctxCorrectCaseSensitive.createUnmarshaller();
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ baseCustomer = null;
+ unmarshallerCorrectCaseInsensitive = unmarshallerOtherCaseInsensitive = unmarshallerCorrectCaseSensitive = unmarshallerOtherCaseSensitive = null;
+ }
+}
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/correctCase/CustomerImpl.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/correctCase/CustomerImpl.java
new file mode 100644
index 0000000..6fb7a63
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/correctCase/CustomerImpl.java
@@ -0,0 +1,93 @@
+/*******************************************************************************
+ * Copyright (c) 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.
+ *
+ * Contributors:
+ * Marcel Valovy - 2.6.0 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.casesensitivity.correctCase;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Implementation of Customer with XML Elements and Attributes with the same case as in the xml resource.
+ *
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ */
+@XmlRootElement
+public class CustomerImpl extends org.eclipse.persistence.testing.jaxb.casesensitivity.Customer {
+
+ private int id;
+ private int age;
+ private String personalName;
+ private String persoNalNaMe; /* collision - this one prevails */
+
+ public int getId() {
+ return id;
+ }
+
+ @XmlAttribute
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ @XmlAttribute
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public String getPersonalName() {
+ return personalName;
+ }
+
+ @XmlElement
+ public void setPersonalName(String personalName) {
+ this.personalName = personalName;
+ }
+
+ public String getPersoNalNaMe() {
+ return persoNalNaMe;
+ }
+
+ @XmlElement
+ public void setPersoNalNaMe(String persoNalNaMe) {
+ this.persoNalNaMe = persoNalNaMe;
+ }
+
+ @Override
+ public String toString() {
+ return "CustomerImpl_correctCase{" +
+ "id=" + id +
+ ", age=" + age +
+ ", persoNalNAMe='" + persoNalNaMe + '\'' +
+ ", personalName='" + personalName + '\'' +
+ '}';
+ }
+
+ @Override
+ public int getIdBridge() {
+ return id;
+ }
+
+ @Override
+ public int getAgeBridge() {
+ return age;
+ }
+
+ @Override
+ public String getNameBridge() {
+ return persoNalNaMe;
+ }
+
+} \ No newline at end of file
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/correctCase/LoremIpsum.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/correctCase/LoremIpsum.java
new file mode 100644
index 0000000..3c894fd
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/correctCase/LoremIpsum.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 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.
+ *
+ * Contributors:
+ * Marcel Valovy - 2.6.0 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.casesensitivity.correctCase;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Dummy class for performance testing, in case corresponding with the xml resource.
+ *
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class LoremIpsum {
+
+ // same cases as the xml - use with Sensitive
+ @XmlAttribute
+ private int Lorem, ipsum, dolor, sit, amet;
+
+ @XmlElement
+ private int consectetur, adipiscing, elit, Phasellus,
+ condimentum, tellus, tincidunt, magna, Fusce, cursus;
+
+ @XmlElement
+ private String diam, id, pulvinar, Mauris, iaculis;
+
+} \ No newline at end of file
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/otherCase/CustomerImpl.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/otherCase/CustomerImpl.java
new file mode 100644
index 0000000..7f956f0
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/otherCase/CustomerImpl.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * Copyright (c) 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.
+ *
+ * Contributors:
+ * Marcel Valovy - 2.6.0 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Implementation of Customer with XML Elements and Attributes in case differing from that in the xml resource.
+ *
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ */
+@XmlRootElement
+public class CustomerImpl extends org.eclipse.persistence.testing.jaxb.casesensitivity.Customer {
+
+ private int ID;
+ private int age;
+ private String personalNAME;
+ private String persoNalNaMe; /* collision - this one prevails */
+
+ public int getID() {
+ return ID;
+ }
+
+ @XmlAttribute
+ public void setID(int ID) {
+ this.ID = ID;
+ }
+
+ public int getAge() {
+ return age;
+ }
+
+ /* Attribute left Camel Case on purpose, to provide safe-point during debugging. */
+ @XmlAttribute
+ public void setAge(int age) {
+ this.age = age;
+ }
+
+ public String getPersonalNAME() {
+ return personalNAME;
+ }
+
+ @XmlElement
+ public void setPersonalNAME(String personalNAME) {
+ this.personalNAME = personalNAME;
+ }
+
+ public String getPersoNalNaMe() {
+ return persoNalNaMe;
+ }
+
+ @XmlElement
+ public void setPersoNalNaMe(String persoNalNaMe) {
+ this.persoNalNaMe = persoNalNaMe;
+ }
+
+ @Override
+ public String toString() {
+ return "CustomerImpl_otherCase{" +
+ "ID=" + ID +
+ ", age=" + age +
+ ", persoNalNaMe='" + persoNalNaMe + '\'' +
+ ", personalNAME='" + personalNAME + '\'' +
+ '}';
+ }
+
+ @Override
+ public int getIdBridge() {
+ return ID;
+ }
+
+ @Override
+ public int getAgeBridge() {
+ return age;
+ }
+
+ @Override
+ public String getNameBridge() {
+ return persoNalNaMe;
+ }
+
+} \ No newline at end of file
diff --git a/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/otherCase/LoremIpsum.java b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/otherCase/LoremIpsum.java
new file mode 100644
index 0000000..e5c4087
--- /dev/null
+++ b/moxy/eclipselink.moxy.test/src/org/eclipse/persistence/testing/jaxb/casesensitivity/otherCase/LoremIpsum.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 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.
+ *
+ * Contributors:
+ * Marcel Valovy - 2.6.0 - initial implementation
+ ******************************************************************************/
+package org.eclipse.persistence.testing.jaxb.casesensitivity.otherCase;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+
+/**
+ * Dummy class for performance testing with case differing from the xml resource.
+ *
+ * @author Marcel Valovy - marcel.valovy@oracle.com
+ */
+@XmlRootElement
+@XmlAccessorType(XmlAccessType.FIELD)
+public class LoremIpsum {
+
+ // different cases than the xml - use with Insensitive
+ @XmlAttribute
+ private int LorEm, ipsUm, DoLor, sIT, AMet;
+ @XmlElement
+ private int conSectetuR, aDiPiscinG, eLIt, PhasEllus,
+ conDimentuM, tElLus, tINciDUnt, magNa, Fusce, cursus;
+
+ @XmlElement
+ private String Diam, iD, pUlVinar, mauRIs, iacuLis;
+
+} \ No newline at end of file
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 6baa12e..db64504 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
@@ -1,17 +1,18 @@
-/*******************************************************************************
- * 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.
- *
- * Contributors:
- * Oracle - initial API and implementation from Oracle TopLink
- ******************************************************************************/
-package org.eclipse.persistence.jaxb;
-
+ *
+ * Contributors:
+ * Oracle - initial API and implementation from Oracle TopLink
+ * Marcel Valovy - 2.6.0 - added case insensitive unmarshalling property
+ ******************************************************************************/
+package org.eclipse.persistence.jaxb;
+
import static org.eclipse.persistence.jaxb.javamodel.Helper.getQualifiedJavaTypeName;
import java.awt.Image;
@@ -1563,12 +1564,13 @@ public class JAXBContext extends javax.xml.bind.JAXBContext {
setPropertyOnUnmarshaller(JAXBContextProperties.NAMESPACE_PREFIX_MAPPER, unmarshaller);
setPropertyOnUnmarshaller(JAXBContextProperties.JSON_INCLUDE_ROOT, unmarshaller);
setPropertyOnUnmarshaller(JAXBContextProperties.JSON_VALUE_WRAPPER, unmarshaller);
- setPropertyOnUnmarshaller(JAXBContextProperties.JSON_NAMESPACE_SEPARATOR, unmarshaller);
- setPropertyOnUnmarshaller(JAXBContextProperties.OBJECT_GRAPH, unmarshaller);
- setPropertyOnUnmarshaller(JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME, unmarshaller);
- }
- return unmarshaller;
- }
+ setPropertyOnUnmarshaller(JAXBContextProperties.JSON_NAMESPACE_SEPARATOR, unmarshaller);
+ setPropertyOnUnmarshaller(JAXBContextProperties.OBJECT_GRAPH, unmarshaller);
+ setPropertyOnUnmarshaller(JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME, unmarshaller);
+ setPropertyOnUnmarshaller(JAXBContextProperties.UNMARSHALLING_CASE_INSENSITIVE, unmarshaller);
+ }
+ return unmarshaller;
+ }
public JAXBBinder createBinder(JAXBContext context) {
XMLMarshaller marshaller = null;
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContextProperties.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContextProperties.java
index 7265fea..870e19a 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContextProperties.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBContextProperties.java
@@ -1,17 +1,18 @@
-/*******************************************************************************
- * Copyright (c) 2012, 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) 2012, 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.
- *
- * Contributors:
- * Blaise Doughan - 2.4.0 - initial implementation
- ******************************************************************************/
-package org.eclipse.persistence.jaxb;
-
+ *
+ * Contributors:
+ * Blaise Doughan - 2.4.0 - initial implementation
+ * Marcel Valovy - 2.6.0 - added case insensitive unmarshalling property
+ ******************************************************************************/
+package org.eclipse.persistence.jaxb;
+
/**
* These are properties that may be passed in to create a JAXBContext:
* <pre>
@@ -220,7 +221,42 @@ public class JAXBContextProperties {
* @since 2.4.2
* @see org.eclipse.persistence.jaxb.MarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME
* @see org.eclipse.persistence.jaxb.UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME
- */
- public static final String JSON_WRAPPER_AS_ARRAY_NAME = "eclipselink.json.wrapper-as-array-name";
-
+ */
+ public static final String JSON_WRAPPER_AS_ARRAY_NAME = "eclipselink.json.wrapper-as-array-name";
+
+ /**
+ * If set to <i>Boolean.TRUE</i>, {@link org.eclipse.persistence.jaxb.JAXBUnmarshaller} will match
+ * XML Elements and XML Attributes to Java fields case insensitively.
+ *
+ * <p><b>Example</b></p>
+ * <p>Given the following class:</p>
+ * <pre>
+ * &#64;XmlAccessorType(XmlAccessType.FIELD)
+ * public class Customer {
+ *
+ * &#64;XmlElement
+ * private String name;
+ * &#64;XmlAttribute
+ * private int id;
+ *
+ * }
+ * </pre>
+ * <p>If the property is set to true, the following XML object will match the class and will be unmarshaled.</p>
+ * <pre>
+ * &lt;customer iD="007"&gt;
+ * &lt;nAMe&gt;cafeBabe&lt;/nAMe&gt;
+ * &lt;/customer&gt;
+ * </pre>
+ *
+ * <p><b>By default, case-insensitive unmarshalling is turned off.</b><p/>
+ *
+ * <p>The property must be passed to the {@link org.eclipse.persistence.jaxb.JAXBContextFactory}, when creating
+ * {@link org.eclipse.persistence.jaxb.JAXBContext}. It will affect only unmarshaller created from that context.</p>
+ *
+ * @since 2.6.0
+ * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=331241">EclipseLink Forum, Bug 331241.</a>
+ * @see org.eclipse.persistence.jaxb.UnmarshallerProperties#UNMARSHALLING_CASE_INSENSITIVE
+ */
+ public static final String UNMARSHALLING_CASE_INSENSITIVE = "eclipselink.unmarshalling.case-insensitive";
+
} \ No newline at end of file
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBUnmarshaller.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBUnmarshaller.java
index 09705a2..c270b3b 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBUnmarshaller.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/JAXBUnmarshaller.java
@@ -1,17 +1,18 @@
-/*******************************************************************************
- * 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.
- *
- * Contributors:
- * Oracle - initial API and implementation from Oracle TopLink
- ******************************************************************************/
-package org.eclipse.persistence.jaxb;
-
+ *
+ * Contributors:
+ * Oracle - initial API and implementation from Oracle TopLink
+ * Marcel Valovy - 2.6.0 - added case insensitive unmarshalling property
+ ******************************************************************************/
+package org.eclipse.persistence.jaxb;
+
import java.io.File;
import java.io.InputStream;
import java.io.Reader;
@@ -750,13 +751,18 @@ public class JAXBUnmarshaller implements Unmarshaller {
} else if(value instanceof String) {
mType = MediaType.getMediaType((String)value);
}
- if(mType == null){
- throw new PropertyException(key, Constants.EMPTY_STRING);
- }
- xmlUnmarshaller.setMediaType(mType);
- } else if (key.equals(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE)){
- if(value == null){
- throw new PropertyException(key, Constants.EMPTY_STRING);
+ if(mType == null){
+ throw new PropertyException(key, Constants.EMPTY_STRING);
+ }
+ xmlUnmarshaller.setMediaType(mType);
+ } else if (key.equals(UnmarshallerProperties.UNMARSHALLING_CASE_INSENSITIVE)){
+ if(value == null){
+ throw new PropertyException(key, Constants.EMPTY_STRING);
+ }
+ xmlUnmarshaller.setCaseInsensitive((Boolean)value);
+ } else if (key.equals(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE)){
+ if(value == null){
+ throw new PropertyException(key, Constants.EMPTY_STRING);
}
xmlUnmarshaller.setAutoDetectMediaType((Boolean)value);
} else if (key.equals(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX)){
@@ -822,12 +828,14 @@ public class JAXBUnmarshaller implements Unmarshaller {
throw new IllegalArgumentException();
}
if (key.equals(UnmarshallerProperties.MEDIA_TYPE)) {
- return xmlUnmarshaller.getMediaType();
- } else if (key.equals(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE)) {
- return xmlUnmarshaller.isAutoDetectMediaType();
- } else if (key.equals(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX)) {
- return xmlUnmarshaller.getAttributePrefix();
- } else if (key.equals(UnmarshallerProperties.JSON_INCLUDE_ROOT)) {
+ return xmlUnmarshaller.getMediaType();
+ } else if (key.equals(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE)) {
+ return xmlUnmarshaller.isAutoDetectMediaType();
+ } else if (key.equals(UnmarshallerProperties.UNMARSHALLING_CASE_INSENSITIVE)) {
+ return xmlUnmarshaller.isCaseInsensitive();
+ } else if (key.equals(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX)) {
+ return xmlUnmarshaller.getAttributePrefix();
+ } else if (key.equals(UnmarshallerProperties.JSON_INCLUDE_ROOT)) {
return xmlUnmarshaller.isIncludeRoot();
} else if (key.equals(UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR)) {
return xmlUnmarshaller.getNamespaceSeparator();
diff --git a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/UnmarshallerProperties.java b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/UnmarshallerProperties.java
index 833050d..1acd726 100644
--- a/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/UnmarshallerProperties.java
+++ b/moxy/org.eclipse.persistence.moxy/src/org/eclipse/persistence/jaxb/UnmarshallerProperties.java
@@ -1,17 +1,18 @@
-/*******************************************************************************
- * Copyright (c) 2012, 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) 2012, 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.
- *
- * Contributors:
- * Blaise Doughan - 2.3.3 - initial implementation
- ******************************************************************************/
-package org.eclipse.persistence.jaxb;
-
+ *
+ * Contributors:
+ * Blaise Doughan - 2.3.3 - initial implementation
+ * Marcel Valovy - 2.6.0 - added case insensitive unmarshalling property
+ ******************************************************************************/
+package org.eclipse.persistence.jaxb;
+
/**
* These are properties that may be set on an instance of Unmarshaller. Below
* is an example of using the property mechanism to enable MOXy's JSON binding
@@ -166,7 +167,42 @@ public class UnmarshallerProperties {
* @since 2.4.2
* @see org.eclipse.persistence.jaxb.JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME
* @see org.eclipse.persistence.jaxb.MarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME
- */
- public static final String JSON_WRAPPER_AS_ARRAY_NAME = JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME;
-
+ */
+ public static final String JSON_WRAPPER_AS_ARRAY_NAME = JAXBContextProperties.JSON_WRAPPER_AS_ARRAY_NAME;
+
+ /**
+ * If set to <i>Boolean.TRUE</i>, {@link org.eclipse.persistence.jaxb.JAXBUnmarshaller} will match
+ * XML Elements and XML Attributes to Java fields case insensitively.
+ *
+ * <p><b>Example</b></p>
+ * <p>Given the following class:</p>
+ * <pre>
+ * &#64;XmlAccessorType(XmlAccessType.FIELD)
+ * public class Customer {
+ *
+ * &#64;XmlElement
+ * private String name;
+ * &#64;XmlAttribute
+ * private int id;
+ *
+ * }
+ * </pre>
+ * <p>If the property is set to true, the following XML object will match the class and will be unmarshaled.</p>
+ * <pre>
+ * &lt;customer iD="007"&gt;
+ * &lt;nAMe&gt;cafeBabe&lt;/nAMe&gt;
+ * &lt;/customer&gt;
+ * </pre>
+ *
+ * <p><b>By default, case-insensitive unmarshalling is turned off.</b><p/>
+ *
+ * <p>The property can be set through {@link org.eclipse.persistence.jaxb.JAXBUnmarshaller#setProperty(String, Object)}.</p>
+ *
+ * @since 2.6.0
+ *
+ * @see <a href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=331241">EclipseLink Forum, Bug 331241.</a>
+ * @see org.eclipse.persistence.jaxb.JAXBContextProperties#UNMARSHALLING_CASE_INSENSITIVE
+ */
+ public static final String UNMARSHALLING_CASE_INSENSITIVE = "eclipselink.unmarshalling.case-insensitive";
+
} \ No newline at end of file