Search in sources :

Example 46 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLObjectBuilder method createRecordForPKExtraction.

/**
 * Create a new row/record for the object builder. This allows subclasses to
 * define different record types.  This will typically be called when a
 * record will be used for temporarily holding on to primary key fields.
 */
@Override
protected AbstractRecord createRecordForPKExtraction(int size, AbstractSession session) {
    NamespaceResolver namespaceResolver = getNamespaceResolver();
    XMLRecord xmlRec = new DOMRecord(getDescriptor().getTableName(), namespaceResolver);
    xmlRec.setSession(session);
    return xmlRec;
}
Also used : DOMRecord(org.eclipse.persistence.oxm.record.DOMRecord) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 47 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class XMLObjectBuilder method buildRow.

public AbstractRecord buildRow(AbstractRecord databaseRow, Object object, AbstractSession session, boolean wasXMLRoot) {
    XMLRecord row = (XMLRecord) databaseRow;
    row.setSession(session);
    XMLMarshaller marshaller = row.getMarshaller();
    if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
        marshaller.getMarshalListener().beforeMarshal(object);
    }
    addNamespaceDeclarations((row).getDocument());
    writeOutMappings(row, object, session);
    // the non default tables.
    if (!getDescriptor().isAggregateDescriptor()) {
        addPrimaryKeyForNonDefaultTable(row);
    }
    if ((marshaller != null) && (marshaller.getMarshalListener() != null)) {
        marshaller.getMarshalListener().afterMarshal(object);
    }
    return row;
}
Also used : XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord)

Example 48 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method generateXMLObjectReferenceMapping.

/**
 * Create an XMLObjectReferenceMapping and add it to the descriptor.
 */
public ObjectReferenceMapping generateXMLObjectReferenceMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, JavaClass referenceClass) {
    ObjectReferenceMapping<AbstractSession, AttributeAccessor, ContainerPolicy, ClassDescriptor, DatabaseField, UnmarshalRecord, XMLField, XMLRecord> mapping = new XMLObjectReferenceMapping();
    initializeXMLMapping((XMLMapping) mapping, property);
    mapping.setReferenceClassName(referenceClass.getQualifiedName());
    // here we need to setup source/target key field associations
    if (property.isSetXmlJoinNodes()) {
        for (XmlJoinNode xmlJoinNode : property.getXmlJoinNodes().getXmlJoinNode()) {
            validateJoinNode(descriptor.getJavaClassName(), property, xmlJoinNode.getReferencedXmlPath(), referenceClass);
            mapping.addSourceToTargetKeyFieldAssociation(xmlJoinNode.getXmlPath(), xmlJoinNode.getReferencedXmlPath());
        }
    } else {
        String tgtXPath = null;
        TypeInfo referenceType = typeInfo.get(referenceClass.getQualifiedName());
        if (null != referenceType && referenceType.isIDSet()) {
            Property prop = referenceType.getIDProperty();
            tgtXPath = getXPathForField(prop, namespaceInfo, !prop.isAttribute(), false).getXPath();
        }
        // if the XPath is set (via xml-path) use it, otherwise figure it out
        Field srcXPath;
        if (property.getXmlPath() != null) {
            srcXPath = new XMLField(property.getXmlPath());
        } else {
            srcXPath = getXPathForField(property, namespaceInfo, true, false);
        }
        mapping.addSourceToTargetKeyFieldAssociation(srcXPath.getXPath(), tgtXPath);
    }
    if (property.getInverseReferencePropertyName() != null) {
        mapping.getInverseReferenceMapping().setAttributeName(property.getInverseReferencePropertyName());
        JavaClass backPointerPropertyType = null;
        if (property.getInverseReferencePropertyGetMethodName() != null && property.getInverseReferencePropertySetMethodName() != null && !property.getInverseReferencePropertyGetMethodName().equals("") && !property.getInverseReferencePropertySetMethodName().equals("")) {
            mapping.getInverseReferenceMapping().setGetMethodName(property.getInverseReferencePropertySetMethodName());
            mapping.getInverseReferenceMapping().setSetMethodName(property.getInverseReferencePropertySetMethodName());
            JavaMethod getMethod = referenceClass.getDeclaredMethod(mapping.getInverseReferenceMapping().getGetMethodName(), new JavaClass[] {});
            if (getMethod != null) {
                backPointerPropertyType = getMethod.getReturnType();
            }
        } else {
            JavaField backpointerField = referenceClass.getDeclaredField(property.getInverseReferencePropertyName());
            if (backpointerField != null) {
                backPointerPropertyType = backpointerField.getResolvedType();
            }
        }
        if (helper.isCollectionType(backPointerPropertyType)) {
            mapping.getInverseReferenceMapping().setContainerPolicy(ContainerPolicy.buildDefaultPolicy());
        }
    }
    return mapping;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) XmlJoinNode(org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode) XMLField(org.eclipse.persistence.oxm.XMLField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Field(org.eclipse.persistence.internal.oxm.mappings.Field) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) JavaMethod(org.eclipse.persistence.jaxb.javamodel.JavaMethod) VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) CustomAccessorAttributeAccessor(org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor) JAXBSetMethodAttributeAccessor(org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) MapValueAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor) MethodAttributeAccessor(org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor) InstanceVariableAttributeAccessor(org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 49 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method generateAnyObjectMapping.

public AnyObjectMapping generateAnyObjectMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo) {
    AnyObjectMapping<AbstractSession, AttributeAccessor, ContainerPolicy, XMLConverter, ClassDescriptor, DatabaseField, XMLMarshaller, Session, UnmarshalKeepAsElementPolicy, XMLUnmarshaller, XMLRecord> mapping = new XMLAnyObjectMapping();
    initializeXMLMapping((XMLMapping) mapping, property);
    // if the XPath is set (via xml-path) use it
    if (property.getXmlPath() != null) {
        mapping.setField(new XMLField(property.getXmlPath()));
    }
    Class<?> declaredType = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(property.getActualType().getQualifiedName(), helper.getClassLoader());
    JAXBElementRootConverter jaxbElementRootConverter = new JAXBElementRootConverter(declaredType);
    mapping.setConverter(jaxbElementRootConverter);
    if (property.getDomHandlerClassName() != null) {
        jaxbElementRootConverter.setNestedConverter(new DomHandlerConverter(property.getDomHandlerClassName()));
    }
    if (property.isLax()) {
        mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
    } else {
        mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT);
    }
    if (property.isMixedContent()) {
        mapping.setMixedContent(true);
    } else {
        mapping.setUseXMLRoot(true);
    }
    return mapping;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) XMLConverter(org.eclipse.persistence.oxm.mappings.converters.XMLConverter) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) DomHandlerConverter(org.eclipse.persistence.internal.jaxb.DomHandlerConverter) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) JAXBElementRootConverter(org.eclipse.persistence.internal.jaxb.JAXBElementRootConverter) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) UnmarshalKeepAsElementPolicy(org.eclipse.persistence.oxm.mappings.UnmarshalKeepAsElementPolicy) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) CustomAccessorAttributeAccessor(org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor) JAXBSetMethodAttributeAccessor(org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) MapValueAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor) MethodAttributeAccessor(org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor) InstanceVariableAttributeAccessor(org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) Session(org.eclipse.persistence.sessions.Session) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Example 50 with XMLRecord

