avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From froehl...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/test TestGUI.java
Date Thu, 08 Nov 2001 23:47:02 GMT
froehlich    01/11/08 15:47:02

  Modified:    apps/db/src/java/org/apache/avalon/db/test TestGUI.java
  Log:
  add XML parser to gui, for further LXSQL usage
  
  Revision  Changes    Path
  1.4       +71 -12    jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/test/TestGUI.java
  
  Index: TestGUI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/test/TestGUI.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TestGUI.java	2001/11/04 08:31:54	1.3
  +++ TestGUI.java	2001/11/08 23:47:02	1.4
  @@ -6,21 +6,32 @@
    * the LICENSE file.
    */
   package org.apache.avalon.db.test;
  -
  -import javax.swing.*;
  -
  +    
  +import java.awt.*;
  +import java.awt.event.*;
  +import java.io.StringReader;
  +import java.io.IOException;
   import java.sql.Connection;
   import java.sql.DriverManager;
   import java.sql.Driver;
   import java.sql.ResultSet;    
   import java.sql.Statement;
   import java.sql.SQLException;
  -    
  -import java.awt.*;
  -import java.awt.event.*;
   
  -import org.apache.avalon.db.driver.AvalonDBDriver;
  +import javax.swing.*;
   
  +import org.w3c.dom.Document;
  +
  +import org.w3c.dom.DocumentType;
  +
  +import org.w3c.dom.Element;
  +import org.xml.sax.InputSource;
  +import org.xml.sax.SAXException;
  +import javax.xml.parsers.DocumentBuilder;
  +import javax.xml.parsers.DocumentBuilderFactory;
  +import javax.xml.parsers.ParserConfigurationException;
  +
  +import org.apache.avalon.db.driver.AvalonDBDriver;
   /**
    * TestGUI for testing the AvalonDB.
    *
  @@ -37,9 +48,19 @@
       private final JTextField connectField = new JTextField();
       private final JScrollPane inputAreaScrollPane = new JScrollPane();
       private final JScrollPane outputAreaScrollPane = new JScrollPane();
  +    private final String XMLHDR = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
  +    private  boolean isconnected = false;
  +    protected DocumentBuilderFactory docBuilderFactory;
  +    protected DocumentBuilder docBuilder;
   
       public TestGUI() {
           setupDBDriver();
  +        try {
  +            docBuilderFactory = DocumentBuilderFactory.newInstance();
  +            docBuilder = docBuilderFactory.newDocumentBuilder();
  +        } catch (ParserConfigurationException e) {
  +            handleException(e);
  +        }
       }
   
       public Component createComponents() {
  @@ -52,9 +73,18 @@
               public void actionPerformed(ActionEvent e) {
                   try {
                       if(!connectField.getText().equals("")) {
  -                        System.out.println("Fired JDBC connect!");
  -                        con = DriverManager.getConnection(connectField.getText(),null);
  -                        outputArea.setText("Connection established!");
  +                        if(!isconnected){
  +                            System.out.println("Fired JDBC connect!");
  +                            con = DriverManager.getConnection(connectField.getText(),null);
  +                            outputArea.setText("Connection established!");
  +                            connect.setText("Re-Connect");
  +                            isconnected = true;
  +                        } else {
  +                            con.close();
  +                            con = DriverManager.getConnection(connectField.getText(),null);
  +                            outputArea.setText("Reconnected!");
  +                            isconnected = true;
  +                        }
                       } else {
                           outputArea.setText("Please insert JDBC URL!");
                       }
  @@ -68,9 +98,20 @@
           execute.addActionListener(new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                   if(con != null) {
  +                    Statement statement = null;
                       try {
  -                        Statement statement = con.createStatement();
  -                        ResultSet rs = statement.executeQuery(inputArea.getText());
  +                        statement = con.createStatement();
  +                        String action = parseInput(inputArea.getText());
  +                        if(action.equals("create-table")) {
  +                            outputArea.setText("Table created!");
  +                            int returnUpdate = statement.executeUpdate(inputArea.getText());
  +                        } else if (action.equals("insert-into")) {
  +                            outputArea.setText("Row inserted!");
  +                            int returnUpdate = statement.executeUpdate(inputArea.getText());
  +                        } else {
  +                            outputArea.setText("Query not implemented yet!");
  +                        }
  +                        statement.close();
                       } catch (SQLException slqe) {
                           handleException(slqe);
                       }
  @@ -175,5 +216,23 @@
           outputArea.setText("--------- UNCAUGHT EXCEPTION ---------" + "\n" 
                                     + exception
                                     + "\n" + exception.getMessage());
  +    }
  +
  +    private String parseInput(String str) {
  +        StringReader sr = new StringReader(XMLHDR + str);
  +        InputSource is = new InputSource(sr);
  +
  +        try {
  +            Document doc = docBuilder.parse(is);
  +            Element rootElement = doc.getDocumentElement();
  +            System.out.println("rootElement=" + rootElement.getTagName());
  +            return rootElement.getTagName();
  +        } catch(SAXException sae) {
  +            handleException(sae);
  +            return "";
  +        } catch(IOException ioe) {
  +            handleException(ioe);
  +            return "";
  +        }
       }
   }
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>


Mime
View raw message