Search in sources :

Example 1 with XmlAbstractNullPolicy

use of org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy 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;
}
Also used : XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) 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) ArrayList(java.util.ArrayList) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) IsSetNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy) XmlNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 2 with XmlAbstractNullPolicy

use of org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy 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;
}
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) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) XmlNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy) QName(javax.xml.namespace.QName) XmlElement(org.eclipse.persistence.jaxb.xmlmodel.XmlElement) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) XmlIsSetNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy) XmlSchemaType(org.eclipse.persistence.jaxb.xmlmodel.XmlSchemaType)

Aggregations

XmlAbstractNullPolicy (org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy)2 XmlIsSetNullPolicy (org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy)2 XmlNullPolicy (org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy)2 AbstractNullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy)2 IsSetNullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy)2 NullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy)2 ArrayList (java.util.ArrayList)1 QName (javax.xml.namespace.QName)1 XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)1 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)1 XmlElement (org.eclipse.persistence.jaxb.xmlmodel.XmlElement)1 XmlSchemaType (org.eclipse.persistence.jaxb.xmlmodel.XmlSchemaType)1