001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * glassfish/bootstrap/legal/CDDLv1.0.txt or
009: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
010: * See the License for the specific language governing
011: * permissions and limitations under the License.
012: *
013: * When distributing Covered Code, include this CDDL
014: * HEADER in each file and include the License file at
015: * glassfish/bootstrap/legal/CDDLv1.0.txt. If applicable,
016: * add the following below this CDDL HEADER, with the
017: * fields enclosed by brackets "[]" replaced with your
018: * own identifying information: Portions Copyright [yyyy]
019: * [name of copyright owner]
020: *
021: * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
022: */
023:
024: package javax.el;
025:
026: /**
027: * An <code>Expression</code> that refers to a method on an object.
028: *
029: * <p>The {@link ExpressionFactory#createMethodExpression} method
030: * can be used to parse an expression string and return a concrete instance
031: * of <code>MethodExpression</code> that encapsulates the parsed expression.
032: * The {@link FunctionMapper} is used at parse time, not evaluation time,
033: * so one is not needed to evaluate an expression using this class.
034: * However, the {@link ELContext} is needed at evaluation time.</p>
035: *
036: * <p>The {@link #getMethodInfo} and {@link #invoke} methods will evaluate the
037: * expression each time they are called. The {@link ELResolver} in the
038: * <code>ELContext</code> is used to resolve the top-level variables and to
039: * determine the behavior of the <code>.</code> and <code>[]</code>
040: * operators. For any of the two methods, the {@link ELResolver#getValue}
041: * method is used to resolve all properties up to but excluding the last
042: * one. This provides the <code>base</code> object on which the method
043: * appears. If the <code>base</code> object is null, a
044: * <code>PropertyNotFoundException</code> must be thrown.
045: * At the last resolution,
046: * the final <code>property</code> is then coerced to a <code>String</code>,
047: * which provides the name of the method to be found. A method matching the
048: * name and expected parameters provided at parse time is found and it is
049: * either queried or invoked (depending on the method called on this
050: * <code>MethodExpression</code>).</p>
051: *
052: * <p>See the notes about comparison, serialization and immutability in
053: * the {@link Expression} javadocs.
054: *
055: * @see ELResolver
056: * @see Expression
057: * @see ExpressionFactory
058: * @since JSP 2.1
059: */
060: public abstract class MethodExpression extends Expression {
061: // Evaluation
062:
063: /**
064: * Evaluates the expression relative to the provided context, and
065: * returns information about the actual referenced method.
066: *
067: * @param context The context of this evaluation
068: * @return an instance of <code>MethodInfo</code> containing information
069: * about the method the expression evaluated to.
070: * @throws NullPointerException if context is <code>null</code>
071: * @throws PropertyNotFoundException if one of the property
072: * resolutions failed because a specified variable or property
073: * does not exist or is not readable.
074: * @throws MethodNotFoundException if no suitable method can be found.
075: * @throws ELException if an exception was thrown while performing
076: * property or variable resolution. The thrown exception
077: * must be included as the cause property of this exception, if
078: * available.
079: */
080: public abstract MethodInfo getMethodInfo(ELContext context);
081:
082: /**
083: * If a String literal is specified as the expression, returns the
084: * String literal coerced to the expected return type of the method
085: * signature. An <code>ELException</code> is thrown if
086: * <code>expectedReturnType</code> is void or if the coercion of the String literal
087: * to the <code>expectedReturnType</code> yields an error (see Section "1.18 Type
088: * Conversion" of the EL specification).
089: *
090: * If not a String literal, evaluates the expression
091: * relative to the provided context, invokes the method that was
092: * found using the supplied parameters, and returns the result of
093: * the method invocation.
094: *
095: * Any parameters passed to this method is ignored if isLiteralText()
096: * is true.
097: *
098: * @param context The context of this evaluation.
099: * @param params The parameters to pass to the method, or
100: * <code>null</code> if no parameters.
101: * @return the result of the method invocation (<code>null</code> if
102: * the method has a <code>void</code> return type).
103: * @throws NullPointerException if context is <code>null</code>
104: * @throws PropertyNotFoundException if one of the property
105: * resolutions failed because a specified variable or property
106: * does not exist or is not readable.
107: * @throws MethodNotFoundException if no suitable method can be found.
108: * @throws ELException if a String literal is specified and
109: * expectedReturnType of the MethodExpression is void or if the coercion of the String literal
110: * to the expectedReturnType yields an error (see Section "1.18 Type
111: * Conversion").
112: * @throws ELException if
113: * an exception was thrown while performing
114: * property or variable resolution. The thrown exception must be
115: * included as the cause property of this exception, if
116: * available. If the exception thrown is an
117: * <code>InvocationTargetException</code>, extract its
118: * <code>cause</code> and pass it to the
119: * <code>ELException</code> constructor.
120: */
121: public abstract Object invoke(ELContext context, Object[] params);
122: }
|