src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/stax/factory/StAXInputFactory.java

Tue, 06 Mar 2012 16:09:35 -0800

author
ohair
date
Tue, 06 Mar 2012 16:09:35 -0800
changeset 286
f50545b5e2f1
parent 0
373ffda63c9a
permissions
-rw-r--r--

7150322: Stop using drop source bundles in jaxws
Reviewed-by: darcy, ohrstrom

     1 /*
     2  * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  *
    25  * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
    26  */
    28 package com.sun.xml.internal.fastinfoset.stax.factory;
    30 import com.sun.xml.internal.fastinfoset.stax.*;
    31 import com.sun.xml.internal.fastinfoset.stax.events.StAXEventReader;
    32 import com.sun.xml.internal.fastinfoset.stax.events.StAXFilteredEvent;
    33 import com.sun.xml.internal.fastinfoset.stax.util.StAXFilteredParser;
    34 import com.sun.xml.internal.fastinfoset.tools.XML_SAX_FI;
    36 import java.io.InputStream;
    37 import java.io.Reader;
    38 import java.io.ByteArrayInputStream;
    39 import java.io.ByteArrayOutputStream;
    40 import java.io.BufferedInputStream;
    41 import java.io.BufferedOutputStream;
    43 import javax.xml.stream.*;
    44 import javax.xml.stream.XMLStreamException;
    45 import javax.xml.stream.util.XMLEventAllocator ;
    46 import javax.xml.transform.Source;
    47 import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
    49 public class StAXInputFactory extends XMLInputFactory {
    50     //List of supported properties and default values.
    51     private StAXManager _manager = new StAXManager(StAXManager.CONTEXT_READER) ;
    53     public StAXInputFactory() {
    54     }
    56     public static XMLInputFactory newInstance() {
    57         return XMLInputFactory.newInstance();
    58     }
    60   /**
    61    * Create a new XMLStreamReader from a reader
    62    * @param xmlfile the XML data to read from
    63    * @throws XMLStreamException
    64    */
    65     public XMLStreamReader createXMLStreamReader(Reader xmlfile) throws XMLStreamException {
    66         return getXMLStreamReader(xmlfile);
    67     }
    69     public XMLStreamReader createXMLStreamReader(InputStream s) throws XMLStreamException {
    70         return new StAXDocumentParser(s, _manager);
    71     }
    73     public XMLStreamReader createXMLStreamReader(String systemId, Reader xmlfile) throws XMLStreamException {
    74         return getXMLStreamReader(xmlfile);
    75     }
    77     public XMLStreamReader createXMLStreamReader(Source source) throws XMLStreamException {
    78         return null;
    79     }
    81     public XMLStreamReader createXMLStreamReader(String systemId, InputStream inputstream) throws XMLStreamException {
    82         return createXMLStreamReader(inputstream);
    83     }
    86     public XMLStreamReader createXMLStreamReader(InputStream inputstream, String encoding) throws XMLStreamException {
    87         return createXMLStreamReader(inputstream);
    88     }
    91     XMLStreamReader getXMLStreamReader(String systemId, InputStream inputstream, String encoding)
    92         throws XMLStreamException{
    93         return createXMLStreamReader(inputstream);
    95     }
    97     /**
    98      * @param inputstream
    99      * @throws XMLStreamException
   100      * @return
   101      */
   102     XMLStreamReader getXMLStreamReader(Reader xmlfile)
   103         throws XMLStreamException{
   105         ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
   106         BufferedOutputStream bufferedStream = new BufferedOutputStream(byteStream);
   107         StAXDocumentParser sr = null;
   108         try {
   109             XML_SAX_FI convertor = new XML_SAX_FI();
   110             convertor.convert(xmlfile, bufferedStream);
   112             ByteArrayInputStream byteInputStream = new ByteArrayInputStream(byteStream.toByteArray());
   113             InputStream document = new BufferedInputStream(byteInputStream);
   114             sr = new StAXDocumentParser();
   115             sr.setInputStream(document);
   116             sr.setManager(_manager);
   117             return sr;
   118             //return new StAXDocumentParser(document, _manager);
   119         } catch (Exception e) {
   120             return null;
   121         }
   123     }
   126     /**
   127      * @param inputstream
   128      * @throws XMLStreamException
   129      * @return XMLEventReader
   130      */
   131     public XMLEventReader createXMLEventReader(InputStream inputstream) throws XMLStreamException {
   132         return new StAXEventReader(createXMLStreamReader(inputstream));
   133     }
   135     public XMLEventReader createXMLEventReader(Reader reader) throws XMLStreamException {
   136         return new StAXEventReader(createXMLStreamReader(reader));
   137     }
   139     public XMLEventReader createXMLEventReader(Source source) throws XMLStreamException {
   140         return new StAXEventReader(createXMLStreamReader(source));
   141     }
   143     public XMLEventReader createXMLEventReader(String systemId, InputStream inputstream) throws XMLStreamException {
   144         return new StAXEventReader(createXMLStreamReader(systemId, inputstream));
   145     }
   147     public XMLEventReader createXMLEventReader(java.io.InputStream stream, String encoding) throws XMLStreamException {
   148         return new StAXEventReader(createXMLStreamReader(stream, encoding));
   149     }
   151     public XMLEventReader createXMLEventReader(String systemId, Reader reader) throws XMLStreamException {
   152         return new StAXEventReader(createXMLStreamReader(systemId, reader));
   153     }
   155     /** Create a new XMLEventReader from an XMLStreamReader.  After being used
   156      * to construct the XMLEventReader instance returned from this method
   157      * the XMLStreamReader must not be used.
   158      * @param streamReader the XMLStreamReader to read from (may not be modified)
   159      * @return a new XMLEventReader
   160      * @throws XMLStreamException
   161      */
   162     public XMLEventReader createXMLEventReader(XMLStreamReader streamReader) throws XMLStreamException {
   163         return new StAXEventReader(streamReader);
   164     }
   166     public XMLEventAllocator getEventAllocator() {
   167         return (XMLEventAllocator)getProperty(XMLInputFactory.ALLOCATOR);
   168     }
   170     public XMLReporter getXMLReporter() {
   171         return (XMLReporter)_manager.getProperty(XMLInputFactory.REPORTER);
   172     }
   174     public XMLResolver getXMLResolver() {
   175         Object object = _manager.getProperty(XMLInputFactory.RESOLVER);
   176         return (XMLResolver)object;
   177         //return (XMLResolver)_manager.getProperty(XMLInputFactory.RESOLVER);
   178     }
   180     public void setXMLReporter(XMLReporter xmlreporter) {
   181         _manager.setProperty(XMLInputFactory.REPORTER, xmlreporter);
   182     }
   184     public void setXMLResolver(XMLResolver xmlresolver) {
   185         _manager.setProperty(XMLInputFactory.RESOLVER, xmlresolver);
   186     }
   188     /** Create a filtered event reader that wraps the filter around the event reader
   189      * @param reader the event reader to wrap
   190      * @param filter the filter to apply to the event reader
   191      * @throws XMLStreamException
   192      */
   193     public XMLEventReader createFilteredReader(XMLEventReader reader, EventFilter filter) throws XMLStreamException {
   194         return new StAXFilteredEvent(reader, filter);
   195     }
   197     /** Create a filtered reader that wraps the filter around the reader
   198      * @param reader the reader to filter
   199      * @param filter the filter to apply to the reader
   200      * @throws XMLStreamException
   201      */
   202     public XMLStreamReader createFilteredReader(XMLStreamReader reader, StreamFilter filter) throws XMLStreamException {
   204         if( reader != null && filter != null )
   205             return new StAXFilteredParser(reader,filter);
   207         return null;
   208     }
   212     /** Get the value of a feature/property from the underlying implementation
   213      * @param name The name of the property (may not be null)
   214      * @return The value of the property
   215      * @throws IllegalArgumentException if the property is not supported
   216      */
   217     public Object getProperty(String name) throws IllegalArgumentException {
   218         if(name == null){
   219             throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.nullPropertyName"));
   220         }
   221         if(_manager.containsProperty(name))
   222             return _manager.getProperty(name);
   223         throw new IllegalArgumentException(CommonResourceBundle.getInstance().getString("message.propertyNotSupported", new Object[]{name}));
   224     }
   226     /** Query the set of Properties that this factory supports.
   227      *
   228      * @param name The name of the property (may not be null)
   229      * @return true if the property is supported and false otherwise
   230      */
   231     public boolean isPropertySupported(String name) {
   232         if(name == null)
   233             return false ;
   234         else
   235             return _manager.containsProperty(name);
   236     }
   238     /** Set a user defined event allocator for events
   239      * @param allocator the user defined allocator
   240      */
   241     public void setEventAllocator(XMLEventAllocator allocator) {
   242         _manager.setProperty(XMLInputFactory.ALLOCATOR, allocator);
   243     }
   245     /** Allows the user to set specific feature/property on the underlying implementation. The underlying implementation
   246      * is not required to support every setting of every property in the specification and may use IllegalArgumentException
   247      * to signal that an unsupported property may not be set with the specified value.
   248      * @param name The name of the property (may not be null)
   249      * @param value The value of the property
   250      * @throws IllegalArgumentException if the property is not supported
   251      */
   252     public void setProperty(String name, Object value) throws IllegalArgumentException {
   253         _manager.setProperty(name,value);
   254     }
   256 }

mercurial