Package org.apache.tuscany.sca.assembly

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


    }

    private ComponentType getComponentType(ModelResolver resolver, JavaImplementation impl) {
        String className = impl.getJavaClass().getName();
        String componentTypeURI = className.replace('.', '/') + ".componentType";
        ComponentType componentType = assemblyFactory.createComponentType();
        componentType.setUnresolved(true);
        componentType.setURI(componentTypeURI);
        componentType = resolver.resolveModel(ComponentType.class, componentType);
        if (!componentType.isUnresolved()) {
            return componentType;
        }
        return null;
    }
View Full Code Here


    public void testReadComponentType() throws Exception {
        ComponentTypeProcessor componentTypeReader = new ComponentTypeProcessor(assemblyFactory, policyFactory, staxProcessor);
        InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType");
        XMLStreamReader reader = inputFactory.createXMLStreamReader(is);
        ComponentType componentType = componentTypeReader.read(reader);
        assertNotNull(componentType);

        //new PrintUtil(System.out).print(componentType);
    }
View Full Code Here

        staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, outputFactory, null);
    }

    public void testReadWriteComponentType() throws Exception {
        InputStream is = getClass().getResourceAsStream("/CalculatorServiceImpl.componentType");
        ComponentType componentType = (ComponentType)staxProcessor.read(inputFactory.createXMLStreamReader(is));
        assertNotNull(componentType);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        staxProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos));
        assertEquals("<?xml version='1.0' encoding='UTF-8'?><componentType xmlns=\"http://www.osoa.org/xmlns/sca/1.0\" xmlns:ns1=\"http://www.osoa.org/xmlns/sca/1.0\"><service name=\"CalculatorService\"><binding.sca /></service><reference name=\"addService\"><binding.sca /></reference></componentType>",
                     bos.toString());
View Full Code Here

        super(modelFactories.getFactory(AssemblyFactory.class),
              modelFactories.getFactory(PolicyFactory.class), extensionProcessor, monitor);
    }
   
    public ComponentType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
        ComponentType componentType = null;
        Service service = null;
        Reference reference = null;
        Contract contract = null;
        Property property = null;
        Callback callback = null;
        QName name = null;
       
        // 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

    }
   
    @Test
    public void testReadWriteComponentType() throws Exception {
        InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType");
        ComponentType componentType = staxProcessor.read(is, ComponentType.class, context);
        staxProcessor.resolve(componentType, resolver, context);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        staxProcessor.write(componentType, bos, context);
    }
View Full Code Here

            throw new ContributionResolveException("Class could not be resolved: " + implementation.getPOJOName());
        }
        implementation.setPOJOClass(pojoClass);
       
        // Check to see if we have a .componentType file describing the POJO class
        ComponentType componentType = assemblyFactory.createComponentType();
        componentType.setUnresolved(true);
        componentType.setURI(implementation.getURI() + ".componentType");
        componentType = resolver.resolveModel(ComponentType.class, componentType);
        if (!componentType.isUnresolved()) {
           
            // We have a component type description, merge it into the POJO model
            implementation.getServices().addAll(componentType.getServices());
            implementation.getReferences().addAll(componentType.getReferences());
            implementation.getProperties().addAll(componentType.getProperties());
           
        } else {
           
            // We have no component type description, simply introspect the POJO and
            // create a single Service for it
View Full Code Here

        staxProcessors.addArtifactProcessor(wsdlProcessor);
    }

    public void testReadWriteComponentType() throws Exception {
        InputStream is = getClass().getResourceAsStream("CalculatorImpl.componentType");
        ComponentType componentType = staxProcessor.read(is, ComponentType.class);
        assertNotNull(componentType);
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        staxProcessor.write(componentType, bos);
    }
View Full Code Here

    public ComponentTypeProcessor(AssemblyFactory factory, PolicyFactory policyFactory, StAXArtifactProcessor extensionProcessor) {
        super(factory, policyFactory, extensionProcessor);
    }
   
    public ComponentType read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
        ComponentType componentType = null;
        Service service = null;
        Reference reference = null;
        Contract contract = null;
        Property property = null;
        Callback callback = null;
        QName name = null;
       
        // 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

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

    public void addModel(Object resolved, ProcessorContext context) {
        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, context);
                            if (!resolved.isUnresolved()) {
                                return modelClass.cast(resolved);
                            }
                        }
                    }
                }
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.