Package org.apache.tuscany.sca.contribution

Examples of org.apache.tuscany.sca.contribution.ContributionMetadata


        installContribution(contribution, dependentContributionURIs, startDeployables);
        return uri;
    }

    private void mergeContributionMetaData(String metaDataURL, Contribution contribution) throws ValidationException {
        ContributionMetadata metaData;
        Monitor monitor = deployer.createMonitor();
        try {
            metaData = deployer.loadXMLDocument(IOHelper.getLocationAsURL(metaDataURL), monitor);
        } catch (Exception e) {
            throw new ValidationException(e);
        }
        monitor.analyzeProblems();
        contribution.getDeployables().addAll(metaData.getDeployables());
        contribution.getImports().addAll(metaData.getImports());
        contribution.getExports().addAll(metaData.getExports());
    }
View Full Code Here


            ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor());

            reader.nextTag();

            // Read the contribution model
            ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context);

            return contribution;

        } catch (XMLStreamException e) {
          ContributionReadException ex = new ContributionReadException(e);
View Full Code Here

    public Class<ContributionMetadata> getModelType() {
        return ContributionMetadata.class;
    }

    public ContributionMetadata read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException {
        ContributionMetadata contribution = null;
        QName name = null;

        try {
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
                    case START_ELEMENT:
                        name = reader.getName();

                        if (CONTRIBUTION_QNAME.equals(name)) {

                            // Read <contribution>
                            contribution = this.contributionFactory.createContributionMetadata();
                            contribution.setSpecVersion(SCA11_NS);
                            contribution.setUnresolved(true);
                            readExtendedAttributes(reader, contribution, attributeProcessor, assemblyFactory, context);

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

                            // Read <deployable>
                            QName compositeName = getQName(reader, "composite");
                            if (compositeName == null) {
                                error(context.getMonitor(), "AttributeCompositeMissing", reader);
                                //throw new ContributionReadException("Attribute 'composite' is missing");
                            } else {
                                if (contribution != null) {
                                    Composite composite = assemblyFactory.createComposite();
                                    composite.setName(compositeName);
                                    composite.setUnresolved(true);
                                    contribution.getDeployables().add(composite);
                                }
                            }
                        } else {

                            // Read an extension element
                            Object extension = extensionProcessor.read(reader, context);
                            if (extension != null && contribution != null) {
                                if (extension instanceof Import) {
                                    // The value of the @package attribute on the <import.java/> element MUST be
                                  // unique across all other <import.java/> elements within the contribution.
                                  if (extension instanceof JavaImport) {
                                    for (Import imports : contribution.getImports()) {
                                      if (imports instanceof JavaImport) {
                                        if (((JavaImport)extension).getPackage().equals(((JavaImport) imports).getPackage())) {
                                          error(context.getMonitor(), "DuplicateJavaImports", reader);
                                        }
                                      }
                                    }
                                  }
                                  contribution.getImports().add((Import)extension);
                                } else if (extension instanceof Export) {
                                  // The value of the @package attribute on the <export.java/> element MUST be
                                  // unique across all other <export.java/> elements within the contribution.
                                  if (extension instanceof JavaExport) {
                                    for (Export exports : contribution.getExports()) {
                                      if (exports instanceof JavaExport) {
                                        if (((JavaExport)extension).getPackage().equals(((JavaExport) exports).getPackage())) {
                                          error(context.getMonitor(), "DuplicateJavaExports", reader);
                                        }
                                      }
                                    }
                                  }
                                    contribution.getExports().add((Export)extension);
                                } else {
                                    contribution.getExtensions().add(extension);
                                }
                            }
                        }
                        break;
View Full Code Here

    public Class<ContributionMetadata> getModelType() {
        return ContributionMetadata.class;
    }

    public ContributionMetadata read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException {
        ContributionMetadata contribution = null;
        QName name = null;

        try {
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
                    case START_ELEMENT:
                        name = reader.getName();

                        if (CONTRIBUTION_QNAME.equals(name)) {

                            // Read <contribution>
                            contribution = this.contributionFactory.createContributionMetadata();
                            contribution.setSpecVersion(SCA11_NS);
                            contribution.setUnresolved(true);
                            readExtendedAttributes(reader, contribution, attributeProcessor, assemblyFactory, context);

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

                            // Read <deployable>
                            QName compositeName = getQName(reader, "composite");
                            if (compositeName == null) {
                                error(context.getMonitor(), "AttributeCompositeMissing", reader);
                                //throw new ContributionReadException("Attribute 'composite' is missing");
                            } else {
                                if (contribution != null) {
                                    Composite composite = assemblyFactory.createComposite();
                                    composite.setName(compositeName);
                                    composite.setUnresolved(true);
                                    contribution.getDeployables().add(composite);
                                }
                            }
                        } else {

                            // Read an extension element
                            Object extension = extensionProcessor.read(reader, context);
                            if (extension != null && contribution != null) {
                                if (extension instanceof Import) {
                                    // The value of the @package attribute on the <import.java/> element MUST be
                                  // unique across all other <import.java/> elements within the contribution.
                                  if (extension instanceof JavaImport) {
                                    for (Import imports : contribution.getImports()) {
                                      if (imports instanceof JavaImport) {
                                        if (((JavaImport)extension).getPackage().equals(((JavaImport) imports).getPackage())) {
                                          error(context.getMonitor(), "DuplicateJavaImports", reader);
                                        }
                                      }
                                    }
                                  }
                                  contribution.getImports().add((Import)extension);
                                } else if (extension instanceof Export) {
                                  // The value of the @package attribute on the <export.java/> element MUST be
                                  // unique across all other <export.java/> elements within the contribution.
                                  if (extension instanceof JavaExport) {
                                    for (Export exports : contribution.getExports()) {
                                      if (exports instanceof JavaExport) {
                                        if (((JavaExport)extension).getPackage().equals(((JavaExport) exports).getPackage())) {
                                          error(context.getMonitor(), "DuplicateJavaExports", reader);
                                        }
                                      }
                                    }
                                  }
                                    contribution.getExports().add((Export)extension);
                                } else {
                                    contribution.getExtensions().add(extension);
                                }
                            }
                        }
                        break;
View Full Code Here

    }

    @Test
    public void testRead() throws Exception {
        XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
        ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context);
        assertNotNull(contribution);
        assertEquals(2, contribution.getDeployables().size());
        assertEquals(1, contribution.getAttributeExtensions().size());
        assertEquals(1, contribution.getExtensions().size());
        reader.close();
    }
View Full Code Here

    }

    @Test
    public void testReadSpecVersion() throws Exception {
        XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
        ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context);
        assertNotNull(contribution);
        assertEquals(SCA11_NS, contribution.getSpecVersion());
        reader.close();
    }   
View Full Code Here

    }   

    @Test
    public void testWrite() throws Exception {
        XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(VALID_XML));
        ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context);

        validateContribution(contribution);

        //write the contribution metadata contents
        StringWriter stringWriter = new StringWriter();
