KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > console > gui > threads > GuiParsingThread


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.console.gui.threads;
26
27 import java.awt.event.KeyEvent JavaDoc;
28 import java.awt.event.KeyListener JavaDoc;
29 import java.util.ArrayList JavaDoc;
30
31 import javax.swing.JTextPane JavaDoc;
32 import javax.swing.event.CaretEvent JavaDoc;
33 import javax.swing.event.CaretListener JavaDoc;
34
35 import org.objectweb.cjdbc.common.xml.XmlValidator;
36
37 /**
38  * This class defines a GuiParsingThread
39  *
40  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
41  * @version 1.0
42  */

43 public class GuiParsingThread extends Thread JavaDoc
44     implements
45       KeyListener JavaDoc,
46       CaretListener JavaDoc
47 {
48   private JTextPane JavaDoc xmlTextPane;
49   private JTextPane JavaDoc outputPane;
50
51   //private DTDParser dtdparser;
52
//private DTD dtd;
53

54   /**
55    * Creates a new <code>GuiParsingThread.java</code> object
56    *
57    * @param xmlTextPane panel that contains the xml to parse
58    */

59   public GuiParsingThread(JTextPane JavaDoc xmlTextPane)
60   {
61     this.xmlTextPane = xmlTextPane;
62     //xmlTextPane.addCaretListener(this);
63
/*
64      * try { this.dtdparser = new DTDParser(this.getClass().getResource(
65      * "/c-jdbc-controller.dtd")); dtd = dtdparser.parse(); } catch (Exception
66      * e) { e.printStackTrace(); }
67      */

68   }
69
70   /**
71    * @see java.lang.Runnable#run()
72    */

73   public void run()
74   {
75     while (true)
76     {
77       synchronized (this)
78       {
79         try
80         {
81           wait();
82         }
83         catch (InterruptedException JavaDoc e)
84         {
85         }
86         XmlValidator validator = new XmlValidator("c-jdbc-controller.dtd",
87             xmlTextPane.getText());
88         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
89         ArrayList JavaDoc exceptions = validator.getExceptions();
90         for (int i = 0; i < exceptions.size(); i++)
91           buffer.append(((Exception JavaDoc) (exceptions.get(i))).getMessage() + "\n");
92         outputPane.setText(buffer.toString());
93       }
94     }
95   }
96
97   /**
98    * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
99    */

100   public void keyPressed(KeyEvent JavaDoc e)
101   {
102     synchronized (this)
103     {
104       this.notify();
105     }
106   }
107
108   /**
109    * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
110    */

111   public void keyReleased(KeyEvent JavaDoc e)
112   {
113   }
114
115   /**
116    * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
117    */

118   public void keyTyped(KeyEvent JavaDoc e)
119   {
120
121   }
122
123   /**
124    * Set the output panel for this parsing thread
125    *
126    * @param rightPane the pane to display the output
127    */

128   public void setOutputPane(JTextPane JavaDoc rightPane)
129   {
130     this.outputPane = rightPane;
131   }
132
133   /**
134    * @see javax.swing.event.CaretListener#caretUpdate(javax.swing.event.CaretEvent)
135    */

136   public void caretUpdate(CaretEvent JavaDoc e)
137   {
138     // int pos = e.getDot();
139
// String string = xmlTextPane.getText();
140
// int low = string.indexOf("<", pos);
141
// int sup = string.indexOf(">", pos);
142
// int end = string.indexOf("/>", pos);
143
// int close = string.indexOf("</", pos);
144
//
145
// System.out.println("low:" + low + ":sup:" + sup + ":end:" + end +
146
// ":close:"
147
// + close);
148
//
149
// String element = null;
150
// if (low == -1 && end == -1 && close == -1)
151
// {
152
// //System.out.println("0");
153
// // end of the file last tag
154
// if (sup == -1)
155
// sup = string.length() - 2;
156
// int ind = sup;
157
// while (string.charAt(ind) != '/')
158
// ind--;
159
// element = string.substring(ind + 1, sup);
160
// }
161
// else if (lt(sup, low) && lt(sup, end) && lt(sup, close))
162
// {
163
// //System.out.println("1");
164
// // we search for an opening tag, like <tag>
165
// int ind = sup;
166
// while (string.charAt(ind) != '<')
167
// ind--;
168
// element = string.substring(ind + 1, string.indexOf(' ', ind));
169
// }
170
// else if (lt(end, sup) && lt(end, low) && lt(end, close))
171
// {
172
// //System.out.println("2");
173
// //we search for a standalone closed tag <tag/>
174
// int ind = end;
175
// while (string.charAt(ind) != '<')
176
// ind--;
177
// element = string.substring(ind + 1, string.indexOf(' ', ind));
178
// }
179
// else if (lt(low, sup) && lt(low, end) && lt(low, close))
180
// {
181
// //System.out.println("3");
182
// //we search for the next starting tag <tag>
183
// element = string.substring(low + 1, nextLow(string, low));
184
// }
185
// else if (lt(close, sup) && lt(close, end) && close == low)
186
// {
187
// //System.out.println("4");
188
// //we search for the name of the closing tag <tag>...</tag>
189
// int space = string.indexOf('>', close + 2);
190
// element = string.substring(close + 2, space);
191
// }
192
//
193
// DTDElement elm = (DTDElement) dtd.elements.get(element);
194
// //System.out.println(element);
195
//
196
// Hashtable attributes = elm.attributes;
197
// Enumeration enume = attributes.keys();
198
// while (enume.hasMoreElements())
199
// {
200
// DTDAttribute att = (DTDAttribute) attributes.get(enume.nextElement());
201
// ////System.out.println(att.name+":"+att.defaultValue);
202
// }
203

204   }
205
206   // private int nextLow(String string, int low)
207
// {
208
// int space = string.indexOf(' ', low);
209
// int ll = string.indexOf('>', low);
210
// int lc = string.indexOf('/', low);
211
// int ref = 0;
212
// if (lt(space, ll) && lt(space, lc))
213
// ref = space;
214
// else if (lt(ll, space) && lt(ll, lc))
215
// ref = ll;
216
// else if (lt(lc, space) && lt(lc, ll))
217
// ref = lc;
218
// return ref;
219
// }
220
//
221
// private boolean lt(int l1, int l2)
222
// {
223
// if (l1 < 0)
224
// return false;
225
// else if (l2 < 0 || l1 < l2)
226
// return true;
227
// else
228
// return false;
229
// }
230
}
Popular Tags