001 /**
002 * GRANITE DATA SERVICES
003 * Copyright (C) 2006-2013 GRANITE DATA SERVICES S.A.S.
004 *
005 * This file is part of the Granite Data Services Platform.
006 *
007 * Granite Data Services is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * Granite Data Services is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
015 * General Public License for more details.
016 *
017 * You should have received a copy of the GNU Lesser General Public
018 * License along with this library; if not, write to the Free Software
019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
020 * USA, or see <http://www.gnu.org/licenses/>.
021 */
022 package org.granite.messaging.service;
023
024 import java.lang.reflect.InvocationTargetException;
025 import java.lang.reflect.Method;
026 import java.util.Arrays;
027
028 import org.granite.config.flex.Destination;
029 import org.granite.messaging.service.security.AbstractSecurityContext;
030
031 import flex.messaging.messages.Message;
032
033 /**
034 * @author Franck WOLFF
035 */
036 public class ServiceInvocationContext extends AbstractSecurityContext {
037
038 private final Object bean;
039 private final Method method;
040 private Object[] parameters;
041
042 public ServiceInvocationContext(
043 Message message,
044 Destination destination,
045 Object bean,
046 Method method,
047 Object[] parameters) {
048
049 super(message, destination);
050 this.bean = bean;
051 this.method = method;
052 this.parameters = parameters;
053 }
054
055 public Object getBean() {
056 return bean;
057 }
058
059 public Method getMethod() {
060 return method;
061 }
062
063 public Object[] getParameters() {
064 return parameters;
065 }
066 public void setParameters(Object[] parameters) {
067 this.parameters = parameters;
068 }
069
070 @Override
071 public Object invoke() throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {
072 return method.invoke(bean, parameters);
073 }
074
075 @Override
076 public String toString() {
077 return getClass().getName() + '{' +
078 "\n message=" + getMessage() +
079 "\n destination=" + getDestination() +
080 "\n bean=" + bean +
081 "\n method=" + method +
082 "\n parameters=" + Arrays.toString(parameters) +
083 '}';
084 }
085 }