Search in sources :

Example 6 with SDOType

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

the class SDOTypeHelperDelegate method initCommonjHashMap.

/**
 * initializes built-in HashMap commonjHashMap.
 */
private void initCommonjHashMap() {
    commonjHashMap.put(SDOConstants.BOOLEAN, SDOConstants.SDO_BOOLEAN);
    commonjHashMap.put(SDOConstants.BYTE, SDOConstants.SDO_BYTE);
    commonjHashMap.put(SDOConstants.BYTES, SDOConstants.SDO_BYTES);
    commonjHashMap.put(SDOConstants.CHARACTER, SDOConstants.SDO_CHARACTER);
    SDOType dataObjectType = new SDODataObjectType(this);
    commonjHashMap.put(dataObjectType.getName(), dataObjectType);
    commonjHashMap.put(SDOConstants.DATE, SDOConstants.SDO_DATE);
    commonjHashMap.put(SDOConstants.DATETIME, SDOConstants.SDO_DATETIME);
    commonjHashMap.put(SDOConstants.DAY, SDOConstants.SDO_DAY);
    commonjHashMap.put(SDOConstants.DECIMAL, SDOConstants.SDO_DECIMAL);
    commonjHashMap.put(SDOConstants.DOUBLE, SDOConstants.SDO_DOUBLE);
    commonjHashMap.put(SDOConstants.DURATION, SDOConstants.SDO_DURATION);
    commonjHashMap.put(SDOConstants.FLOAT, SDOConstants.SDO_FLOAT);
    commonjHashMap.put(SDOConstants.INT, SDOConstants.SDO_INT);
    commonjHashMap.put(SDOConstants.INTEGER, SDOConstants.SDO_INTEGER);
    commonjHashMap.put(SDOConstants.LONG, SDOConstants.SDO_LONG);
    commonjHashMap.put(SDOConstants.MONTH, SDOConstants.SDO_MONTH);
    commonjHashMap.put(SDOConstants.MONTHDAY, SDOConstants.SDO_MONTHDAY);
    // !! the Generation of Object is not sure yet !!
    commonjHashMap.put(SDOConstants.OBJECT, SDOConstants.SDO_OBJECT);
    commonjHashMap.put(SDOConstants.SHORT, SDOConstants.SDO_SHORT);
    commonjHashMap.put(SDOConstants.STRING, SDOConstants.SDO_STRING);
    commonjHashMap.put(SDOConstants.STRINGS, SDOConstants.SDO_STRINGS);
    commonjHashMap.put(SDOConstants.TIME, SDOConstants.SDO_TIME);
    commonjHashMap.put(SDOConstants.YEAR, SDOConstants.SDO_YEAR);
    commonjHashMap.put(SDOConstants.YEARMONTH, SDOConstants.SDO_YEARMONTH);
    commonjHashMap.put(SDOConstants.YEARMONTHDAY, SDOConstants.SDO_YEARMONTHDAY);
    commonjHashMap.put(SDOConstants.URI, SDOConstants.SDO_URI);
    SDOType changeSummaryType = new SDOChangeSummaryType(this);
    commonjHashMap.put(changeSummaryType.getName(), changeSummaryType);
    SDOType typeType = new SDOTypeType(this);
    commonjHashMap.put(typeType.getName(), typeType);
}
Also used : SDOType(org.eclipse.persistence.sdo.SDOType)

Example 7 with SDOType

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

the class SDOTypeHelperDelegate method defineOpenContentProperty.

/**
 *    Define the DataObject as a Property for setting open content.
 *    The new property or, if already defined, an existing property is returned.
 *    The containing Type of the open property is not specified by SDO.
 *    If the specified uri is not null the defined property is accessible through
 *    TypeHelper.getOpenProperty(uri, propertyName).
 *    If a null uri is specified, the location and management of the open property
 *    is not specified by SDO.
 *    @param uri the namespace URI of the open Property or null.
 *    @return the defined open Property.
 *    @throws IllegalArgumentException if the Property could not be defined.
 */
