Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 538228 - @XmpPaths + @XmlIDREF + @XmlElements fail due to bad analyze of referenced types #235

Merged
merged 1 commit into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ public boolean marshalSingleValue(XPathFragment xPathFragment, MarshalRecord mar
QName schemaType = xmlField.getSchemaTypeForValue(fieldValue, session);
XPathFragment groupingFragment = marshalRecord.openStartGroupingElements(namespaceResolver);

if (xPathFragment.isAttribute()) {
if (xPathFragment != null && xPathFragment.isAttribute()) {
marshalRecord.attribute(xPathFragment, namespaceResolver, fieldValue, schemaType);
marshalRecord.closeStartGroupingElements(groupingFragment);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public void buildReference(Object srcObject, XMLField xmlField, Object object, A
}
} else {
XMLField tgtFld = (XMLField) getSourceToTargetKeyFieldAssociations().get(xmlField);
String tgtXPath = tgtFld.getXPath();
String tgtXPath = tgtFld.getQualifiedName();
HashMap primaryKeyMap = reference.getPrimaryKeyMap();
CacheId pks = (CacheId) primaryKeyMap.get(tgtXPath);
ClassDescriptor descriptor = session.getClassDescriptor(referenceClass);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"RootNode": {
"id": "1",
"name": "rootNode1",
"refNodes": {
"ComplexNodeID": [
"10"
],
"LeafNodeID": [
"20"
]
},
"ownedNodes": {
"ComplexNode": [
{
"id": "10",
"name": "complexNode10",
"refNodes": {
"ComplexNodeID": [
"10"
],
"LeafNodeID": [
"20"
]
},
"ownedNodes": {
"ComplexNode": []
}
}
],
"LeafNode": [
{
"id": "20",
"name": "leafNode10",
"isValid": false,
"refNodes": {
"ComplexNodeID": [
"10"
],
"LeafNodeID": [
"20"
]
},
"LNComplexNodeID": "10"
}
]
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!--

Copyright (c) 2018 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 v. 2.0 which is available at
http://www.eclipse.org/legal/epl-2.0,
or the Eclipse Distribution License v. 1.0 which is available at
http://www.eclipse.org/org/documents/edl-v10.php.

SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause

-->

<RootNode id="1" name="rootNode1">
<refNodes>
<ComplexNodeID>10</ComplexNodeID>
<LeafNodeID>20</LeafNodeID>
</refNodes>
<ownedNodes>
<ComplexNode id="10" name="complexNode10">
<refNodes>
<ComplexNodeID>10</ComplexNodeID>
<LeafNodeID>20</LeafNodeID>
</refNodes>
<ownedNodes/>
</ComplexNode>
<LeafNode id="20" name="leafNode10" isValid="false">
<refNodes>
<ComplexNodeID>10</ComplexNodeID>
<LeafNodeID>20</LeafNodeID>
</refNodes>
<LNComplexNodeID>10</LNComplexNodeID>
</LeafNode>
</ownedNodes>
</RootNode>
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.persistence.testing.jaxb.annotations.xmlelementnillable.XmlElementNillableTypeLevelTestCases;
import org.eclipse.persistence.testing.jaxb.annotations.xmlidref.XmlIdRefMissingIdEventHandlerTestCases;
import org.eclipse.persistence.testing.jaxb.annotations.xmlidref.XmlIdRefMissingIdTestCases;
import org.eclipse.persistence.testing.jaxb.annotations.xmlidref.inheritance.XmlIdRefInheritanceTestCases;
import org.eclipse.persistence.testing.jaxb.annotations.xmlidref.self.XmlIdRefSelfTestCases;
import org.eclipse.persistence.testing.jaxb.annotations.xmlinlinebinarydata.InlineHexBinaryTestCases;
import org.eclipse.persistence.testing.jaxb.annotations.xmlinversereference.InverseRefChoiceAdapterTestCases;
Expand Down Expand Up @@ -114,6 +115,7 @@ public static Test suite() {
suite.addTestSuite(XmlIdRefMissingIdTestCases.class);
suite.addTestSuite(XmlIdRefMissingIdEventHandlerTestCases.class);
suite.addTestSuite(XmlIdRefSelfTestCases.class);
suite.addTestSuite(XmlIdRefInheritanceTestCases.class);
suite.addTest(org.eclipse.persistence.testing.jaxb.annotations.xmltransient.XmlTransientTestSuite.suite());
suite.addTestSuite(org.eclipse.persistence.testing.jaxb.annotations.xmlelementdecl.qualified.QualfiedTestCases.class);
suite.addTestSuite(org.eclipse.persistence.testing.jaxb.annotations.xmlelementdecl.noxmlrootelement.NoRootElementTestCases.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright (c) 2018 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 v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// Radek Felcman - 2.7.4 - initial implementation
package org.eclipse.persistence.testing.jaxb.annotations.xmlidref.inheritance;

import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@XmlRootElement(name="ComplexNode")
@XmlAccessorType(XmlAccessType.FIELD)
public class ComplexNode extends Node {

@XmlElementWrapper(name="ownedNodes")
@XmlElements({
@XmlElement(name="ComplexNode", type=ComplexNode.class),
@XmlElement(name="LeafNode", type=LeafNode.class),
})
private List<Node> ownedNodes = new ArrayList<Node>();


public List<Node> getOwnedNodes() {
return ownedNodes;
}

public void setOwnedNodes(List<Node> ownedNodes) {
this.ownedNodes = ownedNodes;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
ComplexNode that = (ComplexNode) o;
return Objects.equals(getId(), that.getId()) &&
Objects.equals(getOwnedNodes(), that.getOwnedNodes());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright (c) 2018 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 v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// Radek Felcman - 2.7.4 - initial implementation
package org.eclipse.persistence.testing.jaxb.annotations.xmlidref.inheritance;

import javax.xml.bind.annotation.*;
import java.util.Objects;

@XmlRootElement(name="LeafNode")
@XmlAccessorType(XmlAccessType.FIELD)
public class LeafNode extends Node {

@XmlAttribute
private boolean isValid;

@XmlIDREF
@XmlElements({
@XmlElement(name="LNComplexNodeID", type=ComplexNode.class),
@XmlElement(name="LNLeafNodeID", type=LeafNode.class),
})
private Node targetNode;

public boolean isValid() {
return isValid;
}

public void setValid(boolean valid) {
isValid = valid;
}

public Node getTargetNode() {
return targetNode;
}

public void setTargetNode(Node targetNode) {
this.targetNode = targetNode;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
LeafNode leafNode = (LeafNode) o;
return isValid() == leafNode.isValid() &&
Objects.equals(getId(), leafNode.getId()) &&
Objects.equals(getTargetNode(), leafNode.getTargetNode());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright (c) 2018 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 v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// Radek Felcman - 2.7.4 - initial implementation
package org.eclipse.persistence.testing.jaxb.annotations.xmlidref.inheritance;

import org.eclipse.persistence.oxm.annotations.XmlPath;
import org.eclipse.persistence.oxm.annotations.XmlPaths;

import javax.xml.bind.annotation.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

@XmlRootElement(name = "Node")
@XmlAccessorType(XmlAccessType.FIELD)
public abstract class Node {

@XmlID
@XmlAttribute(name = "id")
private String id;

@XmlAttribute
private String name;

@XmlIDREF
@XmlPaths({
@XmlPath("refNodes/ComplexNodeID/text()"),
@XmlPath("refNodes/LeafNodeID/text()"),
})
@XmlElements({
@XmlElement(name = "ComplexNodeID", type = ComplexNode.class),
@XmlElement(name = "LeafNodeID", type = LeafNode.class),
})
private List<Node> refNodes = new ArrayList<Node>();


public void setId(String id) {
this.id = id;
}

public String getId() {
return this.id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public List<Node> getRefNodes() {
return refNodes;
}

public void setRefNodes(List<Node> refNodes) {
this.refNodes = refNodes;
}


@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Node node = (Node) o;
if (getRefNodes() == null && node.getRefNodes() != null) return false;
if (node.getRefNodes() == null && getRefNodes() != null) return false;
if (getRefNodes() != null || node.getRefNodes() != null) {
if (getRefNodes().size() != node.getRefNodes().size()) return false;
Iterator<Node> iterator1 = getRefNodes().iterator();
Iterator<Node> iterator2 = node.getRefNodes().iterator();
//Compare just IDs to avoid circular references
while (iterator1.hasNext()) {
if (!iterator1.next().getId().equals(iterator2.next().getId())) return false;
}
}
return Objects.equals(getId(), node.getId()) &&
Objects.equals(getName(), node.getName());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2018 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 v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/

// Contributors:
// Radek Felcman - 2.7.4 - initial implementation
package org.eclipse.persistence.testing.jaxb.annotations.xmlidref.inheritance;

import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement(name="RootNode")
@XmlAccessorType(XmlAccessType.FIELD)
public class RootNode extends ComplexNode {
}