Search in sources :

Example 1 with DomHandlerConverter

use of org.eclipse.persistence.internal.jaxb.DomHandlerConverter in project eclipselink by eclipse-ee4j.

the class MappingsGenerator method generateAnyCollectionMapping.

public AnyCollectionMapping generateAnyCollectionMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, boolean isMixed) {
    AnyCollectionMapping mapping = new XMLAnyCollectionMapping();
    initializeXMLContainerMapping(mapping, property.getType().isArray());
    initializeXMLMapping((XMLMapping) mapping, property);
    // if the XPath is set (via xml-path) use it
    if (property.getXmlPath() != null) {
        mapping.setField(new XMLField(property.getXmlPath()));
    } else {
        if (property.isSetXmlElementWrapper()) {
            mapping.setField(getXPathForField(property, namespaceInfo, false, true));
        }
    }
    if (property.isSetXmlElementWrapper()) {
        mapping.setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
    }
    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() || property.isReference()) {
        mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
    } else {
        if (property.isAny()) {
            mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_ALL_AS_ELEMENT);
        } else {
            mapping.setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_NONE_AS_ELEMENT);
        }
    }
    mapping.setMixedContent(isMixed);
    if (isMixed) {
        mapping.setPreserveWhitespaceForMixedContent(true);
    }
    if (property.isAny()) {
        mapping.setUseXMLRoot(true);
    }
    JavaClass collectionType = property.getType();
    if (collectionType.isArray()) {
        JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), helper.getClassLoader());
        JavaClass componentType = collectionType.getComponentType();
        if (componentType.isArray()) {
            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.useCollectionClass(helper.getClassForJavaClass(collectionType));
    return mapping;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) JAXBElementRootConverter(org.eclipse.persistence.internal.jaxb.JAXBElementRootConverter) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) DomHandlerConverter(org.eclipse.persistence.internal.jaxb.DomHandlerConverter)

Example 2 with DomHandlerConverter

use of org.eclipse.persistence.internal.jaxb.DomHandlerConverter 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)

Aggregations

DomHandlerConverter (org.eclipse.persistence.internal.jaxb.DomHandlerConverter)2 JAXBElementRootConverter (org.eclipse.persistence.internal.jaxb.JAXBElementRootConverter)2 JAXBArrayAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor)2 XMLField (org.eclipse.persistence.oxm.XMLField)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 InstanceVariableAttributeAccessor (org.eclipse.persistence.internal.descriptors.InstanceVariableAttributeAccessor)1 MethodAttributeAccessor (org.eclipse.persistence.internal.descriptors.MethodAttributeAccessor)1 VirtualAttributeAccessor (org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 CustomAccessorAttributeAccessor (org.eclipse.persistence.internal.jaxb.CustomAccessorAttributeAccessor)1 JAXBSetMethodAttributeAccessor (org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor)1 MapValueAttributeAccessor (org.eclipse.persistence.internal.jaxb.many.MapValueAttributeAccessor)1 AnyCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping)1 ContainerPolicy (org.eclipse.persistence.internal.queries.ContainerPolicy)1 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)1 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)1 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)1 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)1 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)1 UnmarshalKeepAsElementPolicy (org.eclipse.persistence.oxm.mappings.UnmarshalKeepAsElementPolicy)1