KickJava   Java API By Example, From Geeks To Geeks.

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


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.config.AlertDeliveryConstants;
18
19 import java.util.*;
20
21 /**
22  *
23  *
24  * Date: Jul 31, 2005
25  * @author Rakesh Kalra
26  */

27 public class AlertDeliveryFactory {
28
29     private static Map typeToAlertDeliveryMap = new HashMap();
30
31     static{
32         List deliveryTypes = AlertSystemConfig.getInstance().getDeliveryTypes();
33         for(Iterator it=deliveryTypes.iterator(); it.hasNext(); ){
34             AlertSystemConfig.DeliveryType deliveryType =
35                     (AlertSystemConfig.DeliveryType)it.next();
36             typeToAlertDeliveryMap.put(deliveryType.getType(),
37                     instantiate(deliveryType.getClassName()));
38         }
39     }
40
41     private static AlertDelivery instantiate(String JavaDoc className){
42         try {
43             Class JavaDoc clazz = Class.forName(className);
44             return (AlertDelivery)clazz.newInstance();
45         } catch (Exception JavaDoc e) {
46             throw new RuntimeException JavaDoc(e);
47         }
48     }
49
50     public static AlertDelivery getAlertDelivery(String JavaDoc deliveryType){
51
52         AlertDelivery delivery =
53                 (AlertDelivery)typeToAlertDeliveryMap.get(deliveryType);
54         if(delivery == null) {
55             throw new RuntimeException JavaDoc("Invalid deliveryType=" + deliveryType);
56         }
57         return delivery;
58     }
59
60     public static List getAlertDeliveries(AlertConfig alertConfig) {
61         String JavaDoc[] deliveryTypes = alertConfig.getAlertDelivery();
62         List deliveries = new ArrayList(deliveryTypes.length);
63         for(int i=0; i < deliveryTypes.length; i++){
64             deliveries.add(getAlertDelivery(deliveryTypes[i]));
65         }
66         return deliveries;
67     }
68 }
69
Popular Tags