Examples of ModelResolver


Examples of org.apache.tuscany.sca.contribution.resolver.ModelResolver

        Contribution contribution = contributionFactory.createContribution();
        contribution.setURI(contributionURI.toString());
        if (contributionURL != null) {
            contribution.setLocation(contributionURL.toString());
        }
        ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories);
        contribution.setModelResolver(modelResolver);
        contribution.setUnresolved(true);

        Monitor monitor = context.getMonitor();
        monitor.pushContext("Contribution: " + contribution.getURI());

        Contribution old = context.setContribution(contribution);
        try {
            if (contributionURL != null) {
                // Create a contribution scanner
                ContributionScanner scanner = scanners.getContributionScanner(contributionURL.getProtocol());
                if (scanner == null) {
                    File file = toFile(contributionURL);
                    if (file != null && file.isDirectory()) {
                        scanner = new DirectoryContributionScanner(contributionFactory);
                    } else {
                        scanner = new JarContributionScanner(contributionFactory);
                    }
                }

                // Scan the contribution and list the artifacts contained in it
                boolean contributionMetadata = false;
                List<Artifact> artifacts = scanner.scan(contribution);
                for (Artifact artifact : artifacts) {
                    // Add the deployed artifact model to the contribution
                    modelResolver.addModel(artifact, context);

                    monitor.pushContext("Artifact: " + artifact.getURI());

                    Artifact oldArtifact = context.setArtifact(artifact);
                    try {
                        // Read each artifact
                        URL artifactLocationURL = null;
                        try {
                            artifactLocationURL = new URL(artifact.getLocation());
                        } catch (MalformedURLException e) {
                            //ignore
                        }

                        Object model =
                            artifactProcessor.read(contributionURL,
                                                   URI.create(artifact.getURI()),
                                                   artifactLocationURL,
                                                   context);
                        if (model != null) {
                            artifact.setModel(model);

                            // Add the loaded model to the model resolver
                            modelResolver.addModel(model, context);

                            // Merge contribution metadata into the contribution model
                            if (model instanceof ContributionMetadata) {
                                contributionMetadata = true;
                                ContributionMetadata c = (ContributionMetadata)model;
View Full Code Here

Examples of org.apache.tuscany.sca.contribution.resolver.ModelResolver

     * @throws ContributionResolveException
     */
    public void preResolve(Contribution contribution, ModelResolver resolver, ProcessorContext context)
        throws ContributionResolveException {
        // Resolve the contribution model itself
        ModelResolver contributionResolver = contribution.getModelResolver();
        contribution.setUnresolved(false);
        contributionResolver.addModel(contribution, context);

        // Resolve Exports
        resolveExports(contribution, contributionResolver, context);
        // Resolve Imports
        resolveImports(contribution, contributionResolver, context);
View Full Code Here

Examples of org.apache.tuscany.sca.contribution.resolver.ModelResolver

        try {
            monitor.pushContext("Contribution: " + contribution.getURI());

            if (!preResolved)
                preResolve(contribution, resolver, context);
            ModelResolver contributionResolver = contribution.getModelResolver();

            // Validate Java Exports: [JCI100007] A Java package that is specified on an export
            // element MUST be contained within the contribution containing the export element.
            for (Export export : contribution.getExports()) {
                if (export instanceof JavaExport) {
                    boolean available = false;
                    String packageName = ((JavaExport)export).getPackage();
                    for (Artifact artifact : contribution.getArtifacts()) {
                        if (packageName.equals(artifact.getURI().replace("/", ".")))
                            available = true;
                    }
                    if (!available)
                        throw new ContributionResolveException("[JCI100007] A Java package " + packageName
                            + " that is specified on an export "
                            + "element MUST be contained within the contribution containing the export element.");
                }
            }

            // Resolve all artifact models
            for (Artifact artifact : contribution.getArtifacts()) {
                Object model = artifact.getModel();
                if (model != null) {
                    Artifact oldArtifact = context.setArtifact(artifact);
                    try {
                        artifactProcessor.resolve(model, contributionResolver, context);
                    } catch (Throwable e) {
                        throw new ContributionResolveException(e);
                    } finally {
                        context.setArtifact(oldArtifact);
                    }
                }
            }

            // Resolve deployable composites
            List<Composite> deployables = contribution.getDeployables();
            Artifact oldArtifact = context.setArtifact(contribution);
            try {
                for (int i = 0, n = deployables.size(); i < n; i++) {
                    Composite deployable = deployables.get(i);
                    Composite resolved =
                        (Composite)contributionResolver.resolveModel(Composite.class, deployable, context);
                    if (resolved != deployable) {
                        deployables.set(i, resolved);
                    }
                } // end for
            } finally {
View Full Code Here

Examples of org.apache.tuscany.sca.contribution.resolver.ModelResolver

                     + "'/>";
        XMLStreamReader reader = getReader(xml);
        assertFalse(inited);
        ImportSDO importSDO = loader.read(reader);
        assertNotNull(importSDO);
        ModelResolver resolver = new TestModelResolver();
        resolver.addModel(new ClassReference(MockFactory.class));
        loader.resolve(importSDO, resolver);
        assertTrue(inited);
    }
View Full Code Here

Examples of org.apache.tuscany.sca.contribution.resolver.ModelResolver

     * @throws MalformedURLException
     */
    private void processReadPhase(Contribution contribution, List<URI> artifacts) throws ContributionException,
        MalformedURLException, XMLStreamException {

        ModelResolver modelResolver = contribution.getModelResolver();
        URL contributionURL = new URL(contribution.getLocation());
       
        List<URI> compositeUris = new ArrayList<URI>();
       
        Object model = null;
        for (URI anArtifactUri : artifacts) {
            if ( anArtifactUri.toString().endsWith(COMPOSITE_FILE_EXTN)) {
                compositeUris.add(anArtifactUri);
            } else {
                URL artifactURL = packageProcessor.getArtifactURL(new URL(contribution.getLocation()), anArtifactUri);

                // Add the deployed artifact model to the resolver
                Artifact artifact = this.contributionFactory.createArtifact();
                artifact.setURI(anArtifactUri.toString());
                artifact.setLocation(artifactURL.toString());
                contribution.getArtifacts().add(artifact);
                modelResolver.addModel(artifact);
               
                model = this.artifactProcessor.read(contributionURL, anArtifactUri, artifactURL);
               
                if (model != null) {
                    artifact.setModel(model);

                    // Add the loaded model to the model resolver
                    modelResolver.addModel(model);
                   
                    if ( isSCADefnsFile(anArtifactUri) ) {
                        scaDefinitionsSink.add(model);
                    }
                }
            }
        }
       
        for (URI anArtifactUri : compositeUris) {
            URL artifactURL = packageProcessor.getArtifactURL(new URL(contribution.getLocation()), anArtifactUri);

            // Add the deployed artifact model to the resolver
            Artifact artifact = this.contributionFactory.createArtifact();
            artifact.setURI(anArtifactUri.toString());
            artifact.setLocation(artifactURL.toString());
            contribution.getArtifacts().add(artifact);
            modelResolver.addModel(artifact);
           
            model = this.artifactProcessor.read(contributionURL, anArtifactUri, artifactURL);
            if (model != null) {
                artifact.setModel(model);
                // Add the loaded model to the model resolver
                modelResolver.addModel(model);
            }
        }
    }
View Full Code Here

Examples of org.apache.tuscany.sca.contribution.resolver.ModelResolver

        //TODO No XMLSchema validation for definitions.xml for now
        // as the XSD for it is not quite right yet
        SCADefinitionsDocumentProcessor definitionsDocumentProcessor =
            new SCADefinitionsDocumentProcessor(staxProcessors, staxProcessor, inputFactory, policyFactory);
        documentProcessors.addArtifactProcessor(definitionsDocumentProcessor);
        ModelResolver domainModelResolver = definitionsDocumentProcessor.getSCADefinitionsResolver();

        // Create Model Resolver extension point
        ModelResolverExtensionPoint modelResolvers = registry.getExtensionPoint(ModelResolverExtensionPoint.class);

        // Create contribution package processor extension point
View Full Code Here

Examples of org.apache.tuscany.sca.contribution.resolver.ModelResolver

    public void contributionAdded(ContributionRepository repository, Contribution contribution) {
       
        // If the contribution does not contain sca-contribution.xml metadata
        // (for example it's an existing JAR developed before SCA existed)
        // export all its Java packages
        ModelResolver modelResolver = contribution.getModelResolver();
       
        // Look for META-INF/sca-contribution.xml
        Artifact artifact = contributionFactory.createArtifact();
        artifact.setURI(Contribution.SCA_CONTRIBUTION_META);
        artifact = modelResolver.resolveModel(Artifact.class, artifact);
        if (artifact.getLocation() == null) {

            // Look for META-INF/sca-contribution-generated.xml
            artifact.setURI(Contribution.SCA_CONTRIBUTION_GENERATED_META);
            artifact = modelResolver.resolveModel(Artifact.class, artifact);
            if (artifact.getLocation() == null) {
               
                // No contribution metadata file was found, default to export all the
                // Java packages found in the contribution
                Set<String> packages = new HashSet<String>();
View Full Code Here

Examples of org.apache.tuscany.sca.contribution.resolver.ModelResolver

       
        // Create contribution model
        Contribution contribution = contributionFactory.createContribution();
        contribution.setURI(contributionURI.toString());
        contribution.setLocation(contributionURL.toString());
        ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories);
        contribution.setModelResolver(modelResolver);
        contribution.setUnresolved(true);

        // Create a contribution scanner
        ContributionScanner scanner;
        if ("file".equals(contributionURL.getProtocol()) && new File(contributionURL.getFile()).isDirectory()) {
            scanner = new DirectoryContributionScanner();
        } else {
            scanner = new JarContributionScanner();
        }
       
        // Scan the contribution and list the artifacts contained in it
        List<Artifact> artifacts = contribution.getArtifacts();
        boolean contributionMetadata = false;
        for (String artifactURI: scanner.getArtifacts(contributionURL)) {
            URL artifactURL = scanner.getArtifactURL(contributionURL, artifactURI);

            // Add the deployed artifact model to the contribution
            Artifact artifact = this.contributionFactory.createArtifact();
            artifact.setURI(artifactURI);
            artifact.setLocation(artifactURL.toString());
            artifacts.add(artifact);
            modelResolver.addModel(artifact);
           
            // Read each artifact
            Object model = artifactProcessor.read(contributionURL, URI.create(artifactURI), artifactURL);
            if (model != null) {
                artifact.setModel(model);

                // Add the loaded model to the model resolver
                modelResolver.addModel(model);

                // Merge contribution metadata into the contribution model
                if (model instanceof Contribution) {
                    contributionMetadata = true;
                    Contribution c = (Contribution)model;
View Full Code Here

Examples of org.apache.tuscany.sca.contribution.resolver.ModelResolver

    }
   
    public void resolve(Contribution contribution, ModelResolver resolver) throws ContributionResolveException {
       
        // Resolve all artifact models
        ModelResolver contributionResolver = contribution.getModelResolver();
        for (Artifact artifact : contribution.getArtifacts()) {
            Object model = artifact.getModel();
            if (model != null) {
                try {
                   artifactProcessor.resolve(model, contributionResolver);
View Full Code Here

Examples of org.apache.tuscany.sca.contribution.resolver.ModelResolver

       
        // Create contribution model
        Contribution contribution = contributionFactory.createContribution();
        contribution.setURI(contributionURI.toString());
        contribution.setLocation(contributionURL.toString());
        ModelResolver modelResolver = new ExtensibleModelResolver(contribution, modelResolvers, modelFactories);
        contribution.setModelResolver(modelResolver);
        contribution.setUnresolved(true);

        // Create a contribution scanner
        ContributionScanner scanner;
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.