use of org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy 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.jaxb.xmlmodel.XmlIsSetNullPolicy in project eclipselink by eclipse-ee4j.
the class XmlBindingsGenerator method processXMLMapping.
/**
* Process a given XMLMapping and return an XmlElement.
*/
protected static XmlElement processXMLMapping(XMLField xfld, String attName, String xpath, String attClassification, AbstractNullPolicy nullPolicy, boolean isCDATA, String containerName, boolean inlineBinary, boolean isSWARef, String mimeType) {
XmlElement xElt = new XmlElement();
xElt.setJavaAttribute(attName);
xElt.setXmlPath(xpath);
if (xfld.isRequired()) {
xElt.setRequired(true);
}
if (isCDATA) {
xElt.setCdata(true);
}
if (inlineBinary) {
xElt.setXmlInlineBinaryData(true);
}
if (isSWARef) {
xElt.setXmlAttachmentRef(true);
}
if (attClassification != null) {
xElt.setType(attClassification);
}
if (containerName != null) {
xElt.setContainerType(containerName);
}
if (mimeType != null) {
xElt.setXmlMimeType(mimeType);
}
QName schemaType = xfld.getSchemaType();
if (schemaType != null) {
XmlSchemaType xSchemaType = new XmlSchemaType();
xSchemaType.setName(schemaType.getLocalPart());
xElt.setXmlSchemaType(xSchemaType);
}
if (!isDefaultNullPolicy(nullPolicy)) {
XmlAbstractNullPolicy xmlNullPolicy;
if (nullPolicy instanceof NullPolicy) {
xmlNullPolicy = new XmlNullPolicy();
((XmlNullPolicy) xmlNullPolicy).setIsSetPerformedForAbsentNode(nullPolicy.getIsSetPerformedForAbsentNode());
} else {
xmlNullPolicy = new XmlIsSetNullPolicy();
}
xmlNullPolicy.setEmptyNodeRepresentsNull(nullPolicy.isNullRepresentedByEmptyNode());
xmlNullPolicy.setXsiNilRepresentsNull(nullPolicy.isNullRepresentedByXsiNil());
xmlNullPolicy.setNullRepresentationForXml(XmlMarshalNullRepresentation.fromValue(nullPolicy.getMarshalNullRepresentation().toString()));
xElt.setXmlAbstractNullPolicy(new JAXBElement<XmlAbstractNullPolicy>(new QName("http://www.eclipse.org/eclipselink/xsds/persistence/oxm", "xml-null-policy"), XmlAbstractNullPolicy.class, xmlNullPolicy));
}
return xElt;
}
Aggregations