Search in sources :

Example 1 with AbstractNullPolicy

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;
}
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 2 with AbstractNullPolicy

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;
}
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 3 with AbstractNullPolicy

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;
}
Also used : AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) IsSetNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy)

Example 4 with AbstractNullPolicy

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);
}
Also used : AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy)

Example 5 with AbstractNullPolicy

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;
}
Also used : XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) XMLField(org.eclipse.persistence.oxm.XMLField) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ElementStyle(org.eclipse.persistence.tools.dbws.NamingConventionTransformer.ElementStyle)

Aggregations

AbstractNullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy)25 QName (javax.xml.namespace.QName)7 CoreContainerPolicy (org.eclipse.persistence.internal.core.queries.CoreContainerPolicy)7 Field (org.eclipse.persistence.internal.oxm.mappings.Field)7 XMLField (org.eclipse.persistence.oxm.XMLField)6 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)5 ArrayList (java.util.ArrayList)4 IsSetNullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.IsSetNullPolicy)4 NullPolicy (org.eclipse.persistence.oxm.mappings.nullpolicy.NullPolicy)4 List (java.util.List)3 XmlAbstractNullPolicy (org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy)3 XmlIsSetNullPolicy (org.eclipse.persistence.jaxb.xmlmodel.XmlIsSetNullPolicy)3 XmlNullPolicy (org.eclipse.persistence.jaxb.xmlmodel.XmlNullPolicy)3 Vector (java.util.Vector)2 Descriptor (org.eclipse.persistence.internal.oxm.mappings.Descriptor)2 UnmarshalKeepAsElementPolicy (org.eclipse.persistence.internal.oxm.mappings.UnmarshalKeepAsElementPolicy)2 MarshalContext (org.eclipse.persistence.internal.oxm.record.MarshalContext)2 ObjectMarshalContext (org.eclipse.persistence.internal.oxm.record.ObjectMarshalContext)2 DataHandler (jakarta.activation.DataHandler)1 JAXBElement (jakarta.xml.bind.JAXBElement)1