001 package railo.runtime.op; 002 003 import railo.runtime.PageContext; 004 import railo.runtime.interpreter.VariableInterpreter; 005 import railo.runtime.type.Collection; 006 import railo.runtime.type.KeyImpl; 007 import railo.runtime.type.scope.Scope; 008 import railo.runtime.util.VariableUtilImpl; 009 010 public class Elvis { 011 012 /** 013 * called by the Elvis operator from generated bytecode 014 * @param pc 015 * @param scope 016 * @param varNames 017 * @return 018 */ 019 public static boolean operate(PageContext pc , double scope,Collection.Key[] varNames) { 020 return _operate(pc, scope, varNames,0); 021 } 022 023 /** 024 * called by the Elvis operator from generated bytecode 025 * @param pc 026 * @param scope 027 * @param varNames 028 * @return 029 */ 030 public static boolean operate(PageContext pc , double scope,String[] varNames) { 031 return _operate(pc, scope, KeyImpl.toKeyArray(varNames),0); 032 } 033 034 /** 035 * called by the Elvis operator from the interpreter 036 * @param pc 037 * @param scope 038 * @param varNames 039 * @return 040 */ 041 public static boolean operate(PageContext pc , String[] varNames) { 042 int scope = VariableInterpreter.scopeString2Int(varNames[0]); 043 return _operate(pc, scope, KeyImpl.toKeyArray(varNames), scope==Scope.SCOPE_UNDEFINED?0:1); 044 } 045 046 private static boolean _operate(PageContext pc , double scope,Collection.Key[] varNames, int startIndex) { 047 Object defVal=null; 048 try { 049 Object coll =VariableInterpreter.scope(pc, (int)scope, false); 050 //Object coll =pc.scope((int)scope); 051 VariableUtilImpl vu = ((VariableUtilImpl)pc.getVariableUtil()); 052 for(int i=startIndex;i<varNames.length;i++) { 053 coll=vu.getCollection(pc,coll,varNames[i],defVal); 054 if(coll==defVal)return false; 055 } 056 } catch (Throwable t) { 057 return false; 058 } 059 return true; 060 } 061 }