geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jdil...@apache.org
Subject cvs commit: incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/console/java Console.java
Date Wed, 13 Aug 2003 10:54:37 GMT
jdillon     2003/08/13 03:54:37

  Added:       modules/twiddle/src/java/org/apache/geronimo/twiddle/console
                        AbstractConsole.java Completer.java Console.java
                        ConsoleFactory.java History.java IOContext.java
                        TransientHistory.java
               modules/twiddle/src/java/org/apache/geronimo/twiddle/console/java
                        Console.java
  Log:
   o Basic framework for the interactive console
   o Simple pure Java console impl, eventually want to plugin editline or
     other BSD-licence friendly readline-ish impls
  
  Revision  Changes    Path
  1.1                  incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/console/AbstractConsole.java
  
  Index: AbstractConsole.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.twiddle.console;
  
  import java.io.IOException;
  
  /**
   * An abstract implementation of {@link Console}.
   *
   * <p>Sub-classes only need to define {@link Console#getLine(String,boolean)}.
   *
   * <p>Also provides helpers to determine if history and/or completion is
   *    enabled.
   *
   * @version <code>$Id: AbstractConsole.java,v 1.1 2003/08/13 10:54:37 jdillon Exp
$</code>
   * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
   */
  public abstract class AbstractConsole
      implements Console
  {
      protected History history;
      protected Completer completer;
      protected IOContext ioContext;
      
      public void setIOContext(final IOContext ioContext)
      {
          this.ioContext = ioContext;
      }
      
      public IOContext getIOContext()
      {
          return ioContext;
      }
      
      public void setHistory(final History history)
      {
          this.history = history;
      }
      
      public History getHistory()
      {
          return history;
      }
      
      protected boolean isHistoryEnabled()
      {
          return history != null;
      }
      
      public void setCompleter(final Completer completer)
      {
          this.completer = completer;
      }
      
      public Completer getCompleter()
      {
          return completer;
      }
      
      protected boolean isCompletionEnabled()
      {
          return completer != null;
      }
      
      public String getLine(final String prompt) throws IOException
      {
          return getLine(prompt, true);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/console/Completer.java
  
  Index: Completer.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.twiddle.console;
  
  /**
  * Provides a {@link Console} with plugable command-line completion.
   *
   * @version <code>$Id: Completer.java,v 1.1 2003/08/13 10:54:37 jdillon Exp $</code>
   * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
   */
  public interface Completer
  {
      /**
       * Attempt to complete the given command-line text.
       *
       * @param text  The command-line text to complete.
       * @return      The completed command-line.
       */
      String complete(String text);
  }
  
  
  
  1.1                  incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/console/Console.java
  
  Index: Console.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.twiddle.console;
  
  import java.io.IOException;
  
  /**
   * Abstraction of a console.
   *
   * <p>Console impl must provide a no-argument constructor for pluggablity.
   *
   * <p>Modeled after Java-Readline.
   *
   * @version <code>$Id: Console.java,v 1.1 2003/08/13 10:54:37 jdillon Exp $</code>
   * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
   */
  public interface Console
  {
      /**
       * Set the input/output context.
       *
       * @param ioContext     The input/output context.
       */
      void setIOContext(IOContext ioContext);
      
      /**
       * Get the input/output context.
       *
       * @return The input/output context.
       */
      IOContext getIOContext();
      
      /**
       * Set the history backing for the console.
       *
       * @param history   The history backing.
       */
      void setHistory(History history);
      
      /**
       * Get the history backing for the console.
       *
       * @return The history backing.
       */
      History getHistory();
      
      /**
       * Set the command-line completer for the console.
       *
       * @param completer     The command-line completer.
       */
      void setCompleter(Completer completer);
      
      /**
       * Get the command-line completer for the console.
       *
       * @return The command-line completer.
       */
      Completer getCompleter();
      
      /**
       * Get a line of input.
       *
       * @param prompt            The command-line prompt to display.
       * @param updateHistory     True to update history, false to disable.
       *
       * @throws IOException      Failed to read input.
       */
      String getLine(String prompt, boolean updateHistory) throws IOException;
      
      /**
       * Get a line of input.
       *
       * @param prompt    The command-line prompt to display.
       *
       * @throws IOException      Failed to read input.
       */
      String getLine(String prompt) throws IOException;
  }
  
  
  
  1.1                  incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/console/ConsoleFactory.java
  
  Index: ConsoleFactory.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.twiddle.console;
  
  /**
  * A factory for creating {@link Console} instances.
   *
   * @version <code>$Id: ConsoleFactory.java,v 1.1 2003/08/13 10:54:37 jdillon Exp $</code>
   * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
   */
  public class ConsoleFactory
  {
      /**
       * Create a new console.
       *
       * @return A new console instance
       *
       * @throws Exception    Failed to create console instance.
       */
      public static Console create() throws Exception
      {
          //
          // TODO: Determine which Console impl to use, create and return it.
          //       For now just use the native Java impl.
          //
          
          return new org.apache.geronimo.twiddle.console.java.Console();
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/console/History.java
  
  Index: History.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.twiddle.console;
  
  /**
   * Provides the interface for command-line history backing.
   *
   * @version <code>$Id: History.java,v 1.1 2003/08/13 10:54:37 jdillon Exp $</code>
   * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
   */
  public interface History
  {
      /**
       * Add a line to the command-line history.
       *
       * @param line  The line to add.
       * @return      The index of the added line.
       */
      int add(String line);
      
      /**
       * Get a line from the command-line history.
       *
       * @param i     The line index to retrieve.
       * @return      The command-line or null if index was not found.
       */
      String get(int i);
      
      /**
       * Get the number of lines in the command-line history.
       *
       * @return The number of lines.
       */
      int size();
      
      /**
       * Clear all command-lines.
       */
      void clear();
  }
  
  
  
  1.1                  incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/console/IOContext.java
  
  Index: IOContext.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.twiddle.console;
  
  import java.io.InputStream;
  import java.io.OutputStream;
  
  import org.apache.geronimo.common.NullArgumentException;
  
  /**
   * Abstraction of a collection of input and output streams.
   *
   * @version <code>$Id: IOContext.java,v 1.1 2003/08/13 10:54:37 jdillon Exp $</code>
   * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
   */
  public class IOContext
  {
      /** The input stream. */
      protected InputStream input;
      
      /** The output stream. */
      protected OutputStream output;
      
      /** The error output stream. */
      protected OutputStream errorOutput;
      
      /**
       * Construct a <code>IOContext</code>.
       *
       * @param input         The input stream.
       * @param output        The output stream.
       * @param errorOutput   The error output stream.
       */
      public IOContext(final InputStream input, final OutputStream output, final OutputStream
errorOutput)
      {
          if (input == null) {
              throw new NullArgumentException("input");
          }
          if (output == null) {
              throw new NullArgumentException("output");
          }
          if (errorOutput == null) {
              throw new NullArgumentException("errorOutput");
          }
          
          this.input = input;
          this.output = output;
          this.errorOutput = errorOutput;
      }
      
      /**
       * Construct a <code>IOContext</code> using the output stream for error
output.
       *
       * @param input     The input stream.
       * @param output    The output stream.
       */
      public IOContext(final InputStream input, final OutputStream output)
      {
          this(input, output, output);
      }
      
      /**
       * Get the input stream.
       *
       * @return The input stream.
       */
      public InputStream getInputStream()
      {
          return input;
      }
      
      /**
       * Get the output stream.
       *
       * @return The output stream.
       */
      public OutputStream getOutputStream()
      {
          return output;
      }
      
      /**
       * Get the error output stream.
       *
       * @return The error output stream.
       */
      public OutputStream getErrorOutputStream()
      {
          return errorOutput;
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/console/TransientHistory.java
  
  Index: TransientHistory.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.twiddle.console;
  
  import java.util.List;
  import java.util.LinkedList;
  
  import org.apache.geronimo.common.NullArgumentException;
  
  /**
   * A transient history backing.
   *
   * @version <code>$Id: TransientHistory.java,v 1.1 2003/08/13 10:54:37 jdillon Exp
$</code>
   * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
   */
  public class TransientHistory
      implements History
  {
      /** The list which provides the backing. */
      protected List backing;
      
      /**
       * Construct a <code>TransientHistory</code> with the given list for backing.
       *
       * @param backing   The list which provides actual backing.
       */
      public TransientHistory(final List backing)
      {
          if (backing == null) {
              throw new NullArgumentException("backing");
          }
          
          this.backing = backing;
      }
      
      /**
       * Construct a <code>TransientHistory</code> with default linked list backing.
       */
      public TransientHistory()
      {
          this(new LinkedList());
      }
      
      
      /////////////////////////////////////////////////////////////////////////
      //                               History                               //
      /////////////////////////////////////////////////////////////////////////
      
      public int add(final String line)
      {
          backing.add(line);
          return backing.size() - 1;
      }
      
      public String get(final int i)
      {
          return (String)backing.get(i);
      }
      
      public int size()
      {
          return backing.size();
      }
      
      public void clear()
      {
          backing.clear();
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/twiddle/src/java/org/apache/geronimo/twiddle/console/java/Console.java
  
  Index: Console.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Geronimo" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Geronimo", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   * ====================================================================
   */
  
  package org.apache.geronimo.twiddle.console.java;
  
  import java.io.IOException;
  import java.io.EOFException;
  import java.io.BufferedReader;
  import java.io.InputStreamReader;
  import java.io.PrintWriter;
  import java.io.OutputStreamWriter;
  
  import org.apache.geronimo.twiddle.console.AbstractConsole;
  import org.apache.geronimo.twiddle.console.Completer;
  import org.apache.geronimo.twiddle.console.History;
  import org.apache.geronimo.twiddle.console.TransientHistory;
  
  /**
   * An implementation of <code>Console</code> in pure Java.
   *
   * <p>Limitations:
   * <ul>
   *    <li>Minimal support for history (collection).
   *    <li>Does not support completion.
   * </ul>
   *
   * @version <code>$Id: Console.java,v 1.1 2003/08/13 10:54:37 jdillon Exp $</code>
   * @author <a href="mailto:jason@planet57.com">Jason Dillon</a>
   */
  public class Console
      extends AbstractConsole
  {
      /** The reader to get input from. */
      protected BufferedReader reader;
      
      /** The writer to render the prompt to. */
      protected PrintWriter writer;
      
      /**
       * Construct a native Java console, using a transient history map.
       */
      public Console()
      {
          setHistory(new TransientHistory());
      }
      
      /**
       * The native Java console impl can not perform completion (at this time).
       *
       * @throws UnsupportedOperationException
       */
      public void setCompleter(Completer completer)
      {
          throw new UnsupportedOperationException();
      }
      
      /**
       * Helper to lazy initialize the reader.
       */
      protected BufferedReader getReader()
      {
          if (reader == null) {
              reader = new BufferedReader(new InputStreamReader(getIOContext().getInputStream()));
          }
          
          return reader;
      }
      
      /**
       * Helper to lazy initialize the writer.
       */
      protected PrintWriter getWriter()
      {
          if (writer == null) {
              writer = new PrintWriter(new OutputStreamWriter(getIOContext().getOutputStream()));
          }
          
          return writer;
      }
      
      /**
       * Get a line of input.
       *
       * @param prompt            The prompt to render.
       * @param updateHistory     True to update history with non-null input.
       * @return                  A line of input, or null if the line was empty.
       *
       * @throws EOFException
       * @throws IOException
       */
      public String getLine(final String prompt, final boolean updateHistory) 
          throws IOException
      {
          // Render the prompt
          PrintWriter writer = getWriter();
          writer.print(prompt);
          writer.flush();
          
          // Get some input
          BufferedReader reader = getReader();
          String line = reader.readLine();
          
          // Sanity check the results
          if (line == null) {
              throw new EOFException();
          }
          if (line.length() == 0) {
              line = null;
          }
          
          // Update history
          if (line != null && updateHistory && isHistoryEnabled()) {
              History h = getHistory();
              h.add(line);
          }
          
          return line;
      }
  }
  
  
  

Mime
View raw message