Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/javax/xml/stream/XMLEventFactory.java
48534 views
/*1* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.2*3* This code is free software; you can redistribute it and/or modify it4* under the terms of the GNU General Public License version 2 only, as5* published by the Free Software Foundation. Oracle designates this6* particular file as subject to the "Classpath" exception as provided7* by Oracle in the LICENSE file that accompanied this code.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*/2324/*25* Copyright (c) 2009, 2013, by Oracle Corporation. All Rights Reserved.26*/2728package javax.xml.stream;29import java.util.Iterator;30import javax.xml.namespace.NamespaceContext;31import javax.xml.namespace.QName;32import javax.xml.stream.events.*;33/**34* This interface defines a utility class for creating instances of35* XMLEvents36* @version 1.237* @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.38* @see javax.xml.stream.events.StartElement39* @see javax.xml.stream.events.EndElement40* @see javax.xml.stream.events.ProcessingInstruction41* @see javax.xml.stream.events.Comment42* @see javax.xml.stream.events.Characters43* @see javax.xml.stream.events.StartDocument44* @see javax.xml.stream.events.EndDocument45* @see javax.xml.stream.events.DTD46* @since 1.647*/48public abstract class XMLEventFactory {49protected XMLEventFactory(){}5051static final String JAXPFACTORYID = "javax.xml.stream.XMLEventFactory";52static final String DEFAULIMPL = "com.sun.xml.internal.stream.events.XMLEventFactoryImpl";535455/**56* Creates a new instance of the factory in exactly the same manner as the57* {@link #newFactory()} method.58* @throws FactoryConfigurationError if an instance of this factory cannot be loaded59*/60public static XMLEventFactory newInstance()61throws FactoryConfigurationError62{63return FactoryFinder.find(XMLEventFactory.class, DEFAULIMPL);64}6566/**67* Create a new instance of the factory.68* <p>69* This static method creates a new factory instance.70* This method uses the following ordered lookup procedure to determine71* the XMLEventFactory implementation class to load:72* </p>73* <ul>74* <li>75* Use the javax.xml.stream.XMLEventFactory system property.76* </li>77* <li>78* Use the properties file "lib/stax.properties" in the JRE directory.79* This configuration file is in standard java.util.Properties format80* and contains the fully qualified name of the implementation class81* with the key being the system property defined above.82* </li>83* <li>84* Use the service-provider loading facilities, defined by the85* {@link java.util.ServiceLoader} class, to attempt to locate and load an86* implementation of the service using the {@linkplain87* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism}:88* the service-provider loading facility will use the {@linkplain89* java.lang.Thread#getContextClassLoader() current thread's context class loader}90* to attempt to load the service. If the context class91* loader is null, the {@linkplain92* ClassLoader#getSystemClassLoader() system class loader} will be used.93* </li>94* <li>95* Otherwise, the system-default implementation is returned.96* </li>97* </ul>98* <p>99* Once an application has obtained a reference to a XMLEventFactory it100* can use the factory to configure and obtain stream instances.101* </p>102* <p>103* Note that this is a new method that replaces the deprecated newInstance() method.104* No changes in behavior are defined by this replacement method relative to105* the deprecated method.106* </p>107* @throws FactoryConfigurationError in case of {@linkplain108* java.util.ServiceConfigurationError service configuration error} or if109* the implementation is not available or cannot be instantiated.110*/111public static XMLEventFactory newFactory()112throws FactoryConfigurationError113{114return FactoryFinder.find(XMLEventFactory.class, DEFAULIMPL);115}116117/**118* Create a new instance of the factory119*120* @param factoryId Name of the factory to find, same as121* a property name122* @param classLoader classLoader to use123* @return the factory implementation124* @throws FactoryConfigurationError if an instance of this factory cannot be loaded125*126* @deprecated This method has been deprecated to maintain API consistency.127* All newInstance methods have been replaced with corresponding128* newFactory methods. The replacement {@link129* #newFactory(java.lang.String, java.lang.ClassLoader)}130* method defines no changes in behavior.131*/132public static XMLEventFactory newInstance(String factoryId,133ClassLoader classLoader)134throws FactoryConfigurationError {135//do not fallback if given classloader can't find the class, throw exception136return FactoryFinder.find(XMLEventFactory.class, factoryId, classLoader, null);137}138139/**140* Create a new instance of the factory.141* If the classLoader argument is null, then the ContextClassLoader is used.142* <p>143* This method uses the following ordered lookup procedure to determine144* the XMLEventFactory implementation class to load:145* </p>146* <ul>147* <li>148* Use the value of the system property identified by {@code factoryId}.149* </li>150* <li>151* Use the properties file "lib/stax.properties" in the JRE directory.152* This configuration file is in standard java.util.Properties format153* and contains the fully qualified name of the implementation class154* with the key being the given {@code factoryId}.155* </li>156* <li>157* If {@code factoryId} is "javax.xml.stream.XMLEventFactory",158* use the service-provider loading facilities, defined by the159* {@link java.util.ServiceLoader} class, to attempt to {@linkplain160* java.util.ServiceLoader#load(java.lang.Class, java.lang.ClassLoader) locate and load}161* an implementation of the service using the specified {@code ClassLoader}.162* If {@code classLoader} is null, the {@linkplain163* java.util.ServiceLoader#load(java.lang.Class) default loading mechanism} will apply:164* That is, the service-provider loading facility will use the {@linkplain165* java.lang.Thread#getContextClassLoader() current thread's context class loader}166* to attempt to load the service. If the context class167* loader is null, the {@linkplain168* ClassLoader#getSystemClassLoader() system class loader} will be used.169* </li>170* <li>171* Otherwise, throws a {@link FactoryConfigurationError}.172* </li>173* </ul>174*175* <p>176* Note that this is a new method that replaces the deprecated177* {@link #newInstance(java.lang.String, java.lang.ClassLoader)178* newInstance(String factoryId, ClassLoader classLoader)} method.179* No changes in behavior are defined by this replacement method relative180* to the deprecated method.181* </p>182*183* @apiNote The parameter factoryId defined here is inconsistent with that184* of other JAXP factories where the first parameter is fully qualified185* factory class name that provides implementation of the factory.186*187* @param factoryId Name of the factory to find, same as188* a property name189* @param classLoader classLoader to use190* @return the factory implementation191* @throws FactoryConfigurationError in case of {@linkplain192* java.util.ServiceConfigurationError service configuration error} or if193* the implementation is not available or cannot be instantiated.194*/195public static XMLEventFactory newFactory(String factoryId,196ClassLoader classLoader)197throws FactoryConfigurationError {198//do not fallback if given classloader can't find the class, throw exception199return FactoryFinder.find(XMLEventFactory.class, factoryId, classLoader, null);200}201202/**203* This method allows setting of the Location on each event that204* is created by this factory. The values are copied by value into205* the events created by this factory. To reset the location206* information set the location to null.207* @param location the location to set on each event created208*/209public abstract void setLocation(Location location);210211/**212* Create a new Attribute213* @param prefix the prefix of this attribute, may not be null214* @param namespaceURI the attribute value is set to this value, may not be null215* @param localName the local name of the XML name of the attribute, localName cannot be null216* @param value the attribute value to set, may not be null217* @return the Attribute with specified values218*/219public abstract Attribute createAttribute(String prefix, String namespaceURI, String localName, String value);220221/**222* Create a new Attribute223* @param localName the local name of the XML name of the attribute, localName cannot be null224* @param value the attribute value to set, may not be null225* @return the Attribute with specified values226*/227public abstract Attribute createAttribute(String localName, String value);228229/**230* Create a new Attribute231* @param name the qualified name of the attribute, may not be null232* @param value the attribute value to set, may not be null233* @return the Attribute with specified values234*/235public abstract Attribute createAttribute(QName name, String value);236237/**238* Create a new default Namespace239* @param namespaceURI the default namespace uri240* @return the Namespace with the specified value241*/242public abstract Namespace createNamespace(String namespaceURI);243244/**245* Create a new Namespace246* @param prefix the prefix of this namespace, may not be null247* @param namespaceUri the attribute value is set to this value, may not be null248* @return the Namespace with the specified values249*/250public abstract Namespace createNamespace(String prefix, String namespaceUri);251252/**253* Create a new StartElement. Namespaces can be added to this StartElement254* by passing in an Iterator that walks over a set of Namespace interfaces.255* Attributes can be added to this StartElement by passing an iterator256* that walks over a set of Attribute interfaces.257*258* @param name the qualified name of the attribute, may not be null259* @param attributes an optional unordered set of objects that260* implement Attribute to add to the new StartElement, may be null261* @param namespaces an optional unordered set of objects that262* implement Namespace to add to the new StartElement, may be null263* @return an instance of the requested StartElement264*/265public abstract StartElement createStartElement(QName name,266Iterator attributes,267Iterator namespaces);268269/**270* Create a new StartElement. This defaults the NamespaceContext to271* an empty NamespaceContext. Querying this event for its namespaces or272* attributes will result in an empty iterator being returned.273*274* @param namespaceUri the uri of the QName of the new StartElement275* @param localName the local name of the QName of the new StartElement276* @param prefix the prefix of the QName of the new StartElement277* @return an instance of the requested StartElement278*/279public abstract StartElement createStartElement(String prefix,280String namespaceUri,281String localName);282/**283* Create a new StartElement. Namespaces can be added to this StartElement284* by passing in an Iterator that walks over a set of Namespace interfaces.285* Attributes can be added to this StartElement by passing an iterator286* that walks over a set of Attribute interfaces.287*288* @param namespaceUri the uri of the QName of the new StartElement289* @param localName the local name of the QName of the new StartElement290* @param prefix the prefix of the QName of the new StartElement291* @param attributes an unordered set of objects that implement292* Attribute to add to the new StartElement293* @param namespaces an unordered set of objects that implement294* Namespace to add to the new StartElement295* @return an instance of the requested StartElement296*/297public abstract StartElement createStartElement(String prefix,298String namespaceUri,299String localName,300Iterator attributes,301Iterator namespaces302);303/**304* Create a new StartElement. Namespaces can be added to this StartElement305* by passing in an Iterator that walks over a set of Namespace interfaces.306* Attributes can be added to this StartElement by passing an iterator307* that walks over a set of Attribute interfaces.308*309* @param namespaceUri the uri of the QName of the new StartElement310* @param localName the local name of the QName of the new StartElement311* @param prefix the prefix of the QName of the new StartElement312* @param attributes an unordered set of objects that implement313* Attribute to add to the new StartElement, may be null314* @param namespaces an unordered set of objects that implement315* Namespace to add to the new StartElement, may be null316* @param context the namespace context of this element317* @return an instance of the requested StartElement318*/319public abstract StartElement createStartElement(String prefix,320String namespaceUri,321String localName,322Iterator attributes,323Iterator namespaces,324NamespaceContext context325);326327/**328* Create a new EndElement329* @param name the qualified name of the EndElement330* @param namespaces an optional unordered set of objects that331* implement Namespace that have gone out of scope, may be null332* @return an instance of the requested EndElement333*/334public abstract EndElement createEndElement(QName name,335Iterator namespaces);336337/**338* Create a new EndElement339* @param namespaceUri the uri of the QName of the new StartElement340* @param localName the local name of the QName of the new StartElement341* @param prefix the prefix of the QName of the new StartElement342* @return an instance of the requested EndElement343*/344public abstract EndElement createEndElement(String prefix,345String namespaceUri,346String localName);347/**348* Create a new EndElement349* @param namespaceUri the uri of the QName of the new StartElement350* @param localName the local name of the QName of the new StartElement351* @param prefix the prefix of the QName of the new StartElement352* @param namespaces an unordered set of objects that implement353* Namespace that have gone out of scope, may be null354* @return an instance of the requested EndElement355*/356public abstract EndElement createEndElement(String prefix,357String namespaceUri,358String localName,359Iterator namespaces);360361/**362* Create a Characters event, this method does not check if the content363* is all whitespace. To create a space event use #createSpace(String)364* @param content the string to create365* @return a Characters event366*/367public abstract Characters createCharacters(String content);368369/**370* Create a Characters event with the CData flag set to true371* @param content the string to create372* @return a Characters event373*/374public abstract Characters createCData(String content);375376/**377* Create a Characters event with the isSpace flag set to true378* @param content the content of the space to create379* @return a Characters event380*/381public abstract Characters createSpace(String content);382/**383* Create an ignorable space384* @param content the space to create385* @return a Characters event386*/387public abstract Characters createIgnorableSpace(String content);388389/**390* Creates a new instance of a StartDocument event391* @return a StartDocument event392*/393public abstract StartDocument createStartDocument();394395/**396* Creates a new instance of a StartDocument event397*398* @param encoding the encoding style399* @param version the XML version400* @param standalone the status of standalone may be set to "true" or "false"401* @return a StartDocument event402*/403public abstract StartDocument createStartDocument(String encoding,404String version,405boolean standalone);406407/**408* Creates a new instance of a StartDocument event409*410* @param encoding the encoding style411* @param version the XML version412* @return a StartDocument event413*/414public abstract StartDocument createStartDocument(String encoding,415String version);416417/**418* Creates a new instance of a StartDocument event419*420* @param encoding the encoding style421* @return a StartDocument event422*/423public abstract StartDocument createStartDocument(String encoding);424425/**426* Creates a new instance of an EndDocument event427* @return an EndDocument event428*/429public abstract EndDocument createEndDocument();430431/** Creates a new instance of a EntityReference event432*433* @param name The name of the reference434* @param declaration the declaration for the event435* @return an EntityReference event436*/437public abstract EntityReference createEntityReference(String name,438EntityDeclaration declaration);439/**440* Create a comment441* @param text The text of the comment442* a Comment event443*/444public abstract Comment createComment(String text);445446/**447* Create a processing instruction448* @param target The target of the processing instruction449* @param data The text of the processing instruction450* @return a ProcessingInstruction event451*/452public abstract ProcessingInstruction createProcessingInstruction(String target,453String data);454455/**456* Create a document type definition event457* This string contains the entire document type declaration that matches458* the doctypedecl in the XML 1.0 specification459* @param dtd the text of the document type definition460* @return a DTD event461*/462public abstract DTD createDTD(String dtd);463}464465466