1 package org.apache.ojb.jdo.jdoql; 2 3 17 18 import java.util.*; 19 20 29 public class MethodInvocation extends PostfixExpression 30 { 31 32 private String _name; 33 34 private List _args; 35 36 private Class _returnType; 37 38 45 public MethodInvocation(Expression base, String methodName, List args) 46 { 47 super(base); 48 _name = methodName; 49 _args = args; 50 for (Iterator it = args.iterator(); it.hasNext();) 51 { 52 ((Expression)it.next()).setParent(this); 53 } 54 } 55 56 59 public boolean hasBaseExpression() 60 { 61 return _base != null; 62 } 63 64 67 public Expression getBaseExpression() 68 { 69 return _base; 70 } 71 72 75 public void setBaseExpression(Expression base) 76 { 77 _base = base; 78 } 79 80 83 public void replaceChild(Expression oldChild, Expression newChild) 84 { 85 if (oldChild == _base) 86 { 87 _base.setParent(null); 88 _base = newChild; 89 _base.setParent(this); 90 } 91 else 92 { 93 Expression expr; 94 95 for (int idx = 0; idx < _args.size(); idx++) 96 { 97 expr = (Expression)_args.get(idx); 98 if (expr == oldChild) 99 { 100 expr.setParent(null); 101 newChild.setParent(this); 102 _args.set(idx, newChild); 103 break; 104 } 105 } 106 } 107 } 108 109 114 public String getName() 115 { 116 return _name; 117 } 118 119 124 public List getArguments() 125 { 126 return _args; 127 } 128 129 132 public void accept(Visitor visitor) 133 { 134 visitor.visit(this); 135 } 136 137 140 public String toString() 141 { 142 StringBuffer result = new StringBuffer (); 143 144 if (_base != null) 145 { 146 result.append(_base.toString()); 147 result.append("."); 148 } 149 result.append(_name); 150 result.append("("); 151 for (Iterator it = _args.iterator(); it.hasNext();) 152 { 153 result.append(it.next().toString()); 154 if (it.hasNext()) 155 { 156 result.append(", "); 157 } 158 } 159 result.append(")"); 160 return result.toString(); 161 } 162 163 168 public void setType(Class type) 169 { 170 _returnType = type; 171 } 172 173 176 public Class getType() 177 { 178 return _returnType; 179 } 180 } 181 | Popular Tags |