Skip to main content

[jax-rs-spec issues] [JIRA] Assigned: (JAX_RS_SPEC-15) Response/ResponseBuilder should be Generic

  • From: "Marek Potociar (JIRA)" <jira-no-reply@...>
  • To: issues@...
  • Subject: [jax-rs-spec issues] [JIRA] Assigned: (JAX_RS_SPEC-15) Response/ResponseBuilder should be Generic
  • Date: Fri, 24 Feb 2012 20:15:39 +0000 (GMT+00:00)
  • Auto-submitted: auto-generated


     [ 
http://java.net/jira/browse/JAX_RS_SPEC-15?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Marek Potociar reassigned JAX_RS_SPEC-15:
-----------------------------------------

    Assignee: Marek Potociar

> Response/ResponseBuilder should be Generic
> ------------------------------------------
>
>                 Key: JAX_RS_SPEC-15
>                 URL: http://java.net/jira/browse/JAX_RS_SPEC-15
>             Project: jax-rs-spec
>          Issue Type: Improvement
>         Environment: Operating System: All
> Platform: All
> URL: 
> http://n2.nabble.com/xml-schema-in-request-and-response-wadl-td3943317.html#a3943317
>            Reporter: gdavison
>            Assignee: Marek Potociar
>             Fix For: 2.0
>
>
> As discussed in this thread, ideally Response/ResponseBuilder would be 
> generic
> to better support static discovery of types for WADL.
> A couple of methods were discussed. Paul Sandoz's original proposal made 
> use of
> the .<Type> notation:
> public class Main {
>      public static class Response<T> {
>          private final T entity;
>          private Response(T entity) {
>              this.entity = entity;
>          }
>          public T getEntity() {
>              return entity;
>          }
>          public static class ResponseBuilder<T> {
>              private T entity;
>              public ResponseBuilder<T> entity(T entity) {
>                  this.entity = entity;
>                  return this;
>              }
>              public Response<T> build() {
>                  return new Response<T>(entity);
>              }
>              static protected <T> ResponseBuilder<T> newInstance() {
>                  return  
> RuntimeDelegate.getInstance().<T>createResponseBuilder();
>              }
>          }
>          static public <T> ResponseBuilder<T> start() {
>              return new ResponseBuilder<T>();
>          }
>      }
>      public static class RuntimeDelegate {
>          public static RuntimeDelegate getInstance() {
>              return new RuntimeDelegate();
>          }
>          public <T> Response.ResponseBuilder<T>  
> createResponseBuilder() {
>              return new Response.ResponseBuilder<T>();
>          }
>      }
>      /**
>       * @param args the command line arguments
>       */
>      public static void main(String[] args) {
>          Response<String> r =  
> Response.<String>start().entity("xx").build();
>          String e = r.getEntity();
>          System.out.println(e);
>      }
> } 
> And then I put forward a modified version that removed the need for using 
> the
> .<Type> notation by creating a new interim typed version of the Builder:
> // Generified Response
> ~
> public class Response<T> {
>     static class GListString extends GenericEntity<List<String>> {
>         public GListString(List<String> list) {
>             super(list);
>         }
>     }
>     private final T entity;
>     private Response(T entity) {
>         this.entity = entity;
>     }
>     public T getEntity() {
>         return entity;
>     }
>    
>     public static <T> ResponseBuilder<T> start() {
>         return new ResponseBuilder<T>("Some State");
>     }
>    
>     public static class ResponseBuilder<T> {
>         private Object state;
>         private Type type;
>         private T entity;
>         public ResponseBuilder(Object state) {
>             this.state = state;
>         }
>         public ResponseBuilder(Object state, Type type, T object) {
>             this(state);
>             this.type = type;
>             this.entity = object;
>         }
>        
>        
>         public ResponseBuilder<T> header(String name, String value) {
>             return this;
>         }
>         public <T, K extends GenericEntity<T>> ResponseBuilder<T>
> entity(K ent) {
>             return new ResponseBuilder<T>(state, ent.getType(),
> ent.getEntity());
>         }
>         public <T> ResponseBuilder<T> entity(T ent) {
>             return new ResponseBuilder<T>(state, ent.getClass(), ent);
>         }
>         public Response<T> build() {
>             return new Response<T>(entity);
>         }
>     }
>     public static void main(String[] args) {
>         List<String> list = new ArrayList<String>();
>         GListString genericList =
>             new GListString(list);
>         Response<List<String>> response = Response
>             .start()
>             .header("Content-Type", "fudge")
>             .entity(list)
>             .build();
>         // Using generic entity
>         //
>         Response<List<String>> genericResponse = Response
>             .start()
>             .header("Content-Type", "fudge")
>             .entity(genericList)
>             .build();
>         // String example
>         //
>        
>         Response<String> stringResponse = Response
>            .start()                        // ResponseBuilder<?>
>            .entity("String")           // ResponseBuilder<String>
>            .header("Content-Type", "cheese")  // ResponseBuilder<String>
>            .build();
>     }
> } 
> It is possible that neither solution is correct; but it would be good to 
> look
> for a modification that covers some of the ideas in the 2.x spec release.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://java.net/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        


[jax-rs-spec issues] [JIRA] Assigned: (JAX_RS_SPEC-15) Response/ResponseBuilder should be Generic

Marek Potociar (JIRA) 02/24/2012
 
 
Close
loading
Please Confirm
Close