Search in sources :

Example 26 with XMLAnyObjectMapping

use of org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping in project eclipselink by eclipse-ee4j.

the class AnyObjectAndAnyCollectionUC16NoDefaultRootComplexChildrenTestCases method buildRootDescriptor.

protected // 
ClassDescriptor buildRootDescriptor(// 
boolean firstMappingIsAnyCollection, // 
boolean firstMappingXPathSet, // 
boolean secondMappingIsAnyCollection, boolean secondMappingXPathSet) {
    // 
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Customer.class);
    descriptor.setDefaultRootElement("customer");
    DatabaseMapping anyMapping1 = null;
    // First Mapping
    if (!firstMappingIsAnyCollection) {
        anyMapping1 = new XMLAnyObjectMapping();
        anyMapping1.setAttributeName("anyObject");
        // ((XMLAnyObjectMapping) anyMapping1).setSetMethodName("setAnyObject");
        if (firstMappingXPathSet) {
            // set first mapping XPath
            ((XMLAnyObjectMapping) anyMapping1).setXPath(MAPPING_XPATH_OBJ);
        }
        descriptor.addMapping(anyMapping1);
    } else {
        anyMapping1 = new XMLAnyCollectionMapping();
        anyMapping1.setAttributeName("contactMethods");
        // ((XMLAnyCollectionMapping) anyMapping1).setSetMethodName("setAnyCollection");
        if (firstMappingXPathSet) {
            // set first mapping XPath
            ((XMLAnyCollectionMapping) anyMapping1).setXPath(MAPPING_XPATH);
        }
        descriptor.addMapping(anyMapping1);
    }
    // Second Mapping
    DatabaseMapping anyMapping2 = null;
    if (!secondMappingIsAnyCollection) {
        anyMapping2 = new XMLAnyObjectMapping();
        anyMapping2.setAttributeName("anyObject");
        // ((XMLAnyObjectMapping) anyMapping2).setSetMethodName("setAnyObject");
        if (secondMappingXPathSet) {
            // set second mapping XPath
            ((XMLAnyObjectMapping) anyMapping2).setXPath(MAPPING_XPATH_OBJ);
        }
        descriptor.addMapping(anyMapping2);
    } else {
        anyMapping2 = new XMLAnyCollectionMapping();
        anyMapping2.setAttributeName("contactMethods");
        // ((XMLAnyCollectionMapping) anyMapping2).setSetMethodName("setAnyCollection");
        if (secondMappingXPathSet) {
            // set second mapping XPath
            ((XMLAnyCollectionMapping) anyMapping2).setXPath(MAPPING_XPATH);
        }
        descriptor.addMapping(anyMapping2);
    }
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Example 27 with XMLAnyObjectMapping

use of org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping 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 28 with XMLAnyObjectMapping

use of org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping in project eclipselink by eclipse-ee4j.

the class TestModelProject method addRootDescriptor.

