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.debug;
020
021import lucee.commons.lang.StringUtil;
022
023public final class DebugTraceImpl implements DebugTrace {
024
025        private static final long serialVersionUID = -3619310656845433643L;
026
027        // FUTURE move the following types to interface
028    public static final int TYPE_INFO=0;
029    public static final int TYPE_DEBUG=1;
030    public static final int TYPE_WARN=2;
031    public static final int TYPE_ERROR=3;
032    public static final int TYPE_FATAL=4;
033    public static final int TYPE_TRACE=5;
034
035        
036        
037        private int type;
038        private String category;
039        private String text;
040        private String template;
041        private int line;
042        private String varValue;
043        private long time;
044        private String varName;
045        private String action;
046
047        public DebugTraceImpl(int type, String category, String text, String template, int line, String action,String varName, String varValue, long time) {
048                this.type=type;
049                this.category=category;
050                this.text=text;
051                this.template=template;
052                this.line=line;
053                this.varName=varName;
054                this.varValue=varValue;
055                this.time=(time<0)?0:time;
056                this.action=StringUtil.emptyIfNull(action);
057        }
058
059        /**
060         * @return the category
061         */
062        public String getCategory() {
063                return category;
064        }
065
066        /**
067         * @return the line
068         */
069        public int getLine() {
070                return line;
071        }
072
073        /**
074         * @return the template
075         */
076        public String getTemplate() {
077                return template;
078        }
079
080        /**
081         * @return the text
082         */
083        public String getText() {
084                return text;
085        }
086
087        /**
088         * @return the time
089         */
090        public long getTime() {
091                return time;
092        }
093
094        /**
095         * @return the type
096         */
097        public int getType() {
098                return type;
099        }
100
101        /**
102         * @return the var value
103         */
104        public String getVarValue() {
105                return varValue;
106        }
107        public String getVarName() {
108                return varName;
109        }
110        public String getAction() {
111                return action;
112        }
113        
114        public static int toType(String type, int defaultValue) {
115        if(type==null) return defaultValue;
116        type=type.toLowerCase().trim();
117        if(type.startsWith("info")) return TYPE_INFO;
118        if(type.startsWith("debug")) return TYPE_DEBUG;
119        if(type.startsWith("warn")) return TYPE_WARN;
120        if(type.startsWith("error")) return TYPE_ERROR;
121        if(type.startsWith("fatal")) return TYPE_FATAL;
122        if(type.startsWith("trace")) return TYPE_TRACE;
123        
124        return defaultValue;
125    } 
126        
127        public static String toType(int type, String defaultValue) {
128        switch(type) {
129        case TYPE_INFO:    return "INFO"; 
130        case TYPE_DEBUG:   return "DEBUG"; 
131        case TYPE_WARN:    return "WARN"; 
132        case TYPE_ERROR:   return "ERROR"; 
133        case TYPE_FATAL:   return "FATAL"; 
134        case TYPE_TRACE:   return "TRACE"; 
135        default:                return defaultValue;
136        }
137    }
138        
139}