use of org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping in project eclipselink by eclipse-ee4j.
the class MappingsGenerator method generateBinaryDataCollectionMapping.
public BinaryDataCollectionMapping generateBinaryDataCollectionMapping(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo) {
BinaryDataCollectionMapping mapping = new XMLBinaryDataCollectionMapping();
initializeXMLMapping((XMLMapping) mapping, property);
initializeXMLContainerMapping(mapping, property.getType().isArray());
if (property.isSetXmlElementWrapper()) {
mapping.setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
}
// handle null policy set via xml metadata
if (property.isSetNullPolicy()) {
mapping.setNullPolicy(getNullPolicyFromProperty(property, getNamespaceResolverForDescriptor(namespaceInfo)));
} else if (property.isNillable()) {
mapping.getNullPolicy().setNullRepresentedByXsiNil(true);
mapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
}
// if the XPath is set (via xml-path) use it
mapping.setField(getXPathForField(property, namespaceInfo, false, false));
if (property.isSwaAttachmentRef()) {
((Field) mapping.getField()).setSchemaType(Constants.SWA_REF_QNAME);
mapping.setSwaRef(true);
} else if (property.isMtomAttachment()) {
Field f = (Field) mapping.getField();
if (!f.getSchemaType().equals(Constants.HEX_BINARY_QNAME)) {
f.setSchemaType(Constants.BASE_64_BINARY_QNAME);
}
}
if (property.isInlineBinaryData()) {
mapping.setShouldInlineBinaryData(true);
}
// use a non-dynamic implementation of MimeTypePolicy to wrap the MIME string
if (property.getMimeType() != null) {
mapping.setMimeTypePolicy(new FixedMimeTypePolicy(property.getMimeType()));
} else {
if (areEquals(property.getType(), javax.xml.transform.Source.class)) {
mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/xml"));
} else {
mapping.setMimeTypePolicy(new FixedMimeTypePolicy("application/octet-stream"));
}
}
JavaClass collectionType = property.getType();
JavaClass itemType = property.getActualType();
if (collectionType != null && helper.isCollectionType(collectionType)) {
try {
Class<Object> declaredClass = PrivilegedAccessHelper.getClassForName(itemType.getQualifiedName(), false, helper.getClassLoader());
mapping.setAttributeElementClass(declaredClass);
} catch (Exception e) {
}
}
collectionType = containerClassImpl(collectionType);
mapping.useCollectionClassName(collectionType.getRawName());
return mapping;
}
use of org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping in project eclipselink by eclipse-ee4j.
the class LoadAndSavePurchaseOrderWithAnnotations method defineTypes.
@Override
protected List defineTypes() {
List types = super.defineTypes();
SDOType itemType = (SDOType) typeHelper.getType(null, "ItemSDO");
SDOType binaryType = (SDOType) typeHelper.getType(null, "myBinaryHandlerType");
SDOProperty binaryDataProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryData");
SDOProperty binaryDataHandlerProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryDataHandler");
SDOProperty binaryDataManyProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryDataMany");
SDOProperty binaryDataHandlerManyProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryDataHandlerMany");
SDOProperty binaryDataHandlerNoMimeProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryDataHandlerNoMime");
SDOProperty binaryDataHandlerManyNoMimeProp = (SDOProperty) itemType.getDeclaredPropertiesMap().get("binaryDataHandlerManyNoMime");
assertTrue(binaryDataProp.getType().equals(SDOConstants.SDO_BYTES));
assertTrue(binaryDataHandlerProp.getType().equals(binaryType));
assertTrue(binaryDataManyProp.isMany());
assertTrue(binaryDataHandlerManyProp.isMany());
assertTrue(binaryDataHandlerManyNoMimeProp.isMany());
assertTrue(binaryDataProp.getXmlMapping() instanceof XMLBinaryDataMapping);
assertTrue(binaryDataHandlerProp.getXmlMapping() instanceof XMLBinaryDataMapping);
assertTrue(binaryDataManyProp.getXmlMapping() instanceof XMLBinaryDataCollectionMapping);
assertTrue(binaryDataHandlerManyProp.getXmlMapping() instanceof XMLBinaryDataCollectionMapping);
assertTrue(binaryDataHandlerNoMimeProp.getXmlMapping() instanceof XMLBinaryDataMapping);
assertTrue(binaryDataHandlerManyNoMimeProp.getXmlMapping() instanceof XMLBinaryDataCollectionMapping);
assertTrue(((XMLBinaryDataMapping) binaryDataProp.getXmlMapping()).getConverter() == null);
assertTrue(((XMLBinaryDataMapping) binaryDataHandlerProp.getXmlMapping()).getConverter() == null);
assertTrue(((XMLBinaryDataMapping) binaryDataHandlerNoMimeProp.getXmlMapping()).getConverter() == null);
assertTrue(((XMLBinaryDataCollectionMapping) binaryDataManyProp.getXmlMapping()).getValueConverter() instanceof TypeConversionConverter);
assertTrue(((XMLBinaryDataCollectionMapping) binaryDataHandlerManyProp.getXmlMapping()).getValueConverter() == null);
assertTrue(((XMLBinaryDataCollectionMapping) binaryDataHandlerManyNoMimeProp.getXmlMapping()).getValueConverter() == null);
return types;
}
use of org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping in project eclipselink by eclipse-ee4j.
the class BinaryDataCollectionReuseProject method getEmployeeDescriptor.
private XMLDescriptor getEmployeeDescriptor(NamespaceResolver aNSResolver) {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.setDefaultRootElement("employee");
XMLDirectMapping idMapping = new XMLDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("@id");
descriptor.addMapping(idMapping);
XMLBinaryDataCollectionMapping photosMapping = new XMLBinaryDataCollectionMapping();
photosMapping.setAttributeName("photos");
XMLField field = new XMLField("photos/list/photo");
field.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
photosMapping.setReuseContainer(true);
photosMapping.setField(field);
descriptor.addMapping(photosMapping);
if (aNSResolver != null) {
descriptor.setNamespaceResolver(aNSResolver);
}
photosMapping.setShouldInlineBinaryData(false);
photosMapping.setSwaRef(false);
photosMapping.setMimeType("image");
photosMapping.setCollectionContentType(ClassConstants.APBYTE);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping in project eclipselink by eclipse-ee4j.
the class BinaryDataCollectionDataHandlerProject method getEmployeeDescriptor.
@Override
protected XMLDescriptor getEmployeeDescriptor(NamespaceResolver aNSResolver) {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(EmployeeWithByteArrayObject.class);
descriptor.setDefaultRootElement("employee");
XMLDirectMapping idMapping = new XMLDirectMapping();
idMapping.setAttributeName("id");
idMapping.setXPath("@id");
descriptor.addMapping(idMapping);
XMLBinaryDataCollectionMapping photosMapping = new XMLBinaryDataCollectionMapping();
photosMapping.setAttributeName("photos");
XMLField field = new XMLField("photos/list/photo");
photosMapping.setField(field);
descriptor.addMapping(photosMapping);
if (aNSResolver != null) {
descriptor.setNamespaceResolver(aNSResolver);
}
photosMapping.setShouldInlineBinaryData(false);
photosMapping.setSwaRef(true);
photosMapping.setMimeType("image");
photosMapping.setAttributeElementClass(DataHandler.class);
return descriptor;
}
use of org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping in project eclipselink by eclipse-ee4j.
the class TestProject method getEmployeeDescriptor.
private XMLDescriptor getEmployeeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(Employee.class);
descriptor.setAlias("Employee");
descriptor.addPrimaryKeyFieldName("name/text()");
descriptor.setNamespaceResolver(nsr);
if (setSchemaContext) {
XMLSchemaReference sRef = new XMLSchemaURLReference();
sRef.setSchemaContext("/employee-type");
sRef.setType(XMLSchemaReference.COMPLEX_TYPE);
descriptor.setSchemaReference(sRef);
}
if (setDefaultRootElement) {
descriptor.setDefaultRootElement("employee");
}
// create name mapping
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setXPath("name/text()");
descriptor.addMapping(nameMapping);
// create address mapping
XMLCompositeObjectMapping addressMapping = new XMLCompositeObjectMapping();
addressMapping.setAttributeName("address");
addressMapping.setXPath("address");
addressMapping.setReferenceClass(Address.class);
descriptor.addMapping(addressMapping);
// create phoneNumbers mapping
XMLCompositeCollectionMapping phonesMapping = new XMLCompositeCollectionMapping();
phonesMapping.setAttributeName("phoneNumbers");
phonesMapping.useCollectionClass(ArrayList.class);
phonesMapping.setXPath("phone-numbers");
phonesMapping.setReferenceClass(PhoneNumber.class);
descriptor.addMapping(phonesMapping);
// create projectIDs mapping
XMLCompositeDirectCollectionMapping projectIdsMapping = new XMLCompositeDirectCollectionMapping();
projectIdsMapping.setAttributeName("projectIDs");
projectIdsMapping.useCollectionClass(ArrayList.class);
projectIdsMapping.setXPath("project-id");
TypeConversionConverter tcc = new TypeConversionConverter(projectIdsMapping);
tcc.setObjectClass(BigDecimal.class);
projectIdsMapping.setValueConverter(tcc);
descriptor.addMapping(projectIdsMapping);
// create stuff mapping
XMLAnyCollectionMapping acMapping = new XMLAnyCollectionMapping();
acMapping.setAttributeName("stuff");
descriptor.addMapping(acMapping);
// Enable Choice testing when Bug 269880 has been fixed
// create choice mapping - choice
XMLChoiceObjectMapping choiceMapping = new XMLChoiceObjectMapping();
choiceMapping.setAttributeName("choice");
choiceMapping.addChoiceElement("nickname/text()", String.class);
choiceMapping.addChoiceElement("secondAddress", Address.class);
choiceMapping.addChoiceElement("age/text()", Integer.class);
// descriptor.addMapping(choiceMapping);
// Enable ChoiceCollection testing when Bug 269880 has been fixed
// create choices mapping
XMLChoiceCollectionMapping choiceCMapping = new XMLChoiceCollectionMapping();
choiceCMapping.setAttributeName("choices");
choiceCMapping.addChoiceElement("badgeId/text()", Integer.class);
choiceCMapping.addChoiceElement("alternateAddress", Address.class);
choiceCMapping.addChoiceElement("codename/text()", String.class);
// descriptor.addMapping(choiceCMapping);
// create billingAddress mapping
XMLObjectReferenceMapping orMapping = new XMLObjectReferenceMapping();
orMapping.setAttributeName("billingAddress");
orMapping.setReferenceClass(Address.class);
orMapping.addSourceToTargetKeyFieldAssociation("@bill-address-id", "@aid");
orMapping.addSourceToTargetKeyFieldAssociation("bill-address-city/text()", "city/text()");
descriptor.addMapping(orMapping);
// create data mapping
XMLBinaryDataMapping dataMapping = new XMLBinaryDataMapping();
dataMapping.setAttributeName("data");
XMLField field = new XMLField("data");
field.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
dataMapping.setField(field);
dataMapping.setShouldInlineBinaryData(false);
dataMapping.setSwaRef(true);
dataMapping.setMimeType("application/binary");
descriptor.addMapping(dataMapping);
// create bytes mapping
XMLBinaryDataCollectionMapping bytesMapping = new XMLBinaryDataCollectionMapping();
bytesMapping.setAttributeName("bytes");
XMLField theField = new XMLField("bytes");
theField.setSchemaType(XMLConstants.BASE_64_BINARY_QNAME);
bytesMapping.setField(theField);
bytesMapping.setShouldInlineBinaryData(false);
bytesMapping.setSwaRef(false);
bytesMapping.setMimeType("text/plain");
descriptor.addMapping(bytesMapping);
// create URL mapping
XMLDirectMapping urlMapping = new XMLDirectMapping();
urlMapping.setAttributeName("aUrl");
urlMapping.setXPath("aUrl/text()");
descriptor.addMapping(urlMapping);
return descriptor;
}
Aggregations