Package org.apache.tuscany.sca.assembly

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


        CompositeActivator compositeActivator = runtime.getCompositeActivator();
        compositeActivator.start(component);
    }

    public void stopComponent(String componentName) throws ActivationException {
        Component component = getComponent(componentName);
        if (component == null) {
            throw new IllegalArgumentException("no component: " + componentName);
        }
        CompositeActivator compositeActivator = runtime.getCompositeActivator();
        compositeActivator.stop(component);
View Full Code Here


            reader.nextTag();
        }
        Object model = extensionProcessor.read(reader, context);
        if (model instanceof Composite) {
            Composite composite = (Composite)model;
            Component component = composite.getComponents().get(0);
            ComponentReference reference = component.getReferences().get(0);
            Binding binding = reference.getBindings().get(0);
            endpointReference.setComponent(component);
            endpointReference.setReference(reference);
            reference.getEndpointReferences().add(endpointReference);
            endpointReference.setBinding(binding);
View Full Code Here

    private Composite wrap(EndpointReference endpointReference) {
        try {
            Composite composite = assemblyFactory.createComposite();
            composite.setName(ENDPOINT_REFERENCE_QNAME);
            composite.setLocal(false);
            Component component = (Component)endpointReference.getComponent().clone();
            composite.getComponents().add(component);
            component.getReferences().clear();
            component.getServices().clear();
            ComponentReference reference = (ComponentReference)endpointReference.getReference().clone();
            component.getReferences().add(reference);
            reference.getBindings().clear();
            Binding binding = (Binding)endpointReference.getBinding().clone();
            reference.getBindings().add(binding);
            //reference.setInterfaceContract(endpointReference.getInterfaceContract());
            if (endpointReference.getStatus() != EndpointReference.Status.RESOLVED_BINDING){
View Full Code Here

    }

    public Component read(XMLStreamReader reader)
            throws ContributionReadException, XMLStreamException {
        Composite include = null;
        Component component = null;
        Property property = null;
        ComponentService componentService = null;
        ComponentReference componentReference = null;
        ComponentProperty componentProperty = null;
        CompositeService compositeService = null;
        CompositeReference compositeReference = null;
        Contract contract = null;
        Wire wire = null;
        Callback callback = null;
        QName name = null;

        // Read the component scdl

        while (reader.hasNext()) {
            int event = reader.getEventType();
            switch (event) {
            case START_ELEMENT:
                QName itemName = reader.getName();
                if (!itemName.getNamespaceURI().equals(SCA10_NS))
                    name = new QName(SCA10_NS, itemName.getLocalPart());
                else
                    name = itemName;

                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 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 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));
                        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 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>
                    Operation operation = assemblyFactory.createOperation();
                    operation.setName(getString(reader, NAME));
                    operation.setUnresolved(true);
                    if (callback != null) {
                        policyProcessor.readPolicies(callback, operation,
                                reader);
                    } else {
                        policyProcessor.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);
                    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) {
                            // <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) {
                                component.getExtensions().add(extension);
                            } else {
                                composite.getExtensions().add(extension);
                            }
                        }
                    }
View Full Code Here

                        .writePolicies(composite));

        // Write <service> elements
        for (Service service : composite.getServices()) {
            CompositeService compositeService = (CompositeService) service;
            Component promotedComponent = compositeService
                    .getPromotedComponent();
            ComponentService promotedService = compositeService
                    .getPromotedService();
            String promote;
            if (promotedService != null) {
                if (promotedService.getName() != null) {
                    promote = promotedComponent.getName() + '/'
                            + promotedService.getService();
                } else {
                    promote = promotedComponent.getName();
                }
            } else {
                promote = null;
            }
            writeStart(writer, SERVICE, new XAttr(NAME, service.getName()),
View Full Code Here

        Contribution contrib = contributionService.getContribution(contribURI);
        List<DeployedArtifact> artifacts = contrib.getArtifacts();
        // RuntimeComponent source = null;
        Composite composite = ArtifactsFinder.findComposite(compositeURI,
                artifacts);
        Component c = ArtifactsFinder.findComponent(composite, componentName);
        if (targetReference.getAutowire() == null) {
            targetReference.setAutowire(c.getAutowire());
        }

        // Reconcile targets
        if (targetReference.getTargets().isEmpty()) {
            targetReference.getTargets().addAll(reference.getTargets());
View Full Code Here

    public void write(Component component, ComponentReference reference, Writer writer) throws IOException {
        try {
            StAXArtifactProcessor<Composite> processor = staxProcessors.getProcessor(Composite.class);
            Composite composite = assemblyFactory.createComposite();
            composite.setName(new QName("http://tuscany.apache.org/xmlns/sca/1.0", "default"));
            Component comp = assemblyFactory.createComponent();
            comp.setName("default");
            comp.setURI(component.getURI());
            composite.getComponents().add(comp);
            comp.getReferences().add(reference);

            XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
            XMLStreamWriter streamWriter = outputFactory.createXMLStreamWriter(writer);
            processor.write(composite, streamWriter);
        } catch (Exception e) {
View Full Code Here

            }
            found = true;
        }

        if (found) {
            Component component = processor.getParsedComponent();
            Composite augmentedComposite = processor.getParsedComposite();
            try {
                processor.resolve(component, contrib.getModelResolver());
                compositeBuilder.attach(augmentedComposite, component);
                ((CompositeActivatorImpl) compositeActivator)
View Full Code Here

        List<DeployedArtifact> artifacts = contrib.getArtifacts();

        Composite composite = ArtifactsFinder.findComposite(compositeURI,
                artifacts);
        List<Component> components = composite.getComponents();
        Component toRemove = null;
        for (Component component : components) {
            if (((RuntimeComponent) component).getName().equals(componentName)) {
                toRemove = component;
                break;
            }
View Full Code Here

        if (!(reference instanceof RuntimeComponentReference)) {
            return;
        }

        // create wire if binding has an endpoint
        Component targetComponent = null;
        ComponentService targetComponentService = null;
        Binding targetBinding = null;
        if (binding instanceof OptimizableBinding) {
            OptimizableBinding endpoint = (OptimizableBinding)binding;
            targetComponent = endpoint.getTargetComponent();
View Full Code Here

TOP

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

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.