Package org.apache.tuscany.sca.assembly

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


    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);
View Full Code Here


        // 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;
View Full Code Here

     * @param reference
     * @param reader
     */
    protected void readTargets(Reference reference, XMLStreamReader reader) {
        String value = reader.getAttributeValue(null, TARGET);
        ComponentService target = null;
        if (value != null) {
            for (StringTokenizer tokens = new StringTokenizer(value); tokens.hasMoreTokens();) {
                target = assemblyFactory.createComponentService();
                target.setUnresolved(true);
                target.setName(tokens.nextToken());
                reference.getTargets().add(target);
            }
        }
    }
View Full Code Here

        }
        throw new ServiceRuntimeException("Property not found: " + propertyName);
    }

    public <B> ServiceReference<B> createSelfReference(Class<B> businessInterface) {
        ComponentService service = ComponentContextHelper.getSingleService(component);
        try {
            return createSelfReference(businessInterface, service);
        } catch (Exception e) {
            throw new ServiceRuntimeException(e.getMessage(), e);
        }
View Full Code Here

                throw new ComponentUpdaterException(e.getMessage());
            }
            source.getImplementation().getReferences().add(reference);

            // targetService.
            ComponentService targetService = assemblyFactory
                    .createComponentService();
            targetService.setUnresolved(true);
            targetService.setName(targetComponent);
            targetReference.getTargets().add(targetService);

            // reconciliate
            reconcileReference(reference, targetReference, componentName);
            // create component reference for the reference
View Full Code Here

    /**
     * @param component
     */
    public static ComponentService getSingleService(Component component) {
        ComponentService targetService;
        List<ComponentService> services = component.getServices();
        List<ComponentService> regularServices = new ArrayList<ComponentService>();
        for (ComponentService service : services) {
            if (service.isCallback()) {
                continue;
View Full Code Here

            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();
            targetComponentService = endpoint.getTargetComponentService();
View Full Code Here

            componentTypeRef == null ? reference.getInterfaceContract() : componentTypeRef.getInterfaceContract();
        sourceContract = sourceContract.makeUnidirectional(false);

        EndpointReference wireSource =
            new EndpointReferenceImpl((RuntimeComponent)refComponent, reference, refBinding, sourceContract);
        ComponentService callbackService = reference.getCallbackService();
        if (callbackService != null) {
            // select a reference callback binding to pass with invocations on this wire
            Binding callbackBinding = null;
            for (Binding binding : callbackService.getBindings()) {
                // first look for a callback binding whose name matches the reference binding name
              if (refBinding.getName().startsWith(binding.getName())) {
                    callbackBinding = binding;
                    break;
                }
            }
            // if no callback binding found, try again based on reference binding type
            if (callbackBinding == null) {
                callbackBinding = callbackService.getBinding(refBinding.getClass());
            }
            InterfaceContract callbackContract = callbackService.getInterfaceContract();
            EndpointReference callbackEndpoint =
                new EndpointReferenceImpl((RuntimeComponent)refComponent, callbackService, callbackBinding,
                                          callbackContract);
            wireSource.setCallbackEndpoint(callbackEndpoint);
        }
View Full Code Here

                        if (index > -1) {
                            serviceName = targetURI.substring(index + 1);
                            targetURI = targetURI.substring(0, index);
                        }
                        Component targetComponent = compositeActivator.resolve(targetURI);
                        ComponentService targetService = null;
                        if (targetComponent != null) {
                            if ("".equals(serviceName)) {
                                targetService = ComponentContextHelper.getSingleService(targetComponent);
                            } else {
                                for (ComponentService service : targetComponent.getServices()) {
                                    if (service.getName().equals(serviceName)) {
                                        targetService = service;
                                        break;
                                    }
                                }
                            }
                        }
                        OptimizableBinding optimizableBinding = (OptimizableBinding)binding;
                        optimizableBinding.setTargetComponent(targetComponent);
                        optimizableBinding.setTargetComponentService(targetService);
                        if (targetService != null) {
                            for (Binding serviceBinding : targetService.getBindings()) {
                                if (serviceBinding.getClass() == binding.getClass()) {
                                    optimizableBinding.setTargetBinding(serviceBinding);
                                    break;
                                }
                            }
View Full Code Here

        ref2.setInterfaceContract(new TestInterfaceContract(factory));
        ref2.setReference(i.getReferences().get(1));
        c.getReferences().add(ref2);
        ref2.getBindings().add(new TestBinding(factory));

        ComponentService s = factory.createComponentService();
        s.setName("AccountService");
        s.setInterfaceContract(new TestInterfaceContract(factory));
        s.setService(i.getServices().get(0));
        c.getServices().add(s);
        s.getBindings().add(new TestBinding(factory));

        return c;
    }
View Full Code Here

TOP

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

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.