Package org.apache.tuscany.sca.assembly

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


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


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

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

                // If the implementation service is a CompositeService, ensure that the Reference that is
                // created is a CompositeReference, otherwise create a Reference
                Reference implReference;
                if (implService instanceof CompositeService) {
                    CompositeReference implCompReference = assemblyFactory.createCompositeReference();
                    // Set the promoted component from the promoted component of the composite service
                    implCompReference.getPromotedComponents().add(((CompositeService)implService)
                        .getPromotedComponent());
                   
                    // Get the promoted component reference corresponding to the service with the callback
                    // fist checking that the promoted service is resolved lest we get a NPE trying to
                    // retrieve the promoted component. It could be unresolved if the user gets the
                    // promotes string wrong
                    // TODO - is there any danger that the callback reference name will clash with other
                    //        reference names. Old code used to qualify it with promoted component name
                    if (((CompositeService)implService).getPromotedService().isUnresolved() == false){
                        String referenceName = ((CompositeService)implService).getPromotedService().getName();
                        ComponentReference promotedReference = ((CompositeService)implService).getPromotedComponent().getReference(referenceName);
                       
                        if (promotedReference != null){
                            implCompReference.getPromotedReferences().add(promotedReference);
                        } else {
                            Monitor.error(monitor,
                                          this,
                                          Messages.ASSEMBLY_VALIDATION,
                                          "PromotedCallbackReferenceNotFound",
View Full Code Here

                if (compositeService.getPromotedService() != null) {
                    compositeService.getPromotedService().setUnresolved(true);
                }
            }
            for (Reference reference : clone.getReferences()) {
                CompositeReference compositeReference = (CompositeReference)reference;
                for (ComponentReference ref : compositeReference.getPromotedReferences()) {
                    // Force the promoted reference to be rebuilt against the clone
                    ref.setUnresolved(true);
                }
            }
View Full Code Here

            }
               
        }
   
        for (Reference reference : composite.getReferences()) {
            CompositeReference compReference = (CompositeReference)reference;
            addPoliciesFromPromotedReference(compReference);
            try {
                //compute the intents for operations under service element
                PolicyConfigurationUtil.computeIntentsForOperations(reference);
                //addInheritedOpConfOnBindings(reference);
               
                if (compReference.getCallback() != null) {
                    PolicyComputationUtils.addInheritedIntents(compReference.getRequiredIntents(),
                                        compReference.getCallback().getRequiredIntents());
                    PolicyComputationUtils.addInheritedPolicySets(compReference.getPolicySets(),
                                           compReference.getCallback().getPolicySets(),
                                           false);
                }
               
                PolicyConfigurationUtil.computeBindingIntentsAndPolicySets(reference);
                PolicyConfigurationUtil.determineApplicableBindingPolicySets(reference, null);
View Full Code Here

                        }
    
                        // If the component reference is a promotion override, override the
                        // configuration of the promoted reference 
                        if (componentReference.isPromotionOverride()) {
                            CompositeReference compositeReference = (CompositeReference)implReference;
                            List<ComponentReference> promotedReferences =
                                ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference);
                            for (ComponentReference promotedReference : promotedReferences) {
                                ReferenceConfigurationUtil.reconcileReferenceBindings(
                                        componentReference, promotedReference, assemblyFactory, endpointFactory, monitor);
View Full Code Here

     */
    public void build(Composite composite, Definitions definitions, Monitor monitor) throws CompositeBuilderException {
   
        // Process composite references declared in this composite
        for (Reference reference : composite.getReferences()) {
            CompositeReference compositeReference = (CompositeReference)reference;

            // If the composite reference is a promotion override, override the
            // configuration of the promoted reference. 
            //FIXME: Policy configuration or wiring of domain-level composite references
            // doesn't cause a promotion override, unless the composite reference has
            // additional bindings.  Do we need to detect this and force an override?
            if (compositeReference.isPromotionOverride()) {
                List<ComponentReference> promotedReferences =
                    ReferenceConfigurationUtil.getPromotedComponentReferences(compositeReference);
                for (ComponentReference promotedReference : promotedReferences) {
                    ReferenceConfigurationUtil.reconcileReferenceBindings(
                            compositeReference, promotedReference, assemblyFactory, endpointFactory, monitor);
                    if (compositeReference.getInterfaceContract() != null && // can be null in unit tests
                        compositeReference.getInterfaceContract().getCallbackInterface() != null) {
                        SCABinding scaCallbackBinding = promotedReference.getCallbackBinding(SCABinding.class);
                        if (promotedReference.getCallback() != null) {
                            promotedReference.getCallback().getBindings().clear();
                        } else {
                            promotedReference.setCallback(assemblyFactory.createCallback());
                        }
                        if (scaCallbackBinding != null) {
                            promotedReference.getCallback().getBindings().add(scaCallbackBinding);
                        }
                        if (compositeReference.getCallback() != null) {
                            promotedReference.getCallback().getBindings().addAll(compositeReference.getCallback()
                                .getBindings());
                        }
                    }
                }
            }
View Full Code Here

                if (componentReference.getTargets().isEmpty()) {

                    // No warning if the reference is promoted out of the current composite
                    boolean promoted = false;
                    for (Reference reference : composite.getReferences()) {
                        CompositeReference compositeReference = (CompositeReference)reference;
                        if (compositeReference.getPromotedReferences().contains(componentReference)) {
                            promoted = true;
                            break;
                        }
                    }
                    if (!promoted && !componentReference.isCallback()) {
View Full Code Here

        // Process nested composites recursively
        configureNestedCompositeReferences(composite);

        // Process top level composite references
        for (Reference reference : composite.getReferences()) {
            CompositeReference compositeReference = (CompositeReference)reference;

            // Get the next lower level promoted reference
            List<ComponentReference> promotedRefs = compositeReference.getPromotedReferences();
            if (!promotedRefs.isEmpty()) {
                if (promotedRefs.size() == 1) {
                    ComponentReference promotedReference = promotedRefs.get(0);

                    // Set the bindings using the top level bindings to override the lower level bindings
                    if (bindingsSpecifiedManually(compositeReference.getBindings())) {
                        compositeReference.setPromotionOverride(true);
                    } else if (bindingsSpecifiedManually(promotedReference.getBindings()) ) {
                        compositeReference.getBindings().clear();
                        for (Binding binding : promotedReference.getBindings()) {
                            try {
                                compositeReference.getBindings().add((Binding)binding.clone());
                            } catch (CloneNotSupportedException ex) {
                                // this binding can't be used in the promoted reference
                            }
                        }
                    }
                    if (compositeReference.getInterfaceContract() != null &&
                        compositeReference.getInterfaceContract().getCallbackInterface() != null) {
                        if (compositeReference.getCallback() != null &&
                            bindingsSpecifiedManually(compositeReference.getCallback().getBindings())) {
                            compositeReference.setPromotionOverride(true);
                        } else if (promotedReference.getCallback() != null &&
                                   bindingsSpecifiedManually(promotedReference.getCallback().getBindings())) {
                            if (compositeReference.getCallback() != null) {
                                compositeReference.getCallback().getBindings().clear();
                            } else {
                                compositeReference.setCallback(assemblyFactory.createCallback());
                            }
                            for (Binding binding : promotedReference.getCallback().getBindings()) {
                                try {
                                    compositeReference.getCallback().getBindings().add((Binding)binding.clone());
                                } catch (CloneNotSupportedException ex) {
                                    // this binding can't be used in the promoted reference
                                }
                            }
                        }
                    }
                } else {
                    // This composite reference promotes multiple component references.
                    // Because the component reference bindings can all be different, we don't
                    // copy any of them up to this composite reference, which will therefore always
                    // have its own binding, even if it's only the default SCA binding.
                    if (bindingsSpecifiedManually(compositeReference.getBindings()) ||
                        (compositeReference.getCallback() != null &&
                         bindingsSpecifiedManually(compositeReference.getCallback().getBindings()))) {
                        compositeReference.setPromotionOverride(true);
                    }
                }
            }
        }
    }
View Full Code Here

TOP

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

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.