KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > proactive > core > xml > io > DefaultHandlerAdapter


1 /*
2 * ################################################################
3 *
4 * ProActive: The Java(TM) library for Parallel, Distributed,
5 * Concurrent computing with Security and Mobility
6 *
7 * Copyright (C) 1997-2002 INRIA/University of Nice-Sophia Antipolis
8 * Contact: proactive-support@inria.fr
9 *
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or any later version.
14 *
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23 * USA
24 *
25 * Initial developer(s): The ProActive Team
26 * http://www.inria.fr/oasis/ProActive/contacts.html
27 * Contributor(s):
28 *
29 * ################################################################
30 */

31 package org.objectweb.proactive.core.xml.io;
32
33
34 /**
35  *
36  * Adaptor between the DefaultHandler from SAX API and the XMLHandler
37  *
38  * @author Lionel Mestre
39  * @version 0.91
40  *
41  */

42 public class DefaultHandlerAdapter extends org.xml.sax.helpers.DefaultHandler JavaDoc {
43   
44   protected XMLHandler targetHandler;
45   
46   
47   //
48
// -- CONSTRUCTORS -----------------------------------------------
49
//
50

51   public DefaultHandlerAdapter(XMLHandler targetHandler) {
52     this.targetHandler = targetHandler;
53   }
54
55
56   //
57
// -- PUBLIC METHODS -----------------------------------------------
58
//
59

60   //
61
// -- ContentHandler methods ------------------------------------------------------
62
//
63

64  /**
65   * startPrefixMapping.
66   * Receives notification of the start of a Namespace mapping.
67   */

68 // public void startPrefixMapping(String prefix, String uri) throws org.xml.sax.SAXException {
69
// //System.out.println("startPrefixMapping prefix="+prefix+" uri="+uri);
70
// targetHandler.startPrefixMapping(prefix, uri);
71
// }
72
//
73
//
74
// /**
75
// * endPrefixMapping.
76
// * Receive notification of the start of a Namespace mapping.
77
// */
78
// public void endPrefixMapping(String prefix) throws org.xml.sax.SAXException {
79
// //System.out.println("endPrefixMapping prefix="+prefix);
80
// targetHandler.endPrefixMapping(prefix);
81
// }
82

83     
84  /**
85   * Start element.
86   */

87   public void startElement(String JavaDoc namespaceURI, String JavaDoc localName,String JavaDoc qName, org.xml.sax.Attributes JavaDoc atts) throws org.xml.sax.SAXException JavaDoc {
88     //System.out.println("DefaultHandlerAdaptor startElement localName="+localName+" qName="+qName);
89
targetHandler.startElement(qName, new AttributesImpl(atts));
90   }
91
92
93  /**
94   * end element.
95   */

96   public void endElement(String JavaDoc namespaceURI, String JavaDoc localName,String JavaDoc qName) throws org.xml.sax.SAXException JavaDoc {
97     //System.out.println("DefaultHandlerAdaptor endElement localName="+localName+" qName="+qName);
98
targetHandler.endElement(qName);
99   }
100
101
102 // public void skippedEntity(java.lang.String name) {
103
// // ignore
104
// // System.out.println("skippedEntity "+name);
105
// }
106
//
107
//
108
// public void processingInstruction(java.lang.String target, java.lang.String data) {
109
// // ignore
110
// //System.out.println("processingInstruction target="+target+" data="+data);
111
// }
112

113   
114  /**
115   * Characters.
116   */

117   public void characters(char ch[], int start, int length) throws org.xml.sax.SAXException JavaDoc {
118     if (length > 0) {
119       char[] c = new char[length];
120       System.arraycopy(ch,start,c,0,length);
121       targetHandler.readValue(parseCharacterEntities(new String JavaDoc(c)));
122     }
123   }
124
125   
126 // /**
127
// * ignorableWhitespace.
128
// */
129
// public void ignorableWhitespace(char[] ch, int start, int length) throws org.xml.sax.SAXException {
130
// // ignore
131
// }
132

133   //
134
// -- ErrorHandler methods ------------------------------------------------------
135
//
136

137 // /**
138
// * Warning.
139
// */
140
// public void warning(org.xml.sax.SAXParseException ex) {
141
// System.err.println("[Warning] : "+ex.getMessage());
142
// }
143
//
144
// /** Error. */
145
// public void error(org.xml.sax.SAXParseException ex) {
146
// System.err.println("[Error] : "+ex.getMessage());
147
// }
148
//
149
// /** Fatal error. */
150
// public void fatalError(org.xml.sax.SAXParseException ex) throws org.xml.sax.SAXException {
151
// System.err.println("[Fatal Error] : "+ex.getMessage());
152
// throw ex;
153
// }
154

155
156   
157   //
158
// -- PROTECTED METHODS ------------------------------------------------------
159
//
160

161   protected class AttributesImpl implements Attributes {
162     private org.xml.sax.Attributes JavaDoc attributes;
163     AttributesImpl(org.xml.sax.Attributes JavaDoc attributes) {
164       this.attributes = attributes;
165     }
166     public String JavaDoc getValue(int index) { return attributes.getValue(index); }
167     public String JavaDoc getValue(String JavaDoc qName) { return attributes.getValue(qName); }
168     public String JavaDoc getValue(String JavaDoc uri, String JavaDoc localPart) { return attributes.getValue(uri,localPart); }
169     public int getLength() { return attributes.getLength(); }
170   }
171
172   protected class EmptyAttributesImpl implements Attributes {
173     EmptyAttributesImpl() {}
174     public String JavaDoc getValue(int index) { return null; }
175     public String JavaDoc getValue(String JavaDoc qName) { return null; }
176     public String JavaDoc getValue(String JavaDoc uri, String JavaDoc localPart) { return null; }
177     public int getLength() { return 0; }
178   }
179   
180   
181   
182   //
183
// -- PRIVATE METHODS ------------------------------------------------------
184
//
185

186   private String JavaDoc parseCharacterEntities(String JavaDoc in) {
187     return in;
188   }
189
190 }
Popular Tags