/** * Request selector interface for implementing a find method. */ @Service(FindService.class) public interface FindRequest extends RequestContext { /** * Use the implicit lookup in passing EntityProxy types to service methods. */ <P extends EntityProxy> Request<P> find(EntityProxyId<P> proxyId); }
/** * Returns the key Object for the given item. * * @param item an item of type P */ public Object getKey(P item) { return item == null ? null : item.stableId(); } }
@Override protected void dispatch(Handler<P> handler) { handler.onProxyChange(this); } }
public void onResponseReceived(Request request, Response response) { wireLogger.finest("Response received"); if (Response.SC_OK == response.getStatusCode()) { String text = response.getText(); receiver.onTransportSuccess(text); } else { String message = SERVER_ERROR + " " + response.getStatusCode() + " " + response.getText(); wireLogger.severe(message); receiver.onTransportFailure(new ServerFailure(message)); } } };
@Override public void execute() { assert !openContextImpl.isLocked() : "AbstractRequestContext.fire() should have been a no-op"; openContextImpl.setFireDisabled(false); openContext.fire(); openContext = null; openContextImpl = null; } });
@Override public void onFailure(ServerFailure error) { try { if (toCall != null) { for (Receiver<? super T> r : toCall) { try { r.onFailure(error); } catch (Throwable t) { onUncaughtThrowable(t); } } } } finally { finish(); } }
@Override public void onConstraintViolation(Set<ConstraintViolation<?>> violations) { try { if (toCall != null) { for (Receiver<? super T> r : toCall) { try { r.onConstraintViolation(violations); } catch (Throwable t) { onUncaughtThrowable(t); } } } } finally { finish(); } }
@Override public void onSuccess(T response) { try { if (toCall != null) { for (Receiver<? super T> r : toCall) { try { r.onSuccess(response); } catch (Throwable t) { onUncaughtThrowable(t); } } } } finally { finish(); } }
public void onError(Request request, Throwable exception) { wireLogger.log(Level.SEVERE, SERVER_ERROR, exception); receiver.onTransportFailure(new ServerFailure(exception.getMessage())); }
/** * Called if an object sent to the server could not be validated. The default * implementation calls {@link #onFailure(ServerFailure)} if <code>errors * </code> is not empty. * * @param errors a Set of {@link Violation} instances * @deprecated Use {@link #onConstraintViolation(Set)} instead */ @Deprecated public void onViolation(Set<Violation> errors) { if (!errors.isEmpty()) { onFailure(new ServerFailure("The call failed on the server due to a ConstraintViolation")); } }
@Override protected RequestData makeRequestData() { // This method is normally generated, hence the ugly constructor return new RequestData(Constants.FIND_METHOD_OPERATION, new Object[] {proxyId}, propertyRefs, proxyId.getProxyClass(), null); } };
/** * An analog to EntityProxy for domain types that do not have an identity * concept. */ @ProxyFor(Object.class) public interface ValueProxy extends BaseProxy { }
void onFail(ServerFailure failure) { if (receiver != null) { receiver.onFailure(failure); } }
void onViolation(Set<ConstraintViolation<?>> errors) { // The user may not have called to() if (receiver != null) { receiver.onConstraintViolation(errors); } } }
@Override protected <T> T ensureMutable(T object) { if (request == null) { // Read-only mode return object; } if (object instanceof BaseProxy) { @SuppressWarnings("unchecked") T toReturn = (T) request.edit((BaseProxy) object); return toReturn; } return object; }
@Override public String getMessage() { return v.getMessage(); }
@Override public String getPath() { return v.getPath(); }
@Override public Object getKey() { return v.getOriginalProxy(); }
/** * A stable, opaque id of an {@link EntityProxy} that remains stable across * updates, creates, deletes on the client. * <p> * In particular, an {@link EntityProxy} foo that is yet to be persisted and a * copy of foo after being persisted have equal {@link EntityProxyId}. * * @param <P> the entity type */ @ProxyFor(Object.class) public interface EntityProxyId<P extends EntityProxy> { /** * Returns the class of the proxy identified. * * @return a Class object of type P */ Class<P> getProxyClass(); }
/** * Returns an unpopulated copy of the changed proxy — all properties are * undefined except its id. * * @return an instance of {@link EntityProxyId}<P> */ @SuppressWarnings("unchecked") public EntityProxyId<P> getProxyId() { return (EntityProxyId<P>) proxy.stableId(); }