001/** 002 * 003 * Copyright (c) 2014, the Railo Company Ltd. All rights reserved. 004 * 005 * This library is free software; you can redistribute it and/or 006 * modify it under the terms of the GNU Lesser General Public 007 * License as published by the Free Software Foundation; either 008 * version 2.1 of the License, or (at your option) any later version. 009 * 010 * This library is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 013 * Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public 016 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 017 * 018 **/ 019package lucee.runtime.type.scope; 020 021import java.util.Iterator; 022 023import lucee.runtime.PageContext; 024import lucee.runtime.dump.DumpData; 025import lucee.runtime.dump.DumpProperties; 026import lucee.runtime.exp.ExpressionException; 027import lucee.runtime.exp.PageException; 028import lucee.runtime.exp.PageRuntimeException; 029import lucee.runtime.type.Collection; 030import lucee.runtime.type.dt.DateTime; 031import lucee.runtime.type.util.StructSupport; 032 033/** 034 * 035 */ 036public final class LocalNotSupportedScope extends StructSupport implements Scope,Local { 037 038 private static final long serialVersionUID = 6670210379924188569L; 039 040 private static LocalNotSupportedScope instance=new LocalNotSupportedScope(); 041 private boolean bind; 042 043 private LocalNotSupportedScope(){} 044 045 public static LocalNotSupportedScope getInstance() { 046 return instance; 047 } 048 049 @Override 050 public int size() { 051 return 0; 052 } 053 054 @Override 055 public Collection.Key[] keys() { 056 return null; 057 } 058 059 @Override 060 public Object removeEL(Key key) { 061 // TODO Auto-generated method stub 062 return null; 063 } 064 065 @Override 066 public Object remove(Key key) throws PageException { 067 throw new ExpressionException("Unsupported Context for Local Scope","Can't invoke key "+key+", Local Scope can only invoked inside a Function"); 068 } 069 070 @Override 071 public void clear() { 072 } 073 @Override 074 public Object get(Collection.Key key) throws ExpressionException { 075 throw new ExpressionException("Unsupported Context for Local Scope","Can't invoke key "+key.getString()+", Local Scope can only invoked inside a Function"); 076 } 077 078 @Override 079 public Object get(Collection.Key key, Object defaultValue) { 080 return defaultValue; 081 } 082 083 @Override 084 public Object set(Key key, Object value) throws ExpressionException { 085 throw new ExpressionException("Unsupported Context for Local Scope","Can't invoke key "+key.getString()+", Local Scope can only invoked inside a Function"); 086 } 087 088 @Override 089 public Object setEL(Collection.Key key, Object value) { 090 return null; 091 } 092 093 @Override 094 public Iterator<Collection.Key> keyIterator() { 095 throw new PageRuntimeException(new ExpressionException("Unsupported Context for Local Scope","Local Scope can only invoked inside a Function")); 096 } 097 098 @Override 099 public Iterator<Entry<Key, Object>> entryIterator() { 100 throw new PageRuntimeException(new ExpressionException("Unsupported Context for Local Scope","Local Scope can only invoked inside a Function")); 101 } 102 103 104 @Override 105 public Iterator<Object> valueIterator() { 106 throw new PageRuntimeException(new ExpressionException("Unsupported Context for Local Scope","Local Scope can only invoked inside a Function")); 107 } 108 109 @Override 110 public boolean isInitalized() { 111 return false; 112 } 113 @Override 114 public void initialize(PageContext pc) { 115 } 116 117 @Override 118 public void release() { 119 } 120 @Override 121 public void release(PageContext pc) { 122 } 123 124 @Override 125 public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) { 126 throw new PageRuntimeException(new ExpressionException("Unsupported Context for Local Scope")); 127 } 128 129 @Override 130 public Collection duplicate(boolean deepCopy) { 131 return new LocalNotSupportedScope(); 132 } 133 134 135 @Override 136 public boolean containsKey(Collection.Key key) { 137 return false; 138 } 139 140 @Override 141 public boolean containsValue(Object value) { 142 return false; 143 } 144 145 @Override 146 public java.util.Collection values() { 147 return null; 148 } 149 150 @Override 151 public String castToString() throws ExpressionException { 152 throw new ExpressionException("Unsupported Context for Local Scope"); 153 } 154 155 @Override 156 public String castToString(String defaultValue) { 157 return defaultValue; 158 } 159 160 161 @Override 162 public boolean castToBooleanValue() throws ExpressionException { 163 throw new ExpressionException("Unsupported Context for Local Scope"); 164 } 165 166 @Override 167 public Boolean castToBoolean(Boolean defaultValue) { 168 return defaultValue; 169 } 170 171 172 @Override 173 public double castToDoubleValue() throws ExpressionException { 174 throw new ExpressionException("Unsupported Context for Local Scope"); 175 } 176 177 @Override 178 public double castToDoubleValue(double defaultValue) { 179 return defaultValue; 180 } 181 182 183 @Override 184 public DateTime castToDateTime() throws ExpressionException { 185 throw new ExpressionException("Unsupported Context for Local Scope"); 186 } 187 188 @Override 189 public DateTime castToDateTime(DateTime defaultValue) { 190 return defaultValue; 191 } 192 193 public int getType() { 194 return SCOPE_LOCAL; 195 } 196 public String getTypeAsString() { 197 return "local"; 198 } 199 public int compareTo(String str) throws PageException { 200 throw new ExpressionException("Unsupported Context for Local Scope"); 201 } 202 public int compareTo(boolean b) throws PageException { 203 throw new ExpressionException("Unsupported Context for Local Scope"); 204 } 205 public int compareTo(double d) throws PageException { 206 throw new ExpressionException("Unsupported Context for Local Scope"); 207 } 208 public int compareTo(DateTime dt) throws PageException { 209 throw new ExpressionException("Unsupported Context for Local Scope"); 210 } 211 @Override 212 public boolean isBind() { 213 return bind; 214 } 215 216 @Override 217 public void setBind(boolean bind) { 218 this.bind=bind; 219 } 220}