Package org.apache.tuscany.sca.contribution

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


   
    public ContributionModelResolver(Contribution contribution, FactoryExtensionPoint modelFactories) {
    }

    public void addModel(Object resolved, ProcessorContext context) {
        Contribution contribution = (Contribution)resolved;
        map.put(contribution.getURI(), contribution);
    }
View Full Code Here


    public <T> T resolveModel(Class<T> modelClass, T unresolved, ProcessorContext context) {
       
        // Lookup a contribution for the given URI
        String uri = ((Contribution)unresolved).getURI();
        if (uri != null) {
            Contribution resolved = (Contribution) map.get(uri);
            if (resolved != null) {
                return modelClass.cast(resolved);
            }
            return unresolved;
        } else {
           
            // If no URI was specified, just return the first contribution
            if (!map.isEmpty()) {
                Contribution resolved = map.values().iterator().next();
                return modelClass.cast(resolved);
            } else {
                return unresolved;
            }
        }
View Full Code Here

            }
            URL contributionURL = uri.toURL();

            // Load the contribution
            logger.log(quietLogging? Level.FINE : Level.INFO, "Loading contribution: " + contributionURL);
            Contribution contribution = deployer.loadContribution(contributionURI, contributionURL, context.getMonitor());
            contributions.add(contribution);

            boolean attached = false;
            for (DeploymentComposite dc : contrib.getDeploymentComposites()) {
                if (dc.getContent() != null) {
                    Reader xml = new StringReader(dc.getContent());
                    attached = attachDeploymentComposite(contribution, xml, null, attached, context);
                } else if (dc.getLocation() != null) {
                    URI dcURI = createURI(dc.getLocation());
                    if (!dcURI.isAbsolute()) {
                        Composite composite = null;
                        // The location is pointing to an artifact within the contribution
                        for (Artifact a : contribution.getArtifacts()) {
                            if (dcURI.toString().equals(a.getURI())) {
                                composite = (Composite)a.getModel();
                                if (!attached) {
                                    contribution.getDeployables().clear();
                                    attached = true;
                                }
                                contribution.getDeployables().add(composite);
                                break;
                            }
                        }
                        if (composite == null) {
                            // Not found
                            throw new ServiceRuntimeException("Deployment composite " + dcURI
                                + " cannot be found within contribution "
                                + contribution.getLocation());
                        }
                    } else {
                        URL url = dcURI.toURL();
                        InputStream is = openStream(url);
                        Reader xml = new InputStreamReader(is, "UTF-8");
View Full Code Here

            if(import_ instanceof JavaImport) {
                JavaImport javaImport = (JavaImport) import_;
               
                //Find a matching contribution
                if(javaImport.getLocation() != null) {
                    Contribution targetContribution = repository.getContribution(javaImport.getLocation());
                    if (targetContribution != null) {
                   
                        // Find a matching contribution export
                        for (Export export: targetContribution.getExports()) {
                            if (export instanceof JavaExport) {
                                JavaExport javaExport = (JavaExport)export;
                                if (javaImport.getPackage().equals(javaExport.getPackage())) {
                                    javaImport.setModelResolver(javaExport.getModelResolver());
                                   
View Full Code Here

        ContributionService contributionService = domain.getContributionService();

        ModelResolver helloResolver = new ModelResolverImpl(cl);
        File helloContrib = new File("./target/classes/");
        URL helloURL = helloContrib.toURL();
        Contribution consumerContribution =
            contributionService.contribute("http://import-export/hello", helloURL, helloResolver, false);
        Composite consumerComposite = consumerContribution.getDeployables().get(0);
        domain.getDomainComposite().getIncludes().add(consumerComposite);
        domain.buildComposite(consumerComposite);

        // Start Components from my composite
        domain.getCompositeActivator().activate(consumerComposite);
View Full Code Here

    public void tearDown() throws Exception {
    }
   
    private Contribution createContribution(String fileName) throws MalformedURLException {

        Contribution contrib = contribFactory.createContribution();
        File contribDir = new File(fileName);       
        contrib.setLocation(contribDir.toURL().toString());
       
        return contrib;
    }
View Full Code Here

   
  
    @Test
    public void testClassLoadingFromContribution() throws ClassNotFoundException, MalformedURLException {
       
        Contribution contribA = createContribution("target/test-classes");
        Contribution contribB = createContribution("target");
        Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar");
       
        // Class present in contribution, also in parent. Class is loaded from parent
        Class<?> testClassA = contribA.getClassLoader().loadClass(this.getClass().getName());       
        Assert.assertNotNull(testClassA);
        Assert.assertSame(this.getClass(), testClassA);
       
        // Class not present in contribution, but present in parent classloader
        Class<?> testClassB = contribB.getClassLoader().loadClass(this.getClass().getName());
        Assert.assertNotNull(testClassB);
        Assert.assertSame(this.getClass(), testClassB);
       
        // Class present in contribution, but not in parent
        Class<?> testClassC = contribC.getClassLoader().loadClass("calculator.AddService");       
        Assert.assertNotNull(testClassC);
       
        // Class not present in contribution or in parent
        try {
            contribA.getClassLoader().loadClass("NonExistent");
View Full Code Here

    }
   
    @Test
    public void testResourceLoadingFromContribution() throws ClassNotFoundException, MalformedURLException {
       
        Contribution contribA = createContribution("target/test-classes");
        Contribution contribB = createContribution("target");
        Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar");
       
        // Resource present in contribution, and in parent
        URL resA = contribA.getClassLoader().getResource("deployables/sample-calculator.jar");
        Assert.assertNotNull(resA);
       
        // Resource not present in contribution, but present in parent classloader
        URL resB = contribB.getClassLoader().getResource("deployables/sample-calculator.jar");
        Assert.assertNotNull(resB);
       
        // Resource present in contribution, but not in parent
        URL resC = contribC.getClassLoader().getResource("calculator/AddService.class");
        Assert.assertNotNull(resC);       
       
        // Load Java class as resource from parent
        String classResName = this.getClass().getName().replaceAll("\\.", "/") + ".class";
        URL classResA = contribA.getClassLoader().getResource(classResName);
View Full Code Here

        // Read the sample store contribution
        URI artifactURI = URI.create(sourceURI);
        //URL contributionURL = FileHelper.toFile(new URL(sourceURL)).toURI().toURL();
        URL artifactURL = new File(sourceURL).toURI().toURL();
        URL contributionURL = new File(compositeURL).toURI().toURL();
        Contribution storeContribution = contributionProcessor.read(contributionURL, artifactURI, artifactURL);               
        workspace.getContributions().add(storeContribution);
       
        // Build the contribution dependencies
        Map<Contribution, List<Contribution>> contributionDependencies = new HashMap<Contribution, List<Contribution>>();
        Set<Contribution> resolved = new HashSet<Contribution>();
View Full Code Here

        // Read the sample store contribution
        URI artifactURI = URI.create(sourceURI);
        //URL contributionURL = FileHelper.toFile(new URL(sourceURL)).toURI().toURL();
        URL artifactURL = new File(sourceURL).toURI().toURL();
        URL contributionURL = new File(compositeURL).toURI().toURL();
        Contribution storeContribution = contributionProcessor.read(contributionURL, artifactURI, artifactURL);               
        workspace.getContributions().add(storeContribution);     
    }
View Full Code Here

TOP

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

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.