Search in sources :

Example 6 with XMLChoiceObjectMapping

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

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

the class EmployeeProject method getEmployeeDescriptor.

private XMLDescriptor getEmployeeDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(Employee.class);
    descriptor.setDefaultRootElement("employee");
    XMLDirectMapping nameMapping = new XMLDirectMapping();
    nameMapping.setAttributeName("name");
    nameMapping.setXPath("name/text()");
    descriptor.addMapping(nameMapping);
    XMLChoiceObjectMapping choiceMapping = new XMLChoiceObjectMapping();
    choiceMapping.setAttributeName("choice");
    choiceMapping.addChoiceElement("street/text()", String.class);
    choiceMapping.addChoiceElement("address", Address.class);
    choiceMapping.addChoiceElement("integer/text()", Integer.class);
    descriptor.addMapping(choiceMapping);
    XMLDirectMapping phoneMapping = new XMLDirectMapping();
    phoneMapping.setAttributeName("phone");
    phoneMapping.setXPath("phone/text()");
    descriptor.addMapping(phoneMapping);
    return descriptor;
}
Also used : XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Example 8 with XMLChoiceObjectMapping

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

the class MappingsGenerator method generateMappingForReferenceProperty.

public Mapping generateMappingForReferenceProperty(Property property, Descriptor descriptor, NamespaceInfo namespaceInfo) {
    boolean isCollection = helper.isCollectionType(property.getType()) || property.getType().isArray();
    Mapping mapping;
    if (isCollection) {
        mapping = new XMLChoiceCollectionMapping();
        initializeXMLContainerMapping((ChoiceCollectionMapping) mapping, property.getType().isArray());
        JavaClass collectionType = property.getType();
        collectionType = containerClassImpl(collectionType);
        ((ChoiceCollectionMapping) mapping).useCollectionClassName(collectionType.getRawName());
        JAXBElementRootConverter jaxbERConverter = new JAXBElementRootConverter(Object.class);
        if (property.isSetXmlJavaTypeAdapter()) {
            JavaClass adapterClass = helper.getJavaClass(property.getXmlJavaTypeAdapter().getValue());
            jaxbERConverter.setNestedConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
        ((ChoiceCollectionMapping) mapping).setConverter(jaxbERConverter);
        if (property.isSetWriteOnly()) {
            ((ChoiceCollectionMapping) mapping).setIsWriteOnly(property.isWriteOnly());
        }
        if (property.isSetXmlElementWrapper()) {
            ((ChoiceCollectionMapping) mapping).setWrapperNullPolicy(getWrapperNullPolicyFromProperty(property));
        }
    } else {
        mapping = new XMLChoiceObjectMapping();
        JAXBElementRootConverter jaxbERConverter = new JAXBElementRootConverter(Object.class);
        if (property.isSetXmlJavaTypeAdapter()) {
            JavaClass adapterClass = helper.getJavaClass(property.getXmlJavaTypeAdapter().getValue());
            jaxbERConverter.setNestedConverter(new XMLJavaTypeConverter(adapterClass.getQualifiedName()));
        }
        ((ChoiceObjectMapping) mapping).setConverter(jaxbERConverter);
        if (property.isSetWriteOnly()) {
            ((ChoiceObjectMapping) mapping).setIsWriteOnly(property.isWriteOnly());
        }
    }
    initializeXMLMapping((XMLMapping) mapping, property);
    List<ElementDeclaration> referencedElements = property.getReferencedElements();
    JavaClass propertyType = property.getType();
    if (propertyType.isArray()) {
        JAXBArrayAttributeAccessor accessor = new JAXBArrayAttributeAccessor(mapping.getAttributeAccessor(), mapping.getContainerPolicy(), helper.getClassLoader());
        accessor.setComponentClassName(property.getType().getComponentType().getQualifiedName());
        JavaClass componentType = propertyType.getComponentType();
        if (componentType.isArray()) {
            Class<?> adaptedClass = classToGeneratedClasses.get(componentType.getQualifiedName());
            accessor.setAdaptedClassName(adaptedClass.getName());
        }
        mapping.setAttributeAccessor(accessor);
    }
    String wrapperXPath = "";
    // handle XmlElementWrapper
    if (property.isSetXmlElementWrapper()) {
        XmlElementWrapper wrapper = property.getXmlElementWrapper();
        String namespace = wrapper.getNamespace();
        if (namespace.equals(XMLProcessor.DEFAULT)) {
            if (namespaceInfo.isElementFormQualified()) {
                namespace = namespaceInfo.getNamespace();
            } else {
                namespace = "";
            }
        }
        if (namespace.equals("")) {
            wrapperXPath += (wrapper.getName() + "/");
        } else {
            String prefix = getPrefixForNamespace(namespace, getNamespaceResolverForDescriptor(namespaceInfo));
            wrapperXPath += getQualifiedString(prefix, wrapper.getName() + "/");
        }
    }
    if (property.isMixedContent() && isCollection) {
        if (wrapperXPath.length() == 0) {
            ((ChoiceCollectionMapping) mapping).setMixedContent(true);
        } else {
            ((ChoiceCollectionMapping) mapping).setMixedContent(wrapperXPath.substring(0, wrapperXPath.length() - 1));
        }
    }
    for (ElementDeclaration element : referencedElements) {
        QName elementName = element.getElementName();
        JavaClass pType = element.getJavaType();
        String pTypeName = element.getJavaTypeName();
        boolean isBinaryType = (areEquals(pType, AnnotationsProcessor.JAVAX_ACTIVATION_DATAHANDLER) || areEquals(pType, byte[].class) || areEquals(pType, Image.class) || areEquals(pType, Source.class) || areEquals(pType, AnnotationsProcessor.JAVAX_MAIL_INTERNET_MIMEMULTIPART));
        boolean isText = pType.isEnum() || (!isBinaryType && !(this.typeInfo.containsKey(element.getJavaTypeName())) && !(element.getJavaTypeName().equals(OBJECT_CLASS_NAME)));
        String xPath = wrapperXPath;
        Field xmlField = this.getXPathForElement(xPath, elementName, namespaceInfo, isText);
        // ensure byte[] goes to base64 instead of the default hex.
        if (helper.getXMLToJavaTypeMap().get(pType.getRawName()) == Constants.BASE_64_BINARY_QNAME) {
            xmlField.setSchemaType(Constants.BASE_64_BINARY_QNAME);
        }
        if (areEquals(pType, Object.class)) {
            setTypedTextField(xmlField);
        }
        Mapping nestedMapping;
        AbstractNullPolicy nullPolicy = null;
        if (isCollection) {
            ChoiceCollectionMapping xmlChoiceCollectionMapping = (ChoiceCollectionMapping) mapping;
            xmlChoiceCollectionMapping.addChoiceElement(xmlField, pTypeName);
            nestedMapping = (Mapping) xmlChoiceCollectionMapping.getChoiceElementMappings().get(xmlField);
            if (nestedMapping.isAbstractCompositeCollectionMapping()) {
                ((CompositeCollectionMapping) nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
                nullPolicy = ((CompositeCollectionMapping) nestedMapping).getNullPolicy();
            }
            if (nestedMapping.isAbstractCompositeDirectCollectionMapping()) {
                DirectCollectionMapping nestedCompositeDirectCollectionMapping = (DirectCollectionMapping) nestedMapping;
                nullPolicy = nestedCompositeDirectCollectionMapping.getNullPolicy();
                if (pType.isEnum()) {
                    TypeInfo enumTypeInfo = typeInfo.get(pType.getQualifiedName());
                    nestedCompositeDirectCollectionMapping.setValueConverter(buildJAXBEnumTypeConverter(nestedCompositeDirectCollectionMapping, (EnumTypeInfo) enumTypeInfo));
                }
                if (element.isList()) {
                    XMLListConverter listConverter = new XMLListConverter();
                    listConverter.setObjectClassName(pType.getQualifiedName());
                    ((DirectCollectionMapping) nestedMapping).setValueConverter(listConverter);
                }
            } else if (nestedMapping instanceof BinaryDataCollectionMapping) {
                nullPolicy = ((BinaryDataCollectionMapping) nestedMapping).getNullPolicy();
                if (element.isList()) {
                    ((XMLField) nestedMapping.getField()).setUsesSingleNode(true);
                }
            }
        } else {
            ChoiceObjectMapping xmlChoiceObjectMapping = (ChoiceObjectMapping) mapping;
            xmlChoiceObjectMapping.addChoiceElement(xmlField, pTypeName);
            nestedMapping = (Mapping) xmlChoiceObjectMapping.getChoiceElementMappings().get(xmlField);
            if (pType.isEnum()) {
                TypeInfo enumTypeInfo = typeInfo.get(pType.getQualifiedName());
                ((DirectMapping) nestedMapping).setConverter(buildJAXBEnumTypeConverter(nestedMapping, (EnumTypeInfo) enumTypeInfo));
            }
            if (nestedMapping.isAbstractCompositeObjectMapping()) {
                ((CompositeObjectMapping) nestedMapping).setKeepAsElementPolicy(UnmarshalKeepAsElementPolicy.KEEP_UNKNOWN_AS_ELEMENT);
                nullPolicy = ((CompositeObjectMapping) nestedMapping).getNullPolicy();
            } else if (nestedMapping instanceof BinaryDataMapping) {
                nullPolicy = ((BinaryDataMapping) nestedMapping).getNullPolicy();
            } else if (nestedMapping instanceof DirectMapping) {
                nullPolicy = ((DirectMapping) nestedMapping).getNullPolicy();
            }
        }
        if (nullPolicy != null) {
            nullPolicy.setNullRepresentedByEmptyNode(false);
            nullPolicy.setMarshalNullRepresentation(XMLNullRepresentationType.XSI_NIL);
            nullPolicy.setNullRepresentedByXsiNil(true);
            nullPolicy.setIgnoreAttributesForNil(false);
        }
        if (!element.isXmlRootElement()) {
            Class<?> scopeClass = element.getScopeClass();
            if (scopeClass == jakarta.xml.bind.annotation.XmlElementDecl.GLOBAL.class) {
                scopeClass = JAXBElement.GlobalScope.class;
            }
            Class<?> declaredType = null;
            if (element.getAdaptedJavaType() != null) {
                declaredType = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(element.getAdaptedJavaType().getQualifiedName(), helper.getClassLoader());
            } else {
                declaredType = org.eclipse.persistence.internal.helper.Helper.getClassFromClasseName(pType.getQualifiedName(), helper.getClassLoader());
            }
            JAXBElementConverter converter = new JAXBElementConverter(xmlField, declaredType, scopeClass);
            if (isCollection) {
                ChoiceCollectionMapping xmlChoiceCollectionMapping = (ChoiceCollectionMapping) mapping;
                if (element.getJavaTypeAdapterClass() != null) {
                    converter.setNestedConverter(new XMLJavaTypeConverter(element.getJavaTypeAdapterClass().getName()));
                } else {
                    CoreConverter originalConverter = xmlChoiceCollectionMapping.getConverter(xmlField);
                    converter.setNestedConverter(originalConverter);
                }
                xmlChoiceCollectionMapping.addConverter(xmlField, converter);
            } else {
                ChoiceObjectMapping xmlChoiceObjectMapping = (ChoiceObjectMapping) mapping;
                if (element.getJavaTypeAdapterClass() != null) {
                    converter.setNestedConverter(new XMLJavaTypeConverter(element.getJavaTypeAdapterClass().getName()));
                } else {
                    CoreConverter originalConverter = xmlChoiceObjectMapping.getConverter(xmlField);
                    converter.setNestedConverter(originalConverter);
                }
                xmlChoiceObjectMapping.addConverter(xmlField, converter);
            }
        }
    }
    if (property.isAny()) {
        if (isCollection) {
            XMLChoiceCollectionMapping xmlChoiceCollectionMapping = (XMLChoiceCollectionMapping) mapping;
            xmlChoiceCollectionMapping.setIsAny(true);
        }
    }
    return mapping;
}
Also used : XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) JAXBArrayAttributeAccessor(org.eclipse.persistence.internal.jaxb.many.JAXBArrayAttributeAccessor) XMLVariableXPathObjectMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathObjectMapping) AnyObjectMapping(org.eclipse.persistence.internal.oxm.mappings.AnyObjectMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) VariableXPathCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathCollectionMapping) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) XMLVariableXPathCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLVariableXPathCollectionMapping) XMLAnyObjectMapping(org.eclipse.persistence.oxm.mappings.XMLAnyObjectMapping) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLMapping(org.eclipse.persistence.oxm.mappings.XMLMapping) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) VariableXPathObjectMapping(org.eclipse.persistence.internal.oxm.mappings.VariableXPathObjectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) CollectionReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.CollectionReferenceMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) TransformationMapping(org.eclipse.persistence.internal.oxm.mappings.TransformationMapping) ObjectReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.ObjectReferenceMapping) XMLAnyAttributeMapping(org.eclipse.persistence.oxm.mappings.XMLAnyAttributeMapping) XMLInverseReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLInverseReferenceMapping) InverseReferenceMapping(org.eclipse.persistence.internal.oxm.mappings.InverseReferenceMapping) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) CoreMapping(org.eclipse.persistence.core.mappings.CoreMapping) AnyCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.AnyCollectionMapping) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLAnyCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLAnyCollectionMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) Mapping(org.eclipse.persistence.internal.oxm.mappings.Mapping) XMLObjectReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping) AnyAttributeMapping(org.eclipse.persistence.internal.oxm.mappings.AnyAttributeMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) XMLContainerMapping(org.eclipse.persistence.internal.oxm.mappings.XMLContainerMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) XMLCollectionReferenceMapping(org.eclipse.persistence.oxm.mappings.XMLCollectionReferenceMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) XMLBinaryDataCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping) BinaryDataCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataCollectionMapping) XMLChoiceCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping) ChoiceCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceCollectionMapping) Source(javax.xml.transform.Source) DirectCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.DirectCollectionMapping) XMLCompositeDirectCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping) 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) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) DirectMapping(org.eclipse.persistence.internal.oxm.mappings.DirectMapping) CoreConverter(org.eclipse.persistence.core.mappings.converters.CoreConverter) XmlElementWrapper(org.eclipse.persistence.jaxb.xmlmodel.XmlElementWrapper) XMLJavaTypeConverter(org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter) XmlAbstractNullPolicy(org.eclipse.persistence.jaxb.xmlmodel.XmlAbstractNullPolicy) AbstractNullPolicy(org.eclipse.persistence.oxm.mappings.nullpolicy.AbstractNullPolicy) QName(javax.xml.namespace.QName) JAXBElementConverter(org.eclipse.persistence.internal.jaxb.JAXBElementConverter) JAXBElement(jakarta.xml.bind.JAXBElement) XMLBinaryDataMapping(org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping) BinaryDataMapping(org.eclipse.persistence.internal.oxm.mappings.BinaryDataMapping) XMLListConverter(org.eclipse.persistence.oxm.mappings.converters.XMLListConverter) JAXBElementRootConverter(org.eclipse.persistence.internal.jaxb.JAXBElementRootConverter) JavaClass(org.eclipse.persistence.jaxb.javamodel.JavaClass) CompositeCollectionMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeCollectionMapping) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) XMLCompositeObjectMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping) CompositeObjectMapping(org.eclipse.persistence.internal.oxm.mappings.CompositeObjectMapping) ChoiceObjectMapping(org.eclipse.persistence.internal.oxm.mappings.ChoiceObjectMapping) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)

