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