Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 1998, 2021 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:
// Oracle - initial API and implementation from Oracle TopLink
package org.eclipse.persistence.oxm.mappings;
import java.lang.reflect.Modifier;
import java.util.Enumeration;
import java.util.Vector;
import javax.xml.namespace.QName;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.exceptions.DatabaseException;
import org.eclipse.persistence.exceptions.DescriptorException;
import org.eclipse.persistence.exceptions.XMLMarshalException;
import org.eclipse.persistence.internal.helper.DatabaseField;
import org.eclipse.persistence.internal.identitymaps.CacheKey;
import org.eclipse.persistence.internal.oxm.ConversionManager;
import org.eclipse.persistence.internal.oxm.XMLObjectBuilder;
import org.eclipse.persistence.internal.oxm.XPathEngine;
import org.eclipse.persistence.internal.oxm.XPathFragment;
import org.eclipse.persistence.internal.oxm.XPathQName;
import org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping;
import org.eclipse.persistence.internal.oxm.mappings.Mapping;
import org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping;
import org.eclipse.persistence.internal.queries.ContainerPolicy;
import org.eclipse.persistence.internal.queries.JoinedAttributeManager;
import org.eclipse.persistence.internal.queries.MapContainerPolicy;
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.mappings.AttributeAccessor;
import org.eclipse.persistence.mappings.converters.Converter;
import org.eclipse.persistence.mappings.foundation.AbstractCompositeCollectionMapping;
import org.eclipse.persistence.oxm.XMLConstants;
import org.eclipse.persistence.oxm.XMLContext;
import org.eclipse.persistence.oxm.XMLDescriptor;
import org.eclipse.persistence.oxm.XMLField;
import org.eclipse.persistence.oxm.XMLMarshaller;
import org.eclipse.persistence.oxm.XMLUnmarshaller;
import org.eclipse.persistence.oxm.mappings.converters.XMLConverter;
import org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy;
import org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy;
import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType;
import org.eclipse.persistence.oxm.record.DOMRecord;
import org.eclipse.persistence.oxm.record.XMLRecord;
import org.eclipse.persistence.platform.xml.XMLPlatformFactory;
import org.eclipse.persistence.queries.ObjectBuildingQuery;
import org.eclipse.persistence.sessions.Session;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
*
Composite collection XML mappings map an attribute that contains a homogeneous collection of objects
* to multiple XML elements. Use composite collection XML mappings to represent one-to-many relationships.
* Composite collection XML mappings can reference any class that has a TopLink descriptor. The attribute in
* the object mapped must implement either the Java Collection interface (for example, Vector or HashSet)
* or Map interface (for example, Hashtable or TreeMap). The CompositeCollectionMapping class
* allows a reference to the mapped class and the indexing type for that class. This mapping is, by
* definition, privately owned.
*
*
Setting the XPath: TopLink XML mappings make use of XPath statements to find the relevant
* data in an XML document. The XPath statement is relative to the context node specified in the descriptor.
* The XPath may contain path and positional information; the last node in the XPath forms the local
* root node for the composite object. The XPath is specified on the mapping using the setXPath
* method.
*
*
The following XPath statements may be used to specify the location of XML data relating to an object's
* name attribute:
*
*
*
XPath statements
*
*
XPath
*
Description
*
*
*
phone-number
*
The phone number information is stored in the phone-number element.
*
*
*
contact-info/phone-number
*
The XPath statement may be used to specify any valid path.
*
*
*
phone-number[2]
*
The XPath statement may contain positional information. In this case the phone
* number information is stored in the second occurrence of the phone-number element.
More Information: For more information about using the XML Composite Collection Mapping, see the
* "Understanding XML Mappings" chapter of the Oracle TopLink Developer's Guide.
*
* @since Oracle TopLink 10g Release 2 (10.1.3)
*/
public class XMLCompositeCollectionMapping extends AbstractCompositeCollectionMapping implements CompositeCollectionMapping, XMLMapping, XMLNillableMapping {
AbstractNullPolicy nullPolicy;
private AbstractNullPolicy wrapperNullPolicy;
private UnmarshalKeepAsElementPolicy keepAsElementPolicy;
private XMLInverseReferenceMapping inverseReferenceMapping;
private boolean defaultEmptyContainer = XMLContainerMapping.EMPTY_CONTAINER_DEFAULT;
private boolean isWriteOnly;
private boolean reuseContainer = false;
public XMLCompositeCollectionMapping() {
super();
// The default policy is NullPolicy
nullPolicy = new NullPolicy();
}
/**
* Gets the AttributeAccessor that is used to get and set the value of the
* container on the target object.
* @deprecated Replaced by getInverseReferenceMapping().getAttributeAccessor()
*/
@Deprecated
public AttributeAccessor getContainerAccessor() {
if (this.inverseReferenceMapping == null) {
return null;
}
return this.inverseReferenceMapping.getAttributeAccessor();
}
/**
* Sets the AttributeAccessor that is used to get and set the value of the
* container on the target object.
*
* @param anAttributeAccessor - the accessor to be used.
* @deprecated Replaced by getInverseReferenceMapping().setAttributeAccessor()
*/
@Deprecated
public void setContainerAccessor(AttributeAccessor anAttributeAccessor) {
if (this.inverseReferenceMapping == null) {
return;
}
this.inverseReferenceMapping.setAttributeAccessor(anAttributeAccessor);
}
/**
* Sets the name of the backpointer attribute on the target object. Used to
* populate the backpointer. If the specified attribute doesn't exist on the
* reference class of this mapping, a DescriptorException will be thrown
* during initialize.
*
* @param attributeName - the name of the backpointer attribute to be populated
* @deprecated Replaced by getInverseReferenceMapping().setAttributeName()
*/
@Deprecated
public void setContainerAttributeName(String attributeName) {
if (this.inverseReferenceMapping == null) {
return;
}
this.inverseReferenceMapping.setAttributeName(attributeName);
}
/**
* Gets the name of the backpointer attribute on the target object.
* @deprecated Replaced by getInverseReferenceMapping().getAttributeName()
*/
@Deprecated
public String getContainerAttributeName() {
if (this.inverseReferenceMapping == null) {
return null;
}
return this.inverseReferenceMapping.getAttributeName();
}
/**
* Sets the method name to be used when accessing the value of the back pointer
* on the target object of this mapping. If the specified method isn't declared
* on the reference class of this mapping, a DescriptorException will be thrown
* during initialize.
*
* @param methodName - the name of the getter method to be used.
* @deprecated Replaced by getInverseReferenceMapping().setGetMethodName()
*/
@Deprecated
public void setContainerGetMethodName(String methodName) {
if (this.inverseReferenceMapping == null) {
return;
}
this.inverseReferenceMapping.setGetMethodName(methodName);
}
/**
* Gets the name of the method to be used when accessing the value of the
* back pointer on the target object of this mapping.
* @deprecated Replaced by getInverseReferenceMapping().getGetMethodName()
*/
@Deprecated
public String getContainerGetMethodName() {
if (this.inverseReferenceMapping == null) {
return null;
}
return this.inverseReferenceMapping.getGetMethodName();
}
/**
* Gets the name of the method to be used when setting the value of the
* back pointer on the target object of this mapping.
* @deprecated Replaced by getInverseReferenceMapping().getSetMethodName()
*/
@Deprecated
public String getContainerSetMethodName() {
if (this.inverseReferenceMapping == null) {
return null;
}
return this.inverseReferenceMapping.getSetMethodName();
}
/**
* Sets the name of the method to be used when setting the value of the back pointer
* on the target object of this mapping. If the specified method isn't declared on
* the reference class of this mapping, a DescriptorException will be
* raised during initialize.
*
* @param methodName - the name of the setter method to be used.
* @deprecated Replaced by getInverseReferenceMapping().setSetMethodName()
*/
@Deprecated
public void setContainerSetMethodName(String methodName) {
if (this.inverseReferenceMapping == null) {
return;
}
this.inverseReferenceMapping.setSetMethodName(methodName);
}
/**
* INTERNAL:
*/
@Override
public boolean isXMLMapping() {
return true;
}
@Override
public void convertClassNamesToClasses(ClassLoader classLoader){
if(XMLConstants.UNKNOWN_OR_TRANSIENT_CLASS.equals(referenceClassName)){
return;
}
super.convertClassNamesToClasses(classLoader);
}
/**
* INTERNAL:
* The mapping is initialized with the given session. This mapping is fully initialized
* after this.
*/
@Override
public void initialize(AbstractSession session) throws DescriptorException {
//modified so that reference class on composite mappings is no longer mandatory
String referenceClassName = getReferenceClassName();
if (this.referenceClass == null && referenceClassName != null) {
if (!referenceClassName.equals(XMLConstants.UNKNOWN_OR_TRANSIENT_CLASS)) {
setReferenceClass(session.getDatasourcePlatform().getConversionManager().convertClassNameToClass(referenceClassName));
}
}
initializeReferenceDescriptorAndField(session);
ContainerPolicy cp = getContainerPolicy();
if (cp != null) {
if (cp.getContainerClass() == null) {
Class