Search in sources :

Example 11 with SDOTypeHelper

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

the class ContainmentTestCases method getRootSDOType.

public SDOType getRootSDOType() {
    SDOType type = new SDOType("http://testing", "myRoot");
    type.setOpen(true);
    type.setAbstract(false);
    SDOProperty prop = new SDOProperty(aHelperContext);
    prop.setName("name");
    prop.setType(SDOConstants.SDO_STRING);
    prop.setContainingType(type);
    type.addDeclaredProperty(prop);
    SDOProperty prop2 = new SDOProperty(aHelperContext);
    prop2.setName("child");
    prop2.setType(typeHelper.getType("http://testing", "firstChildType"));
    prop2.setContainment(true);
    prop2.setContainingType(type);
    type.addDeclaredProperty(prop2);
    SDOProperty prop3 = new SDOProperty(aHelperContext);
    prop3.setName("child2");
    prop3.setType(typeHelper.getType("http://testing", "firstChildType"));
    prop3.setContainment(true);
    prop3.setContainingType(type);
    type.addDeclaredProperty(prop3);
    SDOProperty prop4 = new SDOProperty(aHelperContext);
    prop4.setName("nullTypeProp");
    // we were omitting setting the Type on purpose here - we don't need it - just add anything
    prop4.setType(SDOConstants.SDO_BOOLEAN);
    prop4.setContainingType(type);
    type.addDeclaredProperty(prop4);
    ((SDOTypeHelper) typeHelper).addType(type);
    return type;
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) SDOType(org.eclipse.persistence.sdo.SDOType) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Example 12 with SDOTypeHelper

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

the class SDODataObject method _setOpenContentPropertiesWithXMLRoots.

/**
 * INTERNAL:
 * This function is implemented by SDOType.setOpen() in a mapping setGet/SetMethodName call
 * @param openContentPropertiesWithXMLRoots
 */
public void _setOpenContentPropertiesWithXMLRoots(List openContentPropertiesWithXMLRoots) {
    for (int i = 0, size = openContentPropertiesWithXMLRoots.size(); i < size; i++) {
        Object next = openContentPropertiesWithXMLRoots.get(i);
        String propertyName = null;
        String propertyUri = null;
        Object value = null;
        Type theType = null;
        if (next instanceof XMLRoot) {
            XMLRoot nextXMLRoot = (XMLRoot) next;
            value = nextXMLRoot.getObject();
            propertyName = nextXMLRoot.getLocalName();
            propertyUri = nextXMLRoot.getNamespaceURI();
            if (value instanceof DataObject) {
                theType = ((DataObject) value).getType();
            } else {
                theType = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getTypeForSimpleJavaType(value.getClass());
            }
        } else if (next instanceof DataObject) {
            value = next;
            String qualifiedName = ((SDOType) ((DataObject) next).getType()).getXmlDescriptor().getDefaultRootElement();
            int colonIndex = qualifiedName.indexOf(':');
            if (colonIndex > -1) {
                String prefix = qualifiedName.substring(0, colonIndex);
                if ((prefix != null) && !prefix.equals("")) {
                    propertyUri = ((SDOType) ((DataObject) next).getType()).getXmlDescriptor().getNonNullNamespaceResolver().resolveNamespacePrefix(prefix);
                }
                propertyName = qualifiedName.substring(colonIndex + 1, qualifiedName.length());
            } else {
                propertyName = qualifiedName;
            }
            theType = ((DataObject) next).getType();
        } else {
            theType = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getTypeForSimpleJavaType(next.getClass());
        }
        if (propertyName != null) {
            SDOProperty prop = (SDOProperty) aHelperContext.getXSDHelper().getGlobalProperty(propertyUri, propertyName, true);
            if (prop == null) {
                prop = getInstanceProperty(propertyName);
                if (prop != null) {
                    if (prop.getUri() == null && propertyUri != null) {
                        prop = createNewProperty(propertyName, propertyUri, theType);
                    } else {
                        if (prop.getUri() != null) {
                            if (propertyUri == null) {
                                prop = createNewProperty(propertyName, propertyUri, theType);
                            } else if (!prop.getUri().equals(propertyUri)) {
                                prop = createNewProperty(propertyName, propertyUri, theType);
                            }
                        }
                    }
                } else {
                    prop = createNewProperty(propertyName, propertyUri, theType);
                }
            }
            if (prop.isMany()) {
                ((ListWrapper) getList(prop)).add(value, false);
            } else {
                set(prop, value, false);
            }
        }
    }
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) Type(commonj.sdo.Type) DataObject(commonj.sdo.DataObject) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) ListWrapper(org.eclipse.persistence.sdo.helper.ListWrapper) DataObject(commonj.sdo.DataObject) SequencedObject(org.eclipse.persistence.oxm.sequenced.SequencedObject)

