KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > alert > Alert


1 /**
2 * Copyright (c) 2004-2005 jManage.org
3 *
4 * This is a free software; you can redistribute it and/or
5 * modify it under the terms of the license at
6 * http://www.jmanage.org.
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */

14 package org.jmanage.core.alert;
15
16 import org.jmanage.core.config.AlertConfig;
17 import org.jmanage.core.util.Loggers;
18
19 import java.util.List JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.logging.Logger JavaDoc;
22 import java.util.logging.Level JavaDoc;
23
24 /**
25  *
26  * Date: Jul 4, 2005
27  * @author Rakesh Kalra
28  */

29 public class Alert implements AlertHandler {
30
31     private static Logger JavaDoc logger = Loggers.getLogger(Alert.class);
32
33     private final AlertConfig alertConfig;
34     private final AlertSource source;
35     private final List JavaDoc deliveries;
36
37     public Alert(AlertConfig alertConfig){
38         assert alertConfig != null;
39         this.alertConfig = alertConfig;
40         this.source = AlertSourceFactory.getAlertSource(
41                 alertConfig.getAlertSourceConfig());
42         this.deliveries = AlertDeliveryFactory.getAlertDeliveries(alertConfig);
43     }
44
45     public void register(){
46         source.register(this, alertConfig.getAlertId(), alertConfig.getAlertName());
47     }
48
49     public void unregister(){
50         source.unregister();
51     }
52
53     public void handle(AlertInfo alertInfo) {
54         alertInfo.setAlertConfig(this.alertConfig);
55         for(Iterator JavaDoc it=deliveries.iterator(); it.hasNext(); ){
56             try {
57                 AlertDelivery delivery = (AlertDelivery)it.next();
58                 delivery.deliver(alertInfo);
59             } catch (Exception JavaDoc e) {
60                 logger.log(Level.SEVERE, "Error while deliverying alert", e);
61                 // continue deliverying thru other modes (if any)
62
}
63         }
64     }
65
66     public int hashCode(){
67         return alertConfig.getAlertId().hashCode();
68     }
69
70     public boolean equals(Object JavaDoc obj){
71         if(obj != null && obj instanceof Alert){
72             Alert alert = (Alert)obj;
73             return alert.alertConfig.getAlertId().equals(
74                     alertConfig.getAlertId());
75         }
76         return false;
77     }
78 }
79
Popular Tags