@Override
public Property defineOpenContentProperty(String uri, DataObject propertyDO) {
    if (propertyDO == null) {
        throw new IllegalArgumentException(SDOException.cannotPerformOperationWithNullInputParameter("defineOpenContentProperty", "propertyDO"));
    }
    String name = propertyDO.getString("name");
    Property propertyToReturn = aHelperContext.getXSDHelper().getGlobalProperty(uri, name, true);
    if (propertyToReturn == null) {
        propertyToReturn = aHelperContext.getXSDHelper().getGlobalProperty(uri, name, false);
    }
    if (propertyToReturn == null) {
        List types = new ArrayList();
        propertyToReturn = buildPropertyFromDataObject(propertyDO, null, types);
        initializeTypes(types);
        defineOpenContentProperty(uri, name, propertyToReturn);
    }
    if (propertyToReturn != null) {
        Object propDOType = propertyDO.get("type");
        SDOType existingType = (SDOType) propertyToReturn.getType();
        boolean typeMismatch = false;
        if (propDOType instanceof SDOType) {
            SDOType newType = (SDOType) propDOType;
            if (!newType.getQName().equals(existingType.getQName())) {
                typeMismatch = true;
            }
        } else if (propDOType instanceof DataObject) {
            DataObject newTypeDO = (DataObject) propDOType;
            if (!newTypeDO.get("name").equals(existingType.getName()) || !newTypeDO.get("uri").equals(existingType.getURI())) {
                typeMismatch = true;
            }
        }
        if (typeMismatch) {
            throw new IllegalArgumentException("Should not be able to redefine a Property with a different Type.");
        }
    }
    return propertyToReturn;
}
Also used : SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) ArrayList(java.util.ArrayList) SDOType(org.eclipse.persistence.sdo.SDOType) ArrayList(java.util.ArrayList) List(java.util.List) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) SDOProperty(org.eclipse.persistence.sdo.SDOProperty) Property(commonj.sdo.Property)

Example 8 with SDOType

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

the class SDOXMLHelperDelegate method getTopLinkProject.

@Override
public Project getTopLinkProject() {
    if (topLinkProject == null) {
        topLinkProject = new Project();
        XMLLogin xmlLogin = new XMLLogin();
        xmlLogin.setEqualNamespaceResolvers(false);
        topLinkProject.setDatasourceLogin(xmlLogin);
        // 200606_changeSummary
        NamespaceResolver nr = new NamespaceResolver();
        SDOTypeHelper sdoTypeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
        String sdoPrefix = sdoTypeHelper.getPrefix(SDOConstants.SDO_URL);
        nr.put(sdoPrefix, SDOConstants.SDO_URL);
        SDOType changeSummaryType = (SDOType) sdoTypeHelper.getType(SDOConstants.SDO_URL, SDOConstants.CHANGESUMMARY);
        changeSummaryType.getXmlDescriptor().setNamespaceResolver(nr);
        topLinkProject.addDescriptor(changeSummaryType.getXmlDescriptor());
        SDOType openSequencedType = (SDOType) aHelperContext.getTypeHelper().getType(SDOConstants.ORACLE_SDO_URL, "OpenSequencedType");
        topLinkProject.addDescriptor(openSequencedType.getXmlDescriptor());
        SDOTypeType typeType = (SDOTypeType) aHelperContext.getTypeHelper().getType(SDOConstants.SDO_URL, SDOConstants.TYPE);
        typeType.getXmlDescriptor().setNamespaceResolver(nr);
        if (!typeType.isInitialized()) {
            typeType.initializeMappings();
        }
        topLinkProject.addDescriptor(typeType.getXmlDescriptor());
        SDOPropertyType propertyType = (SDOPropertyType) aHelperContext.getTypeHelper().getType(SDOConstants.SDO_URL, SDOConstants.PROPERTY);
        if (!propertyType.isInitialized()) {
            propertyType.initializeMappings();
        }
        topLinkProject.addDescriptor(propertyType.getXmlDescriptor());
        ((SDOTypeHelper) aHelperContext.getTypeHelper()).addWrappersToProject(topLinkProject);
    }
    return topLinkProject;
}
Also used : Project(org.eclipse.persistence.sessions.Project) SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) SDOTypeType(org.eclipse.persistence.sdo.types.SDOTypeType) XMLLogin(org.eclipse.persistence.oxm.XMLLogin) SDOType(org.eclipse.persistence.sdo.SDOType) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver) SDOPropertyType(org.eclipse.persistence.sdo.types.SDOPropertyType)

