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.dump;
020
021import java.util.Date;
022
023import lucee.runtime.exp.ExpressionException;
024import lucee.runtime.exp.PageException;
025import lucee.runtime.op.Castable;
026import lucee.runtime.op.Caster;
027import lucee.runtime.op.Operator;
028import lucee.runtime.op.date.DateCaster;
029import lucee.runtime.type.dt.DateTime;
030
031public class SimpleDumpData implements DumpData,Castable {
032
033        private String data;
034
035        public SimpleDumpData(String data) {
036                this.data=data;
037        }
038        public SimpleDumpData(double data) {
039                this.data=Caster.toString(data);
040        }
041
042        public SimpleDumpData(boolean data) {
043                this.data=Caster.toString(data);
044        }
045        @Override
046        public String toString() {
047                return data;
048        }
049        
050        @Override
051        public boolean castToBooleanValue() throws PageException {
052                return Caster.toBooleanValue(data);
053        }
054    
055    @Override
056    public Boolean castToBoolean(Boolean defaultValue) {
057        return Caster.toBoolean(data,defaultValue);
058    }
059        
060        @Override
061        public DateTime castToDateTime() throws PageException {
062                return Caster.toDatetime(data, null);
063        }
064    
065    @Override
066    public DateTime castToDateTime(DateTime defaultValue) {
067        return DateCaster.toDateAdvanced(data,DateCaster.CONVERTING_TYPE_OFFSET,null,defaultValue);
068    }
069        
070        @Override
071        public double castToDoubleValue() throws PageException {
072                return Caster.toDoubleValue(data);
073        }
074    
075    @Override
076    public double castToDoubleValue(double defaultValue) {
077        return Caster.toDoubleValue(data,defaultValue);
078    }
079        
080        @Override
081        public String castToString() throws PageException {
082                return Caster.toString(data);
083        }
084
085        @Override
086        public String castToString(String defaultValue) {
087                return Caster.toString(data,defaultValue);
088        }
089
090        @Override
091        public int compareTo(boolean b) throws ExpressionException {
092                return Operator.compare(data, b);
093        }
094
095        @Override
096        public int compareTo(DateTime dt) throws PageException {
097                return Operator.compare(data, (Date)dt);
098        }
099
100        @Override
101        public int compareTo(double d) throws PageException {
102                return Operator.compare(data, d);
103        }
104
105        @Override
106        public int compareTo(String str) throws PageException {
107                return Operator.compare(data, str);
108        }
109}