Package org.apache.tuscany.sca.assembly

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


                extensionProcessor.write(binding, writer);
            }

            // Write <callback> element
            if (service.getCallback() != null) {
                Callback callback = service.getCallback();
                writeStart(writer, CALLBACK, policyProcessor
                        .writePolicies(callback));

                // Write callback bindings
                for (Binding binding : callback.getBindings()) {
                    extensionProcessor.write(binding, writer);
                }

                // Write extensions
                for (Object extension : callback.getExtensions()) {
                    extensionProcessor.write(extension, writer);
                }

                writeEnd(writer);
            }

            // Write extensions
            for (Object extension : service.getExtensions()) {
                extensionProcessor.write(extension, writer);
            }

            writeEnd(writer);
        }

        // Write <component> elements
        for (Component component : composite.getComponents()) {
            writeStart(writer, COMPONENT, new XAttr(NAME, component.getName()),
                    new XAttr(URI, component.getURI()), new XAttr(AUTOWIRE,
                            component.getAutowire()), policyProcessor
                            .writePolicies(component));

            // Write <service> elements
            for (ComponentService service : component.getServices()) {
                writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
                        policyProcessor.writePolicies(service));

                // Write service interface
                extensionProcessor
                        .write(service.getInterfaceContract(), writer);

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

                // Write <callback> element
                if (service.getCallback() != null) {
                    Callback callback = service.getCallback();
                    writeStart(writer, CALLBACK, policyProcessor
                            .writePolicies(callback));

                    // Write bindings
                    for (Binding binding : callback.getBindings()) {
                        extensionProcessor.write(binding, writer);
                    }

                    // Write extensions
                    for (Object extension : callback.getExtensions()) {
                        extensionProcessor.write(extension, writer);
                    }

                    writeEnd(writer);
                }

                // Write extensions
                for (Object extension : service.getExtensions()) {
                    extensionProcessor.write(extension, writer);
                }

                writeEnd(writer);
            }

            // Write <reference> elements
            for (ComponentReference reference : component.getReferences()) {
                writeStart(writer, REFERENCE, new XAttr(NAME, reference
                        .getName()), new XAttr(AUTOWIRE, reference
                        .getAutowire()), writeTargets(reference),
                        policyProcessor.writePolicies(reference));

                // Write reference interface
                extensionProcessor.write(reference.getInterfaceContract(),
                        writer);

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

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

                    // Write callback bindings
                    for (Binding binding : callback.getBindings()) {
                        extensionProcessor.write(binding, writer);
                    }

                    // Write extensions
                    for (Object extensions : callback.getExtensions()) {
                        extensionProcessor.write(extensions, writer);
                    }

                    writeEnd(writer);
                }

                // Write extensions
                for (Object extensions : reference.getExtensions()) {
                    extensionProcessor.write(extensions, writer);
                }

                writeEnd(writer);
            }

            // Write <property> elements
            for (ComponentProperty property : component.getProperties()) {
                writeStart(writer, PROPERTY,
                        new XAttr(NAME, property.getName()), new XAttr(
                                MUST_SUPPLY, property.isMustSupply()),
                        new XAttr(MANY, property.isMany()), new XAttr(TYPE,
                                property.getXSDType()), new XAttr(ELEMENT,
                                property.getXSDElement()), new XAttr(SOURCE,
                                property.getSource()), new XAttr(FILE, property
                                .getFile()), policyProcessor
                                .writePolicies(property));

                // Write property value
                writePropertyValue(property.getValue(), property
                        .getXSDElement(), property.getXSDType(), writer);

                // Write extensions
                for (Object extension : property.getExtensions()) {
                    extensionProcessor.write(extension, writer);
                }

                writeEnd(writer);
            }

            // Write the component implementation
            Implementation implementation = component.getImplementation();
            if (implementation instanceof Composite) {
                writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME,
                        composite.getName()));
                writeEnd(writer);
            } else {
                extensionProcessor.write(component.getImplementation(), writer);
            }

            writeEnd(writer);
        }

        // Write <reference> elements
        for (Reference reference : composite.getReferences()) {
            CompositeReference compositeReference = (CompositeReference) reference;

            // Write list of promoted references
            List<String> promote = new ArrayList<String>();
            for (ComponentReference promoted : compositeReference
                    .getPromotedReferences()) {
                promote.add(promoted.getName());
            }

            // Write <reference> element
            writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
                    new XAttr(PROMOTE, promote), policyProcessor
                            .writePolicies(reference));

            // Write reference interface
            extensionProcessor.write(reference.getInterfaceContract(), writer);

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

            // Write <callback> element
            if (reference.getCallback() != null) {
                Callback callback = reference.getCallback();
                writeStart(writer, CALLBACK);

                // Write callback bindings
                for (Binding binding : callback.getBindings()) {
                    extensionProcessor.write(binding, writer);
                }

                // Write extensions
                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;

        // 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)));
                        if(isSet(reader, AUTOWIRE)) {
                            composite.setAutowire(getBoolean(reader, AUTOWIRE));
                        }
                        composite.setLocal(getBoolean(reader, LOCAL));
                        composite.setConstrainingType(readConstrainingType(reader));
                        policyProcessor.readPolicies(composite, reader);

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

                        // Read an <include>
                        include = assemblyFactory.createComposite();
                        include.setName(getQName(reader, NAME));
                        include.setURI(getString(reader, URI));
                        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);
                            policyProcessor.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);
                            policyProcessor.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);
                            if (isSet(reader, AUTOWIRE)) {
                                componentReference.setAutowire(getBoolean(reader, AUTOWIRE));
                            }
                            readTargets(componentReference, reader);
                            componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                            component.getReferences().add(componentReference);
                            policyProcessor.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);
                            policyProcessor.readPolicies(contract, reader);
                        }

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

                            // Read a <component><property>
                            componentProperty = assemblyFactory.createComponentProperty();
                            property = componentProperty;
                            String source = getString(reader, SOURCE);
                            if(source!=null) {
                                source = source.trim();
                            }
                            componentProperty.setSource(source);
                            if (source != null) {
                                // $<name>/...
                                if (source.charAt(0) == '$') {
                                    int index = source.indexOf('/');
                                    if (index == -1) {
                                        // Tolerating $prop
                                        source = source + "/";
                                        index = source.length() - 1;
                                    }
                                    source = source.substring(index + 1);
                                    if ("".equals(source)) {
                                        source = ".";
                                    }
                                }
                                XPath xpath = xPathFactory.newXPath();
                                xpath.setNamespaceContext(reader.getNamespaceContext());
                                try {
                                    componentProperty.setSourceXPathExpression(xpath.compile(source));
                                } catch (XPathExpressionException e) {
                                    throw new ContributionReadException(e);
                                }
                            }
                            componentProperty.setFile(getString(reader, FILE));
                            policyProcessor.readPolicies(property, reader);
                            readAbstractProperty(componentProperty, reader);
                           
                            // Read the property value
                            Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
                            property.setValue(value);
                           
                            component.getProperties().add(componentProperty);
                        } else {

                            // Read a <composite><property>
                            property = assemblyFactory.createProperty();
                            policyProcessor.readPolicies(property, reader);
                            readAbstractProperty(property, reader);
                           
                            // Read the property value
                            Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
                            property.setValue(value);
                           
                            composite.getProperties().add(property);
                        }
                       
                        // TUSCANY-1949
                        // If the proerty doesn't have a value, the END_ELEMENT event is read by the readPropertyValue
                        if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
                            property = null;
                            componentProperty = null;
                        }

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

                        // Read a <component>
                        component = assemblyFactory.createComponent();
                        component.setName(getString(reader, NAME));
                        if (isSet(reader, AUTOWIRE)) {
                            component.setAutowire(getBoolean(reader, AUTOWIRE));
                        }
                        if (isSet(reader, URI)) {
                            component.setURI(getString(reader, URI));
                        }
                        component.setConstrainingType(readConstrainingType(reader));
                        composite.getComponents().add(component);
                        policyProcessor.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);
                        policyProcessor.readPolicies(wire, reader);

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

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

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

                        // Read an <operation>
                        ConfiguredOperation operation = assemblyFactory.createConfiguredOperation();
                        operation.setName(getString(reader, NAME));
                        operation.setUnresolved(true);
                        if (callback != null) {
                            policyProcessor.readPolicies(operation, reader);
                        } else {
                            policyProcessor.readPolicies(operation, reader);
                        }
                       
                        OperationsConfigurator opConfigurator = null;
                        if ( compositeService != null ) {
                            opConfigurator = compositeService;
                        } else if ( componentService != null ) {
                            opConfigurator = componentService;
                        } else if ( compositeReference != null ) {
                            opConfigurator = compositeReference;
                        } else if ( componentReference != null ) {
                            opConfigurator = componentReference;
                        }
                       
                        opConfigurator.getConfiguredOperations().add(operation);
                    } 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);
                        policyProcessor.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) {
                                if ( extension instanceof PolicySetAttachPoint ) {
                                    IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
                                    bindingType.setName(name);
                                    bindingType.setUnresolved(true);
                                    ((PolicySetAttachPoint)extension).setType(bindingType);
                                }
                                // <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) {
                                if ( extension instanceof PolicySetAttachPoint ) {
                                    IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType();
                                    implType.setName(name);
                                    implType.setUnresolved(true);
                                    ((PolicySetAttachPoint)extension).setType(implType);
                                }
                                // <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

                     "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

                extensionProcessor.write(binding, writer);
            }

            // Write <callback> element
            if (service.getCallback() != null) {
                Callback callback = service.getCallback();
                writeStart(writer, CALLBACK,
                           policyProcessor.writePolicies(callback));
           
                // Write callback bindings
                for (Binding binding : callback.getBindings()) {
                    extensionProcessor.write(binding, writer);
                }
               
                // Write extensions
                for (Object extension : callback.getExtensions()) {
                    extensionProcessor.write(extension, writer);
                }
           
                writeEnd(writer);
            }

            // Write extensions
            for (Object extension : service.getExtensions()) {
                extensionProcessor.write(extension, writer);
            }
           
            writeEnd(writer);
        }

        // Write <component> elements
        for (Component component : composite.getComponents()) {
            writeStart(writer, COMPONENT, new XAttr(NAME, component.getName()),
                       new XAttr(URI, component.getURI()),
                       new XAttr(AUTOWIRE, component.getAutowire()),
                       policyProcessor.writePolicies(component));
           
            // Write the component implementation
            Implementation implementation = component.getImplementation();
            if (implementation instanceof Composite) {
                writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, composite.getName()));
                writeEnd(writer);
            } else {
                extensionProcessor.write(component.getImplementation(), writer);
            }
           
            // Write <service> elements
            for (ComponentService service : component.getServices()) {
                writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
                           policyProcessor.writePolicies(service));

                // Write service interface
                extensionProcessor.write(service.getInterfaceContract(), writer);
               
                // Write bindings
                for (Binding binding : service.getBindings()) {
                    extensionProcessor.write(binding, writer);
                }
               
                // Write <callback> element
                if (service.getCallback() != null) {
                    Callback callback = service.getCallback();
                    writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));
               
                    // Write bindings
                    for (Binding binding : callback.getBindings()) {
                        extensionProcessor.write(binding, writer);
                    }
                   
                    // Write extensions
                    for (Object extension : callback.getExtensions()) {
                        extensionProcessor.write(extension, writer);
                    }
               
                    writeEnd(writer);
                }
               
                // Write extensions
                for (Object extension : service.getExtensions()) {
                    extensionProcessor.write(extension, writer);
                }
               
                writeEnd(writer);
            }
           
            // Write <reference> elements
            for (ComponentReference reference : component.getReferences()) {
                writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
                           new XAttr(AUTOWIRE, reference.getAutowire()),
                           writeTargets(reference),
                           policyProcessor.writePolicies(reference));

                // Write reference interface
                extensionProcessor.write(reference.getInterfaceContract(), writer);

                // Write bindings
                for (Binding binding : reference.getBindings()) {
                    extensionProcessor.write(binding, writer);
                }
               
                // Write callback
                if (reference.getCallback() != null) {
                    Callback callback = reference.getCallback();
                    writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));
               
                    // Write callback bindings
                    for (Binding binding : callback.getBindings()) {
                        extensionProcessor.write(binding, writer);
                    }
                   
                    // Write extensions
                    for (Object extensions : callback.getExtensions()) {
                        extensionProcessor.write(extensions, writer);
                    }
               
                    writeEnd(writer);
                }
               
                // Write extensions
                for (Object extensions : reference.getExtensions()) {
                    extensionProcessor.write(extensions, writer);
                }
               
                writeEnd(writer);
            }
           
            // Write <property> elements
            for (ComponentProperty property : component.getProperties()) {
                writeStart(writer,
                           PROPERTY,
                           new XAttr(NAME, property.getName()),
                           new XAttr(MUST_SUPPLY, property.isMustSupply()),
                           new XAttr(MANY, property.isMany()),
                           new XAttr(TYPE, property.getXSDType()),
                           new XAttr(ELEMENT, property.getXSDElement()),
                           new XAttr(SOURCE, property.getSource()),
                           new XAttr(FILE, property.getFile()),
                           policyProcessor.writePolicies(property));

                // Write property value
                writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);

                // Write extensions
                for (Object extension : property.getExtensions()) {
                    extensionProcessor.write(extension, writer);
                }

                writeEnd(writer);
            }
   
            writeEnd(writer);
        }

        // Write <reference> elements
        for (Reference reference : composite.getReferences()) {
            CompositeReference compositeReference = (CompositeReference)reference;

            // Write list of promoted references
            List<String> promote = new ArrayList<String>();
            for (ComponentReference promoted: compositeReference.getPromotedReferences()) {
                promote.add(promoted.getName());
            }
           
            // Write <reference> element
            writeStart(writer, REFERENCE, new XAttr(NAME, reference.getName()),
                       new XAttr(PROMOTE, promote),
                       policyProcessor.writePolicies(reference));

            // Write reference interface
            extensionProcessor.write(reference.getInterfaceContract(), writer);
           
            // Write bindings
            for (Binding binding : reference.getBindings()) {
                extensionProcessor.write(binding, writer);
            }
           
            // Write <callback> element
            if (reference.getCallback() != null) {
                Callback callback = reference.getCallback();
                writeStart(writer, CALLBACK);
           
                // Write callback bindings
                for (Binding binding : callback.getBindings()) {
                    extensionProcessor.write(binding, writer);
                }
               
                // Write extensions
                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;
        Monitor monitor = context.getMonitor();
        Contribution contribution = context.getContribution();
        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.setSpecVersion(Constants.SCA11_NS);
                            if (contribution != null) {
                                composite.setContributionURI(contribution.getURI());
                            }

                            composite.setName(new QName(getURIString(reader, TARGET_NAMESPACE), getString(reader, NAME)));

                            if (!isSet(reader, TARGET_NAMESPACE)) {
                                // spec says that a composite must have a namespace
                                warning(monitor, "NoCompositeNamespace", composite, composite.getName().toString());
                            }

                            if (isSet(reader, AUTOWIRE)) {
                                composite.setAutowire(getBoolean(reader, AUTOWIRE));
                            }

                            //handle extension attributes
                            this.readExtendedAttributes(reader, name, composite, extensionAttributeProcessor, context);

                            composite.setLocal(getBoolean(reader, LOCAL));
                            policyProcessor.readPolicies(composite, reader);

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

                            // Read an <include>
                            include = assemblyFactory.createComposite();
                            include.setName(getQName(reader, NAME));
                            include.setURI(getURIString(reader, URI));
                            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));

                                //handle extension attributes
                                this.readExtendedAttributes(reader, name, componentService, extensionAttributeProcessor, context);

                                component.getServices().add(componentService);
                                policyProcessor.readPolicies(contract, reader);
                            } else {

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

                                String promoted = getURIString(reader, PROMOTE);
                                if (promoted != null) {
                                    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);
                                }

                                //handle extension attributes
                                this.readExtendedAttributes(reader, name, compositeService, extensionAttributeProcessor, context);

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

                            // set the parent model so that binding processing can
                            // detect it they're being read as part of a reference
                            // or a service
                            context.setParentModel(contract);
                           
                        } 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);
                                if (isSet(reader, AUTOWIRE)) {
                                    componentReference.setAutowire(getBoolean(reader, AUTOWIRE));
                                }
                                // Read @nonOverridable
                                String nonOverridable = reader.getAttributeValue(null, NONOVERRIDABLE);
                                if (nonOverridable != null) {
                                    componentReference.setNonOverridable(Boolean.parseBoolean(nonOverridable));
                                }
                                readTargets(componentReference, reader);
                                componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));

                                //handle extension attributes
                                this.readExtendedAttributes(reader,
                                                            name,
                                                            componentReference,
                                                            extensionAttributeProcessor, context);

                                component.getReferences().add(componentReference);
                                policyProcessor.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 = getString(reader, Constants.PROMOTE);
                                if (promote != null) {
                                    for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) {
                                        String refName = tokens.nextToken();
                                        Component promotedComponent = assemblyFactory.createComponent();
                                        int index = refName.indexOf('/');
                                        if (index == -1) {
                                            error(monitor, "Invalid reference name", compositeReference, refName);
                                        }
                                        String promotedComponentName = refName.substring(0, index);
                                        promotedComponent.setName(promotedComponentName);
                                        promotedComponent.setUnresolved(true);
                                        compositeReference.getPromotedComponents().add(promotedComponent);
                                        ComponentReference promotedReference =
                                            assemblyFactory.createComponentReference();
                                        promotedReference.setUnresolved(true);
                                        promotedReference.setName(refName);
                                        compositeReference.getPromotedReferences().add(promotedReference);
                                    }
                                }
                                compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));

                                //handle extension attributes
                                this.readExtendedAttributes(reader,
                                                            name,
                                                            compositeReference,
                                                            extensionAttributeProcessor, context);

                                composite.getReferences().add(compositeReference);
                                policyProcessor.readPolicies(contract, reader);
                            }

                            // set the parent model so that binding processing can
                            // detect it they're being read as part of a reference
                            // or a service
                            context.setParentModel(contract);
                           
                        } else if (PROPERTY_QNAME.equals(name)) {
                            if (component != null) {

                                // Read a <component><property>
                                componentProperty = assemblyFactory.createComponentProperty();
                                property = componentProperty;
                                String source = getURIString(reader, SOURCE);
                                if (source != null) {
                                    source = source.trim();
                                }
                                componentProperty.setSource(source);
                                if (source != null) {
                                  String xPath = prepareSourceXPathString( source );
                                   
                                    try {
                                        componentProperty.setSourceXPathExpression(xpathHelper.compile(reader
                                            .getNamespaceContext(), xPath));
                                    } catch (XPathExpressionException e) {
                                        ContributionReadException ce = new ContributionReadException(e);
                                        error(monitor, "ContributionReadException", source, ce);
                                        //throw ce;
                                    }
                                }
                                componentProperty.setFile(getURIString(reader, FILE));

                                //handle extension attributes
                                this.readExtendedAttributes(reader,
                                                            name,
                                                            componentProperty,
                                                            extensionAttributeProcessor, context);

                                policyProcessor.readPolicies(property, reader);
                                readAbstractProperty(componentProperty, reader, context);

                                // Read the property value
                                Document value =
                                    readPropertyValue(property.getXSDElement(), property.getXSDType(), property
                                        .isMany(), reader, context);
                                property.setValue(value);

                                component.getProperties().add(componentProperty);
                            } else {

                                // Read a <composite><property>
                                property = assemblyFactory.createProperty();
                                policyProcessor.readPolicies(property, reader);
                                readAbstractProperty(property, reader, context);

                                // Read the property value
                                Document value =
                                    readPropertyValue(property.getXSDElement(), property.getXSDType(), property
                                        .isMany(), reader, context);
                                property.setValue(value);

                                composite.getProperties().add(property);
                            }

                            // TUSCANY-1949
                            // If the property doesn't have a value, the END_ELEMENT event is read by the readPropertyValue
                            if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
                                property = null;
                                componentProperty = null;
                            }

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

                            // Read a <component>
                            component = assemblyFactory.createComponent();
                            component.setName(getString(reader, NAME));
                            if (isSet(reader, AUTOWIRE)) {
                                component.setAutowire(getBoolean(reader, AUTOWIRE));
                            }
                            if (isSet(reader, URI)) {
                                component.setURI(getURIString(reader, URI));
                            }

                            //handle extension attributes
                            this.readExtendedAttributes(reader, name, component, extensionAttributeProcessor, context);

                            composite.getComponents().add(component);
                            policyProcessor.readPolicies(component, reader);

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

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

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

                            // Read @replace
                            String replace = reader.getAttributeValue(null, REPLACE);
                            if (replace != null) {
                                wire.setReplace(Boolean.parseBoolean(replace));
                            }

                            //handle extension attributes
                            this.readExtendedAttributes(reader, name, wire, extensionAttributeProcessor, context);

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

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

                            // Read a <callback>
                            callback = assemblyFactory.createCallback();
                            contract.setCallback(callback);
                            callback.setParentContract(contract);

                            //handle extension attributes
                            this.readExtendedAttributes(reader, name, callback, extensionAttributeProcessor, context);

                            policyProcessor.readPolicies(callback, reader);
                           
                            // set the parent model so that binding processing can
                            // detect it they're being read as part of a callback
                            context.setParentModel(callback);                           

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

                            // Read an implementation.composite
                            Composite implementation = assemblyFactory.createComposite();
                            implementation.setName(getQName(reader, NAME));
                            implementation.setUnresolved(true);

                            //handle extension attributes
                            this.readExtendedAttributes(reader, name, implementation, extensionAttributeProcessor, context);

                            component.setImplementation(implementation);
                            policyProcessor.readPolicies(implementation, reader);
                        } else if (REQUIRES_QNAME.equals(name)) {
                            List<QName> intents = getQNames(reader, INTENTS);
                            for (QName i : intents) {
                                Intent intent = policyFactory.createIntent();
                                intent.setName(i);
                                if (composite != null) {
                                    composite.getRequiredIntents().add(intent);
                                } else if (component != null) {
                                    component.getRequiredIntents().add(intent);
                                } else if (contract != null) {
                                    contract.getRequiredIntents().add(intent);
                                } else if (callback != null) {
                                    callback.getRequiredIntents().add(intent);
                                }
                            }
                        } else if (POLICY_SET_ATTACHMENT_QNAME.equals(name)) {
                            QName ps = getQName(reader, NAME);
                            if (ps != null) {
                                PolicySet policySet = policyFactory.createPolicySet();
                                policySet.setName(ps);
                                if (composite != null) {
                                    composite.getPolicySets().add(policySet);
                                } else if (component != null) {
                                    component.getPolicySets().add(policySet);
                                } else if (contract != null) {
                                    contract.getPolicySets().add(policySet);
                                } else if (callback != null) {
                                    callback.getPolicySets().add(policySet);
                                }
                            }
                        } else if(EXTENSION_QNAME.equals(name)) {
                            // Handle <extension>
                            //ignore element as this is a wrapper for extensibility
                            break;
                        } else {

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

                                    // <service><interface> and
                                    // <reference><interface>
                                    if (contract != null) {
                                        contract.setInterfaceContract((InterfaceContract)extension);
                                    } else {
                                        if (name.getNamespaceURI().equals(SCA11_NS)) {
                                            error(monitor, "UnexpectedInterfaceElement", extension);
                                            //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) {
                                    if (extension instanceof PolicySubject) {
                                        ExtensionType bindingType = intentAttachPointTypeFactory.createBindingType();
                                        bindingType.setType(name);
                                        bindingType.setUnresolved(true);
                                        ((PolicySubject)extension).setExtensionType(bindingType);
                                    }
                                    // <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(SCA11_NS)) {
                                                error(monitor, "UnexpectedBindingElement", extension);
                                                //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) {
                                    if (extension instanceof PolicySubject) {
                                        ExtensionType implType =
                                            intentAttachPointTypeFactory.createImplementationType();
                                        implType.setType(name);
                                        implType.setUnresolved(true);
                                        ((PolicySubject)extension).setExtensionType(implType);
                                    }
                                    // <component><implementation>
                                    if (component != null) {
                                        component.setImplementation((Implementation)extension);
                                    } else {
                                        if (name.getNamespaceURI().equals(SCA11_NS)) {
                                            error(monitor, "UnexpectedImplementationElement", extension);
                                            //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

                extensionProcessor.write(binding, writer, context);
            }

            // Write <callback> element
            if (service.getCallback() != null) {
                Callback callback = service.getCallback();
                writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));

                //write extended attributes
                this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context);

                // Write callback bindings
                for (Binding binding : callback.getBindings()) {
                    extensionProcessor.write(binding, writer, context);
                }

                // Write extensions
                this.writeExtendedElements(writer, service, extensionProcessor, context);

                writeEnd(writer);
            }

            // Write extensions
            this.writeExtendedElements(writer, service, extensionProcessor, context);

            writeEnd(writer);
        }

        // Write <component> elements
        for (Component component : composite.getComponents()) {
            writeStart(writer,
                       COMPONENT,
                       new XAttr(NAME, component.getName()),
                       new XAttr(URI, component.getURI()),
                       new XAttr(AUTOWIRE, component.getAutowire()),
                       policyProcessor.writePolicies(component));

            //write extended attributes
            this.writeExtendedAttributes(writer, component, extensionAttributeProcessor, context);

            // Write the component implementation
            Implementation implementation = component.getImplementation();
            if (implementation instanceof Composite) {
                writeStart(writer, IMPLEMENTATION_COMPOSITE, new XAttr(NAME, ((Composite)implementation).getName()), policyProcessor.writePolicies(implementation));

                //write extended attributes
                this.writeExtendedAttributes(writer, (Composite)implementation, extensionAttributeProcessor, context);
               
                writeEnd(writer);
            } else {
                extensionProcessor.write(component.getImplementation(), writer, context);
            }

            for (Object extension : component.getExtensions()) {
                extensionProcessor.write(extension, writer, context);
            }

            // Write <service> elements
            for (ComponentService service : component.getServices()) {
                writeStart(writer, SERVICE, new XAttr(NAME, service.getName()), policyProcessor.writePolicies(service));

                //write extended attributes
                this.writeExtendedAttributes(writer, service, extensionAttributeProcessor, context);

                // Write service interface
                extensionProcessor.write(service.getInterfaceContract(), writer, context);

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

                // Write <callback> element
                if (service.getCallback() != null) {
                    Callback callback = service.getCallback();
                    writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));

                    //write extended attributes
                    this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context);

                    // Write bindings
                    for (Binding binding : callback.getBindings()) {
                        extensionProcessor.write(binding, writer, context);
                    }

                    // Write extensions
                    this.writeExtendedElements(writer, callback, extensionProcessor, context);

                    writeEnd(writer);
                }

                // Write extensions
                this.writeExtendedElements(writer, service, extensionProcessor, context);
               
                writeEnd(writer);
            }

            // Write <reference> elements
            for (ComponentReference reference : component.getReferences()) {
                writeStart(writer,
                           REFERENCE,
                           new XAttr(NAME, reference.getName()),
                           new XAttr(AUTOWIRE, reference.getAutowire()),
                           (reference.isNonOverridable() ? new XAttr(NONOVERRIDABLE, true) : null),
                           writeMultiplicity(reference),
                           writeTargets(reference),
                           policyProcessor.writePolicies(reference));

                //write extended attributes
                this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor, context);

                // Write reference interface
                extensionProcessor.write(reference.getInterfaceContract(), writer, context);

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

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

                    //write extended attributes
                    this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context);

                    // Write callback bindings
                    for (Binding binding : callback.getBindings()) {
                        extensionProcessor.write(binding, writer, context);
                    }

                    // Write extensions
                    this.writeExtendedElements(writer, callback, extensionProcessor, context);

                    writeEnd(writer);
                }

                // Write extensions
                this.writeExtendedElements(writer, reference, extensionProcessor, context);

                writeEnd(writer);
            }

            // Write <property> elements
            for (ComponentProperty property : component.getProperties()) {
                writeStart(writer,
                           PROPERTY,
                           new XAttr(NAME, property.getName()),
                           new XAttr(MUST_SUPPLY, property.isMustSupply()),
                           new XAttr(MANY, property.isMany()),
                           new XAttr(TYPE, property.getXSDType()),
                           new XAttr(ELEMENT, property.getXSDElement()),
                           new XAttr(SOURCE, property.getSource()),
                           new XAttr(FILE, property.getFile()),
                           policyProcessor.writePolicies(property));

                //write extended attributes
                this.writeExtendedAttributes(writer, property, extensionAttributeProcessor, context);

                // Write property value
                writePropertyValue(property.getValue(), property.getXSDElement(), property.getXSDType(), writer);

                // Write extensions
                for (Object extension : property.getExtensions()) {
                    extensionProcessor.write(extension, writer, context);
                }

                writeEnd(writer);
            }

            writeEnd(writer);
        }

        // Write <reference> elements
        for (Reference reference : composite.getReferences()) {
            CompositeReference compositeReference = (CompositeReference)reference;

            // Write list of promoted references
            List<String> promote = new ArrayList<String>();
            for (ComponentReference promoted : compositeReference.getPromotedReferences()) {
                promote.add(promoted.getName());
            }

            // Write <reference> element
            writeStart(writer,
                       REFERENCE,
                       new XAttr(NAME, reference.getName()),
                       new XAttr(PROMOTE, promote),
                       writeMultiplicity(reference),
                       policyProcessor.writePolicies(reference));

            //write extended attributes
            this.writeExtendedAttributes(writer, reference, extensionAttributeProcessor, context);

            // Write reference interface
            extensionProcessor.write(reference.getInterfaceContract(), writer, context);

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

            // Write <callback> element
            if (reference.getCallback() != null) {
                Callback callback = reference.getCallback();
                writeStart(writer, CALLBACK);

                //write extended attributes
                this.writeExtendedAttributes(writer, callback, extensionAttributeProcessor, context);

                // Write callback bindings
                for (Binding binding : callback.getBindings()) {
                    extensionProcessor.write(binding, writer, context);
                }

                // Write extensions
                this.writeExtendedElements(writer, callback, extensionProcessor, context);
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();
   
                        } 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);
                            policyProcessor.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);
                            policyProcessor.readPolicies(reference, reader);
   
                        } else if (Constants.PROPERTY_QNAME.equals(name)) {
   
                            // Read a <property>
                            property = assemblyFactory.createProperty();
                            readAbstractProperty(property, reader, context);
                            policyProcessor.readPolicies(property, reader);
                           
                            // Read the property value
                            Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), property.isMany(), reader, context);
                            property.setValue(value);
                           
                            componentType.getProperties().add(property);
                           
                        } else if (Constants.IMPLEMENTATION_QNAME.equals(name)) {
                           
                            // Read an <implementation> element
                            policyProcessor.readPolicies(componentType, reader);
                           
                        } else if (Constants.CALLBACK_QNAME.equals(name)) {
   
                            // Read a <callback>
                            callback = assemblyFactory.createCallback();
                            contract.setCallback(callback);
                            policyProcessor.readPolicies(callback, reader);
   
                        } else if (OPERATION_QNAME.equals(name)) {
   
                            // Read an <operation>
                            Operation operation = new OperationImpl();
                            operation.setName(getString(reader, NAME));
                            operation.setUnresolved(true);
                            if (callback != null) {
                                policyProcessor.readPolicies(callback, operation, reader);
                            } else {
                                policyProcessor.readPolicies(contract, operation, reader);
                            }
                        } else if(EXTENSION_QNAME.equals(name)) {
                            // Handle <extension>
                            //ignore element as this is a wrapper for extensibility
                            break;
                        } else {
                       
   
                            // Read an extension element
                            Object extension = extensionProcessor.read(reader, context);
                            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, context);
            }
           
            if (service.getCallback() != null) {
                Callback callback = service.getCallback();
                writeStart(writer, CALLBACK, policyProcessor.writePolicies(callback));

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

        // Write <reference> elements
        for (Reference reference : componentType.getReferences()) {
           
            writeStart(writer, REFERENCE,
                  new XAttr(NAME, reference.getName()),
                  writeMultiplicity(reference),
                  writeTargets(reference),
                  policyProcessor.writePolicies(reference));

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

                for (Binding binding: callback.getBindings()) {
                    extensionProcessor.write(binding, writer, context);
                }
                for (Object extension: callback.getExtensions()) {
                    extensionProcessor.write(extension, writer, context);
                }
               
                writeEnd(writer);
            }
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.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

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.