KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > aspects > gui > Callback


1 /*
2   Copyright (C) 2001-2003 Renaud Pawlak, Laurent Martelli
3   
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU Lesser General Public License as
6   published by the Free Software Foundation; either version 2 of the
7   License, or (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful, but
10   WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public
15   License along with this program; if not, write to the Free Software
16   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17   USA */

18
19 package org.objectweb.jac.aspects.gui;
20
21 import java.util.Arrays JavaDoc;
22 import org.objectweb.jac.core.NameRepository;
23 import org.objectweb.jac.core.rtti.AbstractMethodItem;
24 import org.objectweb.jac.util.Strings;
25
26 /**
27  * This class holds a method and its parameters that can be passed to a
28  * peer object as a callback.
29  */

30 public class Callback {
31     AbstractMethodItem method;
32     Object JavaDoc[] parameters;
33     String JavaDoc objectName;
34     /**
35      * Constructs the callback. */

36     public Callback(String JavaDoc objectName,AbstractMethodItem method, Object JavaDoc[] parameters) {
37         if (Strings.isEmpty(objectName) && !method.isStatic())
38             throw new RuntimeException JavaDoc("Method "+method+" is not static; An object must be provided");
39         this.objectName = objectName;
40         this.method = method;
41         this.parameters = parameters;
42     }
43     /**
44      * The callback method. */

45     public AbstractMethodItem getMethod() {
46         return method;
47     }
48     /**
49      * The parameters that can be passed to the callback method. */

50     public Object JavaDoc[] getParameters() {
51         return parameters;
52     }
53     public String JavaDoc getObjectName() {
54         return objectName;
55     }
56     Object JavaDoc object;
57     public Object JavaDoc getObject() {
58         if (object==null && objectName!=null) {
59             object = NameRepository.get().getObject(objectName);
60         }
61         return object;
62     }
63
64     public void invoke(DisplayContext context, View source) {
65         EventHandler.get().onInvoke(
66             context,
67             new InvokeEvent(source,getObject(),method,parameters));
68     }
69
70     public String JavaDoc toString() {
71         return "Callback@"+Integer.toHexString(System.identityHashCode(this))+
72             " "+objectName+"."+method.getName()+
73             "("+(parameters!=null?Arrays.asList(parameters).toString():"")+")";
74     }
75 }
76
Popular Tags