Package org.apache.tuscany.sca.monitor

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


            monitor.problem(problem);
        }
    }

    public Object read(XMLStreamReader source, ProcessorContext context) throws ContributionReadException, XMLStreamException {
        Monitor monitor = context.getMonitor();
        // Delegate to the processor associated with the element QName
        int event = source.getEventType();
        if (event == XMLStreamConstants.START_DOCUMENT) {
            source.nextTag();
        }
View Full Code Here


     * @param context TODO
     * @return The model
     * @throws ContributionReadException
     */
    public <M> M read(InputStream is, Class<M> type, ProcessorContext context) throws ContributionReadException {
        Monitor monitor = context.getMonitor();
        try {
            XMLStreamReader reader;
            try {
                reader = inputFactory.createXMLStreamReader(is);
                try {
View Full Code Here

    public Monitor getMonitor() {
        return monitor;
    }

    public Monitor setMonitor(Monitor monitor) {
        Monitor old = this.monitor;
        this.monitor = monitor;
        return old;
    }
View Full Code Here

   
  }

  private void readAttachTo(ExternalAttachment attachment,
      XMLStreamReader reader, ProcessorContext context) {
    Monitor monitor = context.getMonitor();
   
    String attachTo = reader.getAttributeValue(null, ATTACH_TO);
    if ( attachTo != null ) {
       try {
               XPath path = xpathHelper.newXPath();
View Full Code Here

        }
        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;
                                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

    } // 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

        CompositeReference compositeReference = null;
        Contract contract = null;
        Wire wire = null;
        Callback callback = null;
        QName name = null;
        Monitor monitor = context.getMonitor();
        Contribution contribution = context.getContribution();
        try {
            // Read the composite document
            while (reader.hasNext()) {
                int event = reader.getEventType();
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 Composite read(URI uri, URL url, InputStream scdlStream, ProcessorContext context) throws ContributionReadException {
        try {      
           
            Composite composite = null;
            Monitor monitor = context.getMonitor();
            // Tag the monitor with the name of the composite artifact
            if( monitor != null ) {
              monitor.setArtifactName(uri.toString());
            } //end if
           
            // Set up a StreamSource for the composite file, since this has an associated URL that
            // can be used by the parser to find references to other files such as DTDs
            StreamSource scdlSource = new StreamSource( scdlStream, url.toString() );
View Full Code Here

        this.inputFactory = modelFactories.getFactory(ValidatingXMLInputFactory.class);
    }
   
    public ComponentType read(URL contributionURL, URI uri, URL url, ProcessorContext context) throws ContributionReadException {
        InputStream urlStream = null;
        Monitor monitor = context.getMonitor();
        try {
           
            // Create a stream reader
            urlStream = IOHelper.openStream(url);
            XMLStreamReader reader = inputFactory.createXMLStreamReader(url.toString(), urlStream);
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.