use of org.eclipse.persistence.internal.jaxb.AccessorFactoryWrapper 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.jaxb.AccessorFactoryWrapper in project eclipselink by eclipse-ee4j.
the class AnnotationsProcessor method processAccessorFactory.
private void processAccessorFactory(JavaClass javaClass, TypeInfo info) {
if (!xmlAccessorFactorySupport) {
return;
}
Annotation xmlAccessorFactory = helper.getAnnotation(javaClass, CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS);
Method valueMethod = null;
if (xmlAccessorFactory != null) {
valueMethod = CompilerHelper.ACCESSOR_FACTORY_VALUE_METHOD;
} else {
// try for internal annotation
xmlAccessorFactory = helper.getAnnotation(javaClass, CompilerHelper.INTERNAL_ACCESSOR_FACTORY_ANNOTATION_CLASS);
if (xmlAccessorFactory != null) {
valueMethod = CompilerHelper.INTERNAL_ACCESSOR_FACTORY_VALUE_METHOD;
}
}
if (xmlAccessorFactory != null) {
Class<?> xmlAccessorFactoryClass = null;
try {
xmlAccessorFactoryClass = PrivilegedAccessHelper.invokeMethod(valueMethod, xmlAccessorFactory, new Object[] {});
info.setXmlAccessorFactory(new AccessorFactoryWrapper(PrivilegedAccessHelper.newInstanceFromClass(xmlAccessorFactoryClass)));
} catch (Exception ex) {
throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
}
}
PackageInfo pInfo = getPackageInfoForPackage(javaClass);
if (pInfo != null) {
info.setPackageLevelXmlAccessorFactory(pInfo.getAccessorFactory());
}
}
use of org.eclipse.persistence.internal.jaxb.AccessorFactoryWrapper in project eclipselink by eclipse-ee4j.
the class AnnotationsProcessor method getPackageInfoForPackage.
public PackageInfo getPackageInfoForPackage(JavaPackage pack, String packageName) {
PackageInfo packageInfo = packageToPackageInfoMappings.get(packageName);
if (packageInfo == null) {
XmlSchema xmlSchema = (XmlSchema) helper.getAnnotation(pack, XmlSchema.class);
packageInfo = new PackageInfo();
NamespaceInfo namespaceInfo = processNamespaceInformation(xmlSchema);
packageInfo.setNamespaceInfo(namespaceInfo);
// if it's still null, generate based on package name
if (namespaceInfo.getNamespace() == null) {
namespaceInfo.setNamespace(EMPTY_STRING);
}
if (helper.isAnnotationPresent(pack, XmlAccessorType.class)) {
XmlAccessorType xmlAccessorType = (XmlAccessorType) helper.getAnnotation(pack, XmlAccessorType.class);
packageInfo.setAccessType(XmlAccessType.fromValue(xmlAccessorType.value().name()));
}
if (helper.isAnnotationPresent(pack, XmlAccessorOrder.class)) {
XmlAccessorOrder xmlAccessorOrder = (XmlAccessorOrder) helper.getAnnotation(pack, XmlAccessorOrder.class);
packageInfo.setAccessOrder(XmlAccessOrder.fromValue(xmlAccessorOrder.value().name()));
}
if (CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS != null && helper.isAnnotationPresent(pack, CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS)) {
Annotation xmlAccessorFactory = helper.getAnnotation(pack, CompilerHelper.ACCESSOR_FACTORY_ANNOTATION_CLASS);
Class<?> xmlAccessorFactoryClass = null;
try {
xmlAccessorFactoryClass = PrivilegedAccessHelper.invokeMethod(CompilerHelper.ACCESSOR_FACTORY_VALUE_METHOD, xmlAccessorFactory, new Object[] {});
packageInfo.setAccessorFactory(new AccessorFactoryWrapper(PrivilegedAccessHelper.newInstanceFromClass(xmlAccessorFactoryClass)));
} catch (Exception ex) {
throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
}
} else if (CompilerHelper.OLD_ACCESSOR_FACTORY_ANNOTATION_CLASS != null && helper.isAnnotationPresent(pack, CompilerHelper.OLD_ACCESSOR_FACTORY_ANNOTATION_CLASS)) {
Annotation xmlAccessorFactory = helper.getAnnotation(pack, CompilerHelper.OLD_ACCESSOR_FACTORY_ANNOTATION_CLASS);
Class<?> xmlAccessorFactoryClass = null;
try {
xmlAccessorFactoryClass = PrivilegedAccessHelper.invokeMethod(CompilerHelper.OLD_ACCESSOR_FACTORY_VALUE_METHOD, xmlAccessorFactory, new Object[] {});
packageInfo.setAccessorFactory(new AccessorFactoryWrapper(PrivilegedAccessHelper.newInstanceFromClass(xmlAccessorFactoryClass)));
} catch (Exception ex) {
throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
}
} else if (CompilerHelper.INTERNAL_ACCESSOR_FACTORY_ANNOTATION_CLASS != null && helper.isAnnotationPresent(pack, CompilerHelper.INTERNAL_ACCESSOR_FACTORY_ANNOTATION_CLASS)) {
Annotation xmlAccessorFactory = helper.getAnnotation(pack, CompilerHelper.INTERNAL_ACCESSOR_FACTORY_ANNOTATION_CLASS);
Class<?> xmlAccessorFactoryClass = null;
try {
xmlAccessorFactoryClass = PrivilegedAccessHelper.invokeMethod(CompilerHelper.INTERNAL_ACCESSOR_FACTORY_VALUE_METHOD, xmlAccessorFactory, new Object[] {});
packageInfo.setAccessorFactory(new AccessorFactoryWrapper(PrivilegedAccessHelper.newInstanceFromClass(xmlAccessorFactoryClass)));
} catch (Exception ex) {
throw JAXBException.errorInstantiatingAccessorFactory(xmlAccessorFactoryClass, ex);
}
}
packageToPackageInfoMappings.put(packageName, packageInfo);
}
return packageInfo;
}
Aggregations