Search in sources :

Example 1 with SDOTypeHelper

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

the class SDODataObject method defineOpenContentProperty.

public Property defineOpenContentProperty(String name, Object value, Type sdotype) throws UnsupportedOperationException, IllegalArgumentException {
    if (value == null) {
        return null;
    }
    if (sdotype == null) {
        return defineOpenContentProperty(name, value);
    }
    DataObject propertyDO = aHelperContext.getDataFactory().create(SDOConstants.SDO_URL, SDOConstants.PROPERTY);
    propertyDO.set("name", name);
    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);
                }
            }
        }
        isMany = true;
    } else if (value instanceof DataObject) {
        if (((DataObject) value).getContainer() == null) {
            isContainment = true;
        }
        sdotype = ((DataObject) value).getType();
    } else {
        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) DataObject(commonj.sdo.DataObject) Collection(java.util.Collection) DataObject(commonj.sdo.DataObject) SequencedObject(org.eclipse.persistence.oxm.sequenced.SequencedObject)

Example 2 with SDOTypeHelper

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

the class SDOSequence method convertToSetting.

private Setting convertToSetting(Property property, Object value) {
    SDOProperty sdoProperty = (SDOProperty) property;
    DatabaseMapping mapping = sdoProperty.getXmlMapping();
    Setting setting = new Setting();
    SDOType sdoType = dataObject.getType();
    XMLDescriptor xmlDescriptor = sdoType.getXmlDescriptor();
    if (null == mapping) {
        setting.setObject(dataObject);
        mapping = xmlDescriptor.getMappingForAttributeName("openContentProperties");
        setting.setMapping(mapping);
        XMLRoot xmlRoot = new XMLRoot();
        if (value instanceof XMLRoot) {
            xmlRoot.setLocalName(((XMLRoot) value).getLocalName());
            xmlRoot.setNamespaceURI(((XMLRoot) value).getNamespaceURI());
            xmlRoot.setObject(((XMLRoot) value).getObject());
        } else {
            xmlRoot.setLocalName(sdoProperty.getName());
            xmlRoot.setNamespaceURI(sdoProperty.getUri());
            xmlRoot.setObject(value);
            // do not set schema type for global properties
            SDOTypeHelper hlpr = (SDOTypeHelper) dataObject.getType().getHelperContext().getTypeHelper();
            if (hlpr.getOpenContentProperty(sdoProperty.getUri(), sdoProperty.getName()) == null) {
                QName schemaTypeQName = hlpr.getXSDTypeFromSDOType(property.getType());
                if (schemaTypeQName != null && schemaTypeQName != XMLConstants.STRING_QNAME) {
                    xmlRoot.setSchemaType(schemaTypeQName);
                }
            }
        }
        setting.setValue(xmlRoot, false);
    } else {
        setting = convertToSetting(mapping, value);
    }
    return setting;
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) XMLRoot(org.eclipse.persistence.oxm.XMLRoot) QName(javax.xml.namespace.QName) Setting(org.eclipse.persistence.oxm.sequenced.Setting) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping)

Example 3 with SDOTypeHelper

use of org.eclipse.persistence.sdo.helper.SDOTypeHelper 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 4 with SDOTypeHelper

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

the class SDOXMLHelperDelegate method getXmlMarshaller.

private XMLMarshaller getXmlMarshaller(Object options) {
    XMLMarshaller xmlMarshaller = getXmlMarshaller().clone();
    if (null == options) {
        return xmlMarshaller;
    }
    try {
        DataObject optionsDO = (DataObject) options;
        if (optionsDO.isSet(SDOConstants.ATTACHMENT_MARSHALLER_OPTION)) {
            xmlMarshaller.setAttachmentMarshaller((XMLAttachmentMarshaller) optionsDO.get(SDOConstants.ATTACHMENT_MARSHALLER_OPTION));
        }
        xmlMarshaller.setMarshalListener(new SDOMarshalListener(xmlMarshaller, (SDOTypeHelper) aHelperContext.getTypeHelper()));
        return xmlMarshaller;
    } catch (ClassCastException ccException) {
        throw SDOException.optionsMustBeADataObject(ccException, SDOConstants.ORACLE_SDO_URL, SDOConstants.XMLHELPER_LOAD_OPTIONS);
    }
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) DataObject(commonj.sdo.DataObject) XMLMarshaller(org.eclipse.persistence.oxm.XMLMarshaller) SDOMarshalListener(org.eclipse.persistence.sdo.helper.SDOMarshalListener)

Example 5 with SDOTypeHelper

use of org.eclipse.persistence.sdo.helper.SDOTypeHelper 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

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