001 package railo.runtime.type.ref; 002 003 import railo.runtime.PageContext; 004 import railo.runtime.exp.PageException; 005 import railo.runtime.type.Collection; 006 import railo.runtime.type.KeyImpl; 007 import railo.runtime.type.StructImpl; 008 009 /** 010 * Handle a Reference 011 */ 012 public final class ReferenceReference implements Reference { 013 014 private Reference reference; 015 private String key; 016 017 /** 018 * @param reference 019 * @param key 020 */ 021 public ReferenceReference(Reference reference, String key) { 022 this.reference=reference; 023 this.key=key; 024 } 025 026 /** 027 * 028 * @see railo.runtime.type.ref.Reference#getKey() 029 */ 030 public Collection.Key getKey() { 031 return KeyImpl.init(key); 032 } 033 034 /** 035 * 036 * @see railo.runtime.type.ref.Reference#getKeyAsString() 037 */ 038 public String getKeyAsString() { 039 return key; 040 } 041 042 /** 043 * @see railo.runtime.type.ref.Reference#get(railo.runtime.PageContext) 044 */ 045 public Object get(PageContext pc) throws PageException { 046 return pc.getCollection(reference.get(pc),key); 047 } 048 049 /** 050 * 051 * @see railo.runtime.type.ref.Reference#get(railo.runtime.PageContext, java.lang.Object) 052 */ 053 public Object get(PageContext pc, Object defaultValue) { 054 return pc.getCollection(reference.get(pc,null),key,defaultValue); 055 } 056 057 /** 058 * @see railo.runtime.type.ref.Reference#set(railo.runtime.PageContext, java.lang.Object) 059 */ 060 public Object set(PageContext pc, Object value) throws PageException { 061 return pc.set(reference.touch(pc),key,value); 062 } 063 064 /** 065 * @see railo.runtime.type.ref.Reference#setEL(railo.runtime.PageContext, java.lang.Object) 066 */ 067 public Object setEL(PageContext pc, Object value) { 068 try { 069 return set(pc,value); 070 } catch (PageException e) { 071 return null; 072 } 073 } 074 075 /** 076 * @see railo.runtime.type.ref.Reference#touch(railo.runtime.PageContext) 077 */ 078 public Object touch(PageContext pc) throws PageException { 079 Object parent=reference.touch(pc); 080 Object o= pc.getCollection(parent,key,null); 081 if(o!=null) return o; 082 return pc.set(parent,key,new StructImpl()); 083 } 084 085 public Object touchEL(PageContext pc) { 086 Object parent=reference.touchEL(pc); 087 Object o= pc.getCollection(parent,key,null); 088 if(o!=null) return o; 089 try { 090 return pc.set(parent,key,new StructImpl()); 091 } catch (PageException e) { 092 return null; 093 } 094 } 095 096 /** 097 * @see railo.runtime.type.ref.Reference#remove(railo.runtime.PageContext) 098 */ 099 public Object remove(PageContext pc) throws PageException { 100 return pc.getVariableUtil().remove(reference.get(pc),key); 101 } 102 103 /** 104 * @see railo.runtime.type.ref.Reference#removeEL(railo.runtime.PageContext) 105 */ 106 public Object removeEL(PageContext pc) { 107 return pc.getVariableUtil().removeEL(reference.get(pc,null),key); 108 } 109 110 /** 111 * @see railo.runtime.type.ref.Reference#getParent() 112 */ 113 public Object getParent() { 114 return reference; 115 } 116 /** 117 * @see java.lang.Object#toString() 118 */ 119 public String toString() { 120 return "java.util.ReferenceReference(reference:"+reference+";key:"+key+")"; 121 } 122 }