Package org.apache.tuscany.sca.contribution

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


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

        Contribution contrib = contributionFactory.createContribution();
        File contribDir = new File(fileName);       
        contrib.setLocation(contribDir.toURI().toURL().toString());
        contrib.setClassLoader(new ContributionClassLoader(contrib, null));
        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

   

    @Test
    public void testClassLoadingFromImportedContribution() throws ClassNotFoundException, MalformedURLException {
       
        Contribution contribA = createContribution("target/test-classes");
        Contribution contribB = createContribution("target");
        Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar");
        ArrayList<Contribution> exportContribList = new ArrayList<Contribution>();
        exportContribList.add(contribA);
        exportContribList.add(contribC);
       
        JavaImport import_ = javaImportExportFactory.createJavaImport();
        import_.setPackage(this.getClass().getPackage().getName());
        import_.setModelResolver(new JavaImportModelResolver(exportContribList, null));
        contribB.getImports().add(import_);
        import_ = javaImportExportFactory.createJavaImport();
        import_.setPackage("calculator");
        import_.setModelResolver(new JavaImportModelResolver(exportContribList, null));
        contribB.getImports().add(import_);
       
        JavaExport export = javaImportExportFactory.createJavaExport();
        export.setPackage(this.getClass().getPackage().getName());
        contribA.getExports().add(export);
        export = javaImportExportFactory.createJavaExport();
        export.setPackage("calculator");
        contribC.getExports().add(export);       
       
        // Load class from parent, class is also present in imported contribution. Class should
        // be loaded from parent
        Class<?> testClassB = contribB.getClassLoader().loadClass(this.getClass().getName());       
        Assert.assertNotNull(testClassB);
        Assert.assertSame(this.getClass(), testClassB);
       
        // Load class from parent, class is also present in parent. Class should be loaded
        // from parent.
        Class<?> testClassA = contribA.getClassLoader().loadClass(this.getClass().getName());       
        Assert.assertNotNull(testClassA);
        Assert.assertSame(this.getClass(), testClassA);
       
        // Imported class should be the same as the one loaded by the exporting contribution
        Assert.assertSame(testClassA, testClassB);
       
        // Load class from imported contribution, class is not present in parent
        Class<?> testClassB1 = contribB.getClassLoader().loadClass("calculator.AddService");
        Assert.assertNotNull(testClassB1);
       
        // Imported class should be the same as the one loaded by the exporting contribution
        Class<?> testClassC = contribC.getClassLoader().loadClass("calculator.AddService");
        Assert.assertNotNull(testClassC);       
        Assert.assertSame(testClassC, testClassB1);
       

        // Try to load class from package which is not explicitly imported - should throw ClassNotFoundException
View Full Code Here

    }

    @Test
    public void testResourceLoadingFromImportedContribution() throws ClassNotFoundException, MalformedURLException {
       
        Contribution contribA = createContribution("target/test-classes");
        Contribution contribB = createContribution("target");
        Contribution contribC = createContribution("target/test-classes/deployables/sample-calculator.jar");
       
        ArrayList<Contribution> exportContribList = new ArrayList<Contribution>();
        exportContribList.add(contribA);
        exportContribList.add(contribC);
       
        JavaImport import_ = javaImportExportFactory.createJavaImport();
        import_.setPackage(this.getClass().getPackage().getName());
        import_.setModelResolver(new JavaImportModelResolver(exportContribList, null));
        contribB.getImports().add(import_);
        JavaImport import1_ = javaImportExportFactory.createJavaImport();
        import1_.setPackage("calculator");
        import1_.setModelResolver(new JavaImportModelResolver(exportContribList, null));
        contribB.getImports().add(import1_);
       
        JavaExport export = javaImportExportFactory.createJavaExport();
        export.setPackage(this.getClass().getPackage().getName());
        contribA.getExports().add(export);
        JavaExport export1 = javaImportExportFactory.createJavaExport();
        export1.setPackage("calculator");
        contribC.getExports().add(export1);

       
        // Load resource from parent
        URL resB = contribB.getClassLoader().getResource("deployables/sample-calculator.jar");
        Assert.assertNotNull(resB);
View Full Code Here

    }
   
    public Workspace read(XMLStreamReader reader) throws ContributionReadException, XMLStreamException {
       
        Workspace workspace = null;
        Contribution contribution = null;
       
        // Read the workspace document
        while (reader.hasNext()) {
            int event = reader.getEventType();
            switch (event) {
                case START_ELEMENT:
                    QName name = reader.getName();

                    if (WORKSPACE_QNAME.equals(name)) {

                        // Read a <workspace>
                        workspace = workspaceFactory.createWorkspace();
                        workspace.setUnresolved(true);

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

                        // Read a <contribution>
                        contribution = contributionFactory.createContribution();
                        contribution.setURI(getString(reader, URI));
                        contribution.setLocation(getString(reader, LOCATION));
                        contribution.setUnresolved(true);
                        workspace.getContributions().add(contribution);
                    }
                    break;

                case END_ELEMENT:
View Full Code Here

    public void resolve(Workspace workspace, ModelResolver resolver) throws ContributionResolveException {
       
        // Resolve the contributions referenced by the workspace
        List<Contribution> contributions = workspace.getContributions();
        for (int i = 0, n = contributions.size(); i < n; i++) {
            Contribution contribution = contributions.get(i);
            Contribution resolved = resolver.resolveModel(Contribution.class, contribution);
            if (resolved != contribution) {
                contributions.set(i, resolved);
            }
        }
       
View Full Code Here

        url = url.substring(0, url.length()-8);
       
        // Contribute the SCA contribution
        TestModelResolver myResolver = new TestModelResolver(myClassLoader);
        ContributionService contributionService = domain.getContributionService();
        Contribution contribution = contributionService.contribute("http://test/contribution", new URL(url), myResolver, false);
        assertNotNull(contribution);
       
        // Decide which SCA composite I want to deploy
        Composite myComposite = myResolver.getComposite(new QName("http://test", "test"));
       
View Full Code Here

        url = url.substring(0, url.length()-8);
       
        // Contribute the SCA contribution
        TestModelResolver myResolver = new TestModelResolver(myClassLoader);
        ContributionService contributionService = domain.getContributionService();
        Contribution contribution = contributionService.contribute("http://test/contribution", new URL(url), myResolver, false);
        assertNotNull(contribution);
       
        // Decide which SCA composite I want to deploy
        Composite myComposite = myResolver.getComposite(new QName("http://test", "test"));
       
View Full Code Here

            if ( contributionURL != null ){
                logger.log(Level.INFO, "Domain management configured from " + contributionURL);
                          
                // add node composite to the management domain
                domainManagementContributionService = domainManagementRuntime.getContributionService();
                Contribution contribution = null;
                contribution = domainManagementContributionService.contribute(domainModel.getDomainURI(),
                                                                              contributionURL,
                                                                              false);
               
                //get the domain builder
                domainBuilder = domainManagementRuntime.getDomainBuilder();
               
               
                Composite composite = null;
                for (Artifact artifact: contribution.getArtifacts()) {
                    if (domainCompositeName.equals(artifact.getURI())) {
                        composite = (Composite)artifact.getModel();
                    }
                }
               
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.