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.security.AccessController;
import java.security.PrivilegedActionException;
import java.util.Vector;
import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.exceptions.DatabaseException;
import org.eclipse.persistence.exceptions.DescriptorException;
import org.eclipse.persistence.exceptions.ValidationException;
import org.eclipse.persistence.internal.core.sessions.CoreAbstractSession;
import org.eclipse.persistence.internal.descriptors.DescriptorIterator;
import org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor;
import org.eclipse.persistence.internal.helper.ClassConstants;
import org.eclipse.persistence.internal.helper.DatabaseField;
import org.eclipse.persistence.internal.identitymaps.CacheKey;
import org.eclipse.persistence.internal.oxm.XMLChoiceFieldToClassAssociation;
import org.eclipse.persistence.internal.oxm.XMLConversionManager;
import org.eclipse.persistence.internal.oxm.XPathFragment;
import org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping;
import org.eclipse.persistence.internal.oxm.record.AbstractMarshalRecord;
import org.eclipse.persistence.internal.queries.ContainerPolicy;
import org.eclipse.persistence.internal.queries.JoinedAttributeManager;
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;
import org.eclipse.persistence.internal.security.PrivilegedClassForName;
import org.eclipse.persistence.internal.sessions.AbstractRecord;
import org.eclipse.persistence.internal.sessions.AbstractSession;
import org.eclipse.persistence.internal.sessions.ChangeRecord;
import org.eclipse.persistence.internal.sessions.MergeManager;
import org.eclipse.persistence.internal.sessions.ObjectChangeSet;
import org.eclipse.persistence.internal.sessions.UnitOfWorkImpl;
import org.eclipse.persistence.internal.sessions.remote.ObjectDescriptor;
import org.eclipse.persistence.mappings.AttributeAccessor;
import org.eclipse.persistence.mappings.DatabaseMapping;
import org.eclipse.persistence.mappings.converters.Converter;
import org.eclipse.persistence.mappings.foundation.AbstractCompositeObjectMapping;
import org.eclipse.persistence.mappings.foundation.AbstractDirectMapping;
import org.eclipse.persistence.oxm.mappings.converters.XMLConverter;
import org.eclipse.persistence.oxm.mappings.converters.XMLRootConverter;
import org.eclipse.persistence.oxm.record.XMLRecord;
import org.eclipse.persistence.queries.ObjectBuildingQuery;
import org.eclipse.persistence.queries.ObjectLevelReadQuery;
import org.eclipse.persistence.sessions.Session;
import org.eclipse.persistence.sessions.remote.DistributedSession;
import org.eclipse.persistence.oxm.XMLField;
import org.eclipse.persistence.oxm.XMLMarshaller;
import org.eclipse.persistence.oxm.XMLRoot;
import org.eclipse.persistence.oxm.XMLUnmarshaller;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import javax.xml.namespace.QName;
/**
* PUBLIC:
*
Purpose:Provide a mapping that can map a single attribute to a number of
* different elements in an XML Document. This will be used to map to Choices or Substitution
* Groups in an XML Schema
*
Responsibilities:
*
Allow the user to specify XPath {@literal ->} Type mappings
*
Handle reading and writing of XML Documents containing a single choice or substitution
* group element
*
*
The XMLChoiceMapping allows the user to specify a number of different xpaths, and types associated with those xpaths.
* When any of these elements are encountered in the XML Document, they are read in as the correct
* type and set in the object.
*
Setting up XPath mappings:Unlike other OXM Mappings, instead of setting a single xpath,
* the addChoiceElement method is used to specify an xpath and the type associated with this xpath.
*
* xmlChoiceCollectionMapping.addChoiceElement("mystring/text()", String.class);
*
* xmlChoiceCollectionMapping.addChoiceElement("myaddress", Address.class);
*
*/
public class XMLChoiceObjectMapping extends DatabaseMapping implements ChoiceObjectMapping, XMLMapping {
private Map> fieldToClassMappings;
private Map, XMLField> classToFieldMappings;
private Map classNameToFieldMappings;
private Map, List> classToSourceFieldsMappings;
private Map> classNameToSourceFieldsMappings;
private Map fieldToClassNameMappings;
private Map choiceElementMappings;
private Map, XMLMapping> choiceElementMappingsByClass;
private Map choiceElementMappingsByClassName;
private Map fieldsToConverters;
private Map classNameToConverter;
private Map, Converter> classToConverter;
private Converter converter;
private boolean isWriteOnly;
private static final AttributeAccessor temporaryAccessor = new InstanceVariableAttributeAccessor();
private static final String DATA_HANDLER = "jakarta.activation.DataHandler";
private static final String MIME_MULTIPART = "jakarta.mail.internet.MimeMultipart";
private static final String IMAGE = "java.awt.Image";
public XMLChoiceObjectMapping() {
fieldToClassMappings = new HashMap<>();
fieldToClassNameMappings = new HashMap<>();
classToFieldMappings = new HashMap<>();
classNameToFieldMappings = new HashMap<>();
choiceElementMappings = new LinkedHashMap<>();
choiceElementMappingsByClass = new LinkedHashMap<>();
choiceElementMappingsByClassName = new LinkedHashMap<>();
fieldsToConverters = new HashMap<>();
}
/**
* Return the converter on the mapping.
* A converter can be used to convert between the object's value and database value of the attribute.
*/
@Override
public Converter getConverter() {
return converter;
}
/**
* Set the converter on the mapping.
* A converter can be used to convert between the object's value and database value of the attribute.
*/
@Override
public void setConverter(Converter converter) {
this.converter = converter;
}
/**
* INTERNAL:
* Clone the attribute from the clone and assign it to the backup.
*/
@Override
public void buildBackupClone(Object clone, Object backup, UnitOfWorkImpl unitOfWork) {
throw DescriptorException.invalidMappingOperation(this, "buildBackupClone");
}
/**
* INTERNAL:
* Clone the attribute from the original and assign it to the clone.
*/
@Override
public void buildClone(Object original, CacheKey cacheKey, Object clone, Integer refreshCascade, AbstractSession cloningSession) {
throw DescriptorException.invalidMappingOperation(this, "buildClone");
}
@Override
public void buildCloneFromRow(AbstractRecord databaseRow, JoinedAttributeManager joinManager, Object clone, CacheKey sharedCacheKey, ObjectBuildingQuery sourceQuery, UnitOfWorkImpl unitOfWork, AbstractSession executionSession) {
throw DescriptorException.invalidMappingOperation(this, "buildCloneFromRow");
}
/**
* INTERNAL:
* Cascade perform delete through mappings that require the cascade
*/
@Override
public void cascadePerformRemoveIfRequired(Object object, UnitOfWorkImpl uow, Map visitedObjects) {
//objects referenced by this mapping are not registered as they have
// no identity, this is a no-op.
}
/**
* INTERNAL:
* Cascade registerNew for Create through mappings that require the cascade
*/
@Override
public void cascadeRegisterNewIfRequired(Object object, UnitOfWorkImpl uow, Map visitedObjects) {
//Our current XML support does not make use of the UNitOfWork.
}
/**
* INTERNAL:
* This method was created in VisualAge.
* @return prototype.changeset.ChangeRecord
*/
@Override
public ChangeRecord compareForChange(Object clone, Object backup, ObjectChangeSet owner, AbstractSession session) {
throw DescriptorException.invalidMappingOperation(this, "compareForChange");
}
/**
* INTERNAL:
* Compare the attributes belonging to this mapping for the objects.
*/
@Override
public boolean compareObjects(Object firstObject, Object secondObject, AbstractSession session) {
throw DescriptorException.invalidMappingOperation(this, "compareObjects");
}
/**
* INTERNAL:
* An object has been serialized from the server to the client.
* Replace the transient attributes of the remote value holders
* with client-side objects.
*/
@Override
public void fixObjectReferences(Object object, Map