Package org.apache.tuscany.sca.assembly

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


        }

        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

    public void testBarAnnotationProcessedFirst() throws Exception {
        JavaImplementation type = javaImplementationFactory.createJavaImplementation();
        Constructor<Foo> ctor = Foo.class.getConstructor(String.class, String.class);
        JavaConstructorImpl<Foo> definition = new JavaConstructorImpl<Foo>(ctor);
        type.setConstructor(definition);
        Property property = factory.createProperty();
        property.setName("myBar");
        definition.getParameters()[0].setName("myBar");
        type.getProperties().add(property);
        visitEnd(Foo.class, type);
        assertEquals(2, type.getProperties().size());
    }
View Full Code Here

        visitEnd(Foo.class, type);

        // now simulate process the bar impl
        JavaConstructorImpl<?> definition = type.getConstructor();
        definition.getParameters()[0].setName("myBar");
        Property property = factory.createProperty();
        property.setName("myBar");
        type.getProperties().add(property);

        assertEquals(2, type.getProperties().size());
        assertEquals("foo", definition.getParameters()[1].getName());
    }
View Full Code Here

        JavaConstructorImpl<Foo2> definition = new JavaConstructorImpl<Foo2>(ctor);
        type.setConstructor(definition);
        // insert placeholder for first param, which would be done by a
        // processor
        definition.getParameters()[0].setName("");
        Property property = factory.createProperty();
        // Hack to add a property member
        JavaElementImpl element = new JavaElementImpl("myBar", String.class, null);
        type.getPropertyMembers().put("myBar", element);
        property.setName("myBar");
        definition.getParameters()[1].setName("myBar");
        type.getProperties().add(property);
        visitEnd(Foo2.class, type);
        assertEquals("baz", definition.getParameters()[0].getName());
        assertEquals(2, type.getProperties().size());
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

                continue;
            }
            String propertyName = envEntry.name;
            propertyName = propertyName.replace("/", "_");
            String value = envEntry.value;
            Property property = assemblyFactory.createComponentProperty();
            property.setName(propertyName);
            property.setXSDType(ALLOWED_ENV_ENTRY_TYPES.get(type));
            property.setValue(value);
            componentType.getProperties().add(property);
        }
       
        return componentType;
    }
View Full Code Here

                continue;
            }
            String propertyName = envEntry.name;
            propertyName = propertyName.replace("/", "_");
            String value = envEntry.value;
            Property property = assemblyFactory.createComponentProperty();
            property.setName(propertyName);
            property.setXSDType(ALLOWED_ENV_ENTRY_TYPES.get(type));
            property.setValue(value);
            componentType.getProperties().add(property);
        }
        return componentType;
    }
