1 6 7 package com.quikj.application.web.oamp.plugin; 8 9 import com.quikj.server.web.*; 10 11 import java.util.*; 12 13 14 public class FeatureOAMPHandlerList 15 { 16 private FeatureOAMPHandlerList() 17 { 18 instance = this; 19 } 20 21 public static FeatureOAMPHandlerList Instance() 22 { 23 if (instance == null) 24 { 25 new FeatureOAMPHandlerList(); 26 } 27 28 return instance; 29 } 30 31 public synchronized void dispose() 32 { 33 Iterator i = featureList.values().iterator(); 34 while (i.hasNext() == true) 35 { 36 ((FeatureHandlerInterface) i.next()).dispose(); 37 } 38 39 featureList.clear(); 40 } 41 42 public synchronized boolean add(String feature_name, String class_name, PluginParameters parms, ClientParms client_parms) 43 { 44 try 45 { 46 if (featureList.get(new String (feature_name)) != null) 48 { 49 errorMessage = new String ("Could not add the application " 50 + class_name 51 + " to the list because the application with name " 52 + feature_name 53 + " is duplicate"); 54 return false; 55 } 56 57 Class app_class = Class.forName(class_name); 58 59 Class [] interfaces = app_class.getInterfaces(); 61 62 boolean found = false; 63 for (int i = 0; i < interfaces.length; i++) 64 { 65 if (interfaces[i].getName().equals("com.quikj.application.web.oamp.plugin.FeatureHandlerInterface") == true) 66 { 67 found = true; 68 break; 69 } 70 } 71 72 if (found == false) 73 { 74 errorMessage = new String ("Class " 75 + class_name 76 + " does not implement the com.quikj.application.web.oamp.plugin.FeatureHandlerInterface"); 77 return false; 78 } 79 80 com.quikj.application.web.oamp.plugin.FeatureHandlerInterface obj = null; 82 try 83 { 84 obj = (FeatureHandlerInterface)app_class.newInstance(); 85 } 86 catch (InstantiationException ex1) 87 { 88 errorMessage = new String ("InstantiationException : " + ex1.getMessage()); 89 return false; 90 } 91 catch (IllegalAccessException ex2) 92 { 93 errorMessage = new String ("IllegalAccessException : " + ex2.getMessage()); 94 return false; 95 } 96 97 if (obj.init(feature_name, parms, client_parms) == false) 99 { 100 return false; 102 } 103 104 obj.start(); 106 107 featureList.put(new String (feature_name), obj); 109 } 110 catch (ClassNotFoundException ex) 111 { 112 errorMessage = new String ("Class " 113 + class_name 114 + " not found"); 115 return false; 116 } 117 118 return true; 119 } 120 121 public void addItemToList (FeatureHandlerInterface item) 122 { 123 featureList.put(new String (item.getFeatureName()), item); 124 } 125 126 public synchronized boolean delete(String feature_name) 127 { 128 FeatureHandlerInterface obj = (FeatureHandlerInterface)featureList.get(new String (feature_name)); 129 130 if (obj == null) 131 { 132 errorMessage = new String ("Application with name " 133 + feature_name 134 + " not found in list"); 135 return false; 136 } 137 138 if (featureList.remove(new String (feature_name)) == null) 139 { 140 errorMessage = new String ("The application with name " 141 + feature_name 142 + " could not be removed from the list"); 143 } 144 145 obj.dispose(); 147 148 return true; 149 } 150 151 public synchronized FeatureHandlerInterface getHandler (String feature_name) 152 { 153 return ((FeatureHandlerInterface) featureList.get(new String (feature_name))); 154 } 155 156 public synchronized FeatureHandlerInterface[] getElements() 157 { 158 FeatureHandlerInterface[] temp = new FeatureHandlerInterface[featureList.size()]; 159 return ((FeatureHandlerInterface[]) (featureList.values().toArray(temp))); 160 } 161 162 public String getErrorMessage() 163 { 164 return errorMessage; 165 } 166 167 private String errorMessage = ""; 168 private Hashtable featureList = new Hashtable(); 169 private static FeatureOAMPHandlerList instance = null; 170 } | Popular Tags |