Example 13 with SDOTypeHelper

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

the class SDODataObject method defineOpenContentProperty.

/**
 * INTERNAL:
 * Create a dynamic open content property if no property exists for (name).
 * @param name
 * @param value
 * @return Property
 * @throws UnsupportedOperationException
 * @throws IllegalArgumentException
 */
public Property defineOpenContentProperty(String name, Object value) throws UnsupportedOperationException, IllegalArgumentException {
    if (value == null) {
        return null;
    }
    DataObject propertyDO = aHelperContext.getDataFactory().create(SDOConstants.SDO_URL, SDOConstants.PROPERTY);
    propertyDO.set("name", name);
    Type sdotype = null;
    boolean isMany = false;
    boolean isContainment = false;
    Class<? extends Object> valueClass = value.getClass();
    if (value instanceof Collection) {
        if (((Collection) value).size() > 0) {
            Object firstObject = ((Collection) value).iterator().next();
            if (firstObject != null) {
                valueClass = firstObject.getClass();
                if (firstObject instanceof DataObject) {
                    if (((DataObject) firstObject).getContainer() == null) {
                        isContainment = true;
                    }
                    sdotype = ((DataObject) firstObject).getType();
                } else {
                    sdotype = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getTypeForSimpleJavaType(valueClass);
                }
            } else {
                return null;
            }
        } else {
            return null;
        }
        isMany = true;
    } else if (value instanceof DataObject) {
        if (((DataObject) value).getContainer() == null) {
            isContainment = true;
        }
        sdotype = ((DataObject) value).getType();
    } else {
        Property xmlElementProperty = aHelperContext.getTypeHelper().getOpenContentProperty(SDOConstants.SDOXML_URL, SDOConstants.XMLELEMENT_PROPERTY_NAME);
        propertyDO.set(xmlElementProperty, Boolean.TRUE);
        sdotype = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getTypeForSimpleJavaType(valueClass);
    }
    propertyDO.set("type", sdotype);
    propertyDO.set("many", isMany);
    propertyDO.set("containment", isContainment);
    return aHelperContext.getTypeHelper().defineOpenContentProperty(null, propertyDO);
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) Type(commonj.sdo.Type) DataObject(commonj.sdo.DataObject) Collection(java.util.Collection) DataObject(commonj.sdo.DataObject) SequencedObject(org.eclipse.persistence.oxm.sequenced.SequencedObject) Property(commonj.sdo.Property)

Example 14 with SDOTypeHelper

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

the class SDOType method initializeNamespaces.

/**
 * INTERNAL:
 * Get the XMLDescriptor associated with this Type or generate a new one.
 */