Example 9 with SDOType

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

the class SDOXMLHelperDelegate method load.

/**
 * Creates and returns an XMLDocument from the inputSource.
 * The InputSource will be closed after reading.
 * By default does not perform XSD validation.
 * @param inputSource specifies the InputSource to read from
 * @param locationURI specifies the URI of the document for relative schema locations
 * @param options implementation-specific options.
 * @return the new XMLDocument loaded
 * @throws IOException for stream exceptions.
 * @throws RuntimeException for errors in XML parsing or
 *    implementation-specific validation.
 */
@Override
public XMLDocument load(InputSource inputSource, String locationURI, Object options) throws IOException {
    // get XMLUnmarshaller once - as we may create a new instance if this helper isDirty=true
    XMLUnmarshaller anXMLUnmarshaller = getXmlUnmarshaller(options);
    Object unmarshalledObject = null;
    if (options == null) {
        try {
            unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource);
        } catch (XMLMarshalException xmlException) {
            handleXMLMarshalException(xmlException);
        }
    } else {
        try {
            DataObject optionsDataObject = (DataObject) options;
            try {
                SDOType theType = (SDOType) optionsDataObject.get(SDOConstants.TYPE_LOAD_OPTION);
                try {
                    if (theType != null) {
                        if (theType.isDataType()) {
                            theType = (SDOType) ((SDOTypeHelper) this.aHelperContext.getTypeHelper()).getWrappersHashMap().get(theType.getQName());
                        }
                        if (theType != null) {
                            unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource, theType.getImplClass());
                        } else {
                            unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource);
                        }
                    } else {
                        unmarshalledObject = anXMLUnmarshaller.unmarshal(inputSource);
                    }
                } catch (XMLMarshalException xmlException) {
                    handleXMLMarshalException(xmlException);
                }
            } catch (ClassCastException ccException) {
                throw SDOException.typePropertyMustBeAType(ccException);
            }
        } catch (ClassCastException ccException) {
            throw SDOException.optionsMustBeADataObject(ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
        }
    }
    if (unmarshalledObject instanceof XMLRoot) {
        XMLRoot xmlRoot = (XMLRoot) unmarshalledObject;
        XMLDocument xmlDocument = createDocument((DataObject) ((XMLRoot) unmarshalledObject).getObject(), ((XMLRoot) unmarshalledObject).getNamespaceURI(), ((XMLRoot) unmarshalledObject).getLocalName());
        if (xmlRoot.getEncoding() != null) {
            xmlDocument.setEncoding(xmlRoot.getEncoding());
        }
        if (xmlRoot.getXMLVersion() != null) {
            xmlDocument.setXMLVersion(xmlRoot.getXMLVersion());
        }
        xmlDocument.setSchemaLocation(xmlRoot.getSchemaLocation());
        xmlDocument.setNoNamespaceSchemaLocation(xmlRoot.getNoNamespaceSchemaLocation());
        return xmlDocument;
    } else if (unmarshalledObject instanceof DataObject) {
        String localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXmlDescriptor().getDefaultRootElement();
        if (localName == null) {
            localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXsdLocalName();
        }
        return createDocument((DataObject) unmarshalledObject, ((DataObject) unmarshalledObject).getType().getURI(), localName);
    } else if (unmarshalledObject instanceof XMLDocument) {
        return (XMLDocument) unmarshalledObject;
    }
    return null;
}
Also used : DataObject(commonj.sdo.DataObject) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) SDOType(org.eclipse.persistence.sdo.SDOType) DataObject(commonj.sdo.DataObject) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) SDOXMLDocument(org.eclipse.persistence.sdo.SDOXMLDocument) XMLDocument(commonj.sdo.helper.XMLDocument)

