001    /*
002     * Copyright (C) 2010 eXo Platform SAS.
003     *
004     * This is free software; you can redistribute it and/or modify it
005     * under the terms of the GNU Lesser General Public License as
006     * published by the Free Software Foundation; either version 2.1 of
007     * the License, or (at your option) any later version.
008     *
009     * This software is distributed in the hope that it will be useful,
010     * but WITHOUT ANY WARRANTY; without even the implied warranty of
011     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012     * Lesser General Public License for more details.
013     *
014     * You should have received a copy of the GNU Lesser General Public
015     * License along with this software; if not, write to the Free
016     * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
017     * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
018     */
019    
020    package org.crsh.term;
021    
022    /**
023     * An event emitted by a term.
024     *
025     * @author <a href="mailto:julien.viet@exoplatform.com">Julien Viet</a>
026     * @version $Revision$
027     */
028    public abstract class TermEvent {
029    
030      public static Complete complete(CharSequence line) {
031        return new Complete(line);
032      }
033    
034      public static Close close() {
035        return Close.INSTANCE;
036      }
037    
038      public static ReadLine readLine(CharSequence line) {
039        return new ReadLine(line);
040      }
041    
042      public static Break brk() {
043        return Break.INSTANCE;
044      }
045    
046      private TermEvent() {
047      }
048    
049      @Override
050      public String toString() {
051        return getClass().getSimpleName() + "[]";
052      }
053    
054      /**
055       * Signals a control-break.
056       */
057      public static class Close extends TermEvent {
058    
059        /** . */
060        private static final Close INSTANCE = new Close();
061    
062        private Close() {
063        }
064      }
065    
066      /**
067       * Signals a control-break.
068       */
069      public static class Break extends TermEvent {
070    
071        /** . */
072        private static final Break INSTANCE = new Break();
073    
074        private Break() {
075        }
076      }
077    
078      /**
079       * Signals the completion of a text line.
080       */
081      public static class Complete extends TermEvent {
082    
083        /** The line to be completed. */
084        private CharSequence line;
085    
086        private Complete(CharSequence line) {
087          this.line = line;
088        }
089    
090        public CharSequence getLine() {
091          return line;
092        }
093    
094        @Override
095        public String toString() {
096          return "Complete[line=" + line + "]";
097        }
098      }
099    
100      /**
101       * Signals a line was submitted for processing.
102       */
103      public static class ReadLine extends TermEvent {
104    
105        /** . */
106        private final CharSequence line;
107    
108        private ReadLine(CharSequence line) {
109          this.line = line;
110        }
111    
112        public CharSequence getLine() {
113          return line;
114        }
115    
116        @Override
117        public String toString() {
118          return "ReadLine[line=" + line + "]";
119        }
120      }
121    }