/* * Copyright 2013 lorislab.org. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.lorislab.smonitor.admin.client.service; import org.jboss.errai.common.client.api.ErrorCallback; import org.jboss.errai.common.client.api.RemoteCallback; import org.jboss.errai.common.client.framework.RemoteServiceProxyFactory; import org.jboss.errai.enterprise.client.jaxrs.AbstractJaxrsProxy; /** * * @author Andrej Petras */ public final class ClientFactory { private static final RemoteServiceProxyFactory proxyProvider = new RemoteServiceProxyFactory(); public static <T> Client<T> create(final Class<T> remoteService) { return new Client<T>() { @Override public T call() { T proxy = proxyProvider.getRemoteProxy(remoteService); ((AbstractJaxrsProxy) proxy).setRemoteCallback(new RemoteCallback<Void>() { @Override public void callback(Void response) { } }); return proxy; } @Override public T call(RemoteCallback<?> callback) { T proxy = proxyProvider.getRemoteProxy(remoteService); ((AbstractJaxrsProxy) proxy).setRemoteCallback(callback); return proxy; } @Override public T call(RemoteCallback<?> callback, ErrorCallback<?> errorCallback) { T proxy = proxyProvider.getRemoteProxy(remoteService); ((AbstractJaxrsProxy) proxy).setRemoteCallback(callback); ((AbstractJaxrsProxy) proxy).setErrorCallback(errorCallback); return proxy; } }; } }