Search in sources :

Example 1 with XMLConversionManager

use of org.eclipse.persistence.internal.oxm.XMLConversionManager 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 XMLConversionManager

use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.

the class Property method isPositional.

/**
 * Indicates if this property is mapped by position, i.e. 'name="data[1]"',
 * or is mapped by attribute value (predicate mapping), i.e.
 * 'personal-info[@pi-type='last-name']/name[@name-type='surname']/text()'
 */
public boolean isPositional() {
    if (getXmlPath() == null) {
        return false;
    }
    Field<XMLConversionManager, NamespaceResolver> field = new XMLField(getXmlPath());
    XPathFragment frag = field.getXPathFragment();
    // loop until we have the last non-null, non-attribute, non-text fragment
    while (true) {
        if (frag.getNextFragment() != null && !frag.getNextFragment().isAttribute() && !frag.getNextFragment().nameIsText()) {
            frag = frag.getNextFragment();
        } else {
            break;
        }
    }
    return frag.containsIndex() || frag.getPredicate() != null;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XPathFragment(org.eclipse.persistence.internal.oxm.XPathFragment) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 3 with XMLConversionManager

use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.

the class SchemaGenerator method addXPathToSchema.

/**
 * Process a given XmlPath, and create the required schema components.  The last
 * fragment may not be processed; in this case the returned XmlPathResult is
 * used to set the current schema and parent complex type, then the owning
 * property is processed as per usual. Note the last fragment may be processed
 * if it has a namespace or is an 'any'.
 *
 * @param property the property containing the XmlPath for which schema components are to be built
 * @param compositor the sequence/choice/all to modify
 * @param schema the schema being built when this method is called - this could
 *        if the XmlPath contains an entry that references a different namespace
 * @param isChoice indicates if the given property is a choice property
 * @param type the ComplexType which compositor(s) should be added to
 * @return AddToSchemaResult containing current schema and sequence/all/choice build
 *         based on the given XmlPath
 */
private AddToSchemaResult addXPathToSchema(Property property, TypeDefParticle compositor, Schema schema, boolean isChoice, ComplexType type) {
    // '.' xml-path requires special handling
    if (property.getXmlPath().equals(DOT)) {
        TypeInfo info = typeInfo.get(property.getActualType().getQualifiedName());
        JavaClass infoClass = property.getActualType();
        addSelfProperties(infoClass, info, compositor, type);
        return null;
    }
    // create the XPathFragment(s) for the path
    Field<XMLConversionManager, NamespaceResolver> xfld = new XMLField(property.getXmlPath());
    xfld.setNamespaceResolver(schema.getNamespaceResolver());
    xfld.initialize();
    // build the schema components for the xml-path
    return buildSchemaComponentsForXPath(xfld.getXPathFragment(), new AddToSchemaResult(compositor, schema), isChoice, property);
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 4 with XMLConversionManager

use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.

the class DynamicJAXBContextFactory method fixDateTimeConversion.

/**
 * Ensures that XSD dateTimes will always be unmarshalled as XMLGregorianCalendars, and never
 * as GregorianCalendars.  CALENDAR entries are removed from the default XMLConversionManager,
 * and replaced with XML_GREGORIAN_CALENDAR.
 */
private static void fixDateTimeConversion(DynamicJAXBContext ctx) {
    XMLConversionManager conversionManager = (XMLConversionManager) ctx.getXMLContext().getSession().getDatasourcePlatform().getConversionManager();
    Map<QName, Class<?>> defaultXmlTypes = XMLConversionManager.getDefaultXMLTypes();
    defaultXmlTypes.remove(Constants.DATE_TIME_QNAME);
    defaultXmlTypes.put(Constants.DATE_TIME_QNAME, CoreClassConstants.XML_GREGORIAN_CALENDAR);
    Map<Class<?>, QName> defaultJavaTypes = XMLConversionManager.getDefaultJavaTypes();
    defaultJavaTypes.remove(CoreClassConstants.CALENDAR);
    defaultJavaTypes.put(CoreClassConstants.XML_GREGORIAN_CALENDAR, Constants.DATE_TIME_QNAME);
}
Also used : QName(javax.xml.namespace.QName) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Example 5 with XMLConversionManager

use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.

the class SDOXMLHelperDelegate method getXmlContext.

@Override
public synchronized XMLContext getXmlContext() {
    if (xmlContext == null) {
        xmlContext = new XMLContext(getTopLinkProject());
        XMLConversionManager xmlConversionManager = getXmlConversionManager();
        xmlConversionManager.setLoader(this.loader);
        xmlConversionManager.setTimeZone(TimeZone.getTimeZone("GMT"));
        xmlConversionManager.setTimeZoneQualified(true);
    }
    return xmlContext;
}
Also used : XMLContext(org.eclipse.persistence.oxm.XMLContext) XMLConversionManager(org.eclipse.persistence.internal.oxm.XMLConversionManager)

Aggregations

XMLConversionManager (org.eclipse.persistence.internal.oxm.XMLConversionManager)34 XMLField (org.eclipse.persistence.oxm.XMLField)12 QName (javax.xml.namespace.QName)10 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)8 ArrayList (java.util.ArrayList)6 Element (org.w3c.dom.Element)6 Time (java.sql.Time)4 Timestamp (java.sql.Timestamp)4 Vector (java.util.Vector)3 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)3 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)3 SDOType (org.eclipse.persistence.sdo.SDOType)3 DataObject (commonj.sdo.DataObject)2 Property (commonj.sdo.Property)2 Type (commonj.sdo.Type)2 DataHandler (jakarta.activation.DataHandler)2 List (java.util.List)2 XMLMarshalException (org.eclipse.persistence.exceptions.XMLMarshalException)2 XMLBinaryDataHelper (org.eclipse.persistence.internal.oxm.XMLBinaryDataHelper)2 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)2