001 /* 002 * Copyright (C) 2012 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.telnet.term; 021 022 public abstract class TermEvent { 023 024 public static Complete complete(CharSequence line) { 025 return new Complete(line); 026 } 027 028 public static Close close() { 029 return Close.INSTANCE; 030 } 031 032 public static ReadLine readLine(CharSequence line) { 033 return new ReadLine(line); 034 } 035 036 public static Break brk() { 037 return Break.INSTANCE; 038 } 039 040 private TermEvent() { 041 } 042 043 @Override 044 public String toString() { 045 return getClass().getSimpleName() + "[]"; 046 } 047 048 /** 049 * Signals a control-break. 050 */ 051 public static class Close extends TermEvent { 052 053 /** . */ 054 private static final Close INSTANCE = new Close(); 055 056 private Close() { 057 } 058 } 059 060 /** 061 * Signals a control-break. 062 */ 063 public static class Break extends TermEvent { 064 065 /** . */ 066 private static final Break INSTANCE = new Break(); 067 068 private Break() { 069 } 070 } 071 072 /** 073 * Signals the completion of a text line. 074 */ 075 public static class Complete extends TermEvent { 076 077 /** The line to be completed. */ 078 private CharSequence line; 079 080 private Complete(CharSequence line) { 081 this.line = line; 082 } 083 084 public CharSequence getLine() { 085 return line; 086 } 087 088 @Override 089 public String toString() { 090 return "Complete[line=" + line + "]"; 091 } 092 } 093 094 /** 095 * Signals a line was submitted for processing. 096 */ 097 public static class ReadLine extends TermEvent { 098 099 /** . */ 100 private final CharSequence line; 101 102 private ReadLine(CharSequence line) { 103 this.line = line; 104 } 105 106 public CharSequence getLine() { 107 return line; 108 } 109 110 @Override 111 public String toString() { 112 return "ReadLine[line=" + line + "]"; 113 } 114 } 115 }