001: /*
002: * Copyright 2006, 2007 Odysseus Software GmbH
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package de.odysseus.el.tree;
017:
018: import javax.el.ELContext;
019: import javax.el.MethodInfo;
020:
021: /**
022: * Expression node interface.
023: * This interface provides all the methods needed for value expressions and method
024: * expressions.
025: *
026: * @see de.odysseus.el.tree.Tree
027: * @author Christoph Beck
028: */
029: public interface ExpressionNode extends Node {
030: /**
031: * @return <code>true</code> if this node represents literal text
032: */
033: public boolean isLiteralText();
034:
035: /**
036: * @return <code>true</code> if the subtree rooted at this node could be used as
037: * an lvalue expression (identifier or property sequence with non-literal proefix).
038: */
039: public boolean isLeftValue();
040:
041: /**
042: * Evaluate node.
043: * @param bindings bindings containing variables and functions
044: * @param context evaluation context
045: * @param expectedType result type
046: * @return evaluated node, coerced to the expected type
047: */
048: public Object getValue(Bindings bindings, ELContext context,
049: Class<?> expectedType);
050:
051: /**
052: * Get the value type accepted in {@link #setValue(Bindings, ELContext, Object)}.
053: * @param bindings bindings containing variables and functions
054: * @param context evaluation context
055: * @return accepted type or <code>null</code> for non-lvalue nodes
056: */
057: public Class<?> getType(Bindings bindings, ELContext context);
058:
059: /**
060: * Determine whether {@link #setValue(Bindings, ELContext, Object)} will throw a
061: * {@link javax.el.PropertyNotWritableException}.
062: * @param bindings bindings containing variables and functions
063: * @param context evaluation context
064: * @return <code>true</code> if this a read-only expression node
065: */
066: public boolean isReadOnly(Bindings bindings, ELContext context);
067:
068: /**
069: * Assign value.
070: * @param bindings bindings containing variables and functions
071: * @param context evaluation context
072: * @param value value to set
073: */
074: public void setValue(Bindings bindings, ELContext context,
075: Object value);
076:
077: /**
078: * Get method information.
079: * If this is a non-lvalue node, answer <code>null</code>.
080: * @param bindings bindings containing variables and functions
081: * @param context evaluation context
082: * @param returnType expected method return type (may be <code>null</code> meaning don't care)
083: * @param paramTypes expected method argument types
084: * @return method information or <code>null</code>
085: */
086: public MethodInfo getMethodInfo(Bindings bindings,
087: ELContext context, Class<?> returnType,
088: Class<?>[] paramTypes);
089:
090: /**
091: * Invoke method.
092: * @param bindings bindings containing variables and functions
093: * @param context evaluation context
094: * @param returnType expected method return type (may be <code>null</code> meaning don't care)
095: * @param paramTypes expected method argument types
096: * @param paramValues parameter values
097: * @return result of the method invocation
098: */
099: public Object invoke(Bindings bindings, ELContext context,
100: Class<?> returnType, Class<?>[] paramTypes,
101: Object[] paramValues);
102:
103: /**
104: * Get the canonical expression string for this node.
105: * Variable and funtion names will be replaced in a way such that two expression
106: * nodes that have the same node structure and bindings will also answer the same
107: * value here.
108: * <p/>
109: * For example, <code>"${foo:bar()+2*foobar}"</code> may lead to
110: * <code>"${<fn>() + 2 * <var>}"</code> if <code>foobar</code> is a bound variable.
111: * Otherwise, the structural id would be <code>"${<fn>() + 2 * foobar}"</code>.
112: * <p/>
113: * If the bindings is <code>null</code>, the full canonical subexpression is returned.
114: */
115: public String getStructuralId(Bindings bindings);
116: }
|