1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/stax/factory/StAXEventFactory.java Tue Mar 06 16:09:35 2012 -0800 1.3 @@ -0,0 +1,342 @@ 1.4 +/* 1.5 + * Copyright (c) 2004, 2011, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. Oracle designates this 1.11 + * particular file as subject to the "Classpath" exception as provided 1.12 + * by Oracle in the LICENSE file that accompanied this code. 1.13 + * 1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.17 + * version 2 for more details (a copy is included in the LICENSE file that 1.18 + * accompanied this code). 1.19 + * 1.20 + * You should have received a copy of the GNU General Public License version 1.21 + * 2 along with this work; if not, write to the Free Software Foundation, 1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.23 + * 1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.25 + * or visit www.oracle.com if you need additional information or have any 1.26 + * questions. 1.27 + * 1.28 + * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. 1.29 + */ 1.30 + 1.31 +package com.sun.xml.internal.fastinfoset.stax.factory; 1.32 + 1.33 +import javax.xml.namespace.QName; 1.34 +import javax.xml.namespace.NamespaceContext; 1.35 +import javax.xml.stream.Location; 1.36 +import javax.xml.stream.XMLEventFactory; 1.37 +import javax.xml.stream.events.*; 1.38 +import java.util.Iterator; 1.39 +import com.sun.xml.internal.fastinfoset.stax.events.*; 1.40 + 1.41 + 1.42 +public class StAXEventFactory extends XMLEventFactory { 1.43 + Location location = null; 1.44 + 1.45 + /** Creates a new instance of StAXEventFactory */ 1.46 + public StAXEventFactory() { 1.47 + } 1.48 + /** 1.49 + * This method allows setting of the Location on each event that 1.50 + * is created by this factory. The values are copied by value into 1.51 + * the events created by this factory. To reset the location 1.52 + * information set the location to null. 1.53 + * @param location the location to set on each event created 1.54 + */ 1.55 + public void setLocation(Location location) { 1.56 + this.location = location; 1.57 + } 1.58 + 1.59 + /** 1.60 + * Create a new Attribute 1.61 + * @param prefix the prefix of this attribute, may not be null 1.62 + * @param namespaceURI the attribute value is set to this value, may not be null 1.63 + * @param localName the local name of the XML name of the attribute, localName cannot be null 1.64 + * @param value the attribute value to set, may not be null 1.65 + * @return the Attribute with specified values 1.66 + */ 1.67 + public Attribute createAttribute(String prefix, String namespaceURI, String localName, String value) { 1.68 + AttributeBase attr = new AttributeBase(prefix, namespaceURI, localName, value, null); 1.69 + if(location != null)attr.setLocation(location); 1.70 + return attr; 1.71 + } 1.72 + 1.73 + /** 1.74 + * Create a new Attribute 1.75 + * @param localName the local name of the XML name of the attribute, localName cannot be null 1.76 + * @param value the attribute value to set, may not be null 1.77 + * @return the Attribute with specified values 1.78 + */ 1.79 + public Attribute createAttribute(String localName, String value) { 1.80 + AttributeBase attr = new AttributeBase(localName, value); 1.81 + if(location != null)attr.setLocation(location); 1.82 + return attr; 1.83 + } 1.84 + 1.85 + public Attribute createAttribute(QName name, String value) { 1.86 + AttributeBase attr = new AttributeBase(name, value); 1.87 + if(location != null)attr.setLocation(location); 1.88 + return attr; 1.89 + } 1.90 + 1.91 + /** 1.92 + * Create a new default Namespace 1.93 + * @param namespaceURI the default namespace uri 1.94 + * @return the Namespace with the specified value 1.95 + */ 1.96 + public Namespace createNamespace(String namespaceURI) { 1.97 + NamespaceBase event = new NamespaceBase(namespaceURI); 1.98 + if(location != null)event.setLocation(location); 1.99 + return event; 1.100 + } 1.101 + 1.102 + /** 1.103 + * Create a new Namespace 1.104 + * @param prefix the prefix of this namespace, may not be null 1.105 + * @param namespaceURI the attribute value is set to this value, may not be null 1.106 + * @return the Namespace with the specified values 1.107 + */ 1.108 + public Namespace createNamespace(String prefix, String namespaceURI) { 1.109 + NamespaceBase event = new NamespaceBase(prefix, namespaceURI); 1.110 + if(location != null)event.setLocation(location); 1.111 + return event; 1.112 + } 1.113 + 1.114 + /** 1.115 + * Create a new StartElement. 1.116 + * @param name the qualified name of the attribute, may not be null 1.117 + * @param attributes an optional unordered set of objects that 1.118 + * implement Attribute to add to the new StartElement, may be null 1.119 + * @param namespaces an optional unordered set of objects that 1.120 + * implement Namespace to add to the new StartElement, may be null 1.121 + * @return an instance of the requested StartElement 1.122 + */ 1.123 + public StartElement createStartElement(QName name, Iterator attributes, Iterator namespaces) { 1.124 + return createStartElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), attributes, namespaces); 1.125 + } 1.126 + 1.127 + public StartElement createStartElement(String prefix, String namespaceUri, String localName) { 1.128 + StartElementEvent event = new StartElementEvent(prefix, namespaceUri, localName); 1.129 + if(location != null)event.setLocation(location); 1.130 + return event; 1.131 + } 1.132 + 1.133 + public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces) { 1.134 + return createStartElement(prefix, namespaceUri, localName, attributes, namespaces, null); 1.135 + } 1.136 + 1.137 + public StartElement createStartElement(String prefix, String namespaceUri, String localName, Iterator attributes, Iterator namespaces, NamespaceContext context) { 1.138 + StartElementEvent elem = new StartElementEvent(prefix, namespaceUri, localName); 1.139 + elem.addAttributes(attributes); 1.140 + elem.addNamespaces(namespaces); 1.141 + elem.setNamespaceContext(context); 1.142 + if(location != null)elem.setLocation(location); 1.143 + return elem; 1.144 + } 1.145 + 1.146 + /** 1.147 + * Create a new EndElement 1.148 + * @param name the qualified name of the EndElement 1.149 + * @param namespaces an optional unordered set of objects that 1.150 + * implement Namespace that have gone out of scope, may be null 1.151 + * @return an instance of the requested EndElement 1.152 + */ 1.153 + public EndElement createEndElement(QName name, Iterator namespaces) { 1.154 + return createEndElement(name.getPrefix(), name.getNamespaceURI(), name.getLocalPart(), namespaces); 1.155 + } 1.156 + 1.157 + /** 1.158 + * Create a new EndElement 1.159 + * @param namespaceUri the uri of the QName of the new StartElement 1.160 + * @param localName the local name of the QName of the new StartElement 1.161 + * @param prefix the prefix of the QName of the new StartElement 1.162 + * @return an instance of the requested EndElement 1.163 + */ 1.164 + public EndElement createEndElement(String prefix, String namespaceUri, String localName) { 1.165 + EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName); 1.166 + if(location != null)event.setLocation(location); 1.167 + return event; 1.168 + } 1.169 + 1.170 + /** 1.171 + * Create a new EndElement 1.172 + * @param namespaceUri the uri of the QName of the new StartElement 1.173 + * @param localName the local name of the QName of the new StartElement 1.174 + * @param prefix the prefix of the QName of the new StartElement 1.175 + * @param namespaces an unordered set of objects that implement 1.176 + * Namespace that have gone out of scope, may be null 1.177 + * @return an instance of the requested EndElement 1.178 + */ 1.179 + public EndElement createEndElement(String prefix, String namespaceUri, String localName, Iterator namespaces) { 1.180 + 1.181 + EndElementEvent event = new EndElementEvent(prefix, namespaceUri, localName); 1.182 + if(namespaces!=null){ 1.183 + while(namespaces.hasNext()) 1.184 + event.addNamespace((Namespace)namespaces.next()); 1.185 + } 1.186 + if(location != null)event.setLocation(location); 1.187 + return event; 1.188 + } 1.189 + 1.190 + /** 1.191 + * Create a Characters event, this method does not check if the content 1.192 + * is all whitespace. To create a space event use #createSpace(String) 1.193 + * @param content the string to create 1.194 + * @return a Characters event 1.195 + */ 1.196 + public Characters createCharacters(String content) { 1.197 + CharactersEvent charEvent = new CharactersEvent(content); 1.198 + if(location != null)charEvent.setLocation(location); 1.199 + return charEvent; 1.200 + } 1.201 + 1.202 + /** 1.203 + * Create a Characters event with the CData flag set to true 1.204 + * @param content the string to create 1.205 + * @return a Characters event 1.206 + */ 1.207 + public Characters createCData(String content) { 1.208 + CharactersEvent charEvent = new CharactersEvent(content, true); 1.209 + if(location != null)charEvent.setLocation(location); 1.210 + return charEvent; 1.211 + } 1.212 + 1.213 + /** 1.214 + * Create a Characters event with the isSpace flag set to true 1.215 + * @param content the content of the space to create 1.216 + * @return a Characters event 1.217 + */ 1.218 + public Characters createSpace(String content) { 1.219 + CharactersEvent event = new CharactersEvent(content); 1.220 + event.setSpace(true); 1.221 + if(location != null)event.setLocation(location); 1.222 + return event; 1.223 + } 1.224 + /** 1.225 + * Create an ignorable space 1.226 + * @param content the space to create 1.227 + * @return a Characters event 1.228 + */ 1.229 + public Characters createIgnorableSpace(String content) { 1.230 + CharactersEvent event = new CharactersEvent(content, false); 1.231 + event.setSpace(true); 1.232 + event.setIgnorable(true); 1.233 + if(location != null)event.setLocation(location); 1.234 + return event; 1.235 + } 1.236 + /** 1.237 + * Creates a new instance of a StartDocument event 1.238 + * @return a StartDocument event 1.239 + */ 1.240 + public StartDocument createStartDocument() { 1.241 + StartDocumentEvent event = new StartDocumentEvent(); 1.242 + if(location != null)event.setLocation(location); 1.243 + return event; 1.244 + } 1.245 + 1.246 + /** 1.247 + * Creates a new instance of a StartDocument event 1.248 + * 1.249 + * @param encoding the encoding style 1.250 + * @return a StartDocument event 1.251 + */ 1.252 + public StartDocument createStartDocument(String encoding) { 1.253 + StartDocumentEvent event = new StartDocumentEvent(encoding); 1.254 + if(location != null)event.setLocation(location); 1.255 + return event; 1.256 + } 1.257 + 1.258 + /** 1.259 + * Creates a new instance of a StartDocument event 1.260 + * 1.261 + * @param encoding the encoding style 1.262 + * @param version the XML version 1.263 + * @return a StartDocument event 1.264 + */ 1.265 + public StartDocument createStartDocument(String encoding, String version) { 1.266 + StartDocumentEvent event = new StartDocumentEvent(encoding, version); 1.267 + if(location != null)event.setLocation(location); 1.268 + return event; 1.269 + } 1.270 + 1.271 + /** 1.272 + * Creates a new instance of a StartDocument event 1.273 + * 1.274 + * @param encoding the encoding style 1.275 + * @param version the XML version 1.276 + * @param standalone the status of standalone may be set to "true" or "false" 1.277 + * @return a StartDocument event 1.278 + */ 1.279 + public StartDocument createStartDocument(String encoding, String version, boolean standalone) { 1.280 + StartDocumentEvent event = new StartDocumentEvent(encoding, version); 1.281 + event.setStandalone(standalone); 1.282 + if(location != null)event.setLocation(location); 1.283 + return event; 1.284 + } 1.285 + 1.286 + public EndDocument createEndDocument() { 1.287 + EndDocumentEvent event =new EndDocumentEvent(); 1.288 + if(location != null)event.setLocation(location); 1.289 + return event; 1.290 + } 1.291 + 1.292 + /** Creates a new instance of a EntityReference event 1.293 + * 1.294 + * @param name The name of the reference 1.295 + * @param entityDeclaration the declaration for the event 1.296 + * @return an EntityReference event 1.297 + */ 1.298 + public EntityReference createEntityReference(String name, EntityDeclaration entityDeclaration) { 1.299 + EntityReferenceEvent event = new EntityReferenceEvent(name, entityDeclaration); 1.300 + if(location != null)event.setLocation(location); 1.301 + return event; 1.302 + } 1.303 + 1.304 + /** 1.305 + * Create a comment 1.306 + * @param text The text of the comment 1.307 + * a Comment event 1.308 + */ 1.309 + public Comment createComment(String text) { 1.310 + CommentEvent charEvent = new CommentEvent(text); 1.311 + if(location != null)charEvent.setLocation(location); 1.312 + return charEvent; 1.313 + } 1.314 + 1.315 + /** 1.316 + * Create a document type definition event 1.317 + * This string contains the entire document type declaration that matches 1.318 + * the doctypedecl in the XML 1.0 specification 1.319 + * @param dtd the text of the document type definition 1.320 + * @return a DTD event 1.321 + */ 1.322 + public DTD createDTD(String dtd) { 1.323 + DTDEvent dtdEvent = new DTDEvent(dtd); 1.324 + if(location != null)dtdEvent.setLocation(location); 1.325 + return dtdEvent; 1.326 + } 1.327 + 1.328 + 1.329 + /** 1.330 + * Create a processing instruction 1.331 + * @param target The target of the processing instruction 1.332 + * @param data The text of the processing instruction 1.333 + * @return a ProcessingInstruction event 1.334 + */ 1.335 + public ProcessingInstruction createProcessingInstruction(String target, String data) { 1.336 + ProcessingInstructionEvent event = new ProcessingInstructionEvent(target, data); 1.337 + if(location != null)event.setLocation(location); 1.338 + return event; 1.339 + } 1.340 + 1.341 + 1.342 + 1.343 + 1.344 + 1.345 +}