src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/stax/factory/StAXEventFactory.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

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 javax.xml.namespace.QName;
aoqi@0 31 import javax.xml.namespace.NamespaceContext;
aoqi@0 32 import javax.xml.stream.Location;
aoqi@0 33 import javax.xml.stream.XMLEventFactory;
aoqi@0 34 import javax.xml.stream.events.*;
aoqi@0 35 import java.util.Iterator;
aoqi@0 36 import com.sun.xml.internal.fastinfoset.stax.events.*;
aoqi@0 37
aoqi@0 38
aoqi@0 39 public class StAXEventFactory extends XMLEventFactory {
aoqi@0 40 Location location = null;
aoqi@0 41
aoqi@0 42 /** Creates a new instance of StAXEventFactory */
aoqi@0 43 public StAXEventFactory() {
aoqi@0 44 }
aoqi@0 45 /**
aoqi@0 46 * This method allows setting of the Location on each event that
aoqi@0 47 * is created by this factory. The values are copied by value into
aoqi@0 48 * the events created by this factory. To reset the location
aoqi@0 49 * information set the location to null.
aoqi@0 50 * @param location the location to set on each event created
aoqi@0 51 */
aoqi@0 52 public void setLocation(Location location) {
aoqi@0 53 this.location = location;
aoqi@0 54 }
aoqi@0 55
aoqi@0 56 /**
aoqi@0 57 * Create a new Attribute
aoqi@0 58 * @param prefix the prefix of this attribute, may not be null
aoqi@0 59 * @param namespaceURI the attribute value is set to this value, may not be null
aoqi@0 60 * @param localName the local name of the XML name of the attribute, localName cannot be null
aoqi@0 61 * @param value the attribute value to set, may not be null
aoqi@0 62 * @return the Attribute with specified values
aoqi@0 63 */
aoqi@0 64 public Attribute createAttribute(String prefix, String namespaceURI, String localName, String value) {
aoqi@0 65 AttributeBase attr = new AttributeBase(prefix, namespaceURI, localName, value, null);
aoqi@0 66 if(location != null)attr.setLocation(location);
aoqi@0 67 return attr;
aoqi@0 68 }
aoqi@0 69
aoqi@0 70 /**
aoqi@0 71 * Create a new Attribute
aoqi@0 72 * @param localName the local name of the XML name of the attribute, localName cannot be null
aoqi@0 73 * @param value the attribute value to set, may not be null
aoqi@0 74 * @return the Attribute with specified values
aoqi@0 75 */
aoqi@0 76 public Attribute createAttribute(String localName, String value) {
aoqi@0 77 AttributeBase attr = new AttributeBase(localName, value);
aoqi@0 78 if(location != null)attr.setLocation(location);
aoqi@0 79 return attr;
aoqi@0 80 }
aoqi@0 81
aoqi@0 82 public Attribute createAttribute(QName name, String value) {
aoqi@0 83 AttributeBase attr = new AttributeBase(name, value);
aoqi@0 84 if(location != null)attr.setLocation(location);
aoqi@0 85 return attr;
aoqi@0 86 }
aoqi@0 87
aoqi@0 88 /**
aoqi@0 89 * Create a new default Namespace
aoqi@0 90 * @param namespaceURI the default namespace uri
aoqi@0 91 * @return the Namespace with the specified value
aoqi@0 92 */
aoqi@0 93 public Namespace createNamespace(String namespaceURI) {
aoqi@0 94 NamespaceBase event = new NamespaceBase(namespaceURI);
aoqi@0 95 if(location != null)event.setLocation(location);
aoqi@0 96 return event;
aoqi@0 97 }
aoqi@0 98
aoqi@0 99 /**
aoqi@0 100 * Create a new Namespace
aoqi@0 101 * @param prefix the prefix of this namespace, may not be null
aoqi@0 102 * @param namespaceURI the attribute value is set to this value, may not be null
aoqi@0 103 * @return the Namespace with the specified values
aoqi@0 104 */
aoqi@0 105 public Namespace createNamespace(String prefix, String namespaceURI) {
aoqi@0 106 NamespaceBase event = new NamespaceBase(prefix, namespaceURI);
aoqi@0 107 if(location != null)event.setLocation(location);
aoqi@0 108 return event;
aoqi@0 109 }
aoqi@0 110
aoqi@0 111 /**
aoqi@0 112 * Create a new StartElement.
aoqi@0 113 * @param name the qualified name of the attribute, may not be null
aoqi@0 114 * @param attributes an optional unordered set of objects that
aoqi@0 115 * implement Attribute to add to the new StartElement, may be null
aoqi@0 116 * @param namespaces an optional unordered set of objects that
aoqi@0 117 * implement Namespace to add to the new StartElement, may be null
aoqi@0 118 * @return an instance of the requested StartElement
aoqi@0 119 */
aoqi@0 120 public StartElement createStartElement(QName name, Iterator attributes, Iterator namespaces) {
aoqi@0 121 return createStartElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), attributes, namespaces);
aoqi@0 122 }
aoqi@0 123
aoqi@0 124 public StartElement createStartElement(String prefix, String namespaceUri, String localName) {
aoqi@0 125 StartElementEvent event = new StartElementEvent(prefix, namespaceUri, localName);
aoqi@0 126 if(location != null)event.setLocation(location);
aoqi@0 127 return event;
aoqi@0 128 }
aoqi@0 129
aoqi@0 130 public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces) {
aoqi@0 131 return createStartElement(prefix, namespaceUri, localName, attributes, namespaces, null);
aoqi@0 132 }
aoqi@0 133
aoqi@0 134 public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces, NamespaceContext context) {
aoqi@0 135 StartElementEvent elem = new StartElementEvent(prefix, namespaceUri, localName);
aoqi@0 136 elem.addAttributes(attributes);
aoqi@0 137 elem.addNamespaces(namespaces);
aoqi@0 138 elem.setNamespaceContext(context);
aoqi@0 139 if(location != null)elem.setLocation(location);
aoqi@0 140 return elem;
aoqi@0 141 }
aoqi@0 142
aoqi@0 143 /**
aoqi@0 144 * Create a new EndElement
aoqi@0 145 * @param name the qualified name of the EndElement
aoqi@0 146 * @param namespaces an optional unordered set of objects that
aoqi@0 147 * implement Namespace that have gone out of scope, may be null
aoqi@0 148 * @return an instance of the requested EndElement
aoqi@0 149 */
aoqi@0 150 public EndElement createEndElement(QName name, Iterator namespaces) {
aoqi@0 151 return createEndElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), namespaces);
aoqi@0 152 }
aoqi@0 153
aoqi@0 154 /**
aoqi@0 155 * Create a new EndElement
aoqi@0 156 * @param namespaceUri the uri of the QName of the new StartElement
aoqi@0 157 * @param localName the local name of the QName of the new StartElement
aoqi@0 158 * @param prefix the prefix of the QName of the new StartElement
aoqi@0 159 * @return an instance of the requested EndElement
aoqi@0 160 */
aoqi@0 161 public EndElement createEndElement(String prefix, String namespaceUri, String localName) {
aoqi@0 162 EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
aoqi@0 163 if(location != null)event.setLocation(location);
aoqi@0 164 return event;
aoqi@0 165 }
aoqi@0 166
aoqi@0 167 /**
aoqi@0 168 * Create a new EndElement
aoqi@0 169 * @param namespaceUri the uri of the QName of the new StartElement
aoqi@0 170 * @param localName the local name of the QName of the new StartElement
aoqi@0 171 * @param prefix the prefix of the QName of the new StartElement
aoqi@0 172 * @param namespaces an unordered set of objects that implement
aoqi@0 173 * Namespace that have gone out of scope, may be null
aoqi@0 174 * @return an instance of the requested EndElement
aoqi@0 175 */
aoqi@0 176 public EndElement createEndElement(String prefix, String namespaceUri, String localName, Iterator namespaces) {
aoqi@0 177
aoqi@0 178 EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName);
aoqi@0 179 if(namespaces!=null){
aoqi@0 180 while(namespaces.hasNext())
aoqi@0 181 event.addNamespace((Namespace)namespaces.next());
aoqi@0 182 }
aoqi@0 183 if(location != null)event.setLocation(location);
aoqi@0 184 return event;
aoqi@0 185 }
aoqi@0 186
aoqi@0 187 /**
aoqi@0 188 * Create a Characters event, this method does not check if the content
aoqi@0 189 * is all whitespace. To create a space event use #createSpace(String)
aoqi@0 190 * @param content the string to create
aoqi@0 191 * @return a Characters event
aoqi@0 192 */
aoqi@0 193 public Characters createCharacters(String content) {
aoqi@0 194 CharactersEvent charEvent = new CharactersEvent(content);
aoqi@0 195 if(location != null)charEvent.setLocation(location);
aoqi@0 196 return charEvent;
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 /**
aoqi@0 200 * Create a Characters event with the CData flag set to true
aoqi@0 201 * @param content the string to create
aoqi@0 202 * @return a Characters event
aoqi@0 203 */
aoqi@0 204 public Characters createCData(String content) {
aoqi@0 205 CharactersEvent charEvent = new CharactersEvent(content, true);
aoqi@0 206 if(location != null)charEvent.setLocation(location);
aoqi@0 207 return charEvent;
aoqi@0 208 }
aoqi@0 209
aoqi@0 210 /**
aoqi@0 211 * Create a Characters event with the isSpace flag set to true
aoqi@0 212 * @param content the content of the space to create
aoqi@0 213 * @return a Characters event
aoqi@0 214 */
aoqi@0 215 public Characters createSpace(String content) {
aoqi@0 216 CharactersEvent event = new CharactersEvent(content);
aoqi@0 217 event.setSpace(true);
aoqi@0 218 if(location != null)event.setLocation(location);
aoqi@0 219 return event;
aoqi@0 220 }
aoqi@0 221 /**
aoqi@0 222 * Create an ignorable space
aoqi@0 223 * @param content the space to create
aoqi@0 224 * @return a Characters event
aoqi@0 225 */
aoqi@0 226 public Characters createIgnorableSpace(String content) {
aoqi@0 227 CharactersEvent event = new CharactersEvent(content, false);
aoqi@0 228 event.setSpace(true);
aoqi@0 229 event.setIgnorable(true);
aoqi@0 230 if(location != null)event.setLocation(location);
aoqi@0 231 return event;
aoqi@0 232 }
aoqi@0 233 /**
aoqi@0 234 * Creates a new instance of a StartDocument event
aoqi@0 235 * @return a StartDocument event
aoqi@0 236 */
aoqi@0 237 public StartDocument createStartDocument() {
aoqi@0 238 StartDocumentEvent event = new StartDocumentEvent();
aoqi@0 239 if(location != null)event.setLocation(location);
aoqi@0 240 return event;
aoqi@0 241 }
aoqi@0 242
aoqi@0 243 /**
aoqi@0 244 * Creates a new instance of a StartDocument event
aoqi@0 245 *
aoqi@0 246 * @param encoding the encoding style
aoqi@0 247 * @return a StartDocument event
aoqi@0 248 */
aoqi@0 249 public StartDocument createStartDocument(String encoding) {
aoqi@0 250 StartDocumentEvent event = new StartDocumentEvent(encoding);
aoqi@0 251 if(location != null)event.setLocation(location);
aoqi@0 252 return event;
aoqi@0 253 }
aoqi@0 254
aoqi@0 255 /**
aoqi@0 256 * Creates a new instance of a StartDocument event
aoqi@0 257 *
aoqi@0 258 * @param encoding the encoding style
aoqi@0 259 * @param version the XML version
aoqi@0 260 * @return a StartDocument event
aoqi@0 261 */
aoqi@0 262 public StartDocument createStartDocument(String encoding, String version) {
aoqi@0 263 StartDocumentEvent event = new StartDocumentEvent(encoding, version);
aoqi@0 264 if(location != null)event.setLocation(location);
aoqi@0 265 return event;
aoqi@0 266 }
aoqi@0 267
aoqi@0 268 /**
aoqi@0 269 * Creates a new instance of a StartDocument event
aoqi@0 270 *
aoqi@0 271 * @param encoding the encoding style
aoqi@0 272 * @param version the XML version
aoqi@0 273 * @param standalone the status of standalone may be set to "true" or "false"
aoqi@0 274 * @return a StartDocument event
aoqi@0 275 */
aoqi@0 276 public StartDocument createStartDocument(String encoding, String version, boolean standalone) {
aoqi@0 277 StartDocumentEvent event = new StartDocumentEvent(encoding, version);
aoqi@0 278 event.setStandalone(standalone);
aoqi@0 279 if(location != null)event.setLocation(location);
aoqi@0 280 return event;
aoqi@0 281 }
aoqi@0 282
aoqi@0 283 public EndDocument createEndDocument() {
aoqi@0 284 EndDocumentEvent event =new EndDocumentEvent();
aoqi@0 285 if(location != null)event.setLocation(location);
aoqi@0 286 return event;
aoqi@0 287 }
aoqi@0 288
aoqi@0 289 /** Creates a new instance of a EntityReference event
aoqi@0 290 *
aoqi@0 291 * @param name The name of the reference
aoqi@0 292 * @param entityDeclaration the declaration for the event
aoqi@0 293 * @return an EntityReference event
aoqi@0 294 */
aoqi@0 295 public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) {
aoqi@0 296 EntityReferenceEvent event = new EntityReferenceEvent(name, entityDeclaration);
aoqi@0 297 if(location != null)event.setLocation(location);
aoqi@0 298 return event;
aoqi@0 299 }
aoqi@0 300
aoqi@0 301 /**
aoqi@0 302 * Create a comment
aoqi@0 303 * @param text The text of the comment
aoqi@0 304 * a Comment event
aoqi@0 305 */
aoqi@0 306 public Comment createComment(String text) {
aoqi@0 307 CommentEvent charEvent = new CommentEvent(text);
aoqi@0 308 if(location != null)charEvent.setLocation(location);
aoqi@0 309 return charEvent;
aoqi@0 310 }
aoqi@0 311
aoqi@0 312 /**
aoqi@0 313 * Create a document type definition event
aoqi@0 314 * This string contains the entire document type declaration that matches
aoqi@0 315 * the doctypedecl in the XML 1.0 specification
aoqi@0 316 * @param dtd the text of the document type definition
aoqi@0 317 * @return a DTD event
aoqi@0 318 */
aoqi@0 319 public DTD createDTD(String dtd) {
aoqi@0 320 DTDEvent dtdEvent = new DTDEvent(dtd);
aoqi@0 321 if(location != null)dtdEvent.setLocation(location);
aoqi@0 322 return dtdEvent;
aoqi@0 323 }
aoqi@0 324
aoqi@0 325
aoqi@0 326 /**
aoqi@0 327 * Create a processing instruction
aoqi@0 328 * @param target The target of the processing instruction
aoqi@0 329 * @param data The text of the processing instruction
aoqi@0 330 * @return a ProcessingInstruction event
aoqi@0 331 */
aoqi@0 332 public ProcessingInstruction createProcessingInstruction(String target, String data) {
aoqi@0 333 ProcessingInstructionEvent event = new ProcessingInstructionEvent(target, data);
aoqi@0 334 if(location != null)event.setLocation(location);
aoqi@0 335 return event;
aoqi@0 336 }
aoqi@0 337
aoqi@0 338
aoqi@0 339
aoqi@0 340
aoqi@0 341
aoqi@0 342 }

mercurial