001: package org.drools.audit.event;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: /**
020: * An activation event logged by the WorkingMemoryLogger.
021: * It is a snapshot of the event as it was thrown by the working memory.
022: * It contains the activation id, the name of the rule and a String
023: * representing the declarations of the activation, which is a list of
024: * name-value-pairs for each of the declarations in the tuple of the
025: * activation. The name is the identifier (=name) of the
026: * declaration, and the value is a toString of the value of the
027: * parameter, followed by the id of the fact between parentheses.
028: * e.g. param1=10; param2=Person[John Doe]
029: *
030: * Such a String representation is used to create a snapshot of the
031: * current state of the activation by storing a toString of the facts
032: * bound in the activation. If necessary, this event could be extended
033: * to contain a map of declarations too.
034: *
035: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen </a>
036: */
037: public class ActivationLogEvent extends LogEvent {
038:
039: private String activationId;
040: private String rule;
041: private String declarations;
042: private String ruleFlowGroup;
043:
044: /**
045: * Create a new activation log event.
046: *
047: * @param type The type of event. This can only be ACTIVATION_CREATED, ACTIVATION_CANCELLED,
048: * BEFORE_ACTIVATION_FIRE or AFTER_ACTIVATION_FIRE.
049: * @param activationId The id of the activation
050: * @param rule The name of the rule of the activation
051: * @param declarations A String representation of the declarations in the
052: * activation.
053: */
054: public ActivationLogEvent(final int type,
055: final String activationId, final String rule,
056: final String declarations, final String ruleFlowGroup) {
057: super (type);
058: this .activationId = activationId;
059: this .rule = rule;
060: this .declarations = declarations;
061: this .ruleFlowGroup = ruleFlowGroup;
062: }
063:
064: /**
065: * Returns a unique id for the activation.
066: *
067: * @return The id of the activation
068: */
069: public String getActivationId() {
070: return this .activationId;
071: }
072:
073: /**
074: * Returns the name of the rule of the activation.
075: *
076: * @return The name of the rule
077: */
078: public String getRule() {
079: return this .rule;
080: }
081:
082: /**
083: * Returns a String representation of the declarations in the
084: * activation.
085: *
086: * @return A String representation of the declarations.
087: */
088: public String getDeclarations() {
089: return this .declarations;
090: }
091:
092: public String getRuleFlowGroup() {
093: return ruleFlowGroup;
094: }
095:
096: public String toString() {
097:
098: String msg = null;
099: switch (this .getType()) {
100: case ACTIVATION_CANCELLED:
101: msg = "ACTIVATION CANCELLED";
102: break;
103: case ACTIVATION_CREATED:
104: msg = "ACTIVATION CREATED";
105: break;
106:
107: case AFTER_ACTIVATION_FIRE:
108: msg = "AFTER ACTIVATION FIRED";
109: break;
110: case BEFORE_ACTIVATION_FIRE:
111: msg = "BEFORE ACTIVATION FIRED";
112: break;
113: }
114: return msg
115: + " rule:"
116: + this .rule
117: + " activationId:"
118: + this .activationId
119: + " declarations: "
120: + this .declarations
121: + (ruleFlowGroup == null ? "" : " ruleflow-group: "
122: + ruleFlowGroup);
123: }
124: }
|