001    package railo.runtime.type.scope.session;
002    
003    import railo.commons.io.log.Log;
004    import railo.runtime.PageContext;
005    import railo.runtime.exp.PageException;
006    import railo.runtime.type.Collection;
007    import railo.runtime.type.Struct;
008    import railo.runtime.type.StructImpl;
009    import railo.runtime.type.scope.SessionPlus;
010    import railo.runtime.type.scope.storage.StorageScopeCache;
011    
012    public final class SessionCache extends StorageScopeCache implements SessionPlus {
013            
014            private static final long serialVersionUID = -875719423763891692L;
015    
016            private SessionCache(PageContext pc,String cacheName, String appName,Struct sct) { 
017                    super(pc,cacheName,appName,"session",SCOPE_SESSION,sct);
018            }
019    
020            /**
021             * Constructor of the class, clone existing
022             * @param other
023             */
024            private SessionCache(StorageScopeCache other,boolean deepCopy) {
025                    super(other,deepCopy);
026            }
027            
028            /**
029             * @see railo.runtime.type.Collection#duplicate(boolean)
030             */
031            public Collection duplicate(boolean deepCopy) {
032            return new SessionCache(this,deepCopy);
033            }
034            
035            /**
036             * load an new instance of the client datasource scope
037             * @param cacheName 
038             * @param appName
039             * @param pc
040             * @return client datasource scope
041             * @throws PageException
042             */
043            public static SessionPlus getInstance(String cacheName, String appName, PageContext pc,Log log) throws PageException {
044                            Struct _sct = _loadData(pc, cacheName, appName,"session", log);
045                            //structOk=true;
046                            if(_sct==null) _sct=new StructImpl();
047                            
048                    return new SessionCache(pc,cacheName,appName,_sct);
049            }
050            
051            public static boolean hasInstance(String cacheName, String appName, PageContext pc) {
052                    try {
053                            return _loadData(pc, cacheName, appName,"session", null)!=null;
054                    } 
055                    catch (PageException e) {
056                            return false;
057                    }
058    }
059            
060    
061            public static SessionPlus getInstance(String cacheName, String appName, PageContext pc,Log log, SessionPlus defaultValue) {
062                    try {
063                            return getInstance(cacheName, appName, pc,log);
064                    }
065                    catch (PageException e) {}
066                    return defaultValue;
067            }
068    
069    }