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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations