use of org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor 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.internal.jaxb.JAXBSetMethodAttributeAccessor in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method initializeXMLMapping.
private void initializeXMLMapping(XMLMapping mapping, Property property) {
mapping.setAttributeName(property.getPropertyName());
// handle read-only set via metadata
if (property.isSetReadOnly()) {
mapping.setIsReadOnly(property.isReadOnly());
}
// handle write-only set via metadata
if (property.isSetWriteOnly()) {
mapping.setIsWriteOnly(property.isWriteOnly());
}
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.setIsReadOnly(true);
mapping.setSetMethodName(property.getSetMethodName());
} else if (property.getSetMethodName() == null) {
mapping.setGetMethodName(property.getGetMethodName());
mapping.setIsWriteOnly(true);
} else {
mapping.setSetMethodName(property.getSetMethodName());
mapping.setGetMethodName(property.getGetMethodName());
}
}
}
use of org.eclipse.persistence.internal.jaxb.JAXBSetMethodAttributeAccessor in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method initializeVariableXPathMapping.
private void initializeVariableXPathMapping(VariableXPathObjectMapping mapping, Property property, JavaClass actualType) {
String variableAttributeName = property.getVariableAttributeName();
TypeInfo refInfo = typeInfo.get(actualType.getName());
if (refInfo == null) {
throw JAXBException.unknownTypeForVariableNode(actualType.getName());
}
Property refProperty = refInfo.getProperties().get(variableAttributeName);
while (refProperty == null) {
JavaClass superClass = CompilerHelper.getNextMappedSuperClass(actualType, typeInfo, helper);
if (superClass != null) {
refInfo = typeInfo.get(superClass.getName());
refProperty = refInfo.getProperties().get(variableAttributeName);
} else {
break;
}
}
if (refProperty == null) {
throw JAXBException.unknownPropertyForVariableNode(variableAttributeName, actualType.getName());
}
String refPropertyType = refProperty.getActualType().getQualifiedName();
if (!(refPropertyType.equals("java.lang.String") || refPropertyType.equals("javax.xml.namespace.QName"))) {
throw JAXBException.invalidTypeForVariableNode(variableAttributeName, refPropertyType, actualType.getName());
}
if (refProperty.isMethodProperty()) {
if (refProperty.getGetMethodName() == null) {
// handle case of set with no get method
String paramTypeAsString = refProperty.getType().getName();
JAXBSetMethodAttributeAccessor accessor = new JAXBSetMethodAttributeAccessor(paramTypeAsString, helper.getClassLoader());
accessor.setIsReadOnly(true);
accessor.setSetMethodName(refProperty.getSetMethodName());
mapping.setIsReadOnly(true);
accessor.setAttributeName("thingBLAH");
mapping.setVariableAttributeAccessor(accessor);
} else if (refProperty.getSetMethodName() == null) {
mapping.setVariableGetMethodName(refProperty.getGetMethodName());
} else {
mapping.setVariableGetMethodName(refProperty.getGetMethodName());
mapping.setVariableSetMethodName(refProperty.getSetMethodName());
}
} else {
mapping.setVariableAttributeName(property.getVariableAttributeName());
}
if (property.getVariableClassName() != null) {
mapping.setReferenceClassName(property.getVariableClassName());
} else {
mapping.setReferenceClassName(actualType.getQualifiedName());
}
mapping.setAttribute(property.isVariableNodeAttribute());
}
Aggregations