Package org.apache.tuscany.sca.assembly

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


    public List<Property> getProperties() {
        return properties;
    }
   
    public Property getProperty(String name){
        Property property = null;
       
        for (Property tmp : getProperties()){
            if (tmp.getName().equals(name)){
                property = tmp;
                break;
View Full Code Here


        assertEquals(calcComponentReference.getRequiredIntents().get(0).getName(),
                     new QName("http://test", "confidentiality"));
        assertEquals(calcComponentReference.getPolicySets().get(0).getName(), new QName("http://test", "SecureReliablePolicy"));
        // TODO test operations

        Property property = calcComponent.getProperties().get(0);
        assertEquals(property.getName(), "round");
        Document doc = (Document) property.getValue();
        Element element = doc.getDocumentElement();
        String value = element.getTextContent();
        assertEquals(value, "true");
        assertEquals(property.getXSDType(), new QName("http://www.w3.org/2001/XMLSchema", "boolean"));
        assertEquals(property.isMany(), false);

        CompositeReference calcCompositeReference = (CompositeReference)composite.getReferences().get(0);
        assertEquals(calcCompositeReference.getName(), "MultiplyService");
        assertTrue(calcCompositeReference.getPromotedReferences().get(0).isUnresolved());
        assertEquals(calcCompositeReference.getPromotedReferences().get(0).getName(),
View Full Code Here

            } else if (uri.startsWith(SCA_PROPERTY_JAVA_PREFIX)) {
                String propertyName = prefix;
                String className = uri.substring(SCA_PROPERTY_JAVA_PREFIX.length());
                Class<?> clazz = resolveClass(resolver, className);
                QName xmlType = JavaXMLMapper.getXMLType(clazz);
                Property theProperty = createProperty(xmlType, propertyName);
                xqueryImplementation.getProperties().add(theProperty);
            } else if (uri.startsWith(SCA_PROPERTY_XML_PREFIX)) {
                String propertyName = prefix;
                String namespaceAndLocalname = uri.substring(SCA_PROPERTY_XML_PREFIX.length());
                int localNameDelimiterPostition = namespaceAndLocalname.lastIndexOf(':');
                String localName = null;
                String namespace = null;
                if (localNameDelimiterPostition < 0) {
                    localName = namespaceAndLocalname;
                    namespace = "";
                } else {
                    namespace = namespaceAndLocalname.substring(0, localNameDelimiterPostition);
                    localName = namespaceAndLocalname.substring(localNameDelimiterPostition + 1);
                }
                QName xmlType = new QName(namespace, localName);
                Property theProperty = createProperty(xmlType, propertyName);
                xqueryImplementation.getProperties().add(theProperty);
            }
        }
    }
View Full Code Here

        return service;
    } // end method createService

    protected Property createProperty(QName type, String name) {

        Property property = assemblyFactory.createProperty();
        property.setName(name);
        property.setXSDType(type);

        property.setMany(false);
        return property;

    }
View Full Code Here

    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);
                       
                    } else if (Constants.CALLBACK_QNAME.equals(name)) {

                        // Read a <callback>
                        callback = assemblyFactory.createCallback();
                        contract.setCallback(callback);
                        policyProcessor.readPolicies(callback, reader);

                    } else if (OPERATION.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

    public Component read(XMLStreamReader reader)
            throws ContributionReadException, XMLStreamException {
        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;

        // Read the component scdl

        while (reader.hasNext()) {
            int event = reader.getEventType();
            switch (event) {
            case START_ELEMENT:
                QName itemName = reader.getName();
                if (!itemName.getNamespaceURI().equals(SCA10_NS))
                    name = new QName(SCA10_NS, itemName.getLocalPart());
                else
                    name = itemName;

                if (SERVICE_QNAME.equals(name)) {
                    if (component != null) {

                        // Read a <component><service>
                        componentService = assemblyFactory
                                .createComponentService();
                        contract = componentService;
                        componentService.setName(getString(reader, NAME));
                        component.getServices().add(componentService);
                        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));
                        component.getReferences().add(componentReference);
                        policyProcessor.readPolicies(contract, reader);
                    }

                } else if (PROPERTY_QNAME.equals(name)) {
                    if (component != null) {

                        // Read a <component><property>
                        componentProperty = assemblyFactory
                                .createComponentProperty();
                        property = componentProperty;
                        componentProperty.setSource(getString(reader, SOURCE));
                        componentProperty.setFile(getString(reader, FILE));
                        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 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));
                    }
                    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);

                    composite.getWires().add(wire);
                    policyProcessor.readPolicies(wire, reader);

                } else if (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 = assemblyFactory.createOperation();
                    operation.setName(getString(reader, NAME));
                    operation.setUnresolved(true);
                    if (callback != null) {
                        policyProcessor.readPolicies(callback, operation,
                                reader);
                    } else {
                        policyProcessor.readPolicies(contract, operation,
                                reader);
                    }
                } else if (IMPLEMENTATION_COMPOSITE_QNAME.equals(name)) {

                    // Read an implementation.composite
                    Composite implementation = assemblyFactory
                            .createComposite();
                    implementation.setName(getQName(reader, NAME));
                    implementation.setUnresolved(true);
                    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)) {
                                    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) {
                            // <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)) {
                                        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) {

                            // <component><implementation>
                            if (component != null) {
                                component
                                        .setImplementation((Implementation) extension);
                            } else {
                                if (name.getNamespaceURI().equals(SCA10_NS)) {
                                    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

            while(scanner.hasNextLine()) {
                String line = scanner.nextLine();
                if(line.contains(WEB_PROPERTY_ANNOTATION)) {
                  //process the next line, as it has the property info
                  if (scanner.hasNextLine()) {
                    Property property = processPropertyScript(scanner.nextLine());
                    if (property != null) {
                      widgetImplementation.getProperties().add(property);
                    }
                  }
                 
View Full Code Here

     *   
     * @param scriptContent
     * @return
     */
    private Property processPropertyScript(String scriptContent) {
      Property property = null;
        String propertyName = null;
       
        String tokens[] = scriptContent.split("=");
        tokens = tokens[0].split(" ");
        propertyName = tokens[tokens.length -1];
       
        if(propertyName != null) {
            property = assemblyFactory.createProperty();
            property.setName(propertyName);    
        }
       
        return property;
    }
View Full Code Here

     * @return
     */
    ComponentType createComponentType() {
        ComponentType ctype = factory.createComponentType();

        Property p = factory.createProperty();
        p.setName("currency");
        p.setValue("USD");
        p.setMustSupply(true);
        p.setXSDType(new QName("", ""));
        ctype.getProperties().add(p);

        Reference ref1 = factory.createReference();
        ref1.setName("accountDataService");
        ref1.setInterfaceContract(new TestInterfaceContract(factory));
View Full Code Here

                    source = source + "/";
                    index = source.length() - 1;
                }
                if (source.charAt(0) == '$') {
                    String name = source.substring(1, index);
                    Property compositeProp = compositeProperties.get(name);
                    if (compositeProp == null) {
                        throw new CompositeBuilderException("The 'source' cannot be resolved to a composite property: " + source);
                    }

                    Document compositePropDefValues = (Document)compositeProp.getValue();

                    // FIXME: How to deal with namespaces?
                    Document node = evaluate(compositePropDefValues, aProperty.getSourceXPathExpression());

                    if (node != null) {
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.