Package org.apache.tuscany.sca.assembly

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


    private void processProperties(List<?> props, Hashtable<String, Object> propsTable) {

        if (props != null) {
            for (Object p : props) {

                Property prop = (Property)p;
                Class javaType = SimpleTypeMapperImpl.getJavaType(prop.getXSDType());
                ObjectFactory<?> objFactory = propertyValueFactory.createValueFactory(prop, prop.getValue(), javaType);
                Object value = objFactory.getInstance();

                propsTable.put(prop.getName(), value);
            }
        }
    }
View Full Code Here


                                     Map<String, Property> properties,
                                     Map<String, ComponentProperty> componentProperties) {

        // Connect component properties to their properties
        for (ComponentProperty componentProperty : component.getProperties()) {
            Property property = properties.get(componentProperty.getName());
            if (property != null) {
                componentProperty.setProperty(property);
            } else {
                warning("PropertyNotFound", component, component.getName(), componentProperty.getName());
            }
        }

        // Create component properties for all properties
        if (component.getImplementation() != null) {
            for (Property property : component.getImplementation().getProperties()) {
                if (!componentProperties.containsKey(property.getName())) {
                    ComponentProperty componentProperty = assemblyFactory.createComponentProperty();
                    componentProperty.setName(property.getName());
                    componentProperty.setMany(property.isMany());
                    componentProperty.setXSDElement(property.getXSDElement());
                    componentProperty.setXSDType(property.getXSDType());
                    componentProperty.setProperty(property);
                    component.getProperties().add(componentProperty);
                }
            }
        }

        // Reconcile component properties and their properties
        for (ComponentProperty componentProperty : component.getProperties()) {
            Property property = componentProperty.getProperty();
            if (property != null) {

                // Check that a component property does not override the
                // mustSupply attribute
                if (!property.isMustSupply() && componentProperty.isMustSupply()) {
                    warning("PropertyMustSupplyIncompatible", component, component.getName(), componentProperty.getName());
                }

                // Default to the mustSupply attribute specified on the property
                if (!componentProperty.isMustSupply())
                    componentProperty.setMustSupply(property.isMustSupply());

                // Default to the value specified on the property
                if (componentProperty.getValue() == null) {
                    componentProperty.setValue(property.getValue());
                }
               
                // Override the property value for the composite
                if(component.getImplementation() instanceof Composite) {
                    property.setValue(componentProperty.getValue());
                }

                // Check that a value is supplied
                if (componentProperty.getValue() == null && property.isMustSupply()) {
                    warning("PropertyMustSupplyNull", component, component.getName(), componentProperty.getName());
                }

                // Check that a a component property does not override the
                // many attribute
                if (!property.isMany() && componentProperty.isMany()) {

                    warning("PropertyOverrideManyAttribute", component, component.getName(), componentProperty.getName());
                }

                // Default to the many attribute defined on the property
                componentProperty.setMany(property.isMany());

                // Default to the type and element defined on the property
                if (componentProperty.getXSDType() == null) {
                    componentProperty.setXSDType(property.getXSDType());
                }
                if (componentProperty.getXSDElement() == null) {
                    componentProperty.setXSDElement(property.getXSDElement());
                }

                // Check that a type or element are specified
                if (componentProperty.getXSDElement() == null && componentProperty.getXSDType() == null) {
                    warning("NoTypeForComponentProperty", component, component.getName(), componentProperty.getName());
View Full Code Here

    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);
                           
                        } else if (Constants.CALLBACK_QNAME.equals(name)) {
   
                            // Read a <callback>
                            callback = assemblyFactory.createCallback();
                            contract.setCallback(callback);
                            policyProcessor.readPolicies(callback, reader);
   
                        } else if (OPERATION_QNAME.equals(name)) {
   
                            // Read an <operation>
                            Operation operation = new OperationImpl();
                            operation.setName(getString(reader, NAME));
                            operation.setUnresolved(true);
                            if (callback != null) {
                                policyProcessor.readPolicies(callback, operation, reader);
                            } else {
                                policyProcessor.readPolicies(contract, operation, reader);
                            }
                        } else {
   
                            // Read an extension element
                            Object extension = extensionProcessor.read(reader);
                            if (extension != null) {
                                if (extension instanceof InterfaceContract) {
   
                                    // <service><interface> and <reference><interface>
                                    contract.setInterfaceContract((InterfaceContract)extension);
   
                                } else if (extension instanceof Binding) {
   
                                    // <service><binding> and <reference><binding>
                                    if (callback != null) {
                                        callback.getBindings().add((Binding)extension);
                                    } else {
                                        contract.getBindings().add((Binding)extension);
                                    }
                                } else {
                                   
                                    // Add the extension element to the current element
                                    if (callback != null) {
                                        callback.getExtensions().add(extension);
                                    } else if (contract != null) {
                                        contract.getExtensions().add(extension);
                                    } else if (property != null) {
                                        property.getExtensions().add(extension);
                                    } else {
                                        if (componentType instanceof Extensible) {
                                            ((Extensible)componentType).getExtensions().add(extension);
                                        }
                                    }
View Full Code Here

        }

        removeProperty(prop, type);
       
        JavaElementImpl element = new JavaElementImpl(method, 0);
        Property property = createProperty(name, element);

        property.setMustSupply(annotation.required());
        type.getProperties().add(property);
        properties.put(name, element);
    }
View Full Code Here

            throw new DuplicatePropertyException(name);
        }

        if (prop == null) {
            JavaElementImpl element = new JavaElementImpl(field);
            Property property = createProperty(name, element);
            property.setMustSupply(annotation.required());
            type.getProperties().add(property);
            properties.put(name, element);
        }
    }
View Full Code Here

        throws IntrospectionException {
    }

    protected Property createProperty(String name, JavaElementImpl element) throws IntrospectionException {

        Property property = assemblyFactory.createProperty();
        property.setName(name);
        Class<?> baseType = JavaIntrospectionHelper.getBaseType(element.getType(), element.getGenericType());
        property.setXSDType(JavaXMLMapper.getXMLType(baseType));

        Class<?> javaType = element.getType();
        if (javaType.isArray() || Collection.class.isAssignableFrom(javaType)) {
            property.setMany(true);
        }
        return property;
    }
View Full Code Here

        }
        return null;
    }

    protected Property createProperty(Property property) {
        Property newProperty;
        try {
            newProperty = (Property)property.clone();
        } catch (CloneNotSupportedException e) {
            throw new AssertionError(e); // should not ever happen
        }
View Full Code Here

        }
        return null;
    }

    protected Property createProperty(Property property) {
        Property newProperty;
        try {
            newProperty = (Property)property.clone();
        } catch (CloneNotSupportedException e) {
            throw new AssertionError(e); // should not ever happen
        }
View Full Code Here

        }
        return newReference;
    }

    protected Property createProperty(Property property) {
        Property newProperty;
        try {
            newProperty = (Property)property.clone();
        } catch (CloneNotSupportedException e) {
            throw new AssertionError(e); // should not ever happen
        }
View Full Code Here

    @Test
    public void testVisitMethod() throws Exception {
        Method method = Foo.class.getMethod("setBar", String.class);
        JavaImplementation type = javaImplementationFactory.createJavaImplementation();
        extension.visitMethod(method, type);
        Property prop = getProperty(type, "test");
        assertNotNull(prop);
    }
View Full Code Here

TOP

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

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.