Search in sources :

Example 1 with SDODataObject

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

the class SDOTypeHelperDelegate method buildPropertyFromDataObject.

private SDOProperty buildPropertyFromDataObject(DataObject dataObject, Type containingType, List types) {
    String nameValue = dataObject.getString("name");
    Object typeObjectValue = dataObject.get("type");
    if (isXmlNameValidationEnabled && !SDOUtil.isValidXmlNCName(nameValue)) {
        throw new IllegalArgumentException(SDOException.errorDefiningPropertyInvalidName(nameValue));
    }
    SDOProperty newProperty = new SDOProperty(aHelperContext);
    newProperty.setName(nameValue);
    Type typeValue = (Type) getValueFromObject(typeObjectValue, types);
    newProperty.setType(typeValue);
    if (typeValue != null) {
        if (typeValue == SDOConstants.SDO_BYTES) {
            newProperty.setXsdType(XMLConstants.BASE_64_BINARY_QNAME);
        } else if (typeValue.isDataType()) {
            if (isBaseTypeBytes(typeValue)) {
                newProperty.setXsdType(XMLConstants.BASE_64_BINARY_QNAME);
            }
        }
    }
    newProperty.setAppInfoElements((List) dataObject.get(SDOConstants.APPINFO));
    if (dataObject.isSet("containment")) {
        newProperty.setContainment(dataObject.getBoolean("containment"));
    } else {
        if (typeValue != null) {
            newProperty.setContainment(!typeValue.isDataType());
        }
    }
    newProperty.setReadOnly(dataObject.getBoolean("readOnly"));
    newProperty.setMany(dataObject.getBoolean("many"));
    newProperty.setNullable(dataObject.getBoolean("nullable"));
    List aliasNames = dataObject.getList("aliasName");
    for (int i = 0; i < aliasNames.size(); i++) {
        Object aliasName = aliasNames.get(i);
        newProperty.getAliasNames().add(aliasName);
    }
    Object opposite = dataObject.get("opposite");
    if (opposite != null) {
        if (opposite instanceof SDOProperty) {
            newProperty.setOpposite((SDOProperty) opposite);
            ((SDOProperty) opposite).setOpposite(newProperty);
        } else if (opposite instanceof DataObject) {
            SDOProperty prop = (SDOProperty) typeValue.getProperty(((DataObject) opposite).getString("name"));
            if (prop != null) {
                newProperty.setOpposite(prop);
                prop.setOpposite(newProperty);
            }
        }
    }
    // set the default only if the default on the dataObject is set
    if (dataObject.isSet("default")) {
        newProperty.setDefault(dataObject.get("default"));
    }
    List openProps = ((SDODataObject) dataObject)._getOpenContentProperties();
    for (int i = 0; i < openProps.size(); i++) {
        SDOProperty nextProp = (SDOProperty) openProps.get(i);
        Object value = getValueFromObject(dataObject.get(nextProp), types);
        newProperty.setInstanceProperty(nextProp, value);
    }
    List openPropsAttrs = ((SDODataObject) dataObject)._getOpenContentPropertiesAttributes();
    for (int i = 0; i < openPropsAttrs.size(); i++) {
        SDOProperty nextProp = (SDOProperty) openPropsAttrs.get(i);
        Object value = getValueFromObject(dataObject.get(nextProp), types);
        newProperty.setInstanceProperty(nextProp, value);
    }
    // verify that this property has a type set bug 5768381
    if (newProperty.getType() == null) {
        throw SDOException.noTypeSpecifiedForProperty(newProperty.getName());
    }
    if (containingType != null) {
        ((SDOType) containingType).addDeclaredProperty(newProperty);
        if (aHelperContext.getXSDHelper().isElement(newProperty) || newProperty.getType().isChangeSummaryType()) {
            newProperty.setNamespaceQualified(true);
        }
        newProperty.buildMapping(containingType.getURI());
    }
    return newProperty;
}
Also used : Type(commonj.sdo.Type) SDOXMLHelperLoadOptionsType(org.eclipse.persistence.sdo.types.SDOXMLHelperLoadOptionsType) SDOType(org.eclipse.persistence.sdo.SDOType) SDOWrapperType(org.eclipse.persistence.sdo.types.SDOWrapperType) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOType(org.eclipse.persistence.sdo.SDOType) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ArrayList(java.util.ArrayList) List(java.util.List) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 2 with SDODataObject

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

the class XPathEngine method set.

/**
 * Set a property's value.
 *
 * @param lastProperty      the property to queries.
 * @param lastDataObject    the DataObject, owner of the queried property
 * @param numInLastProperty the index number in the value list of the above property
 * @param value             the value to be set as the target property's value
 * @param convertValue     boolean used for set if we should convert the value
 */
