KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > config > ApplicationConfig


1 /**
2  * Copyright 2004-2005 jManage.org
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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.jmanage.core.config;
17
18
19 import java.util.*;
20
21 /**
22  *
23  * date: Jun 11, 2004
24  * @author Rakesh Kalra
25  */

26 public abstract class ApplicationConfig {
27
28     // jsr160 constants
29
public static final String JavaDoc JNDI_FACTORY = "java.naming.factory.initial";
30     public static final String JavaDoc JNDI_URL = "java.naming.provider.url";
31
32     private static final List EMPTY_LIST = new ArrayList();
33
34     public static String JavaDoc getNextApplicationId(){
35         //todo: Need something better
36
return String.valueOf(System.currentTimeMillis());
37     }
38
39     private String JavaDoc appId;
40     private String JavaDoc type;
41     private String JavaDoc name;
42     private String JavaDoc host;
43     private Integer JavaDoc port;
44     private String JavaDoc url;
45     private String JavaDoc username;
46     private String JavaDoc password;
47     protected Map paramValues;
48     private List mbeanList = new LinkedList();
49     private List graphList = new LinkedList();
50     // clusterConfig: if this is part of a cluster
51
private ApplicationConfig clusterConfig;
52     private List alertsList = new LinkedList();
53
54     public String JavaDoc getApplicationId(){
55         return appId;
56     }
57
58     public void setApplicationId(String JavaDoc appId){
59         assert this.appId == null;
60         this.appId = appId;
61     }
62
63     /**
64      * @return type of application
65      */

66     public String JavaDoc getType(){
67         return type;
68     }
69
70     public void setType(String JavaDoc type){
71         assert this.type == null;
72         this.type = type;
73     }
74
75     /**
76      * @return the name of the application
77      */

78     public String JavaDoc getName() {
79         return name;
80     }
81
82     public void setName(String JavaDoc name) {
83         this.name = name;
84     }
85
86     public String JavaDoc getHost() {
87         return host;
88     }
89
90     public void setHost(String JavaDoc host) {
91         this.host = host;
92     }
93
94     public Integer JavaDoc getPort() {
95         return port;
96     }
97
98     public void setPort(Integer JavaDoc port) {
99         this.port = port;
100     }
101
102     public String JavaDoc getURL() {
103         if(url == null){
104             return host + ":" + port;
105         }
106         return url;
107     }
108
109     public void setURL(String JavaDoc url) {
110         this.url = url;
111     }
112
113     public String JavaDoc getUsername() {
114         return username;
115     }
116
117     public void setUsername(String JavaDoc username) {
118         this.username = username;
119     }
120
121     public String JavaDoc getPassword() {
122         return password;
123     }
124
125     public void setPassword(String JavaDoc password) {
126         this.password = password;
127     }
128
129     /**
130      * If there are no additional parameters, the returned list is empty
131      *
132      * @return list of additional configuration parameters(ConfigParam objects)
133      */

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     /**
149      * @return true: if its a application cluster; false: otherwise
150      */

151     public boolean isCluster(){
152         return false;
153     }
154
155     /**
156      * If this is a application cluster, this method returns a list of
157      * applications in this cluster.
158      *
159      * @return list of applications in this cluster
160      */

161     public List getApplications(){
162         return null;
163     }
164
165     /**
166      * @return list of MBeanConfig objects
167      */

168     public List getMBeans(){
169         return mbeanList;
170     }
171
172     /**
173      *
174      * @param mbeanList list of MBeanConfig objects
175      */

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 JavaDoc 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 JavaDoc toString(){
197         return getApplicationId() + ";" + getName() + ";" + getURL();
198     }
199
200     public MBeanConfig removeMBean(String JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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 JavaDoc 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     /**
292      * @return list of AlertConfig objects
293      */

294    public List getAlerts(){
295        return alertsList;
296    }
297    /**
298     *
299     * @param alertsList list of MBeanConfig objects
300     */

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 JavaDoc 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 JavaDoc 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 JavaDoc 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