Search in sources :

Example 1 with SDOType

use of org.eclipse.persistence.sdo.SDOType in project metro-jax-ws by eclipse-ee4j.

the class SDOUtils method validateSupportedType.

public static boolean validateSupportedType(HelperContext hc, String javaType, QName qname) {
    TypeHelper typeHelper = hc.getTypeHelper();
    if (qname != null) {
        Type type = typeHelper.getType(qname.getNamespaceURI(), qname.getLocalPart());
        String java = ((SDOType) type).getInstanceClassName();
        if (java != null) {
            return java.equals(javaType);
        }
        return false;
    } else {
        if (isPrimitive(javaType)) {
            return true;
        }
        try {
            Class cls = Thread.currentThread().getContextClassLoader().loadClass(javaType);
            Type type = typeHelper.getType(cls);
            return type != null;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
Also used : TypeHelper(commonj.sdo.helper.TypeHelper) Type(commonj.sdo.Type) SDOType(org.eclipse.persistence.sdo.SDOType) SDOType(org.eclipse.persistence.sdo.SDOType) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 2 with SDOType

use of org.eclipse.persistence.sdo.SDOType in project metro-jax-ws by eclipse-ee4j.

the class Xsd2JavaSDOModel method getJavaTypeForElementName.

/**
 * return the java type used for the element, only Global elements can be located.
 * Containing types are not searched
 */
public String getJavaTypeForElementName(QName qname) {
    XSDHelper xsdHelper = context.getXSDHelper();
    Property globalProperty = xsdHelper.getGlobalProperty(qname.getNamespaceURI(), qname.getLocalPart(), true);
    if (globalProperty == null) {
        throw new RuntimeException("Given element with name: " + qname + "is not found.");
    }
    Type elementType = globalProperty.getType();
    if (elementType == null) {
        throw new RuntimeException("Given element with name: " + qname + "is not found.");
    }
    return ((SDOType) elementType).getInstanceClassName();
}
Also used : SDOType(org.eclipse.persistence.sdo.SDOType) Type(commonj.sdo.Type) SDOType(org.eclipse.persistence.sdo.SDOType) XSDHelper(commonj.sdo.helper.XSDHelper) Property(commonj.sdo.Property)

Example 3 with SDOType

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

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

the class SDOTypeHelperDelegate method getType.

/**
 * Return the Type for this interfaceClass or null if not found.
 * @param interfaceClass is the interface for the DataObject's Type -
 *    type.getInstanceClass();
 * @return the Type for this interfaceClass or null if not found.
 */
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public SDOType getType(Class interfaceClass) {
    if (LOGGER.isLoggable(Level.INFO)) {
        LOGGER.info("Looking for : " + interfaceClass);
    }
    final Object[] searchSources = new Object[] { interfacesToSDOTypeHashMap, sdoTypeForSimpleJavaType, getTypesHashMap().values(), anonymousTypes, commonjHashMap.values() };
    for (int i = 0; i < searchSources.length; i++) {
        Object searchSource = searchSources[i];
        if (searchSource == null)
            continue;
        SDOType type;
        if (searchSource instanceof Map) {
            type = ((Map<Class<?>, SDOType>) searchSource).get(interfaceClass);
        } else {
            // collection
            type = getFromCollection(((Collection<SDOType>) searchSource), interfaceClass);
        }
        if (type != null) {
            if (LOGGER.isLoggable(Level.INFO)) {
                LOGGER.info(interfaceClass + " was found in: " + SEARCH_SOURCES_NAMES[i] + '.');
            }
            return type;
        }
    }
    if (LOGGER.isLoggable(Level.INFO)) {
        final StringBuilder log = new StringBuilder();
        log.append("Not found: ").append(interfaceClass).append('\n');
        for (int i = 0; i < searchSources.length; i++) {
            // let's show content of all search sources
            log.append("Content of ").append(SEARCH_SOURCES_NAMES[i]).append(": ");
            final Object searchSource = searchSources[i];
            if (searchSource == null) {
                log.append("null");
            } else {
                if (searchSource instanceof Map) {
                    log.append(((Map) searchSource).keySet());
                } else {
                    // collection
                    for (SDOType sdoType : (Collection<SDOType>) searchSource) {
                        log.append(sdoType.getInstanceClass()).append(", ");
                    }
                }
            }
            log.append('\n');
        }
        LOGGER.info(log.toString());
    }
    return null;
}
Also used : SDOType(org.eclipse.persistence.sdo.SDOType) Collection(java.util.Collection) SDODataObject(org.eclipse.persistence.sdo.SDODataObject) DataObject(commonj.sdo.DataObject) HashMap(java.util.HashMap) Map(java.util.Map)

Example 5 with SDOType

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

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