Example usage for com.google.gwt.autobean.shared AutoBeanUtils getAutoBean

List of usage examples for com.google.gwt.autobean.shared AutoBeanUtils getAutoBean

Introduction

In this page you can find the example usage for com.google.gwt.autobean.shared AutoBeanUtils getAutoBean.

Prototype

@SuppressWarnings("unchecked")
public static <T, U extends T> AutoBean<T> getAutoBean(U delegate) 

Source Link

Document

Return the single AutoBean wrapper that is observing the delegate object or null if the parameter is null or not wrapped by an AutoBean.

Usage

From source file:com.acme.gwt.server.TvViewerJsonBootstrap.java

License:Apache License

public String getViewerAsJson() {
    SimpleRequestProcessor p = new SimpleRequestProcessor(ServiceLayer.create(isld));
    TvViewer user = viewerProvider.get();
    if (user == null) {
        return "";
    }//from w  w  w.jav  a  2s  .  co m

    MessageFactory factory = MessageFactoryHolder.FACTORY;
    AutoBean<IdMessage> id = factory.id();
    try {
        id.as().setServerId(Base64Utils.toBase64(user.getId().toString().getBytes("UTF-8")));
    } catch (UnsupportedEncodingException e) {
        return "";
    }
    id.as().setStrength(Strength.PERSISTED);
    id.as().setTypeToken(TvViewerProxy.class.getName());

    AutoBean<RequestMessage> msg = factory.request();
    msg.as().setInvocations(new ArrayList<InvocationMessage>());
    InvocationMessage invocation = factory.invocation().as();
    invocation.setOperation("com.google.gwt.requestfactory.shared.impl.FindRequest::find");
    invocation.setParameters(new ArrayList<Splittable>());
    invocation.getParameters().add(AutoBeanCodex.encode(id));
    msg.as().getInvocations().add(invocation);

    String value = p.process(AutoBeanCodex.encode(msg).getPayload());

    ResponseMessage response = AutoBeanCodex.decode(factory, ResponseMessage.class, value).as();
    OperationMessage opMsg = response.getOperations().get(0);
    DefaultProxyStore store = new DefaultProxyStore();
    store.put(TvViewerProxy.STORE_KEY, AutoBeanCodex.encode(AutoBeanUtils.getAutoBean(opMsg)));

    return store.encode();
}