Package org.apache.tuscany.sca.assembly

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


     * Returns a constrainingType attribute.
     * @param componentType
     * @return
     */
    protected XAttr writeConstrainingType(ComponentType componentType) {
        ConstrainingType constrainingType = componentType.getConstrainingType();
        if (constrainingType != null)
            return new XAttr(Constants.CONSTRAINING_TYPE, constrainingType.getName());
        else
            return null;
    }
View Full Code Here


            urlStream = connection.getInputStream();
            XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
            reader.nextTag();
           
            // Read the constrainingType model
            ConstrainingType constrainingType = (ConstrainingType)extensionProcessor.read(reader);

            // For debugging purposes, write it back to XML
//            if (constrainingType != null) {
//                try {
//                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
View Full Code Here

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

    public void addModel(Object resolved) {
        ConstrainingType composite = (ConstrainingType)resolved;
        map.put(composite.getName(), composite);
    }
View Full Code Here

   
    public <T> T resolveModel(Class<T> modelClass, T unresolved) {
       
        // Lookup a definition for the given namespace
        QName qname = ((ConstrainingType)unresolved).getName();
        ConstrainingType resolved = (ConstrainingType) map.get(qname);
        if (resolved != null) {
            return modelClass.cast(resolved);
        }
       
        // No definition found, delegate the resolution to the imports
        for (Import import_ : this.contribution.getImports()) {
            if (import_ instanceof NamespaceImport) {
                NamespaceImport namespaceImport = (NamespaceImport)import_;
                if (namespaceImport.getNamespace().equals(qname.getNamespaceURI())) {
                   
                    // Delegate the resolution to the import resolver
                    resolved = namespaceImport.getModelResolver().resolveModel(ConstrainingType.class, (ConstrainingType)unresolved);
                    if (!resolved.isUnresolved()) {
                        return modelClass.cast(resolved);
                    }
                }
            }
        }
View Full Code Here

     * @return
     */
    protected ConstrainingType readConstrainingType(XMLStreamReader reader) {
        QName constrainingTypeName = getQName(reader, Constants.CONSTRAINING_TYPE);
        if (constrainingTypeName != null) {
            ConstrainingType constrainingType = assemblyFactory.createConstrainingType();
            constrainingType.setName(constrainingTypeName);
            constrainingType.setUnresolved(true);
            return constrainingType;
        } else {
            return null;
        }
    }
View Full Code Here

     * Returns a constrainingType attribute.
     * @param componentType
     * @return
     */
    protected XAttr writeConstrainingType(ComponentType componentType) {
        ConstrainingType constrainingType = componentType.getConstrainingType();
        if (constrainingType != null)
            return new XAttr(Constants.CONSTRAINING_TYPE, constrainingType.getName());
        else
            return null;
    }
View Full Code Here

                                     Monitor monitor) {
        super(modelFactories, extensionProcessor, monitor);
    }
   
    public ConstrainingType read(XMLStreamReader reader) throws ContributionReadException {
        ConstrainingType constrainingType = null;
        AbstractService abstractService = null;
        AbstractReference abstractReference = null;
        AbstractProperty abstractProperty = null;
        AbstractContract abstractContract = null;
        QName name = null;
       
        try {
            // Read the constrainingType document
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
   
                    case START_ELEMENT:
                        name = reader.getName();
                       
                        // Read a <constrainingType>
                        if (Constants.CONSTRAINING_TYPE_QNAME.equals(name)) {
                            constrainingType = assemblyFactory.createConstrainingType();
                            constrainingType.setName(new QName(getString(reader, TARGET_NAMESPACE), getString(reader, NAME)));
                            policyProcessor.readPolicies(constrainingType, reader);
   
                        } else if (Constants.SERVICE_QNAME.equals(name)) {
                           
                            // Read a <service>
                            abstractService = assemblyFactory.createAbstractService();
                            abstractContract = abstractService;
                            abstractService.setName(getString(reader, Constants.NAME));
                            constrainingType.getServices().add(abstractService);
                            policyProcessor.readPolicies(abstractService, reader);
   
                        } else if (Constants.REFERENCE_QNAME.equals(name)) {
                           
                            // Read a <reference>
                            abstractReference = assemblyFactory.createAbstractReference();
                            abstractContract = abstractReference;
                            abstractReference.setName(getString(reader, Constants.NAME));
                            readMultiplicity(abstractReference, reader);
                            constrainingType.getReferences().add(abstractReference);
                            policyProcessor.readPolicies(abstractReference, reader);
   
                        } else if (Constants.PROPERTY_QNAME.equals(name)) {
                           
                            // Read a <property>
                            abstractProperty = assemblyFactory.createAbstractProperty();
                            readAbstractProperty(abstractProperty, reader);
                           
                            // Read the property value
                            Document value = readPropertyValue(abstractProperty.getXSDElement(), abstractProperty.getXSDType(), reader);
                            abstractProperty.setValue(value);
                           
                            constrainingType.getProperties().add(abstractProperty);
                            policyProcessor.readPolicies(abstractProperty, reader);
                           
                        } else if (OPERATION_QNAME.equals(name)) {
   
                            // Read an <operation>
                            Operation operation = new OperationImpl();
                            operation.setName(getString(reader, NAME));
                            operation.setUnresolved(true);
                            policyProcessor.readPolicies(abstractContract, operation, reader);
                           
                        } else {
   
                            // Read an extension element
                            Object extension = extensionProcessor.read(reader);
                            if (extension instanceof InterfaceContract) {
                               
                                // <service><interface> and <reference><interface>
                                abstractContract.setInterfaceContract((InterfaceContract)extension);
                            } else {
   
                                // Add the extension element to the current element
                                if (abstractContract != null) {
                                    abstractContract.getExtensions().add(extension);
                                } else {
                                    constrainingType.getExtensions().add(extension);
                                }
                               
                            }
                        }
                        break;
View Full Code Here

    }

    public void resolve(Composite composite, ModelResolver resolver) throws ContributionResolveException {

        // Resolve constraining type
        ConstrainingType constrainingType = composite.getConstrainingType();
        if (constrainingType != null) {
            constrainingType = resolver.resolveModel(ConstrainingType.class, constrainingType);
            composite.setConstrainingType(constrainingType);
        }
View Full Code Here

    @Test
    public void testResolveConstrainingType() throws Exception {

        URL url = getClass().getResource("CalculatorComponent.constrainingType");
        URI uri = URI.create("CalculatorComponent.constrainingType");
        ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url);
        assertNotNull(constrainingType);
        resolver.addModel(constrainingType);

        url = getClass().getResource("TestAllCalculator.composite");
        uri = URI.create("TestAllCalculator.composite");
View Full Code Here

    @Test
    public void testResolveConstrainingType() throws Exception {

        URL url = getClass().getResource("CalculatorComponent.constrainingType");
        URI uri = URI.create("CalculatorComponent.constrainingType");
        ConstrainingType constrainingType = (ConstrainingType)documentProcessor.read(null, uri, url);
        assertNotNull(constrainingType);
        resolver.addModel(constrainingType);

        url = getClass().getResource("TestAllCalculator.composite");
        uri = URI.create("TestAllCalculator.composite");
View Full Code Here

TOP

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

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.