private void set(Property lastProperty, DataObject lastDataObject, int numInLastProperty, Object value, boolean convertValue) {
    if (numInLastProperty == -1) {
        if (lastDataObject != null) {
            if (convertValue) {
                DataHelper dataHelper = ((SDODataObject) lastDataObject).getType().getHelperContext().getDataHelper();
                value = dataHelper.convert(lastProperty, value);
            }
            lastDataObject.set(lastProperty, value);
        } else {
            throw new IllegalArgumentException("lastDataObject is null");
        }
    } else {
        // case like set("a/b.1", List) will cause a list be added into a existed list
        List objects = lastDataObject.getList(lastProperty);
        if (convertValue) {
            DataHelper dataHelper = ((SDODataObject) lastDataObject).getType().getHelperContext().getDataHelper();
            value = dataHelper.convert(lastProperty.getType(), value);
        }
        Sequence seq = lastDataObject.getSequence();
        if (seq != null) {
            seq.setValue(numInLastProperty, value);
        } else {
            objects.set(numInLastProperty, value);
        }
    }
}
Also used : List(java.util.List) DataHelper(commonj.sdo.helper.DataHelper) Sequence(commonj.sdo.Sequence) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 3 with SDODataObject

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

the class SDOTypeHelperDelegate method define.

/**
 * Define the DataObject as a Type.
 * The Type is available through TypeHelper and DataGraph getType() methods.
 * @param dataObject the DataObject representing the Type.
 * @return the defined Type.
 * @throws IllegalArgumentException if the Type could not be defined.
 */
public synchronized Type define(DataObject dataObject, List types) {
    SDOTypeHelper typeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
    if ((dataObject == null) || (dataObject.getType() == null) || (!dataObject.getType().getURI().equals(SDOConstants.SDO_URL)) || (!dataObject.getType().getName().equals(SDOConstants.TYPE))) {
        throw new IllegalArgumentException(SDOException.errorDefiningType());
    }
    String uri = dataObject.getString("uri");
    String name = dataObject.getString("name");
    if (name == null) {
        throw new IllegalArgumentException(SDOException.errorDefiningTypeNoName());
    }
    SDOType type = (SDOType) typeHelper.getType(uri, name);
    if (null != type) {
        return type;
    }
    if (isXmlNameValidationEnabled && !SDOUtil.isValidXmlNCName(name)) {
        throw new IllegalArgumentException(SDOException.errorDefiningTypeInvalidName(name));
    }
    boolean isDataType = dataObject.getBoolean("dataType");
    if (isDataType) {
        type = new SDODataType(uri, name, this);
    } else {
        type = new SDOType(uri, name, this);
        if (dataObject.getBoolean("sequenced")) {
            type.setSequenced(true);
            type.setMixed(true);
        }
    }
    type.setDataType(isDataType);
    addType(type);
    types.add(type);
    type.setAppInfoElements((List) dataObject.get(SDOConstants.APPINFO));
    type.setAbstract(dataObject.getBoolean("abstract"));
    List baseTypes = dataObject.getList("baseType");
    for (int i = 0; i < baseTypes.size(); i++) {
        SDOType baseType = (SDOType) getValueFromObject(baseTypes.get(i), types);
        type.addBaseType(baseType);
    }
    List aliasNames = dataObject.getList("aliasName");
    for (int i = 0; i < aliasNames.size(); i++) {
        Object aliasName = aliasNames.get(i);
        type.getAliasNames().add(aliasName);
    }
    List openProps = ((SDODataObject) dataObject)._getOpenContentProperties();
    for (int i = 0; i < openProps.size(); i++) {
        SDOProperty nextProp = (SDOProperty) openProps.get(i);
        Object value = getValueFromObject(dataObject.get(nextProp), types);
        type.setInstanceProperty(nextProp, value);
    }
    List openPropsAttrs = ((SDODataObject) dataObject)._getOpenContentPropertiesAttributes();
    for (int i = 0; i < openPropsAttrs.size(); i++) {
        SDOProperty nextProp = (SDOProperty) openPropsAttrs.get(i);
        Object value = getValueFromObject(dataObject.get(nextProp), types);
        type.setInstanceProperty(nextProp, value);
    }
    if (!type.isDataType()) {
        type.preInitialize(null, null);
    }
    List properties = dataObject.getList("property");
    for (int i = 0; i < properties.size(); i++) {
        Object nextValue = properties.get(i);
        if (nextValue instanceof DataObject) {
            buildPropertyFromDataObject((DataObject) nextValue, type, types);
        }
    }
    type.setOpen(dataObject.getBoolean("open"));
    if (type.isDataType()) {
        QName typeQName = new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI, name);
        if (typeHelper.getWrappersHashMap().get(typeQName) != null) {
            // wrappers created, so do not continue on building a new WrapperType.
            return type;
        }
        // Defining a new simple type from a DataObject.
        // See also: SDOTypesGenerator:startNewSimpleType for "types from XSD" equivalent
        // If this simple type is a restriction, get the QName for the base type and
        // include it when creating the WrapperType.  The QName will be used during
        // conversions (eg. "myBinaryElement" could be a restriction of base64Binary
        // or hexBinary.
        QName currentTypeQName = null;
        if (type.isSubType()) {
            SDOType baseType = (SDOType) type.getBaseTypes().get(0);
            currentTypeQName = new QName(javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI, baseType.getName());
        }
        // Create the new WrapperType
        SDOWrapperType wrapperType = new SDOWrapperType(type, name, this, currentTypeQName);
        // Register WrapperType with maps on TypeHelper
        typeHelper.getWrappersHashMap().put(typeQName, wrapperType);
        typeHelper.getTypesHashMap().put(typeQName, wrapperType);
        typeHelper.getImplClassesToSDOType().put(wrapperType.getXmlDescriptor().getJavaClass(), wrapperType);
        // Add descriptor to XMLHelper
        ArrayList list = new ArrayList(1);
        list.add(wrapperType);
        ((SDOXMLHelper) aHelperContext.getXMLHelper()).addDescriptors(list);
    }
    return type;
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) QName(javax.xml.namespace.QName) SDOWrapperType(org.eclipse.persistence.sdo.types.SDOWrapperType) SDOType(org.eclipse.persistence.sdo.SDOType) ArrayList(java.util.ArrayList) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ArrayList(java.util.ArrayList) List(java.util.List) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 4 with SDODataObject

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

