1 16 package org.jmanage.core.config; 17 18 19 import java.util.*; 20 21 26 public abstract class ApplicationConfig { 27 28 public static final String JNDI_FACTORY = "java.naming.factory.initial"; 30 public static final String JNDI_URL = "java.naming.provider.url"; 31 32 private static final List EMPTY_LIST = new ArrayList(); 33 34 public static String getNextApplicationId(){ 35 return String.valueOf(System.currentTimeMillis()); 37 } 38 39 private String appId; 40 private String type; 41 private String name; 42 private String host; 43 private Integer port; 44 private String url; 45 private String username; 46 private String password; 47 protected Map paramValues; 48 private List mbeanList = new LinkedList(); 49 private List graphList = new LinkedList(); 50 private ApplicationConfig clusterConfig; 52 private List alertsList = new LinkedList(); 53 54 public String getApplicationId(){ 55 return appId; 56 } 57 58 public void setApplicationId(String appId){ 59 assert this.appId == null; 60 this.appId = appId; 61 } 62 63 66 public String getType(){ 67 return type; 68 } 69 70 public void setType(String type){ 71 assert this.type == null; 72 this.type = type; 73 } 74 75 78 public String getName() { 79 return name; 80 } 81 82 public void setName(String name) { 83 this.name = name; 84 } 85 86 public String getHost() { 87 return host; 88 } 89 90 public void setHost(String host) { 91 this.host = host; 92 } 93 94 public Integer getPort() { 95 return port; 96 } 97 98 public void setPort(Integer port) { 99 this.port = port; 100 } 101 102 public String getURL() { 103 if(url == null){ 104 return host + ":" + port; 105 } 106 return url; 107 } 108 109 public void setURL(String url) { 110 this.url = url; 111 } 112 113 public String getUsername() { 114 return username; 115 } 116 117 public void setUsername(String username) { 118 this.username = username; 119 } 120 121 public String getPassword() { 122 return password; 123 } 124 125 public void setPassword(String password) { 126 this.password = password; 127 } 128 129 134 public List getAdditionalParameters(){ 135 return EMPTY_LIST; 136 } 137 138 public Map getParamValues(){ 139 if(paramValues == null) 140 paramValues = new HashMap(); 141 return paramValues; 142 } 143 144 public void setParamValues(Map paramValues){ 145 this.paramValues = paramValues; 146 } 147 148 151 public boolean isCluster(){ 152 return false; 153 } 154 155 161 public List getApplications(){ 162 return null; 163 } 164 165 168 public List getMBeans(){ 169 return mbeanList; 170 } 171 172 176 public void setMBeans(List mbeanList){ 177 if(mbeanList != null){ 178 this.mbeanList = mbeanList; 179 }else{ 180 this.mbeanList = new LinkedList(); 181 } 182 } 183 184 public int hashCode(){ 185 return getApplicationId().hashCode(); 186 } 187 188 public boolean equals(Object obj){ 189 if(obj instanceof ApplicationConfig){ 190 ApplicationConfig config = (ApplicationConfig)obj; 191 return config.getApplicationId().equals(this.getApplicationId()); 192 } 193 return false; 194 } 195 196 public String toString(){ 197 return getApplicationId() + ";" + getName() + ";" + getURL(); 198 } 199 200 public MBeanConfig removeMBean(String objectName){ 201 202 for(Iterator it=mbeanList.iterator(); it.hasNext();){ 203 MBeanConfig mbeanConfig = (MBeanConfig)it.next(); 204 if(mbeanConfig.getObjectName().equals(objectName)){ 205 mbeanList.remove(mbeanConfig); 206 return mbeanConfig; 207 } 208 } 209 return null; 210 } 211 212 public void addMBean(MBeanConfig mbeanConfig){ 213 214 assert !containsMBean(mbeanConfig.getObjectName()); 215 mbeanList.add(mbeanConfig); 216 } 217 218 public ApplicationConfig getClusterConfig() { 219 return clusterConfig; 220 } 221 222 public void setClusterConfig(ApplicationConfig clusterConfig) { 223 this.clusterConfig = clusterConfig; 224 } 225 226 public MBeanConfig findMBean(String mbeanName) { 227 for(Iterator it=mbeanList.iterator(); it.hasNext();){ 228 MBeanConfig mbeanConfig = (MBeanConfig)it.next(); 229 if(mbeanConfig.getName().equals(mbeanName)){ 230 return mbeanConfig; 231 } 232 } 233 return null; 234 } 235 236 public MBeanConfig findMBeanByObjectName(String objectName){ 237 for(Iterator it=mbeanList.iterator(); it.hasNext();){ 238 MBeanConfig mbeanConfig = (MBeanConfig)it.next(); 239 if(mbeanConfig.getObjectName().equals(objectName)){ 240 return mbeanConfig; 241 } 242 } 243 return null; 244 } 245 246 public boolean containsMBean(String objectName) { 247 return findMBeanByObjectName(objectName) != null; 248 } 249 250 public void addGraph(GraphConfig graphConfig){ 251 assert graphConfig!=null:"graphConfig is null"; 252 graphList.add(graphConfig); 253 } 254 public void setGraphs(List graphList) { 255 if(graphList != null){ 256 this.graphList = graphList; 257 }else{ 258 this.graphList = new LinkedList(); 259 } 260 } 261 262 public List getGraphs(){ 263 return graphList; 264 } 265 266 public GraphConfig findGraph(String graphId) { 267 for(Iterator it=graphList.iterator(); it.hasNext(); ){ 268 GraphConfig graphConfig = (GraphConfig)it.next(); 269 if(graphConfig.getId().equals(graphId)){ 270 return graphConfig; 271 } 272 } 273 return null; 274 } 275 public GraphConfig removeGraph(String graphId){ 276 GraphConfig graphConfig = findGraph(graphId); 277 if(graphConfig!=null){ 278 graphList.remove(graphConfig); 279 return graphConfig; 280 } 281 return null; 282 } 283 284 285 286 public void addAlert(AlertConfig alertConfig){ 287 assert alertConfig!=null:"alert config is null"; 288 alertsList.add(alertConfig); 289 } 290 291 294 public List getAlerts(){ 295 return alertsList; 296 } 297 301 public void setAlerts(List alertsList){ 302 if(alertsList != null){ 303 this.alertsList = alertsList; 304 }else{ 305 this.alertsList = new LinkedList(); 306 } 307 } 308 309 public AlertConfig findAlertById(String alertId){ 310 AlertConfig alert = null; 311 for(Iterator itr=alertsList.iterator();itr.hasNext();){ 312 AlertConfig alertConfig = (AlertConfig)itr.next(); 313 if(alertConfig.getAlertId().equals(alertId)){ 314 alert = alertConfig; 315 break; 316 } 317 } 318 return alert; 319 } 320 321 public AlertConfig removeAlert(String alertId){ 322 AlertConfig alertConfig = findAlertById(alertId); 323 if(alertConfig!=null){ 324 alertsList.remove(alertConfig); 325 return alertConfig; 326 } 327 return null; 328 } 329 330 public ClassLoader getApplicationClassLoader(){ 331 ApplicationType appType = 332 ApplicationTypes.getApplicationType(getType()); 333 assert appType != null; 334 return appType.getClassLoader(); 335 } 336 337 public ApplicationType getApplicationType(){ 338 return ApplicationTypes.getApplicationType(getType()); 339 } 340 } 341 | Popular Tags |