KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > xml > stream > XMLInputFactoryImpl


1 /*
2 * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3 *
4 * This file is part of Resin(R) Open Source
5 *
6 * Each copy or derived work must preserve the copyright notice and this
7 * notice unmodified.
8 *
9 * Resin Open Source is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * Resin Open Source is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17 * of NON-INFRINGEMENT. See the GNU General Public License for more
18 * details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Resin Open Source; if not, write to the
22 *
23 * Free Software Foundation, Inc.
24 * 59 Temple Place, Suite 330
25 * Boston, MA 02111-1307 USA
26 *
27 * @author Adam Megacz
28 */

29
30 package com.caucho.xml.stream;
31 import javax.xml.stream.*;
32 import javax.xml.stream.util.XMLEventAllocator;
33 import javax.xml.transform.Source JavaDoc;
34 import java.io.IOException JavaDoc;
35 import java.io.InputStream JavaDoc;
36 import java.io.InputStreamReader JavaDoc;
37 import java.io.Reader JavaDoc;
38
39 public class XMLInputFactoryImpl extends XMLInputFactory {
40
41   private XMLEventAllocator _allocator = new XMLEventAllocatorImpl();
42   private XMLReporter _reporter;
43   private XMLResolver _resolver;
44
45   public XMLInputFactoryImpl()
46   {
47   }
48
49   //
50
// Filtered
51
//
52

53   public XMLEventReader
54     createFilteredReader(XMLEventReader reader, EventFilter filter)
55     throws XMLStreamException
56   {
57     return new FilteredEventReader(reader, filter);
58   }
59
60   public XMLStreamReader
61     createFilteredReader(XMLStreamReader reader, StreamFilter filter)
62     throws XMLStreamException
63   {
64     return new FilteredStreamReader(reader, filter);
65   }
66
67   //
68
// Event reader
69
//
70

71   public XMLEventReader
72     createXMLEventReader(InputStream JavaDoc stream)
73     throws XMLStreamException
74   {
75     return new XMLEventReaderImpl(createXMLStreamReader(stream));
76   }
77
78   public XMLEventReader
79     createXMLEventReader(InputStream JavaDoc stream, String JavaDoc encoding)
80     throws XMLStreamException
81   {
82     return new XMLEventReaderImpl(createXMLStreamReader(stream, encoding));
83   }
84
85   public XMLEventReader
86     createXMLEventReader(Reader JavaDoc reader)
87     throws XMLStreamException
88   {
89     return new XMLEventReaderImpl(createXMLStreamReader(reader));
90   }
91
92   /**
93    * "Support of this method is optional."
94    */

95   public XMLEventReader
96     createXMLEventReader(Source JavaDoc source)
97     throws XMLStreamException
98   {
99     throw new JAXPNotSupportedInStAXException();
100   }
101
102   public XMLEventReader
103     createXMLEventReader(String JavaDoc systemId, InputStream JavaDoc stream)
104     throws XMLStreamException
105   {
106     return new XMLEventReaderImpl(createXMLStreamReader(systemId, stream));
107   }
108
109   public XMLEventReader
110     createXMLEventReader(String JavaDoc systemId, Reader JavaDoc reader)
111     throws XMLStreamException
112   {
113     return new XMLEventReaderImpl(createXMLStreamReader(systemId, reader));
114   }
115
116   public XMLEventReader
117     createXMLEventReader(XMLStreamReader reader)
118     throws XMLStreamException
119   {
120     return new XMLEventReaderImpl(reader);
121   }
122
123   //
124
// Stream reader
125
//
126

127   public XMLStreamReader
128     createXMLStreamReader(InputStream JavaDoc stream)
129     throws XMLStreamException
130   {
131     return new XMLStreamReaderImpl(stream);
132   }
133
134   public XMLStreamReader
135     createXMLStreamReader(InputStream JavaDoc stream, String JavaDoc encoding)
136     throws XMLStreamException
137   {
138     try {
139       InputStreamReader JavaDoc isr = new InputStreamReader JavaDoc(stream, encoding);
140       return new XMLStreamReaderImpl(isr);
141     }
142     catch (IOException JavaDoc e) {
143       throw new XMLStreamException(e);
144     }
145   }
146
147   public XMLStreamReader
148     createXMLStreamReader(Reader JavaDoc reader)
149     throws XMLStreamException
150   {
151     return new XMLStreamReaderImpl(reader);
152   }
153
154   /**
155    * "Support of this method is optional."
156    */

157   public XMLStreamReader
158     createXMLStreamReader(Source JavaDoc source)
159     throws XMLStreamException
160   {
161     throw new JAXPNotSupportedInStAXException();
162   }
163
164   public XMLStreamReader
165     createXMLStreamReader(String JavaDoc systemId, InputStream JavaDoc stream)
166     throws XMLStreamException
167   {
168     return new XMLStreamReaderImpl(stream, systemId);
169   }
170
171   public XMLStreamReader
172     createXMLStreamReader(String JavaDoc systemId, Reader JavaDoc reader)
173     throws XMLStreamException
174   {
175     return new XMLStreamReaderImpl(reader, systemId);
176   }
177
178   public XMLEventAllocator getEventAllocator()
179   {
180     return _allocator;
181   }
182
183   public Object JavaDoc getProperty(String JavaDoc name)
184     throws IllegalArgumentException JavaDoc
185   {
186     throw new IllegalArgumentException JavaDoc("property \""+name+"\" not supported");
187   }
188
189   public XMLReporter getXMLReporter()
190   {
191     return _reporter;
192   }
193
194   public XMLResolver getXMLResolver()
195   {
196     return _resolver;
197   }
198
199   public boolean isPropertySupported(String JavaDoc name)
200   {
201     return false;
202   }
203
204   public void setEventAllocator(XMLEventAllocator allocator)
205   {
206     _allocator = allocator;
207   }
208
209   public void setProperty(String JavaDoc name, Object JavaDoc value)
210     throws IllegalArgumentException JavaDoc
211   {
212
213     if ("javax.xml.stream.allocator".equals(name)) {
214       setEventAllocator((XMLEventAllocator)value);
215       return;
216     }
217
218     throw new IllegalArgumentException JavaDoc("property \""+name+"\" not supported");
219   }
220
221   public void setXMLReporter(XMLReporter reporter)
222   {
223     _reporter = reporter;
224   }
225
226   public void setXMLResolver(XMLResolver resolver)
227   {
228     _resolver = resolver;
229   }
230
231 }
232
233
Popular Tags