001: //--------------------------------------------------------------------------
002: // Copyright (c) 1998-2004, Drew Davidson and Luke Blanshard
003: // All rights reserved.
004: //
005: // Redistribution and use in source and binary forms, with or without
006: // modification, are permitted provided that the following conditions are
007: // met:
008: //
009: // Redistributions of source code must retain the above copyright notice,
010: // this list of conditions and the following disclaimer.
011: // Redistributions in binary form must reproduce the above copyright
012: // notice, this list of conditions and the following disclaimer in the
013: // documentation and/or other materials provided with the distribution.
014: // Neither the name of the Drew Davidson nor the names of its contributors
015: // may be used to endorse or promote products derived from this software
016: // without specific prior written permission.
017: //
018: // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
019: // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
020: // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
021: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
022: // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
023: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
024: // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
025: // OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
026: // AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
027: // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
028: // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
029: // DAMAGE.
030: //--------------------------------------------------------------------------
031: package ognl;
032:
033: /**
034: * @author Luke Blanshard (blanshlu@netscape.net)
035: * @author Drew Davidson (drew@ognl.org)
036: */
037: class ASTMethod extends SimpleNode {
038: private String methodName;
039:
040: public ASTMethod(int id) {
041: super (id);
042: }
043:
044: public ASTMethod(OgnlParser p, int id) {
045: super (p, id);
046: }
047:
048: /** Called from parser action. */
049: void setMethodName(String methodName) {
050: this .methodName = methodName;
051: }
052:
053: /**
054: Returns the method name that this node will call.
055: */
056: public String getMethodName() {
057: return methodName;
058: }
059:
060: protected Object getValueBody(OgnlContext context, Object source)
061: throws OgnlException {
062: Object[] args = OgnlRuntime.getObjectArrayPool().create(
063: jjtGetNumChildren());
064:
065: try {
066: Object result, root = context.getRoot();
067:
068: for (int i = 0, icount = args.length; i < icount; ++i) {
069: args[i] = children[i].getValue(context, root);
070: }
071: result = OgnlRuntime.callMethod(context, source,
072: methodName, null, args);
073: if (result == null) {
074: NullHandler nh = OgnlRuntime.getNullHandler(OgnlRuntime
075: .getTargetClass(source));
076:
077: result = nh.nullMethodResult(context, source,
078: methodName, args);
079: }
080: return result;
081: } finally {
082: OgnlRuntime.getObjectArrayPool().recycle(args);
083: }
084: }
085:
086: public String toString() {
087: String result = methodName;
088:
089: result = result + "(";
090: if ((children != null) && (children.length > 0)) {
091: for (int i = 0; i < children.length; i++) {
092: if (i > 0) {
093: result = result + ", ";
094: }
095: result = result + children[i];
096: }
097: }
098: result = result + ")";
099: return result;
100: }
101: }
|