public void initializeNamespaces(List namespaceResolvers) {
    if (!isDataType()) {
        NamespaceResolver nr = new NamespaceResolver();
        // copy namespaces between resolvers for well known and SDO namespaces
        if (namespaceResolvers != null) {
            for (int i = 0; i < namespaceResolvers.size(); i++) {
                NamespaceResolver nextNR = (NamespaceResolver) namespaceResolvers.get(i);
                if (nextNR != null) {
                    for (int j = 0, size = nextNR.getNamespaces().size(); j < size; j++) {
                        Namespace nextNamespace = nextNR.getNamespaces().get(j);
                        if ((!nextNamespace.getPrefix().equals(javax.xml.XMLConstants.XMLNS_ATTRIBUTE)) && (!nextNamespace.getNamespaceURI().equals(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI)) && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDOJAVA_URL)) && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDOXML_URL)) && (!nextNamespace.getNamespaceURI().equals(SDOConstants.SDO_URL))) {
                            String newPrefix = ((SDOTypeHelper) aHelperContext.getTypeHelper()).addNamespace(nextNamespace.getPrefix(), nextNamespace.getNamespaceURI());
                            nr.put(newPrefix, nextNamespace.getNamespaceURI());
                        }
                    }
                }
            }
        }
        xmlDescriptor.setNamespaceResolver(nr);
        if (getURI() != null) {
            String prefix = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getPrefix(getURI());
            xmlDescriptor.getNamespaceResolver().put(prefix, getURI());
        }
        xmlDescriptor.getNamespaceResolver().put(XMLConstants.SCHEMA_INSTANCE_PREFIX, javax.xml.XMLConstants.W3C_XML_SCHEMA_INSTANCE_NS_URI);
    }
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) Namespace(org.eclipse.persistence.internal.oxm.Namespace)

Example 15 with SDOTypeHelper

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

the class SDOType method postInitialize.

/**
 * INTERNAL:
 */
public void postInitialize() {
    String idPropName = (String) get(SDOConstants.ID_PROPERTY);
    if (idPropName != null) {
        SDOProperty idProp = getProperty(idPropName);
        if (idProp != null) {
            String targetxpath = idProp.getQualifiedXPath(getURI(), true);
            getXmlDescriptor().addPrimaryKeyFieldName(targetxpath);
        }
    }
    setFinalized(true);
    if (null != nonFinalizedReferencingProps) {
        for (int i = 0; i < nonFinalizedReferencingProps.size(); i++) {
            SDOProperty nextProp = nonFinalizedReferencingProps.get(i);
            String nextURI = (String) getNonFinalizedMappingURIs().get(i);
            nextProp.buildMapping(nextURI, nextProp.getIndexInType());
        }
        nonFinalizedReferencingProps = null;
        nonFinalizedMappingURIs = null;
    }
    // set @sdoRef attribute mapping for complex types that are not involved in inheritance
    if (!isDataType() && !isSubType() && !isBaseType()) {
        String sdoPrefix = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getPrefix(SDOConstants.SDO_URL);
        XMLDirectMapping sdoRefMapping = new XMLDirectMapping();
        sdoRefMapping.setAttributeName(SDO_REF_MAPPING_ATTRIBUTE_NAME);
        XMLField xmlField = new XMLField("@" + sdoPrefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + SDOConstants.CHANGESUMMARY_REF);
        xmlField.getXPathFragment().setNamespaceURI(SDOConstants.SDO_URL);
        xmlField.getLastXPathFragment().setNamespaceURI(SDOConstants.SDO_URL);
        sdoRefMapping.setField(xmlField);
        xmlDescriptor.addMapping(sdoRefMapping);
    }
    if (!isDataType()) {
        getImplClass();
        if (!isAbstract() && !isWrapperType()) {
            TypeInstantiationPolicy tip = new TypeInstantiationPolicy(this);
            this.xmlDescriptor.setInstantiationPolicy(tip);
        }
    }
}
Also used : XMLField(org.eclipse.persistence.oxm.XMLField) SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) XMLDirectMapping(org.eclipse.persistence.oxm.mappings.XMLDirectMapping)

Aggregations

SDOTypeHelper (org.eclipse.persistence.sdo.helper.SDOTypeHelper)31 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)17 SDOType (org.eclipse.persistence.sdo.SDOType)17 DataObject (commonj.sdo.DataObject)13 Type (commonj.sdo.Type)9 ArrayList (java.util.ArrayList)9 List (java.util.List)7 QName (javax.xml.namespace.QName)3 SequencedObject (org.eclipse.persistence.oxm.sequenced.SequencedObject)3 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)3 SDOXSDHelper (org.eclipse.persistence.sdo.helper.SDOXSDHelper)3 Collection (java.util.Collection)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)2 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)2 XMLField (org.eclipse.persistence.oxm.XMLField)2 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)2 XMLRoot (org.eclipse.persistence.oxm.XMLRoot)2 XMLDirectMapping (org.eclipse.persistence.oxm.mappings.XMLDirectMapping)2 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)2