Search in sources :

Example 1 with NullPolicy

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

the class MappingsGenerator method generateDirectEnumerationMapping.

public DirectMapping generateDirectEnumerationMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, EnumTypeInfo enumInfo) {
    DirectMapping mapping = new XMLDirectMapping();
    initializeXMLMapping((XMLMapping) mapping, property);
    mapping.setNullValueMarshalled(true);
    mapping.setConverter(buildJAXBEnumTypeConverter(mapping, enumInfo));
    // handle null policy set via xml metadata
    if (property.isSetNullPolicy()) {
        mapping.setNullPolicy(getNullPolicyFromProperty(property, getNamespaceResolverForDescriptor(namespaceInfo)));
    } else if (property.isNillable()) {
        mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
        mapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
    }
    mapping.setField(getXPathForField(property, namespaceInfo, true, false));
    if (!mapping.getXPath().equals("text()")) {
        ((NullPolicy) mapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
    }
    return mapping;
}
Also used : IsSetNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy) NullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy) XmlNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping)

Example 2 with NullPolicy

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

the class MappingsGenerator method generateVariableXPathObjectMapping.

private Mapping generateVariableXPathObjectMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, JavaClass actualType) {
    XMLVariableXPathObjectMapping mapping = new XMLVariableXPathObjectMapping();
    initializeXMLMapping(mapping, property);
    initializeVariableXPathMapping(mapping, property, actualType);
    // handle null policy set via xml metadata
    if (property.isSetNullPolicy()) {
        mapping.setNullPolicy(getNullPolicyFromProperty(property, getNamespaceResolverForDescriptor(namespaceInfo)));
    } else {
        NullPolicy nullPolicy = (NullPolicy) mapping.getNullPolicy();
        nullPolicy.setSetPerformedForAbsentNode(false);
        if (property.isNillable()) {
            nullPolicy.setNullRepresentedByXsiNil(true);
            nullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
        }
    }
    if (property.getXmlPath() != null) {
        mapping.setField(new XMLField(property.getXmlPath()));
    } else {
        if (property.isSetXmlElementWrapper()) {
            mapping.setField((XMLField) getXPathForField(property, namespaceInfo, false, true));
        }
    }
    return mapping;
}
Also used : IsSetNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy) NullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy) XmlNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) XMLField(org.eclipse.persistence.oxm.XMLField) XMLVariableXPathObjectMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathObjectMapping)

Example 3 with NullPolicy

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

the class MappingsGenerator method generateBinaryMapping.

public BinaryDataMapping generateBinaryMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo) {
    BinaryDataMapping mapping = new XMLBinaryDataMapping();
    initializeXMLMapping((XMLMapping) mapping, property);
    // if the XPath is set (via xml-path) use it
    mapping.setField(getXPathForField(property, namespaceInfo, false, false));
    if (property.isSwaAttachmentRef()) {
        ((Field) mapping.getField()).setSchemaType(Constants.SWA_REF_QNAME);
        mapping.setSwaRef(true);
    } else if (property.isMtomAttachment()) {
        Field f = ((Field) mapping.getField());
        if (!f.getSchemaType().equals(Constants.HEX_BINARY_QNAME)) {
            f.setSchemaType(Constants.BASE_64_BINARY_QNAME);
        }
    }
    if (property.isInlineBinaryData()) {
        mapping.setShouldInlineBinaryData(true);
    }
    // use a non-dynamic implementation of MimeTypePolicy to wrap the MIME string
    if (property.getMimeType() != null) {
        mapping.setMimeTypePolicy(new FixedMimeTypePolicy(property.getMimeType(), (DatabaseMapping) mapping));
    } else {
        if (areEquals(property.getType(), javax.xml.transform.Source.class)) {
            mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/xml", (DatabaseMapping) mapping));
        } else if (areEquals(property.getType(), java.awt.Image.class)) {
            mapping.setMimeTypePolicy(new FixedMimeTypePolicy("image/png", (DatabaseMapping) mapping));
        } else {
            mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/octet-stream", (DatabaseMapping) mapping));
        }
    }
    if (property.isSetNullPolicy()) {
        mapping.setNullPolicy(getNullPolicyFromProperty(property, getNamespaceResolverForDescriptor(namespaceInfo)));
    } else {
        if (property.isNillable()) {
            mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
            mapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
        }
        mapping.getNullPolicy().setNullRepresentedByEmptyNode(false);
        if (!mapping.getXPath().equals("text()")) {
            ((NullPolicy) mapping.getNullPolicy()).setSetPerformedForAbsentNode(false);
        }
    }
    mapping.setAttributeClassificationName(property.getActualType().getQualifiedName());
    return mapping;
}
Also used : XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) IsSetNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy) NullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy) XmlNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) 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) FixedMimeTypePolicy(org.eclipse.persistence.oxm.mappings.FixedMimeTypePolicy) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) Image(java.awt.Image) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping)

