Search in sources :

Example 16 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class NoRefClassProject method getCustomerDescriptor.

private XMLDescriptor getCustomerDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Customer.class);
    XMLObjectReferenceMapping addressMapping = new XMLObjectReferenceMapping();
    addressMapping.setAttributeName("address");
    addressMapping.addSourceToTargetKeyFieldAssociation("address-id/text()", null);
    xmlDescriptor.addMapping(addressMapping);
    XMLCollectionReferenceMapping phoneNumbersMapping = new XMLCollectionReferenceMapping();
    phoneNumbersMapping.setAttributeName("phoneNumbers");
    phoneNumbersMapping.addSourceToTargetKeyFieldAssociation("phone-number-id/text()", null);
    phoneNumbersMapping.getContainerPolicy().setContainerClass(ArrayList.class);
    xmlDescriptor.addMapping(phoneNumbersMapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)

Example 17 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class SingleElementProject method getCustomerDescriptor.

private XMLDescriptor getCustomerDescriptor() {
    XMLDescriptor xmlDescriptor = new XMLDescriptor();
    xmlDescriptor.setJavaClass(Customer.class);
    XMLObjectReferenceMapping addressMapping = new XMLObjectReferenceMapping();
    addressMapping.setAttributeName("address");
    addressMapping.addSourceToTargetKeyFieldAssociation("address-id/text()", null);
    xmlDescriptor.addMapping(addressMapping);
    XMLCollectionReferenceMapping phoneNumbersMapping = new XMLCollectionReferenceMapping();
    phoneNumbersMapping.setAttributeName("phoneNumbers");
    phoneNumbersMapping.addSourceToTargetKeyFieldAssociation("phone-number-id/text()", null);
    phoneNumbersMapping.getContainerPolicy().setContainerClass(ArrayList.class);
    phoneNumbersMapping.setUsesSingleNode(true);
    xmlDescriptor.addMapping(phoneNumbersMapping);
    return xmlDescriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)

Example 18 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping 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)

Example 19 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class AttributeProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.addPrimaryKeyFieldName("id/@id1");
    descriptor.addPrimaryKeyFieldName("id/@ns:id2");
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("ns", "urn:example");
    descriptor.setNamespaceResolver(namespaceResolver);
    XMLCompositeObjectMapping idMapping = new XMLCompositeObjectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("id");
    idMapping.setReferenceClass(EmployeeID.class);
    descriptor.addMapping(idMapping);
    XMLObjectReferenceMapping managerMapping = new XMLObjectReferenceMapping();
    managerMapping.setAttributeName("manager");
    managerMapping.addSourceToTargetKeyFieldAssociation("manager/@fk1", "id/@id1");
    managerMapping.addSourceToTargetKeyFieldAssociation("manager/@ns:fk2", "id/@ns:id2");
    managerMapping.setReferenceClass(Employee.class);
    descriptor.addMapping(managerMapping);
    XMLCollectionReferenceMapping employeesMapping = new XMLCollectionReferenceMapping();
    employeesMapping.setAttributeName("teamMembers");
    employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/@fk1", "id/@id1");
    employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/@ns:fk2", "id/@ns:id2");
    employeesMapping.setReferenceClass(Employee.class);
    descriptor.addMapping(employeesMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Example 20 with XMLObjectReferenceMapping

use of org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping in project eclipselink by eclipse-ee4j.

the class SingleNodeProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.addPrimaryKeyFieldName("id/id1/text()");
    descriptor.addPrimaryKeyFieldName("id/ns:id2/text()");
    NamespaceResolver namespaceResolver = new NamespaceResolver();
    namespaceResolver.put("ns", "urn:example");
    descriptor.setNamespaceResolver(namespaceResolver);
    XMLCompositeObjectMapping idMapping = new XMLCompositeObjectMapping();
    idMapping.setAttributeName("id");
    idMapping.setXPath("id");
    idMapping.setReferenceClass(EmployeeID.class);
    descriptor.addMapping(idMapping);
    XMLObjectReferenceMapping managerMapping = new XMLObjectReferenceMapping();
    managerMapping.setAttributeName("manager");
    managerMapping.addSourceToTargetKeyFieldAssociation("manager/@fk1", "id/id1/text()");
    managerMapping.addSourceToTargetKeyFieldAssociation("manager/ns:fk2/text()", "id/ns:id2/text()");
    managerMapping.setReferenceClass(Employee.class);
    descriptor.addMapping(managerMapping);
    XMLCollectionReferenceMapping employeesMapping = new XMLCollectionReferenceMapping();
    employeesMapping.setAttributeName("teamMembers");
    employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/@fk1", "id/id1/text()");
    employeesMapping.addSourceToTargetKeyFieldAssociation("team-member/ns:fk2/text()", "id/ns:id2/text()");
    employeesMapping.setReferenceClass(Employee.class);
    employeesMapping.setUsesSingleNode(true);
    descriptor.addMapping(employeesMapping);
    return descriptor;
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)

Aggregations

XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)35 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)32 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)20 XMLCollectionReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping)14 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)12 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)8 XMLField (org.eclipse.persistence.oxm.XMLField)6 XMLSchemaClassPathReference (org.eclipse.persistence.oxm.schema.XMLSchemaClassPathReference)6 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)2 XPathFragment (org.eclipse.persistence.internal.oxm.XPathFragment)2 AttributeAccessor (org.eclipse.persistence.mappings.AttributeAccessor)2 XMLBinaryDataCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping)2 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)2 XMLChoiceCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping)2 XMLChoiceObjectMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)2 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1