
main.java.com.dragome.web.services.ClientSideServiceFactory Maven / Gradle / Ivy
/*
* Copyright (c) 2011-2014 Fernando Petrola
*
* 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 com.dragome.web.services;
import java.io.Serializable;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.Map;
import com.dragome.services.interfaces.AsyncCallback;
import com.dragome.services.interfaces.AsyncServiceExecutor;
import com.dragome.services.interfaces.RequestExecutor;
import com.dragome.services.interfaces.SerializationService;
import com.dragome.services.interfaces.ServiceFactory;
public class ClientSideServiceFactory implements ServiceFactory
{
public T createSyncService(Class extends T> type)
{
return createProxy(type, new AbstractServicesInvocationHandler(type)
{
public Object execute(Map parameters, RequestExecutor requestExecutor, SerializationService serializationService, boolean returnsValue)
{
String result= requestExecutor.executeSynchronousRequest(AbstractServicesInvocationHandler.SERVICE_INVOKER_PATH, parameters);
return serializationService.deserialize(result);
}
});
}
public T createFixedSyncService(Class extends T> type)
{
return createProxy(type, new AbstractServicesInvocationHandler(type)
{
public Object execute(Map parameters, RequestExecutor requestExecutor, SerializationService serializationService, boolean returnsValue)
{
String result= requestExecutor.executeFixedSynchronousRequest(AbstractServicesInvocationHandler.SERVICE_INVOKER_PATH, parameters);
return serializationService.deserialize(result);
}
});
}
public AsyncServiceExecutor createAsyncService(final Class extends T> type)
{
return new AsyncServiceExecutor()
{
protected AsyncCallback
© 2015 - 2025 Weber Informatics LLC | Privacy Policy