Example 4 with NullPolicy

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

the class MappingsGenerator method getWrapperNullPolicyFromProperty.

private AbstractNullPolicy getWrapperNullPolicyFromProperty(Property property) {
    NullPolicy nullPolicy = null;
    if (property.isSetXmlElementWrapper()) {
        nullPolicy = new NullPolicy();
        nullPolicy.setNullRepresentedByEmptyNode(false);
        nullPolicy.setSetPerformedForAbsentNode(false);
        if (property.getXmlElementWrapper().isNillable()) {
            nullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
            nullPolicy.setNullRepresentedByXsiNil(true);
        } else {
            nullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.ABSENT_NODE);
            nullPolicy.setNullRepresentedByXsiNil(false);
        }
    }
    return nullPolicy;
}
Also used : IsSetNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy) NullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy) XmlNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy)

Example 5 with NullPolicy

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

the class MappingsGenerator method generateCompositeObjectMapping.

public CompositeObjectMapping generateCompositeObjectMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo, String referenceClassName) {
    CompositeObjectMapping mapping = new XMLCompositeObjectMapping();
    initializeXMLMapping((XMLMapping) mapping, property);
    // if the XPath is set (via xml-path) use it; otherwise figure it out
    mapping.setField(getXPathForField(property, namespaceInfo, false, false));
    // handle null policy set via xml metadata
    if (property.isSetNullPolicy()) {
        mapping.setNullPolicy(getNullPolicyFromProperty(property, getNamespaceResolverForDescriptor(namespaceInfo)));
    } else {
        NullPolicy nullPolicy = (NullPolicy) mapping.getNullPolicy();
        nullPolicy.setSetPerformedForAbsentNode(false);
        if (property.isNillable()) {
            nullPolicy.setNullRepresentedByXsiNil(true);
            nullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
        }
    }
    if (referenceClassName == null) {
        setTypedTextField((Field) mapping.getField());
        String defaultValue = property.getDefaultValue();
        if (null != defaultValue) {
            mapping.setConverter(new DefaultElementConverter(defaultValue));
        }
    } else {
        mapping.setReferenceClassName(referenceClassName);
    }
    if (property.isTransientType()) {
        mapping.setReferenceClassName(Constants.UNKNOWN_OR_TRANSIENT_CLASS);
    }
    if (property.isRequired()) {
        ((Field) mapping.getField()).setRequired(true);
    }
    return mapping;
}
Also used : IsSetNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy) NullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy) XmlNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) 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) DefaultElementConverter(org.eclipse.persistence.internal.jaxb.DefaultElementConverter) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Aggregations

NullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy)19 AbstractNullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy)15 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)10 IsSetNullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy)9 XmlAbstractNullPolicy (org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy)8 XmlIsSetNullPolicy (org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy)8 XmlNullPolicy (org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy)8 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)4 XMLField (org.eclipse.persistence.oxm.XMLField)4 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)3 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)3 Field (org.eclipse.persistence.internal.oxm.mappings.Field)3 JavaField (org.eclipse.persistence.jaxb.javamodel.JavaField)3 DirectMapping (org.eclipse.persistence.internal.oxm.mappings.DirectMapping)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2 EnumTypeConverter (org.eclipse.persistence.mappings.converters.EnumTypeConverter)2 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)2 Image (java.awt.Image)1 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1