View Full Code Here

    public Composite read(XMLStreamReader reader) throws ContributionReadException {
        Composite composite = null;
        Composite include = null;
        Component component = null;
        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;

        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.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
   
                            if(!isSet(reader, TARGET_NAMESPACE)){
                                // spec says that a composite must have a namespace
                                warning("NoCompositeNamespace", composite, composite.getName().toString());  
                            }
                           
                            if(isSet(reader, AUTOWIRE)) {
                                composite.setAutowire(getBoolean(reader, AUTOWIRE));
                            }
                           
                            //handle extension attributes
                            this.readExtendedAttributes(reader, composite);
   
                            composite.setLocal(getBoolean(reader, LOCAL));
                            composite.setConstrainingType(readConstrainingType(reader));
                            policyProcessor.readPolicies(composite, reader);
   
                        } else if (INCLUDE_QNAME.equals(name)) {
   
                            // Read an <include>
                            include = assemblyFactory.createComposite();
                            include.setName(getQName(reader, NAME));
                            include.setURI(getString(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, componentService);
   
                                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 = getString(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, compositeService);
   
                                composite.getServices().add(compositeService);
                                policyProcessor.readPolicies(contract, reader);
                            }
   
                        } 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));
                                }
                                readTargets(componentReference, reader);
                                componentReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                               
                                //handle extension attributes
                                this.readExtendedAttributes(reader, componentReference);
   
                                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 = reader.getAttributeValue(null, Constants.PROMOTE);
                                if (promote != null) {
                                    for (StringTokenizer tokens = new StringTokenizer(promote); tokens.hasMoreTokens();) {
                                        ComponentReference promotedReference =
                                            assemblyFactory.createComponentReference();
                                        promotedReference.setUnresolved(true);
                                        promotedReference.setName(tokens.nextToken());
                                        compositeReference.getPromotedReferences().add(promotedReference);
                                    }
                                }
                                compositeReference.setWiredByImpl(getBoolean(reader, WIRED_BY_IMPL));
                               
                                //handle extension attributes
                                this.readExtendedAttributes(reader, compositeReference);
   
                                composite.getReferences().add(compositeReference);                           
                                policyProcessor.readPolicies(contract, reader);
                            }
   
                        } else if (PROPERTY_QNAME.equals(name)) {
                            if (component != null) {
   
                                // Read a <component><property>
                                componentProperty = assemblyFactory.createComponentProperty();
                                property = componentProperty;
                                String source = getString(reader, SOURCE);
                                if(source!=null) {
                                    source = source.trim();
                                }
                                componentProperty.setSource(source);
                                if (source != null) {
                                    // $<name>/...
                                    if (source.charAt(0) == '$') {
                                        int index = source.indexOf('/');
                                        if (index == -1) {
                                            // Tolerating $prop
                                            source = source + "/";
                                            index = source.length() - 1;
                                        }
                                        source = source.substring(index + 1);
                                        if ("".equals(source)) {
                                            source = ".";
                                        }
                                    }
                                    XPath xpath = xPathFactory.newXPath();
                                    xpath.setNamespaceContext(reader.getNamespaceContext());
                                    try {
                                        componentProperty.setSourceXPathExpression(xpath.compile(source));
                                    } catch (XPathExpressionException e) {
                                      ContributionReadException ce = new ContributionReadException(e);
                                      error("ContributionReadException", xpath, ce);
                                        //throw ce;
                                    }
                                }
                                componentProperty.setFile(getString(reader, FILE));
                               
                                //handle extension attributes
                                this.readExtendedAttributes(reader, componentProperty);
   
                                policyProcessor.readPolicies(property, reader);
                                readAbstractProperty(componentProperty, reader);
                               
                                // Read the property value
                                Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
                                property.setValue(value);
                               
                                component.getProperties().add(componentProperty);
                            } else {
   
                                // Read a <composite><property>
                                property = assemblyFactory.createProperty();
                                policyProcessor.readPolicies(property, reader);
                                readAbstractProperty(property, reader);
                               
                                // Read the property value
                                Document value = readPropertyValue(property.getXSDElement(), property.getXSDType(), reader);
                                property.setValue(value);
                               
                                composite.getProperties().add(property);
                            }
                           
                            // TUSCANY-1949
                            // If the property doesn't have a value, the END_ELEMENT event is read by the readPropertyValue
                            if (reader.getEventType() == END_ELEMENT && PROPERTY_QNAME.equals(reader.getName())) {
                                property = null;
                                componentProperty = null;
                            }
   
                        } else if (COMPONENT_QNAME.equals(name)) {
   
                            // Read a <component>
                            component = assemblyFactory.createComponent();
                            component.setName(getString(reader, NAME));
                            if (isSet(reader, AUTOWIRE)) {
                                component.setAutowire(getBoolean(reader, AUTOWIRE));
                            }
                            if (isSet(reader, URI)) {
                                component.setURI(getString(reader, URI));
                            }
                           
                            //handle extension attributes
                           this.readExtendedAttributes(reader, component);
                           
                            component.setConstrainingType(readConstrainingType(reader));
                            composite.getComponents().add(component);
                            policyProcessor.readPolicies(component, reader);
   
                        } else if (WIRE_QNAME.equals(name)) {
   
                            // Read a <wire>
                            wire = assemblyFactory.createWire();
                            ComponentReference source = assemblyFactory.createComponentReference();
                            source.setUnresolved(true);
                            source.setName(getString(reader, SOURCE));
                            wire.setSource(source);
   
                            ComponentService target = assemblyFactory.createComponentService();
                            target.setUnresolved(true);
                            target.setName(getString(reader, TARGET));
                            wire.setTarget(target);
   
                            //handle extension attributes
                            this.readExtendedAttributes(reader, wire);
   
                            composite.getWires().add(wire);
                            policyProcessor.readPolicies(wire, reader);
   
                        } else if (CALLBACK_QNAME.equals(name)) {
   
                            // Read a <callback>
                            callback = assemblyFactory.createCallback();
                            contract.setCallback(callback);
                           
                            //handle extension attributes
                            this.readExtendedAttributes(reader, callback);
                           
                            policyProcessor.readPolicies(callback, reader);
   
                        } else if (OPERATION_QNAME.equals(name)) {
   
                            // Read an <operation>
                            ConfiguredOperation operation = assemblyFactory.createConfiguredOperation();
                            operation.setName(getString(reader, NAME));
                            operation.setUnresolved(true);
                            if (callback != null) {
                                policyProcessor.readPolicies(operation, reader);
                            } else {
                                policyProcessor.readPolicies(operation, reader);
                            }
                           
                            OperationsConfigurator opConfigurator = null;
                            if ( compositeService != null ) {
                                opConfigurator = compositeService;
                            } else if ( componentService != null ) {
                                opConfigurator = componentService;
                            } else if ( compositeReference != null ) {
                                opConfigurator = compositeReference;
                            } else if ( componentReference != null ) {
                                opConfigurator = componentReference;
                            }
                           
                            opConfigurator.getConfiguredOperations().add(operation);
                        } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {
   
                            // Read an implementation.composite
                            Composite implementation = assemblyFactory.createComposite();
                            implementation.setName(getQName(reader, NAME));
                            implementation.setUnresolved(true);
                           
                            //handle extension attributes
                            this.readExtendedAttributes(reader, implementation);
   
                            component.setImplementation(implementation);
                            policyProcessor.readPolicies(implementation, reader);
                        } else {
   
                            // Read an extension element
                            Object extension = extensionProcessor.read(reader);
                            if (extension != null) {
                                if (extension instanceof InterfaceContract) {
   
                                    // <service><interface> and
                                    // <reference><interface>
                                    if (contract != null) {
                                        contract.setInterfaceContract((InterfaceContract)extension);
                                    } else {
                                        if (name.getNamespaceURI().equals(SCA10_NS)) {
                                          error("UnexpectedInterfaceElement", extension);
                                            //throw new ContributionReadException("Unexpected <interface> element found. It should appear inside a <service> or <reference> element");
                                        } else {
                                            composite.getExtensions().add(extension);
                                        }
                                    }
                                } else if (extension instanceof Binding) {
                                    if ( extension instanceof PolicySetAttachPoint ) {
                                        IntentAttachPointType bindingType = intentAttachPointTypeFactory.createBindingType();
                                        bindingType.setName(name);
                                        bindingType.setUnresolved(true);
                                        ((PolicySetAttachPoint)extension).setType(bindingType);
                                    }
                                    // <service><binding> and
                                    // <reference><binding>
                                    if (callback != null) {
                                        callback.getBindings().add((Binding)extension);
                                    } else {
                                        if (contract != null) {
                                            contract.getBindings().add((Binding)extension);
                                        } else {
                                            if (name.getNamespaceURI().equals(SCA10_NS)) {
                                              error("UnexpectedBindingElement", extension);
                                                //throw new ContributionReadException("Unexpected <binding> element found. It should appear inside a <service> or <reference> element");
                                            } else {
                                                composite.getExtensions().add(extension);
                                            }
                                        }
                                    }
   
                                } else if (extension instanceof Implementation) {
                                    if ( extension instanceof PolicySetAttachPoint ) {
                                        IntentAttachPointType implType = intentAttachPointTypeFactory.createImplementationType();
                                        implType.setName(name);
                                        implType.setUnresolved(true);
                                        ((PolicySetAttachPoint)extension).setType(implType);
                                    }
                                    // <component><implementation>
                                    if (component != null) {
                                        component.setImplementation((Implementation)extension);
                                    } else {
                                        if (name.getNamespaceURI().equals(SCA10_NS)) {
                                          error("UnexpectedImplementationElement", extension);
                                            //throw new ContributionReadException("Unexpected <implementation> element found. It should appear inside a <component> element");
                                        } else {
                                            composite.getExtensions().add(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 (component != null) {
                                        component.getExtensions().add(extension);
                                    } else {
                                        composite.getExtensions().add(extension);
                                    }
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.