Search in sources :

Example 1 with SDOXMLHelper

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

the class SDOUtils method sdoToXML.

/**
 * Serialize a DataObject to the specified xml element in text xml
 */
public static Source sdoToXML(HelperContext hc, DataObject obj, String targetNamespace, String localName) throws ParserConfigurationException, IOException {
    SDOXMLHelper sdoXMLHelper = (SDOXMLHelper) hc.getXMLHelper();
    sdoXMLHelper.setTimeZone(TimeZone.getTimeZone("GMT"));
    sdoXMLHelper.setTimeZoneQualified(true);
    XMLDocument xmlDoc = sdoXMLHelper.createDocument(obj, targetNamespace, localName);
    if (xmlDoc == null) {
        return null;
    }
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    StreamResult result = new StreamResult(bout);
    sdoXMLHelper.save(xmlDoc, result, null);
    byte[] bytes = bout.toByteArray();
    System.out.println("data obj converted to xml: " + new String(bytes));
    return new StreamSource(new ByteArrayInputStream(bytes));
}
Also used : StreamResult(javax.xml.transform.stream.StreamResult) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamSource(javax.xml.transform.stream.StreamSource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper) XMLDocument(commonj.sdo.helper.XMLDocument)

Example 2 with SDOXMLHelper

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

the class SDOType method getInstanceClass.

@Override
public Class<?> getInstanceClass() {
    if ((javaClass == null) && (javaClassName != null)) {
        try {
            SDOClassLoader loader = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getLoader();
            Class<?> clazz = loader.getParent().loadClass(javaClassName);
            if (isValidInstanceClass(clazz)) {
                javaClass = clazz;
            } else {
                javaClass = getClass();
            }
        } catch (ClassNotFoundException e) {
            javaClass = getClass();
        } catch (SecurityException e) {
            throw SDOException.classNotFound(e, getURI(), getName());
        }
    }
    if (javaClass == getClass()) {
        return null;
    }
    return javaClass;
}
Also used : SDOClassLoader(org.eclipse.persistence.sdo.helper.SDOClassLoader) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper)

Example 3 with SDOXMLHelper

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

the class SDOType method getImplClass.

/**
 * INTERNAL:
 */
public Class<?> getImplClass() {
    if ((javaImplClass == null) && (getImplClassName() != null)) {
        try {
            SDOClassLoader loader = ((SDOXMLHelper) aHelperContext.getXMLHelper()).getLoader();
            javaImplClass = loader.loadClass(getImplClassName(), this);
            xmlDescriptor.setJavaClass(javaImplClass);
        } catch (ClassNotFoundException e) {
            throw SDOException.classNotFound(e, getURI(), getName());
        } catch (SecurityException e) {
            throw SDOException.classNotFound(e, getURI(), getName());
        }
    }
    return javaImplClass;
}
Also used : SDOClassLoader(org.eclipse.persistence.sdo.helper.SDOClassLoader) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper)

Example 4 with SDOXMLHelper

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

the class SDODataFactoryDelegate method create.

@Override
@SuppressWarnings({ "rawtypes" })
public DataObject create(Class interfaceClass) {
    if (interfaceClass == null) {
        throw new IllegalArgumentException(SDOException.cannotPerformOperationWithNullInputParameter("create", "interfaceClass"));
    }
    Type type = getHelperContext().getTypeHelper().getType(interfaceClass);
    if (type != null) {
        return create(type);
    }
    // at this point the type may not have been defined or there could be a classloader issue
    SDOXMLHelper xmlHelper = (SDOXMLHelper) getHelperContext().getXMLHelper();
    ClassLoader contextLoader = xmlHelper.getLoader();
    ClassLoader interfaceLoader = interfaceClass.getClassLoader();
    boolean loadersAreRelated = false;
    // check the hierarchy to see if the interface loader is a parent of the context loader
    List<ClassLoader> visitedLoaders = new ArrayList<ClassLoader>();
    while (contextLoader != null && !loadersAreRelated) {
        if (visitedLoaders.contains(contextLoader)) {
            // if we encounter a loader we've already checked, break out
            break;
        }
        visitedLoaders.add(contextLoader);
        if (contextLoader == interfaceLoader) {
            loadersAreRelated = true;
        }
        ClassLoader parentLoader = contextLoader.getParent();
        if (contextLoader == parentLoader) {
            break;
        }
        contextLoader = parentLoader;
    }
    throw new IllegalArgumentException(SDOException.typeNotFoundForInterface(interfaceClass.getName(), loadersAreRelated));
}
Also used : SDOType(org.eclipse.persistence.sdo.SDOType) Type(commonj.sdo.Type) ArrayList(java.util.ArrayList) SDOXMLHelper(org.eclipse.persistence.sdo.helper.SDOXMLHelper)

Example 5 with SDOXMLHelper

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

SDOXMLHelper (org.eclipse.persistence.sdo.helper.SDOXMLHelper)40 SDOMarshalListener (org.eclipse.persistence.sdo.helper.SDOMarshalListener)22 SDODataObject (org.eclipse.persistence.sdo.SDODataObject)21 SDOChangeSummary (org.eclipse.persistence.sdo.SDOChangeSummary)16 XMLDocument (commonj.sdo.helper.XMLDocument)6 XMLMarshaller (org.eclipse.persistence.oxm.XMLMarshaller)6 XMLUnmarshaller (org.eclipse.persistence.oxm.XMLUnmarshaller)5 XMLAttachmentMarshaller (org.eclipse.persistence.oxm.attachment.XMLAttachmentMarshaller)5 XMLAttachmentUnmarshaller (org.eclipse.persistence.oxm.attachment.XMLAttachmentUnmarshaller)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 SDOType (org.eclipse.persistence.sdo.SDOType)3 SDOClassLoader (org.eclipse.persistence.sdo.helper.SDOClassLoader)3 SDOTypeHelper (org.eclipse.persistence.sdo.helper.SDOTypeHelper)3 DataObject (commonj.sdo.DataObject)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 FileInputStream (java.io.FileInputStream)2 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)2 SDOXSDHelper (org.eclipse.persistence.sdo.helper.SDOXSDHelper)2 Type (commonj.sdo.Type)1