Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

GuiParsingThread.java

00001 /**
00002  * C-JDBC: Clustered JDBC.
00003  * Copyright (C) 2002-2004 French National Institute For Research In Computer
00004  * Science And Control (INRIA).
00005  * Contact: c-jdbc@objectweb.org
00006  * 
00007  * This library is free software; you can redistribute it and/or modify it
00008  * under the terms of the GNU Lesser General Public License as published by the
00009  * Free Software Foundation; either version 2.1 of the License, or any later
00010  * version.
00011  * 
00012  * This library is distributed in the hope that it will be useful, but WITHOUT
00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00015  * for more details.
00016  * 
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this library; if not, write to the Free Software Foundation,
00019  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
00020  *
00021  * Initial developer(s): Nicolas Modrzyk
00022  * Contributor(s): ______________________.
00023  */
00024 
00025 package org.objectweb.cjdbc.console.gui.threads;
00026 
00027 import java.awt.event.KeyEvent;
00028 import java.awt.event.KeyListener;
00029 import java.util.ArrayList;
00030 
00031 import javax.swing.JTextPane;
00032 import javax.swing.event.CaretEvent;
00033 import javax.swing.event.CaretListener;
00034 
00035 import org.objectweb.cjdbc.common.xml.XmlValidator;
00036 
00037 /**
00038  * This class defines a GuiParsingThread
00039  * 
00040  * @author <a href="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
00041  * @version 1.0
00042  */
00043 public class GuiParsingThread extends Thread
00044     implements
00045       KeyListener,
00046       CaretListener
00047 {
00048   private JTextPane xmlTextPane;
00049   private JTextPane outputPane;
00050 
00051   //private DTDParser dtdparser;
00052   //private DTD dtd;
00053 
00054   /**
00055    * Creates a new <code>GuiParsingThread.java</code> object
00056    * 
00057    * @param xmlTextPane panel that contains the xml to parse
00058    */
00059   public GuiParsingThread(JTextPane xmlTextPane)
00060   {
00061     this.xmlTextPane = xmlTextPane;
00062     //xmlTextPane.addCaretListener(this);
00063     /*
00064      * try { this.dtdparser = new DTDParser(this.getClass().getResource(
00065      * "/c-jdbc-controller.dtd")); dtd = dtdparser.parse(); } catch (Exception
00066      * e) { e.printStackTrace(); }
00067      */
00068   }
00069 
00070   /**
00071    * @see java.lang.Runnable#run()
00072    */
00073   public void run()
00074   {
00075     while (true)
00076     {
00077       synchronized (this)
00078       {
00079         try
00080         {
00081           wait();
00082         }
00083         catch (InterruptedException e)
00084         {
00085         }
00086         XmlValidator validator = new XmlValidator("c-jdbc-controller.dtd",
00087             xmlTextPane.getText());
00088         StringBuffer buffer = new StringBuffer();
00089         ArrayList exceptions = validator.getExceptions();
00090         for (int i = 0; i < exceptions.size(); i++)
00091           buffer.append(((Exception) (exceptions.get(i))).getMessage() + "\n");
00092         outputPane.setText(buffer.toString());
00093       }
00094     }
00095   }
00096 
00097   /**
00098    * @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent)
00099    */
00100   public void keyPressed(KeyEvent e)
00101   {
00102     synchronized (this)
00103     {
00104       this.notify();
00105     }
00106   }
00107 
00108   /**
00109    * @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent)
00110    */
00111   public void keyReleased(KeyEvent e)
00112   {
00113   }
00114 
00115   /**
00116    * @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent)
00117    */
00118   public void keyTyped(KeyEvent e)
00119   {
00120 
00121   }
00122 
00123   /**
00124    * Set the output panel for this parsing thread
00125    * 
00126    * @param rightPane the pane to display the output
00127    */
00128   public void setOutputPane(JTextPane rightPane)
00129   {
00130     this.outputPane = rightPane;
00131   }
00132 
00133   /**
00134    * @see javax.swing.event.CaretListener#caretUpdate(javax.swing.event.CaretEvent)
00135    */
00136   public void caretUpdate(CaretEvent e)
00137   {
00138     //    int pos = e.getDot();
00139     //    String string = xmlTextPane.getText();
00140     //    int low = string.indexOf("<", pos);
00141     //    int sup = string.indexOf(">", pos);
00142     //    int end = string.indexOf("/>", pos);
00143     //    int close = string.indexOf("</", pos);
00144     //
00145     //    System.out.println("low:" + low + ":sup:" + sup + ":end:" + end +
00146     //     ":close:"
00147     //        + close);
00148     //
00149     //    String element = null;
00150     //    if (low == -1 && end == -1 && close == -1)
00151     //    {
00152     //      //System.out.println("0");
00153     //      // end of the file last tag
00154     //      if (sup == -1)
00155     //        sup = string.length() - 2;
00156     //      int ind = sup;
00157     //      while (string.charAt(ind) != '/')
00158     //        ind--;
00159     //      element = string.substring(ind + 1, sup);
00160     //    }
00161     //    else if (lt(sup, low) && lt(sup, end) && lt(sup, close))
00162     //    {
00163     //      //System.out.println("1");
00164     //      // we search for an opening tag, like <tag>
00165     //      int ind = sup;
00166     //      while (string.charAt(ind) != '<')
00167     //        ind--;
00168     //      element = string.substring(ind + 1, string.indexOf(' ', ind));
00169     //    }
00170     //    else if (lt(end, sup) && lt(end, low) && lt(end, close))
00171     //    {
00172     //      //System.out.println("2");
00173     //      //we search for a standalone closed tag <tag/>
00174     //      int ind = end;
00175     //      while (string.charAt(ind) != '<')
00176     //        ind--;
00177     //      element = string.substring(ind + 1, string.indexOf(' ', ind));
00178     //    }
00179     //    else if (lt(low, sup) && lt(low, end) && lt(low, close))
00180     //    {
00181     //      //System.out.println("3");
00182     //      //we search for the next starting tag <tag>
00183     //      element = string.substring(low + 1, nextLow(string, low));
00184     //    }
00185     //    else if (lt(close, sup) && lt(close, end) && close == low)
00186     //    {
00187     //      //System.out.println("4");
00188     //      //we search for the name of the closing tag <tag>...</tag>
00189     //      int space = string.indexOf('>', close + 2);
00190     //      element = string.substring(close + 2, space);
00191     //    }
00192     //
00193     //    DTDElement elm = (DTDElement) dtd.elements.get(element);
00194     //    //System.out.println(element);
00195     //    
00196     //    Hashtable attributes = elm.attributes;
00197     //    Enumeration enume = attributes.keys();
00198     //    while (enume.hasMoreElements())
00199     //    {
00200     //      DTDAttribute att = (DTDAttribute) attributes.get(enume.nextElement());
00201     //      ////System.out.println(att.name+":"+att.defaultValue);
00202     //    }
00203 
00204   }
00205 
00206   //  private int nextLow(String string, int low)
00207   //  {
00208   //    int space = string.indexOf(' ', low);
00209   //    int ll = string.indexOf('>', low);
00210   //    int lc = string.indexOf('/', low);
00211   //    int ref = 0;
00212   //    if (lt(space, ll) && lt(space, lc))
00213   //      ref = space;
00214   //    else if (lt(ll, space) && lt(ll, lc))
00215   //      ref = ll;
00216   //    else if (lt(lc, space) && lt(lc, ll))
00217   //      ref = lc;
00218   //    return ref;
00219   //  }
00220   //
00221   //  private boolean lt(int l1, int l2)
00222   //  {
00223   //    if (l1 < 0)
00224   //      return false;
00225   //    else if (l2 < 0 || l1 < l2)
00226   //      return true;
00227   //    else
00228   //      return false;
00229   //  }
00230 }

Generated on Mon Apr 11 22:01:32 2005 for C-JDBC by  doxygen 1.3.9.1