001: /*
002: * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005:
006: package com.sun.portal.desktop.context;
007:
008: import com.sun.portal.util.ResourceLoader;
009:
010: import javax.servlet.ServletContext;
011:
012: import java.io.FileInputStream;
013: import java.io.FileNotFoundException;
014: import java.io.IOException;
015: import java.util.ArrayList;
016: import java.util.List;
017: import java.util.Properties;
018: import java.util.StringTokenizer;
019:
020: public class PropertiesConfigContext implements ConfigContext {
021: public static final String PROPERTIESFILE = "desktop.propertiesFile";
022: public static final String DESKTOP_CONFIG_FILE = "desktopconfig.properties";
023:
024: public static final String SERVICEAPPCONTEXTCLASSNAME_KEY = "serviceAppContextClassName";
025: public static final String TEMPLATEBASEDIR_KEY = "templateBaseDir";
026: public static final String PROVIDERCLASSBASEDIR_KEY = "providerClassBaseDir";
027: public static final String JSPCOMPILERWARCLASSPATH_KEY = "jspCompilerWARClassPath";
028: public static final String DEFAULT_DESKTOPTYPE_KEY = "defaultDesktopType";
029:
030: public static final String TEMPLATE_SCAN_INTERVAL = "templateScanInterval";
031: public static final String DP_SCAN_INTERVAL = "dpScanInterval";
032: public static final String CLASSLOADER_REVALIDATE_INTERVAL = "classLoaderRevalidateInterval";
033: public static final String BROWSER_CACHE_INTERVAL = "browserCacheInterval";
034:
035: public static final String GETTER_POOL_MIN_SIZE_KEY = "getterPoolMinSize";
036: public static final String GETTER_POOL_MAX_SIZE_KEY = "getterPoolMaxSize";
037: public static final String GETTER_POOL_PARTITION_SIZE_KEY = "getterPoolPartitionSize";
038:
039: public static final String CALLER_POOL_MIN_SIZE_KEY = "callerPoolMinSize";
040: public static final String CALLER_POOL_MAX_SIZE_KEY = "callerPoolMaxSize";
041: public static final String CALLER_POOL_PARTITION_SIZE_KEY = "callerPoolPartitionSize";
042:
043: public static final String COOKIEPREFIX_KEY = "cookiePrefix";
044: public static final String LB_COOKIE_NAME = "lb.cookie.name";
045: public static final String JSPSCRATCHDIR_KEY = "jspScratchDir";
046: public static final String MAX_EVENT_GENERATIONS = "maxEventGenerations";
047: public static final String PORTLET_RENDER_MODE_PARALLEL = "portletRenderModeParallel";
048:
049: public static final String COMMUNITY_CONTRIBUTOR_TYPES = "community.contributor.types";
050: protected static final String COMMUNITY_CONTRIBUTOR_TYPES_DELIMITERS = " ,|";
051: protected static final String COMMUNITY_CONTRIBUTOR_TYPES_DEFAULT = "jdo";
052: protected static List communityContributorTypes = null;
053:
054: protected static Properties properties = null;
055:
056: public PropertiesConfigContext() {
057: }
058:
059: public void init(ServletContext sc) {
060: ResourceLoader resourceLoader = ResourceLoader
061: .getInstance(System.getProperties());
062: try {
063: properties = resourceLoader
064: .getProperties(DESKTOP_CONFIG_FILE);
065: } catch (FileNotFoundException fnfe) {
066: throw new ContextError("PropertiesConfigContext.init(): ",
067: fnfe);
068: } catch (IOException ioe) {
069: throw new ContextError("PropertiesConfigContext.init(): ",
070: ioe);
071: }
072: }
073:
074: public void init(String filename) {
075: properties = new Properties();
076: try {
077: properties.load(new FileInputStream(filename));
078: } catch (FileNotFoundException fnfe) {
079: throw new ContextError("PropertiesConfigContext.init(): ",
080: fnfe);
081: } catch (IOException ioe) {
082: throw new ContextError("PropertiesConfigContext.init(): ",
083: ioe);
084: }
085: }
086:
087: public String getServiceAppContextClassName() {
088: return properties.getProperty(SERVICEAPPCONTEXTCLASSNAME_KEY);
089: }
090:
091: public String getConfigProperty(String key) {
092: return properties.getProperty(key);
093: }
094:
095: public String getTemplateBaseDir() {
096: return properties.getProperty(TEMPLATEBASEDIR_KEY);
097: }
098:
099: public String getCookiePrefix() {
100: return properties.getProperty(COOKIEPREFIX_KEY);
101: }
102:
103: public String getLBCookieName() {
104: return properties.getProperty(LB_COOKIE_NAME);
105: }
106:
107: public String getProviderClassBaseDir() {
108: return properties.getProperty(PROVIDERCLASSBASEDIR_KEY);
109: }
110:
111: public String getJSPCompilerWARClassPath() {
112: return properties.getProperty(JSPCOMPILERWARCLASSPATH_KEY);
113: }
114:
115: public String getJSPScratchDir() {
116: return properties.getProperty(JSPSCRATCHDIR_KEY);
117: }
118:
119: public String getDefaultDesktopType() {
120: return properties.getProperty(DEFAULT_DESKTOPTYPE_KEY);
121: }
122:
123: public String getPortalId() {
124: return ResourceLoader.getInstance(System.getProperties())
125: .getPortalId();
126: }
127:
128: public String getInstanceId() {
129: return ResourceLoader.getInstance(System.getProperties())
130: .getInstanceId();
131: }
132:
133: //Execution mode for portlets in Appserver
134: //(true: parallel exec, false: serial exec)
135: //true by default
136: public String getPortletRenderModeParallel() {
137: String portletRenderModeParallel = properties
138: .getProperty(PORTLET_RENDER_MODE_PARALLEL);
139: //Make sure that the default works ...
140: if (portletRenderModeParallel == null)
141: portletRenderModeParallel = new String("true");
142: return portletRenderModeParallel;
143: }
144:
145: public int getGetterPoolMinSize() {
146: return getIntegerProperty(GETTER_POOL_MIN_SIZE_KEY);
147: }
148:
149: public int getGetterPoolMaxSize() {
150: return getIntegerProperty(GETTER_POOL_MAX_SIZE_KEY);
151: }
152:
153: public int getGetterPoolPartitionSize() {
154: return getIntegerProperty(GETTER_POOL_PARTITION_SIZE_KEY);
155: }
156:
157: public int getCallerPoolMinSize() {
158: return getIntegerProperty(CALLER_POOL_MIN_SIZE_KEY);
159: }
160:
161: public int getCallerPoolMaxSize() {
162: return getIntegerProperty(CALLER_POOL_MAX_SIZE_KEY);
163: }
164:
165: public int getCallerPoolPartitionSize() {
166: return getIntegerProperty(CALLER_POOL_PARTITION_SIZE_KEY);
167: }
168:
169: public int getTemplateScanInterval() {
170: return getIntegerProperty(TEMPLATE_SCAN_INTERVAL);
171: }
172:
173: public int getDPScanInterval() {
174: return getIntegerProperty(DP_SCAN_INTERVAL);
175: }
176:
177: public int getClassLoaderRevalidateInterval() {
178: return getIntegerProperty(CLASSLOADER_REVALIDATE_INTERVAL);
179: }
180:
181: public int getBrowserCacheInterval() {
182: return getIntegerProperty(BROWSER_CACHE_INTERVAL);
183: }
184:
185: public int getMaxEventGenerations() {
186: return getIntegerProperty(MAX_EVENT_GENERATIONS);
187: }
188:
189: public List getCommunityContributorTypes() {
190: if (communityContributorTypes == null) {
191: communityContributorTypes = new ArrayList();
192:
193: StringTokenizer tokenizer = new StringTokenizer(properties
194: .getProperty(COMMUNITY_CONTRIBUTOR_TYPES,
195: COMMUNITY_CONTRIBUTOR_TYPES_DEFAULT),
196: COMMUNITY_CONTRIBUTOR_TYPES_DELIMITERS);
197: while (tokenizer.hasMoreTokens()) {
198: communityContributorTypes.add(tokenizer.nextToken());
199: }
200: }
201:
202: return communityContributorTypes;
203: }
204:
205: private int getIntegerProperty(String key) {
206: String strInt = properties.getProperty(key);
207: int result = 0;
208: if (strInt != null && strInt.length() > 0) {
209: try {
210: result = Integer.parseInt(strInt);
211: } catch (NumberFormatException e) {
212: throw new ContextError(
213: "PropertiesConfigContext.getIntegerProperty(): invalid number format for key "
214: + key, e);
215: }
216: }
217: return result;
218: }
219: }
|