New protocol wrapping transport model for Thrift Java


git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@664846 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/lib/java/src/protocol/TProtocol.java b/lib/java/src/protocol/TProtocol.java
index 0831d12..43b4f07 100644
--- a/lib/java/src/protocol/TProtocol.java
+++ b/lib/java/src/protocol/TProtocol.java
@@ -8,106 +8,129 @@
  *
  * @author Mark Slee <mcslee@facebook.com>
  */
-public interface TProtocol {
+public abstract class TProtocol {
+
+  /**
+   * Prevent direct instantiation
+   */
+  private TProtocol() {}
+
+  /**
+   * Input transport
+   */ 
+  protected TTransport inputTransport_;
+
+  /**
+   * Output transport
+   */
+  protected TTransport outputTransport_;
+
+  /**
+   * Constructor
+   */
+  protected TProtocol(TTransport in, TTransport out) {
+    inputTransport_ = in;
+    outputTransport_ = out;
+  }
+  
+  /**
+   * Input accessor
+   */
+  public TTransport getInputTransport() {
+    return inputTransport_;
+  }
+
+  /**
+   * Output accessor
+   */
+  public TTransport getOutputTransport() {
+    return outputTransport_;
+  }
 
   /**
    * Writing methods.
    */
 
-  public void writeMessageBegin(TTransport out,
-                                TMessage   message) throws TException;
+  public abstract void writeMessageBegin(TMessage message) throws TException;
 
-  public void writeMessageEnd  (TTransport out)     throws TException;
+  public abstract void writeMessageEnd() throws TException;
   
-  public void writeStructBegin (TTransport out,
-                                TStruct    struct)  throws TException;
+  public abstract void writeStructBegin(TStruct struct) throws TException;
 
-  public void writeStructEnd   (TTransport out)     throws TException;
+  public abstract void writeStructEnd() throws TException;
 
-  public void writeFieldBegin  (TTransport out,
-                                TField     field)   throws TException;
+  public abstract void writeFieldBegin(TField field) throws TException;
 
-  public void writeFieldEnd    (TTransport out)     throws TException;
+  public abstract void writeFieldEnd() throws TException;
 
-  public void writeFieldStop   (TTransport out)     throws TException;
+  public abstract void writeFieldStop() throws TException;
 
-  public void writeMapBegin    (TTransport out,
-                                TMap       map)     throws TException;
+  public abstract void writeMapBegin(TMap map) throws TException;
 
-  public void writeMapEnd      (TTransport out)     throws TException;
+  public abstract void writeMapEnd() throws TException;
 
-  public void writeListBegin   (TTransport out,
-                                TList      list)    throws TException;
+  public abstract void writeListBegin(TList list) throws TException;
 
-  public void writeListEnd     (TTransport out)     throws TException;
+  public abstract void writeListEnd() throws TException;
 
-  public void writeSetBegin    (TTransport out,
-                                TSet       set)     throws TException;
+  public abstract void writeSetBegin(TSet set) throws TException;
 
-  public void writeSetEnd      (TTransport out)     throws TException;
+  public abstract void writeSetEnd() throws TException;
 
-  public void writeBool        (TTransport out,
-                                boolean    b)       throws TException;
+  public abstract void writeBool(boolean b) throws TException;
 
-  public void writeByte        (TTransport out,
-                                byte       b)       throws TException;
+  public abstract void writeByte(byte b) throws TException;
 
-  public void writeI16         (TTransport out,
-                                short      i16)     throws TException;
+  public abstract void writeI16(short i16) throws TException;
 
-  public void writeI32         (TTransport out,
-                                int        i32)     throws TException;
+  public abstract void writeI32(int i32) throws TException;
 
-  public void writeI64         (TTransport out,
-                                long       i64)     throws TException;
+  public abstract void writeI64(long i64) throws TException;
 
-  public void writeDouble      (TTransport out,
-                                double     dub)     throws TException;
+  public abstract void writeDouble(double dub) throws TException;
 
-
-  public void writeString      (TTransport out,
-                                String     str)     throws TException;
+  public abstract void writeString(String str) throws TException;
 
   /**
    * Reading methods.
    */
 
-  public TMessage readMessageBegin (TTransport in)  throws TException;
+  public abstract TMessage readMessageBegin() throws TException;
 
-  public void     readMessageEnd   (TTransport in)  throws TException;
+  public abstract void readMessageEnd() throws TException;
 
-  public TStruct  readStructBegin  (TTransport in)  throws TException;
+  public abstract TStruct readStructBegin() throws TException;
 
-  public void     readStructEnd    (TTransport in)  throws TException;
+  public abstract void readStructEnd() throws TException;
 
-  public TField   readFieldBegin   (TTransport in)  throws TException;
+  public abstract TField readFieldBegin() throws TException;
   
-  public void     readFieldEnd     (TTransport in)  throws TException;
+  public abstract void readFieldEnd() throws TException;
  
-  public TMap     readMapBegin     (TTransport in)  throws TException;
+  public abstract TMap readMapBegin() throws TException;
 
-  public void     readMapEnd       (TTransport in)  throws TException;
+  public abstract void readMapEnd() throws TException;
 
-  public TList    readListBegin    (TTransport in)  throws TException;
+  public abstract TList readListBegin() throws TException;
 
-  public void     readListEnd      (TTransport in)  throws TException;
+  public abstract void readListEnd() throws TException;
 
-  public TSet     readSetBegin     (TTransport in)  throws TException;
+  public abstract TSet readSetBegin() throws TException;
 
-  public void     readSetEnd       (TTransport in)  throws TException;
+  public abstract void readSetEnd() throws TException;
 
-  public boolean  readBool         (TTransport in)  throws TException;
+  public abstract boolean readBool() throws TException;
 
-  public byte     readByte         (TTransport in)  throws TException;
+  public abstract byte readByte() throws TException;
 
-  public short    readI16          (TTransport in)  throws TException;
+  public abstract short readI16() throws TException;
 
-  public int      readI32          (TTransport in)  throws TException;
+  public abstract int readI32() throws TException;
  
-  public long     readI64          (TTransport in)  throws TException;
+  public abstract long readI64() throws TException;
 
-  public double   readDouble       (TTransport in)  throws TException;
+  public abstract double readDouble() throws TException;
 
-  public String   readString       (TTransport in)  throws TException;
+  public abstract String readString() throws TException;
 
 }