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 componentType processor.

Version:
$Rev: 828119 $ $Date: 2009-10-21 21:00:07 +0300 (Wed, 21 Oct 2009) $
 
     private ValidatingXMLInputFactory inputFactory;
    
    
Constructs a new componentType processor.

Parameters:
modelFactories
staxProcessor
 
     public ComponentTypeDocumentProcessor(FactoryExtensionPoint modelFactories,
                                           StAXArtifactProcessor staxProcessor) {
         super(modelFactoriesstaxProcessor);
         this. = modelFactories.getFactory(ValidatingXMLInputFactory.class);
     }
     
     public ComponentType read(URL contributionURLURI uriURL urlProcessorContext contextthrows ContributionReadException {
         InputStream urlStream = null;
         Monitor monitor = context.getMonitor();
         try {
             
             // Create a stream reader
             urlStream = IOHelper.openStream(url);
             XMLStreamReader reader = .createXMLStreamReader(url.toString(), urlStream);
             ValidatingXMLInputFactory.setMonitor(readermonitor);
             reader.nextTag();
             
             // Reader the componentType model 
             ComponentType componentType = (ComponentType).read(readercontext);
             if (componentType != null) {
                 componentType.setURI(uri.toString());
             }
 
             // For debugging purposes, write it back to XML
 //            if (componentType != null) {
 //                try {
 //                    ByteArrayOutputStream bos = new ByteArrayOutputStream();
 //                    XMLOutputFactory outputFactory = XMLOutputFactory.newInstance();
 //                    outputFactory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
 //                    extensionProcessor.write(componentType, outputFactory.createXMLStreamWriter(bos));
 //                    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(bos.toByteArray()));
 //                    OutputFormat format = new OutputFormat();
 //                    format.setIndenting(true);
 //                    format.setIndent(2);
 //                    XMLSerializer serializer = new XMLSerializer(System.out, format);
 //                    serializer.serialize(document);
 //                } catch (Exception e) {
 //                    e.printStackTrace();
 //                }
 //            }
             
             return componentType;
             
         } catch (XMLStreamException e) {
         	ContributionReadException ce = new ContributionReadException(e);
        	error(monitor"ContributionReadException"ce);
            throw ce;
        } catch (IOException e) {
        	error(monitor"ContributionReadException"ce);
            throw ce;
        } finally {
            try {
                if (urlStream != null) {
                    urlStream.close();
                    urlStream = null;
                }
            } catch (IOException ioe) {
                //ignore
            }
        }
    }
    
    public void resolve(ComponentType componentTypeModelResolver resolverProcessorContext contextthrows ContributionResolveException {
        .resolve(componentTyperesolvercontext);
    }
    
    public String getArtifactType() {
        return ".componentType";
    }
    
    public Class<ComponentTypegetModelType() {
        return ComponentType.class;
    }
New to GrepCode? Check out our FAQ X