/** * Register a instance of a client-side action handler. * * @param handler The {@link ClientActionHandler}; */ protected void register(final ClientActionHandler<?, ?> handler) { register(handler.getActionType(), new IndirectProvider<ClientActionHandler<?, ?>>() { @Override public void get(AsyncCallback<ClientActionHandler<?, ?>> callback) { callback.onSuccess(handler); } }); }
/** * Register an {@link com.google.gwt.inject.client.AsyncProvider} of a client-side action handler. * * @param actionType The type of that the client-side action handler supports. * @param handlerProvider The {@link com.google.gwt.inject.client.AsyncProvider} of the handler. */ protected void register(Class<?> actionType, final AsyncProvider<? extends ClientActionHandler<?, ?>> handlerProvider) { register(actionType, new IndirectProvider<ClientActionHandler<?, ?>>() { @Override public void get(AsyncCallback<ClientActionHandler<?, ?>> callback) { handlerProvider.get(callback); } }); }
@Override public void onSuccess(ClientActionHandler<?, ?> clientActionHandler) { if (clientActionHandler.getActionType() != action.getClass()) { dispatchRequest.cancel(); callback.onFailure(new ClientActionHandlerMismatchException( (Class<? extends Action<?>>) action.getClass(), clientActionHandler.getActionType())); return; } if (dispatchRequest.isPending()) { dispatchRequest.setDelegate(((ClientActionHandler<A, R>) clientActionHandler).execute( action, callback, new ExecuteCommand<A, R>() { @Override public DispatchRequest execute(A action, AsyncCallback<R> resultCallback) { if (dispatchRequest.isPending()) { return doExecute(securityCookie, action, resultCallback); } else { return null; } } })); } }
@Override public void onSuccess(ClientActionHandler<?, ?> clientActionHandler) { if (clientActionHandler.getActionType() != action.getClass()) { dispatchRequest.cancel(); callback.onFailure(new ClientActionHandlerMismatchException( (Class<? extends Action<?>>) action.getClass(), clientActionHandler.getActionType())); return; } if (dispatchRequest.isPending()) { dispatchRequest.setDelegate(((ClientActionHandler<A, R>) clientActionHandler).undo( action, result, callback, new UndoCommand<A, R>() { @Override public DispatchRequest undo(A action, R result, AsyncCallback<Void> callback) { if (dispatchRequest.isPending()) { return doUndo(securityCookie, action, result, callback); } else { return null; } } })); } }
private void delegateFailure(ClientActionHandler<?, ?> clientActionHandler) { ClientActionHandlerMismatchException exception = new ClientActionHandlerMismatchException(action.getClass(), clientActionHandler.getActionType()); onFailure(exception); }
private void delegateExecute(ClientActionHandler<A, R> clientActionHandler) { dispatchRequest.setDelegate(clientActionHandler.execute(action, callback, this)); } }
@SuppressWarnings("unchecked") @Override public void onSuccess(ClientActionHandler<?, ?> clientActionHandler) { if (clientActionHandler.getActionType() != action.getClass()) { delegateFailure(clientActionHandler); } else if (dispatchRequest.isPending()) { delegateExecute((ClientActionHandler<A, R>) clientActionHandler); } }
@SuppressWarnings("unchecked") @Override public <A extends Action<R>, R extends Result> DispatchRequest undo(A action, R result, AsyncCallback<Void> callback) { ClientActionHandler<?, ?> clientActionHandler = clientActionHandlers.get(action.getClass()); if (clientActionHandler != null) { DelegatingDispatchRequest request = new DelegatingDispatchRequest(); ((ClientActionHandler<A, R>) clientActionHandler).undo(action, result, callback, new UndoCommand<A, R>() { @Override public DispatchRequest undo(A action, R result, AsyncCallback<Void> callback) { return serviceUndo(action, result, callback); } }); return request; } else { serviceUndo(action, result, callback); return new TestingDispatchRequest(); } }
.find(action.getClass());
/** * Register a instance of a client-side action handler. * * @param handler The {@link ClientActionHandler}; */ protected void register(final ClientActionHandler<?, ?> handler) { register(handler.getActionType(), new IndirectProvider<ClientActionHandler<?, ?>>() { @Override public void get(AsyncCallback<ClientActionHandler<?, ?>> callback) { callback.onSuccess(handler); } }); }
/** * Register a {@link javax.inject.Provider} of a client-side action handler. * * @param actionType The type of action that the client-side action handler supports. * @param handlerProvider The {@link com.google.inject.Provider} of the handler. */ protected void register(Class<?> actionType, final Provider<? extends ClientActionHandler<?, ?>> handlerProvider) { register(actionType, new IndirectProvider<ClientActionHandler<?, ?>>() { @Override public void get(AsyncCallback<ClientActionHandler<?, ?>> callback) { callback.onSuccess(handlerProvider.get()); } }); }
@SuppressWarnings("unchecked") @Override public <A extends Action<R>, R extends Result> DispatchRequest execute( A action, AsyncCallback<R> callback) { assert callback != null; ClientActionHandler<?, ?> clientActionHandler = clientActionHandlers.get(action.getClass()); if (clientActionHandler != null) { DelegatingDispatchRequest request = new DelegatingDispatchRequest(); ((ClientActionHandler<A, R>) clientActionHandler).execute(action, callback, new ExecuteCommand<A, R>() { @Override public DispatchRequest execute(A action, AsyncCallback<R> resultCallback) { return serviceExecute(action, resultCallback); } }); return request; } else { serviceExecute(action, callback); return new TestingDispatchRequest(); } }
clientActionHandlerRegistry.find(action.getClass());
/** * Register a {@link Provider} of a client-side action handler. * * @param actionType The type of {@link Action} that the * client-side action handler supports. * @param handlerProvider The {@link Provider} of the handler. */ protected void register(Class<? extends Action<?>> actionType, final Provider<? extends ClientActionHandler<?, ?>> handlerProvider) { register(actionType, new IndirectProvider<ClientActionHandler<?, ?>>() { @Override public void get(AsyncCallback<ClientActionHandler<?, ?>> callback) { callback.onSuccess(handlerProvider.get()); } }); }
/** * Register an {@link AsyncProvider} of a client-side action handler. * * @param actionType The type of {@link Action} that the * client-side action handler supports. * @param handlerProvider The {@link AsyncProvider} of the handler. */ protected void register(Class<? extends Action<?>> actionType, final AsyncProvider<? extends ClientActionHandler<?, ?>> handlerProvider) { register(actionType, new IndirectProvider<ClientActionHandler<?, ?>>() { @SuppressWarnings("unchecked") @Override public void get(AsyncCallback<ClientActionHandler<?, ?>> callback) { ((AsyncProvider<ClientActionHandler<?, ?>>) handlerProvider).get(callback); } }); }
/** * Register a client-side action handler that is part of a {@link com.gwtplatform.common.client.ProviderBundle}. * * @param actionType The type of that the client-side action handler supports. * @param bundleProvider The {@link javax.inject.Provider} of the * {@link com.gwtplatform.common.client.ProviderBundle}. * @param providerId The id of the client-side action handler provider. */ protected <B extends ProviderBundle> void register(Class<?> actionType, AsyncProvider<B> bundleProvider, int providerId) { register(actionType, new CodeSplitBundleProvider<ClientActionHandler<?, ?>, B>(bundleProvider, providerId)); }
/** * Register a client-side action handler that is part of a {@link com.gwtplatform.common.client.ProviderBundle}. * * @param actionType The type of {@link Action} that the * client-side action handler supports. * @param bundleProvider The {@link Provider} of the {@link ProviderBundle}. * @param providerId The id of the client-side action handler provider. */ protected <B extends ProviderBundle> void register( Class<? extends Action<?>> actionType, AsyncProvider<B> bundleProvider, int providerId) { register(actionType, new CodeSplitBundleProvider<ClientActionHandler<?, ?>, B>( bundleProvider, providerId)); }