the class SDOTestCase method assertValueStoresInitializedAfterLoggingOn.

/**
 */
// test undo when logging is off (with previous changes)
protected void assertValueStoresInitializedAfterLoggingOn(DataObject aRootObject) {
    // verify logging is on
    assertTrue(aRootObject.getChangeSummary().isLogging());
    // verify original VS is null and save a copy of current VS for object
    // identity testing after undo
    ValueStore aCurrentValueStore = ((SDODataObject) aRootObject)._getCurrentValueStore();
    assertNotNull(aCurrentValueStore);
    ValueStore anOriginalValueStore = (ValueStore) ((SDOChangeSummary) aRootObject.getChangeSummary()).getOriginalValueStores().get(aRootObject);
    assertNull(anOriginalValueStore);
}
Also used : ValueStore(org.eclipse.persistence.sdo.ValueStore) SDOChangeSummary(org.eclipse.persistence.sdo.SDOChangeSummary) SDODataObject(org.eclipse.persistence.sdo.SDODataObject)

Example 5 with SDODataObject

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

the class SDOTestCase method assertChangeSummaryStatusIfClearedIfCSIsAncestor.

/*
     * ChangeSummary specific functions for undoChanges
     */
/**
 */
public void assertChangeSummaryStatusIfClearedIfCSIsAncestor(DataObject currentDO, boolean isCSonAncestor) {
    if (currentDO != null) {
        // check current DO
        if (isCSonAncestor) {
            assertNull(((SDODataObject) currentDO).getChangeSummary());
        } else {
            assertNotNull(((SDODataObject) currentDO).getChangeSummary());
        }
        // check DO's recursively
        List instanceProperties = currentDO.getInstanceProperties();
        for (int i = 0; i < instanceProperties.size(); i++) {
            SDOProperty nextProperty = (SDOProperty) instanceProperties.get(i);
            Object value = currentDO.get(nextProperty);
            if (!nextProperty.getType().isChangeSummaryType() && !nextProperty.getType().isDataType() && value != null) {
                if (nextProperty.isMany()) {
                    // iterate list
                    Object manyItem;
                    // ConcurrentModificationException
                    for (int index = 0; index < ((List) value).size(); index++) {
                        manyItem = ((List) value).get(index);
                        if (manyItem != null) {
                            assertChangeSummaryStatusIfClearedIfCSIsAncestor((SDODataObject) manyItem, isCSonAncestor);
                        }
                    }
                } else {
                    assertChangeSummaryStatusIfClearedIfCSIsAncestor((SDODataObject) value, isCSonAncestor);
                }
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Aggregations

SDODataObject (org.eclipse.persistence.sdo.SDODataObject)301 DataObject (commonj.sdo.DataObject)118 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)99 ArrayList (java.util.ArrayList)79 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)76 SDOType (org.eclipse.persistence.sdo.SDOType)70 List (java.util.List)65 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)64 Property (commonj.sdo.Property)52 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)51 ValueStore (org.eclipse.persistence.sdo.ValueStore)22 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)21 ChangeSummary (commonj.sdo.ChangeSummary)20 SDOMarshalListener (org.eclipse.persistence.sdo.helper.SDOMarshalListener)20 Iterator (java.util.Iterator)18 Type (commonj.sdo.Type)9 XMLDocument (commonj.sdo.helper.XMLDocument)6 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)5 Map (java.util.Map)5