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.engine;
020
021import java.util.Iterator;
022import java.util.Map;
023import java.util.Map.Entry;
024
025import lucee.runtime.PageContext;
026import lucee.runtime.type.Struct;
027import lucee.runtime.type.StructImpl;
028
029public class ExecutionLogFactory {
030        
031        private Class clazz;
032        private Map<String, String> arguments;
033        //private ExecutionLog executionLog;
034
035        public ExecutionLogFactory(Class clazz, Map<String, String> arguments){
036                this.clazz=clazz;
037                this.arguments=arguments;
038        } 
039        
040        public ExecutionLog getInstance(PageContext pc){
041                ExecutionLog el;
042                try {
043                        el=(ExecutionLog) clazz.newInstance();
044                } catch (Exception e) {
045                        el= new ConsoleExecutionLog();
046                }
047                el.init(pc, arguments);
048                return el;
049        }
050        
051        public String toString(){
052                return super.toString()+":"+clazz.getName();
053        }
054        
055        public Class getClazz(){
056                return clazz;
057        }
058        
059        public Struct getArgumentsAsStruct(){
060                StructImpl sct=new StructImpl();
061                if(arguments!=null) {
062                        Iterator<Entry<String, String>> it = arguments.entrySet().iterator();
063                        Entry<String, String> e;
064                        while(it.hasNext()){
065                                e = it.next();
066                                sct.setEL(e.getKey(), e.getValue());
067                        }
068                }
069                return sct;
070        }
071}