KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > el > MethodExpressionImpl


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  *
23  * Free Software Foundation, Inc.
24  * 59 Temple Place, Suite 330
25  * Boston, MA 02111-1307 USA
26  *
27  * @author Scott Ferguson
28  */

29
30 package com.caucho.el;
31
32 import com.caucho.util.L10N;
33
34 import javax.el.ELContext;
35 import javax.el.ELException;
36 import javax.el.MethodExpression;
37 import javax.el.MethodInfo;
38 import javax.el.MethodNotFoundException;
39 import javax.el.PropertyNotFoundException;
40 import java.util.logging.Logger JavaDoc;
41
42 /**
43  * Implementation of the method expression.
44  */

45 public class MethodExpressionImpl extends MethodExpression
46 {
47   protected static final Logger JavaDoc log
48     = Logger.getLogger(MethodExpressionImpl.class.getName());
49   protected static final L10N L = new L10N(MethodExpressionImpl.class);
50
51   private final String JavaDoc _expressionString;
52   private final Expr _expr;
53   private final Class JavaDoc _expectedType;
54   private final Class JavaDoc []_expectedArgs;
55
56   public MethodExpressionImpl(Expr expr,
57                   String JavaDoc expressionString,
58                   Class JavaDoc<?> expectedType,
59                   Class JavaDoc<?> []expectedArgs)
60   {
61     _expr = expr;
62     _expressionString = expressionString;
63     _expectedType = expectedType;
64     _expectedArgs = expectedArgs;
65   }
66
67   public boolean isLiteralText()
68   {
69     return _expr.isLiteralText();
70   }
71
72   public String JavaDoc getExpressionString()
73   {
74     return _expressionString;
75   }
76   
77   public MethodInfo getMethodInfo(ELContext context)
78     throws PropertyNotFoundException,
79        MethodNotFoundException,
80        ELException
81   {
82     return _expr.getMethodInfo(context, _expectedType, _expectedArgs);
83   }
84
85   public Object JavaDoc invoke(ELContext context,
86                Object JavaDoc []params)
87     throws PropertyNotFoundException,
88        MethodNotFoundException,
89        ELException
90   {
91     if (params == null && _expectedArgs.length != 0
92     || params != null && params.length != _expectedArgs.length) {
93       throw new IllegalArgumentException JavaDoc(L.l("expected arguments do not match actual arguments for '{0}'", _expr.toString()));
94     }
95
96     Object JavaDoc value = _expr.invoke(context, _expectedArgs, params);
97       
98     return Expr.coerceToType(value, _expectedType);
99   }
100
101   public int hashCode()
102   {
103     return _expr.hashCode();
104   }
105   
106   public boolean equals(Object JavaDoc o)
107   {
108     if (this == o)
109       return true;
110     else if (! (o instanceof MethodExpressionImpl))
111       return false;
112
113     MethodExpressionImpl expr = (MethodExpressionImpl) o;
114
115     return _expr.equals(expr._expr);
116   }
117
118   public String JavaDoc toString()
119   {
120     return "MethodExpressionImpl[" + getExpressionString() + "]";
121   }
122 }
123
Popular Tags