Package org.apache.tuscany.sca.monitor

Examples of org.apache.tuscany.sca.monitor.Monitor


    @Test
    public void testRead() throws Exception {
        Deployer deployer = new DefaultDeployer();
        File file = new File("../../../samples/learning-more/binding-sca/calculator-contribution/target/sample-binding-sca-calculator-contribution.jar");
        URL url = file.toURI().toURL();
        Monitor monitor = deployer.createMonitor();
        Contribution contribution = deployer.loadContribution(url.toURI(), url, monitor);
        deployer.build(Arrays.asList(contribution), Arrays.asList(contribution), null, monitor);
       
        // Ferkle around in the contribution verifying it looks as expected
        Assert.assertNotNull(contribution);
View Full Code Here


        CompositeReference compositeReference = null;
        Contract contract = null;
        Wire wire = null;
        Callback callback = null;
        QName name = null;
        Monitor monitor = context.getMonitor();
        try {
            // Read the composite document
            while (reader.hasNext()) {
                int event = reader.getEventType();
                switch (event) {
View Full Code Here

        writeEndDocument(writer);
    }

    public void resolve(Composite composite, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {

        Monitor monitor = context.getMonitor();
        try {
            monitor.pushContext("Composite: " + composite.getName());

            // Resolve includes in the composite
            for (int i = 0, n = composite.getIncludes().size(); i < n; i++) {
                Composite include = composite.getIncludes().get(i);
                if (include != null) {
                    Composite resolved = resolver.resolveModel(Composite.class, include, context);
                    if (!resolved.isUnresolved()) {
                        if ((composite.isLocal() && resolved.isLocal()) || (!composite.isLocal() && !resolved.isLocal())) {
                            composite.getIncludes().set(i, resolved);
                        } else {
                            ContributionResolveException ce =
                                new ContributionResolveException("[ASM60041] Error: Composite " + composite.getName()
                                    + " can only include another composite with the identical @local attribute value");
                            error(monitor, "ContributionResolveException", include, ce);
                        }
                    } else {
                        ContributionResolveException ce =
                            new ContributionResolveException("[ASM60042] Error: Composite " + include.getName()
                                + " is not a valid composite within the domain");
                        error(monitor, "ContributionResolveException", include, ce);
                    }
                }
            }

            // Resolve extensions
            for (Object extension : composite.getExtensions()) {
                if (extension != null) {
                    extensionProcessor.resolve(extension, resolver, context);
                }
            }

            //Resolve composite services and references
            resolveContracts(composite, composite.getServices(), resolver, context);
            resolveContracts(composite, composite.getReferences(), resolver, context);
           
            for (Property property : composite.getProperties()){
                resolvePropertyType("composite " + composite.getName().toString(),
                                    property,
                                    context.getContribution(), context);
            }

            // Resolve component implementations, services and references
            for (Component component : composite.getComponents()) {

                //resolve component services and references
                resolveContracts(component, component.getServices(), resolver, context);
                resolveContracts(component, component.getReferences(), resolver, context);

                for (ComponentProperty componentProperty : component.getProperties()) {
                    // resolve a reference to a property file
                    if (componentProperty.getFile() != null) {
                        Artifact artifact = contributionFactory.createArtifact();
                        artifact.setURI(componentProperty.getFile());
                        artifact = resolver.resolveModel(Artifact.class, artifact, context);
                        if (artifact.getLocation() != null) {
                            componentProperty.setFile(artifact.getLocation());
                        }
                    }
                   
                    // resolve the reference to a complex property
                    resolvePropertyType("component " + component.getName(),
                                        componentProperty,
                                        context.getContribution(), context);
                }

                //resolve component implementation
                Implementation implementation = component.getImplementation();
                if (implementation != null) {
                    //now resolve the implementation so that even if there is a shared instance
                    //for this that is resolved, the specified intents and policysets are safe in the
                    //component and not lost

                  List<PolicySet> policySets = new ArrayList<PolicySet>(implementation.getPolicySets());                 
                  List<Intent> intents = new ArrayList<Intent>(implementation.getRequiredIntents());
                    implementation = resolveImplementation(implementation, resolver, context);

                    // If there are any policy sets on the implementation or component we have to
                    // ignore policy sets from the component type (policy spec 4.9)
                    if ( !policySets.isEmpty() || !component.getPolicySets().isEmpty() ) {                     
                      implementation.getPolicySets().clear();
                      implementation.getPolicySets().addAll(policySets);                     
                    }
                     
                    implementation.getRequiredIntents().addAll(intents);             

                    component.setImplementation(implementation);
                }

                //add model resolver to component
                if (component instanceof ResolverExtension) {
                    ((ResolverExtension)component).setModelResolver(resolver);
                }
            }

            // Add model resolver to promoted components
            for (Service service : composite.getServices()) {
                CompositeService compositeService = (CompositeService)service;
                Component promotedComponent = compositeService.getPromotedComponent();
                if (promotedComponent instanceof ResolverExtension) {
                    ((ResolverExtension)promotedComponent).setModelResolver(resolver);
                }
            } // end for

        } finally {
            // Pop context
            monitor.popContext();
        } // end try
    }
View Full Code Here

    public static void setUp() throws Exception {
        final DefaultExtensionPointRegistry ep = new DefaultExtensionPointRegistry();
        final ContributionFactory contribFactory = new DefaultContributionFactory();
        final Contribution contrib = contribFactory.createContribution();
        contrib.setLocation(ReadWriteTestCase.class.getProtectionDomain().getCodeSource().getLocation().toString());
        final Monitor mon = new DefaultMonitorFactory().createMonitor();
        ctx = new ProcessorContext(contrib, mon);
        xif = XMLInputFactory.newInstance();
        xof = XMLOutputFactory.newInstance();
        final StAXArtifactProcessorExtensionPoint xpep = new DefaultStAXArtifactProcessorExtensionPoint(ep);
        xproc = new ExtensibleStAXArtifactProcessor(xpep, xif, xof);
View Full Code Here

        systemDefinitions = definitionsFactory.createDefinitions();

        DefinitionsExtensionPoint definitionsExtensionPoint =
            registry.getExtensionPoint(DefinitionsExtensionPoint.class);
       
        Monitor monitor = context.getMonitor();
        monitor.pushContext("Extension points definitions");
        try {
            for (Definitions defs : definitionsExtensionPoint.getDefinitions()) {
                DefinitionsUtil.aggregate(defs, systemDefinitions, monitor);
            }
        } finally {
            monitor.popContext();
        }

        // create a system contribution to hold the definitions. The contribution
        // will be extended later with definitions from application contributions
        systemContribution = contributionFactory.createContribution();
View Full Code Here

        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 {
            // 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;
                            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);
                }                   
            }
           
            List<Artifact> contributionArtifacts = contribution.getArtifacts();
            contributionArtifacts.addAll(artifacts);
   
            // If no sca-contribution.xml file was provided then just consider
            // all composites in the contribution as deployables
            if (!contributionMetadata) {
                for (Artifact artifact: artifacts) {
                    if (artifact.getModel() instanceof Composite) {
                        contribution.getDeployables().add((Composite)artifact.getModel());
                    }
                }
   
                // Add default contribution import and export
                DefaultImport defaultImport = contributionFactory.createDefaultImport();
                defaultImport.setModelResolver(new DefaultModelResolver());
                contribution.getImports().add(defaultImport);
                DefaultExport defaultExport = contributionFactory.createDefaultExport();
                contribution.getExports().add(defaultExport);
            } else {
                if (contribution.getDeployables().size() > 0) {
                    // Update the deployable Composite objects with the correct Composite object for the artifact
                    for (Artifact a : contribution.getArtifacts()) {
                        if (a.getModel() instanceof Composite) {
                            for (ListIterator<Composite> lit = contribution.getDeployables().listIterator(); lit.hasNext();) {
                                if (lit.next().getName().equals(((Composite)a.getModel()).getName())) {
                                    lit.set((Composite)a.getModel());
                                }
                            }
                        }
                    }
                }
            }
        } finally {
            monitor.popContext();
            context.setContribution(old);
        }
       
        return contribution;
    }
View Full Code Here

        preResolved = true;
    } // end method preResolve

    public void resolve(Contribution contribution, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException {

        Monitor monitor = context.getMonitor();
        Contribution old = context.setContribution(contribution);
      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 {
                context.setArtifact(oldArtifact);
            }
      } finally {
        monitor.popContext();
        context.setContribution(old);
      } // end try
    } // end method resolve
