KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jac > core > rtti > MixinMethodItem


1 /*
2   Copyright (C) 2004 Laurent Martelli <laurent@aopsys.com>
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,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12   GNU 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.core.rtti;
20
21 import java.lang.reflect.Method JavaDoc;
22 import java.lang.reflect.Modifier JavaDoc;
23 import org.objectweb.jac.util.ExtArrays;
24
25 public class MixinMethodItem extends MethodItem {
26     public MixinMethodItem(Method JavaDoc method, ClassItem parent)
27         throws InvalidDelegateException
28     {
29         super(method,parent);
30         if (!Modifier.isStatic(method.getModifiers()))
31             throw new InvalidDelegateException(delegate,"Mixin method is not static");
32         if (!method.getParameterTypes()[0].isAssignableFrom((Class JavaDoc)parent.getDelegate()))
33             throw new InvalidDelegateException(
34                 delegate,"1st parameter of mixin method should be "+parent.getName());
35         paramTypes = (Class JavaDoc[])ExtArrays.subArray(method.getParameterTypes(),1);
36     }
37
38     /**
39      * Invoke as a static method, prepending object at the beginning
40      * of parameters.
41      */

42     public Object JavaDoc invoke(Object JavaDoc object, Object JavaDoc[] parameters) {
43         return invokeStatic(ExtArrays.add(0, object, parameters));
44     }
45
46     Class JavaDoc[] paramTypes;
47     public Class JavaDoc[] getParameterTypes() {
48         return paramTypes;
49     }
50
51     public void setParameter(Object JavaDoc[] params, int i, Object JavaDoc value) {
52         params[i+1] = value;
53     }
54     public Object JavaDoc getParameter(Object JavaDoc[] params, int i) {
55         return params[i+1];
56     }
57 }
58
Popular Tags