1. /*
  2. * Copyright 2000-2001,2004 The Apache Software Foundation.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  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. package org.apache.commons.jexl.util;
  17. import java.lang.reflect.InvocationTargetException;
  18. import org.apache.commons.logging.Log;
  19. /**
  20. * Executor that simply tries to execute a get(key)
  21. * operation. This will try to find a get(key) method
  22. * for any type of object, not just objects that
  23. * implement the Map interface as was previously
  24. * the case.
  25. *
  26. * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a>
  27. * @version $Id: GetExecutor.java,v 1.4 2004/02/28 13:45:21 yoavs Exp $
  28. */
  29. public class GetExecutor extends AbstractExecutor
  30. {
  31. /**
  32. * Container to hold the 'key' part of
  33. * get(key).
  34. */
  35. private Object[] args = new Object[1];
  36. /**
  37. * Default constructor.
  38. */
  39. public GetExecutor(Log r, org.apache.commons.jexl.util.introspection.Introspector ispect, Class c, String key)
  40. throws Exception
  41. {
  42. rlog = r;
  43. args[0] = key;
  44. method = ispect.getMethod(c, "get", args);
  45. }
  46. /**
  47. * Execute method against context.
  48. */
  49. public Object execute(Object o)
  50. throws IllegalAccessException, InvocationTargetException
  51. {
  52. if (method == null)
  53. return null;
  54. return method.invoke(o, args);
  55. }
  56. }