/machinelearning/5.0.x/drools-core/src/main/java/org/drools/audit/event/ActivationLogEvent.java

https://github.com/sotty/droolsjbpm-contributed-experiments · Java · 141 lines · 67 code · 15 blank · 59 comment · 2 complexity · b8085b468421180a6dc4b6846b36c96e MD5 · raw file

  1. package org.drools.audit.event;
  2. import java.io.IOException;
  3. import java.io.ObjectInput;
  4. import java.io.ObjectOutput;
  5. /*
  6. * Copyright 2005 JBoss Inc
  7. *
  8. * Licensed under the Apache License, Version 2.0 (the "License");
  9. * you may not use this file except in compliance with the License.
  10. * You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS,
  16. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. * See the License for the specific language governing permissions and
  18. * limitations under the License.
  19. */
  20. /**
  21. * An activation event logged by the WorkingMemoryLogger.
  22. * It is a snapshot of the event as it was thrown by the working memory.
  23. * It contains the activation id, the name of the rule and a String
  24. * representing the declarations of the activation, which is a list of
  25. * name-value-pairs for each of the declarations in the tuple of the
  26. * activation. The name is the identifier (=name) of the
  27. * declaration, and the value is a toString of the value of the
  28. * parameter, followed by the id of the fact between parentheses.
  29. * e.g. param1=10; param2=Person[John Doe]
  30. *
  31. * Such a String representation is used to create a snapshot of the
  32. * current state of the activation by storing a toString of the facts
  33. * bound in the activation. If necessary, this event could be extended
  34. * to contain a map of declarations too.
  35. *
  36. * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen </a>
  37. */
  38. public class ActivationLogEvent extends LogEvent {
  39. private String activationId;
  40. private String rule;
  41. private String declarations;
  42. private String ruleFlowGroup;
  43. public ActivationLogEvent() {
  44. }
  45. /**
  46. * Create a new activation log event.
  47. *
  48. * @param type The type of event. This can only be ACTIVATION_CREATED, ACTIVATION_CANCELLED,
  49. * BEFORE_ACTIVATION_FIRE or AFTER_ACTIVATION_FIRE.
  50. * @param activationId The id of the activation
  51. * @param rule The name of the rule of the activation
  52. * @param declarations A String representation of the declarations in the
  53. * activation.
  54. */
  55. public ActivationLogEvent(final int type,
  56. final String activationId,
  57. final String rule,
  58. final String declarations,
  59. final String ruleFlowGroup) {
  60. super( type );
  61. this.activationId = activationId;
  62. this.rule = rule;
  63. this.declarations = declarations;
  64. this.ruleFlowGroup = ruleFlowGroup;
  65. }
  66. public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
  67. super.readExternal(in);
  68. activationId = (String)in.readObject();
  69. rule = (String)in.readObject();
  70. declarations = (String)in.readObject();
  71. ruleFlowGroup = (String)in.readObject();
  72. }
  73. public void writeExternal(ObjectOutput out) throws IOException {
  74. super.writeExternal(out);
  75. out.writeObject(activationId);
  76. out.writeObject(rule);
  77. out.writeObject(declarations);
  78. out.writeObject(ruleFlowGroup);
  79. }
  80. /**
  81. * Returns a unique id for the activation.
  82. *
  83. * @return The id of the activation
  84. */
  85. public String getActivationId() {
  86. return this.activationId;
  87. }
  88. /**
  89. * Returns the name of the rule of the activation.
  90. *
  91. * @return The name of the rule
  92. */
  93. public String getRule() {
  94. return this.rule;
  95. }
  96. /**
  97. * Returns a String representation of the declarations in the
  98. * activation.
  99. *
  100. * @return A String representation of the declarations.
  101. */
  102. public String getDeclarations() {
  103. return this.declarations;
  104. }
  105. public String getRuleFlowGroup() {
  106. return ruleFlowGroup;
  107. }
  108. public String toString() {
  109. String msg = null;
  110. switch ( this.getType() ) {
  111. case ACTIVATION_CANCELLED :
  112. msg = "ACTIVATION CANCELLED";
  113. break;
  114. case ACTIVATION_CREATED :
  115. msg = "ACTIVATION CREATED";
  116. break;
  117. case AFTER_ACTIVATION_FIRE :
  118. msg = "AFTER ACTIVATION FIRED";
  119. break;
  120. case BEFORE_ACTIVATION_FIRE :
  121. msg = "BEFORE ACTIVATION FIRED";
  122. break;
  123. }
  124. return msg + " rule:" + this.rule + " activationId:" + this.activationId + " declarations: " + this.declarations + (ruleFlowGroup == null ? "" : " ruleflow-group: " + ruleFlowGroup);
  125. }
  126. }