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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations