001 /*
002 GRANITE DATA SERVICES
003 Copyright (C) 2011 GRANITE DATA SERVICES S.A.S.
004
005 This file is part of Granite Data Services.
006
007 Granite Data Services is free software; you can redistribute it and/or modify
008 it under the terms of the GNU Library General Public License as published by
009 the Free Software Foundation; either version 2 of the License, or (at your
010 option) any later version.
011
012 Granite Data Services is distributed in the hope that it will be useful, but
013 WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License
015 for more details.
016
017 You should have received a copy of the GNU Library General Public License
018 along with this library; if not, see <http://www.gnu.org/licenses/>.
019 */
020
021 package org.granite.context;
022
023 import java.util.Map;
024
025 import org.granite.config.GraniteConfig;
026 import org.granite.config.flex.ServicesConfig;
027
028 /**
029 * @author Franck WOLFF
030 */
031 public abstract class GraniteContext {
032
033 private static ThreadLocal<GraniteContext> instance = new ThreadLocal<GraniteContext>() {
034 @Override
035 protected GraniteContext initialValue() {
036 return (null);
037 }
038 };
039
040 private final GraniteConfig graniteConfig;
041 private final ServicesConfig servicesConfig;
042 private final AMFContext amfContext;
043
044 public GraniteContext(GraniteConfig graniteConfig, ServicesConfig servicesConfig) {
045 this.servicesConfig = servicesConfig;
046 this.graniteConfig = graniteConfig;
047 this.amfContext = new AMFContextImpl();
048 }
049
050 public static GraniteContext getCurrentInstance() {
051 return instance.get();
052 }
053
054 protected static void setCurrentInstance(GraniteContext context) {
055 instance.set(context);
056 }
057
058 public static void release() {
059 instance.set(null);
060 }
061
062 public ServicesConfig getServicesConfig() {
063 return servicesConfig;
064 }
065
066 public GraniteConfig getGraniteConfig() {
067 return graniteConfig;
068 }
069
070 public AMFContext getAMFContext() {
071 return amfContext;
072 }
073
074 public abstract Object getSessionLock();
075
076 public abstract Map<String, String> getInitialisationMap();
077 public abstract Map<String, Object> getApplicationMap();
078 public abstract Map<String, Object> getSessionMap();
079 public abstract Map<String, Object> getSessionMap(boolean create);
080 public abstract Map<String, Object> getRequestMap();
081 }