KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > mapper > storage > BaseXMLReaderImpl


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.mapper.storage;
24
25 import java.io.IOException JavaDoc;
26
27 import org.xml.sax.*;
28 import org.xml.sax.ext.LexicalHandler JavaDoc;
29 import org.xquark.util.SAXConstants;
30 import org.xquark.xml.xdbc.XMLDBCException;
31
32
33 /** Common part ot the {@link org.xquark.mapper.XMLCollection XMLCollection}
34  * implementations.
35  *
36  */

37
38 public abstract class BaseXMLReaderImpl extends XMLBuilder
39 implements RepositoryReader, SAXConstants
40 {
41     private static final String JavaDoc RCSRevision = "$Revision: 1.1 $";
42     private static final String JavaDoc RCSName = "$Name: $";
43     //
44
// Data
45
//
46

47     // the repository instance
48

49     //
50
// Options
51
//
52
protected boolean restoreEnumeratedAttrTypes = false; // if true NMTOKEN attribute types generated
53
// (contrary as specified by SAX 2.0)
54
/** Constructor.
55      * @param name The name of the repository.
56      * @param config A CollectionConfig object.
57      * @exception java.sql.SQLException RDBMS exception.
58      */

59
60     public BaseXMLReaderImpl(_RepositoryCollection collection)
61     throws XMLDBCException
62     {
63         super(collection);
64     }
65
66     ///////////////////////////////////////////////////////////////////////////
67
// XMLReader implementation
68
///////////////////////////////////////////////////////////////////////////
69
public void parse(InputSource input)
70     throws IOException JavaDoc, SAXException
71     {
72         if (input.getSystemId() != null)
73             parse(input.getSystemId());
74         else
75             parse(input.getPublicId());
76     }
77     
78     public boolean getFeature(String JavaDoc name)
79     throws SAXNotRecognizedException, SAXNotSupportedException
80     {
81         if (name.equals(SAX_NAMESPACE_FEATURE))
82             return true;
83         else if (name.equals(SAX_PREFIX_FEATURE))
84             return false;
85         else if (name.equals(SAX_VALIDATION_FEATURE))
86             return false;
87         else
88             throw new SAXNotSupportedException("Unrecognized feature.");
89     }
90     public Object JavaDoc getProperty (String JavaDoc name)
91     throws SAXNotRecognizedException, SAXNotSupportedException
92     {
93         if (name.equals(SAX_LEXICAL_PROPERTY))
94             return lexicalHandler;
95         else
96             throw new SAXNotSupportedException("Unrecognized property.");
97     }
98
99     public ContentHandler getContentHandler ()
100     {
101         return contentHandler;
102     }
103     
104     public ErrorHandler getErrorHandler ()
105     {
106         return errorHandler;
107     }
108     
109     public EntityResolver getEntityResolver()
110     {
111         return null;
112     }
113
114     public DTDHandler getDTDHandler ()
115     {
116         return null;
117     }
118     
119     public void setContentHandler(ContentHandler handler)
120     {
121         contentHandler = handler;
122     }
123     
124     public void setDTDHandler(DTDHandler handler)
125     {
126         // No op : not supported
127
}
128
129     public void setErrorHandler(ErrorHandler handler)
130     {
131         errorHandler = handler;
132     }
133     
134     public void setEntityResolver(EntityResolver resolver)
135     {
136     }
137     
138     public void setFeature(String JavaDoc name,boolean value)
139     throws SAXNotRecognizedException, SAXNotSupportedException
140     {
141         if (name.equals(SAX_NAMESPACE_FEATURE))
142             {
143                 if (!value)
144                     throw new SAXNotSupportedException("This feature can only be set to true.");
145                 else
146                     return;
147             }
148         else if (name.equals(SAX_PREFIX_FEATURE))
149             {
150                 if (value)
151                     throw new SAXNotSupportedException("This feature can only be set to false.");
152                 else
153                     return;
154             }
155         else if (name.equals(SAX_VALIDATION_FEATURE))
156             return;
157         else
158             throw new SAXNotSupportedException("Unrecognized feature.");
159     }
160     
161     public void setProperty(String JavaDoc name,Object JavaDoc value)
162     throws SAXNotRecognizedException, SAXNotSupportedException
163     {
164         if (name.equals(SAX_LEXICAL_PROPERTY))
165             lexicalHandler = (LexicalHandler JavaDoc)value;
166         else
167             throw new SAXNotSupportedException("Unrecognized property.");
168     }
169     
170     ////////////////////////////////////////////////////////////////////////////////
171
// private Utilities
172
////////////////////////////////////////////////////////////////////////////////
173

174     //////////////////////
175
// Inner Classes
176
//////////////////////
177

178 } // class
179
Popular Tags