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)
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
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
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
;
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
,
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
,
113 return new StartElementImpl(location
, name
,
114 createLinkedList(attributes
),
115 createLinkedList(namespaces
),
119 public StartElement
createStartElement(String prefix
,
123 return new StartElementImpl(location
,
124 new QName(namespaceUri
, localName
, prefix
),
125 Collections
.EMPTY_LIST
,
126 Collections
.EMPTY_LIST
,
130 public StartElement
createStartElement(String prefix
,
136 return new StartElementImpl(location
,
137 new QName(namespaceUri
, localName
, prefix
),
138 createLinkedList(attributes
),
139 createLinkedList(namespaces
),
143 public StartElement
createStartElement(String prefix
,
148 NamespaceContext context
)
150 return new StartElementImpl(location
,
151 new QName(namespaceUri
, localName
, prefix
),
152 createLinkedList(attributes
),
153 createLinkedList(namespaces
),
157 public EndElement
createEndElement(QName name
,
160 return new EndElementImpl(location
, name
,
161 createLinkedList(namespaces
));
164 public EndElement
createEndElement(String prefix
,
168 return new EndElementImpl(location
,
169 new QName(namespaceUri
, localName
, prefix
),
170 Collections
.EMPTY_LIST
);
173 public EndElement
createEndElement(String prefix
,
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
,
213 return new StartDocumentImpl(location
, null, encoding
, version
,
214 standalone
, true, true);
217 public StartDocument
createStartDocument(String encoding
,
220 return new StartDocumentImpl(location
, null, encoding
, version
,
224 public StartDocument
createStartDocument(String encoding
)
226 return new StartDocumentImpl(location
, null, encoding
, "1.0",
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
,
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();