Package org.apache.tuscany.sca.contribution.processor

Examples of org.apache.tuscany.sca.contribution.processor.ContributionReadException


               attachTo = PolicyXPathFunction.normalize(attachTo,getSCAPrefix(nsContext));
               XPathExpression expression = xpathHelper.compile(path, nsContext, attachTo);
               attachment.setAttachTo(attachTo);
               attachment.setAttachToXPathExpression(expression);
           } catch (XPathExpressionException e) {
               ContributionReadException ce = new ContributionReadException(e);
               error(monitor, "ContributionReadException", attachment, ce);             
           }
    }
   
  }
View Full Code Here


            ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context);

            return contribution;

        } catch (XMLStreamException e) {
          ContributionReadException ex = new ContributionReadException(e);
          error(context.getMonitor(), "XMLStreamException", inputFactory, ex);
          throw ex;
        } catch (IOException e) {
          ContributionReadException ex = new ContributionReadException(e);
          error(context.getMonitor(), "IOException", inputFactory, ex);
            throw ex;
        } finally {
            try {
                if (urlStream != null) {
View Full Code Here

                artifact.setURI(uri);
                artifact.setLocation(file.toURI().toURL().toString());

                artifacts.add(artifact);
            } catch (MalformedURLException e) {
                throw new ContributionReadException(e);
            }
        }

        contribution.getTypes().add(getContributionType());
        return artifacts;
View Full Code Here

        // [rfeng] There are cases that the folder contains symbolic links that point to the same physical directory
        Set<File> visited = new HashSet<File>();
        try {
            traverse(artifacts, directory, directory, visited);
        } catch (IOException e) {
            throw new ContributionReadException(e);
        }

        return artifacts;
    }
View Full Code Here

        URI uri = null;
        try {
            uri = new URI(contribution.getLocation());
            file = new File(uri);
        } catch (URISyntaxException e) {
            throw new ContributionReadException(e);
        } catch(IllegalArgumentException e) {
            // Hack for file:./a.txt or file:../a/c.wsdl
            return new File(uri.getPath());
        }
        if (!file.exists() || !file.isDirectory()) {
            throw new ContributionReadException(contribution.getLocation());
        }
        return file;
    }
View Full Code Here

            } finally {
                jar.close();
            }
        } catch (IOException e) {
            throw new ContributionReadException(e);
        }
    }
View Full Code Here

            } else {
                url = new URL("jar:" + contribution.getLocation() + "!/" + artifact);
            }
            return url;
        } catch (MalformedURLException e) {
            throw new ContributionReadException(e);
        }
    }