Example 9 with XMLChoiceObjectMapping

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

the class SDOProperty method buildXMLChoiceObjectMapping.

private DatabaseMapping buildXMLChoiceObjectMapping(String mappingUri) {
    XMLChoiceObjectMapping mapping = new XMLChoiceObjectMapping();
    mapping.setAttributeName(getName());
    // First add XPath for this property
    String xPath = getQualifiedXPath(mappingUri, getType().isDataType());
    mapping.addChoiceElement(xPath, getType().getImplClass());
    // For each substitutable property, create the xpath and add it.
    Iterator<SDOProperty> properties = this.getSubstitutableElements().iterator();
    while (properties.hasNext()) {
        SDOProperty nextProp = properties.next();
        xPath = nextProp.getQualifiedXPath(mappingUri, nextProp.getType().isDataType(), getContainingType());
        mapping.addChoiceElement(xPath, nextProp.getType().getImplClass());
    }
    return mapping;
}
Also used : XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)

Example 10 with XMLChoiceObjectMapping

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

the class DBWSBuilderModelProject method buildSQLOperationModelDescriptor.

protected ClassDescriptor buildSQLOperationModelDescriptor() {
    XMLDescriptor descriptor = new XMLDescriptor();
    descriptor.setJavaClass(SQLOperationModel.class);
    descriptor.setDefaultRootElement("sql");
    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);
    // bug 322949
    XMLChoiceObjectMapping statementMapping = new XMLChoiceObjectMapping();
    statementMapping.setAttributeName("sql");
    // support old element name 'text' and new name 'statement'
    XMLField f1 = new XMLField("statement/text()");
    f1.setIsCDATA(true);
    statementMapping.addChoiceElement(f1, String.class);
    XMLField f2 = new XMLField("text/text()");
    f2.setIsCDATA(true);
    statementMapping.addChoiceElement(f2, String.class);
    descriptor.addMapping(statementMapping);
    XMLDirectMapping buildStatementMapping = new XMLDirectMapping();
    buildStatementMapping.setAttributeName("buildSql");
    buildStatementMapping.setXPath("build-statement/text()");
    buildStatementMapping.setIsCDATA(true);
    descriptor.addMapping(buildStatementMapping);
    XMLCompositeCollectionMapping bindingsMapping = new XMLCompositeCollectionMapping();
    bindingsMapping.setAttributeName("bindings");
    bindingsMapping.setReferenceClass(BindingModel.class);
    bindingsMapping.setContainerPolicy(new ListContainerPolicy(ArrayList.class));
    bindingsMapping.setXPath("binding");
    descriptor.addMapping(bindingsMapping);
    return descriptor;
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLChoiceObjectMapping(org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) ListContainerPolicy(org.eclipse.persistence.internal.queries.ListContainerPolicy) ObjectTypeConverter(org.eclipse.persistence.mappings.converters.ObjectTypeConverter) XMLCompositeCollectionMapping(org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping) ArrayList(java.util.ArrayList)