public void addRootDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClassName("org.persistence.testing.jaxb.dynamic.xxx.Root");
    descriptor.setNamespaceResolver(nsResolver);
    XMLCompositeObjectMapping compObj = new XMLCompositeObjectMapping();
    compObj.setAttributeName("compObj");
    compObj.setXPath("comp-obj");
    compObj.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CompositeObjectTarget");
    descriptor.addMapping(compObj);
    XMLCompositeCollectionMapping compColl = new XMLCompositeCollectionMapping();
    compColl.setAttributeName("compColl");
    compColl.setXPath("comp-coll/item");
    compColl.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CompositeCollectionTarget");
    compColl.useCollectionClass(ArrayList.class);
    compColl.setContainerPolicy(ContainerPolicy.buildPolicyFor(ArrayList.class));
    descriptor.addMapping(compColl);
    XMLCompositeDirectCollectionMapping compDirColl = new XMLCompositeDirectCollectionMapping();
    compDirColl.setAttributeName("compDirColl");
    compDirColl.setXPath("comp-dir-coll");
    descriptor.addMapping(compDirColl);
    XMLBinaryDataMapping binData = new XMLBinaryDataMapping();
    binData.setAttributeName("binData");
    XMLField binDataField = new XMLField("bin-data");
    binDataField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    binData.setField(binDataField);
    binData.setShouldInlineBinaryData(true);
    descriptor.addMapping(binData);
    XMLBinaryDataCollectionMapping binDataColl = new XMLBinaryDataCollectionMapping();
    binDataColl.setAttributeName("binDataColl");
    XMLField binDataCollField = new XMLField("bin-data-coll");
    binDataCollField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
    binDataColl.setField(binDataCollField);
    binDataColl.setShouldInlineBinaryData(true);
    descriptor.addMapping(binDataColl);
    XMLAnyObjectMapping anyObj = new XMLAnyObjectMapping();
    anyObj.setAttributeName("anyObj");
    anyObj.setField(new XMLField("any-obj"));
    descriptor.addMapping(anyObj);
    XMLCompositeObjectMapping anyAtt = new XMLCompositeObjectMapping();
    anyAtt.setAttributeName("anyAtt");
    anyAtt.setXPath("any-att");
    anyAtt.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.AnyAttributeTarget");
    descriptor.addMapping(anyAtt);
    XMLTransformationMapping transform = new XMLTransformationMapping();
    transform.setAttributeName("transform");
    transform.setAttributeTransformer(new AttributeTransformer());
    transform.addFieldTransformer("transform/first-val/text()", new FirstFieldTransformer());
    transform.addFieldTransformer("transform/second-val/text()", new SecondFieldTransformer());
    descriptor.addMapping(transform);
    XMLFragmentMapping frag = new XMLFragmentMapping();
    frag.setAttributeName("frag");
    frag.setXPath("frag");
    descriptor.addMapping(frag);
    XMLFragmentCollectionMapping fragColl = new XMLFragmentCollectionMapping();
    fragColl.setAttributeName("fragColl");
    fragColl.setXPath("frag-coll");
    fragColl.useCollectionClass(ArrayList.class);
    descriptor.addMapping(fragColl);
    XMLObjectReferenceMapping objRef = new XMLObjectReferenceMapping();
    objRef.setAttributeName("objRef");
    objRef.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.ObjectReferenceTarget");
    objRef.addSourceToTargetKeyFieldAssociation("obj-ref-id/text()", "@id");
    descriptor.addMapping(objRef);
    XMLCollectionReferenceMapping collRef = new XMLCollectionReferenceMapping();
    collRef.setAttributeName("collRef");
    collRef.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CollectionReferenceTarget");
    collRef.addSourceToTargetKeyFieldAssociation("coll-ref-id/text()", "@id");
    descriptor.addMapping(collRef);
    XMLChoiceObjectMapping choice = new XMLChoiceObjectMapping();
    choice.setAttributeName("choice");
    choice.addChoiceElement("choice-int/text()", Integer.class);
    choice.addChoiceElement("choice-float/text()", Float.class);
    descriptor.addMapping(choice);
    XMLChoiceCollectionMapping choiceColl = new XMLChoiceCollectionMapping();
    choiceColl.setAttributeName("choiceColl");
    choiceColl.addChoiceElement("choice-coll-double/text()", Double.class);
    choiceColl.addChoiceElement("choice-coll-string/text()", String.class);
    choiceColl.addChoiceElement("choice-coll-boolean/text()", Boolean.class);
    descriptor.addMapping(choiceColl);
    this.addDescriptor(descriptor);
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) ArrayList(java.util.ArrayList) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) SecondFieldTransformer(org.eclipse.persistence.testing.jaxb.dynamic.util.SecondFieldTransformer) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) XMLFragmentCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentCollectionMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) FirstFieldTransformer(org.eclipse.persistence.testing.jaxb.dynamic.util.FirstFieldTransformer) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) AttributeTransformer(org.eclipse.persistence.testing.jaxb.dynamic.util.AttributeTransformer) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLFragmentMapping(org.eclipse.persistence.oxm.mappings.XMLFragmentMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)

Aggregations

XMLAnyObjectMapping (org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping)28 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)25 XMLAnyCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping)18 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)17 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)4 XMLField (org.eclipse.persistence.oxm.XMLField)3 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)2 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)2 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)2 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)2 InputStream (java.io.InputStream)1 Set (java.util.Set)1 QName (javax.xml.namespace.QName)1 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 DynamicType (org.eclipse.persistence.dynamic.DynamicType)1 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)1