avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hamm...@apache.org
Subject cvs commit: jakarta-avalon-cornerstone/apps/db/src/manifest test-gui.mf
Date Fri, 02 Nov 2001 22:37:52 GMT
hammant     01/11/02 14:37:52

  Modified:    apps/db  build.xml
               apps/db/src/java/org/apache/avalon/db/driver
                        AvalonDBDriver.java
  Added:       apps/db/src/java/org/apache/avalon/db/test TestGUI.java
               apps/db/src/java/org/apache/avalon/db/utils StringUtils.java
                        Tokenizer.java
               apps/db/src/manifest test-gui.mf
  Log:
  New GUI testclient and utility packages from Cocoon
  
  Revision  Changes    Path
  1.9       +14 -2     jakarta-avalon-cornerstone/apps/db/build.xml
  
  Index: build.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/build.xml,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- build.xml	2001/11/02 12:17:32	1.8
  +++ build.xml	2001/11/02 22:37:52	1.9
  @@ -109,7 +109,7 @@
           <include name="org/apache/avalon/db/**"/>
           <exclude name="org/apache/avalon/db/transport/cmdstream/client/**"/>
           <exclude name="org/apache/avalon/db/driver/**"/>
  -        <exclude name="org/apache/avalon/db/test/**"/>        
  +        <exclude name="org/apache/avalon/db/test/**"/>
         </fileset>
         <fileset dir="${java.dir}">
           <include name="org/apache/avalon/db/**/*.xinfo"/>
  @@ -124,9 +124,21 @@
           <include name="org/apache/avalon/db/transport/*"/>
           <include name="org/apache/avalon/db/common/**"/>
           <include name="org/apache/avalon/db/driver/**"/>
  -        <include name="org/apache/avalon/db/results/**"/>        
  +        <include name="org/apache/avalon/db/results/**"/>
  +        <include name="org/apache/avalon/db/utils/**"/>
         </fileset>
       </jar>
  +
  +
  +    <!-- Test GUI -->
  +    <jar file="${build.lib}/avalon-db-testgui.jar" manifest="${manifest.dir}/test-gui.mf">
  +      <fileset dir="${build.classes}">
  +        <include name="org/apache/avalon/db/**"/>
  +        <exclude name="org/apache/avalon/db/transport/cmdstream/client/**"/>
  +        <exclude name="org/apache/avalon/db/driver/**"/>
  +      </fileset>
  +    </jar>
  +
   
   
     </target>
  
  
  
  1.6       +6 -3      jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/AvalonDBDriver.java
  
  Index: AvalonDBDriver.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/driver/AvalonDBDriver.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- AvalonDBDriver.java	2001/11/02 12:27:08	1.5
  +++ AvalonDBDriver.java	2001/11/02 22:37:52	1.6
  @@ -11,6 +11,7 @@
   
   
   import org.apache.avalon.db.common.Version;
  +import org.apache.avalon.db.util.StringUtils;
   
   import java.sql.Driver;
   import java.sql.Connection;
  @@ -25,7 +26,7 @@
    *
    *
    * @author Paul Hammant <a href="mailto:Paul_Hammant@yahoo.com">Paul_Hammant@yahoo.com</a>
  - * @version $Revision: 1.5 $
  + * @version $Revision: 1.6 $
    */
   public class
           AvalonDBDriver extends AbstractDriver implements Driver {
  @@ -67,11 +68,13 @@
       }
   
       private String getHost(String url) {
  -        return null; //TODO
  +        String[] str = StringUtils.split(url,":");
  +        return str[4];
       }
   
       private int getPort(String url) {
  -        return 0; //TODO
  +        String[] str = StringUtils.split(url,":");
  +        return new Integer(str[5]).intValue();
       }
   
       /**
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/test/TestGUI.java
  
  Index: TestGUI.java
  ===================================================================
  /*
   * Copyright (C) The avalon Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the avalon Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE file.
   */
  package org.apache.avalon.db.test;
  
  import java.awt.*;
  import java.util.StringTokenizer;
  import java.util.Vector;
  import java.sql.Connection;
  import java.sql.DriverManager;
  import java.sql.Driver;
  import java.sql.ResultSet;    
  import java.sql.Statement;
  import javax.swing.*;
  import org.apache.avalon.db.driver.AvalonDBDriver;
  
  /**
   * Little GUI for AvalonDB Testing. Only socket connection in the
   * moment. Code was mostly generated from IBM'S Dark Age :))
   *
   * @author Gerhard Froehlich <a href="mailto:g-froehlich@gmx.de">g-froehlich@gmx.de</a>
   */
  public class TestGUI extends JFrame {
  	private JPanel ivjAvalonDBClientPane = null;
  	private JPanel ivjJFrameContentPane = null;
  	private JPanel ivjJPanel1 = null;
  	private JScrollPane ivjJScrollPane1 = null;
  	private JScrollPane ivjJScrollPane2 = null;
      private JTextField ivjConnectTextField = null;	
      private JTextArea ivjInputTextArea = null;	
      private JTextArea ivjOutputTextArea = null;
  
      private Connection con = null;
  
      class IvjEventHandler implements java.awt.event.ActionListener {
      		public void actionPerformed(java.awt.event.ActionEvent e) {
      			if (e.getSource() == TestGUI.this.getExecuteButton())
      				connEtoC1(e);
      			if (e.getSource() == TestGUI.this.getConnectButton())
      				connEtoC2(e);
      		};
      	};
  	private JButton ivjConnectButton = null;
  	IvjEventHandler ivjEventHandler = new IvjEventHandler();
  	private JButton ivjExecuteButton = null;
      
      /**
       * TestGUI constructor comment.
       */
      public TestGUI() {
      	super();
          try {
              Driver driver = (Driver)Class.forName("org.apache.avalon.db.driver.AvalonDBDriver").newInstance();
              DriverManager.registerDriver(driver);
          } catch (Exception e) {
              handleException(e);
          }   
      	initialize();
      }
      
      /**
       * TestGUI constructor comment.
       * @param title java.lang.String
       */
      public TestGUI(String title) {
      	super(title);
      }
      
      /**
       * Comment
       */
      public void connectButton_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
          return;       
      }
  
      /**
           * connEtoC1:  (ExecuteButton.action.actionPerformed(java.awt.event.ActionEvent)
--> TestGUI.executeButton_ActionPerformed(Ljava.awt.event.ActionEvent;)V)
           * @param arg1 java.awt.event.ActionEvent
           */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private void connEtoC1(java.awt.event.ActionEvent arg1) {
      	try {
              if(con != null) {
                  Statement statement = con.createStatement();
                  ResultSet rs = statement.executeQuery(ivjInputTextArea.getText());
                  //TODO rs processing
              } else {
                  ivjOutputTextArea.setText("No connection");
              }
      		this.executeButton_ActionPerformed(arg1);
      	} catch (Throwable ivjExc) {
      		handleException(ivjExc);
      	}
      }
  
      /**
           * connEtoC2:  (ConnectButton.action.actionPerformed(java.awt.event.ActionEvent)
--> TestGUI.connectButton_ActionPerformed(Ljava.awt.event.ActionEvent;)V)
           * @param arg1 java.awt.event.ActionEvent
           */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private void connEtoC2(java.awt.event.ActionEvent arg1) {
      	try {
              if(!ivjConnectTextField.getText().equals("")) {
                  System.out.println("Fired JDBC connect!");
                  con = DriverManager.getConnection(ivjConnectTextField.getText(),null);
                  ivjOutputTextArea.setText("Connection established!");
              } else {
                  ivjOutputTextArea.setText("Please insert JDBC URL!");
              }
      		this.connectButton_ActionPerformed(arg1);
      	} catch (Throwable ivjExc) {
              ivjOutputTextArea.setText("Connection not established!");
      		handleException(ivjExc);
      	}
      }
  
      /**
       * Comment
       */
      public void executeButton_ActionPerformed(java.awt.event.ActionEvent actionEvent) {
      	return;
      }
  
      /**
       * Return the AvalonDBClientPane property value.
       * @return javax.swing.JPanel
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private JPanel getAvalonDBClientPane() {
      	if (ivjAvalonDBClientPane == null) {
      		try {
      			ivjAvalonDBClientPane = new JPanel();
      			ivjAvalonDBClientPane.setName("AvalonDBClientPane");
      			ivjAvalonDBClientPane.setLayout(null);
      			getAvalonDBClientPane().add(getJPanel1(), getJPanel1().getName());
      			// user code begin {1}
      			// user code end
      		} catch (Throwable ivjExc) {
      			// user code begin {2}
      			// user code end
      			handleException(ivjExc);
      		}
      	}
      	return ivjAvalonDBClientPane;
      }
  
      /**
       * Return the JButton1 property value.
       * @return javax.swing.JButton
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private JButton getConnectButton() {
      	if (ivjConnectButton == null) {
      		try {
      			ivjConnectButton = new JButton();
      			ivjConnectButton.setName("ConnectButton");
      			ivjConnectButton.setText("Connect");
      			ivjConnectButton.setBounds(208, 15, 85, 25);
      			// user code begin {1}
      			// user code end
      		} catch (Throwable ivjExc) {
      			// user code begin {2}
      			// user code end
      			handleException(ivjExc);
      		}
      	}
      	return ivjConnectButton;
      }
  
      /**
       * Return the JButton2 property value.
       * @return javax.swing.JButton
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private JButton getExecuteButton() {
      	if (ivjExecuteButton == null) {
      		try {
      			ivjExecuteButton = new JButton();
      			ivjExecuteButton.setName("ExecuteButton");
      			ivjExecuteButton.setText("Execute");
      			ivjExecuteButton.setBounds(301, 14, 85, 25);
      			// user code begin {1}
      			// user code end
      		} catch (Throwable ivjExc) {
      			// user code begin {2}
      			// user code end
      			handleException(ivjExc);
      		}
      	}
      	return ivjExecuteButton;
      }
      /**
       * Return the JFrameContentPane property value.
       * @return javax.swing.JPanel
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private JPanel getJFrameContentPane() {
      	if (ivjJFrameContentPane == null) {
      		try {
      			ivjJFrameContentPane = new JPanel();
      			ivjJFrameContentPane.setName("JFrameContentPane");
      			ivjJFrameContentPane.setLayout(new BorderLayout());
      			getJFrameContentPane().add(getAvalonDBClientPane(), "Center");
      			// user code begin {1}
      			// user code end
      		} catch (Throwable ivjExc) {
      			// user code begin {2}
      			// user code end
      			handleException(ivjExc);
      		}
      	}
      	return ivjJFrameContentPane;
      }
      /**
       * Return the JPanel1 property value.
       * @return javax.swing.JPanel
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private JPanel getJPanel1() {
      	if (ivjJPanel1 == null) {
      		try {
      			ivjJPanel1 = new JPanel();
      			ivjJPanel1.setName("JPanel1");
      			ivjJPanel1.setLayout(null);
      			ivjJPanel1.setBounds(1, 2, 462, 326);
      			getJPanel1().add(getJScrollPane1(), getJScrollPane1().getName());
      			getJPanel1().add(getJScrollPane2(), getJScrollPane2().getName());
      			getJPanel1().add(getConnectTextField(), getConnectTextField().getName());
      			getJPanel1().add(getConnectButton(), getConnectButton().getName());
      			getJPanel1().add(getExecuteButton(), getExecuteButton().getName());
      			// user code begin {1}
      			// user code end
      		} catch (Throwable ivjExc) {
      			// user code begin {2}
      			// user code end
      			handleException(ivjExc);
      		}
      	}
      	return ivjJPanel1;
      }
      
      /**
       * Return the JScrollPane1 property value.
       * @return javax.swing.JScrollPane
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private JScrollPane getJScrollPane1() {
      	if (ivjJScrollPane1 == null) {
      		try {
      			ivjJScrollPane1 = new JScrollPane();
      			ivjJScrollPane1.setName("JScrollPane1");
      			ivjJScrollPane1.setBounds(4, 180, 458, 126);
      			getJScrollPane1().setViewportView(getOutputTextArea());
      			// user code begin {1}
      			// user code end
      		} catch (Throwable ivjExc) {
      			// user code begin {2}
      			// user code end
      			handleException(ivjExc);
      		}
      	}
      	return ivjJScrollPane1;
      }
      
      /**
       * Return the JScrollPane2 property value.
       * @return javax.swing.JScrollPane
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private JScrollPane getJScrollPane2() {
      	if (ivjJScrollPane2 == null) {
      		try {
      			ivjJScrollPane2 = new JScrollPane();
      			ivjJScrollPane2.setName("JScrollPane2");
      			ivjJScrollPane2.setBounds(5, 44, 457, 130);
      			getJScrollPane2().setViewportView(getInputTextArea());
      			// user code begin {1}
      			// user code end
      		} catch (Throwable ivjExc) {
      			// user code begin {2}
      			// user code end
      			handleException(ivjExc);
      		}
      	}
      	return ivjJScrollPane2;
      }
      
      
      
      
      /**
       * Called whenever the part throws an exception.
       * @param exception java.lang.Throwable
       */
      private void handleException(Throwable exception) {
      
      	/* Uncomment the following lines to print uncaught exceptions to stdout */
      	System.out.println("--------- UNCAUGHT EXCEPTION ---------");
      	exception.printStackTrace(System.out);
      }
      /**
       * Initializes connections
       * @exception java.lang.Exception The exception description.
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private void initConnections() throws Exception {
      	// user code begin {1}
      	// user code end
      	getExecuteButton().addActionListener(ivjEventHandler);
      	getConnectButton().addActionListener(ivjEventHandler);
      }
      /**
       * Initialize the class.
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private void initialize() {
      	try {
      		// user code begin {1}
      		// user code end
      		setName("TestGUI");
      		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
      		setResizable(false);
      		setSize(469, 370);
      		setTitle("TestGUI");
      		setContentPane(getJFrameContentPane());
      		initConnections();
      	} catch (Throwable ivjExc) {
      		handleException(ivjExc);
      	}
      	// user code begin {2}
      	// user code end
      }
      /**
       * Starts the application.
       * @param args an array of command-line arguments
       */
      public static void main(String[] args) {
      	try {
      		/* Set native look and feel */
      		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      		/* Create the frame */
      		TestGUI aAvalonDBClient = new TestGUI();
      		/* Add a windowListener for the windowClosedEvent */
      		aAvalonDBClient.addWindowListener(new java.awt.event.WindowAdapter() {
      			public void windowClosed(java.awt.event.WindowEvent e) {
      				System.exit(0);
      			};
      		});
      		aAvalonDBClient.setVisible(true);
      	} catch (Throwable exception) {
      		System.err.println("Exception occurred in main() of TestGUI");
      		exception.printStackTrace(System.out);
      	}
      }
     	
      /**
       * Return the JTextField1 property value.
       * @return javax.swing.JTextField
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private JTextField getConnectTextField() {
      	if (ivjConnectTextField == null) {
      		try {
      			ivjConnectTextField = new JTextField();
      			ivjConnectTextField.setName("ConnectTextField");
      			ivjConnectTextField.setBounds(6, 19, 186, 20);
      			// user code begin {1}
      			// user code end
      		} catch (Throwable ivjExc) {
      			// user code begin {2}
      			// user code end
      			handleException(ivjExc);
      		}
      	}
      	return ivjConnectTextField;
      }
  
      /**
       * Return the JTextArea1 property value.
       * @return javax.swing.JTextArea
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private JTextArea getInputTextArea() {
      	if (ivjInputTextArea == null) {
      		try {
      			ivjInputTextArea = new JTextArea();
      			ivjInputTextArea.setName("InputTextArea");
      			ivjInputTextArea.setBounds(-12, 0, 463, 127);
      			// user code begin {1}
      			// user code end
      		} catch (Throwable ivjExc) {
      			// user code begin {2}
      			// user code end
      			handleException(ivjExc);
      		}
      	}
      	return ivjInputTextArea;
      }
      /**
       * Return the JTextArea2 property value.
       * @return javax.swing.JTextArea
       */
      /* WARNING: THIS METHOD WILL BE REGENERATED. */
      private JTextArea getOutputTextArea() {
      	if (ivjOutputTextArea == null) {
      		try {
      			ivjOutputTextArea = new JTextArea();
      			ivjOutputTextArea.setName("OutputTextArea");
      			ivjOutputTextArea.setBounds(0, 0, 425, 123);
      			ivjOutputTextArea.setEditable(false);
      			// user code begin {1}
      			// user code end
      		} catch (Throwable ivjExc) {
      			// user code begin {2}
      			// user code end
      			handleException(ivjExc);
      		}
      	}
      	return ivjOutputTextArea;
      }
  }
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/utils/StringUtils.java
  
  Index: StringUtils.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.avalon.db.util;
  
  
  
  /**
   * A collection of <code>String</code> handling utility methods.
   *
   * @author <a href="mailto:ricardo@apache.org">Ricardo Rocha</a>
   * @author <a href="mailto:stefano@apache.org">Stefano Mazzocchi</a>
   * @version CVS $Revision: 1.1 $ $Date: 2001/11/02 22:37:52 $
   */
  public class StringUtils {
    
      /**
       * Split a string as an array using whitespace as separator
       *
       * @param line The string to be split
       * @return An array of whitespace-separated tokens
       */
      public static String[] split(String line) {
          return split(line, " \t\n\r");
      }
  
      /**
       * Split a string as an array using a given set of separators
       *
       * @param line The string to be split
       * @param delimiter A string containing token separators
       * @return An array of token
       */
      public static String[] split(String line, String delimiter) {
          Tokenizer tokenizer = new Tokenizer(line, delimiter);
          int tokenCount = tokenizer.countTokens();
          String[] result = new String[tokenCount];
          
          for (int i = 0; i < tokenCount; i++) {
              result[i] = tokenizer.nextToken();
          }
          
          return result;
      }
  
      /**
       * Tests whether a given character is alphabetic, numeric or
       * underscore
       *
       * @param c The character to be tested
       * @return whether the given character is alphameric or not
       */
      public static boolean isAlphaNumeric(char c) {
          return c == '_' ||
              (c >= 'a' && c <= 'z') ||
              (c >= 'A' && c <= 'Z') ||
              (c >= '0' && c <= '9');
      }
  
      /**
       * Counts the occurrence of the given char in the string.
       *
       * @param str The string to be tested
       * @param c the char to be counted
       * @return the occurrence of the character in the string.
       */
      public static int count(String str, char c) {
          int index = 0;
          char[] chars = str.toCharArray();
          for (int i = 0; i < chars.length; i++) {
              if (chars[i] == c) index++;
          }
          return index;
      }
  
      /**
       * Matches two strings.
       *
       * @param a The first string
       * @param b The second string
       * @return the index where the two strings stop matching starting from 0
       */
      public static int matchStrings(String a, String b) {
          int i;
          char[] ca = a.toCharArray();
          char[] cb = b.toCharArray();
          for (i = 0; (i < ca.length) || (i < cb.length); i++) {
              if (ca[i] != cb[i]) break;
          }
          return i;
      }
  
      /**
       * Replaces tokens in input with Value present in System.getProperty
       */
      public static String replaceToken(String s) {
          int startToken = s.indexOf("${");
          int endToken = s.indexOf("}",startToken);
          String token = s.substring(startToken+2,endToken);
          StringBuffer value = new StringBuffer();
          value.append(s.substring(0,startToken));
          value.append(System.getProperty(token));
          value.append(s.substring(endToken+1));
          return value.toString();
      }
  }
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/java/org/apache/avalon/db/utils/Tokenizer.java
  
  Index: Tokenizer.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included  with this distribution in *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  package org.apache.avalon.db.util;
  
  
  import java.util.Enumeration;
  import java.util.NoSuchElementException;
  
  /**
   * Replacement for StringTokenizer in java.util, beacuse of bug in the
   * Sun's implementation.
   *
   * @author <A HREF="mailto:moravek@pobox.sk">Peter Moravek</A>
   */
  public class Tokenizer implements Enumeration {
  
    /**
     * Constructs a string tokenizer for the specified string. All characters
     * in the delim argument are the delimiters for separating tokens.
     * If the returnTokens flag is true, then the delimiter characters are
     * also returned as tokens. Each delimiter is returned as a string of
     * length one. If the flag is false, the delimiter characters are skipped
     * and only serve as separators between tokens.
     *
     * @param str           a string to be parsed
     * @param delim         the delimiters
     * @param returnTokens  flag indicating whether to return the delimiters
     *                      as tokens
     */
    public Tokenizer(String str, String delim, boolean returnTokens) {
      this.str = str;
      this.delim = delim;
      this.returnTokens = returnTokens;
  
      max = str.length();
    }
  
    /**
     * Constructs a string tokenizer for the specified string. The characters
     * in the delim argument are the delimiters for separating tokens.
     * Delimiter characters themselves will not be treated as tokens.
     *
     * @param str          a string to be parsed
     * @param delim        the delimiters
     */
    public Tokenizer(String str, String delim) {
      this(str, delim, false);
    }
  
    /**
     * Constructs a string tokenizer for the specified string. The character
     * in the delim argument is the delimiter for separating tokens.
     * Delimiter character themselves will not be treated as token.
     *
     * @param str          a string to be parsed
     * @param delim        the delimiter
     */
    public Tokenizer(String str, char delim) {
      this(str, String.valueOf(delim), false);
    }
  
    /**
     * Constructs a string tokenizer for the specified string. The tokenizer
     * uses the default delimiter set, which is " \t\n\r\f": the space
     * character, the tab character, the newline character, the carriage-return
     * character, and the form-feed character. Delimiter characters themselves
     * will not be treated as tokens.
     *
     * @param str          a string to be parsed
     */
    public Tokenizer(String str) {
      this(str, DEFAULT_DELIMITERS, false);
    }
  
    /**
     * Tests if there are more tokens available from this tokenizer's string.
     * If this method returns true, then a subsequent call to nextToken with
     * no argument will successfully return a token.
     *
     * @return true if and only if there is at least one token in the string
     * after the current position; false otherwise.
     */
    public boolean hasMoreTokens() {
      return ((current < max) ? (true) :
        (((current == max) && (max == 0
          || (returnTokens && delim.indexOf(str.charAt(previous)) >= 0)))));
    }
  
    /**
     * Returns the next token from this string tokenizer.
     *
     * @return the next token from this string tokenizer
     *
     * @exception NoSuchElementException  if there are no more tokens in this
     *                                    tokenizer's string
     */
    public String nextToken() throws NoSuchElementException {
      if (current == max
        && (max == 0
        || (returnTokens && delim.indexOf(str.charAt(previous)) >= 0))) {
  
        current++;
        return new String();
      }
  
      if (current >= max)
        throw new NoSuchElementException();
  
      int start = current;
      String result = null;
  
      if (delim.indexOf(str.charAt(start)) >= 0) {
        if (previous == -1 || (returnTokens && previous != current
          && delim.indexOf(str.charAt(previous)) >= 0)) {
  
          result = new String();
        }
        else if (returnTokens)
          result = str.substring(start, ++current);
  
        if (!returnTokens)
          current++;
      }
  
      previous = start;
      start = current;
  
      if (result == null)
        while (current < max && delim.indexOf(str.charAt(current)) < 0)
          current++;
  
      return result == null ? str.substring(start, current) : result;
    }
  
    /**
     * Returns the next token in this string tokenizer's string. First, the
     * set of characters considered to be delimiters by this Tokenizer
     * object is changed to be the characters in the string delim.
     * Then the next token in the string after the current position is
     * returned. The current position is advanced beyond the recognized token.
     * The new delimiter set remains the default after this call.
     *
     * @param delim the new delimiters
     *
     * @return the next token, after switching to the new delimiter set
     *
     * @exception NoSuchElementException  if there are no more tokens in this
     *                                    tokenizer's string.
     */
    public String nextToken(String delim) throws NoSuchElementException {
      this.delim = delim;
      return nextToken();
    }
  
    /**
     * Returns the same value as the hasMoreTokens method. It exists so that
     * this class can implement the Enumeration interface.
     *
     * @return true if there are more tokens; false otherwise.
     */
    public boolean hasMoreElements() {
      return hasMoreTokens();
    }
  
    /**
     * Returns the same value as the nextToken method, except that its
     * declared return value is Object rather than String. It exists so that
     * this class can implement the Enumeration interface.
     *
     * @return the next token in the string
     *
     * @exception NoSuchElementException  if there are no more tokens in this
     *                                    tokenizer's string
     */
    public Object nextElement() {
      return nextToken();
    }
  
    /**
     * Calculates the number of times that this tokenizer's nextToken method
     * can be called before it generates an exception. The current position
     * is not advanced.
     *
     * @return  the number of tokens remaining in the string using the
     *          current delimiter set
     */
    public int countTokens() {
      int curr = current;
      int count = 0;
  
      for (int i = curr; i < max; i++) {
        if (delim.indexOf(str.charAt(i)) >= 0)
          count++;
  
        curr++;
      }
  
      return count + (returnTokens ? count : 0) + 1;
    }
  
    /**
     * Resets this tokenizer's state so the tokenizing starts from the begin.
     */
    public void reset() {
      previous = -1;
      current = 0;
    }
  
    /**
     * Constructs a string tokenizer for the specified string. All characters
     * in the delim argument are the delimiters for separating tokens.
     * If the returnTokens flag is true, then the delimiter characters are
     * also returned as tokens. Each delimiter is returned as a string of
     * length one. If the flag is false, the delimiter characters are skipped
     * and only serve as separators between tokens. Then tokenizes the str
     * and return an String[] array with tokens.
     *
     * @param str           a string to be parsed
     * @param delim         the delimiters
     * @param returnTokens  flag indicating whether to return the delimiters
     *                      as tokens
     *
     * @return array with tokens
     */
    public static String[] tokenize(String str, String delim,
      boolean returnTokens) {
  
      Tokenizer tokenizer = new Tokenizer(str, delim, returnTokens);
      String[] tokens = new String[tokenizer.countTokens()];
  
      for (int i = 0; i < tokens.length; i++)
        tokens[i] = tokenizer.nextToken();
  
      return tokens;
    }
  
    /**
     * Default delimiters "\t\n\r\f":
     * the space character, the tab character, the newline character,
     * the carriage-return character, and the form-feed character.
     */
    public static final String DEFAULT_DELIMITERS = " \t\n\r\f";
  
    /**
     * String to tokenize.
     */
    private String str = null;
  
    /**
     * Delimiters.
     */
    private String delim = null;
  
    /**
     * Flag indicating whether to return the delimiters as tokens.
     */
    private boolean returnTokens = false;
  
    /**
     * Previous token start.
     */
    private int previous = -1;
  
    /**
     * Current position in str string.
     */
    private int current = 0;
  
    /**
     * Maximal position in str string.
     */
    private int max = 0;
  }
  
  
  
  
  
  1.1                  jakarta-avalon-cornerstone/apps/db/src/manifest/test-gui.mf
  
  Index: test-gui.mf
  ===================================================================
  Manifest-Version: 1.0
  Main-Class: org.apache.avalon.db.test.TestGUI
  
  
  
  

--
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