org.eclipse.persistence.eis.EISObjectPersistenceXMLProject Maven / Gradle / Ivy
Show all versions of eclipselink Show documentation
/*
* 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.eis;
// javase imports
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
// Java extension imports
import javax.xml.namespace.QName;
// EclipseLink imports
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.eis.interactions.XMLInteraction;
import org.eclipse.persistence.eis.mappings.EISCompositeCollectionMapping;
import org.eclipse.persistence.eis.mappings.EISCompositeDirectCollectionMapping;
import org.eclipse.persistence.eis.mappings.EISCompositeObjectMapping;
import org.eclipse.persistence.eis.mappings.EISDirectMapping;
import org.eclipse.persistence.eis.mappings.EISOneToManyMapping;
import org.eclipse.persistence.eis.mappings.EISOneToOneMapping;
import org.eclipse.persistence.eis.mappings.EISTransformationMapping;
import org.eclipse.persistence.internal.descriptors.InteractionArgument;
import org.eclipse.persistence.internal.helper.DatabaseField;
import org.eclipse.persistence.internal.indirection.IndirectionPolicy;
import org.eclipse.persistence.internal.indirection.NoIndirectionPolicy;
import org.eclipse.persistence.internal.queries.ContainerPolicy;
import org.eclipse.persistence.internal.sessions.factories.NamespaceResolvableProject;
import org.eclipse.persistence.internal.sessions.factories.NamespaceResolverWithPrefixes;
import org.eclipse.persistence.mappings.Association;
import org.eclipse.persistence.mappings.AttributeAccessor;
import org.eclipse.persistence.mappings.CollectionMapping;
import org.eclipse.persistence.mappings.ForeignReferenceMapping;
import org.eclipse.persistence.mappings.ObjectReferenceMapping;
import org.eclipse.persistence.mappings.converters.ClassInstanceConverter;
import org.eclipse.persistence.mappings.foundation.AbstractCompositeCollectionMapping;
import org.eclipse.persistence.mappings.foundation.AbstractCompositeDirectCollectionMapping;
import org.eclipse.persistence.mappings.foundation.AbstractCompositeObjectMapping;
import org.eclipse.persistence.mappings.foundation.AbstractDirectMapping;
import org.eclipse.persistence.mappings.foundation.AbstractTransformationMapping;
import org.eclipse.persistence.oxm.NamespaceResolver;
import org.eclipse.persistence.oxm.XMLConstants;
import org.eclipse.persistence.oxm.XMLDescriptor;
import org.eclipse.persistence.oxm.XMLField;
import org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping;
import org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping;
import org.eclipse.persistence.oxm.mappings.XMLDirectMapping;
import org.eclipse.persistence.queries.Call;
import org.eclipse.persistence.queries.ModifyQuery;
import org.eclipse.persistence.queries.ReadQuery;
import org.eclipse.persistence.sessions.DatasourceLogin;
/**
* INTERNAL:
* EISObjectPersistenceXMLProject
defines the EclipseLink EIS
* project and descriptor information to read a EclipseLink project from an XML
* file. The EIS meta-data must be defined separately as it has separate jar
* dependencies that must not be required if not using EIS.
*/
public class EISObjectPersistenceXMLProject extends NamespaceResolvableProject {
/**
* INTERNAL:
* Return a new descriptor project.
*/
public EISObjectPersistenceXMLProject() {
super();
}
public EISObjectPersistenceXMLProject(NamespaceResolverWithPrefixes namespaceResolverWithPrefixes) {
super(namespaceResolverWithPrefixes);
}
@Override
protected void buildDescriptors() {
addDescriptor(buildEISDescriptorDescriptor());
addDescriptor(buildXMLInteractionDescriptor());
addDescriptor(buildEISLoginDescriptor());
addDescriptor(buildInteractionArgumentDescriptor());
addDescriptor(buildEISDirectMappingDescriptor());
addDescriptor(buildEISTransformationMappingDescriptor());
addDescriptor(buildEISCompositeDirectCollectionMappingDescriptor());
addDescriptor(buildEISCompositeObjectMappingDescriptor());
addDescriptor(buildEISCompositeCollectionMappingDescriptor());
addDescriptor(buildEISOneToOneMappingDescriptor());
addDescriptor(buildEISOneToManyMappingDescriptor());
}
protected ClassDescriptor buildEISDescriptorDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(EISDescriptor.class);
descriptor.getInheritancePolicy().setParentClass(ClassDescriptor.class);
XMLDirectMapping structureMapping = new XMLDirectMapping();
structureMapping.setAttributeName("dataTypeName");
structureMapping.setGetMethodName("getDataTypeName");
structureMapping.setSetMethodName("setDataTypeName");
structureMapping.setXPath(getPrimaryNamespaceXPath() + "datatype/text()");
descriptor.addMapping(structureMapping);
XMLCompositeObjectMapping namespaceResolverMapping = new XMLCompositeObjectMapping();
namespaceResolverMapping.setXPath(getPrimaryNamespaceXPath() + "namespace-resolver");
namespaceResolverMapping.setAttributeName("namespaceResolver");
namespaceResolverMapping.setGetMethodName("getNamespaceResolver");
namespaceResolverMapping.setSetMethodName("setNamespaceResolver");
namespaceResolverMapping.setReferenceClass(NamespaceResolver.class);
descriptor.addMapping(namespaceResolverMapping);
return descriptor;
}
protected ClassDescriptor buildXMLInteractionDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(XMLInteraction.class);
descriptor.descriptorIsAggregate();
descriptor.getInheritancePolicy().setParentClass(Call.class);
XMLDirectMapping functionNameMapping = new XMLDirectMapping();
functionNameMapping.setAttributeName("functionName");
functionNameMapping.setGetMethodName("getFunctionName");
functionNameMapping.setSetMethodName("setFunctionName");
functionNameMapping.setXPath(getPrimaryNamespaceXPath() + "function-name/text()");
functionNameMapping.setNullValue("");
descriptor.addMapping(functionNameMapping);
XMLDirectMapping inputRecordNameMapping = new XMLDirectMapping();
inputRecordNameMapping.setAttributeName("inputRecordName");
inputRecordNameMapping.setGetMethodName("getInputRecordName");
inputRecordNameMapping.setSetMethodName("setInputRecordName");
inputRecordNameMapping.setXPath(getPrimaryNamespaceXPath() + "input-record-name/text()");
inputRecordNameMapping.setNullValue("");
descriptor.addMapping(inputRecordNameMapping);
XMLDirectMapping inputRootElementNameMapping = new XMLDirectMapping();
inputRootElementNameMapping.setAttributeName("inputRootElementName");
inputRootElementNameMapping.setGetMethodName("getInputRootElementName");
inputRootElementNameMapping.setSetMethodName("setInputRootElementName");
inputRootElementNameMapping.setXPath(getPrimaryNamespaceXPath() + "input-root-element-name/text()");
inputRootElementNameMapping.setNullValue("");
descriptor.addMapping(inputRootElementNameMapping);
XMLDirectMapping inputResultPathMapping = new XMLDirectMapping();
inputResultPathMapping.setAttributeName("inputResultPath");
inputResultPathMapping.setGetMethodName("getInputResultPath");
inputResultPathMapping.setSetMethodName("setInputResultPath");
inputResultPathMapping.setXPath(getPrimaryNamespaceXPath() + "input-result-path/text()");
inputResultPathMapping.setNullValue("");
descriptor.addMapping(inputResultPathMapping);
XMLDirectMapping outputResultPathMapping = new XMLDirectMapping();
outputResultPathMapping.setAttributeName("outputResultPath");
outputResultPathMapping.setGetMethodName("getOutputResultPath");
outputResultPathMapping.setSetMethodName("setOutputResultPath");
outputResultPathMapping.setXPath(getPrimaryNamespaceXPath() + "output-result-path/text()");
outputResultPathMapping.setNullValue("");
descriptor.addMapping(outputResultPathMapping);
XMLCompositeCollectionMapping argumentsMapping = new XMLCompositeCollectionMapping();
// Handle translation of argument lists to interaction-arguments.
argumentsMapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
XMLInteraction interaction = (XMLInteraction)object;
Vector argumentNames = interaction.getArgumentNames();
Vector> arguments = interaction.getArguments();
Vector interactionArguments = new Vector<>(arguments.size());
for (int index = 0; index < arguments.size(); index++) {
InteractionArgument interactionArgument = new InteractionArgument();
interactionArgument.setArgumentName(argumentNames.get(index));
Object argument = arguments.get(index);
if (argument instanceof DatabaseField) {
interactionArgument.setKey(argument);
} else {
interactionArgument.setValue(argument);
}
interactionArguments.add(interactionArgument);
}
return interactionArguments;
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
XMLInteraction interaction = (XMLInteraction)object;
@SuppressWarnings({"unchecked"})
Vector interactionArguments = (Vector)value;
Vector arguments = new Vector<>(interactionArguments.size());
Vector argumentNames = new Vector<>(interactionArguments.size());
Vector