Package org.apache.tuscany.sca.assembly

Examples of org.apache.tuscany.sca.assembly.Callback


                     "CalculatorService");
        assertEquals(calcCompositeService.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcCompositeService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations
        Callback calcServiceCallback = calcCompositeService.getCallback();
        assertNotNull(calcServiceCallback);
        assertEquals(calcServiceCallback.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcServiceCallback.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations

        Component calcComponent = composite.getComponents().get(0);
        assertEquals(calcComponent.getName(), "CalculatorServiceComponent");
        assertEquals(calcComponent.getAutowire(), Boolean.FALSE);
        assertEquals(calcComponent.getConstrainingType().getName(), new QName("http://calc",
                                                                              "CalculatorComponent"));
        assertEquals(calcComponent.getRequiredIntents().get(0).getName(), new QName("http://test",
                                                                                    "confidentiality"));
        assertEquals(calcComponent.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));

        ComponentService calcComponentService = calcComponent.getServices().get(0);
        assertEquals(calcComponentService.getName(), "CalculatorService");
        assertEquals(calcComponentService.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcComponentService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations

        ComponentReference calcComponentReference = calcComponent.getReferences().get(0);
        assertEquals(calcComponentReference.getName(), "addService");
        assertEquals(calcComponentReference.getAutowire(), Boolean.FALSE);
        assertEquals(calcComponentReference.isWiredByImpl(), false);
        assertEquals(calcComponentReference.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcComponentReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations

        Property property = calcComponent.getProperties().get(0);
        assertEquals(property.getName(), "round");
        Document doc = (Document) property.getValue();
        Element element = doc.getDocumentElement();
        String value = element.getTextContent();
        assertEquals(value, "true");
        assertEquals(property.getXSDType(), new QName("http://www.w3.org/2001/XMLSchema", "boolean"));
        assertEquals(property.isMany(), false);

        CompositeReference calcCompositeReference = (CompositeReference)composite.getReferences().get(0);
        assertEquals(calcCompositeReference.getName(), "MultiplyService");
        assertTrue(calcCompositeReference.getPromotedReferences().get(0).isUnresolved());
        assertEquals(calcCompositeReference.getPromotedReferences().get(0).getName(),
                     "CalculatorServiceComponent/multiplyService");
        assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations
        Callback calcCallback = calcCompositeReference.getCallback();
        assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        assertNotNull(calcCallback);
        // TODO test operations
View Full Code Here


               
                // Read intents on the callback interface
                if (javaInterfaceContract.getCallbackInterface() != null) {
                    JavaInterface javaCallbackInterface = (JavaInterface)javaInterfaceContract.getCallbackInterface();
                    if (javaCallbackInterface.getJavaClass() != null) {
                        Callback callback = service.getCallback();
                        if (callback == null) {
                            callback = assemblyFactory.createCallback();
                            service.setCallback(callback);
                        }
                        readIntentsAndPolicySets(javaCallbackInterface.getJavaClass(),
                                                 callback.getRequiredIntents(),
                                                 callback.getPolicySets());

                        // Read intents on the callback interface methods
                        Method[] methods = javaCallbackInterface.getJavaClass().getMethods();
                        ConfiguredOperation confOp = null;
                        for (Method method: methods) {
                            confOp = assemblyFactory.createConfiguredOperation();
                            confOp.setName(method.getName());
                            callback.getConfiguredOperations().add(confOp);
                            readIntents(method.getAnnotation(Requires.class), confOp.getRequiredIntents());
                            readPolicySets(method.getAnnotation(PolicySets.class), confOp.getPolicySets());
                        }
                    }
                }
View Full Code Here

               
                // Read intents on the callback interface
                if (javaInterfaceContract.getCallbackInterface() != null) {
                    JavaInterface javaCallbackInterface = (JavaInterface)javaInterfaceContract.getCallbackInterface();
                    if (javaCallbackInterface.getJavaClass() != null) {
                        Callback callback = service.getCallback();
                        if (callback == null) {
                            callback = assemblyFactory.createCallback();
                            service.setCallback(callback);
                        }
                        readIntents(javaCallbackInterface.getJavaClass(), callback.getRequiredIntents());

                        // Read intents on the callback interface methods
                        Method[] methods = javaCallbackInterface.getJavaClass().getMethods();
                        for (Method method: methods) {
                            readIntents(method, callback.getRequiredIntents());
                        }
                    }
                }
            }
        }
View Full Code Here

                     "CalculatorService");
        assertEquals(calcCompositeService.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcCompositeService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations
        Callback calcServiceCallback = calcCompositeService.getCallback();
        assertNotNull(calcServiceCallback);
        assertEquals(calcServiceCallback.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcServiceCallback.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations

        Component calcComponent = composite.getComponents().get(0);
        assertEquals(calcComponent.getName(), "CalculatorServiceComponent");
        assertEquals(calcComponent.isAutowire(), false);
        assertEquals(calcComponent.getConstrainingType().getName(), new QName("http://calc",
                                                                              "CalculatorComponent"));
        assertEquals(calcComponent.getRequiredIntents().get(0).getName(), new QName("http://test",
                                                                                    "confidentiality"));
        assertEquals(calcComponent.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));

        ComponentService calcComponentService = calcComponent.getServices().get(0);
        assertEquals(calcComponentService.getName(), "CalculatorService");
        assertEquals(calcComponentService.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcComponentService.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations

        ComponentReference calcComponentReference = calcComponent.getReferences().get(0);
        assertEquals(calcComponentReference.getName(), "addService");
        assertEquals(calcComponentReference.isAutowire(), false);
        assertEquals(calcComponentReference.isWiredByImpl(), false);
        assertEquals(calcComponentReference.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcComponentReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations

        Property property = calcComponent.getProperties().get(0);
        assertEquals(property.getName(), "round");
        Document doc = (Document) property.getValue();
        Element element = doc.getDocumentElement();
        String value = element.getTextContent();
        assertEquals(value, "true");
        assertEquals(property.getXSDType(), new QName("http://www.w3.org/2001/XMLSchema", "boolean"));
        assertEquals(property.isMany(), false);

        CompositeReference calcCompositeReference = (CompositeReference)composite.getReferences().get(0);
        assertEquals(calcCompositeReference.getName(), "MultiplyService");
        assertTrue(calcCompositeReference.getPromotedReferences().get(0).isUnresolved());
        assertEquals(calcCompositeReference.getPromotedReferences().get(0).getName(),
                     "CalculatorServiceComponent/multiplyService");
        assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations
        Callback calcCallback = calcCompositeReference.getCallback();
        assertEquals(calcCompositeReference.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcCompositeReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        assertNotNull(calcCallback);
        // TODO test operations
View Full Code Here

        ComponentType componentType = null;
        Service service = null;
        Reference reference = null;
        Contract contract = null;
        Property property = null;
        Callback callback = null;
        QName name = null;
       
        try {
   
            // Read the componentType document
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
                    case START_ELEMENT:
                        name = reader.getName();
   
                        if (Constants.COMPONENT_TYPE_QNAME.equals(name)) {
   
                            // Read a <componentType>
                            componentType = assemblyFactory.createComponentType();
                            componentType.setConstrainingType(getConstrainingType(reader));
                            readPolicies(componentType, reader);
   
                        } else if (Constants.SERVICE_QNAME.equals(name)) {
   
                            // Read a <service>
                            service = assemblyFactory.createService();
                            contract = service;
                            service.setName(getString(reader, Constants.NAME));
                            componentType.getServices().add(service);
                            readPolicies(service, reader);
   
                        } else if (Constants.REFERENCE_QNAME.equals(name)) {
                            // Read a <reference>
                            reference = assemblyFactory.createReference();
                            contract = reference;
                            reference.setName(getString(reader, Constants.NAME));
                            reference.setWiredByImpl(getBoolean(reader, Constants.WIRED_BY_IMPL));
                            readMultiplicity(reference, reader);
                            readTargets(reference, reader);
                            componentType.getReferences().add(reference);
                            readPolicies(reference, reader);
   
                        } else if (Constants.PROPERTY_QNAME.equals(name)) {
   
                            // Read a <property>
                            property = assemblyFactory.createProperty();
                            readPolicies(property, reader);
                            readProperty(property, reader);
                            componentType.getProperties().add(property);
                           
                        } else if (Constants.IMPLEMENTATION_QNAME.equals(name)) {
                           
                            // Read an <implementation> element
                            readPolicies(componentType, reader);
                           
                        } else if (Constants.CALLBACK_QNAME.equals(name)) {
   
                            // Read a <callback>
                            callback = assemblyFactory.createCallback();
                            contract.setCallback(callback);
                            readPolicies(callback, reader);
   
                        } else if (OPERATION.equals(name)) {
   
                            // Read an <operation>
                            Operation operation = assemblyFactory.createOperation();
                            operation.setName(getString(reader, NAME));
                            operation.setUnresolved(true);
                            if (callback != null) {
                                readPolicies(callback, operation, reader);
                            } else {
                                readPolicies(contract, operation, reader);
                            }
                        } else {
   
                            // Read an extension element
                            Object extension = extensionProcessor.read(reader);
                            if (extension != null) {
                                if (extension instanceof InterfaceContract) {
   
                                    // <service><interface> and <reference><interface>
                                    contract.setInterfaceContract((InterfaceContract)extension);
   
                                } else if (extension instanceof Binding) {
   
                                    // <service><binding> and <reference><binding>
                                    if (callback != null) {
                                        callback.getBindings().add((Binding)extension);
                                    } else {
                                        contract.getBindings().add((Binding)extension);
                                    }
                                } else {
                                   
                                    // Add the extension element to the current element
                                    if (callback != null) {
                                        callback.getExtensions().add(extension);
                                    } else if (contract != null) {
                                        contract.getExtensions().add(extension);
                                    } else if (property != null) {
                                        property.getExtensions().add(extension);
                                    } else {
View Full Code Here

                for (Binding binding: service.getBindings()) {
                    extensionProcessor.write(binding, writer);
                }
               
                if (service.getCallback() != null) {
                    Callback callback = service.getCallback();
                    writeStart(writer, CALLBACK);

                    for (Binding binding: callback.getBindings()) {
                        extensionProcessor.write(binding, writer);
                    }
                    for (Object extension: callback.getExtensions()) {
                        extensionProcessor.write(extension, writer);
                    }
                   
                    writeEnd(writer);
                }

                for (Object extension: service.getExtensions()) {
                    extensionProcessor.write(extension, writer);
                }
               
                writeEnd(writer);
            }
   
            for (Reference reference : componentType.getReferences()) {
                // TODO handle multivalued target attribute
                String target = reference.getTargets().isEmpty() ? null : reference.getTargets().get(0).getName();
                writeStart(writer, REFERENCE,
                      new XAttr(NAME, reference.getName()),
                      new XAttr(TARGET, target));

                extensionProcessor.write(reference.getInterfaceContract(), writer);
               
                for (Binding binding: reference.getBindings()) {
                    extensionProcessor.write(binding, writer);
                }
               
                if (reference.getCallback() != null) {
                    Callback callback = reference.getCallback();
                    writeStart(writer, CALLBACK);

                    for (Binding binding: callback.getBindings()) {
                        extensionProcessor.write(binding, writer);
                    }
                    for (Object extension: callback.getExtensions()) {
                        extensionProcessor.write(extension, writer);
                    }
                   
                    writeEnd(writer);
                }
View Full Code Here

        ComponentProperty componentProperty = null;
        CompositeService compositeService = null;
        CompositeReference compositeReference = null;
        Contract contract = null;
        Wire wire = null;
        Callback callback = null;
        QName name = null;

        try {

            // Read the composite document
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
                    case START_ELEMENT:
                        name = reader.getName();

                        if (COMPOSITE_QNAME.equals(name)) {

                            // Read a <composite>
                            composite = assemblyFactory.createComposite();
                            composite.setName(new QName(getString(reader, TARGET_NAMESPACE),
                                                        getString(reader, NAME)));
                            composite.setAutowire(getBoolean(reader, AUTOWIRE));
                            composite.setLocal(getBoolean(reader, LOCAL));
                            composite.setConstrainingType(getConstrainingType(reader));
                            readPolicies(composite, reader);

                        } else if (INCLUDE_QNAME.equals(name)) {

                            // Read an <include>
                            include = assemblyFactory.createComposite();
                            include.setName(getQName(reader, "name"));
                            include.setUnresolved(true);
                            composite.getIncludes().add(include);

                        } else if (SERVICE_QNAME.equals(name)) {
                            if (component != null) {

                                // Read a <component><service>
                                componentService = assemblyFactory.createComponentService();
                                contract = componentService;
                                componentService.setName(getString(reader, NAME));
                                component.getServices().add(componentService);
                                readPolicies(contract, reader);
                            } else {

                                // Read a <composite><service>
                                compositeService = assemblyFactory.createCompositeService();
                                contract = compositeService;
                                compositeService.setName(getString(reader, NAME));

                                String promoted = getString(reader, PROMOTE);
                                String promotedComponentName;
                                String promotedServiceName;
                                int s = promoted.indexOf('/');
                                if (s == -1) {
                                    promotedComponentName = promoted;
                                    promotedServiceName = null;
                                } else {
                                    promotedComponentName = promoted.substring(0, s);
                                    promotedServiceName = promoted.substring(s + 1);
                                }

                                Component promotedComponent = assemblyFactory.createComponent();
                                promotedComponent.setUnresolved(true);
                                promotedComponent.setName(promotedComponentName);
                                compositeService.setPromotedComponent(promotedComponent);

                                ComponentService promotedService =
                                    assemblyFactory.createComponentService();
                                promotedService.setUnresolved(true);
                                promotedService.setName(promotedServiceName);
                                compositeService.setPromotedService(promotedService);

                                composite.getServices().add(compositeService);
                                readPolicies(contract, reader);
                            }

                        } else if (REFERENCE_QNAME.equals(name)) {
                            if (component != null) {
                                // Read a <component><reference>
                                componentReference = assemblyFactory.createComponentReference();
                                contract = componentReference;
                                componentReference.setName(getString(reader, NAME));
                                readMultiplicity(componentReference, reader);
                                componentReference.setAutowire(getBoolean(reader, AUTOWIRE));
                                readTargets(componentReference, reader);
                                componentReference
                                    .setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                                component.getReferences().add(componentReference);
                                readPolicies(contract, reader);
                            } else {
                                // Read a <composite><reference>
                                compositeReference = assemblyFactory.createCompositeReference();
                                contract = compositeReference;
                                compositeReference.setName(getString(reader, NAME));
                                readMultiplicity(compositeReference, reader);
                                readTargets(compositeReference, reader);
                                String promote = reader.getAttributeValue(null, Constants.PROMOTE);
                                if (promote != null) {
                                    for (StringTokenizer tokens = new StringTokenizer(promote); tokens
                                        .hasMoreTokens();) {
                                        ComponentReference promotedReference =
                                            assemblyFactory.createComponentReference();
                                        promotedReference.setUnresolved(true);
                                        promotedReference.setName(tokens.nextToken());
                                        compositeReference.getPromotedReferences()
                                            .add(promotedReference);
                                    }
                                }
                                compositeReference
                                    .setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                                composite.getReferences().add(compositeReference);
                                readPolicies(contract, reader);
                            }

                        } else if (PROPERTY_QNAME.equals(name)) {
                            if (component != null) {
                                // Read a <component><property>
                                componentProperty = assemblyFactory.createComponentProperty();
                                property = componentProperty;
                                componentProperty.setSource(getString(reader, SOURCE));
                                componentProperty.setFile(getString(reader, FILE));
                                readPolicies(property, reader);
                                readProperty(componentProperty, reader);
                                component.getProperties().add(componentProperty);
                            } else {

                                // Read a <composite><property>
                                property = assemblyFactory.createProperty();
                                readPolicies(property, reader);
                                readProperty(property, reader);
                                composite.getProperties().add(property);
                            }

                        } else if (COMPONENT_QNAME.equals(name)) {

                            // Read a <component>
                            component = assemblyFactory.createComponent();
                            component.setName(getString(reader, NAME));
                            component.setConstrainingType(getConstrainingType(reader));
                            composite.getComponents().add(component);
                            readPolicies(component, reader);

                        } else if (WIRE_QNAME.equals(name)) {

                            // Read a <wire>
                            wire = assemblyFactory.createWire();
                            ComponentReference source = assemblyFactory.createComponentReference();
                            source.setUnresolved(true);
                            source.setName(getString(reader, SOURCE));
                            wire.setSource(source);

                            ComponentService target = assemblyFactory.createComponentService();
                            target.setUnresolved(true);
                            target.setName(getString(reader, TARGET));
                            wire.setTarget(target);

                            composite.getWires().add(wire);
                            readPolicies(wire, reader);

                        } else if (CALLBACK_QNAME.equals(name)) {

                            // Read a <callback>
                            callback = assemblyFactory.createCallback();
                            contract.setCallback(callback);
                            readPolicies(callback, reader);

                        } else if (OPERATION_QNAME.equals(name)) {

                            // Read an <operation>
                            Operation operation = assemblyFactory.createOperation();
                            operation.setName(getString(reader, NAME));
                            operation.setUnresolved(true);
                            if (callback != null) {
                                readPolicies(callback, operation, reader);
                            } else {
                                readPolicies(contract, operation, reader);
                            }
                        } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {

                            // Read an implementation.composite
                            Composite implementation = assemblyFactory.createComposite();
                            implementation.setName(getQName(reader, NAME));
                            implementation.setUnresolved(true);
                            component.setImplementation(implementation);
                            readPolicies(implementation, reader);
                        } else {

                            // Read an extension element
                            Object extension = extensionProcessor.read(reader);
                            if (extension != null) {
                                if (extension instanceof InterfaceContract) {

                                    // <service><interface> and
                                    // <reference><interface>
                                    if (contract != null) {
                                        contract.setInterfaceContract((InterfaceContract)extension);
                                    } else {
                                        if (name.getNamespaceURI().equals(SCA10_NS)){
                                            throw new ContributionReadException("Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
                                        } else {
                                            composite.getExtensions().add(extension);
                                        }
                                    }

                                } else if (extension instanceof Binding) {
                                    // <service><binding> and
                                    // <reference><binding>
                                    if (callback != null) {
                                        callback.getBindings().add((Binding)extension);
                                    } else {
                                        if (contract != null) {
                                            contract.getBindings().add((Binding)extension);
                                        } else {
                                            if (name.getNamespaceURI().equals(SCA10_NS)){
                                                throw new ContributionReadException("Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
                                            } else {
                                                composite.getExtensions().add(extension);
                                            }
                                        }
                                    }

                                } else if (extension instanceof Implementation) {

                                    // <component><implementation>
                                    if (component != null) {
                                        component.setImplementation((Implementation)extension);
                                    } else {
                                        if (name.getNamespaceURI().equals(SCA10_NS)){
                                            throw new ContributionReadException("Unexpected <implementation> element found. It should appear inside a <component> element");
                                        } else {
                                            composite.getExtensions().add(extension);
                                        }
                                    }
                                } else {

                                    // Add the extension element to the current
                                    // element
                                    if (callback != null) {
                                        callback.getExtensions().add(extension);
                                    } else if (contract != null) {
                                        contract.getExtensions().add(extension);
                                    } else if (property != null) {
                                        property.getExtensions().add(extension);
                                    } else if (component != null) {
View Full Code Here

        for (Binding binding : reference.getBindings()) {
            extensionProcessor.write(binding, writer);
        }

        if (reference.getCallback() != null) {
            Callback callback = reference.getCallback();
            writeStart(writer, CALLBACK);

            for (Binding binding : callback.getBindings()) {
                extensionProcessor.write(binding, writer);
            }
            for (Object extension : callback.getExtensions()) {
                extensionProcessor.write(extension, writer);
            }

            writeEnd(writer);
        }
View Full Code Here

        for (Binding binding : service.getBindings()) {
            extensionProcessor.write(binding, writer);
        }

        if (service.getCallback() != null) {
            Callback callback = service.getCallback();
            writeStart(writer, CALLBACK);

            for (Binding binding : callback.getBindings()) {
                extensionProcessor.write(binding, writer);
            }
            for (Object extension : callback.getExtensions()) {
                extensionProcessor.write(extension, writer);
            }

            writeEnd(writer);
        }
View Full Code Here

        for (Binding binding : service.getBindings()) {
            extensionProcessor.write(binding, writer);
        }

        if (service.getCallback() != null) {
            Callback callback = service.getCallback();
            writeStart(writer, CALLBACK);

            for (Binding binding : callback.getBindings()) {
                extensionProcessor.write(binding, writer);
            }
            for (Object extension : callback.getExtensions()) {
                extensionProcessor.write(extension, writer);
            }

            writeEnd(writer);
        }
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.assembly.Callback

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.