1 29 30 package com.caucho.el; 31 32 import com.caucho.vfs.WriteStream; 33 34 import javax.el.ELContext; 35 import javax.el.ELException; 36 import javax.el.MethodInfo; 37 import java.io.IOException ; 38 39 44 public class PathExpr extends Expr { 45 private Expr _expr; 46 47 private String _path; 48 49 55 public PathExpr(Expr expr, String path) 56 { 57 _expr = expr; 58 _path = path; 59 } 60 61 66 @Override 67 public Expr createField(String field) 68 { 69 Expr arrayExpr = _expr.createField(new StringLiteral(field)); 70 71 return new PathExpr(arrayExpr, _path + '.' + field); 72 } 73 74 80 @Override 81 public Expr createMethod(Expr []args) 82 { 83 if (_expr instanceof ArrayExpr) { 84 86 ArrayExpr array = (ArrayExpr) _expr; 87 88 Expr index = array.getIndex(); 89 90 if (index instanceof StringLiteral) { 91 StringLiteral string = (StringLiteral) index; 92 93 return new MethodExpr(array.getExpr(), string.getValue(), args); 94 } 95 } 96 else if (_expr instanceof ArrayResolverExpr) { 97 ArrayResolverExpr array = (ArrayResolverExpr) _expr; 98 99 Expr index = array.getIndex(); 100 101 if (index instanceof StringLiteral) { 102 StringLiteral string = (StringLiteral) index; 103 104 return new MethodExpr(array.getExpr(), string.getValue(), args); 105 } 106 } 107 108 return new FunctionExpr(this, args); 109 } 110 111 118 @Override 119 public Object getValue(ELContext env) 120 throws ELException 121 { 122 Object value = _expr.getValue(env); 123 124 if (value != null) 125 return value; 126 127 return env.getELResolver().getValue(env, _path, null); 128 } 129 130 137 @Override 138 public MethodInfo getMethodInfo(ELContext env, 139 Class <?> retType, 140 Class <?> []argTypes) 141 throws ELException 142 { 143 return _expr.getMethodInfo(env, retType, argTypes); 144 } 145 146 153 @Override 154 public Object invoke(ELContext env, Class <?> []argTypes, Object []args) 155 throws ELException 156 { 157 return _expr.invoke(env, argTypes, args); 158 } 159 160 165 @Override 166 public void printCreate(WriteStream os) 167 throws IOException 168 { 169 os.print("new com.caucho.el.PathExpr("); 170 _expr.printCreate(os); 171 os.print(", \""); 172 os.print(_path); 173 os.print("\")"); 174 } 175 176 179 public boolean equals(Object o) 180 { 181 if (! (o instanceof PathExpr)) 182 return false; 183 184 PathExpr expr = (PathExpr) o; 185 186 return (_expr.equals(expr._expr) && _path.equals(expr._path)); 187 } 188 189 192 public String toString() 193 { 194 return String.valueOf(_expr); 195 } 196 } 197 | Popular Tags |