use of org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor in project eclipselink by eclipse-ee4j.
the class MappingAccessor method setAccessorMethods.
/**
* INTERNAL:
* Set the getter and setter access methods for this accessor.
*/
protected void setAccessorMethods(DatabaseMapping mapping) {
if (usesPropertyAccess() || usesVirtualAccess()) {
if (usesVirtualAccess()) {
mapping.setAttributeAccessor(new VirtualAttributeAccessor());
}
mapping.setGetMethodName(getGetMethodName());
mapping.setSetMethodName(getSetMethodName());
}
}
use of org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateMappings.
/**
* Generate mappings for a given TypeInfo.
*/
public void generateMappings(TypeInfo info, Descriptor descriptor, JavaClass descriptorJavaClass, NamespaceInfo namespaceInfo) {
if (info.isAnonymousComplexType()) {
// may need to generate inherited mappings
generateInheritedMappingsForAnonymousType(info, descriptor, descriptorJavaClass, namespaceInfo);
}
List<Property> propertiesInOrder = info.getNonTransientPropertiesInPropOrder();
for (int i = 0; i < propertiesInOrder.size(); i++) {
Property next = propertiesInOrder.get(i);
if (next != null && (!next.isTransient() || (next.isTransient() && next.isXmlLocation()))) {
Mapping mapping = generateMapping(next, descriptor, descriptorJavaClass, namespaceInfo);
if (next.isVirtual()) {
VirtualAttributeAccessor accessor = new VirtualAttributeAccessor();
accessor.setAttributeName(mapping.getAttributeName());
String getMethod = info.getXmlVirtualAccessMethods().getGetMethod();
String setMethod = info.getXmlVirtualAccessMethods().getSetMethod();
// Check to see if get/set were overridden in the mapping
if (mapping.getAttributeAccessor().isMethodAttributeAccessor()) {
getMethod = ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getGetMethodName();
setMethod = ((MethodAttributeAccessor) mapping.getAttributeAccessor()).getSetMethodName();
accessor.setValueType(mapping.getAttributeClassification());
}
accessor.setGetMethodName(getMethod);
accessor.setSetMethodName(setMethod);
if (mapping.getAttributeAccessor() instanceof JAXBArrayAttributeAccessor) {
JAXBArrayAttributeAccessor jaa = (JAXBArrayAttributeAccessor) mapping.getAttributeAccessor();
jaa.setNestedAccessor(accessor);
} else {
mapping.setAttributeAccessor(accessor);
}
}
if (mapping != null) {
descriptor.addMapping((CoreMapping) mapping);
}
// set user-defined properties if necessary
if (next.isSetUserProperties()) {
mapping.setProperties(next.getUserProperties());
}
// get package info
AccessorFactoryWrapper accessorFactory = info.getXmlAccessorFactory();
if (accessorFactory == null) {
accessorFactory = info.getPackageLevelXmlAccessorFactory();
}
if (accessorFactory != null) {
try {
Object accessor = CompilerHelper.createAccessorFor(descriptorJavaClass, next, helper, accessorFactory);
if (accessor != null) {
CustomAccessorAttributeAccessor attributeAccessor = new CustomAccessorAttributeAccessor(accessor);
mapping.setAttributeAccessor(attributeAccessor);
}
} catch (Exception ex) {
}
}
}
next.postInitialize();
}
}
use of org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor in project eclipselink by eclipse-ee4j.
the class PreLoginMappingAdapter method copyAccessorToMapping.
/**
* Update the targetMapping to have the same accessor as the originMapping
*/
private static void copyAccessorToMapping(DatabaseMapping originMapping, DatabaseMapping targetMapping) {
if (originMapping.getAttributeAccessor().isVirtualAttributeAccessor()) {
VirtualAttributeAccessor accessor = new VirtualAttributeAccessor();
accessor.setGetMethodName(originMapping.getGetMethodName());
accessor.setSetMethodName(originMapping.getSetMethodName());
targetMapping.setAttributeAccessor(accessor);
}
if (originMapping.getAttributeAccessor().isValuesAccessor()) {
ValuesAccessor accessor = new ValuesAccessor(originMapping);
accessor.setAttributeName(originMapping.getAttributeAccessor().getAttributeName());
targetMapping.setAttributeAccessor(accessor);
} else {
targetMapping.setAttributeName(originMapping.getAttributeName());
targetMapping.setGetMethodName(originMapping.getGetMethodName());
targetMapping.setSetMethodName(originMapping.getSetMethodName());
}
}
use of org.eclipse.persistence.internal.descriptors.VirtualAttributeAccessor in project eclipselink by eclipse-ee4j.
the class DynamicXMLMetadataSource method createJAXBProperty.
/**
* Create a JAXB property for a particular mapping.
* This will only create JAXBProperties for mappings that are virtual - either because their
* parent object is a dynamic class, or because the owning static class has virtual properties
*/
private JAXBElement<XmlElement> createJAXBProperty(DatabaseMapping mapping, ObjectFactory objectFactory, JavaType owningType, boolean isDynamic) {
if (!mapping.getAttributeAccessor().isVirtualAttributeAccessor() && !isDynamic) {
return null;
}
XmlElement xmlElement = new XmlElement();
xmlElement.setJavaAttribute(mapping.getAttributeName());
if (mapping.isObjectReferenceMapping()) {
xmlElement.setType(((ObjectReferenceMapping) mapping).getReferenceClassName());
} else if (mapping.isCollectionMapping()) {
if (mapping.isEISMapping()) {
// It will be fine for simple collections
if (mapping instanceof EISCompositeDirectCollectionMapping) {
xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
} else if (mapping instanceof EISCompositeCollectionMapping) {
xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
xmlElement.setType(((EISCompositeCollectionMapping) mapping).getReferenceClassName());
}
} else {
xmlElement.setType(((CollectionMapping) mapping).getReferenceClassName());
xmlElement.setContainerType(mapping.getContainerPolicy().getContainerClassName());
}
} else {
xmlElement.setType(mapping.getAttributeClassification().getName());
}
if (mapping.getAttributeAccessor().isVirtualAttributeAccessor()) {
VirtualAttributeAccessor jpaAccessor = (VirtualAttributeAccessor) mapping.getAttributeAccessor();
if (owningType.getXmlVirtualAccessMethods() == null) {
XmlVirtualAccessMethods virtualAccessMethods = new XmlVirtualAccessMethods();
virtualAccessMethods.setGetMethod(jpaAccessor.getGetMethodName());
virtualAccessMethods.setSetMethod(jpaAccessor.getSetMethodName());
owningType.setXmlVirtualAccessMethods(virtualAccessMethods);
} else if (!owningType.getXmlVirtualAccessMethods().getGetMethod().equals(jpaAccessor.getGetMethodName())) {
XmlAccessMethods accessMethods = new XmlAccessMethods();
accessMethods.setGetMethod(jpaAccessor.getGetMethodName());
accessMethods.setSetMethod(jpaAccessor.getSetMethodName());
xmlElement.setXmlAccessMethods(accessMethods);
}
}
return objectFactory.createXmlElement(xmlElement);
}
Aggregations