use of org.eclipse.persistence.jaxb.xmlmodel.XmlElement 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);
}
use of org.eclipse.persistence.jaxb.xmlmodel.XmlElement in project eclipselink by eclipse-ee4j.
the class DynamicXMLMetadataSource method createJAXBType.
/**
* Create a javaType to be used by JAXB to map a particular class.
* For static classes, JAXB annotations, xml and defaults will be used to map the class.
* For Dynamic classes we create properties for each JPA mapping on the class
* thing we create is a
*/
private JavaType createJAXBType(ClassDescriptor classDescriptor, ObjectFactory objectFactory) {
JavaType javaType = new JavaType();
String alias = classDescriptor.getAlias();
if (alias == null || alias.isEmpty()) {
alias = classDescriptor.getJavaClass().getSimpleName();
}
javaType.setName(alias);
javaType.setJavaAttributes(new JavaAttributes());
boolean isDynamic = DynamicEntity.class.isAssignableFrom(classDescriptor.getJavaClass());
for (DatabaseMapping ormMapping : classDescriptor.getMappings()) {
JAXBElement<XmlElement> element = createJAXBProperty(ormMapping, objectFactory, javaType, isDynamic);
if (element != null) {
javaType.getJavaAttributes().getJavaAttribute().add(element);
}
}
// Embeddables don't need Rest adapters, return if the classDescriptor is an aggregate descriptor.
if (classDescriptor.isAggregateDescriptor()) {
return javaType;
}
// Set an adapter that is a subclass of ReferenceAdapter that can adapt the class to create a link for
// the persistence_href field that has been weaved in.
String name = RestAdapterClassWriter.constructClassNameForReferenceAdapter(classDescriptor.getJavaClassName());
XmlJavaTypeAdapter adapter = new XmlJavaTypeAdapter();
adapter.setValue(name);
adapter.setValueType(classDescriptor.getJavaClassName());
adapter.setType(classDescriptor.getJavaClassName());
javaType.setXmlJavaTypeAdapter(adapter);
return javaType;
}
use of org.eclipse.persistence.jaxb.xmlmodel.XmlElement in project eclipselink by eclipse-ee4j.
the class DynamicXmlV2MetadataSource method createProperty.
/**
* Create a JAXB property for given reference mapping.
*/
private JAXBElement<XmlElement> createProperty(ForeignReferenceMapping mapping, ObjectFactory objectFactory) {
final String referenceClassName = mapping.getReferenceClassName();
final XmlElement xmlElement = new XmlElement();
xmlElement.setJavaAttribute(mapping.getAttributeName());
xmlElement.setType(referenceClassName);
final String adapterName = RestReferenceAdapterV2ClassWriter.getClassName(referenceClassName);
final XmlJavaTypeAdapter adapter = new XmlJavaTypeAdapter();
adapter.setValue(adapterName);
adapter.setType(referenceClassName);
xmlElement.setXmlJavaTypeAdapter(adapter);
return objectFactory.createXmlElement(xmlElement);
}
use of org.eclipse.persistence.jaxb.xmlmodel.XmlElement in project eclipselink by eclipse-ee4j.
the class DynamicXmlV2MetadataSource method createCollectionProperty.
/**
* Create a JAXB property for given collection mapping.
*/
private JAXBElement<XmlElement> createCollectionProperty(DatabaseMapping mapping, ObjectFactory objectFactory) {
final XmlElement xmlElement = new XmlElement();
xmlElement.setJavaAttribute(mapping.getAttributeName());
xmlElement.setType(((CollectionMapping) mapping).getReferenceClassName());
final XmlJavaTypeAdapter adapter = new XmlJavaTypeAdapter();
final String adapterName = RestCollectionAdapterClassWriter.getClassName(((CollectionMapping) mapping).getReferenceClassName());
adapter.setValue(adapterName);
adapter.setType(Collection.class.getName());
xmlElement.setXmlJavaTypeAdapter(adapter);
return objectFactory.createXmlElement(xmlElement);
}
use of org.eclipse.persistence.jaxb.xmlmodel.XmlElement in project eclipselink by eclipse-ee4j.
the class DynamicXmlV2MetadataSource method createJAXBType.
/**
* Create a javaType to be used by JAXB to map a particular class.
*/
private JavaType createJAXBType(ClassDescriptor classDescriptor, ObjectFactory objectFactory) {
JavaType javaType = new JavaType();
String alias = classDescriptor.getAlias();
if (alias == null || alias.isEmpty()) {
alias = classDescriptor.getJavaClass().getSimpleName();
}
javaType.setName(alias);
final JavaAttributes javaAttributes = new JavaAttributes();
for (DatabaseMapping ormMapping : classDescriptor.getMappings()) {
JAXBElement<XmlElement> element = null;
if (ormMapping instanceof DirectCollectionMapping) {
// Direct mapping -> no adapter
continue;
} else if (ormMapping.isCollectionMapping()) {
// This is a collection mapping -> create collection adapter
element = createCollectionProperty(ormMapping, objectFactory);
} else if (ForeignReferenceMapping.class.isAssignableFrom(ormMapping.getClass())) {
// FK mapping -> create reference adapter
element = createProperty((ForeignReferenceMapping) ormMapping, objectFactory);
}
if (element != null) {
javaAttributes.getJavaAttribute().add(element);
}
}
if (!javaAttributes.getJavaAttribute().isEmpty()) {
javaType.setJavaAttributes(javaAttributes);
}
return javaType;
}
Aggregations