Aggregations

XMLChoiceObjectMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceObjectMapping)12 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)7 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)7 XMLField (org.eclipse.persistence.oxm.XMLField)6 XMLCompositeCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeCollectionMapping)6 XMLChoiceCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLChoiceCollectionMapping)5 XMLCompositeObjectMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeObjectMapping)5 ArrayList (java.util.ArrayList)4 XMLBinaryDataMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataMapping)4 XMLJavaTypeConverter (org.eclipse.persistence.internal.jaxb.XMLJavaTypeConverter)3 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)3 XMLBinaryDataCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLBinaryDataCollectionMapping)3 XMLCompositeDirectCollectionMapping (org.eclipse.persistence.oxm.mappings.XMLCompositeDirectCollectionMapping)3 XMLMapping (org.eclipse.persistence.oxm.mappings.XMLMapping)3 XMLObjectReferenceMapping (org.eclipse.persistence.oxm.mappings.XMLObjectReferenceMapping)3 CoreConverter (org.eclipse.persistence.core.mappings.converters.CoreConverter)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 DatabaseField (org.eclipse.persistence.internal.helper.DatabaseField)2 JAXBElementConverter (org.eclipse.persistence.internal.jaxb.JAXBElementConverter)2 JAXBElementRootConverter (org.eclipse.persistence.internal.jaxb.JAXBElementRootConverter)2