[ 
https://issues.apache.org/jira/browse/THRIFT-2531?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jeremiah Menétrey updated THRIFT-2531:
--------------------------------------

    Description: 
Currently, generated thrift objects implement the TBase interface, which 
defines generic methods applicable to all generated objects (read/write from 
protocol objects, retrieving a field value by specifying the field ID).

My request is for the generation of an interface for each thrift object, which 
in turn implement that interface.

The interface should contain all getters and setters for the fields specified 
in the thrift definition (e.g. {{getXXX()}}, {{setXXX(...)}}, {{isXXXSet()}}, 
etc.).
All those methods are already generated for thrift objects, they just should 
also be declared in an interface for each object.

*Rationale*
This will allow to use Java's dynamic proxies to decorate and manipulate thrift 
objects.
Java's reflective framework ({{Proxy}} and {{InvocationHandler}}) work with 
interfaces and are not able to manage classes as proxyed types. E.g. it is not 
possible to cast a proxy for an instance of {{MyType}} to a variable of type 
{{MyType}} if {{MyType}} is not an interface.

Thus, if the class {{MyType}} defines getters and setters, the user will not be 
able to use them behind a dynamic proxy as casting the proxy to {{MyType}} will 
throw a {{ClassCastException}}.

{code}
public interface MyIFace { ... }
public class MyClass implements MyIFace { ... }
{code}
{code}
// proxify(MyClass instance) is implemented somewhere
// The proxy has to declare proxying for an interface (MyIFace) or it won't 
even compile.

MyIFace f = (MyIFace) proxify(new MyClass()) // OK
MyClass x = (MyClass) proxify(new MyClass()) // Throws ClassCastException
{code}

  was:
Currently, generated thrift objects implement the TBase interface, which 
defines generic methods applicable to all generated objects (read/write from 
protocol objects, retrieving a field value by specifying the field ID).

My request is for the generation of an interface for each thrift object, which 
in turn implement that interface. It looks like what is already done for thrift 
services:

{code}
public class MyType implements org.apache.thrift.TBase<MyType, MyType._Fields>, 
MyType.IFace, ... {
  public interface IFace {
    ...
  }
  ...
}
{code}

The interface should contain all getters and setters for the fields specified 
in the thrift definition (e.g. {{getXXX()}}, {{setXXX(...)}}, {{isXXXSet()}}, 
etc.).
All those methods are already generated for thrift objects, they just should 
also be declared in an interface for each object.

*Rationale*
This will allow to use Java's dynamic proxies to decorate and manipulate thrift 
objects.
Java's reflective framework ({{Proxy}} and {{InvocationHandler}}) work with 
interfaces and are not able to manage classes as proxyed types. E.g. it is not 
possible to cast a proxy for an instance of {{MyType}} to a variable of type 
{{MyType}} if {{MyType}} is not an interface.

Thus, if the class {{MyType}} defines getters and setters, the user will not be 
able to use them behind a dynamic proxy as casting the proxy to {{MyType}} will 
throw a {{ClassCastException}}.

{code}
public interface MyIFace { ... }
public class MyClass implements MyIFace { ... }
{code}
{code}
// proxify(MyClass instance) is implemented somewhere
// The proxy has to declare proxying for an interface (MyIFace) or it won't 
even compile.

MyIFace f = (MyIFace) proxify(new MyClass()) // OK
MyClass x = (MyClass) proxify(new MyClass()) // Throws ClassCastException
{code}


> Generate Interface for thrift objects
> -------------------------------------
>
>                 Key: THRIFT-2531
>                 URL: https://issues.apache.org/jira/browse/THRIFT-2531
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Java - Compiler
>    Affects Versions: 0.7, 0.9.1
>         Environment: Java 6
>            Reporter: Jeremiah Menétrey
>              Labels: features
>
> Currently, generated thrift objects implement the TBase interface, which 
> defines generic methods applicable to all generated objects (read/write from 
> protocol objects, retrieving a field value by specifying the field ID).
> My request is for the generation of an interface for each thrift object, 
> which in turn implement that interface.
> The interface should contain all getters and setters for the fields specified 
> in the thrift definition (e.g. {{getXXX()}}, {{setXXX(...)}}, {{isXXXSet()}}, 
> etc.).
> All those methods are already generated for thrift objects, they just should 
> also be declared in an interface for each object.
> *Rationale*
> This will allow to use Java's dynamic proxies to decorate and manipulate 
> thrift objects.
> Java's reflective framework ({{Proxy}} and {{InvocationHandler}}) work with 
> interfaces and are not able to manage classes as proxyed types. E.g. it is 
> not possible to cast a proxy for an instance of {{MyType}} to a variable of 
> type {{MyType}} if {{MyType}} is not an interface.
> Thus, if the class {{MyType}} defines getters and setters, the user will not 
> be able to use them behind a dynamic proxy as casting the proxy to {{MyType}} 
> will throw a {{ClassCastException}}.
> {code}
> public interface MyIFace { ... }
> public class MyClass implements MyIFace { ... }
> {code}
> {code}
> // proxify(MyClass instance) is implemented somewhere
> // The proxy has to declare proxying for an interface (MyIFace) or it won't 
> even compile.
> MyIFace f = (MyIFace) proxify(new MyClass()) // OK
> MyClass x = (MyClass) proxify(new MyClass()) // Throws ClassCastException
> {code}



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to