Search in sources :

Example 1 with XMLBinaryDataCollectionMapping

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;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) DatabaseField(org.eclipse.persistence.internal.helper.DatabaseField) Field(org.eclipse.persistence.internal.oxm.mappings.Field) JavaField(org.eclipse.persistence.jaxb.javamodel.JavaField) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) FixedMimeTypePolicy(org.eclipse.persistence.oxm.mappings.FixedMimeTypePolicy) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) JAXBException(org.eclipse.persistence.exceptions.JAXBException) DescriptorException(org.eclipse.persistence.exceptions.DescriptorException)

Example 2 with XMLBinaryDataCollectionMapping

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;
}
Also used : XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) SDOType(org.eclipse.persistence.sdo.SDOType) ArrayList(java.util.ArrayList) List(java.util.List) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Example 3 with XMLBinaryDataCollectionMapping

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;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping)

Example 4 with XMLBinaryDataCollectionMapping

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;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping)

Example 5 with XMLBinaryDataCollectionMapping

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;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) XMLSchemaURLReference(org.eclipse.persistence.oxm.schema.XMLSchemaURLReference) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLSchemaReference(org.eclipse.persistence.oxm.schema.XMLSchemaReference) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Aggregations

XMLBinaryDataCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping)9 XMLField (org.eclipse.persistence.oxm.XMLField)8 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)6 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)5 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)3 ArrayList (java.util.ArrayList)2 TypeConversionConverter (org.eclipse.persistence.mappings.converters.TypeConversionConverter)2 XMLChoiceCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping)2 XMLChoiceObjectMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)2 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)2 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)2 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)2 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)2 List (java.util.List)1 DescriptorException (org.eclipse.persistence.exceptions.DescriptorException)1 JAXBException (org.eclipse.persistence.exceptions.JAXBException)1 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)1 BinaryDataCollectionMapping (org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping)1 Field (org.eclipse.persistence.internal.oxm.mappings.Field)1 JavaClass (org.eclipse.persistence.jaxb.javamodel.JavaClass)1