use of org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy 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.AbstractNullPolicy in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method getNullPolicyFromProperty.
/**
* Convenience method which returns an AbstractNullPolicy built from an XmlAbstractNullPolicy.
*
* @param nsr if 'NullRepresentedByXsiNil' is true, this is the resolver
* that we will add the schema instance prefix/uri pair to
* @see org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy
* @see org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy
*/
private AbstractNullPolicy getNullPolicyFromProperty(Property property, NamespaceResolver nsr) {
AbstractNullPolicy absNullPolicy = null;
XmlAbstractNullPolicy xmlAbsNullPolicy = property.getNullPolicy();
// policy is assumed to be one of XmlNullPolicy or XmlIsSetNullPolicy
if (xmlAbsNullPolicy instanceof XmlNullPolicy) {
XmlNullPolicy xmlNullPolicy = (XmlNullPolicy) xmlAbsNullPolicy;
NullPolicy nullPolicy = new NullPolicy();
nullPolicy.setSetPerformedForAbsentNode(xmlNullPolicy.isIsSetPerformedForAbsentNode());
absNullPolicy = nullPolicy;
} else {
XmlIsSetNullPolicy xmlIsSetNullPolicy = (XmlIsSetNullPolicy) xmlAbsNullPolicy;
IsSetNullPolicy isSetNullPolicy = new IsSetNullPolicy();
isSetNullPolicy.setIsSetMethodName(xmlIsSetNullPolicy.getIsSetMethodName());
// handle isSetParams
ArrayList<Object> parameters = new ArrayList<>();
ArrayList<Class<?>> parameterTypes = new ArrayList<>();
List<XmlIsSetNullPolicy.IsSetParameter> params = xmlIsSetNullPolicy.getIsSetParameter();
for (XmlIsSetNullPolicy.IsSetParameter param : params) {
String valueStr = param.getValue();
String typeStr = param.getType();
// create a conversion manager instance with the helper's loader
XMLConversionManager mgr = new XMLConversionManager();
mgr.setLoader(helper.getClassLoader());
// handle parameter type
Class<Object> typeClass = mgr.convertClassNameToClass(typeStr);
// handle parameter value
Object parameterValue = mgr.convertObject(valueStr, typeClass);
parameters.add(parameterValue);
parameterTypes.add(typeClass);
}
isSetNullPolicy.setIsSetParameters(parameters.toArray());
isSetNullPolicy.setIsSetParameterTypes(parameterTypes.toArray(new Class<?>[parameterTypes.size()]));
absNullPolicy = isSetNullPolicy;
}
// handle commmon settings
absNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.valueOf(xmlAbsNullPolicy.getNullRepresentationForXml().name()));
absNullPolicy.setNullRepresentedByEmptyNode(xmlAbsNullPolicy.isEmptyNodeRepresentsNull());
boolean xsiRepresentsNull = xmlAbsNullPolicy.isXsiNilRepresentsNull();
if (xsiRepresentsNull) {
absNullPolicy.setNullRepresentedByXsiNil(true);
}
return absNullPolicy;
}
use of org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy in project eclipselink by eclipse-ee4j.
the class SDOProperty method setIsSetPolicyOnMapping.
/**
* INTERNAL:
* Create and set an IsSetNodePolicy on the mapping - leaving the policy in default state
* @param aMapping
* @param propertyName
* @return
*/
private AbstractNullPolicy setIsSetPolicyOnMapping(XMLNillableMapping aMapping, Object propertyName) {
AbstractNullPolicy aNullPolicy = new IsSetNullPolicy();
// Set the isSet method signature on policy
((IsSetNullPolicy) aNullPolicy).setIsSetMethodName(SDOConstants.SDO_ISSET_METHOD_NAME);
// Set fields even though defaults are set
// aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
// Parameter type is always String
((IsSetNullPolicy) aNullPolicy).setIsSetParameterTypes(new Class<?>[] { ClassConstants.STRING });
((IsSetNullPolicy) aNullPolicy).setIsSetParameters(new Object[] { propertyName });
aMapping.setNullPolicy(aNullPolicy);
return aNullPolicy;
}
use of org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy in project eclipselink by eclipse-ee4j.
the class SDOProperty method setIsSetOptionalPolicyOnMapping.
/**
* INTERNAL
* Alter the default state of the policy to act as an optional non-nillable null policy
* @param aMapping
* @param propertyName
*/
private void setIsSetOptionalPolicyOnMapping(XMLNillableMapping aMapping, Object propertyName) {
AbstractNullPolicy aNullPolicy = setIsSetPolicyOnMapping(aMapping, propertyName);
// Alter unmarshal policy state
aNullPolicy.setNullRepresentedByEmptyNode(false);
aNullPolicy.setNullRepresentedByXsiNil(false);
// Alter marshal policy state
// .ABSENT_NODE);
aNullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE);
}
use of org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy in project eclipselink by eclipse-ee4j.
the class BaseDBWSBuilderHelper method setUpXMLDirectMapping.
protected XMLDirectMapping setUpXMLDirectMapping(String columnName, QName qName, NamingConventionTransformer nct, Class<?> attributeClass, int jdbcType, boolean isPk) {
XMLDirectMapping xdm = null;
// figure out if binary attachments are required
boolean binaryAttach = false;
String attachmentType = null;
if (BASE_64_BINARY_QNAME.equals(qName)) {
// use primitive byte[] array, not object Byte[] array
attributeClass = APBYTE;
for (OperationModel om : dbwsBuilder.operations) {
if (om.isTableOperation()) {
TableOperationModel tom = (TableOperationModel) om;
if (tom.getBinaryAttachment()) {
binaryAttach = true;
if (MTOM_STR.equalsIgnoreCase(tom.getAttachmentType())) {
attachmentType = MTOM_STR;
} else {
attachmentType = SWAREF_STR;
}
// only need one operation to require attachments
break;
}
if (tom.additionalOperations != null && tom.additionalOperations.size() > 0) {
for (OperationModel om2 : tom.additionalOperations) {
if (om2.isProcedureOperation()) {
ProcedureOperationModel pom = (ProcedureOperationModel) om2;
if (pom.getBinaryAttachment()) {
binaryAttach = true;
if (MTOM_STR.equalsIgnoreCase(tom.getAttachmentType())) {
attachmentType = MTOM_STR;
} else {
attachmentType = SWAREF_STR;
}
break;
}
}
}
}
}
}
XMLBinaryDataMapping xbdm = new XMLBinaryDataMapping();
if (binaryAttach) {
if (attachmentType.equals(SWAREF_STR)) {
xbdm.setSwaRef(true);
qName = XMLConstants.SWA_REF_QNAME;
}
} else {
xbdm.setShouldInlineBinaryData(true);
}
xbdm.setMimeType(DEFAULT_ATTACHMENT_MIMETYPE);
xdm = xbdm;
} else {
xdm = new XMLDirectMapping();
}
String fieldName = nct.generateElementAlias(columnName);
xdm.setAttributeName(fieldName);
xdm.setAttributeClassificationName(attributeClass.getName());
String xPath = EMPTY_STRING;
ElementStyle style = nct.styleForElement(columnName);
if (style == ATTRIBUTE) {
xPath += AT_SIGN + fieldName;
} else if (style == ELEMENT) {
xPath += fieldName;
}
if (style == ELEMENT && attributeClass != APBYTE) {
xPath += SLASH_TEXT;
}
xdm.setXPath(xPath);
XMLField xmlField = (XMLField) xdm.getField();
xmlField.setSchemaType(qName);
if (isPk) {
xmlField.setRequired(true);
} else {
AbstractNullPolicy nullPolicy = xdm.getNullPolicy();
nullPolicy.setNullRepresentedByEmptyNode(false);
nullPolicy.setMarshalNullRepresentation(XSI_NIL);
nullPolicy.setNullRepresentedByXsiNil(true);
xdm.setNullPolicy(nullPolicy);
}
return xdm;
}
Aggregations