001 /* 002 Copyright (C) 2001-2003 Renaud Pawlak, Laurent Martelli 003 004 This program is free software; you can redistribute it and/or modify 005 it under the terms of the GNU Lesser General Public License as 006 published by the Free Software Foundation; either version 2 of the 007 License, or (at your option) any later version. 008 009 This program is distributed in the hope that it will be useful, but 010 WITHOUT ANY WARRANTY; without even the implied warranty of 011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 Lesser General Public License for more details. 013 014 You should have received a copy of the GNU Lesser General Public 015 License along with this program; if not, write to the Free Software 016 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 017 USA */ 018 019 package org.objectweb.jac.aspects.gui; 020 021 import java.util.Arrays; 022 import org.objectweb.jac.core.NameRepository; 023 import org.objectweb.jac.core.rtti.AbstractMethodItem; 024 import org.objectweb.jac.util.Strings; 025 026 /** 027 * This class holds a method and its parameters that can be passed to a 028 * peer object as a callback. 029 */ 030 public class Callback { 031 AbstractMethodItem method; 032 Object[] parameters; 033 String objectName; 034 /** 035 * Constructs the callback. */ 036 public Callback(String objectName,AbstractMethodItem method, Object[] parameters) { 037 if (Strings.isEmpty(objectName) && !method.isStatic()) 038 throw new RuntimeException("Method "+method+" is not static; An object must be provided"); 039 this.objectName = objectName; 040 this.method = method; 041 this.parameters = parameters; 042 } 043 /** 044 * The callback method. */ 045 public AbstractMethodItem getMethod() { 046 return method; 047 } 048 /** 049 * The parameters that can be passed to the callback method. */ 050 public Object[] getParameters() { 051 return parameters; 052 } 053 public String getObjectName() { 054 return objectName; 055 } 056 Object object; 057 public Object getObject() { 058 if (object==null && objectName!=null) { 059 object = NameRepository.get().getObject(objectName); 060 } 061 return object; 062 } 063 064 public void invoke(DisplayContext context, View source) { 065 EventHandler.get().onInvoke( 066 context, 067 new InvokeEvent(source,getObject(),method,parameters)); 068 } 069 070 public String toString() { 071 return "Callback@"+Integer.toHexString(System.identityHashCode(this))+ 072 " "+objectName+"."+method.getName()+ 073 "("+(parameters!=null?Arrays.asList(parameters).toString():"")+")"; 074 } 075 }