Search in sources :

Example 1 with SDOWrapperType

use of org.eclipse.persistence.sdo.types.SDOWrapperType 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 2 with SDOWrapperType

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

the class SDOTypesGenerator method addRootElementToDescriptor.

private void addRootElementToDescriptor(SDOProperty p, String targetNamespace, String xsdName) {
    if (!p.getType().isDataType()) {
        String prefix = null;
        if (targetNamespace != null && !XMLConstants.EMPTY_STRING.equals(targetNamespace)) {
            NamespaceResolver nr = p.getType().getXmlDescriptor().getNamespaceResolver();
            if (nr != null) {
                prefix = nr.resolveNamespaceURI(targetNamespace);
                if (null == prefix) {
                    prefix = nr.generatePrefix();
                    nr.put(prefix, targetNamespace);
                }
            }
        }
        if ((prefix == null) || prefix.equals(SDOConstants.EMPTY_STRING)) {
            p.getType().getXmlDescriptor().addRootElement(xsdName);
        } else {
            p.getType().getXmlDescriptor().addRootElement(// 
            prefix + SDOConstants.SDO_XPATH_NS_SEPARATOR_FRAGMENT + xsdName);
        }
    } else {
        // Types from Schema: isDataType() == true so:
        // - find the SDOWrapperType from TypeHelper's WrappersHashMap
        // - set the root element name on it
        // - add the descriptor to XMLContext's DescriptorsByQName map
        // See also: SDOTypeHelperDelegate:defineOpenContentProperty
        SDOTypeHelper typeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
        SDOWrapperType wrapperType = (SDOWrapperType) typeHelper.getWrappersHashMap().get(p.getType().getQName());
        XMLDescriptor d = wrapperType.getXmlDescriptor(p.getXsdType());
        if (wrapperType != null) {
            d.addRootElement(xsdName);
            QName descriptorQname = new QName(targetNamespace, xsdName);
            ((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().addDescriptorByQName(descriptorQname, d);
        }
    }
}
Also used : XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) QName(javax.xml.namespace.QName) SDOWrapperType(org.eclipse.persistence.sdo.types.SDOWrapperType) NamespaceResolver(org.eclipse.persistence.oxm.NamespaceResolver)

Example 3 with SDOWrapperType

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

the class SDOTypesGenerator method startNewSimpleType.

private SDOType startNewSimpleType(String targetNamespace, String defaultNamespace, String sdoTypeName, String xsdLocalName, SimpleType simpleType) {
    SDOType currentType;
    if (null == simpleType.getName()) {
        currentType = createSDOTypeForName(targetNamespace, sdoTypeName, xsdLocalName);
        currentType.setDataType(true);
    } else {
        currentType = getGeneratedTypesByXsdQName().get(new QName(targetNamespace, simpleType.getName()));
    }
    // Defining a new simple type from XSD.
    // See also: SDOTypeHelperDelegate:define for "types from DataObjects" equivalent
    SDOTypeHelper typeHelper = ((SDOTypeHelper) aHelperContext.getTypeHelper());
    // 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 baseTypeQName = null;
    if (simpleType.getRestriction() != null) {
        String baseType = simpleType.getRestriction().getBaseType();
        baseTypeQName = this.getQNameForString(defaultNamespace, baseType);
        SDOType baseSDOType = getTypeForXSDQName(baseTypeQName);
        currentType.addBaseType(baseSDOType);
        currentType.setInstanceClass(baseSDOType.getInstanceClass());
    }
    // Create the new WrapperType
    SDOWrapperType wrapperType = new SDOWrapperType(currentType, sdoTypeName, typeHelper, baseTypeQName);
    // Register WrapperType with maps on TypeHelper
    typeHelper.getWrappersHashMap().put(currentType.getQName(), wrapperType);
    typeHelper.getTypesHashMap().put(wrapperType.getQName(), wrapperType);
    typeHelper.getImplClassesToSDOType().put(wrapperType.getXmlDescriptor().getJavaClass(), wrapperType);
    // Add descriptor to XMLHelper
    ArrayList<SDOWrapperType> list = new ArrayList<>(1);
    list.add(wrapperType);
    ((SDOXMLHelper) aHelperContext.getXMLHelper()).addDescriptors(list);
    if (simpleType.getAnnotation() != null) {
        currentType.setAppInfoElements(simpleType.getAnnotation().getAppInfo());
    }
    return currentType;
}
Also used : QName(javax.xml.namespace.QName) SDOWrapperType(org.eclipse.persistence.sdo.types.SDOWrapperType) SDOType(org.eclipse.persistence.sdo.SDOType) ArrayList(java.util.ArrayList)

Example 4 with SDOWrapperType

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

the class SDOHelperTestCases method testUnwrapTypeToSDOWrapperType.

public void testUnwrapTypeToSDOWrapperType() {
    Type wrapperType = new SDOWrapperType(teamType, "MyTeamTypeWrapper", (SDOTypeHelper) typeHelper);
    assertTrue(SDOHelper.unwrap(wrapperType, SDOWrapperType.class) instanceof SDOWrapperType);
}
Also used : SDOChangeSummaryType(org.eclipse.persistence.sdo.types.SDOChangeSummaryType) SDOOpenSequencedType(org.eclipse.persistence.sdo.types.SDOOpenSequencedType) SDOXMLHelperLoadOptionsType(org.eclipse.persistence.sdo.types.SDOXMLHelperLoadOptionsType) SDOPropertyType(org.eclipse.persistence.sdo.types.SDOPropertyType) SDOObjectType(org.eclipse.persistence.sdo.types.SDOObjectType) SDOWrapperType(org.eclipse.persistence.sdo.types.SDOWrapperType) Type(commonj.sdo.Type) SDODataType(org.eclipse.persistence.sdo.types.SDODataType) SDODataObjectType(org.eclipse.persistence.sdo.types.SDODataObjectType) SDOTypeType(org.eclipse.persistence.sdo.types.SDOTypeType) SDOType(org.eclipse.persistence.sdo.SDOType) SDOWrapperType(org.eclipse.persistence.sdo.types.SDOWrapperType)

Example 5 with SDOWrapperType

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

the class SDOTypeHelperDelegate method defineOpenContentProperty.

/**
 * INTERNAL:
 * @param propertyUri
 * @param property
 */
private void defineOpenContentProperty(String propertyUri, String propertyName, Property property) {
    if (propertyUri != null) {
        QName propertyQName = new QName(propertyUri, propertyName);
        openContentProperties.put(propertyQName, property);
        boolean isElement = aHelperContext.getXSDHelper().isElement(property);
        ((SDOXSDHelper) aHelperContext.getXSDHelper()).addGlobalProperty(propertyQName, property, isElement);
        ((SDOProperty) property).setUri(propertyUri);
        XMLDescriptor aDescriptor;
        if (property.getType().isDataType()) {
            // RICK: Types from DataObjects: isDataType() == true so:
            // - find the SDOWrapperType from TypeHelper's WrappersHashMap
            // - add the descriptor to XMLContext's DescriptorsByQName map
            // See also: SDOTypesGenerator:addRootElementToDescriptor
            SDOTypeHelper typeHelper = (SDOTypeHelper) aHelperContext.getTypeHelper();
            SDOWrapperType wrapperType = (SDOWrapperType) typeHelper.getWrappersHashMap().get(((SDOProperty) property).getType().getQName());
            if (wrapperType != null) {
                QName descriptorQname = new QName(propertyUri, propertyName);
                ((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().addDescriptorByQName(descriptorQname, wrapperType.getXmlDescriptor(((SDOProperty) property).getXsdType()));
            }
            return;
        } else {
            aDescriptor = ((SDOType) property.getType()).getXmlDescriptor();
        }
        // synchronized threads that access the NonSynchronizedVector tables in XMLDescriptor
        if (aDescriptor != null) {
            synchronized (aDescriptor) {
                String rootName = propertyName;
                String prefix = aDescriptor.getNonNullNamespaceResolver().resolveNamespaceURI(propertyUri);
                if ((prefix == null) || prefix.equals(SDOConstants.EMPTY_STRING)) {
                    prefix = ((SDOTypeHelper) aHelperContext.getTypeHelper()).getPrefix(propertyUri);
                    aDescriptor.getNonNullNamespaceResolver().put(prefix, propertyUri);
                }
                if ((prefix != null) && !prefix.equals(SDOConstants.EMPTY_STRING)) {
                    rootName = prefix + ":" + rootName;
                }
                aDescriptor.setDefaultRootElement(rootName);
                QName elementType = new QName(propertyUri, rootName);
                aDescriptor.setDefaultRootElementType(elementType);
                ((SDOXMLHelper) aHelperContext.getXMLHelper()).getXmlContext().storeXMLDescriptorByQName(aDescriptor);
            }
        }
    }
}
Also used : SDOTypeHelper(org.eclipse.persistence.sdo.helper.SDOTypeHelper) XMLDescriptor(org.eclipse.persistence.oxm.XMLDescriptor) QName(javax.xml.namespace.QName) SDOWrapperType(org.eclipse.persistence.sdo.types.SDOWrapperType) SDOXSDHelper(org.eclipse.persistence.sdo.helper.SDOXSDHelper) SDOProperty(org.eclipse.persistence.sdo.SDOProperty)

Aggregations

SDOWrapperType (org.eclipse.persistence.sdo.types.SDOWrapperType)6 QName (javax.xml.namespace.QName)5 SDOType (org.eclipse.persistence.sdo.SDOType)4 XMLDescriptor (org.eclipse.persistence.oxm.XMLDescriptor)3 ArrayList (java.util.ArrayList)2 SDOProperty (org.eclipse.persistence.sdo.SDOProperty)2 SDOTypeHelper (org.eclipse.persistence.sdo.helper.SDOTypeHelper)2 DataObject (commonj.sdo.DataObject)1 Type (commonj.sdo.Type)1 Iterator (java.util.Iterator)1 List (java.util.List)1 NamespaceResolver (org.eclipse.persistence.oxm.NamespaceResolver)1 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)1 SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)1 SDOXSDHelper (org.eclipse.persistence.sdo.helper.SDOXSDHelper)1 SDOChangeSummaryType (org.eclipse.persistence.sdo.types.SDOChangeSummaryType)1 SDODataObjectType (org.eclipse.persistence.sdo.types.SDODataObjectType)1 SDODataType (org.eclipse.persistence.sdo.types.SDODataType)1 SDOObjectType (org.eclipse.persistence.sdo.types.SDOObjectType)1 SDOOpenSequencedType (org.eclipse.persistence.sdo.types.SDOOpenSequencedType)1