View Full Code Here

                .getDomainURI());
       
        UtilityExtensionPoint utilities = nodeFactory.registry.getExtensionPoint(UtilityExtensionPoint.class);
        this.compositeActivator = utilities.getUtility(CompositeActivator.class);
        try {
            Monitor monitor = nodeFactory.monitorFactory.createMonitor();
            ProcessorContext context = new ProcessorContext(monitor);
           
            // Set up the thead context monitor
            Monitor tcm = nodeFactory.monitorFactory.setContextMonitor(monitor);
            try {
                if (contributions == null) {
                    contributions = nodeFactory.loadContributions(configuration, context);
                }
                domainComposite = nodeFactory.configureNode(configuration, contributions, context);
View Full Code Here

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

    public JMSBinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
        Monitor monitor = context.getMonitor();
        JMSBinding jmsBinding = new JMSBinding();
        // Reset validation message to keep track of validation issues.

        // Read policies
        policyProcessor.readPolicies(jmsBinding, reader);
View Full Code Here

      error(monitor, "InvalidCreate", reader, create);
  }

    private void parseResponse(XMLStreamReader reader, JMSBinding jmsBinding, ProcessorContext context) throws ContributionReadException, XMLStreamException {
        // Read sub-elements of response
        Monitor monitor = context.getMonitor();
        while (true) {
            switch (reader.next()) {
                case START_ELEMENT:
                    String elementName = reader.getName().getLocalPart();
                    if ("destination".equals(elementName)) {
View Full Code Here

TOP

Related Classes of org.apache.tuscany.sca.monitor.Monitor

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.