use of org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping in project aai-aai-common by onap.
the class FromOxmVertexSchema method fromOxm.
public void fromOxm(String vertexType, DynamicJAXBContext jaxbContext, HashMap<String, DynamicType> xmlElementLookup) throws SchemaProviderException {
name = vertexType;
properties = new HashMap<String, PropertySchema>();
annotations = new HashMap<String, String>();
String javaTypeName = CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, vertexType);
DynamicType modelObjectType = jaxbContext.getDynamicType(javaTypeName);
if (modelObjectType == null) {
// Try to lookup by xml root element by exact match
modelObjectType = xmlElementLookup.get(vertexType);
}
if (modelObjectType == null) {
// Try to lookup by xml root element by lowercase
modelObjectType = xmlElementLookup.get(vertexType.toLowerCase());
}
if (modelObjectType == null) {
// Direct lookup as java-type name
modelObjectType = jaxbContext.getDynamicType(vertexType);
}
if (modelObjectType == null) {
// Vertex isn't found in the OXM
throw new SchemaProviderException("Vertex " + vertexType + " not found in OXM");
}
// Check annotations
Map<String, Object> oxmProps = modelObjectType.getDescriptor().getProperties();
for (Map.Entry<String, Object> entry : oxmProps.entrySet()) {
if (entry.getValue() instanceof String) {
annotations.put(entry.getKey().toLowerCase(), (String) entry.getValue());
}
}
// Regular props
for (DatabaseMapping mapping : modelObjectType.getDescriptor().getMappings()) {
if (mapping instanceof XMLAnyObjectMapping)
continue;
if (mapping instanceof XMLAnyCollectionMapping)
continue;
FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
propSchema.fromOxm(mapping, modelObjectType, false);
properties.put(propSchema.getName().toLowerCase(), propSchema);
}
// Reserved Props
final DynamicType reservedType = jaxbContext.getDynamicType("ReservedPropNames");
for (DatabaseMapping mapping : reservedType.getDescriptor().getMappings()) {
if (mapping.isAbstractDirectMapping()) {
FromOxmPropertySchema propSchema = new FromOxmPropertySchema();
propSchema.fromOxm(mapping, reservedType, true);
properties.put(propSchema.getName().toLowerCase(), propSchema);
}
}
}
use of org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping in project eclipselink by eclipse-ee4j.
the class CustomerProject method getCustomerDescriptor.
private XMLDescriptor getCustomerDescriptor() {
XMLDescriptor xmlDescriptor = new XMLDescriptor();
xmlDescriptor.setJavaClass(Customer.class);
xmlDescriptor.setDefaultRootElement("customer");
XMLCompositeObjectMapping addressMapping = new XMLCompositeObjectMapping();
addressMapping.setReferenceClass(Address.class);
addressMapping.setAttributeName("address");
addressMapping.setXPath("customer-address");
xmlDescriptor.addMapping(addressMapping);
XMLCompositeCollectionMapping addressesMapping = new XMLCompositeCollectionMapping();
addressesMapping.setReferenceClass(Address.class);
addressesMapping.setAttributeName("addresses");
addressesMapping.setXPath("customer-addresses/customer-address");
xmlDescriptor.addMapping(addressesMapping);
XMLAnyObjectMapping anyMapping = new XMLAnyObjectMapping();
anyMapping.setAttributeName("any");
anyMapping.setXPath("any-object");
xmlDescriptor.addMapping(anyMapping);
XMLAnyCollectionMapping anyCollectionMapping = new XMLAnyCollectionMapping();
anyCollectionMapping.setAttributeName("anyCollection");
anyCollectionMapping.setXPath("any-collection");
xmlDescriptor.addMapping(anyCollectionMapping);
return xmlDescriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping in project eclipselink by eclipse-ee4j.
the class EmployeeProject method getEmployeeDescriptor.
public XMLDescriptor getEmployeeDescriptor() {
if (null == employeeDescriptor) {
employeeDescriptor = new XMLDescriptor();
employeeDescriptor.setJavaClass(Employee.class);
employeeDescriptor.setDefaultRootElement("ns:employee");
employeeDescriptor.setSequencedObject(true);
NamespaceResolver nsResolver = new NamespaceResolver();
nsResolver.put("ns", "urn:example");
employeeDescriptor.setNamespaceResolver(nsResolver);
XMLDirectMapping idMapping = new XMLDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("@id");
employeeDescriptor.addMapping(idMapping);
XMLDirectMapping fnMapping = new XMLDirectMapping();
fnMapping.setAttributeName("firstName");
fnMapping.setXPath("personal-info/ns:first-name/text()");
employeeDescriptor.addMapping(fnMapping);
XMLDirectMapping lnMapping = new XMLDirectMapping();
lnMapping.setAttributeName("lastName");
lnMapping.setXPath("personal-info/last-name/text()");
employeeDescriptor.addMapping(lnMapping);
XMLCompositeObjectMapping addressMapping = new XMLCompositeObjectMapping();
addressMapping.setAttributeName("address");
addressMapping.setXPath("address");
addressMapping.setReferenceClass(Address.class);
employeeDescriptor.addMapping(addressMapping);
XMLCompositeObjectMapping dependentMapping = new XMLCompositeObjectMapping();
dependentMapping.setAttributeName("dependent");
dependentMapping.setXPath("dependent");
dependentMapping.setReferenceClass(Dependent.class);
employeeDescriptor.addMapping(dependentMapping);
XMLAnyObjectMapping anyMapping = new XMLAnyObjectMapping();
anyMapping.setAttributeName("any");
anyMapping.setUseXMLRoot(true);
employeeDescriptor.addMapping(anyMapping);
XMLFragmentMapping nodeMapping = new XMLFragmentMapping();
nodeMapping.setAttributeName("node");
nodeMapping.setXPath("fragment");
employeeDescriptor.addMapping(nodeMapping);
/*
XMLChoiceMapping choiceMapping = new XMLChoiceMapping();
choiceMapping.setAttributeName("choice");
choiceMapping.addChoiceElement("choice-address", Address.class);
choiceMapping.addChoiceElement("choice-dependent", Dependent.class);
choiceMapping.addChoiceElement("choice-string/text()", String.class);
employeeDescriptor.addMapping(choiceMapping);
*/
}
return employeeDescriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping in project eclipselink by eclipse-ee4j.
the class TransformationMappingTestProject method getRootWithAnyObjectDescriptor.
public XMLDescriptor getRootWithAnyObjectDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(RootWithAnyObject.class);
descriptor.setDefaultRootElement("root-with-any-object");
XMLAnyObjectMapping objectMapping = new XMLAnyObjectMapping();
objectMapping.setAttributeName("object");
descriptor.addMapping(objectMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping in project eclipselink by eclipse-ee4j.
the class AnyObjectAndAnyCollectionUC13NoDefaultRootComplexChildrenTestCases method buildRootDescriptor.
protected //
ClassDescriptor buildRootDescriptor(//
boolean firstMappingIsAnyCollection, //
boolean firstMappingXPathSet, //
boolean secondMappingIsAnyCollection, boolean secondMappingXPathSet) {
//
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Customer.class);
descriptor.setDefaultRootElement("customer");
DatabaseMapping anyMapping1 = null;
// First Mapping
if (!firstMappingIsAnyCollection) {
anyMapping1 = new XMLAnyObjectMapping();
anyMapping1.setAttributeName("anyObject");
// ((XMLAnyObjectMapping) anyMapping1).setSetMethodName("setAnyObject");
if (firstMappingXPathSet) {
// set first mapping XPath
((XMLAnyObjectMapping) anyMapping1).setXPath(MAPPING_XPATH_OBJ);
}
descriptor.addMapping(anyMapping1);
} else {
anyMapping1 = new XMLAnyCollectionMapping();
anyMapping1.setAttributeName("contactMethods");
// ((XMLAnyCollectionMapping) anyMapping1).setSetMethodName("setAnyCollection");
if (firstMappingXPathSet) {
// set first mapping XPath
((XMLAnyCollectionMapping) anyMapping1).setXPath(MAPPING_XPATH);
}
descriptor.addMapping(anyMapping1);
}
// Second Mapping
DatabaseMapping anyMapping2 = null;
if (!secondMappingIsAnyCollection) {
anyMapping2 = new XMLAnyObjectMapping();
anyMapping2.setAttributeName("anyObject");
// ((XMLAnyObjectMapping) anyMapping2).setSetMethodName("setAnyObject");
if (secondMappingXPathSet) {
// set second mapping XPath
((XMLAnyObjectMapping) anyMapping2).setXPath(MAPPING_XPATH_OBJ);
}
descriptor.addMapping(anyMapping2);
} else {
anyMapping2 = new XMLAnyCollectionMapping();
anyMapping2.setAttributeName("contactMethods");
// ((XMLAnyCollectionMapping) anyMapping2).setSetMethodName("setAnyCollection");
if (secondMappingXPathSet) {
// set second mapping XPath
((XMLAnyCollectionMapping) anyMapping2).setXPath(MAPPING_XPATH);
}
descriptor.addMapping(anyMapping2);
}
return descriptor;
}
Aggregations