001: /*
002: * Copyright 2001 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.search.rdmserver;
007:
008: import com.sun.portal.search.rdm.*;
009: import com.sun.portal.search.soif.*;
010: import com.sun.portal.search.util.*;
011: import com.sun.portal.log.common.PortalLogger;
012: import com.sun.portal.log.common.PortalLogManager;
013:
014: import com.sun.kt.search.*;
015:
016: import java.io.*;
017: import java.util.*;
018: import java.util.logging.Logger;
019: import java.util.logging.Level;
020: import java.util.logging.LogRecord;
021:
022: /**
023: * RDMContext is a container for logging, configuration, schema, etc.
024: */
025: abstract public class RDMContext {
026:
027: Map contextConfig; // RDM context configuration
028: RDMConfig rdmConfig; // RDM config data
029: //String logFile; // RDM log file, eg, rdm.log
030: //PrintWriter rdmLogStream; // RDM log stream
031:
032: /** @deprecated */
033: boolean rdm_log_enabled = true;
034:
035: // XXX This uses rdmConfig, but should really use RDMContextConfig
036: // (for now, they are the same thing) - change for dsame, etc
037: public RDMContext(RDMConfig rdmconf) throws Exception {
038:
039: rdmConfig = rdmconf;
040:
041: String rdmctx_conf = new File(rdmconf.getServerRoot(),
042: SearchConfig.CONFDIR + File.separator
043: + SearchConfig.SEARCH_CONF).getPath();
044:
045: // Read the csid pblock config file
046: try {
047: contextConfig = new HashMap();
048: PBlock.parsePBlockConfigFile(rdmctx_conf, contextConfig);
049: } catch (Exception e) {
050: throw new Exception(
051: "rdm-init: failed to read config file: "
052: + rdmctx_conf + ": " + e.getMessage());
053: }
054:
055: rdm_init_real();
056: }
057:
058: /** Container logging */
059: abstract public void log(String msg);
060:
061: /** Container logging */
062: abstract public void log(String msg, Exception e);
063:
064: /** RDM request/response logging */
065: public void logrdm(String msg) {
066: Logger rdmRootLogger = SearchLogger.getRDMLogger();
067: if (rdmRootLogger != null) {
068: rdmRootLogger.log(Level.SEVERE, "PSSH_CSPSRDMS0137", msg);
069: }
070: }
071:
072: /** @deprecated */
073: public void rdmLogEnable(boolean enable) {
074: rdm_log_enabled = enable;
075: }
076:
077: public RDMConfig getRDMConfig() {
078: return rdmConfig;
079: }
080:
081: protected void rdm_init_real() throws Exception {
082:
083: // Initialize rdmserver.log
084: try {
085: SearchLogger.init(SearchConfig.RDMSERVER_LOGGER, rdmConfig
086: .getServerRoot());
087: } catch (Exception e) {
088: System.err.println("Failed to initialise RDM error log: "
089: + e.getMessage());
090: throw new Exception("Failed to initialise RDM error log: "
091: + e.getMessage());
092: }
093:
094: String search_engine_log = (String) contextConfig
095: .get(SearchConfig.SENGINE_LOGFN);
096: if (search_engine_log != null) {
097:
098: String debug_log_level = (String) contextConfig
099: .get(SearchConfig.DEBUG_LOGLV);
100: int loglevel = 0;
101: if (debug_log_level != null)
102: loglevel = Integer.parseInt(debug_log_level);
103:
104: try {
105: // Nova logging. XXX no rotation
106: Log log = Log.getLog();
107: OutputStream os = new FileOutputStream(
108: search_engine_log, true);
109: log.setStream(os);
110: log.setLevel(loglevel);
111: if (!Build.debug)
112: log.setLevel(Log.DEBUG, 0);
113: } catch (Exception e) {
114: if (SearchLogger.getLogger().isLoggable(Level.WARNING)) {
115: LogRecord rec = new LogRecord(Level.WARNING,
116: "PSSH_CSPSRDMS0136");
117: Object[] obj = new Object[] { search_engine_log };
118: rec.setParameters(obj);
119: rec.setThrown(e);
120: rec.setLoggerName(SearchLogger.getLogger()
121: .getName());
122: SearchLogger.getLogger().log(rec);
123: }
124: throw e;
125: }
126: }
127:
128: // Initialize rdm.log
129: try {
130: rdm_log_init();
131: } catch (Exception e) {
132: throw new Exception("Failed to initialise RDM error log: "
133: + e.getMessage());
134: }
135: schema_init();
136:
137: }
138:
139: /** logging support */
140: protected void rdm_log_init() throws Exception {
141: SearchLogger.rdmLogInit(SearchConfig.RDM_LOGGER, rdmConfig
142: .getServerRoot());
143: }
144:
145: public void schema_init() throws Exception {
146: // XXX schema is part of CSID???
147: // We're getting rid of csid concept. Schema will be shared by all dbs.
148: String schemafn = null;
149: try {
150: // XXX schema.rdm currently only defines the DOCUMENT object type.
151: // XXX It should either define all object types, or be renamed document.schema
152: schemafn = SearchConfig.getValue(SearchConfig.SCHEMA);
153: SOIFInputStream ss = new SOIFInputStream(schemafn);
154: SOIF s;
155: while ((s = ss.readSOIF()) != null) {
156: RDMSchema docSchema = RDMSchema.register(new RDMSchema(
157: s));
158: SearchLogger.getLogger().log(Level.INFO,
159: "PSSH_CSPSRDMS0039", docSchema.getName());
160: }
161: RDMSchema classSchema = RDMSchema.register(new RDMSchema(
162: RDMSchema.getClassificationSchemaSOIF()));
163: SearchLogger.getLogger().log(Level.INFO,
164: "PSSH_CSPSRDMS0040", classSchema.getName());
165: } catch (Exception e) {
166: if (SearchLogger.getLogger().isLoggable(Level.WARNING)) {
167: LogRecord rec = new LogRecord(Level.WARNING,
168: "PSSH_CSPSRDMS0041");
169: Object[] obj = new Object[] { schemafn };
170: rec.setParameters(obj);
171: rec.setThrown(e);
172: rec.setLoggerName(SearchLogger.getLogger().getName());
173: SearchLogger.getLogger().log(rec);
174: }
175: throw e;
176: }
177: }
178:
179: }
|