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.ubt;
006:
007: import com.sun.portal.log.common.PortalLogger;
008:
009: import java.util.logging.Level;
010: import java.util.logging.Logger;
011: import java.util.Hashtable;
012:
013: /**
014: * This class represents the UBT event type.
015: * Any UBT event that need to be logged, need to be of this type.
016: */
017: public class UBTEvent {
018: private static Logger logger = PortalLogger
019: .getLogger(UBTEvent.class);
020:
021: /**
022: * Method to get instance of an event of UBTEvent type, given the name.
023: * This method configures the event based on UBT configurations.
024: * The configurations involve the level, logger.
025: * @param name Name of the event.
026: * @return UBTEvent object
027: */
028: public static UBTEvent getInstance(String name) {
029: UBTEvent event = new UBTEvent(name);
030: event.setLevel(UBTLogManager.getInstance().getEventLevel(
031: name,
032: Logger.getLogger(UBTLogManager.UBT_ROOT_LOGGER)
033: .getLevel()));
034: event.setLoggerName(UBTLogManager.getInstance()
035: .getEventLoggerName(name, event.elogger));
036: return event;
037: }
038:
039: private String ID;
040: private String elogger = UBTLogManager.UBT_ROOT_LOGGER;
041:
042: private Level level;
043:
044: //It is possible that each event interprets the record fields
045: // in a different way. So, it is required for the event to decide
046: // what value to be assigned for each field rather than deciding at record level
047: private Hashtable table = new Hashtable();
048:
049: private UBTEvent(String ID) {
050: this .ID = ID;
051: }
052:
053: /**
054: * gets Event ID.
055: * @return ID.
056: */
057: public String getID() {
058: return ID;
059: }
060:
061: private void setID(String ID) {
062: this .ID = ID;
063: }
064:
065: private void setLoggerName(String logger) {
066: this .elogger = logger;
067: }
068:
069: /**
070: * Get the logger name associated with the event.
071: * @return logger name.
072: */
073: public String getLoggerName() {
074: return elogger;
075: }
076:
077: /**
078: * Puts the give UBTLogField object into an internal hashtable, along with the value specified.
079: * The value object should be such that value.toString() should return meaningful value so that the
080: * formatter publishes properly.
081: * @param field UBTLogField
082: * @param value Field value
083: */
084: public void put(UBTLogField field, Object value) {
085: try {
086: table.put(field, value);
087: } catch (Exception e) {
088: logger.log(Level.FINE, "PSUB_CSPU0002");
089: }
090: }
091:
092: /**
093: * Gets the table of log fields.
094: * @return table of log fields.
095: */
096: public Hashtable getLogTable() {
097: return table;
098: }
099:
100: /**
101: * Get the level associated.
102: * @return Level
103: */
104: public Level getLevel() {
105: return level;
106: }
107:
108: private void setLevel(Level level) {
109: this.level = level;
110: }
111:
112: }
|