use of org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping in project eclipselink by eclipse-ee4j.
the class DBWSBuilderModelProject method buildTableOperationModelDescriptor.
protected ClassDescriptor buildTableOperationModelDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(TableOperationModel.class);
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setXPath("@name");
descriptor.addMapping(nameMapping);
ObjectTypeConverter converter = new ObjectTypeConverter();
converter.addConversionValue("true", Boolean.TRUE);
converter.addConversionValue("false", Boolean.FALSE);
converter.setFieldClassification(String.class);
XMLDirectMapping simpleXMLFormatTagMapping = new XMLDirectMapping();
simpleXMLFormatTagMapping.setAttributeName("simpleXMLFormatTag");
simpleXMLFormatTagMapping.setGetMethodName("getSimpleXMLFormatTag");
simpleXMLFormatTagMapping.setSetMethodName("setSimpleXMLFormatTag");
simpleXMLFormatTagMapping.setXPath("@simpleXMLFormatTag");
descriptor.addMapping(simpleXMLFormatTagMapping);
XMLDirectMapping xmlTagMapping = new XMLDirectMapping();
xmlTagMapping.setAttributeName("xmlTag");
xmlTagMapping.setGetMethodName("getXmlTag");
xmlTagMapping.setSetMethodName("setXmlTag");
xmlTagMapping.setXPath("@xmlTag");
descriptor.addMapping(xmlTagMapping);
XMLDirectMapping isCollectionMapping = new XMLDirectMapping();
isCollectionMapping.setAttributeName("isCollection");
isCollectionMapping.setConverter(converter);
isCollectionMapping.setNullValue(Boolean.FALSE);
isCollectionMapping.setXPath("@isCollection");
descriptor.addMapping(isCollectionMapping);
XMLDirectMapping binaryAttachment = new XMLDirectMapping();
binaryAttachment.setAttributeName("binaryAttachment");
binaryAttachment.setConverter(converter);
binaryAttachment.setNullValue(Boolean.FALSE);
binaryAttachment.setXPath("@binaryAttachment");
descriptor.addMapping(binaryAttachment);
XMLDirectMapping attachmentType = new XMLDirectMapping();
attachmentType.setAttributeName("attachmentType");
attachmentType.setXPath("@attachmentType");
descriptor.addMapping(attachmentType);
XMLDirectMapping returnTypeMapping = new XMLDirectMapping();
returnTypeMapping.setAttributeName("returnType");
returnTypeMapping.setXPath("@returnType");
descriptor.addMapping(returnTypeMapping);
XMLDirectMapping catalogPatternMapping = new XMLDirectMapping();
catalogPatternMapping.setAttributeName("catalogPattern");
catalogPatternMapping.setXPath("@catalogPattern");
descriptor.addMapping(catalogPatternMapping);
XMLDirectMapping schemaPatternMapping = new XMLDirectMapping();
schemaPatternMapping.setAttributeName("schemaPattern");
schemaPatternMapping.setXPath("@schemaPattern");
descriptor.addMapping(schemaPatternMapping);
XMLDirectMapping tableNamePatternMapping = new XMLDirectMapping();
tableNamePatternMapping.setAttributeName("tablePattern");
tableNamePatternMapping.setXPath("@tableNamePattern");
descriptor.addMapping(tableNamePatternMapping);
XMLChoiceCollectionMapping additionalOperationsMapping = new XMLChoiceCollectionMapping();
additionalOperationsMapping.setAttributeName("additionalOperations");
additionalOperationsMapping.setContainerPolicy(new ListContainerPolicy(ArrayList.class));
additionalOperationsMapping.addChoiceElement("procedure", ProcedureOperationModel.class);
additionalOperationsMapping.addChoiceElement("plsql-procedure", PLSQLProcedureOperationModel.class);
additionalOperationsMapping.addChoiceElement("sql", SQLOperationModel.class);
additionalOperationsMapping.addChoiceElement("batch-sql", BatchSQLOperationModel.class);
descriptor.addMapping(additionalOperationsMapping);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping in project eclipselink by eclipse-ee4j.
the class PreLoginMappingAdapter method convertMappingToXMLChoiceMapping.
/**
* Build an XMLChoiceObjectMapping based on a particular mapping and replace that mapping with
* the newly created XMLChoiceObjectMapping in jaxbDescriptor.
* @param jaxbDescriptor the jaxb descriptor
* @param jpaMapping the jpa mapping
* @param cl the classloader
*/
@SuppressWarnings("rawtypes")
private static void convertMappingToXMLChoiceMapping(ClassDescriptor jaxbDescriptor, DatabaseMapping jpaMapping, ClassLoader cl, Session jpaSession) {
if ((jpaMapping != null) && (jaxbDescriptor != null)) {
if ((jpaMapping instanceof ForeignReferenceMapping) && ((jpaMapping.isAggregateCollectionMapping()) || (jpaMapping.isAggregateMapping()))) {
// Aggregates don't have identity to create links, thus no weaved REST adapters to insert choice mappings
return;
}
String attributeName = jpaMapping.getAttributeName();
DatabaseMapping jaxbMapping = jaxbDescriptor.getMappingForAttributeName(jpaMapping.getAttributeName());
if (!(jaxbMapping.isXMLMapping() && (jaxbMapping.isAbstractCompositeCollectionMapping() || jaxbMapping.isAbstractCompositeObjectMapping()))) {
return;
}
ClassDescriptor refDesc = null;
if (jpaMapping instanceof ForeignReferenceMapping) {
Class clazz = ((ForeignReferenceMapping) jpaMapping).getReferenceClass();
refDesc = jpaSession.getDescriptor(clazz);
} else if (jpaMapping instanceof XMLCompositeObjectMapping) {
Class clazz = ((XMLCompositeObjectMapping) jpaMapping).getReferenceClass();
refDesc = jpaSession.getDescriptor(clazz);
}
if (refDesc == null) {
return;
}
String adapterClassName = RestAdapterClassWriter.constructClassNameForReferenceAdapter(refDesc.getJavaClassName());
if (adapterClassName != null) {
try {
if (jaxbMapping.isAbstractCompositeObjectMapping()) {
XMLChoiceObjectMapping xmlChoiceMapping = new XMLChoiceObjectMapping();
xmlChoiceMapping.setAttributeName(attributeName);
copyAccessorToMapping(jaxbMapping, xmlChoiceMapping);
xmlChoiceMapping.setProperties(jaxbMapping.getProperties());
XMLCompositeObjectMapping compositeMapping = (XMLCompositeObjectMapping) jaxbMapping;
xmlChoiceMapping.addChoiceElement(compositeMapping.getXPath(), Link.class);
xmlChoiceMapping.addChoiceElement(compositeMapping.getXPath(), refDesc.getJavaClass());
xmlChoiceMapping.setConverter(new XMLJavaTypeConverter((Class<? extends XmlAdapter<?, ?>>) Class.forName(adapterClassName, true, cl)));
jaxbDescriptor.removeMappingForAttributeName(jaxbMapping.getAttributeName());
jaxbDescriptor.addMapping(xmlChoiceMapping);
} else if (jaxbMapping.isAbstractCompositeCollectionMapping()) {
XMLChoiceCollectionMapping xmlChoiceMapping = new XMLChoiceCollectionMapping();
xmlChoiceMapping.setAttributeName(attributeName);
copyAccessorToMapping(jaxbMapping, xmlChoiceMapping);
xmlChoiceMapping.setProperties(jaxbMapping.getProperties());
XMLCompositeCollectionMapping compositeMapping = (XMLCompositeCollectionMapping) jaxbMapping;
xmlChoiceMapping.addChoiceElement(compositeMapping.getXPath(), Link.class);
xmlChoiceMapping.addChoiceElement(compositeMapping.getXPath(), refDesc.getJavaClass());
xmlChoiceMapping.setContainerPolicy(jaxbMapping.getContainerPolicy());
xmlChoiceMapping.setConverter(new XMLJavaTypeConverter((Class<? extends XmlAdapter<?, ?>>) Class.forName(adapterClassName, true, cl)));
jaxbDescriptor.removeMappingForAttributeName(jaxbMapping.getAttributeName());
jaxbDescriptor.addMapping(xmlChoiceMapping);
}
} catch (Exception ex) {
throw JPARSException.exceptionOccurred(ex);
}
}
}
}
use of org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping in project eclipselink by eclipse-ee4j.
the class TestModelProject method addRootDescriptor.
public void addRootDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClassName("org.persistence.testing.jaxb.dynamic.xxx.Root");
descriptor.setNamespaceResolver(nsResolver);
XMLCompositeObjectMapping compObj = new XMLCompositeObjectMapping();
compObj.setAttributeName("compObj");
compObj.setXPath("comp-obj");
compObj.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CompositeObjectTarget");
descriptor.addMapping(compObj);
XMLCompositeCollectionMapping compColl = new XMLCompositeCollectionMapping();
compColl.setAttributeName("compColl");
compColl.setXPath("comp-coll/item");
compColl.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CompositeCollectionTarget");
compColl.useCollectionClass(ArrayList.class);
compColl.setContainerPolicy(ContainerPolicy.buildPolicyFor(ArrayList.class));
descriptor.addMapping(compColl);
XMLCompositeDirectCollectionMapping compDirColl = new XMLCompositeDirectCollectionMapping();
compDirColl.setAttributeName("compDirColl");
compDirColl.setXPath("comp-dir-coll");
descriptor.addMapping(compDirColl);
XMLBinaryDataMapping binData = new XMLBinaryDataMapping();
binData.setAttributeName("binData");
XMLField binDataField = new XMLField("bin-data");
binDataField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
binData.setField(binDataField);
binData.setShouldInlineBinaryData(true);
descriptor.addMapping(binData);
XMLBinaryDataCollectionMapping binDataColl = new XMLBinaryDataCollectionMapping();
binDataColl.setAttributeName("binDataColl");
XMLField binDataCollField = new XMLField("bin-data-coll");
binDataCollField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
binDataColl.setField(binDataCollField);
binDataColl.setShouldInlineBinaryData(true);
descriptor.addMapping(binDataColl);
XMLAnyObjectMapping anyObj = new XMLAnyObjectMapping();
anyObj.setAttributeName("anyObj");
anyObj.setField(new XMLField("any-obj"));
descriptor.addMapping(anyObj);
XMLCompositeObjectMapping anyAtt = new XMLCompositeObjectMapping();
anyAtt.setAttributeName("anyAtt");
anyAtt.setXPath("any-att");
anyAtt.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.AnyAttributeTarget");
descriptor.addMapping(anyAtt);
XMLTransformationMapping transform = new XMLTransformationMapping();
transform.setAttributeName("transform");
transform.setAttributeTransformer(new AttributeTransformer());
transform.addFieldTransformer("transform/first-val/text()", new FirstFieldTransformer());
transform.addFieldTransformer("transform/second-val/text()", new SecondFieldTransformer());
descriptor.addMapping(transform);
XMLFragmentMapping frag = new XMLFragmentMapping();
frag.setAttributeName("frag");
frag.setXPath("frag");
descriptor.addMapping(frag);
XMLFragmentCollectionMapping fragColl = new XMLFragmentCollectionMapping();
fragColl.setAttributeName("fragColl");
fragColl.setXPath("frag-coll");
fragColl.useCollectionClass(ArrayList.class);
descriptor.addMapping(fragColl);
XMLObjectReferenceMapping objRef = new XMLObjectReferenceMapping();
objRef.setAttributeName("objRef");
objRef.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.ObjectReferenceTarget");
objRef.addSourceToTargetKeyFieldAssociation("obj-ref-id/text()", "@id");
descriptor.addMapping(objRef);
XMLCollectionReferenceMapping collRef = new XMLCollectionReferenceMapping();
collRef.setAttributeName("collRef");
collRef.setReferenceClassName("org.persistence.testing.jaxb.dynamic.xxx.CollectionReferenceTarget");
collRef.addSourceToTargetKeyFieldAssociation("coll-ref-id/text()", "@id");
descriptor.addMapping(collRef);
XMLChoiceObjectMapping choice = new XMLChoiceObjectMapping();
choice.setAttributeName("choice");
choice.addChoiceElement("choice-int/text()", Integer.class);
choice.addChoiceElement("choice-float/text()", Float.class);
descriptor.addMapping(choice);
XMLChoiceCollectionMapping choiceColl = new XMLChoiceCollectionMapping();
choiceColl.setAttributeName("choiceColl");
choiceColl.addChoiceElement("choice-coll-double/text()", Double.class);
choiceColl.addChoiceElement("choice-coll-string/text()", String.class);
choiceColl.addChoiceElement("choice-coll-boolean/text()", Boolean.class);
descriptor.addMapping(choiceColl);
this.addDescriptor(descriptor);
}
Aggregations