View Full Code Here

            ValidatingXMLInputFactory.setMonitor(reader, context.getMonitor());

            reader.nextTag();

            // Read the contribution model
            ContributionMetadata contribution = (ContributionMetadata)staxProcessor.read(reader, context);

            return contribution;

        } catch (XMLStreamException e) {
          ContributionReadException ex = new ContributionReadException(e);
View Full Code Here

                            modelResolver.addModel(model, context);

                            // Merge contribution metadata into the contribution model
                            if (model instanceof ContributionMetadata) {
                                contributionMetadata = true;
                                ContributionMetadata c = (ContributionMetadata)model;
                                contribution.getImports().addAll(c.getImports());
                                contribution.getExports().addAll(c.getExports());
                                contribution.getDeployables().addAll(c.getDeployables());
                                contribution.getExtensions().addAll(c.getExtensions());
                                contribution.getAttributeExtensions().addAll(c.getAttributeExtensions());
                            }
                        }
                    } finally {
                        monitor.popContext();
                        context.setArtifact(oldArtifact);
View Full Code Here

        }
        if (logger.isLoggable(quietLogging? Level.FINE : Level.INFO)) logger.log(quietLogging? Level.FINE : Level.INFO, "uninstallContribution: " + contributionURI);
    }
   
    protected void mergeContributionMetaData(String metaDataURL, Contribution contribution) throws ValidationException {
        ContributionMetadata metaData;
        Monitor monitor = deployer.createMonitor();
        try {
            metaData = deployer.loadXMLDocument(IOHelper.getLocationAsURL(metaDataURL), monitor);
        } catch (Exception e) {
            throw new ValidationException(e);
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.contribution.ContributionMetadata

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.