001: /*
002: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
003: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
004: */
005: package com.sun.portal.monitoring;
006:
007: import com.sun.portal.monitoring.utilities.PropertyHelper;
008: import com.sun.portal.monitoring.utilities.UtilityException;
009: import com.sun.portal.monitoring.security.SecurityContext;
010: import com.sun.portal.monitoring.security.sasl.SaslContext;
011: import com.sun.portal.monitoring.security.ssl.SslContext;
012: import com.sun.portal.log.common.PortalLogger;
013:
014: import java.io.File;
015: import java.util.logging.Logger;
016: import java.util.logging.Level;
017: import java.util.logging.LogRecord;
018:
019: public class MonitoringContext {
020: private static final Logger logger = PortalLogger
021: .getLogger(MonitoringContext.class);
022:
023: private static LogRecord getLogRecord(Level level, String message,
024: Object[] parameters, Throwable t) {
025: LogRecord result = new LogRecord(level, message);
026: result.setLoggerName(logger.getName());
027: result.setParameters(parameters);
028: result.setThrown(t);
029: return result;
030: }
031:
032: public MonitoringContext(PropertyHelper propertyHelper) {
033: this .propertyHelper = propertyHelper;
034: if (propertyHelper == null) {
035: this .propertyHelper = new PropertyHelper(null);
036: }
037: }
038:
039: private PropertyHelper propertyHelper;
040:
041: public PropertyHelper getPropertyHelper() {
042: return propertyHelper;
043: }
044:
045: public String getCustomPropertiesDirectory() {
046: return customPropertiesDirectory;
047: }
048:
049: public void setCustomPropertiesDirectory(
050: String customPropertiesDirectory) {
051: this .customPropertiesDirectory = customPropertiesDirectory;
052: }
053:
054: public String getCustomPropertiesFileName() {
055: return customPropertiesFileName;
056: }
057:
058: public void setCustomPropertiesFileName(
059: String customPropertiesFileName) {
060: this .customPropertiesFileName = customPropertiesFileName;
061: }
062:
063: public String getSubsystemMode() {
064: return subsystemMode;
065: }
066:
067: public void setSubsystemMode(String subsystemMode) {
068: this .subsystemMode = subsystemMode;
069: }
070:
071: public String getSubsystemType() {
072: return subsystemType;
073: }
074:
075: public void setSubsystemType(String subsystemType) {
076: this .subsystemType = subsystemType;
077: }
078:
079: public String getConfigurationDirectory() {
080: return configurationDirectory;
081: }
082:
083: public void setConfigurationDirectory(String configurationDirectory) {
084: this .configurationDirectory = configurationDirectory;
085: }
086:
087: public String getUserName() {
088: return userName;
089: }
090:
091: public void setUserName(String userName) {
092: this .userName = userName;
093: }
094:
095: public String getUserPassword() {
096: return userPassword;
097: }
098:
099: public void setUserPassword(String userPassword) {
100: this .userPassword = userPassword;
101: }
102:
103: public String getNamingDomain() {
104: return namingDomain;
105: }
106:
107: public void setNamingDomain(String namingDomain) {
108: this .namingDomain = namingDomain;
109: }
110:
111: public Boolean getMonitoringDisable() {
112: return monitoringDisable;
113: }
114:
115: public void setMonitoringDisable(Boolean monitoringDisable) {
116: this .monitoringDisable = monitoringDisable;
117: }
118:
119: public String getHtmlAdaptorPort() {
120: return htmlAdaptorPort;
121: }
122:
123: public void setHtmlAdaptorPort(String htmlAdaptorPort) {
124: this .htmlAdaptorPort = htmlAdaptorPort;
125: }
126:
127: public String getNamingTypeConnectorServer() {
128: return namingTypeConnectorServer;
129: }
130:
131: public void setNamingTypeConnectorServer(
132: String namingTypeConnectorServer) {
133: this .namingTypeConnectorServer = namingTypeConnectorServer;
134: }
135:
136: public String getNamingTypeHtmlAdaptorServer() {
137: return namingTypeHtmlAdaptorServer;
138: }
139:
140: public void setNamingTypeHtmlAdaptorServer(
141: String namingTypeHtmlAdaptorServer) {
142: this .namingTypeHtmlAdaptorServer = namingTypeHtmlAdaptorServer;
143: }
144:
145: public String getNamingTypeMonitoringConfiguration() {
146: return namingTypeMonitoringConfiguration;
147: }
148:
149: public void setNamingTypeMonitoringConfiguration(
150: String namingTypeMonitoringConfiguration) {
151: this .namingTypeMonitoringConfiguration = namingTypeMonitoringConfiguration;
152: }
153:
154: public Boolean getUseJavaPlatformMBeanServer() {
155: return useJavaPlatformMBeanServer;
156: }
157:
158: public void setUseJavaPlatformMBeanServer(
159: Boolean useJavaPlatformMBeanServer) {
160: this .useJavaPlatformMBeanServer = useJavaPlatformMBeanServer;
161: }
162:
163: private Boolean getBooleanProperty(String propertySuffix) {
164: return propertyHelper.getBooleanProperty(getClass().getName(),
165: propertySuffix);
166: }
167:
168: private String getProperty(String propertySuffix,
169: String defaultValue) {
170: return propertyHelper.getProperty(getClass().getName(),
171: propertySuffix, defaultValue);
172: }
173:
174: private String setProperty(String propertySuffix, String value) {
175: return propertyHelper.setProperty(getClass().getName(),
176: propertySuffix, value);
177: }
178:
179: private void gearUpCustomProperties() {
180: try {
181: propertyHelper
182: .loadProperties(getCustomPropertiesDirectory()
183: + File.separator
184: + getCustomPropertiesFileName());
185: } catch (UtilityException e) {
186: /* Commenting this exception as Custom Properties are not used by default setup
187: * Eating-exception-completely is allowed here!
188: if (logger.isLoggable(Level.CONFIG)) {
189: logger.log(getLogRecord(Level.CONFIG, "PSMN_CSPM0001", new Object[] {e.getLocalizedMessage()}, e));
190: }
191: */
192: }
193: }
194:
195: public void gearUp() {
196: setCustomPropertiesDirectory(getProperty(
197: PROPERTY_SUFFIX_CUSTOM_PROPERTIES_DIRECTORY,
198: CUSTOM_PROPERTIES_DIRECTORY));
199: setCustomPropertiesFileName(getProperty(
200: PROPERTY_SUFFIX_CUSTOM_PROPERTIES_FILE_NAME,
201: CUSTOM_PROPERTIES_FILE_NAME));
202: gearUpCustomProperties();
203:
204: setSubsystemMode(getProperty(PROPERTY_SUFFIX_SUBSYSTEM_MODE,
205: SUBSYSTEM_MODE));
206: setSubsystemType(getProperty(PROPERTY_SUFFIX_SUBSYSTEM_TYPE,
207: SUBSYSTEM_TYPE));
208:
209: setConfigurationDirectory(getProperty(
210: PROPERTY_SUFFIX_CONFIGURATION_DIRECTORY,
211: CONFIGURATION_DIRECTORY));
212: setUserName(getProperty(PROPERTY_SUFFIX_USER_NAME, USER_NAME));
213: String userPassword = getProperty(
214: PROPERTY_SUFFIX_USER_PASSWORD, USER_PASSWORD);
215: setUserPassword(userPassword.equals("") ? USER_PASSWORD
216: : userPassword);
217: setProperty(PROPERTY_SUFFIX_USER_PASSWORD, "");
218:
219: setNamingDomain(getProperty(PROPERTY_SUFFIX_NAMING_DOMAIN,
220: NAMING_DOMAIN));
221: setNamingTypeConnectorServer(getProperty(
222: PROPERTY_SUFFIX_NAMING_TYPE_CONNECTOR_SERVER,
223: NAMING_TYPE_CONNECTOR_SERVER));
224: setNamingTypeHtmlAdaptorServer(getProperty(
225: PROPERTY_SUFFIX_NAMING_TYPE_HTML_ADAPTOR_SERVER,
226: NAMING_TYPE_HTML_ADAPTOR_SERVER));
227: setNamingTypeMonitoringConfiguration(getProperty(
228: PROPERTY_SUFFIX_NAMING_TYPE_MONITORING_CONFIGURATION,
229: NAMING_TYPE_MONITORING_CONFIGURATION));
230:
231: setMonitoringDisable(getBooleanProperty(PROPERTY_SUFFIX_MONITORING_DISABLE));
232: setHtmlAdaptorPort(getProperty(
233: PROPERTY_SUFFIX_HTML_ADAPTOR_PORT, HTML_ADAPTOR_PORT));
234: setUseJavaPlatformMBeanServer(getBooleanProperty(PROPERTY_SUFFIX_USE_JAVA_PLATFORM_MBEANSERVER));
235:
236: gearUpSecurityContext();
237: gearUpSslContext();
238: gearUpSaslContext();
239: }
240:
241: public static String PROPERTY_SUFFIX_CUSTOM_PROPERTIES_DIRECTORY = "custom.properties.directory";
242: public static String CUSTOM_PROPERTIES_DIRECTORY = ".";
243: private String customPropertiesDirectory;
244:
245: public static String PROPERTY_SUFFIX_CUSTOM_PROPERTIES_FILE_NAME = "custom.properties.file.name";
246: public static String CUSTOM_PROPERTIES_FILE_NAME = "monitoring.custom.properties";
247: private String customPropertiesFileName;
248:
249: public static String PROPERTY_SUFFIX_SUBSYSTEM_MODE = "subsystem.mode";
250: public static String SUBSYSTEM_MODE = "Server"; // Client
251: private String subsystemMode;
252:
253: public static String PROPERTY_SUFFIX_SUBSYSTEM_TYPE = "subsystem.type";
254: public static String SUBSYSTEM_TYPE_BEA = "Bea";
255: public static String SUBSYSTEM_TYPE_ = "Ibm";
256: public static String SUBSYSTEM_TYPE_SUN = "Sun";
257: public static String SUBSYSTEM_TYPE = SUBSYSTEM_TYPE_SUN;
258: private String subsystemType;
259:
260: public static String PROPERTY_SUFFIX_CONFIGURATION_DIRECTORY = "configuration.directory";
261: public static String CONFIGURATION_DIRECTORY = ".";
262: private String configurationDirectory;
263:
264: public static String PROPERTY_SUFFIX_USER_NAME = "user.name";
265: public static String USER_NAME = "DemoUser";
266: private String userName;
267:
268: public static String PROPERTY_SUFFIX_USER_PASSWORD = "user.password";
269: public static String USER_PASSWORD = "DemoPassword";
270: private String userPassword;
271:
272: public static String PROPERTY_SUFFIX_NAMING_DOMAIN = "naming.domain";
273: public static String NAMING_DOMAIN = "PortalServer";
274: private String namingDomain;
275:
276: public static String PROPERTY_SUFFIX_MONITORING_DISABLE = "monitoring.disable";
277: private Boolean monitoringDisable;
278:
279: public static String PROPERTY_SUFFIX_HTML_ADAPTOR_PORT = "html.adaptor.port";
280: public static String HTML_ADAPTOR_PORT = "0";
281: private String htmlAdaptorPort;
282:
283: public static String PROPERTY_SUFFIX_NAMING_TYPE_CONNECTOR_SERVER = "naming.type.connector.server";
284: public static String NAMING_TYPE_CONNECTOR_SERVER = "ConnectorServer";
285: private String namingTypeConnectorServer;
286:
287: public static String PROPERTY_SUFFIX_NAMING_TYPE_HTML_ADAPTOR_SERVER = "naming.type.html.adaptor.server";
288: public static String NAMING_TYPE_HTML_ADAPTOR_SERVER = "HtmlAdaptorServer";
289: private String namingTypeHtmlAdaptorServer;
290:
291: public static String PROPERTY_SUFFIX_NAMING_TYPE_MONITORING_CONFIGURATION = "naming.type.monitoring.configuration";
292: public static String NAMING_TYPE_MONITORING_CONFIGURATION = "MonitoringConfiguration";
293: private String namingTypeMonitoringConfiguration;
294:
295: public static String PROPERTY_SUFFIX_USE_JAVA_PLATFORM_MBEANSERVER = "use.java.platform.mbeanserver";
296: private Boolean useJavaPlatformMBeanServer;
297:
298: public SecurityContext getSecurityContext() {
299: return securityContext;
300: }
301:
302: public SslContext getSslContext() {
303: return sslContext;
304: }
305:
306: public SaslContext getSaslContext() {
307: return saslContext;
308: }
309:
310: public ConnectorContext getConnectorContext() {
311: return connectorContext;
312: }
313:
314: private void gearUpSecurityContext() {
315: securityContext = new SecurityContext(propertyHelper);
316: }
317:
318: private void gearUpSslContext() {
319: sslContext = new SslContext(propertyHelper);
320:
321: sslContext.setSecurityContext(getSecurityContext());
322: sslContext.gearUp();
323: }
324:
325: private void gearUpSaslContext() {
326: saslContext = new SaslContext(propertyHelper);
327: saslContext.gearUp();
328: }
329:
330: public void gearUpConnectorContext() throws MonitoringException {
331: connectorContext = new ConnectorContext(propertyHelper);
332: connectorContext.gearUp(getSaslContext(), getSslContext());
333: }
334:
335: private SecurityContext securityContext;
336: private SslContext sslContext;
337: private SaslContext saslContext;
338: private ConnectorContext connectorContext;
339: }
|