Search in sources :

Example 11 with SDOType

use of org.eclipse.persistence.sdo.SDOType 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 12 with SDOType

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

the class TypeStringConverter method convertObjectValueToDataValue.

@Override
public Object convertObjectValueToDataValue(Object object, Session session) {
    if (!(object instanceof SDOType)) {
        return null;
    }
    SDOType type = (SDOType) object;
    String typeString = type.getURI() + "#" + type.getName();
    return typeString;
}
Also used : SDOType(org.eclipse.persistence.sdo.SDOType)

Example 13 with SDOType

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

the class SDOEqualityHelperTest method testDeepEqualWithTwoDataObjectsHavingManyTypePropertiesDataObjectsFailListSizeUnequal.

// compare DataObject with properties as many
public void testDeepEqualWithTwoDataObjectsHavingManyTypePropertiesDataObjectsFailListSizeUnequal() {
    // rootProperty4.setContainment(false);
    // SDOType rootProperty4_type = new SDOType("", "");
    // rootProperty4.setType(SDOConstants.SDO_STRING);
    SDOType mockType = new SDOType("uri", "name");
    SDOProperty p = new SDOProperty(aHelperContext);
    p.setContainment(false);
    p.setMany(false);
    p.setName("fortest");
    p.setType(SDOConstants.SDO_STRING);
    mockType.addDeclaredProperty(p);
    DataObject d1 = dataFactory.create(mockType);
    DataObject d2 = dataFactory.create(mockType);
    DataObject d3 = dataFactory.create(mockType);
    DataObject d4 = dataFactory.create(mockType);
    objects.add(d1);
    objects.add(d3);
    // objects1.add(d4);
    objects1.add(d2);
    // d4.set(p, "fail");
    rootProperty4.setMany(true);
    root.set(rootProperty4, objects);
    root1.set(rootProperty4, objects1);
    assertFalse(equalityHelper.equal(root, root1));
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) SDOType(org.eclipse.persistence.sdo.SDOType) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Example 14 with SDOType

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

the class SDOEqualityHelperTest method testDeepEqualWithADataObjectToAnotherOpenContentPropertiesNotDataTypeBoth.

// purpose: one has open content datatype property while another doesn't
public void testDeepEqualWithADataObjectToAnotherOpenContentPropertiesNotDataTypeBoth() {
    SDOProperty openP = new SDOProperty(aHelperContext);
    openP.setName("open");
    openP.setContainment(true);
    openP.setMany(false);
    openP.setType(new SDOType("", ""));
    containedType.setOpen(true);
    SDOType mockType = new SDOType("uri", "name");
    DataObject d1 = dataFactory.create(mockType);
    DataObject d2 = dataFactory.create(mockType);
    containedDataObject.set(openP, d1);
    containedDataObject_1.set(openP, d2);
    assertTrue(equalityHelper.equal(root, root1));
}
Also used : DataObject(commonj.sdo.DataObject) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) SDOType(org.eclipse.persistence.sdo.SDOType) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Example 15 with SDOType

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

the class SDOHelperContextTest method testMultipleInstancesOfContexts.

public void testMultipleInstancesOfContexts() {
    SDOProperty property1 = aNonStaticHelperContext1DataObject.getInstanceProperty("address");
    SDOProperty property2 = aNonStaticHelperContext2DataObject.getInstanceProperty("address");
    SDOProperty property3 = aStaticHelperContextDataObject.getInstanceProperty("address");
    SDOType type1 = aNonStaticHelperContext1DataObject.getInstanceProperty("address").getType();
    SDOType type2 = aNonStaticHelperContext2DataObject.getInstanceProperty("address").getType();
    SDOType type3 = aStaticHelperContextDataObject.getInstanceProperty("address").getType();
    // verify types do not xref
    assertNotSame(type1, type2);
    assertNotSame(type1, type3);
    assertNotSame(type2, type3);
    // modify types in one context
    assertFalse(property1.isMany());
    assertFalse(property2.isMany());
    assertFalse(property3.isMany());
    // change one type from bounded to unbounded
    property1.setMany(true);
    // verify modified types do not affect other context
    assertTrue(property1.isMany());
    assertFalse(property2.isMany());
    assertFalse(property3.isMany());
}
Also used : SDOType(org.eclipse.persistence.sdo.SDOType) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Aggregations

SDOType (org.eclipse.persistence.sdo.SDOType)318 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)158 DataObject (commonj.sdo.DataObject)139 Type (commonj.sdo.Type)132 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)102 ArrayList (java.util.ArrayList)89 List (java.util.List)83 QName (javax.xml.namespace.QName)31 Property (commonj.sdo.Property)30 SDOTypeHelper (org.eclipse.persistence.sdo.helper.SDOTypeHelper)17 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)13 ChangeSummary (commonj.sdo.ChangeSummary)11 SDOWrapperType (org.eclipse.persistence.sdo.types.SDOWrapperType)10 ComplexType (org.eclipse.persistence.internal.oxm.schema.model.ComplexType)9 SimpleType (org.eclipse.persistence.internal.oxm.schema.model.SimpleType)9 XMLDocument (commonj.sdo.helper.XMLDocument)8 SDOXSDHelper (org.eclipse.persistence.sdo.helper.SDOXSDHelper)8 SDODataType (org.eclipse.persistence.sdo.types.SDODataType)7 IOException (java.io.IOException)6 FileInputStream (java.io.FileInputStream)5