Package org.apache.tuscany.sca.assembly

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


    }

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


    @Test
    @Ignore // broken in 2.0 bring up
    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://docs.oasis-open.org/ns/opencsa/sca/200903\" xmlns:ns1=\"http://docs.oasis-open.org/ns/opencsa/sca/200903\"><service name=\"CalculatorService\"><binding.sca /><interface.java interface=\"calculator.CalculatorService\" /></service><reference name=\"addService\"><binding.sca /><interface.java interface=\"calculator.AddService\" /></reference></componentType>",
                 bos.toString());
View Full Code Here

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

            //throw new ContributionResolveException("Could not locate OSGi bundle " +
            //impl.getBundleSymbolicName());
            return;
        }

        ComponentType componentType = assemblyFactory.createComponentType();
        componentType.setURI("OSGI-INF/sca/bundle.componentType");
        componentType.setUnresolved(true);
        componentType = resolver.resolveModel(ComponentType.class, componentType);
        if (componentType.isUnresolved()) {
            // Try to derive it from the service descriptions
            if (!deriveFromServiceDescriptions(impl, resolver)) {
                error("MissingComponentTypeFile", impl, componentType.getURI());
            }
            //throw new ContributionResolveException("missing .componentType side file " + ctURI);
            return;
        } else {
            mergeFromComponentType(impl, componentType, resolver);
View Full Code Here

        // FIXME: How to find the RFC 119 service descriptions in the contribution and
        // derive the SCA component type from them?
        ServiceDescriptions descriptions = serviceDescriptionsFactory.createServiceDescriptions();
        descriptions = resolver.resolveModel(ServiceDescriptions.class, descriptions);
        if (descriptions != null && !descriptions.isEmpty()) {
            ComponentType ct = assemblyFactory.createComponentType();
            int index = 0;
            for (ServiceDescription ds : descriptions) {
                for (String i : ds.getInterfaces()) {
                    Class<?> cls = getJavaClass(resolver, i);
                    JavaInterface javaInterface;
                    try {
                        javaInterface = javaInterfaceFactory.createJavaInterface(cls);
                    } catch (InvalidInterfaceException e) {
                        throw new ContributionResolveException(e);
                    }
                    Reference reference = assemblyFactory.createReference();
                    JavaInterfaceContract contract = javaInterfaceFactory.createJavaInterfaceContract();
                    contract.setInterface(javaInterface);
                    reference.setInterfaceContract(contract);
                    String refName = (String)ds.getProperties().get(OSGiProperty.SCA_REFERENCE);
                    if (refName == null) {
                        refName = "ref" + (index++);
                    }
                    reference.setName(refName);
                    reference.setUnresolved(false);
                    ct.getReferences().add(reference);
                }
            }
            mergeFromComponentType(impl, ct, resolver);
            return true;
        }
View Full Code Here

        Composite composite = (Composite)staxProcessor.read(reader);
        assertNotNull(composite);

        is = getClass().getClassLoader().getResourceAsStream("OSGI-INF/sca/bundle.componentType");
        reader = inputFactory.createXMLStreamReader(is);
        ComponentType componentType = (ComponentType)staxProcessor.read(reader);

        assertEquals(1, componentType.getServices().size());
        Object prop1 = componentType.getServices().get(0).getExtensions().get(0);
        assertTrue(prop1 instanceof OSGiProperty);
        OSGiProperty osgiProp1 = (OSGiProperty)prop1;
        assertEquals("1", osgiProp1.getValue());
        assertEquals("prop1", osgiProp1.getName());

        assertEquals(4, componentType.getReferences().size());
        Object prop2 = componentType.getReferences().get(0).getExtensions().get(1);
        assertTrue(prop2 instanceof OSGiProperty);
        OSGiProperty osgiProp2 = (OSGiProperty)prop2;
        assertEquals("ABC", osgiProp2.getValue());
        assertEquals("prop2", osgiProp2.getName());
View Full Code Here

        if (resolved != null) {

            if (unresolved instanceof OSGiImplementationImpl && !(resolved instanceof OSGiImplementationImpl)) {

                OSGiImplementationImpl impl = ((OSGiImplementationImpl)unresolved);
                ComponentType componentType = (ComponentType)resolved;

                List<Property> properties = componentType.getProperties();
                for (Property property : properties) {
                    impl.getProperties().add(property);
                }
                impl.setUnresolved(false);
                return unresolved;
View Full Code Here

                                  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

     * @param resolver
     * @param impl
     */
    private void mergeComponentType(ModelResolver resolver, JavaImplementation impl) {
        // FIXME: Need to clarify how to merge
        ComponentType componentType = getComponentType(resolver, impl);
        if (componentType != null && !componentType.isUnresolved()) {
            Map<String, Reference> refMap = new HashMap<String, Reference>();
            for (Reference ref : impl.getReferences()) {
                refMap.put(ref.getName(), ref);
            }
            for (Reference reference : componentType.getReferences()) {
                refMap.put(reference.getName(), reference);
            }
            impl.getReferences().clear();
            impl.getReferences().addAll(refMap.values());

            // Try to match references by type
            Map<String, JavaElementImpl> refMembers = impl.getReferenceMembers();
            for (Reference ref : impl.getReferences()) {
                if (ref.getInterfaceContract() != null) {
                    Interface i = ref.getInterfaceContract().getInterface();
                    if (i instanceof JavaInterface) {
                        Class<?> type = ((JavaInterface)i).getJavaClass();
                        if (!refMembers.containsKey(ref.getName())) {
                            JavaElementImpl e = getMemeber(impl, ref.getName(), type);
                            if (e != null) {
                                refMembers.put(ref.getName(), e);
                            }
                        }
                    }
                }
            }

            Map<String, Service> serviceMap = new HashMap<String, Service>();
            for (Service svc : impl.getServices()) {
                serviceMap.put(svc.getName(), svc);
            }
            for (Service service : componentType.getServices()) {
                serviceMap.put(service.getName(), service);
            }
            impl.getServices().clear();
            impl.getServices().addAll(serviceMap.values());

            Map<String, Property> propMap = new HashMap<String, Property>();
            for (Property prop : impl.getProperties()) {
                propMap.put(prop.getName(), prop);
            }
            for (Property property : componentType.getProperties()) {
                propMap.put(property.getName(), property);
            }
            impl.getProperties().clear();
            impl.getProperties().addAll(propMap.values());

            if (componentType.getConstrainingType() != null) {
                impl.setConstrainingType(componentType.getConstrainingType());
            }
        }
    }
View Full Code Here

    }

    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

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.