286N/A/*
286N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
286N/A *
286N/A * This code is free software; you can redistribute it and/or modify it
286N/A * under the terms of the GNU General Public License version 2 only, as
286N/A * published by the Free Software Foundation. Oracle designates this
286N/A * particular file as subject to the "Classpath" exception as provided
286N/A * by Oracle in the LICENSE file that accompanied this code.
286N/A *
286N/A * This code is distributed in the hope that it will be useful, but WITHOUT
286N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
286N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
286N/A * version 2 for more details (a copy is included in the LICENSE file that
286N/A * accompanied this code).
286N/A *
286N/A * You should have received a copy of the GNU General Public License version
286N/A * 2 along with this work; if not, write to the Free Software Foundation,
286N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
286N/A *
286N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
286N/A * or visit www.oracle.com if you need additional information or have any
286N/A * questions.
286N/A */
286N/A
286N/A/*
286N/A * Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
286N/A */
286N/A
286N/Apackage javax.xml.stream;
286N/Aimport javax.xml.stream.events.*;
286N/Aimport javax.xml.namespace.NamespaceContext;
286N/Aimport javax.xml.namespace.QName;
286N/Aimport java.util.Iterator;
286N/A/**
286N/A * This interface defines a utility class for creating instances of
286N/A * XMLEvents
286N/A * @version 1.2
286N/A * @author Copyright (c) 2009 by Oracle Corporation. All Rights Reserved.
286N/A * @see javax.xml.stream.events.StartElement
286N/A * @see javax.xml.stream.events.EndElement
286N/A * @see javax.xml.stream.events.ProcessingInstruction
286N/A * @see javax.xml.stream.events.Comment
286N/A * @see javax.xml.stream.events.Characters
286N/A * @see javax.xml.stream.events.StartDocument
286N/A * @see javax.xml.stream.events.EndDocument
286N/A * @see javax.xml.stream.events.DTD
286N/A * @since 1.6
286N/A */
286N/Apublic abstract class XMLEventFactory {
286N/A protected XMLEventFactory(){}
286N/A
406N/A static final String JAXPFACTORYID = "javax.xml.stream.XMLEventFactory";
406N/A static final String DEFAULIMPL = "com.sun.xml.internal.stream.events.XMLEventFactoryImpl";
406N/A
406N/A
286N/A /**
286N/A * Create a new instance of the factory
286N/A * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
286N/A */
286N/A public static XMLEventFactory newInstance()
286N/A throws FactoryConfigurationError
286N/A {
286N/A return (XMLEventFactory) FactoryFinder.find(
406N/A JAXPFACTORYID,
406N/A DEFAULIMPL);
286N/A }
286N/A
286N/A /**
286N/A * Create a new instance of the factory.
286N/A * This static method creates a new factory instance.
286N/A * This method uses the following ordered lookup procedure to determine
286N/A * the XMLEventFactory implementation class to load:
286N/A * Use the javax.xml.stream.XMLEventFactory system property.
286N/A * Use the properties file "lib/stax.properties" in the JRE directory.
286N/A * This configuration file is in standard java.util.Properties format
286N/A * and contains the fully qualified name of the implementation class
286N/A * with the key being the system property defined above.
286N/A * Use the Services API (as detailed in the JAR specification), if available,
286N/A * to determine the classname. The Services API will look for a classname
286N/A * in the file META-INF/services/javax.xml.stream.XMLEventFactory in jars
286N/A * available to the runtime.
286N/A * Platform default XMLEventFactory instance.
286N/A *
286N/A * Once an application has obtained a reference to a XMLEventFactory it
286N/A * can use the factory to configure and obtain stream instances.
286N/A *
286N/A * Note that this is a new method that replaces the deprecated newInstance() method.
286N/A * No changes in behavior are defined by this replacement method relative to
286N/A * the deprecated method.
286N/A *
286N/A * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
286N/A */
286N/A public static XMLEventFactory newFactory()
286N/A throws FactoryConfigurationError
286N/A {
286N/A return (XMLEventFactory) FactoryFinder.find(
406N/A JAXPFACTORYID,
406N/A DEFAULIMPL);
286N/A }
286N/A
286N/A /**
286N/A * Create a new instance of the factory
286N/A *
286N/A * @param factoryId Name of the factory to find, same as
286N/A * a property name
286N/A * @param classLoader classLoader to use
286N/A * @return the factory implementation
286N/A * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
286N/A *
286N/A * @deprecated This method has been deprecated to maintain API consistency.
286N/A * All newInstance methods have been replaced with corresponding
286N/A * newFactory methods. The replacement {@link
286N/A * #newFactory(java.lang.String, java.lang.ClassLoader)}
286N/A * method defines no changes in behavior.
286N/A */
286N/A public static XMLEventFactory newInstance(String factoryId,
286N/A ClassLoader classLoader)
286N/A throws FactoryConfigurationError {
286N/A try {
286N/A //do not fallback if given classloader can't find the class, throw exception
406N/A return (XMLEventFactory) FactoryFinder.find(factoryId, classLoader, null);
286N/A } catch (FactoryFinder.ConfigurationError e) {
286N/A throw new FactoryConfigurationError(e.getException(),
286N/A e.getMessage());
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * Create a new instance of the factory.
286N/A * If the classLoader argument is null, then the ContextClassLoader is used.
286N/A *
286N/A * Note that this is a new method that replaces the deprecated
286N/A * newInstance(String factoryId, ClassLoader classLoader) method.
286N/A * No changes in behavior are defined by this replacement method relative
286N/A * to the deprecated method.
286N/A *
286N/A * @param factoryId Name of the factory to find, same as
286N/A * a property name
286N/A * @param classLoader classLoader to use
286N/A * @return the factory implementation
286N/A * @throws FactoryConfigurationError if an instance of this factory cannot be loaded
286N/A */
286N/A public static XMLEventFactory newFactory(String factoryId,
286N/A ClassLoader classLoader)
286N/A throws FactoryConfigurationError {
286N/A try {
286N/A //do not fallback if given classloader can't find the class, throw exception
406N/A return (XMLEventFactory) FactoryFinder.find(factoryId, classLoader, null);
286N/A } catch (FactoryFinder.ConfigurationError e) {
286N/A throw new FactoryConfigurationError(e.getException(),
286N/A e.getMessage());
286N/A }
286N/A }
286N/A
286N/A /**
286N/A * This method allows setting of the Location on each event that
286N/A * is created by this factory. The values are copied by value into
286N/A * the events created by this factory. To reset the location
286N/A * information set the location to null.
286N/A * @param location the location to set on each event created
286N/A */
286N/A public abstract void setLocation(Location location);
286N/A
286N/A /**
286N/A * Create a new Attribute
286N/A * @param prefix the prefix of this attribute, may not be null
286N/A * @param namespaceURI the attribute value is set to this value, may not be null
286N/A * @param localName the local name of the XML name of the attribute, localName cannot be null
286N/A * @param value the attribute value to set, may not be null
286N/A * @return the Attribute with specified values
286N/A */
286N/A public abstract Attribute createAttribute(String prefix, String namespaceURI, String localName, String value);
286N/A
286N/A /**
286N/A * Create a new Attribute
286N/A * @param localName the local name of the XML name of the attribute, localName cannot be null
286N/A * @param value the attribute value to set, may not be null
286N/A * @return the Attribute with specified values
286N/A */
286N/A public abstract Attribute createAttribute(String localName, String value);
286N/A
286N/A /**
286N/A * Create a new Attribute
286N/A * @param name the qualified name of the attribute, may not be null
286N/A * @param value the attribute value to set, may not be null
286N/A * @return the Attribute with specified values
286N/A */
286N/A public abstract Attribute createAttribute(QName name, String value);
286N/A
286N/A /**
286N/A * Create a new default Namespace
286N/A * @param namespaceURI the default namespace uri
286N/A * @return the Namespace with the specified value
286N/A */
286N/A public abstract Namespace createNamespace(String namespaceURI);
286N/A
286N/A /**
286N/A * Create a new Namespace
286N/A * @param prefix the prefix of this namespace, may not be null
286N/A * @param namespaceUri the attribute value is set to this value, may not be null
286N/A * @return the Namespace with the specified values
286N/A */
286N/A public abstract Namespace createNamespace(String prefix, String namespaceUri);
286N/A
286N/A /**
286N/A * Create a new StartElement. Namespaces can be added to this StartElement
286N/A * by passing in an Iterator that walks over a set of Namespace interfaces.
286N/A * Attributes can be added to this StartElement by passing an iterator
286N/A * that walks over a set of Attribute interfaces.
286N/A *
286N/A * @param name the qualified name of the attribute, may not be null
286N/A * @param attributes an optional unordered set of objects that
286N/A * implement Attribute to add to the new StartElement, may be null
286N/A * @param namespaces an optional unordered set of objects that
286N/A * implement Namespace to add to the new StartElement, may be null
286N/A * @return an instance of the requested StartElement
286N/A */
286N/A public abstract StartElement createStartElement(QName name,
286N/A Iterator attributes,
286N/A Iterator namespaces);
286N/A
286N/A /**
286N/A * Create a new StartElement. This defaults the NamespaceContext to
286N/A * an empty NamespaceContext. Querying this event for its namespaces or
286N/A * attributes will result in an empty iterator being returned.
286N/A *
286N/A * @param namespaceUri the uri of the QName of the new StartElement
286N/A * @param localName the local name of the QName of the new StartElement
286N/A * @param prefix the prefix of the QName of the new StartElement
286N/A * @return an instance of the requested StartElement
286N/A */
286N/A public abstract StartElement createStartElement(String prefix,
286N/A String namespaceUri,
286N/A String localName);
286N/A /**
286N/A * Create a new StartElement. Namespaces can be added to this StartElement
286N/A * by passing in an Iterator that walks over a set of Namespace interfaces.
286N/A * Attributes can be added to this StartElement by passing an iterator
286N/A * that walks over a set of Attribute interfaces.
286N/A *
286N/A * @param namespaceUri the uri of the QName of the new StartElement
286N/A * @param localName the local name of the QName of the new StartElement
286N/A * @param prefix the prefix of the QName of the new StartElement
286N/A * @param attributes an unordered set of objects that implement
286N/A * Attribute to add to the new StartElement
286N/A * @param namespaces an unordered set of objects that implement
286N/A * Namespace to add to the new StartElement
286N/A * @return an instance of the requested StartElement
286N/A */
286N/A public abstract StartElement createStartElement(String prefix,
286N/A String namespaceUri,
286N/A String localName,
286N/A Iterator attributes,
286N/A Iterator namespaces
286N/A );
286N/A /**
286N/A * Create a new StartElement. Namespaces can be added to this StartElement
286N/A * by passing in an Iterator that walks over a set of Namespace interfaces.
286N/A * Attributes can be added to this StartElement by passing an iterator
286N/A * that walks over a set of Attribute interfaces.
286N/A *
286N/A * @param namespaceUri the uri of the QName of the new StartElement
286N/A * @param localName the local name of the QName of the new StartElement
286N/A * @param prefix the prefix of the QName of the new StartElement
286N/A * @param attributes an unordered set of objects that implement
286N/A * Attribute to add to the new StartElement, may be null
286N/A * @param namespaces an unordered set of objects that implement
286N/A * Namespace to add to the new StartElement, may be null
286N/A * @param context the namespace context of this element
286N/A * @return an instance of the requested StartElement
286N/A */
286N/A public abstract StartElement createStartElement(String prefix,
286N/A String namespaceUri,
286N/A String localName,
286N/A Iterator attributes,
286N/A Iterator namespaces,
286N/A NamespaceContext context
286N/A );
286N/A
286N/A /**
286N/A * Create a new EndElement
286N/A * @param name the qualified name of the EndElement
286N/A * @param namespaces an optional unordered set of objects that
286N/A * implement Namespace that have gone out of scope, may be null
286N/A * @return an instance of the requested EndElement
286N/A */
286N/A public abstract EndElement createEndElement(QName name,
286N/A Iterator namespaces);
286N/A
286N/A /**
286N/A * Create a new EndElement
286N/A * @param namespaceUri the uri of the QName of the new StartElement
286N/A * @param localName the local name of the QName of the new StartElement
286N/A * @param prefix the prefix of the QName of the new StartElement
286N/A * @return an instance of the requested EndElement
286N/A */
286N/A public abstract EndElement createEndElement(String prefix,
286N/A String namespaceUri,
286N/A String localName);
286N/A /**
286N/A * Create a new EndElement
286N/A * @param namespaceUri the uri of the QName of the new StartElement
286N/A * @param localName the local name of the QName of the new StartElement
286N/A * @param prefix the prefix of the QName of the new StartElement
286N/A * @param namespaces an unordered set of objects that implement
286N/A * Namespace that have gone out of scope, may be null
286N/A * @return an instance of the requested EndElement
286N/A */
286N/A public abstract EndElement createEndElement(String prefix,
286N/A String namespaceUri,
286N/A String localName,
286N/A Iterator namespaces);
286N/A
286N/A /**
286N/A * Create a Characters event, this method does not check if the content
286N/A * is all whitespace. To create a space event use #createSpace(String)
286N/A * @param content the string to create
286N/A * @return a Characters event
286N/A */
286N/A public abstract Characters createCharacters(String content);
286N/A
286N/A /**
286N/A * Create a Characters event with the CData flag set to true
286N/A * @param content the string to create
286N/A * @return a Characters event
286N/A */
286N/A public abstract Characters createCData(String content);
286N/A
286N/A /**
286N/A * Create a Characters event with the isSpace flag set to true
286N/A * @param content the content of the space to create
286N/A * @return a Characters event
286N/A */
286N/A public abstract Characters createSpace(String content);
286N/A /**
286N/A * Create an ignorable space
286N/A * @param content the space to create
286N/A * @return a Characters event
286N/A */
286N/A public abstract Characters createIgnorableSpace(String content);
286N/A
286N/A /**
286N/A * Creates a new instance of a StartDocument event
286N/A * @return a StartDocument event
286N/A */
286N/A public abstract StartDocument createStartDocument();
286N/A
286N/A /**
286N/A * Creates a new instance of a StartDocument event
286N/A *
286N/A * @param encoding the encoding style
286N/A * @param version the XML version
286N/A * @param standalone the status of standalone may be set to "true" or "false"
286N/A * @return a StartDocument event
286N/A */
286N/A public abstract StartDocument createStartDocument(String encoding,
286N/A String version,
286N/A boolean standalone);
286N/A
286N/A /**
286N/A * Creates a new instance of a StartDocument event
286N/A *
286N/A * @param encoding the encoding style
286N/A * @param version the XML version
286N/A * @return a StartDocument event
286N/A */
286N/A public abstract StartDocument createStartDocument(String encoding,
286N/A String version);
286N/A
286N/A /**
286N/A * Creates a new instance of a StartDocument event
286N/A *
286N/A * @param encoding the encoding style
286N/A * @return a StartDocument event
286N/A */
286N/A public abstract StartDocument createStartDocument(String encoding);
286N/A
286N/A /**
286N/A * Creates a new instance of an EndDocument event
286N/A * @return an EndDocument event
286N/A */
286N/A public abstract EndDocument createEndDocument();
286N/A
286N/A /** Creates a new instance of a EntityReference event
286N/A *
286N/A * @param name The name of the reference
286N/A * @param declaration the declaration for the event
286N/A * @return an EntityReference event
286N/A */
286N/A public abstract EntityReference createEntityReference(String name,
286N/A EntityDeclaration declaration);
286N/A /**
286N/A * Create a comment
286N/A * @param text The text of the comment
286N/A * a Comment event
286N/A */
286N/A public abstract Comment createComment(String text);
286N/A
286N/A /**
286N/A * Create a processing instruction
286N/A * @param target The target of the processing instruction
286N/A * @param data The text of the processing instruction
286N/A * @return a ProcessingInstruction event
286N/A */
286N/A public abstract ProcessingInstruction createProcessingInstruction(String target,
286N/A String data);
286N/A
286N/A /**
286N/A * Create a document type definition event
286N/A * This string contains the entire document type declaration that matches
286N/A * the doctypedecl in the XML 1.0 specification
286N/A * @param dtd the text of the document type definition
286N/A * @return a DTD event
286N/A */
286N/A public abstract DTD createDTD(String dtd);
286N/A}