View Javadoc
1   /**
2    * Copyright 2005-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.krad.rules.rule.event;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  
23  /**
24   * Created by nigupta on 4/28/2014.
25   */
26  abstract public class RuleEventBase implements RuleEvent {
27  
28      private String name;
29      private final String description;
30      private final String errorPathPrefix;
31      private Map<String, Object> facts = new HashMap<String, Object>();
32      private String ruleMethodName;
33  
34      /**
35       * As a general rule, business rule classes should not change the original object. This constructor was created so
36       * that PreRulesCheckEvent, a UI level rule checker, can make changes.
37       *
38       * @param description
39       * @param errorPathPrefix
40       */
41      public RuleEventBase( String description, String errorPathPrefix ) {
42          this.description = description;
43          this.errorPathPrefix = errorPathPrefix;
44      }
45  
46      public void addFact( String key, Object object ) {
47          facts.put( key, object );
48      }
49  
50      /**
51       * the name of this event
52       * @return - the event name
53       */
54      public String getName() {
55          return name;
56      }
57  
58      /**
59       * @see RuleEventBase#getName()
60       */
61      public void setName( String name ) {
62          this.name = name;
63      }
64  
65      /**
66       * @return a description of this event
67       */
68      public final String getDescription() {
69          return description;
70      }
71  
72      /**
73       * @return the error path prefix for this event
74       */
75      public String getErrorPathPrefix() {
76          return errorPathPrefix;
77      }
78  
79      /**
80       * @see java.lang.Object#toString()
81       */
82      @Override
83      public String toString() {
84          return getName();
85      }
86  
87      /**
88       * {@inheritDoc}
89       */
90      public Map<String, Object> getFacts() {
91          return facts;
92      }
93  
94      /**
95       * @see RuleEventBase#getFacts()
96       */
97      public void setFacts( Map<String, Object> facts ) {
98          this.facts = facts;
99      }
100 
101     /**
102      * {@inheritDoc}
103      */
104     public String getRuleMethodName() {
105         return ruleMethodName;
106     }
107 
108     /**
109      * @see RuleEventBase#getRuleMethodName()
110      */
111     public void setRuleMethodName( String name ) {
112         this.ruleMethodName = name;
113     }
114 
115     /**
116      * @see org.kuali.rice.krad.rules.rule.event.RuleEvent#generateEvents()
117      */
118     @Override
119     public List<RuleEvent> generateEvents() {
120         return new ArrayList<RuleEvent>();
121     }
122 }