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 java.util.HashSet;
022import java.util.Set;
023
024import lucee.runtime.PageContext;
025import lucee.runtime.config.ConfigImpl;
026import lucee.runtime.config.ConfigWebImpl;
027import lucee.runtime.exp.PageException;
028import lucee.runtime.type.Query;
029import lucee.runtime.type.QueryImpl;
030import lucee.runtime.type.Struct;
031import lucee.runtime.type.StructImpl;
032import lucee.runtime.type.util.KeyConstants;
033
034public class DebuggerUtil {
035
036        
037        public Struct pointOutClosuresInPersistentScopes(PageContext pc){
038                Struct sct=new StructImpl();
039                Set<Object> done=new HashSet<Object>();
040                //Application Scope
041                try {
042                        sct.set(
043                                        KeyConstants._application, 
044                                        _pointOutClosuresInPersistentScopes(pc,pc.applicationScope(),done));
045                } 
046                catch (PageException e) {}
047                
048                //Session Scope
049                try {
050                        sct.set(
051                                        KeyConstants._application, 
052                                        _pointOutClosuresInPersistentScopes(pc,pc.sessionScope(),done));
053                } 
054                catch (PageException e) {}
055                
056                //Server Scope
057                try {
058                        sct.set(
059                                        KeyConstants._application, 
060                                        _pointOutClosuresInPersistentScopes(pc,pc.serverScope(),done));
061                } 
062                catch (PageException e) {}
063                
064                
065                
066                return null;
067        }
068
069        private Struct _pointOutClosuresInPersistentScopes(PageContext pc, Struct sct, Set<Object> done) {
070                
071                return null;
072        }
073        
074        public static boolean debugQueryUsage(PageContext pageContext, Query query) {
075                if(pageContext.getConfig().debug() && query instanceof QueryImpl) {
076                        if(((ConfigWebImpl)pageContext.getConfig()).hasDebugOptions(ConfigImpl.DEBUG_QUERY_USAGE)){
077                                ((QueryImpl)query).enableShowQueryUsage();
078                                return true;
079                        }
080                }
081                return false;
082        }
083}