Imported GNU Classpath 0.90
[official-gcc.git] / libjava / classpath / gnu / xml / stream / XMLEventFactoryImpl.java
blobe1d7d6ab82f5729d47abe3883f94495d736cb682
1 /* XMLEventFactoryImpl.java --
2 Copyright (C) 2005,2006 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19 02110-1301 USA.
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
24 combination.
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package gnu.xml.stream;
40 import java.util.Collections;
41 import java.util.Iterator;
42 import java.util.LinkedList;
43 import javax.xml.XMLConstants;
44 import javax.xml.namespace.NamespaceContext;
45 import javax.xml.namespace.QName;
46 import javax.xml.stream.Location;
47 import javax.xml.stream.XMLEventFactory;
48 import javax.xml.stream.events.Attribute;
49 import javax.xml.stream.events.Characters;
50 import javax.xml.stream.events.Comment;
51 import javax.xml.stream.events.DTD;
52 import javax.xml.stream.events.EndDocument;
53 import javax.xml.stream.events.EndElement;
54 import javax.xml.stream.events.EntityDeclaration;
55 import javax.xml.stream.events.EntityReference;
56 import javax.xml.stream.events.Namespace;
57 import javax.xml.stream.events.ProcessingInstruction;
58 import javax.xml.stream.events.StartDocument;
59 import javax.xml.stream.events.StartElement;
61 /**
62 * Factory for XML events.
64 * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a>
66 public class XMLEventFactoryImpl
67 extends XMLEventFactory
70 protected Location location;
72 public void setLocation(Location location)
74 this.location = location;
77 public Attribute createAttribute(String prefix, String namespaceURI,
78 String localName, String value)
80 return new AttributeImpl(location,
81 new QName(namespaceURI, localName, prefix),
82 value, QName.valueOf("CDATA"), true);
85 public Attribute createAttribute(String localName, String value)
87 return new AttributeImpl(location,
88 new QName(localName),
89 value, QName.valueOf("CDATA"), true);
92 public Attribute createAttribute(QName name, String value)
94 return new AttributeImpl(location, name, value,
95 QName.valueOf("CDATA"), true);
98 public Namespace createNamespace(String namespaceURI)
100 return new NamespaceImpl(location,
101 XMLConstants.DEFAULT_NS_PREFIX, namespaceURI);
104 public Namespace createNamespace(String prefix, String namespaceUri)
106 return new NamespaceImpl(location, prefix, namespaceUri);
109 public StartElement createStartElement(QName name,
110 Iterator attributes,
111 Iterator namespaces)
113 return new StartElementImpl(location, name,
114 createLinkedList(attributes),
115 createLinkedList(namespaces),
116 null);
119 public StartElement createStartElement(String prefix,
120 String namespaceUri,
121 String localName)
123 return new StartElementImpl(location,
124 new QName(namespaceUri, localName, prefix),
125 Collections.EMPTY_LIST,
126 Collections.EMPTY_LIST,
127 null);
130 public StartElement createStartElement(String prefix,
131 String namespaceUri,
132 String localName,
133 Iterator attributes,
134 Iterator namespaces)
136 return new StartElementImpl(location,
137 new QName(namespaceUri, localName, prefix),
138 createLinkedList(attributes),
139 createLinkedList(namespaces),
140 null);
143 public StartElement createStartElement(String prefix,
144 String namespaceUri,
145 String localName,
146 Iterator attributes,
147 Iterator namespaces,
148 NamespaceContext context)
150 return new StartElementImpl(location,
151 new QName(namespaceUri, localName, prefix),
152 createLinkedList(attributes),
153 createLinkedList(namespaces),
154 context);
157 public EndElement createEndElement(QName name,
158 Iterator namespaces)
160 return new EndElementImpl(location, name,
161 createLinkedList(namespaces));
164 public EndElement createEndElement(String prefix,
165 String namespaceUri,
166 String localName)
168 return new EndElementImpl(location,
169 new QName(namespaceUri, localName, prefix),
170 Collections.EMPTY_LIST);
173 public EndElement createEndElement(String prefix,
174 String namespaceUri,
175 String localName,
176 Iterator namespaces)
178 return new EndElementImpl(location,
179 new QName(namespaceUri, localName, prefix),
180 createLinkedList(namespaces));
183 public Characters createCharacters(String content)
185 return new CharactersImpl(location, content, false, false, false);
188 public Characters createCData(String content)
190 return new CharactersImpl(location, content, false, true, false);
193 public Characters createSpace(String content)
195 return new CharactersImpl(location, content, true, false, false);
198 public Characters createIgnorableSpace(String content)
200 return new CharactersImpl(location, content, true, false, true);
203 public StartDocument createStartDocument()
205 return new StartDocumentImpl(location, null, "UTF-8", "1.0",
206 false, false, false);
209 public StartDocument createStartDocument(String encoding,
210 String version,
211 boolean standalone)
213 return new StartDocumentImpl(location, null, encoding, version,
214 standalone, true, true);
217 public StartDocument createStartDocument(String encoding,
218 String version)
220 return new StartDocumentImpl(location, null, encoding, version,
221 false, false, true);
224 public StartDocument createStartDocument(String encoding)
226 return new StartDocumentImpl(location, null, encoding, "1.0",
227 false, false, true);
230 public EndDocument createEndDocument()
232 return new EndDocumentImpl(location);
235 public EntityReference createEntityReference(String name,
236 EntityDeclaration declaration)
238 return new EntityReferenceImpl(location, declaration, name);
241 public Comment createComment(String text)
243 return new CommentImpl(location, text);
246 public ProcessingInstruction createProcessingInstruction(String target,
247 String data)
249 return new ProcessingInstructionImpl(location, target, data);
252 public DTD createDTD(String dtd)
254 return new DTDImpl(location, dtd, null,
255 Collections.EMPTY_LIST,
256 Collections.EMPTY_LIST);
259 LinkedList createLinkedList(Iterator i)
261 LinkedList ret = new LinkedList();
262 while (i.hasNext())
263 ret.add(i.next());
264 return ret;