Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Licensed to the Apache Software Foundation (ASF) under one
   * or more contributor license agreements.  See the NOTICE file
   * distributed with this work for additional information
   * regarding copyright ownership.  The ASF licenses this file
   * to you under the Apache License, Version 2.0 (the
   * "License"); you may not use this file except in compliance
   * with the License.  You may obtain a copy of the License at
   * 
  *   http://www.apache.org/licenses/LICENSE-2.0
  * 
  * Unless required by applicable law or agreed to in writing,
  * software distributed under the License is distributed on an
  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  * KIND, either express or implied.  See the License for the
  * specific language governing permissions and limitations
  * under the License.    
  */
 
 package org.apache.tuscany.sca.assembly.xml;
 
 import java.net.URI;
 import java.net.URL;
 
 
A composite processor.

Version:
$Rev: 945562 $ $Date: 2010-05-18 12:36:18 +0300 (Tue, 18 May 2010) $
 
                                                                                  XMLStreamConstants {
     private ValidatingXMLInputFactory inputFactory;
    

    
Constructs a composite document processor

Parameters:
modelFactories
staxProcessor
monitor
 
     public CompositeDocumentProcessor(FactoryExtensionPoint modelFactories,
                                       StAXArtifactProcessor<?> staxProcessor) {
         super(modelFactoriesstaxProcessor);
         this. = modelFactories.getFactory(ValidatingXMLInputFactory.class);
     }
    
    
Reads the contents of a Composite document and returns a Composite object

Parameters:
contributionURL - the URL of the contribution containing the Composite - can be null
uri - the URI of the composite document
url - the URL of the composite document
Returns:
a Composite object built from the supplied Composite document
 
     public Composite read(URL contributionURLURI uriURL urlProcessorContext contextthrows ContributionReadException {
     	ifuri == null || url == null ) {
     		throw new ContributionReadException("Request to read composite with uri or url NULL");
     	} // end if
         InputStream scdlStream = null;
         
         try {
             scdlStream = IOHelper.openStream(url);
         } catch (IOException e) {
             ContributionReadException ce = new ContributionReadException("Exception reading " + urie);
             error(context.getMonitor(), "ContributionReadException"urlce);
             throw ce;
         } 
         return read(uriurlscdlStreamcontext);
     }
 
     public Composite read(URI uriURL urlInputStream scdlStreamProcessorContext contextthrows ContributionReadException {
         try {       
             
             Composite composite = null;
             Monitor monitor = context.getMonitor();
             // Tag the monitor with the name of the composite artifact
             ifmonitor != 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 StreamSourcescdlStreamurl.toString() );
            XMLStreamReader reader = .createXMLStreamReader(scdlSource);
            
            // set the monitor on the input factory as the standard XMLInputFactory
            // methods used for creating readers don't allow for the context to
            // be passed in
            ValidatingXMLInputFactory.setMonitor(readercontext.getMonitor());
            
            // Read the header (i.e. text before the <composite> element, if any
            readCompositeFileHeaderreader );
            
            // Read the composite model
            composite = (Composite).read(readercontext);
            if (composite != null) {
                composite.setURI(uri.toString());
            }
            return composite;
            
        } catch (XMLStreamException e) {
        	ContributionReadException ce = new ContributionReadException("Exception reading " + urie);
        	error(context.getMonitor(), "ContributionReadException"ce);
            throw ce;
        } finally {
            try {
                if (scdlStream != null) {
                    scdlStream.close();
                    scdlStream = null;
                }
            } catch (IOException ioe) {
                //ignore
            }
        }
    }
    
    
Reads the header portion of a composite file - i.e. the section of the file before the <composite> start tag In particular handle any DTD declarations

Parameters:
reader - an XMLStreamReader which is reading the composite file
Throws:
javax.xml.stream.XMLStreamException
    private void readCompositeFileHeaderXMLStreamReader reader ) throws XMLStreamException {
    	    	
        while (true) {
        	int event = reader.next();
            if ( event == 
                || event == 
                || event == 
                || event == 
                || event ==  
                || event ==  
                || event ==  )  {
                continue;
            } // end if
            
            // The first start (or end) element terminates the header scan
            if (event ==  || event == ) {
                return;
            } // end if
        } // end while
    } // end method readCompositeFileHeader
    
    public void resolve(Composite compositeModelResolver resolverProcessorContext contextthrows ContributionResolveException {
    	try {
	        if (composite != null)
	    	    .resolve(compositeresolvercontext);
    	} catch (Throwable e ) {
    		// Add information about which composite was being processed when the exception occurred
    		String newMessage = "Processing composite " + composite.getName() + ": " + e.getMessage();
    		throw new ContributionResolveExceptionnewMessagee );
    	} // end try
    }
    public String getArtifactType() {
        return ".composite";
    }
    
    public Class<CompositegetModelType() {
        return Composite.class;
    }
    
// end class
New to GrepCode? Check out our FAQ X