Package commonj.sdo.helper

Examples of commonj.sdo.helper.HelperContext


    public void runSample () throws Exception {

        commentary("Demonstrates accessing a DataObject's properties using the XPath style getter/setter methods");


        HelperContext scope = createScopeForTypes();
       
       
        commentary(
            "First we create the type system using an XML Schema file and then create\n"+
            "A DataObject using an XML document for convenience");
View Full Code Here


*/
public class XMLDocument2OMElement extends BaseTransformer<XMLDocument, OMElement> implements
    PullTransformer<XMLDocument, OMElement> {

    public OMElement transform(XMLDocument source, TransformationContext context) {
        HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
        SDODataSource dataSource = new SDODataSource(source, helperContext);
        OMFactory factory = OMAbstractFactory.getOMFactory();
        QName name = new QName(source.getRootElementURI(), source.getRootElementName());
        OMElement element = AxiomHelper.createOMElement(factory, name, dataSource);
        return element;
View Full Code Here

*/
public class DataObject2OMElement extends BaseTransformer<DataObject, OMElement> implements
    PullTransformer<DataObject, OMElement> {

    public OMElement transform(DataObject source, TransformationContext context) {
        HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
        OMFactory factory = OMAbstractFactory.getOMFactory();

        QName name  = ROOT_ELEMENT;
        if (context != null) {
            DataType dataType = context.getTargetDataType();
            Object logical = dataType == null ? null : dataType.getLogical();
            if (logical instanceof XMLType) {
                XMLType xmlType = (XMLType)logical;
                if (xmlType.isElement()) {
                    name = xmlType.getElementName();
                }
            }
        }

        XMLDocument document = helperContext.getXMLHelper().createDocument(source,
                                                                           name.getNamespaceURI(),
                                                                           name.getLocalPart());
        SDODataSource dataSource = new SDODataSource(document, helperContext);
        OMElement element = AxiomHelper.createOMElement(factory, name, dataSource);
        return element;
View Full Code Here

* @version $Rev: 644124 $ $Date: 2008-04-03 03:54:59 +0300 (Thu, 03 Apr 2008) $
*/
public class SDOContextHelperTestCase {
    @Test
    public void testGenerateSchema() throws IOException {
        HelperContext context = SDOUtil.createHelperContext();
        URL url = getClass().getResource("/ipo.xsd");
        Assert.assertNotNull(url);
        InputStream is = url.openStream();
        XSDHelper xsdHelper = context.getXSDHelper();
        xsdHelper.define(is, url.toExternalForm());
        TypeHelper typeHelper = context.getTypeHelper();
        Type type = typeHelper.getType("http://www.example.com/IPO", "PurchaseOrderType");
        Assert.assertNotNull(type);
        /*
        SDOContextHelper.generateSchema(context, Arrays.asList(type));
        */
 
View Full Code Here

    public Object toJavaObject(QName typeName, String value, TransformationContext context) {
        Type type = null;
        if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) {
            type = SDOUtil.getXSDSDOType(typeName.getLocalPart());
        } else {
            HelperContext helperContext = SDOContextHelper.getHelperContext(context, false);
            TypeHelper typeHelper = helperContext.getTypeHelper();
            type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart());
        }
        return SDOUtil.createFromString(type, value);
    }
View Full Code Here

    public String toXMLLiteral(QName typeName, Object obj, TransformationContext context) {
        Type type = null;
        if (URI_2001_SCHEMA_XSD.equals(typeName.getNamespaceURI())) {
            type = SDOUtil.getXSDSDOType(typeName.getLocalPart());
        } else {
            HelperContext helperContext = SDOContextHelper.getHelperContext(context, true);
            TypeHelper typeHelper = helperContext.getTypeHelper();
            type = typeHelper.getType(typeName.getNamespaceURI(), typeName.getLocalPart());
        }
        return SDOUtil.convertToString(type, obj);
    }
View Full Code Here

    @Override
    public boolean introspect(DataType dataType, final Operation operation) {
        final Class javaType = dataType.getPhysical();
        // Allow privileged access to read system properties. Requires PropertyPermission
        // java.specification.version read in security policy.
        final HelperContext context = AccessController.doPrivileged(new PrivilegedAction<HelperContext>() {
            public HelperContext run() {
                return SDOContextHelper.getHelperContext(operation);
            }
        });

        final Type type = context.getTypeHelper().getType(javaType);
        if (type == null) {
            // FIXME: Need a better to test dynamic SDO
            if (DataObject.class.isAssignableFrom(javaType)) {
                // Dynamic SDO
                dataType.setDataBinding(getName());
                if (dataType.getLogical() == null) {
                    dataType.setLogical(XMLType.UNKNOWN);
                }
                return true;
            }
            return false;
        }
        if (type.isDataType()) {
            // FIXME: Ignore simple types?
            return false;
        }

        // Found a SDO type, replace the default context with a private one
        AccessController.doPrivileged(new PrivilegedAction<Object>() {
            public Object run() {
                if (context == SDOContextHelper.getDefaultHelperContext()) {
                    HelperContext newContext = SDOUtil.createHelperContext();
                    SDOContextHelper.register(newContext, type);
                    if (operation != null) {
                        operation.getInputType().setMetaData(HelperContext.class, newContext);
                    }
                } else {
View Full Code Here

        return xmlTypeHelper;
    }

    @Override
    public Object copy(Object arg, DataType dataType, DataType targetDataType, Operation operation, Operation targetOperation) {
        HelperContext context = SDOContextHelper.getHelperContext(operation);
        CopyHelper copyHelper = context.getCopyHelper();
        if (arg instanceof XMLDocument) {
            XMLDocument document = (XMLDocument)arg;
            DataObject dataObject = copyHelper.copy(document.getRootObject());
            return context.getXMLHelper().createDocument(dataObject,
                                                         document.getRootElementURI(),
                                                         document.getRootElementName());
        } else if (arg instanceof DataObject) {
            return context.getCopyHelper().copy((DataObject)arg);
        } else {
            return super.copy(arg, dataType, targetDataType, operation, targetOperation);
        }
    }
View Full Code Here

    public static HelperContext getHelperContext(TransformationContext context, boolean source) {
        if (context == null) {
            return getDefaultHelperContext();
        }

        HelperContext helperContext = null;
        Operation op = source ? context.getSourceOperation() : context.getTargetOperation();
        if (op == null) {
            DataType<?> dt = source ? context.getSourceDataType() : context.getTargetDataType();

            helperContext = dt.getMetaData(HelperContext.class);
View Full Code Here

    public static HelperContext getHelperContext(Operation op) {
        if (op == null) {
            return getDefaultHelperContext();
        }

        HelperContext helperContext = op.getInputType().getMetaData(HelperContext.class);

        if (helperContext != null) {
            return helperContext;
        }
View Full Code Here

TOP

Related Classes of commonj.sdo.helper.HelperContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.