Search in sources :

Example 1 with SDOProperty

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

the class SDOTypeHelperDelegate method initOpenProps.

private void initOpenProps() {
    SDOType typeType = this.getType(SDOConstants.SDO_URL, SDOConstants.TYPE);
    openContentProperties = new HashMap();
    openContentProperties.put(SDOConstants.MIME_TYPE_QNAME, SDOConstants.MIME_TYPE_PROPERTY);
    openContentProperties.put(SDOConstants.MIME_TYPE_PROPERTY_QNAME, SDOConstants.MIME_TYPE_PROPERTY_PROPERTY);
    openContentProperties.put(SDOConstants.SCHEMA_TYPE_QNAME, new SDOProperty(aHelperContext, SDOConstants.ORACLE_SDO_URL, SDOConstants.XML_SCHEMA_TYPE_NAME, typeType));
    openContentProperties.put(SDOConstants.JAVA_CLASS_QNAME, SDOConstants.JAVA_CLASS_PROPERTY);
    openContentProperties.put(SDOConstants.XML_ELEMENT_QNAME, SDOConstants.XMLELEMENT_PROPERTY);
    openContentProperties.put(SDOConstants.XML_DATATYPE_QNAME, new SDOProperty(aHelperContext, SDOConstants.SDOXML_URL, SDOConstants.SDOXML_DATATYPE, typeType));
    openContentProperties.put(SDOConstants.XML_ID_PROPERTY_QNAME, SDOConstants.ID_PROPERTY);
    openContentProperties.put(SDOConstants.DOCUMENTATION_PROPERTY_QNAME, SDOConstants.DOCUMENTATION_PROPERTY);
}
Also used : HashMap(java.util.HashMap) SDOType(org.eclipse.persistence.sdo.SDOType) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Example 2 with SDOProperty

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

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

the class SDOXSDHelperDelegate method isElement.

/**
 * Returns true if the property is declared as an element in the XSD.
 * Returns false if not known or for advanced cases.
 * It is possible for both isAttribute and isElement to return false
 * but they will not both return true.
 * @param property to identify if an element.
 * @return true if the property is declared as an element in the XSD.
 */
@Override
public boolean isElement(Property property) {
    if (property == null) {
        return false;
    }
    SDOProperty sdoProperty = (SDOProperty) property;
    Object value = sdoProperty.get(SDOConstants.XMLELEMENT_PROPERTY);
    if ((value != null) && value instanceof Boolean) {
        return (Boolean) value;
    }
    if ((sdoProperty.getOpposite() != null) && (sdoProperty.getOpposite().isContainment())) {
        return false;
    } else if (sdoProperty.isMany() || sdoProperty.isContainment() || sdoProperty.isNullable()) {
        return true;
    }
    return false;
}
Also used : SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Example 4 with SDOProperty

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

the class SDOXSDHelperDelegate method isAttribute.

/**
 * Returns true if the property is declared as an attribute in the XSD.
 * Returns false if not known or for advanced cases.
 * It is possible for both isAttribute and isElement to return false
 * but they will not both return true.
 * @param property to identify if an attribute.
 * @return true if the property is declared as an attribute in the XSD.
 */
@Override
public boolean isAttribute(Property property) {
    if (property == null) {
        return false;
    }
    SDOProperty sdoProperty = (SDOProperty) property;
    Object value = sdoProperty.get(SDOConstants.XMLELEMENT_PROPERTY);
    if ((value != null) && value instanceof Boolean) {
        boolean isElement = (Boolean) value;
        if (isElement) {
            return false;
        }
    }
    if ((sdoProperty.getOpposite() != null) && (sdoProperty.getOpposite().isContainment())) {
        return false;
    } else if (sdoProperty.isMany() || sdoProperty.isContainment() || sdoProperty.isNullable()) {
        return false;
    }
    // Case: open content non-attribute property
    return true;
}
Also used : SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Example 5 with SDOProperty

use of org.eclipse.persistence.sdo.SDOProperty 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)

Aggregations

SDOProperty (org.eclipse.persistence.sdo.SDOProperty)1552 SDOType (org.eclipse.persistence.sdo.SDOType)233 DataObject (commonj.sdo.DataObject)220 Type (commonj.sdo.Type)188 ArrayList (java.util.ArrayList)155 List (java.util.List)153 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)124 BigInteger (java.math.BigInteger)105 BigDecimal (java.math.BigDecimal)96 Date (java.util.Date)30 Property (commonj.sdo.Property)29 SDOSequence (org.eclipse.persistence.sdo.SDOSequence)21 SDOTypeHelper (org.eclipse.persistence.sdo.helper.SDOTypeHelper)17 QName (javax.xml.namespace.QName)16 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)15 SDOException (org.eclipse.persistence.exceptions.SDOException)14 ChangeSummary (commonj.sdo.ChangeSummary)10 Calendar (java.util.Calendar)10 Iterator (java.util.Iterator)8 ListWrapper (org.eclipse.persistence.sdo.helper.ListWrapper)8