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.contribution.processor;
 
 
 
Implementation of an extensible StAX artifact processor. Takes a StAXArtifactProcessorExtensionPoint and delegates to the proper StAXArtifactProcessor by element QName

Version:
$Rev: 831467 $ $Date: 2009-10-30 22:08:25 +0000 (Fri, 30 Oct 2009) $
 
     private static final Logger logger = Logger.getLogger(ExtensibleStAXArtifactProcessor.class.getName());
     private static final String XMLSCHEMA_NS = "http://www.w3.org/2001/XMLSchema";
     public static final QName ANY_ELEMENT = new QName("any");
 
     private XMLInputFactory inputFactory;
     private XMLOutputFactory outputFactory;
Constructs a new ExtensibleStAXArtifactProcessor.

Parameters:
processors
inputFactory
outputFactory
 
                                            XMLInputFactory inputFactory,
                                            XMLOutputFactory outputFactory) {
         super();
         this. = processors;
         this. = inputFactory;
         this. = outputFactory;
         if (this. != null) {
         }
     }
     
         super();
         this. = registry.getExtensionPoint(StAXArtifactProcessorExtensionPoint.class);
         FactoryExtensionPoint factories = registry.getExtensionPoint(FactoryExtensionPoint.class);
         this. = factories.getFactory(XMLInputFactory.class);
         this. = factories.getFactory(XMLOutputFactory.class);
         if (this. != null) {
         }
     }

    
Report a warning.

Parameters:
problems
message
model
 
     private void warning(Monitor monitorString messageObject modelObject... messageParameters) {
         if (monitor != null) {
             Problem problem =
                monitor.createProblem(this.getClass().getName(),
                                      "contribution-validation-messages",
                                      .,
                                      model,
                                      message,
                                      (Object[])messageParameters);
            monitor.problem(problem);
        }
    }

    
Report a error.

Parameters:
problems
message
model
    private void error(Monitor monitorString messageObject modelObject... messageParameters) {
        if (monitor != null) {
            Problem problem =
                monitor.createProblem(this.getClass().getName(),
                                      "contribution-validation-messages",
                                      .,
                                      model,
                                      message,
                                      (Object[])messageParameters);
            monitor.problem(problem);
        }
    }

    
Report a exception.

Parameters:
problems
message
model
    private void error(Monitor monitorString messageObject modelException ex) {
        if (monitor != null) {
            Problem problem =
                monitor.createProblem(this.getClass().getName(),
                                      "contribution-validation-messages",
                                      .,
                                      model,
                                      message,
                                      ex);
            monitor.problem(problem);
        }
    }
        Monitor monitor = context.getMonitor();
        // Delegate to the processor associated with the element QName
        int event = source.getEventType();
        if (event == .) {
            source.nextTag();
        }
        QName name = source.getName();
        StAXArtifactProcessor<?> processor = (StAXArtifactProcessor<?>).getProcessor(name);
        if (processor == null) {
            Location location = source.getLocation();
            error(monitor"ElementCannotBeProcessed"namelocation);
            StAXArtifactProcessor anyElementProcessor = .getProcessor();
            if (anyElementProcessor != null) {
                return anyElementProcessor.read(sourcecontext);
            } else {
                return null;
            }
        }
        return processor.read(sourcecontext);
    }
    @SuppressWarnings("unchecked")
    public void write(Object modelXMLStreamWriter outputSourceProcessorContext contextthrows ContributionWriteExceptionXMLStreamException {
        // Delegate to the processor associated with the model type
        if (model != null) {
            StAXArtifactProcessor processor = .getProcessor(model.getClass());
            if (processor != null) {
                processor.write(modeloutputSourcecontext);
            } else {
                if (.isLoggable(.)) {
                    .warning("No StAX processor is configured to handle " + model.getClass());
                }
                StAXArtifactProcessor anyElementProcessor = .getProcessor();
                if ((model instanceof Extension) && anyElementProcessor != null) {
                    anyElementProcessor.write(modeloutputSourcecontext);
                }
            }
        }
    }
    @SuppressWarnings("unchecked")
    public void resolve(Object modelModelResolver resolverProcessorContext contextthrows ContributionResolveException {
        // Delegate to the processor associated with the model type
        if (model != null) {
            StAXArtifactProcessor processor = .getProcessor(model.getClass());
            if (processor != null) {
                processor.resolve(modelresolvercontext);
            }
        }
    }

    
Read a model from an InputStream.

Parameters:
is The artifact InputStream
type Model type
context TODO
Returns:
The model
Throws:
ContributionReadException
    public <M> M read(InputStream isClass<M> typeProcessorContext contextthrows ContributionReadException {
        Monitor monitor = context.getMonitor();
        try {
            XMLStreamReader reader;
            try {
                reader = .createXMLStreamReader(is);
                try {
                    reader.nextTag();
                    QName name = reader.getName();
                    Object mo = read(readercontext);
                    if (type.isInstance(mo)) {
                        return type.cast(mo);
                    } else {
                        error(monitor"UnrecognizedElementException"readername);
                        UnrecognizedElementException e = new UnrecognizedElementException(name);
                        throw e;
                    }
                } catch (ContributionReadException e) {
                    Location location = reader.getLocation();
                    e.setLine(location.getLineNumber());
                    e.setColumn(location.getColumnNumber());
                    error(monitor"ContributionReadException"readere);
                    throw e;
                } finally {
                    try {
                        reader.close();
                    } catch (XMLStreamException e) {
                        // ignore
                    }
                }
            } finally {
                try {
                    is.close();
                } catch (IOException e) {
                    // ignore
                }
            }
        } catch (XMLStreamException e) {
            ContributionReadException ce = new ContributionReadException(e);
            error(monitor"ContributionReadException"ce);
            throw ce;
        }
    }

    
Write a model to an OutputStream.

Parameters:
model
os
context
Throws:
ContributionWriteException
    public void write(Object modelOutputStream osProcessorContext contextthrows ContributionWriteException {
        try {
            XMLStreamWriter writer = .createXMLStreamWriter(os);
            write(modelwritercontext);
            writer.flush();
            writer.close();
        } catch (XMLStreamException e) {
            ContributionWriteException cw = new ContributionWriteException(e);
            error(context.getMonitor(), "ContributionWriteException"cw);
            throw cw;
        }
    }
    public QName getArtifactType() {
        return null;
    }
    public Class<ObjectgetModelType() {
        return null;
    }
New to GrepCode? Check out our FAQ X