Package org.apache.tuscany.sca.assembly

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


                                  Monitor monitor) {
        super(modelFactories, extensionProcessor, monitor);
    }
   
    public ComponentType read(XMLStreamReader reader) throws ContributionReadException {
        ComponentType componentType = null;
        Service service = null;
        Reference reference = null;
        Contract contract = null;
        Property property = null;
        Callback callback = null;
        QName name = null;
       
        try {
            // Read the componentType document
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
                    case START_ELEMENT:
                        name = reader.getName();
   
                        if (Constants.COMPONENT_TYPE_QNAME.equals(name)) {
   
                            // Read a <componentType>
                            componentType = assemblyFactory.createComponentType();
                            componentType.setConstrainingType(readConstrainingType(reader));
   
                        } else if (Constants.SERVICE_QNAME.equals(name)) {
   
                            // Read a <service>
                            service = assemblyFactory.createService();
                            contract = service;
                            service.setName(getString(reader, Constants.NAME));
                            componentType.getServices().add(service);
                            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);
                            policyProcessor.readPolicies(property, reader);
                           
                            // Read the property value
                            Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
                            property.setValue(value);
                           
                            componentType.getProperties().add(property);
                           
                        } else if (Constants.IMPLEMENTATION_QNAME.equals(name)) {
                           
                            // Read an <implementation> element
                            policyProcessor.readPolicies(componentType, reader);
View Full Code Here


                int d = uri.lastIndexOf('.');
                if (d != -1) {
                    uri = uri.substring(0, d) + ".componentType";
                   
                    // Resolve the component type
                    ComponentType componentType = assemblyFactory.createComponentType();
                    componentType.setURI(uri);
                    componentType.setUnresolved(true);
                   
                    componentType = resolver.resolveModel(ComponentType.class, componentType);
                    if (componentType != null && !componentType.isUnresolved()) {
                       
                        // We found a component type, merge it into the implementation model
                        implementation.getServices().addAll(componentType.getServices());
                        implementation.getReferences().addAll(componentType.getReferences());
                        implementation.getProperties().addAll(componentType.getProperties());
                        implementation.setConstrainingType(componentType.getConstrainingType());
                       
                        if (implementation instanceof PolicySubject &&
                                componentType instanceof PolicySubject ) {
                            PolicySubject policiedImpl = (PolicySubject)implementation;
                            PolicySubject policiedCompType = (PolicySubject)componentType;
View Full Code Here

            urlStream = connection.getInputStream();
            XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
            reader.nextTag();
           
            // Reader the componentType model
            ComponentType componentType = (ComponentType)extensionProcessor.read(reader);
            if (componentType != null) {
                componentType.setURI(uri.toString());
            }

            // For debugging purposes, write it back to XML
//            if (componentType != null) {
//                try {
View Full Code Here

    public ComponentTypeModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) {
      this.contribution = contribution;
    }

    public void addModel(Object resolved) {
        ComponentType componentType = (ComponentType)resolved;
        map.put(componentType.getURI(), componentType);
    }
View Full Code Here

        if (uri == null) {
          return (T)unresolved;
        }
       
        //lookup the componentType
        ComponentType resolved = (ComponentType) map.get(uri);
        if (resolved != null) {
            return modelClass.cast(resolved);
        }
       
        //If not found, delegate the resolution to the imports (in this case based on the java imports)
        //compute the package name from the componentType URI
        if (unresolved instanceof ComponentType) {
            //FIXME The core assembly model now depends on java imports to
            // resolve componentTypes of all kinds, this is not right at all!!!
            int s = uri.lastIndexOf('/');
            if (s != -1) {
                String packageName = uri.substring(0, uri.lastIndexOf("/"));
                for (Import import_ : this.contribution.getImports()) {
                    if (import_ instanceof JavaImport) {
                      JavaImport javaImport = (JavaImport)import_;
                      //check the import location against the computed package name from the componentType URI
                        if (javaImport.getPackage().equals(packageName)) {
                            // Delegate the resolution to the import resolver
                            resolved = javaImport.getModelResolver().resolveModel(ComponentType.class, (ComponentType)unresolved);
                            if (!resolved.isUnresolved()) {
                                return modelClass.cast(resolved);
                            }
                        }
                    }
                }
View Full Code Here

     * @throws ContributionResolveException
     */
    private void generateComponentType(BPELImplementation impl) throws ContributionResolveException {

        // Create a ComponentType and mark it unresolved
        ComponentType componentType = assemblyFactory.createComponentType();
        componentType.setUnresolved(true);
        impl.setComponentType(componentType);

        // Each partner link in the process represents either a service or a
        // reference
        // - or both, in the sense of involving a callback
        BPELProcessDefinition theProcess = impl.getProcessDefinition();
        List<BPELPartnerLinkElement> partnerLinks = theProcess.getPartnerLinks();

        for (BPELPartnerLinkElement pLink : partnerLinks) {

            // check that the partner link has been designated as service or
            // reference in SCA terms
            if (pLink.isSCATyped()) {
                String scaName = pLink.getSCAName();
                if (pLink.querySCAType().equals("reference")) {
                    componentType.getReferences().add(generateReference(scaName, pLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces()));
                } else {
                    componentType.getServices().add(generateService(scaName, pLink.getMyRolePortType(), pLink.getPartnerRolePortType(), theProcess.getInterfaces()));
                } // end if
            } // end if
        } // end for

    } // end getComponentType
View Full Code Here

     * @param impl
     */
    private void mergeComponentType(ModelResolver resolver, BPELImplementation impl) {

        // Load the component type from a component type file, if any
        ComponentType componentType = getComponentType(resolver, impl);
        if (componentType != null && !componentType.isUnresolved()) {

            // References...
            Map<String, Reference> refMap = new HashMap<String, Reference>();
            for (Reference reference : componentType.getReferences()) {
                refMap.put(reference.getName(), reference);
            } // end for

            // For the present, overwrite anything arising from the component
            // type sidefile if
            // equivalent services are defined in the implementation.
            // TODO - a more careful merge must be done, using the
            // implementation introspection data
            // as the master but adding any additional and non-conflicting
            // information from the
            // sidefile
            for (Reference ref : impl.getReferences()) {
                refMap.put(ref.getName(), ref);
            } // end for

            impl.getReferences().clear();
            impl.getReferences().addAll(refMap.values());

            // Services.....
            Map<String, Service> serviceMap = new HashMap<String, Service>();
            for (Service service : componentType.getServices()) {
                serviceMap.put(service.getName(), service);
            } // end for

            // For the present, overwrite anything arising from the component
            // type sidefile if
            // equivalent services are defined in the implementation.
            // TODO - a more careful merge must be done, using the
            // implementation introspection data
            // as the master but adding any additional and non-conflicting
            // information from the
            // sidefile
            for (Service svc : impl.getServices()) {
                serviceMap.put(svc.getName(), svc);
            } // end for

            impl.getServices().clear();
            impl.getServices().addAll(serviceMap.values());

            // Properties
            Map<String, Property> propMap = new HashMap<String, Property>();
            for (Property property : componentType.getProperties()) {
                propMap.put(property.getName(), property);
            } // end for

            // A simple overwrite of any equivalent properties from the
            // component type sidefile
View Full Code Here

    private ComponentType getComponentType(ModelResolver resolver, BPELImplementation impl) {
        String bpelProcessURI = impl.getProcessDefinition().getURI().toString();
       
        // Get the component type definition contained in the componentType file, if any
        String componentTypeURI = bpelProcessURI.replace(".bpel", ".componentType");
        ComponentType componentType = assemblyFactory.createComponentType();
        componentType.setUnresolved(true);
        componentType.setURI(componentTypeURI);
        componentType = resolver.resolveModel(ComponentType.class, componentType);
        if (!componentType.isUnresolved()) {
            return componentType;
        }
        return null;
    } // end getComponentType
View Full Code Here

            PROCESS_ELEMENT_END );
   
    // <active/> element
    stream.println( ACTIVE_ELEMENT );
   
    ComponentType componentType = implementation.getComponentType();
    List<Service> theServices = componentType.getServices();
    // Loop over the <provide/> elements - one per service
    for ( Service service : theServices ) {
      String serviceName = service.getName();
      // Provide element...
      stream.println( PROVIDE_ELEMENT_START + serviceName + PROVIDE_ELEMENT_END );
      // Child service element...
      stream.println( SERVICE_ELEMENT_START + serviceName +
          SERVICE_ELEMENT_PORT + serviceName + SERVICE_ELEMENT_END );
      stream.println( PROVIDE_ENDELEMENT );
    } // end for
   
    // Loop over the <invoke/> elements - one per reference
    List<Reference> theReferences = componentType.getReferences();
    for ( Reference reference : theReferences ) {
      String referenceName = reference.getName();
      stream.println( INVOKE_ELEMENT_START + referenceName + INVOKE_ELEMENT_END );
      // Child service element...
      stream.println( SERVICE_ELEMENT_START + referenceName +
View Full Code Here

    @Test
    public void testReadComponentType() throws Exception {
        InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType");
        XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
        ComponentType componentType = (ComponentType)staxProcessor.read(reader);
        assertNotNull(componentType);
    }
View Full Code Here

TOP

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

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.