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