use of org.eclipse.persistence.oxm.record.XMLRecord in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method generateXMLCollectionReferenceMapping.

/**
 * Create an XMLCollectionReferenceMapping and add it to the descriptor.
 */
public CollectionReferenceMapping generateXMLCollectionReferenceMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, JavaClass referenceClass) {
    CollectionReferenceMapping<AbstractSession, AttributeAccessor, ContainerPolicy, ClassDescriptor, DatabaseField, UnmarshalRecord, XMLField, XMLRecord> mapping = new XMLCollectionReferenceMapping();
    initializeXMLMapping((XMLMapping) mapping, property);
    initializeXMLContainerMapping(mapping, property.getType().isArray());
    mapping.setUsesSingleNode(property.isXmlList() || (property.isAttribute() && (property.getXmlPath() == null || !property.getXmlPath().contains("/"))));
    String referenceClassName = referenceClass.getQualifiedName();
    JavaClass collectionType = property.getType();
    if (collectionType.isArray()) {
        JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), helper.getClassLoader());
        JavaClass componentType = collectionType.getComponentType();
        if (componentType.isArray()) {
            Class<?> adaptedClass = classToGeneratedClasses.get(componentType.getName());
            referenceClassName = adaptedClass.getName();
            accessor.setAdaptedClassName(referenceClassName);
            JavaClass baseComponentType = getBaseComponentType(componentType);
            if (baseComponentType.isPrimitive()) {
                Class<Object> primitiveClass = XMLConversionManager.getDefaultManager().convertClassNameToClass(baseComponentType.getRawName());
                accessor.setComponentClass(primitiveClass);
            } else {
                accessor.setComponentClassName(baseComponentType.getQualifiedName());
            }
        } else {
            accessor.setComponentClassName(componentType.getQualifiedName());
        }
        mapping.setAttributeAccessor(accessor);
    }
    collectionType = containerClassImpl(collectionType);
    mapping.useCollectionClassName(collectionType.getRawName());
    mapping.setReferenceClassName(referenceClassName);
    // here we need to setup source/target key field associations
    if (property.isSetXmlJoinNodes()) {
        for (XmlJoinNode xmlJoinNode : property.getXmlJoinNodes().getXmlJoinNode()) {
            validateJoinNode(descriptor.getJavaClassName(), property, xmlJoinNode.getReferencedXmlPath(), referenceClass);
            mapping.addSourceToTargetKeyFieldAssociation(xmlJoinNode.getXmlPath(), xmlJoinNode.getReferencedXmlPath());
        }
    } else {
        // here we need to setup source/target key field associations
        TypeInfo referenceType = typeInfo.get(referenceClass.getQualifiedName());
        String tgtXPath = null;
        if (null != referenceType && referenceType.isIDSet()) {
            Property prop = referenceType.getIDProperty();
            tgtXPath = getXPathForField(prop, namespaceInfo, !prop.isAttribute(), false).getXPath();
        }
        // if the XPath is set (via xml-path) use it
        Field srcXPath;
        if (property.getXmlPath() != null) {
            srcXPath = new XMLField(property.getXmlPath());
        } else {
            srcXPath = getXPathForField(property, namespaceInfo, true, false);
        }
        mapping.addSourceToTargetKeyFieldAssociation(srcXPath.getXPath(), tgtXPath);
    }
    if (property.getInverseReferencePropertyName() != null) {
        mapping.getInverseReferenceMapping().setAttributeName(property.getInverseReferencePropertyName());
        JavaClass backPointerPropertyType = null;
        if (property.getInverseReferencePropertyGetMethodName() != null && property.getInverseReferencePropertySetMethodName() != null && !property.getInverseReferencePropertyGetMethodName().equals("") && !property.getInverseReferencePropertySetMethodName().equals("")) {
            mapping.getInverseReferenceMapping().setGetMethodName(property.getInverseReferencePropertySetMethodName());
            mapping.getInverseReferenceMapping().setSetMethodName(property.getInverseReferencePropertySetMethodName());
            JavaMethod getMethod = referenceClass.getDeclaredMethod(mapping.getInverseReferenceMapping().getGetMethodName(), new JavaClass[] {});
            if (getMethod != null) {
                backPointerPropertyType = getMethod.getReturnType();
            }
        } else {
            JavaField backpointerField = referenceClass.getDeclaredField(property.getInverseReferencePropertyName());
            if (backpointerField != null) {
                backPointerPropertyType = backpointerField.getResolvedType();
            }
        }
        if (helper.isCollectionType(backPointerPropertyType)) {
            mapping.getInverseReferenceMapping().setContainerPolicy(ContainerPolicy.buildDefaultPolicy());
        }
    }
    return mapping;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) XMLRecord(org.eclipse.persistence.oxm.record.XMLRecord) XmlJoinNode(org.eclipse.persistence.jaxb.xmlmodel.XmlJoinNodes.XmlJoinNode) XMLField(org.eclipse.persistence.oxm.XMLField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Field(org.eclipse.persistence.internal.oxm.mappings.Field) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) UnmarshalRecord(org.eclipse.persistence.internal.oxm.record.UnmarshalRecord) JavaMethod(org.eclipse.persistence.jaxb.javamodel.JavaMethod) VirtualAttributeAccessor(org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor) CustomAccessorAttributeAccessor(org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor) JAXBSetMethodAttributeAccessor(org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor) AttributeAccessor(org.eclipse.persistence.mappings.AttributeAccessor) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) MapValueAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor) MethodAttributeAccessor(org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor) InstanceVariableAttributeAccessor(org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Aggregations

XMLRecord (org.eclipse.persistence.oxm.record.XMLRecord)50 XMLField (org.eclipse.persistence.oxm.XMLField)19 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)16 DOMRecord (org.eclipse.persistence.oxm.record.DOMRecord)14 Element (org.w3c.dom.Element)11 Vector (java.util.Vector)10 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)10 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)8 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)7 XMLObjectBuilder (org.eclipse.persistence.internal.oxm.XMLObjectBuilder)7 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)6 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)6 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)6 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)6 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)6 JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)6 MapValueAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor)6 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)6 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)6 Field (org.eclipse.persistence.internal.oxm.mappings.Field)5