001 package railo.runtime.interpreter.ref.cast; 002 003 import railo.runtime.PageContext; 004 import railo.runtime.exp.PageException; 005 import railo.runtime.interpreter.ref.Ref; 006 import railo.runtime.interpreter.ref.RefSupport; 007 import railo.runtime.interpreter.ref.var.Variable; 008 import railo.runtime.op.Caster; 009 010 /** 011 * cast 012 */ 013 public final class Casting extends RefSupport implements Ref { 014 015 private short type; 016 private Ref ref; 017 private Object val; 018 private String strType; 019 020 /** 021 * constructor of the class 022 * @param pc 023 * @param strType 024 * @param type 025 * @param ref 026 */ 027 public Casting(String strType,short type, Ref ref) { 028 this.type=type; 029 this.strType=strType; 030 this.ref=ref; 031 } 032 public Casting(String strType,short type, Object val) { 033 this.type=type; 034 this.strType=strType; 035 this.val=val; 036 } 037 038 @Override 039 public Object getValue(PageContext pc) throws PageException { 040 if(val!=null) return Caster.castTo(pc,type,strType,val); 041 // patch for valueList ..., the complete interpreter code should be removed soon anyway 042 if(ref instanceof Variable && "queryColumn".equalsIgnoreCase(strType)) { 043 Variable var=(Variable) ref; 044 return Caster.castTo(pc,type,strType,var.getCollection(pc)); 045 } 046 return Caster.castTo(pc,type,strType,ref.getValue(pc)); 047 } 048 049 public Ref getRef() { 050 return ref; 051 } 052 053 public String getStringType() { 054 return strType; 055 } 056 057 public short getType() { 058 return type; 059 } 060 061 public String getTypeName() { 062 return "operation"; 063 } 064 }