View Full Code Here

                                   
                                    try {
                                        componentProperty.setSourceXPathExpression(xpathHelper.compile(reader
                                            .getNamespaceContext(), xPath));
                                    } catch (XPathExpressionException e) {
                                        ContributionReadException ce = new ContributionReadException(e);
                                        error(monitor, "ContributionReadException", source, ce);
                                        //throw ce;
                                    }
                                }
                                componentProperty.setFile(getURIString(reader, FILE));

                                //handle extension attributes
                                this.readExtendedAttributes(reader,
                                                            name,
                                                            componentProperty,
                                                            extensionAttributeProcessor, context);

                                policyProcessor.readPolicies(property, reader);
                                readAbstractProperty(componentProperty, reader, context);

                                // Read the property value
                                Document value =
                                    readPropertyValue(property.getXSDElement(), property.getXSDType(), property
                                        .isMany(), reader, context);
                                property.setValue(value);

                                component.getProperties().add(componentProperty);
                            } else {

                                // Read a <composite><property>
                                property = assemblyFactory.createProperty();
                                policyProcessor.readPolicies(property, reader);
                                readAbstractProperty(property, reader, context);

                                // Read the property value
                                Document value =
                                    readPropertyValue(property.getXSDElement(), property.getXSDType(), property
                                        .isMany(), reader, context);
                                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(getURIString(reader, URI));
                            }

                            //handle extension attributes
                            this.readExtendedAttributes(reader, name, component, extensionAttributeProcessor, context);

                            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(getURIString(reader, SOURCE));
                            wire.setSource(source);

                            ComponentService target = assemblyFactory.createComponentService();
                            target.setUnresolved(true);
                            target.setName(getURIString(reader, TARGET));
                            wire.setTarget(target);

                            // Read @replace
                            String replace = reader.getAttributeValue(null, REPLACE);
                            if (replace != null) {
                                wire.setReplace(Boolean.parseBoolean(replace));
                            }

                            //handle extension attributes
                            this.readExtendedAttributes(reader, name, wire, extensionAttributeProcessor, context);

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

                        } else if (CALLBACK_QNAME.equals(name)) {

                            // Read a <callback>
                            callback = assemblyFactory.createCallback();
                            contract.setCallback(callback);
                            callback.setParentContract(contract);

                            //handle extension attributes
                            this.readExtendedAttributes(reader, name, callback, extensionAttributeProcessor, context);

                            policyProcessor.readPolicies(callback, reader);
                           
                            // set the parent model so that binding processing can
                            // detect it they're being read as part of a callback
                            context.setParentModel(callback);                           

                        } 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, name, implementation, extensionAttributeProcessor, context);

                            component.setImplementation(implementation);
                            policyProcessor.readPolicies(implementation, reader);
                        } else if (REQUIRES_QNAME.equals(name)) {
                            List<QName> intents = getQNames(reader, INTENTS);
                            for (QName i : intents) {
                                Intent intent = policyFactory.createIntent();
                                intent.setName(i);
                                if (composite != null) {
                                    composite.getRequiredIntents().add(intent);
                                } else if (component != null) {
                                    component.getRequiredIntents().add(intent);
                                } else if (contract != null) {
                                    contract.getRequiredIntents().add(intent);
                                } else if (callback != null) {
                                    callback.getRequiredIntents().add(intent);
                                }
                            }
                        } else if (POLICY_SET_ATTACHMENT_QNAME.equals(name)) {
                            QName ps = getQName(reader, NAME);
                            if (ps != null) {
                                PolicySet policySet = policyFactory.createPolicySet();
                                policySet.setName(ps);
                                if (composite != null) {
                                    composite.getPolicySets().add(policySet);
                                } else if (component != null) {
                                    component.getPolicySets().add(policySet);
                                } else if (contract != null) {
                                    contract.getPolicySets().add(policySet);
                                } else if (callback != null) {
                                    callback.getPolicySets().add(policySet);
                                }
                            }
                        } else if(EXTENSION_QNAME.equals(name)) {
                            // Handle <extension>
                            //ignore element as this is a wrapper for extensibility
                            break;
                        } else {

                            // Read an extension element
                            Object extension = extensionProcessor.read(reader, context);
                            if (extension != null) {
                                if (extension instanceof InterfaceContract) {

                                    // <service><interface> and
                                    // <reference><interface>
                                    if (contract != null) {
                                        contract.setInterfaceContract((InterfaceContract)extension);
                                    } else {
                                        if (name.getNamespaceURI().equals(SCA11_NS)) {
                                            error(monitor, "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 PolicySubject) {
                                        ExtensionType bindingType = intentAttachPointTypeFactory.createBindingType();
                                        bindingType.setType(name);
                                        bindingType.setUnresolved(true);
                                        ((PolicySubject)extension).setExtensionType(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(SCA11_NS)) {
                                                error(monitor, "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 PolicySubject) {
                                        ExtensionType implType =
                                            intentAttachPointTypeFactory.createImplementationType();
                                        implType.setType(name);
                                        implType.setUnresolved(true);
                                        ((PolicySubject)extension).setExtensionType(implType);
                                    }
                                    // <component><implementation>
                                    if (component != null) {
                                        component.setImplementation((Implementation)extension);
                                    } else {
                                        if (name.getNamespaceURI().equals(SCA11_NS)) {
                                            error(monitor, "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);
                                    }
                                }
                            }
                        }
                        break;

                    case XMLStreamConstants.CHARACTERS:
                        break;

                    case END_ELEMENT:
                        name = reader.getName();

                        // Clear current state when reading reaching end element
                        if (SERVICE_QNAME.equals(name)) {
                            componentService = null;
                            compositeService = null;
                            contract = null;
                        } else if (INCLUDE_QNAME.equals(name)) {
                            include = null;
                        } else if (REFERENCE_QNAME.equals(name)) {
                            componentReference = null;
                            compositeReference = null;
                            contract = null;
                        } else if (PROPERTY_QNAME.equals(name)) {
                            componentProperty = null;
                            property = null;
                        } else if (COMPONENT_QNAME.equals(name)) {
                            component = null;
                        } else if (WIRE_QNAME.equals(name)) {
                            wire = null;
                        } else if (CALLBACK_QNAME.equals(name)) {
                            callback = null;
                        }
                        break;
                }

                // Read the next element
                if (reader.hasNext()) {
                    reader.next();
                }
            }
        } catch (XMLStreamException e) {
            ContributionReadException ex = new ContributionReadException(e);
            error(monitor, "XMLStreamException", reader, ex);
        }

        return composite;
    }
View Full Code Here

     * @param url - the URL of the composite document
     * @return a Composite object built from the supplied Composite document
     */
    public Composite read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException {
      if( uri == null || url == null ) {
        throw new ContributionReadException("Request to read composite with uri or url NULL");
      } // end if
        InputStream scdlStream = null;
       
        try {
            scdlStream = IOHelper.openStream(url);
        } catch (IOException e) {
            ContributionReadException ce = new ContributionReadException("Exception reading " + uri, e);
            error(context.getMonitor(), "ContributionReadException", url, ce);
            throw ce;
        }
        return read(uri, url, scdlStream, context);
    }
View Full Code Here

            }

            return composite;
           
        } catch (XMLStreamException e) {
          ContributionReadException ce = new ContributionReadException("Exception reading " + uri, e);
          error(context.getMonitor(), "ContributionReadException", inputFactory, ce);
            throw ce;
        } finally {
            try {
                if (scdlStream != null) {
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.contribution.processor.ContributionReadException

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.