Example 10 with SDOType

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

the class SDOXMLHelperDelegate method load.

@Override
public XMLDocument load(Source source, String locationURI, Object options) throws IOException {
    // get XMLUnmarshaller once - as we may create a new instance if this helper isDirty=true
    XMLUnmarshaller anXMLUnmarshaller = getXmlUnmarshaller(options);
    Object unmarshalledObject = null;
    if (options == null) {
        try {
            unmarshalledObject = anXMLUnmarshaller.unmarshal(source);
        } catch (XMLMarshalException xmlException) {
            handleXMLMarshalException(xmlException);
        }
    } else {
        try {
            DataObject optionsDataObject = (DataObject) options;
            try {
                SDOType theType = (SDOType) optionsDataObject.get(SDOConstants.TYPE_LOAD_OPTION);
                try {
                    if (theType != null) {
                        if (theType.isDataType()) {
                            theType = (SDOType) ((SDOTypeHelper) this.aHelperContext.getTypeHelper()).getWrappersHashMap().get(theType.getQName());
                        }
                        if (theType != null) {
                            unmarshalledObject = anXMLUnmarshaller.unmarshal(source, theType.getImplClass());
                        } else {
                            unmarshalledObject = anXMLUnmarshaller.unmarshal(source);
                        }
                    } else {
                        unmarshalledObject = anXMLUnmarshaller.unmarshal(source);
                    }
                } catch (XMLMarshalException xmlException) {
                    handleXMLMarshalException(xmlException);
                }
            } catch (ClassCastException ccException) {
                throw SDOException.typePropertyMustBeAType(ccException);
            }
        } catch (ClassCastException ccException) {
            throw SDOException.optionsMustBeADataObject(ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
        }
    }
    if (unmarshalledObject instanceof XMLRoot) {
        XMLRoot xmlRoot = (XMLRoot) unmarshalledObject;
        XMLDocument xmlDocument = createDocument((DataObject) ((XMLRoot) unmarshalledObject).getObject(), ((XMLRoot) unmarshalledObject).getNamespaceURI(), ((XMLRoot) unmarshalledObject).getLocalName());
        if (xmlRoot.getEncoding() != null) {
            xmlDocument.setEncoding(xmlRoot.getEncoding());
        }
        if (xmlRoot.getXMLVersion() != null) {
            xmlDocument.setXMLVersion(xmlRoot.getXMLVersion());
        }
        xmlDocument.setSchemaLocation(xmlRoot.getSchemaLocation());
        xmlDocument.setNoNamespaceSchemaLocation(xmlRoot.getNoNamespaceSchemaLocation());
        return xmlDocument;
    } else if (unmarshalledObject instanceof DataObject) {
        DataObject unmarshalledDataObject = (DataObject) unmarshalledObject;
        String localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXmlDescriptor().getDefaultRootElement();
        if (localName == null) {
            localName = ((SDOType) ((DataObject) unmarshalledObject).getType()).getXsdLocalName();
        }
        return createDocument(unmarshalledDataObject, unmarshalledDataObject.getType().getURI(), localName);
    } else if (unmarshalledObject instanceof XMLDocument) {
        return (XMLDocument) unmarshalledObject;
    }
    return null;
}
Also used : DataObject(commonj.sdo.DataObject) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) SDOType(org.eclipse.persistence.sdo.SDOType) DataObject(commonj.sdo.DataObject) XMLUnmarshaller(org.eclipse.persistence.oxm.XMLUnmarshaller) XMLMarshalException(org.eclipse.persistence.exceptions.XMLMarshalException) SDOXMLDocument(org.eclipse.persistence.sdo.SDOXMLDocument) XMLDocument(commonj.sdo.helper.XMLDocument)

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