01: /*
02: * Copyright 2000-2001,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.commons.jexl.util;
18:
19: import java.lang.reflect.InvocationTargetException;
20:
21: import org.apache.commons.logging.Log;
22:
23: /**
24: * Executor that simply tries to execute a get(key)
25: * operation. This will try to find a get(key) method
26: * for any type of object, not just objects that
27: * implement the Map interface as was previously
28: * the case.
29: *
30: * @since 1.0
31: * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
32: * @version $Id: GetExecutor.java 398171 2006-04-29 14:57:29Z dion $
33: */
34: public class GetExecutor extends AbstractExecutor {
35: /**
36: * Container to hold the 'key' part of
37: * get(key).
38: */
39: private final Object[] args = new Object[1];
40:
41: /**
42: * Default constructor.
43: *
44: * @param r The instance log.
45: * @param ispect The JEXL introspector.
46: * @param c The class being examined.
47: * @param key The key for the get(key) operation.
48: * @throws Exception Failure while trying to obtain the pertinent method.
49: */
50: public GetExecutor(
51: Log r,
52: org.apache.commons.jexl.util.introspection.Introspector ispect,
53: Class c, String key) throws Exception {
54: rlog = r;
55: args[0] = key;
56: method = ispect.getMethod(c, "get", args);
57: }
58:
59: /**
60: * {@inheritDoc}
61: */
62: public Object execute(Object o) throws IllegalAccessException,
63: InvocationTargetException {
64: if (method == null) {
65: return null;
66: }
67:
68: return method.invoke(o, args);
69: }
70:
71: }
|