use of org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateTransformationMapping.
/**
* Generate an XMLTransformationMapping based on a given Property.
*/
public TransformationMapping generateTransformationMapping(Property property, Descriptor descriptor, NamespaceInfo namespace) {
TransformationMapping<AbstractSession, AttributeAccessor, ContainerPolicy, ClassDescriptor, DatabaseField, XMLTransformationRecord, XMLRecord> mapping = new XMLTransformationMapping();
if (property.isMethodProperty()) {
if (property.getGetMethodName() == null) {
// handle case of set with no get method
String paramTypeAsString = property.getType().getName();
mapping.setAttributeAccessor(new JAXBSetMethodAttributeAccessor(paramTypeAsString, helper.getClassLoader()));
mapping.setSetMethodName(property.getSetMethodName());
} else if (property.getSetMethodName() == null) {
mapping.setGetMethodName(property.getGetMethodName());
} else {
mapping.setSetMethodName(property.getSetMethodName());
mapping.setGetMethodName(property.getGetMethodName());
}
}
// handle transformation
if (property.isSetXmlTransformation()) {
XmlTransformation xmlTransformation = property.getXmlTransformation();
mapping.setIsOptional(xmlTransformation.isOptional());
// handle transformer(s)
if (xmlTransformation.isSetXmlReadTransformer()) {
// handle read transformer
mapping.setAttributeName(property.getPropertyName());
XmlReadTransformer readTransformer = xmlTransformation.getXmlReadTransformer();
if (readTransformer.isSetTransformerClass()) {
mapping.setAttributeTransformerClassName(xmlTransformation.getXmlReadTransformer().getTransformerClass());
} else {
mapping.setAttributeTransformation(xmlTransformation.getXmlReadTransformer().getMethod());
}
}
if (xmlTransformation.isSetXmlWriteTransformers()) {
// handle write transformer(s)
for (XmlWriteTransformer writeTransformer : xmlTransformation.getXmlWriteTransformer()) {
if (writeTransformer.isSetTransformerClass()) {
mapping.addFieldTransformerClassName(writeTransformer.getXmlPath(), writeTransformer.getTransformerClass());
} else {
mapping.addFieldTransformation(writeTransformer.getXmlPath(), writeTransformer.getMethod());
}
}
}
}
return mapping;
}
use of org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer in project eclipselink by eclipse-ee4j.
the class AnnotationsProcessor method buildTransformationProperty.
private Property buildTransformationProperty(JavaHasAnnotations javaHasAnnotations, JavaClass cls) {
Property property = new Property(helper);
org.eclipse.persistence.oxm.annotations.XmlTransformation transformationAnnotation = (org.eclipse.persistence.oxm.annotations.XmlTransformation) helper.getAnnotation(javaHasAnnotations, org.eclipse.persistence.oxm.annotations.XmlTransformation.class);
XmlTransformation transformation = new XmlTransformation();
if (transformationAnnotation != null) {
transformation.setOptional(transformationAnnotation.optional());
}
// Read Transformer
org.eclipse.persistence.oxm.annotations.XmlReadTransformer readTransformer = (org.eclipse.persistence.oxm.annotations.XmlReadTransformer) helper.getAnnotation(javaHasAnnotations, org.eclipse.persistence.oxm.annotations.XmlReadTransformer.class);
if (readTransformer != null) {
org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlReadTransformer xmlReadTransformer = new org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlReadTransformer();
if (!(readTransformer.transformerClass() == AttributeTransformer.class)) {
xmlReadTransformer.setTransformerClass(readTransformer.transformerClass().getName());
} else if (!(readTransformer.method().equals(EMPTY_STRING))) {
xmlReadTransformer.setMethod(readTransformer.method());
}
transformation.setXmlReadTransformer(xmlReadTransformer);
}
// Handle Write Transformers
org.eclipse.persistence.oxm.annotations.XmlWriteTransformer[] transformers = null;
if (helper.isAnnotationPresent(javaHasAnnotations, org.eclipse.persistence.oxm.annotations.XmlWriteTransformer.class)) {
org.eclipse.persistence.oxm.annotations.XmlWriteTransformer writeTransformer = (org.eclipse.persistence.oxm.annotations.XmlWriteTransformer) helper.getAnnotation(javaHasAnnotations, org.eclipse.persistence.oxm.annotations.XmlWriteTransformer.class);
transformers = new org.eclipse.persistence.oxm.annotations.XmlWriteTransformer[] { writeTransformer };
} else if (helper.isAnnotationPresent(javaHasAnnotations, XmlWriteTransformers.class)) {
XmlWriteTransformers writeTransformers = (XmlWriteTransformers) helper.getAnnotation(javaHasAnnotations, XmlWriteTransformers.class);
transformers = writeTransformers.value();
}
if (transformers != null) {
for (org.eclipse.persistence.oxm.annotations.XmlWriteTransformer next : transformers) {
org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer xmlWriteTransformer = new org.eclipse.persistence.jaxb.xmlmodel.XmlTransformation.XmlWriteTransformer();
if (!(next.transformerClass() == FieldTransformer.class)) {
xmlWriteTransformer.setTransformerClass(next.transformerClass().getName());
} else if (!(next.method().equals(EMPTY_STRING))) {
xmlWriteTransformer.setMethod(next.method());
}
xmlWriteTransformer.setXmlPath(next.xmlPath());
transformation.getXmlWriteTransformer().add(xmlWriteTransformer);
}
}
property.setXmlTransformation(transformation);
property.setIsXmlTransformation(true);
return property;
}
Aggregations