use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.
the class DateAndTimeTestCases method testSqlTimeToString_dateTime_dstTimeZone.
public void testSqlTimeToString_dateTime_dstTimeZone() {
XMLConversionManager xmlConversionManager = (XMLConversionManager) XMLConversionManager.getDefaultXMLManager().clone();
xmlConversionManager.setTimeZone(TimeZone.getTimeZone(CONTROL_DST_TIME_ZONE));
xmlConversionManager.setTimeZoneQualified(true);
java.sql.Time sqlTime = xmlConversionManager.convertObject(CONTROL_DST_INPUT_DATE_TIME, Time.class, XMLConstants.DATE_TIME_QNAME);
String testString = xmlConversionManager.convertObject(sqlTime, String.class, XMLConstants.DATE_TIME_QNAME);
assertEquals("2003-08-29T03:00:00" + controlXmlConversionTimeSuffix + "-04:00", testString);
}
use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.
the class DateAndTimeTestCases method testUtilDateToString_default_dstTimeZone.
public void testUtilDateToString_default_dstTimeZone() {
XMLConversionManager xmlConversionManager = (XMLConversionManager) XMLConversionManager.getDefaultXMLManager().clone();
xmlConversionManager.setTimeZone(TimeZone.getTimeZone(CONTROL_DST_TIME_ZONE));
xmlConversionManager.setTimeZoneQualified(true);
java.util.Date utilDate = xmlConversionManager.convertObject(CONTROL_DST_INPUT_DATE_TIME, java.util.Date.class);
String testString = xmlConversionManager.convertObject(utilDate, String.class);
assertEquals("2003-08-29T03:00:00" + controlXmlConversionTimeSuffix + "-04:00", testString);
}
use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.
the class DateAndTimeTestCases method testSqlTimeToString_default_dstTimeZone.
public void testSqlTimeToString_default_dstTimeZone() {
XMLConversionManager xmlConversionManager = (XMLConversionManager) XMLConversionManager.getDefaultXMLManager().clone();
xmlConversionManager.setTimeZone(TimeZone.getTimeZone(CONTROL_DST_TIME_ZONE));
xmlConversionManager.setTimeZoneQualified(true);
java.sql.Time sqlTime = xmlConversionManager.convertObject(CONTROL_DST_INPUT_DATE_TIME, Time.class, XMLConstants.DATE_TIME_QNAME);
String testString = xmlConversionManager.convertObject(sqlTime, String.class);
assertEquals("03:00:00" + controlXmlConversionTimeSuffix + "-04:00", testString);
}
use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.
the class AnnotationsProcessor method buildNewProperty.
/*
* Create a new Property Object and process the annotations that are common
* to fields and methods
*/
Property buildNewProperty(TypeInfo info, JavaClass cls, JavaHasAnnotations javaHasAnnotations, String propertyName, JavaClass ptype) {
Property property = null;
if (helper.isAnnotationPresent(javaHasAnnotations, XmlElements.class)) {
property = buildChoiceProperty(javaHasAnnotations);
} else if (helper.isAnnotationPresent(javaHasAnnotations, XmlElementRef.class) || helper.isAnnotationPresent(javaHasAnnotations, XmlElementRefs.class)) {
findAndProcessObjectFactory(cls);
property = buildReferenceProperty(info, javaHasAnnotations, propertyName, ptype);
if (helper.isAnnotationPresent(javaHasAnnotations, XmlAnyElement.class)) {
XmlAnyElement anyElement = (XmlAnyElement) helper.getAnnotation(javaHasAnnotations, XmlAnyElement.class);
property.setIsAny(true);
if (anyElement.value() != null) {
property.setDomHandlerClassName(anyElement.value().getName());
}
property.setLax(anyElement.lax());
info.setAnyElementPropertyName(propertyName);
}
} else if (helper.isAnnotationPresent(javaHasAnnotations, XmlAnyElement.class)) {
findAndProcessObjectFactory(cls);
XmlAnyElement anyElement = (XmlAnyElement) helper.getAnnotation(javaHasAnnotations, XmlAnyElement.class);
property = new Property(helper);
property.setIsAny(true);
if (anyElement.value() != null) {
property.setDomHandlerClassName(anyElement.value().getName());
}
property.setLax(anyElement.lax());
info.setAnyElementPropertyName(propertyName);
} else if (helper.isAnnotationPresent(javaHasAnnotations, org.eclipse.persistence.oxm.annotations.XmlTransformation.class) || helper.isAnnotationPresent(javaHasAnnotations, org.eclipse.persistence.oxm.annotations.XmlReadTransformer.class) || helper.isAnnotationPresent(javaHasAnnotations, org.eclipse.persistence.oxm.annotations.XmlWriteTransformer.class) || helper.isAnnotationPresent(javaHasAnnotations, XmlWriteTransformers.class)) {
property = buildTransformationProperty(javaHasAnnotations, cls);
} else {
property = new Property(helper);
}
property.setPropertyName(propertyName);
property.setElement(javaHasAnnotations);
// check the class
if (helper.isCollectionType(ptype)) {
JavaClass componentType = helper.getJavaClass(Object.class);
Collection typeArgs = ptype.getActualTypeArguments();
if (!typeArgs.isEmpty()) {
componentType = (JavaClass) typeArgs.iterator().next();
}
updatePropertyType(property, ptype, componentType);
} else {
updatePropertyType(property, ptype, ptype);
}
if (helper.isAnnotationPresent(javaHasAnnotations, XmlVariableNode.class)) {
XmlVariableNode variableNode = (XmlVariableNode) helper.getAnnotation(javaHasAnnotations, XmlVariableNode.class);
if (variableNode.type() != XmlVariableNode.DEFAULT.class) {
property.setVariableClassName(variableNode.type().getName());
JavaClass componentType = helper.getJavaClass(variableNode.type());
if (helper.isCollectionType(ptype)) {
property.setGenericType(componentType);
} else {
property.setType(componentType);
}
}
if (!variableNode.value().equals("##default")) {
property.setVariableAttributeName(variableNode.value());
}
property.setVariableNodeAttribute(variableNode.attribute());
}
if ((ptype.isArray() && !areEquals(ptype, byte[].class)) || (helper.isCollectionType(ptype) && !helper.isAnnotationPresent(javaHasAnnotations, XmlList.class))) {
property.setNillable(true);
}
processPropertyAnnotations(info, cls, javaHasAnnotations, property);
if (helper.isAnnotationPresent(javaHasAnnotations, XmlPath.class)) {
XmlPath xmlPath = (XmlPath) helper.getAnnotation(javaHasAnnotations, XmlPath.class);
property.setXmlPath(xmlPath.value());
Field<XMLConversionManager, NamespaceResolver> tempField = new XMLField(xmlPath.value());
boolean isAttribute = tempField.getLastXPathFragment().isAttribute();
property.setIsAttribute(isAttribute);
// set schema name
String schemaName = XMLProcessor.getNameFromXPath(xmlPath.value(), property.getPropertyName(), isAttribute);
QName qName;
NamespaceInfo nsInfo = getPackageInfoForPackage(cls).getNamespaceInfo();
if (isAttribute) {
if (nsInfo.isAttributeFormQualified()) {
qName = new QName(nsInfo.getNamespace(), schemaName);
} else {
qName = new QName(schemaName);
}
} else {
if (nsInfo.isElementFormQualified()) {
qName = new QName(nsInfo.getNamespace(), schemaName);
} else {
qName = new QName(schemaName);
}
}
property.setSchemaName(qName);
// create properties for any predicates
XPathFragment fragment = tempField.getXPathFragment();
String currentPath = "";
while (fragment != null && !(fragment.nameIsText()) && !(fragment.isAttribute())) {
if (fragment.getPredicate() != null) {
// can't append xpath directly since it will contain the predicate
String fragmentPath = fragment.getLocalName();
if (fragment.getPrefix() != null && !(Constants.EMPTY_STRING.equals(fragment.getPrefix()))) {
fragmentPath = fragment.getPrefix() + ":" + fragmentPath;
}
currentPath += fragmentPath;
String predicatePath = currentPath;
TypeInfo targetInfo = info;
if (fragment.getNextFragment() == null) {
// if this is the last fragment, and there's no text after, then this is
// complex. May need to add the attribute property to the target type.
processReferencedClass(ptype);
TypeInfo predicateTypeInfo = typeInfos.get(ptype.getQualifiedName());
if (predicateTypeInfo != null) {
targetInfo = predicateTypeInfo;
predicatePath = "";
}
}
Property predicateProperty = new Property(helper);
predicateProperty.setType(helper.getJavaClass("java.lang.String"));
if (predicatePath.length() > 0) {
predicatePath += "/";
}
predicatePath += fragment.getPredicate().getXPathFragment().getXPath();
predicateProperty.setXmlPath(predicatePath);
predicateProperty.setIsAttribute(true);
String predschemaName = XMLProcessor.getNameFromXPath(predicatePath, property.getPropertyName(), true);
QName predQname;
if (nsInfo.isAttributeFormQualified()) {
predQname = new QName(nsInfo.getNamespace(), predschemaName);
} else {
predQname = new QName(predschemaName);
}
predicateProperty.setSchemaName(predQname);
if (!targetInfo.hasPredicateProperty(predicateProperty)) {
targetInfo.getPredicateProperties().add(predicateProperty);
}
} else {
currentPath += fragment.getXPath();
}
currentPath += "/";
fragment = fragment.getNextFragment();
}
} else {
property.setSchemaName(getQNameForProperty(property, propertyName, javaHasAnnotations, getPackageInfoForPackage(cls).getNamespaceInfo(), info));
}
ptype = property.getActualType();
if (ptype.isPrimitive()) {
if (property.getType().isArray() && helper.isAnnotationPresent(javaHasAnnotations, XmlElement.class)) {
XmlElement elemAnno = (XmlElement) helper.getAnnotation(javaHasAnnotations, XmlElement.class);
property.setIsRequired(elemAnno.required());
} else {
property.setIsRequired(true);
}
}
// apply class level adapters - don't override property level adapter
if (!property.isSetXmlJavaTypeAdapter()) {
TypeInfo refClassInfo = getTypeInfos().get(ptype.getQualifiedName());
if (refClassInfo != null && refClassInfo.isSetXmlJavaTypeAdapter()) {
org.eclipse.persistence.jaxb.xmlmodel.XmlJavaTypeAdapter xmlJavaTypeAdapter = null;
try {
xmlJavaTypeAdapter = refClassInfo.getXmlJavaTypeAdapter();
property.setXmlJavaTypeAdapter(refClassInfo.getXmlJavaTypeAdapter());
} catch (JAXBException e) {
throw JAXBException.invalidTypeAdapterClass(xmlJavaTypeAdapter.getValue(), cls.getName());
}
}
}
if (property.isXmlTransformation()) {
referencedByTransformer.add(property.getType().getName());
}
return property;
}
use of org.eclipse.persistence.internal.oxm.XMLConversionManager in project eclipselink by eclipse-ee4j.
the class SchemaGenerator method addXmlJoinNodesToSchema.
/**
* Convenience method that processes the XmlJoinNodes for a given Property and adds the
* appropriate components to the schema.
*
* @param property the Property contianing one or more XmlJoinNode entries
* @param compositor the sequence/choice/all that will be added to
* @param schema the schema currently being built
* @param type the complex type currently being built
*/
private void addXmlJoinNodesToSchema(Property property, TypeDefParticle compositor, Schema schema, ComplexType type) {
for (XmlJoinNode xmlJoinNode : property.getXmlJoinNodes().getXmlJoinNode()) {
// create the XPathFragment(s) for the path
Field<XMLConversionManager, NamespaceResolver> xfld = new XMLField(xmlJoinNode.getXmlPath());
xfld.setNamespaceResolver(schema.getNamespaceResolver());
xfld.initialize();
// build the schema components for the xml-path
AddToSchemaResult asr = buildSchemaComponentsForXPath(xfld.getXPathFragment(), new AddToSchemaResult(compositor, schema), false, property);
// process the last fragment
TypeDefParticle currentParticle = asr.particle;
Schema currentSchema = asr.schema;
if (currentParticle.getOwner() instanceof ComplexType) {
type = ((ComplexType) currentParticle.getOwner());
}
// get a QName for the last part of the xpath - this will be used as the
// attribute/element name, and also to figure out if a ref is required
QName schemaName;
XPathFragment frag = xfld.getLastXPathFragment();
boolean isAttribute = xmlJoinNode.getXmlPath().contains(ATT);
// for non-attributes, the last fragment may be 'text()'
if (!isAttribute) {
if (frag.nameIsText()) {
frag = xfld.getXPathFragment();
while (frag.getNextFragment() != null && !frag.getNextFragment().nameIsText()) {
frag = frag.getNextFragment();
}
}
}
schemaName = new QName(frag.getNamespaceURI(), frag.getLocalName());
// handle Element/Attribute
if (isAttribute) {
addAttributeToSchema(buildAttribute(schemaName, Constants.SCHEMA_PREFIX + COLON + Constants.ANY_SIMPLE_TYPE), schemaName, currentSchema, type);
} else {
addElementToSchema(buildElement(schemaName.getLocalPart(), Constants.SCHEMA_PREFIX + COLON + Constants.ANY_SIMPLE_TYPE, currentParticle instanceof All), schemaName.getNamespaceURI(), false, currentParticle, currentSchema, null);
}
}
}
Aggregations