KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > jaxp > SAXParserFactoryImpl


1 /*
2  *
3  * The Apache Software License, Version 1.1
4  *
5  *
6  * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
7  * reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution,
22  * if any, must include the following acknowledgment:
23  * "This product includes software developed by the
24  * Apache Software Foundation (http://www.apache.org/)."
25  * Alternately, this acknowledgment may appear in the software itself,
26  * if and wherever such third-party acknowledgments normally appear.
27  *
28  * 4. The names "Xerces" and "Apache Software Foundation" must
29  * not be used to endorse or promote products derived from this
30  * software without prior written permission. For written
31  * permission, please contact apache@apache.org.
32  *
33  * 5. Products derived from this software may not be called "Apache",
34  * nor may "Apache" appear in their name, without prior written
35  * permission of the Apache Software Foundation.
36  *
37  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
38  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
40  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
41  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
42  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
43  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
44  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
45  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
46  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
48  * SUCH DAMAGE.
49  * ====================================================================
50  *
51  * This software consists of voluntary contributions made by many
52  * individuals on behalf of the Apache Software Foundation and was
53  * originally based on software copyright (c) 1999, Sun Microsystems, Inc.,
54  * http://www.sun.com. For more information on the Apache Software
55  * Foundation, please see <http://www.apache.org/>.
56  */

57
58
59 package com.sun.org.apache.xerces.internal.jaxp;
60
61 import java.util.Hashtable JavaDoc;
62
63 import javax.xml.XMLConstants JavaDoc;
64 import javax.xml.parsers.ParserConfigurationException JavaDoc;
65 import javax.xml.parsers.SAXParser JavaDoc;
66 import javax.xml.parsers.SAXParserFactory JavaDoc;
67 import javax.xml.validation.Schema JavaDoc;
68
69 import org.xml.sax.SAXException JavaDoc;
70 import org.xml.sax.SAXNotRecognizedException JavaDoc;
71 import org.xml.sax.SAXNotSupportedException JavaDoc;
72 /**
73  * @author Rajiv Mordani
74  * @author Edwin Goei
75  * @version $Id: SAXParserFactoryImpl.java,v 1.6 2003/11/18 00:22:59 kk122374 Exp $
76  */

77
78 /**
79  * This is the implementation specific class for the
80  * <code>javax.xml.parsers.SAXParserFactory</code>. This is the platform
81  * default implementation for the platform.
82  */

83 public class SAXParserFactoryImpl extends SAXParserFactory JavaDoc {
84     private Hashtable JavaDoc features;
85     private Schema JavaDoc grammar;
86     private boolean isXIncludeAware;
87
88     /**
89      * Creates a new instance of <code>SAXParser</code> using the currently
90      * configured factory parameters.
91      * @return javax.xml.parsers.SAXParser
92      */

93     public SAXParser JavaDoc newSAXParser()
94         throws ParserConfigurationException JavaDoc
95     {
96         SAXParser JavaDoc saxParserImpl;
97         try {
98             saxParserImpl = new SAXParserImpl(this, features);
99         } catch (SAXException JavaDoc se) {
100             // Translate to ParserConfigurationException
101
throw new ParserConfigurationException JavaDoc(se.getMessage());
102         }
103         return saxParserImpl;
104     }
105
106     /**
107      * Common code for translating exceptions
108      */

109     private SAXParserImpl newSAXParserImpl()
110         throws ParserConfigurationException JavaDoc, SAXNotRecognizedException JavaDoc,
111         SAXNotSupportedException JavaDoc
112     {
113         SAXParserImpl saxParserImpl;
114         try {
115             saxParserImpl = new SAXParserImpl(this, features);
116         } catch (SAXNotSupportedException JavaDoc e) {
117             throw e;
118         } catch (SAXNotRecognizedException JavaDoc e) {
119             throw e;
120         } catch (SAXException JavaDoc se) {
121             throw new ParserConfigurationException JavaDoc(se.getMessage());
122         }
123         return saxParserImpl;
124     }
125
126     /**
127      * Sets the particular feature in the underlying implementation of
128      * org.xml.sax.XMLReader.
129      */

130     public void setFeature(String JavaDoc name, boolean value)
131         throws ParserConfigurationException JavaDoc, SAXNotRecognizedException JavaDoc,
132         SAXNotSupportedException JavaDoc
133     {
134         // XXX This is ugly. We have to collect the features and then
135
// later create an XMLReader to verify the features.
136
if (features == null) {
137             features = new Hashtable JavaDoc();
138         }
139         features.put(name, value ? Boolean.TRUE : Boolean.FALSE);
140
141         // Test the feature by possibly throwing SAX exceptions
142
try {
143             newSAXParserImpl();
144         } catch (SAXNotSupportedException JavaDoc e) {
145             features.remove(name);
146             throw e;
147         } catch (SAXNotRecognizedException JavaDoc e) {
148             features.remove(name);
149             throw e;
150         }
151     }
152
153     /**
154      * returns the particular property requested for in the underlying
155      * implementation of org.xml.sax.XMLReader.
156      */

157     public boolean getFeature(String JavaDoc name)
158         throws ParserConfigurationException JavaDoc, SAXNotRecognizedException JavaDoc,
159         SAXNotSupportedException JavaDoc
160     {
161         // Check for valid name by creating a dummy XMLReader to get
162
// feature value
163
if(name.equals(XMLConstants.FEATURE_SECURE_PROCESSING) && features != null){
164             Boolean JavaDoc ob =(Boolean JavaDoc) features.get(name);
165             if(ob == null )
166                 return false;
167             return ob.booleanValue();
168         }
169         return newSAXParserImpl().getXMLReader().getFeature(name);
170     }
171     
172     public Schema JavaDoc getSchema() {
173         return grammar;
174     }
175
176     public void setSchema(Schema JavaDoc grammar) {
177         this.grammar = grammar;
178     }
179
180     
181     public boolean isXIncludeAware() {
182         return this.isXIncludeAware;
183     }
184
185     public void setXIncludeAware(boolean state) {
186         this.isXIncludeAware = state;
187     }
188 }
189
Popular Tags