001 package railo.runtime.type; 002 003 import railo.runtime.exp.ExpressionException; 004 import railo.runtime.exp.PageException; 005 import railo.runtime.exp.PageRuntimeException; 006 007 /** 008 * a read only Struct if flag is set to readonly 009 */ 010 public class ReadOnlyStruct extends StructImpl { 011 012 013 private boolean isReadOnly=false; 014 015 /** 016 * sets if scope is readonly or not 017 * @param isReadOnly 018 */ 019 public void setReadOnly(boolean isReadOnly) { 020 this.isReadOnly=isReadOnly; 021 } 022 023 /** 024 * @see railo.runtime.type.StructImpl#remove(java.lang.String) 025 */ 026 public Object remove(String key) throws PageException { 027 if(isReadOnly)throw new ExpressionException("can't remove key ["+key+"] from struct, struct is readonly"); 028 return super.remove (KeyImpl.init(key)); 029 } 030 031 /** 032 * 033 * @see railo.runtime.type.StructImpl#remove(railo.runtime.type.Collection.Key) 034 */ 035 public Object remove(Collection.Key key) throws PageException { 036 if(isReadOnly)throw new ExpressionException("can't remove key ["+key.getString()+"] from struct, struct is readonly"); 037 return super.remove (key); 038 } 039 040 /** 041 * 042 * @see railo.runtime.type.StructImpl#removeEL(java.lang.String) 043 */ 044 public Object removeEL(Collection.Key key) { 045 if(isReadOnly)return null; 046 return super.removeEL (key); 047 } 048 049 /** 050 * @see railo.runtime.type.Collection#clear() 051 */ 052 public void removeAll() { 053 if(!isReadOnly)super.clear(); 054 } 055 056 /** 057 * 058 * @see railo.runtime.type.StructImpl#set(railo.runtime.type.Collection.Key, java.lang.Object) 059 */ 060 public Object set(Collection.Key key, Object value) throws PageException { 061 if(isReadOnly)throw new ExpressionException("can't set key ["+key.getString()+"] to struct, struct is readonly"); 062 return super.set (key,value); 063 } 064 065 /** 066 * @see railo.runtime.type.StructImpl#setEL(railo.runtime.type.Collection.Key, java.lang.Object) 067 */ 068 public Object setEL(Collection.Key key, Object value) { 069 if(!isReadOnly)super.setEL (key,value); 070 return value; 071 } 072 073 074 /** 075 * @see railo.runtime.type.StructImpl#duplicate(boolean) 076 */ 077 public Collection duplicate(boolean deepCopy) { 078 ReadOnlyStruct trg=new ReadOnlyStruct(); 079 trg.isReadOnly=isReadOnly; 080 copy(this, trg, deepCopy); 081 return trg; 082 } 083 084 085 /** 086 * @see railo.runtime.type.Collection#clear() 087 */ 088 public void clear() { 089 if(isReadOnly)throw new PageRuntimeException(new ExpressionException("can't clear struct, struct is readonly")); 090 super.clear(); 091 } 092 }