use of org.eclipse.persistence.core.descriptors.CoreDescriptor in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateWrapperClassAndDescriptor.
private Class<?> generateWrapperClassAndDescriptor(TypeInfo type, QName next, ElementDeclaration nextElement, String nextClassName, String attributeTypeName) {
String namespaceUri = null;
if (next != null) {
// generate a class/descriptor for this element
namespaceUri = next.getNamespaceURI();
if (namespaceUri == null || namespaceUri.equals(XMLProcessor.DEFAULT)) {
namespaceUri = "";
}
}
TypeMappingInfo tmi = nextElement.getTypeMappingInfo();
Class<?> generatedClass = null;
JaxbClassLoader loader = getJaxbClassLoader();
if (tmi != null) {
generatedClass = CompilerHelper.getExisitingGeneratedClass(tmi, typeMappingInfoToGeneratedClasses, typeMappingInfoToAdapterClasses, helper.getClassLoader());
if (generatedClass == null) {
generatedClass = this.generateWrapperClass(loader.nextAvailableGeneratedClassName(), attributeTypeName, nextElement.isList(), next);
}
typeMappingInfoToGeneratedClasses.put(tmi, generatedClass);
} else {
generatedClass = this.generateWrapperClass(loader.nextAvailableGeneratedClassName(), attributeTypeName, nextElement.isList(), next);
}
this.qNamesToGeneratedClasses.put(next, generatedClass);
try {
Class<Object> declaredClass = PrivilegedAccessHelper.getClassForName(nextClassName, false, helper.getClassLoader());
this.qNamesToDeclaredClasses.put(next, declaredClass);
} catch (Exception e) {
}
Descriptor desc = (Descriptor) project.getDescriptor(generatedClass);
if (desc == null) {
desc = new XMLDescriptor();
desc.setJavaClass(generatedClass);
if (nextElement.isList()) {
DirectCollectionMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, XMLUnmarshaller, XMLRecord> mapping = new XMLCompositeDirectCollectionMapping();
mapping.setAttributeName("value");
mapping.setXPath("text()");
mapping.setUsesSingleNode(true);
mapping.setReuseContainer(true);
if (type != null && type.isEnumerationType()) {
mapping.setValueConverter(buildJAXBEnumTypeConverter(mapping, (EnumTypeInfo) type));
} else {
try {
Class<Object> fieldElementClass = PrivilegedAccessHelper.getClassForName(nextClassName, false, helper.getClassLoader());
mapping.setFieldElementClass(fieldElementClass);
} catch (ClassNotFoundException e) {
}
}
if (nextClassName.equals("[B") || nextClassName.equals("[Ljava.lang.Byte;")) {
((Field) mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
} else if (nextClassName.equals("javax.xml.namespace.QName")) {
((Field) mapping.getField()).setSchemaType(Constants.QNAME_QNAME);
}
desc.addMapping((CoreMapping) mapping);
} else {
if (nextElement.getJavaTypeName().equals(OBJECT_CLASS_NAME)) {
CompositeObjectMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, UnmarshalKeepAsElementPolicy, XMLUnmarshaller, XMLRecord> mapping = new XMLCompositeObjectMapping();
mapping.setAttributeName("value");
mapping.setSetMethodName("setValue");
mapping.setGetMethodName("getValue");
mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
mapping.setXPath(".");
setTypedTextField((Field) mapping.getField());
desc.addMapping((CoreMapping) mapping);
} else if (isBinaryData(nextElement.getJavaType())) {
BinaryDataMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, MimeTypePolicy, Session, XMLUnmarshaller, XMLRecord> mapping = new XMLBinaryDataMapping();
mapping.setAttributeName("value");
mapping.setXPath(".");
((Field) mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
mapping.setSetMethodName("setValue");
mapping.setGetMethodName("getValue");
mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
Class<?> attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(attributeTypeName, helper.getClassLoader());
mapping.setAttributeClassification(attributeClassification);
mapping.setShouldInlineBinaryData(false);
// if(nextElement.getTypeMappingInfo() != null) {
mapping.setSwaRef(nextElement.isXmlAttachmentRef());
mapping.setMimeType(nextElement.getXmlMimeType());
// }
desc.addMapping((CoreMapping) mapping);
} else {
DirectMapping<AbstractSession, AttributeAccessor, ContainerPolicy, Converter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, XMLUnmarshaller, XMLRecord> mapping = new XMLDirectMapping();
mapping.setNullValueMarshalled(true);
mapping.setAttributeName("value");
mapping.setXPath("text()");
mapping.setSetMethodName("setValue");
mapping.setGetMethodName("getValue");
if (nextElement.getDefaultValue() != null) {
mapping.setNullValue(nextElement.getDefaultValue());
mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
}
if (helper.isBuiltInJavaType(nextElement.getJavaType())) {
Class<?> attributeClassification = null;
if (nextElement.getJavaType().isPrimitive()) {
attributeClassification = XMLConversionManager.getDefaultManager().convertClassNameToClass(attributeTypeName);
} else {
attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(attributeTypeName, helper.getClassLoader());
}
mapping.setAttributeClassification(attributeClassification);
}
IsSetNullPolicy nullPolicy = new IsSetNullPolicy("isSetValue", false, true, XMLNullRepresentationType.ABSENT_NODE);
// nullPolicy.setNullRepresentedByEmptyNode(true);
mapping.setNullPolicy(nullPolicy);
if (type != null && type.isEnumerationType()) {
mapping.setConverter(buildJAXBEnumTypeConverter(mapping, (EnumTypeInfo) type));
}
if (nextClassName.equals("[B") || nextClassName.equals("[Ljava.lang.Byte;")) {
((Field) mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
} else if (nextClassName.equals("javax.xml.namespace.QName")) {
((Field) mapping.getField()).setSchemaType(Constants.QNAME_QNAME);
}
if (nextElement.getJavaTypeAdapterClass() != null) {
mapping.setConverter(new XMLJavaTypeConverter(nextElement.getJavaTypeAdapterClass()));
}
desc.addMapping((CoreMapping) mapping);
}
}
if (next != null) {
NamespaceInfo info = getNamespaceInfoForURI(namespaceUri);
if (info != null) {
NamespaceResolver resolver = getNamespaceResolverForDescriptor(info);
String prefix = null;
if (namespaceUri != Constants.EMPTY_STRING) {
prefix = resolver.resolveNamespaceURI(namespaceUri);
if (prefix == null) {
prefix = getPrefixForNamespace(namespaceUri, resolver);
}
}
desc.setNamespaceResolver(resolver);
if (nextElement.isXmlRootElement()) {
desc.setDefaultRootElement(getQualifiedString(prefix, next.getLocalPart()));
} else {
desc.setDefaultRootElement("");
desc.addRootElement(getQualifiedString(prefix, next.getLocalPart()));
desc.setResultAlwaysXMLRoot(true);
}
} else {
if (namespaceUri.equals("")) {
desc.setDefaultRootElement(next.getLocalPart());
} else {
NamespaceResolver resolver = new org.eclipse.persistence.oxm.NamespaceResolver();
String prefix = getPrefixForNamespace(namespaceUri, resolver);
desc.setNamespaceResolver(resolver);
if (nextElement.isXmlRootElement()) {
desc.setDefaultRootElement(getQualifiedString(prefix, next.getLocalPart()));
} else {
desc.setDefaultRootElement("");
desc.addRootElement(getQualifiedString(prefix, next.getLocalPart()));
desc.setResultAlwaysXMLRoot(true);
}
}
}
}
project.addDescriptor((CoreDescriptor) desc);
}
return generatedClass;
}
use of org.eclipse.persistence.core.descriptors.CoreDescriptor in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateDescriptorForJAXBElementSubclass.
public void generateDescriptorForJAXBElementSubclass(JavaClass javaClass, CoreProject project, NamespaceResolver nsr) {
String jClassName = javaClass.getQualifiedName();
TypeInfo info = typeInfo.get(jClassName);
Descriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClassName(jClassName);
String[] factoryMethodParamTypes = info.getFactoryMethodParamTypes();
MultiArgInstantiationPolicy policy = new MultiArgInstantiationPolicy();
policy.useFactoryInstantiationPolicy(info.getObjectFactoryClassName(), info.getFactoryMethodName());
policy.setParameterTypeNames(factoryMethodParamTypes);
policy.setDefaultValues(new String[] { null });
xmlDescriptor.setInstantiationPolicy(policy);
JavaClass paramClass = helper.getJavaClass(factoryMethodParamTypes[0]);
boolean isObject = paramClass.getName().equals("java.lang.Object");
if (helper.isBuiltInJavaType(paramClass) && !isObject) {
if (isBinaryData(paramClass)) {
BinaryDataMapping mapping = new XMLBinaryDataMapping();
mapping.setAttributeName("value");
mapping.setXPath(".");
((Field) mapping.getField()).setSchemaType(Constants.BASE_64_BINARY_QNAME);
mapping.setSetMethodName("setValue");
mapping.setGetMethodName("getValue");
Class<?> attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(factoryMethodParamTypes[0], helper.getClassLoader());
mapping.setAttributeClassification(attributeClassification);
mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
mapping.setShouldInlineBinaryData(false);
if (mapping.getMimeType() == null) {
if (areEquals(paramClass, javax.xml.transform.Source.class)) {
mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/xml"));
} else {
mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/octet-stream"));
}
}
xmlDescriptor.addMapping((CoreMapping) mapping);
} else {
DirectMapping mapping = new XMLDirectMapping();
mapping.setNullValueMarshalled(true);
mapping.setAttributeName("value");
mapping.setGetMethodName("getValue");
mapping.setSetMethodName("setValue");
mapping.setXPath("text()");
Class<?> attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(factoryMethodParamTypes[0], helper.getClassLoader());
mapping.setAttributeClassification(attributeClassification);
xmlDescriptor.addMapping((CoreMapping) mapping);
}
} else if (paramClass.isEnum()) {
EnumTypeInfo enumInfo = (EnumTypeInfo) typeInfo.get(paramClass.getQualifiedName());
DirectMapping mapping = new XMLDirectMapping();
mapping.setConverter(buildJAXBEnumTypeConverter(mapping, enumInfo));
mapping.setNullValueMarshalled(true);
mapping.setAttributeName("value");
mapping.setGetMethodName("getValue");
mapping.setSetMethodName("setValue");
mapping.setXPath("text()");
Class<?> attributeClassification = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(factoryMethodParamTypes[0], helper.getClassLoader());
mapping.setAttributeClassification(attributeClassification);
xmlDescriptor.addMapping((CoreMapping) mapping);
} else {
CompositeObjectMapping mapping = new XMLCompositeObjectMapping();
mapping.setAttributeName("value");
mapping.setGetMethodName("getValue");
mapping.setSetMethodName("setValue");
mapping.setXPath(".");
if (isObject) {
mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
} else {
mapping.setReferenceClassName(factoryMethodParamTypes[0]);
}
xmlDescriptor.addMapping((CoreMapping) mapping);
}
xmlDescriptor.setNamespaceResolver(nsr);
setSchemaContext(xmlDescriptor, info);
project.addDescriptor((CoreDescriptor) xmlDescriptor);
info.setDescriptor(xmlDescriptor);
}
use of org.eclipse.persistence.core.descriptors.CoreDescriptor in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateDescriptor.
public void generateDescriptor(JavaClass javaClass, CoreProject project) {
String jClassName = javaClass.getQualifiedName();
TypeInfo info = typeInfo.get(jClassName);
if (info.isTransient()) {
return;
}
NamespaceInfo namespaceInfo = this.packageToPackageInfoMappings.get(javaClass.getPackageName()).getNamespaceInfo();
String packageNamespace = namespaceInfo.getNamespace();
String elementName;
String namespace;
if (javaClass.getSuperclass() != null && javaClass.getSuperclass().getName().equals("jakarta.xml.bind.JAXBElement")) {
generateDescriptorForJAXBElementSubclass(javaClass, project, getNamespaceResolverForDescriptor(namespaceInfo));
return;
}
Descriptor descriptor = new XMLDescriptor();
org.eclipse.persistence.jaxb.xmlmodel.XmlRootElement rootElem = info.getXmlRootElement();
if (rootElem == null) {
try {
elementName = info.getXmlNameTransformer().transformRootElementName(javaClass.getName());
} catch (Exception ex) {
throw org.eclipse.persistence.exceptions.JAXBException.exceptionDuringNameTransformation(javaClass.getName(), info.getXmlNameTransformer().getClass().getName(), ex);
}
namespace = packageNamespace;
} else {
elementName = rootElem.getName();
if (elementName.equals(XMLProcessor.DEFAULT)) {
try {
elementName = info.getXmlNameTransformer().transformRootElementName(javaClass.getName());
} catch (Exception ex) {
throw org.eclipse.persistence.exceptions.JAXBException.exceptionDuringNameTransformation(javaClass.getName(), info.getXmlNameTransformer().getClass().getName(), ex);
}
}
namespace = rootElem.getNamespace();
}
descriptor.setJavaClassName(jClassName);
if (info.getFactoryMethodName() != null) {
descriptor.getInstantiationPolicy().useFactoryInstantiationPolicy(info.getObjectFactoryClassName(), info.getFactoryMethodName());
}
if (namespace.equals(XMLProcessor.DEFAULT)) {
namespace = namespaceInfo.getNamespace();
}
NamespaceResolver resolverForDescriptor = getNamespaceResolverForDescriptor(namespaceInfo);
JavaClass manyValueJavaClass = helper.getJavaClass(ManyValue.class);
if (!manyValueJavaClass.isAssignableFrom(javaClass)) {
if (isDefaultNamespaceAllowed && namespace.length() != 0 && globalNamespaceResolver.getDefaultNamespaceURI() == null && !resolverForDescriptor.getPrefixesToNamespaces().containsValue(namespace)) {
globalNamespaceResolver.setDefaultNamespaceURI(namespace);
resolverForDescriptor.setDefaultNamespaceURI(namespace);
}
if (rootElem == null) {
descriptor.setDefaultRootElement("");
} else {
if (namespace.length() == 0) {
descriptor.setDefaultRootElement(elementName);
} else {
descriptor.setDefaultRootElement(getQualifiedString(getPrefixForNamespace(namespace, resolverForDescriptor), elementName));
}
}
}
descriptor.setNamespaceResolver(resolverForDescriptor);
setSchemaContext(descriptor, info);
// set the ClassExtractor class name if necessary
if (info.isSetClassExtractorName()) {
descriptor.getInheritancePolicy().setClassExtractorName(info.getClassExtractorName());
}
// set any user-defined properties
if (info.getUserProperties() != null) {
descriptor.setProperties(info.getUserProperties());
}
if (info.isLocationAware()) {
Property locProp = null;
Iterator<Property> i = info.getPropertyList().iterator();
while (i.hasNext()) {
Property p = i.next();
if (p.getType().getName().equals(Constants.LOCATOR_CLASS_NAME)) {
locProp = p;
}
}
if (locProp != null && locProp.isTransient()) {
// don't make a mapping
if (locProp.isMethodProperty()) {
MethodAttributeAccessor aa = new MethodAttributeAccessor();
aa.setAttributeName(locProp.getPropertyName());
aa.setSetMethodName(locProp.getSetMethodName());
aa.setGetMethodName(locProp.getGetMethodName());
descriptor.setLocationAccessor(aa);
} else {
// instance variable property
InstanceVariableAttributeAccessor aa = new InstanceVariableAttributeAccessor();
aa.setAttributeName(locProp.getPropertyName());
descriptor.setLocationAccessor(aa);
}
}
}
if (!info.getObjectGraphs().isEmpty()) {
// these will be populated later to allow for linking
for (XmlNamedObjectGraph next : info.getObjectGraphs()) {
AttributeGroup attributeGroup = new AttributeGroup(next.getName(), info.getJavaClassName(), false);
((XMLDescriptor) descriptor).addAttributeGroup(attributeGroup);
// process subclass graphs for inheritance
// for(NamedSubgraph nextSubclass:next.getNamedSubclassGraph()) {
// attributeGroup.insertSubClass(new AttributeGroup(next.getName(), nextSubclass.getType()));
// }
}
}
project.addDescriptor((CoreDescriptor) descriptor);
info.setDescriptor(descriptor);
}
use of org.eclipse.persistence.core.descriptors.CoreDescriptor in project eclipselink by eclipse-ee4j.
the class UnmarshalRecordImpl method endDocument.
@Override
public void endDocument() throws SAXException {
if (unmarshaller.getIDResolver() != null && parentRecord == null) {
unmarshaller.getIDResolver().endDocument();
}
if (null != selfRecords) {
for (int x = 0, selfRecordsSize = selfRecords.size(); x < selfRecordsSize; x++) {
UnmarshalRecord selfRecord = selfRecords.get(x);
if (selfRecord != null) {
selfRecord.endDocument();
}
}
}
if (null != xPathNode.getSelfChildren()) {
int selfChildrenSize = xPathNode.getSelfChildren().size();
for (int x = 0; x < selfChildrenSize; x++) {
XPathNode selfNode = xPathNode.getSelfChildren().get(x);
if (null != selfNode.getNodeValue()) {
selfNode.getNodeValue().endSelfNodeValue(this, selfRecords.get(x), attributes);
}
}
}
CoreDescriptor xmlDescriptor = treeObjectBuilder.getDescriptor();
try {
// All populated containerValues need to be set on the object
if (null != populatedContainerValues) {
for (int populatedCVSize = populatedContainerValues.size(), i = populatedCVSize - 1; i >= 0; i--) {
ContainerValue cv = (populatedContainerValues.get(i));
cv.setContainerInstance(currentObject, getContainerInstance(cv, cv.isDefaultEmptyContainer()));
}
}
// Additionally if any containerValues are defaultEmptyContainerValues they need to be set to a new empty container
if (null != defaultEmptyContainerValues) {
for (int defaultEmptyCVSize = defaultEmptyContainerValues.size(), i = defaultEmptyCVSize - 1; i >= 0; i--) {
ContainerValue cv = (defaultEmptyContainerValues.get(i));
cv.setContainerInstance(currentObject, getContainerInstance(cv, cv.isDefaultEmptyContainer()));
}
}
// trigger the mapping.
if (null != nullCapableValues) {
for (int x = 0, nullValuesSize = nullCapableValues.size(); x < nullValuesSize; x++) {
nullCapableValues.get(x).setNullValue(currentObject, session);
}
}
// PROCESS TRANSFORMATION MAPPINGS
List<TransformationMapping> transformationMappings = treeObjectBuilder.getTransformationMappings();
if (null != transformationMappings) {
for (int x = 0, transformationMappingsSize = transformationMappings.size(); x < transformationMappingsSize; x++) {
TransformationMapping transformationMapping = transformationMappings.get(x);
transformationMapping.readFromRowIntoObject((XMLRecord) transformationRecord, currentObject, session, true);
}
}
Unmarshaller.Listener listener = unmarshaller.getUnmarshalListener();
if (listener != null) {
if (this.parentRecord != null) {
listener.afterUnmarshal(currentObject, parentRecord.getCurrentObject());
} else {
listener.afterUnmarshal(currentObject, null);
}
}
// HANDLE POST BUILD EVENTS
if (xmlDescriptor.hasEventManager()) {
CoreDescriptorEventManager eventManager = xmlDescriptor.getEventManager();
if (null != eventManager && eventManager.hasAnyEventListeners()) {
DescriptorEvent event = new DescriptorEvent(currentObject);
event.setSession((AbstractSession) session);
// this);
event.setRecord(null);
event.setEventCode(DescriptorEventManager.PostBuildEvent);
eventManager.executeEvent(event);
}
}
} catch (EclipseLinkException e) {
if (null == xmlReader.getErrorHandler()) {
throw e;
} else {
SAXParseException saxParseException = new SAXParseException(null, getDocumentLocator(), e);
xmlReader.getErrorHandler().error(saxParseException);
}
}
// if the object has any primary key fields set, add it to the cache
if (null != referenceResolver) {
if (null != xmlDescriptor) {
List primaryKeyFields = xmlDescriptor.getPrimaryKeyFields();
if (null != primaryKeyFields) {
int primaryKeyFieldsSize = primaryKeyFields.size();
if (primaryKeyFieldsSize > 0) {
CacheId pk = (CacheId) treeObjectBuilder.extractPrimaryKeyFromObject(currentObject, session);
for (int x = 0; x < primaryKeyFieldsSize; x++) {
Object value = pk.getPrimaryKey()[x];
if (null == value) {
Field pkField = (Field) xmlDescriptor.getPrimaryKeyFields().get(x);
pk.set(x, unmarshaller.getContext().getValueByXPath(currentObject, pkField.getXPath(), pkField.getNamespaceResolver(), Object.class));
}
}
referenceResolver.putValue(xmlDescriptor.getJavaClass(), pk, currentObject);
if (unmarshaller.getIDResolver() != null) {
try {
if (primaryKeyFieldsSize > 1) {
Map<String, Object> idWrapper = new HashMap<>();
for (int x = 0; x < primaryKeyFieldsSize; x++) {
String idName = (String) xmlDescriptor.getPrimaryKeyFieldNames().get(x);
Object idValue = pk.getPrimaryKey()[x];
idWrapper.put(idName, idValue);
}
unmarshaller.getIDResolver().bind(idWrapper, currentObject);
} else {
unmarshaller.getIDResolver().bind(pk.getPrimaryKey()[0], currentObject);
}
} catch (SAXException e) {
throw XMLMarshalException.unmarshalException(e);
}
}
}
}
}
}
if (null != parentRecord) {
reset();
}
// Set XML Location if applicable
if (xmlLocation != null && ((Descriptor) xmlDescriptor).getLocationAccessor() != null) {
((Descriptor) xmlDescriptor).getLocationAccessor().setAttributeValueInObject(getCurrentObject(), xmlLocation);
}
}
use of org.eclipse.persistence.core.descriptors.CoreDescriptor in project eclipselink by eclipse-ee4j.
the class ReferenceResolver method getValue.
/**
* Add java doc if you understand this code.
*/
private Object getValue(final CoreAbstractSession session, final Reference reference, final CacheId primaryKey, final ErrorHandler handler) {
final Class<?> referenceTargetClass = reference.getTargetClass();
if (null == referenceTargetClass || referenceTargetClass == CoreClassConstants.OBJECT) {
for (Object entry : session.getDescriptors().values()) {
Object value = null;
final Descriptor targetDescriptor = (Descriptor) entry;
final List pkFields = targetDescriptor.getPrimaryKeyFields();
if (null != pkFields && 1 == pkFields.size()) {
Field pkField = (Field) pkFields.get(0);
pkField = (Field) targetDescriptor.getTypedField(pkField);
final Class<?> targetType = pkField.getType();
if (targetType == CoreClassConstants.STRING || targetType == CoreClassConstants.OBJECT) {
value = getValue(targetDescriptor.getJavaClass(), primaryKey);
} else {
try {
final Object[] pkValues = primaryKey.getPrimaryKey();
final Object[] convertedPkValues = new Object[pkValues.length];
for (int x = 0; x < pkValues.length; x++) {
convertedPkValues[x] = session.getDatasourcePlatform().getConversionManager().convertObject(pkValues[x], targetType);
}
value = getValue(targetDescriptor.getJavaClass(), new CacheId(convertedPkValues));
} catch (ConversionException ignored) {
}
}
if (null != value) {
return value;
}
}
}
if (primaryKey.getPrimaryKey()[0] != null) {
final XMLMarshalException e = XMLMarshalException.missingIDForIDRef(Object.class.getName(), primaryKey.getPrimaryKey());
if (handler != null) {
final SAXParseException saxParseException = new SAXParseException(e.getLocalizedMessage(), null, e);
try {
handler.warning(saxParseException);
} catch (SAXException saxException) {
throw e;
}
}
}
return null;
} else {
Object value = getValue(referenceTargetClass, primaryKey);
if (null == value) {
final CoreMapping mapping = (CoreMapping) reference.getMapping();
final CoreDescriptor targetDescriptor = mapping.getReferenceDescriptor();
if (targetDescriptor.hasInheritance()) {
final CoreInheritancePolicy inheritancePolicy = targetDescriptor.getInheritancePolicy();
final List<CoreDescriptor> childDescriptors = inheritancePolicy.getAllChildDescriptors();
for (CoreDescriptor childDescriptor : childDescriptors) {
value = getValue(childDescriptor.getJavaClass(), primaryKey);
if (null != value) {
return value;
}
}
}
}
if (value == null && (primaryKey.getPrimaryKey()[0] != null)) {
final XMLMarshalException e = XMLMarshalException.missingIDForIDRef(referenceTargetClass.getName(), primaryKey.getPrimaryKey());
if (handler != null) {
SAXParseException saxParseException = new SAXParseException(e.getLocalizedMessage(), null, e);
try {
handler.warning(saxParseException);
} catch (SAXException saxException) {
throw e;
}
}
}
return value;
}
}
Aggregations