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.Session;
010    import railo.runtime.type.scope.storage.StorageScopeCache;
011    
012    public final class SessionCache extends StorageScopeCache implements Session {
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            @Override
029            public Collection duplicate(boolean deepCopy) {
030            return new SessionCache(this,deepCopy);
031            }
032            
033            /**
034             * load an new instance of the client datasource scope
035             * @param cacheName 
036             * @param appName
037             * @param pc
038             * @return client datasource scope
039             * @throws PageException
040             */
041            public static Session getInstance(String cacheName, String appName, PageContext pc,Log log) throws PageException {
042                            Struct _sct = _loadData(pc, cacheName, appName,"session", log);
043                            //structOk=true;
044                            if(_sct==null) _sct=new StructImpl();
045                            
046                    return new SessionCache(pc,cacheName,appName,_sct);
047            }
048            
049            public static boolean hasInstance(String cacheName, String appName, PageContext pc) {
050                    try {
051                            return _loadData(pc, cacheName, appName,"session", null)!=null;
052                    } 
053                    catch (PageException e) {
054                            return false;
055                    }
056    }
057            
058    
059            public static Session getInstance(String cacheName, String appName, PageContext pc,Log log, Session defaultValue) {
060                    try {
061                            return getInstance(cacheName, appName, pc,log);
062                    }
063                    catch (PageException e) {}
064                    return defaultValue;
065            }
066    
067    }