Search in sources :

Example 1 with SDOMethodAttributeAccessor

use of org.eclipse.persistence.sdo.helper.SDOMethodAttributeAccessor in project eclipselink by eclipse-ee4j.

the class SDOProperty method addMappingToOwner.

/**
 * INTERNAL:
 */
public void addMappingToOwner(boolean sdoMethodAttributeAccessor, int indexToAdd) {
    if (xmlMapping != null) {
        if (sdoMethodAttributeAccessor) {
            SDOMethodAttributeAccessor accessor = null;
            if (this.getType().isDataType()) {
                Class<?> theClass = getType().getInstanceClass();
                accessor = new SDOMethodAttributeAccessor(this, theClass);
            } else {
                accessor = new SDOMethodAttributeAccessor(this);
            }
            xmlMapping.setAttributeAccessor(accessor);
        }
        if ((getContainingType() != null) && !getContainingType().isDataType()) {
            ClassDescriptor containingDescriptor = getContainingType().getXmlDescriptor();
            xmlMapping.setDescriptor(containingDescriptor);
            XMLMapping mapping = (XMLMapping) getContainingType().getXmlDescriptor().getMappingForAttributeName(getName());
            if (mapping != null) {
                getContainingType().getXmlDescriptor().getMappings().remove(mapping);
            }
            if (indexToAdd == -1) {
                getContainingType().getXmlDescriptor().getMappings().add(xmlMapping);
            } else {
                // iterate over the mappings and find the correct place to insert this mapping relative to the
                // indecies of the others.
                SDOType containingType = getContainingType();
                Vector<DatabaseMapping> mappings = containingType.getXmlDescriptor().getMappings();
                boolean added = false;
                for (int i = 0; i < mappings.size(); i++) {
                    DatabaseMapping next = mappings.get(i);
                    SDOProperty associatedProperty = containingType.getProperty(next.getAttributeName());
                    if (associatedProperty != null && indexToAdd < associatedProperty.getIndexInType()) {
                        mappings.add(i, xmlMapping);
                        added = true;
                        break;
                    }
                }
                if (!added) {
                    getContainingType().getXmlDescriptor().getMappings().add(xmlMapping);
                }
            }
        }
    }
}
Also used : ClassDescriptor(org.eclipse.persistence.descriptors.ClassDescriptor) XMLMapping(org.eclipse.persistence.oxm.mappings.XMLMapping) SDOMethodAttributeAccessor(org.eclipse.persistence.sdo.helper.SDOMethodAttributeAccessor) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 2 with SDOMethodAttributeAccessor

use of org.eclipse.persistence.sdo.helper.SDOMethodAttributeAccessor in project eclipselink by eclipse-ee4j.

the class SDOWrapperType method initializeDescriptor.

private void initializeDescriptor(XMLDescriptor aDescriptor, QName aQName, Type aPropertyType, SDOProperty aValueProperty) {
    aDescriptor.setNamespaceResolver(null);
    SDOMethodAttributeAccessor accessor = null;
    accessor = new SDOMethodAttributeAccessor(aValueProperty);
    if (XMLConstants.QNAME_QNAME.equals(aQName)) {
        XMLTransformationMapping mapping = new XMLTransformationMapping();
        mapping.setAttributeName(ATTRIBUTE_NAME);
        QNameTransformer transformer = new QNameTransformer("text()");
        mapping.setAttributeTransformer(transformer);
        mapping.addFieldTransformer(XPATH, transformer);
        NamespaceResolver nsr = new NamespaceResolver();
        nsr.setDefaultNamespaceURI(javax.xml.XMLConstants.XMLNS_ATTRIBUTE_NS_URI);
        XMLField field = new XMLField();
        field.setNamespaceResolver(nsr);
        field.setXPath("@" + javax.xml.XMLConstants.XMLNS_ATTRIBUTE);
        mapping.addFieldTransformer(field, new NamespaceURITransformer());
        mapping.setAttributeAccessor(accessor);
        aDescriptor.addMapping(mapping);
    } else {
        XMLDirectMapping mapping = new XMLDirectMapping();
        mapping.setAttributeName(ATTRIBUTE_NAME);
        mapping.setXPath(XPATH);
        mapping.setAttributeClassification(aPropertyType.getInstanceClass());
        ((XMLField) mapping.getField()).setSchemaType(aQName);
        mapping.setAttributeAccessor(accessor);
        aDescriptor.addMapping(mapping);
    }
    aDescriptor.setIsWrapper(true);
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping) QNameTransformer(org.eclipse.persistence.sdo.helper.metadata.QNameTransformer) XMLTransformationMapping(org.eclipse.persistence.oxm.mappings.XMLTransformationMapping) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) SDOMethodAttributeAccessor(org.eclipse.persistence.sdo.helper.SDOMethodAttributeAccessor) NamespaceURITransformer(org.eclipse.persistence.sdo.helper.metadata.NamespaceURITransformer)

Aggregations

SDOMethodAttributeAccessor (org.eclipse.persistence.sdo.helper.SDOMethodAttributeAccessor)2 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)1 XMLField (org.eclipse.persistence.oxm.XMLField)1 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)1 XMLMapping (org.eclipse.persistence.oxm.mappings.XMLMapping)1 XMLTransformationMapping (org.eclipse.persistence.oxm.mappings.XMLTransformationMapping)1 NamespaceURITransformer (org.eclipse.persistence.sdo.helper.metadata.NamespaceURITransformer)1 QNameTransformer (org.eclipse.persistence.sdo.helper.metadata.QNameTransformer)1