OK, I've finally got some time to look at this again. But I'm still having 
some issues. Based on your feedback, I should eliminate the following two 
classes:

   - Class to represent the request and hold its DTO
   - Class to represent the response and hold its DTO

These currently both extend an abstract generic class (one implements 
Action and one implements Response). I haven't been able to make those 
classes generic enough that these 2 request/response classes can be removed.

I suppose that I may need to use GIN to make this happen, but I have not 
yet figured out if that would be required and/or how to do it yet.

*Here are the abstract classes:*

public abstract class CustomRequest<T> implements 
Action<CustomResponse<T>>, Serializable
{
private static final long serialVersionUID = 2497682157216814807L;
 private T request;
 public void setRequest(T request)
{
this.request = request;
}
 public T getRequest()
{
return request;
}
}

public abstract class CustomResponse<T> implements Response, Serializable
{
private static final long serialVersionUID = -7854717568064553824L;
private T response;
private String statusString = "";
private int msgStatus = 0;
 public T getResponse()
{
return response;
}
 public void setResponse(T response)
{
this.response = response;
}

        // Getters and setters.
}

*Then the classes that extend these abstract req/response classes:*

public class Login extends CustomRequest<MyLoginReqDto>
{
private static final long serialVersionUID = 2497682157216814807L;
 public Login() {}
public Login(MyLoginReqDto creds)
{
setRequest(creds);
}
}

public class LoginResponse extends CustomResponse<MyLoginReqDto>
{
private static final long serialVersionUID = -7854717568064553824L;
public LoginResponse() {}
public LoginResponse(MyLoginReqDto creds)
{
setResponse(creds);
}
}

So obviously for each of my ~40 DTOs, I need to send/receive a different 
DTO. I'm not completely clear on how to do this while eliminating all 4 of 
the classes above.

*Here are my service interfaces:*

@RemoteServiceRelativePath("Login") 
public interface LoginService extends RemoteService
{
@SuppressWarnings("rawtypes")
CustomResponse sendRequest(Login req);
}

public interface LoginServiceAsync<T>
{
void sendRequest(Login req, AsyncCallback<CustomResponse<T>> callback);
}

*And then my service implementation:*

public class LoginServiceImpl
extends CustomService<Login, LoginResponse> implements LoginService
{
private static final long serialVersionUID = 8883630570739973203L;
        public LoginResponse getDataFromJNI(Login req)
        {
                // custom code to deal with the backend data retrieval.
        }
}

*Finally, my abstract service:*
*
*
public abstract class CustomService<REQ extends CustomRequest, RSP extends 
CustomResponse> extends RemoteServiceServlet
{
         // static System.loadLibrary() call for JNI connection.

public RSP sendRequest(REQ req)
{
RSP response = null;
 try
{
if (jniConnection == null)
{
// custom JNI connection code.
}
 response = getDataFromJNI(req);
}
catch (Exception ex)
{
ex.printStackTrace();
}
 return response;
}

        protected abstract RSP getDataFromJNI(REQ req);
}

So this does get my JNI connection code factored out into a single class. 
But it still is causing me to need to define a specific Request/Response 
for every service.

I'd love to have a single service handle all of the different DTOs with a 
single service implementation and various methods to handle each DTO. I'm 
just not clear on how I can make that happen and I'm running short on 
schedule time to be contemplating and researching. I've looked at a ton of 
examples online, but I haven't been able to find one that really maps to 
what I need and makes sense. I haven't found one that handles many 
different DTOs in a single service implementation.

Please let me know if I'm way off here. Is DI the way to solve all of this? 
Is it just a minor tweak to my classes? Or do I need to start from scratch 
with a whole new approach? If you have a link to a project or bit of code 
that already demonstrates this, I would love to see it.

Thank you,

Michael Prentice
GDG Space Coast
Hope to see you at http://gwtcreate.com/ in December!

On Saturday, August 3, 2013 5:18:21 AM UTC-4, Thomas Broyer wrote:
>
>
> How about using a single service/serviceAsync/serviceImpl for more than 
> one request/response/DTOs? Instead of "40 services" with all that 
> boilerplate, you'd *only* need 40 methods on a single *service*.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-web-toolkit+unsubscr...@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to