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.trace;
020
021import lucee.runtime.PageContext;
022import lucee.runtime.debug.Debugger;
023import lucee.runtime.dump.DumpData;
024import lucee.runtime.dump.DumpProperties;
025import lucee.runtime.dump.DumpUtil;
026import lucee.runtime.exp.PageException;
027import lucee.runtime.op.Caster;
028import lucee.runtime.op.Operator;
029import lucee.runtime.type.Collection.Key;
030import lucee.runtime.type.Objects;
031import lucee.runtime.type.Struct;
032import lucee.runtime.type.dt.DateTime;
033import lucee.runtime.util.VariableUtilImpl;
034
035public class TOObjects extends TraceObjectSupport implements Objects {
036        
037        private static final long serialVersionUID = -2011026266467450312L;
038
039        protected TOObjects(Debugger debugger,Object obj,int type,String category,String text) {
040                super(debugger,obj,type,category,text);
041        }
042
043        @Override
044        public DumpData toDumpData(PageContext pageContext, int maxlevel, DumpProperties properties) {
045                log();
046                return DumpUtil.toDumpData(o, pageContext, maxlevel, properties);
047        }
048
049        @Override
050        public String castToString() throws PageException {
051                log();
052                return Caster.toString(o);
053        }
054        
055        @Override
056        public String castToString(String defaultValue) {
057                log();
058                return Caster.toString(o,defaultValue);
059        }
060        
061        @Override
062        public boolean castToBooleanValue() throws PageException {
063                log();
064                return Caster.toBooleanValue(o);
065        }
066        
067        @Override
068        public Boolean castToBoolean(Boolean defaultValue) {
069                log();
070                return Caster.toBoolean(o,defaultValue);
071        }
072        
073        @Override
074        public double castToDoubleValue() throws PageException {
075                log();
076                return Caster.toDoubleValue(o);
077        }
078        
079        @Override
080        public double castToDoubleValue(double defaultValue) {
081                log();
082                return Caster.toDoubleValue(o,true,defaultValue);
083        }
084        
085        @Override
086        public DateTime castToDateTime() throws PageException {
087                log();
088                return new TODateTime(debugger,Caster.toDate(o, false,null),type,category,text);
089        }
090        
091        @Override
092        public DateTime castToDateTime(DateTime defaultValue) {
093                log();
094                return new TODateTime(debugger,Caster.toDate(o, false,null,defaultValue),type,category,text);
095        }
096        
097        @Override
098        public int compareTo(boolean b) throws PageException {
099                log();
100                return Operator.compare(o, b);
101        }
102        
103        @Override
104        public int compareTo(DateTime dt) throws PageException {
105                log();
106                return Operator.compare(o, (Object)dt);
107        }
108
109        @Override
110        public int compareTo(double d) throws PageException {
111                log();
112                return Operator.compare(o, d);
113        }
114        
115        @Override
116        public int compareTo(String str) throws PageException {
117                log();
118                return Operator.compare(o, str);
119        }
120
121        @Override
122        public Object get(PageContext pc, Key key) throws PageException {
123                log(key.getString());
124                VariableUtilImpl var = (VariableUtilImpl) pc.getVariableUtil();
125                return var.get(pc, o, key);
126                //return TraceObjectSupport.toTraceObject(debugger,var.get(pc, o, key),type,category,text);
127        }
128        
129        @Override
130        public Object get(PageContext pc, Key key, Object defaultValue) {
131                log(key.getString());
132                VariableUtilImpl var = (VariableUtilImpl) pc.getVariableUtil();
133                return var.get(pc, o, key, defaultValue);
134                //return TraceObjectSupport.toTraceObject(debugger,var.get(pc, o, key, defaultValue),type,category,text);
135        }
136        
137        @Override
138        public Object set(PageContext pc, Key key, Object value) throws PageException {
139                log(key,value);
140                VariableUtilImpl var = (VariableUtilImpl) pc.getVariableUtil();
141                return var.set(pc, o, key, value);
142                //return TraceObjectSupport.toTraceObject(debugger,var.set(pc, o, key, value),type,category,text);
143        }
144        
145        @Override
146        public Object setEL(PageContext pc, Key key, Object value) {
147                log(key,value);
148                VariableUtilImpl var = (VariableUtilImpl) pc.getVariableUtil();
149                return var.setEL(pc, o, key, value);
150                //return TraceObjectSupport.toTraceObject(debugger,var.setEL(pc, o, key, value),type,category,text);
151        }
152
153        @Override
154        public Object call(PageContext pc, Key key, Object[] args) throws PageException {
155                log(key.getString());
156                VariableUtilImpl var = (VariableUtilImpl) pc.getVariableUtil();
157                return var.callFunctionWithoutNamedValues(pc, o, key, args);
158        }
159        
160        @Override
161        public Object callWithNamedValues(PageContext pc, Key key, Struct args) throws PageException {
162                log(key.getString());
163                VariableUtilImpl var = (VariableUtilImpl) pc.getVariableUtil();
164                return var.callFunctionWithNamedValues(pc, o, key, args);
165        }
166        
167        public boolean isInitalized() {
168                log();
169                return true;
170        }
171}