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;
020
021import java.util.Iterator;
022import java.util.Set;
023
024import lucee.commons.lang.types.RefBoolean;
025import lucee.runtime.component.Member;
026import lucee.runtime.component.Property;
027import lucee.runtime.dump.DumpData;
028import lucee.runtime.dump.DumpProperties;
029import lucee.runtime.exp.ExpressionException;
030import lucee.runtime.exp.PageException;
031import lucee.runtime.type.Collection;
032import lucee.runtime.type.KeyImpl;
033import lucee.runtime.type.Objects;
034import lucee.runtime.type.Struct;
035import lucee.runtime.type.UDF;
036import lucee.runtime.type.UDFProperties;
037import lucee.runtime.type.dt.DateTime;
038import lucee.runtime.type.util.ComponentProUtil;
039import lucee.runtime.type.util.StructSupport;
040
041public final class ComponentSpecificAccess extends StructSupport implements ComponentPro, Objects {
042   
043    private int access;
044    private ComponentPro component;
045
046    /**
047     * constructor of the class
048     * @param access
049     * @param component
050     * @throws ExpressionException 
051     */
052    public ComponentSpecificAccess(int access, Component component) {
053        this.access=access;
054        this.component=ComponentProUtil.toComponentPro(component);
055    }
056    
057    public static ComponentSpecificAccess  toComponentSpecificAccess(int access, Component component) {
058        if(component instanceof ComponentSpecificAccess) {
059                ComponentSpecificAccess csa=(ComponentSpecificAccess) component;
060                if(access==csa.getAccess()) return csa;
061                component=csa.getComponent();
062        }
063        
064        return new ComponentSpecificAccess(access, component);
065    }
066
067    @Override
068    public PageSource getPageSource(){
069        return component.getPageSource();
070    }
071    
072    @Override
073    public Set keySet() {
074        return component.keySet(access);
075    }
076
077    @Override
078    public String getDisplayName() {
079        return component.getDisplayName();
080    }
081
082    @Override
083    public String getExtends() {
084        return component.getExtends();
085    }
086
087    @Override
088    public String getHint() {
089        return component.getHint();
090    }
091
092    @Override
093    public String getName() {
094        return component.getName();
095    }
096
097    @Override
098    public String getCallName() {
099        return component.getCallName();
100    }
101
102    @Override
103    public String getAbsName() {
104        return component.getAbsName();
105    }
106    
107    @Override
108    public String getBaseAbsName() {
109        return component.getBaseAbsName();
110    }
111    
112    public boolean isBasePeristent() {
113                return component.isPersistent();
114        }
115
116    @Override
117    public boolean getOutput() {
118        return component.getOutput();
119    }
120
121    @Override
122    public boolean instanceOf(String type) {
123        return component.instanceOf(type);
124    }
125
126    @Override
127    public boolean isValidAccess(int access) {
128        return component.isValidAccess(access);
129    }
130
131    @Override
132    public Struct getMetaData(PageContext pc) throws PageException {
133        return component.getMetaData(pc);
134    }
135
136    @Override
137    public Object call(PageContext pc, String key, Object[] args) throws PageException {
138        return call(pc, KeyImpl.init(key), args);
139    }
140
141        @Override
142        public Object call(PageContext pc, Collection.Key key, Object[] args) throws PageException {
143                return component.call(pc,access,key,args);
144        }
145
146    @Override
147    public Object callWithNamedValues(PageContext pc, String key, Struct args)throws PageException {
148        return callWithNamedValues(pc,KeyImpl.init(key),args);
149    }
150
151        @Override
152        public Object callWithNamedValues(PageContext pc, Collection.Key key, Struct args) throws PageException {
153                return component.callWithNamedValues(pc,access,key,args);
154        }
155
156    @Override
157    public int size() {
158        return component.size(access);
159    }
160
161    @Override
162    public Collection.Key[] keys() {
163        return component.keys(access);
164    }
165
166        @Override
167        public Object remove(Collection.Key key) throws PageException {
168                return component.remove(key);
169        }
170
171
172        @Override
173        public Object removeEL(Collection.Key key) {
174                return component.removeEL(key);
175        }
176
177    @Override
178    public void clear() {
179        component.clear();
180    }
181
182        @Override
183        public Object get(Collection.Key key) throws PageException {
184                return component.get(access,key);
185        }
186
187        @Override
188        public Object get(Collection.Key key, Object defaultValue) {
189                 return component.get(access,key, defaultValue);
190        }
191
192        @Override
193        public Object set(Collection.Key key, Object value) throws PageException {
194                return component.set(key,value);
195        }
196
197        @Override
198        public Object setEL(Collection.Key key, Object value) {
199                return component.setEL(key,value);
200        }
201
202    @Override
203    public Iterator<Collection.Key> keyIterator() {
204        return component.keyIterator(access);
205    }
206    
207        @Override
208        public Iterator<String> keysAsStringIterator() {
209        return component.keysAsStringIterator(access);
210    }
211        
212        @Override
213        public Iterator<Entry<Key, Object>> entryIterator() {
214                return component.entryIterator(access);
215        }
216        
217        @Override
218        public Iterator<Object> valueIterator() {
219                return component.valueIterator(access);
220        }
221    
222        @Override
223        public boolean containsKey(Collection.Key key) {
224                return component.get(access,key,null)!=null;
225        }
226
227    @Override
228        public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp) {
229            return component.toDumpData(pageContext,maxlevel,dp,access);
230    }
231
232    @Override
233    public String castToString() throws PageException {
234        return component.castToString();
235    }
236    
237        @Override
238        public String castToString(String defaultValue) {
239                return component.castToString(defaultValue);
240        }
241
242    @Override
243    public boolean castToBooleanValue() throws PageException {
244        return component.castToBooleanValue();
245    }
246    
247    @Override
248    public Boolean castToBoolean(Boolean defaultValue) {
249        return component.castToBoolean(defaultValue);
250    }
251
252    @Override
253    public double castToDoubleValue() throws PageException {
254        return component.castToDoubleValue();
255    }
256    
257    @Override
258    public double castToDoubleValue(double defaultValue) {
259        return component.castToDoubleValue(defaultValue);
260    }
261
262    @Override
263    public DateTime castToDateTime() throws PageException {
264        return component.castToDateTime();
265    }
266    
267    @Override
268    public DateTime castToDateTime(DateTime defaultValue) {
269        return component.castToDateTime(defaultValue);
270    }
271
272
273        @Override
274        public int compareTo(boolean b) throws PageException {
275                return component.compareTo(b);
276        }
277
278        @Override
279        public int compareTo(DateTime dt) throws PageException {
280                return component.compareTo(dt);
281        }
282
283        @Override
284        public int compareTo(String str) throws PageException {
285                return component.compareTo(str);
286        }
287
288        @Override
289        public int compareTo(double d) throws PageException {
290                return component.compareTo(d);
291        }
292
293    /*public Object get(PageContext pc, String key, Object defaultValue) {
294        return get(pc,KeyImpl.init(key),defaultValue);
295    }*/
296
297        @Override
298        public Object get(PageContext pc, Collection.Key key, Object defaultValue) {
299                return component.get(access,key,defaultValue);
300        }
301
302    /*public Object get(PageContext pc, String key) throws PageException {
303        return get(pc,KeyImpl.init(key));
304    }*/
305
306        @Override
307        public Object get(PageContext pc, Collection.Key key) throws PageException {
308                return component.get(access,key);
309        }
310    
311    @Override
312    public Collection duplicate(boolean deepCopy) {
313        return new ComponentSpecificAccess(access,(ComponentPro)component.duplicate(deepCopy));
314    }
315
316    /*public Object set(PageContext pc, String propertyName, Object value) throws PageException {
317        return component.set(propertyName,value);
318    }*/
319
320        @Override
321        public Object set(PageContext pc, Collection.Key propertyName, Object value) throws PageException {
322                return component.set(propertyName,value);
323        }
324
325    /*public Object setEL(PageContext pc, String propertyName, Object value) {
326        return component.setEL(propertyName,value);
327    }*/
328
329        @Override
330        public Object setEL(PageContext pc, Key propertyName, Object value) {
331                return component.setEL(propertyName,value);
332        }
333
334    public int getAccess() {
335        return access;
336    }
337
338        @Override
339        public Class getJavaAccessClass(RefBoolean isNew) throws PageException {
340                return component.getJavaAccessClass(isNew);
341        }
342
343        public String getWSDLFile() {
344                return component.getWSDLFile();
345        }
346
347        @Override
348        public Property[] getProperties(boolean onlyPeristent) {
349                return component.getProperties(onlyPeristent);
350        }
351
352        @Override
353        public Property[] getProperties(boolean onlyPeristent, boolean includeBaseProperties, boolean overrideProperties, boolean inheritedMappedSuperClassOnly) {
354                return ComponentProUtil.getProperties(component, onlyPeristent, includeBaseProperties, overrideProperties, inheritedMappedSuperClassOnly);
355        }
356
357        @Override
358        public ComponentScope getComponentScope(){
359                return component.getComponentScope();
360        }
361
362        public Component getComponent() {
363                return component;
364        }
365
366        @Override
367        public boolean contains(PageContext pc, Key key) {
368                return component.contains(access,key);
369        }
370
371        public Member getMember(int access, Key key, boolean dataMember,boolean superAccess) {
372                return component.getMember(access, key, dataMember, superAccess);
373        }
374
375        @Override
376        public void setProperty(Property property) throws PageException {
377                component.setProperty(property);
378        }
379
380        public boolean equalTo(String type) {
381                return component.equalTo(type);
382        }
383        
384        @Override
385    public void registerUDF(String key, UDF udf){
386        component.registerUDF(key, udf);
387    }
388    
389        @Override
390    public void registerUDF(Collection.Key key, UDF udf){
391                component.registerUDF(key, udf);
392    }
393    
394        @Override
395    public void registerUDF(String key, UDFProperties props){
396                component.registerUDF(key, props);
397    }
398    
399        @Override
400    public void registerUDF(Collection.Key key, UDFProperties props){
401                component.registerUDF(key, props);
402    }
403
404        @Override
405        public boolean isPersistent() {
406                return component.isPersistent();
407        }
408
409        @Override
410        public boolean isAccessors() {
411                return component.isAccessors();
412        }
413
414        @Override
415        public void setEntity(boolean entity) {
416                component.setEntity(entity);
417        }
418
419        @Override
420        public boolean isEntity() {
421                return component.isEntity();
422        }
423
424        @Override
425        public Component getBaseComponent() {
426                return component.getBaseComponent();
427        }
428
429        @Override
430        public Set<Key> keySet(int access) {
431                return component.keySet(access);
432        }
433
434        @Override
435        public Object getMetaStructItem(Key name) {
436                return component.getMetaStructItem(name);
437        }
438
439
440        @Override
441        public Object call(PageContext pc, int access, Key name, Object[] args) throws PageException {
442                return component.call(pc, access, name, args);
443        }
444
445
446        @Override
447        public Object callWithNamedValues(PageContext pc, int access, Key name, Struct args) throws PageException {
448                return component.callWithNamedValues(pc, access, name, args);
449        }
450
451        @Override
452        public int size(int access) {
453                return component.size();
454        }
455
456        @Override
457        public Key[] keys(int access) {
458                return component.keys(access);
459        }
460
461
462        @Override
463        public Iterator<Key> keyIterator(int access) {
464                return component.keyIterator(access);
465        }
466
467        @Override
468        public Iterator<String> keysAsStringIterator(int access) {
469                return component.keysAsStringIterator(access);
470        }
471
472        @Override
473        public Iterator<Entry<Key, Object>> entryIterator(int access) {
474                return component.entryIterator(access);
475        }
476
477        @Override
478        public Iterator<Object> valueIterator(int access) {
479                return component.valueIterator(access);
480        }
481
482        @Override
483        public Object get(int access, Key key) throws PageException {
484                return component.get(access, key);
485        }
486
487        @Override
488        public Object get(int access, Key key, Object defaultValue) {
489                return component.get(access, key, defaultValue);
490        }
491
492        @Override
493        public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties dp, int access) {
494                return toDumpData(pageContext, maxlevel, dp, access);
495        }
496
497        @Override
498        public boolean contains(int access, Key name) {
499                return component.contains(access, name);
500        }
501}