KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > util > DeploymentProperties


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * DeploymentProperties.java
26  *
27  * Created on August 7, 2003, 10:15 PM
28  */

29
30 package com.sun.enterprise.deployment.util;
31
32 import java.util.Properties JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.Map JavaDoc;
36 import java.io.File JavaDoc;
37 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
38
39 /**
40  * This properties are used to transfer information between
41  * deployment clients and server
42  *
43  * @author Sandhya E
44  */

45 public class DeploymentProperties extends Properties JavaDoc {
46
47     // declare SUID for class versioning compatibility
48
// generated using pe build fcs-b50
49
// this value should stay the same for all
50
// 8.x releases
51
static final long serialVersionUID = -6891581813642829148L;
52
53     public DeploymentProperties() {
54         super();
55     }
56
57     // construct a DeploymentProperties using the props
58
// passe from client
59
public DeploymentProperties(Properties JavaDoc props) {
60         super();
61     putAll(props);
62     }
63     
64     // construct a DeploymentProperties using the map
65
// passed from client
66
// 1. For keys defined before AMX time, since different
67
// keys were defined in the DeploymentMgrMBean,
68
// we need to do conversion between the keys
69
// to keep backward compatibilities
70
// 2. For internal keys and the new keys defined after AMX
71
// time, we don't need to do any conversion
72
//
73
public DeploymentProperties(Map JavaDoc map) {
74         super();
75         if (map == null) {
76             return;
77         }
78         Properties JavaDoc props = new Properties JavaDoc();
79         for (Iterator JavaDoc itr = map.keySet().iterator(); itr.hasNext();) {
80             String JavaDoc mapKey = (String JavaDoc) itr.next();
81             String JavaDoc mapValue = (String JavaDoc) map.get(mapKey);
82             String JavaDoc propsKey = (String JavaDoc) keyMap.get(mapKey);
83             if (mapValue != null) {
84                 // for public keys, we need to convert
85
if (propsKey != null) {
86                     props.put(propsKey, mapValue);
87                 }
88                 // for internal keys and new keys, we just add it
89
// without conversion
90
else {
91                     props.put(mapKey, mapValue);
92                 }
93             }
94         }
95         putAll(props);
96     }
97
98     // Construct a map with the keys defined in DeploymentMgrMBean
99
// this is used when the ASAPI client convert the props
100
// from the client to a map to invoke DeploymentMgrMBean API
101
// 1. For keys defined before AMX time, since different
102
// keys were defined in the DeploymentMgrMBean,
103
// we need to do conversion between the keys
104
// to keep backward compatibilities
105
// 2. For internal keys and the new keys defined after AMX
106
// time, we don't need to do any conversion
107
//
108
public static Map JavaDoc propsToMap(Properties JavaDoc dProps) {
109         Map JavaDoc map = new HashMap JavaDoc();
110         if (dProps == null) {
111             return map;
112         }
113         for (Iterator JavaDoc itr = dProps.keySet().iterator(); itr.hasNext();) {
114             String JavaDoc propsKey = (String JavaDoc) itr.next();
115             String JavaDoc propsValue = (String JavaDoc) dProps.get(propsKey);
116             String JavaDoc mapKey = (String JavaDoc) keyMap.get(propsKey);
117             if (propsValue != null) {
118                 // for public keys, we need to convert
119
if (mapKey != null) {
120                     map.put(mapKey, propsValue);
121                 // for internal keys and new keys, we just add it
122
// without conversion
123
} else {
124                     map.put(propsKey, propsValue);
125                 }
126             }
127         }
128         return map;
129     }
130
131     /**
132      * This set of get and set for WSDL_TARGET_HINT is to enable back generate WSDL with the host and port info of the
133      * actual server target in case only one target has been specified by the client; Refer to bug ID 6157923 for more
134      * details
135      */

136     
137     public String JavaDoc getWsdlTargetHint() throws IllegalArgumentException JavaDoc {
138         return getProperty(WSDL_TARGET_HINT, null);
139     }
140     
141     public void setWsdlTargetHint(String JavaDoc target) {
142         if(target != null) {
143             setProperty(WSDL_TARGET_HINT, target);
144         }
145     }
146     
147     public String JavaDoc getTarget() throws IllegalArgumentException JavaDoc {
148         return getProperty(TARGET, null);
149     }
150     
151     public void setTarget(String JavaDoc target) {
152         if (target != null)
153             setProperty(TARGET, target);
154     }
155     
156     public boolean getRedeploy() {
157         return Boolean.valueOf(getProperty(REDEPLOY, DEFAULT_REDEPLOY)).booleanValue();
158     }
159
160     public void setRedeploy(boolean redeploy) {
161         setProperty(REDEPLOY, new Boolean JavaDoc(redeploy).toString());
162     }
163
164     public String JavaDoc getArchiveName() throws IllegalArgumentException JavaDoc{
165         return getProperty(ARCHIVE_NAME, null);
166     }
167     
168     public void setArchiveName(String JavaDoc archiveName) {
169         if(archiveName != null)
170             setProperty(ARCHIVE_NAME, archiveName);
171     }
172         
173     public boolean getForce() {
174         return Boolean.valueOf(getProperty(FORCE,DEFAULT_FORCE)).booleanValue();
175     }
176     
177     public void setForce(boolean force) {
178         setProperty(FORCE, new Boolean JavaDoc(force).toString());
179     }
180
181     public boolean getReload() {
182         return Boolean.valueOf(getProperty(RELOAD,DEFAULT_RELOAD)).booleanValue();
183     }
184
185     public void setReload(boolean reload) {
186         setProperty(RELOAD, new Boolean JavaDoc(reload).toString());
187     }
188
189     public boolean getCascade() {
190         return Boolean.valueOf(getProperty(CASCADE,DEFAULT_CASCADE)).booleanValue();
191     }
192     
193     public void setCascade(boolean cascade) {
194         setProperty(CASCADE, new Boolean JavaDoc(cascade).toString());
195     }
196     
197     public boolean getPrecompileJSP() {
198         return Boolean.valueOf(getProperty(PRECOMPILE_JSP,DEFAULT_PRECOMPILE_JSP)).booleanValue();
199     }
200     
201     public void setPrecompileJSP(boolean precompileJSP) {
202         setProperty(PRECOMPILE_JSP, new Boolean JavaDoc(precompileJSP).toString());
203     }
204     
205     public boolean getVerify() {
206         return Boolean.valueOf(getProperty(VERIFY,DEFAULT_VERIFY)).booleanValue();
207     }
208     
209     public void setVerify(boolean verify) {
210         setProperty(VERIFY, new Boolean JavaDoc(verify).toString());
211     }
212     
213     public String JavaDoc getVirtualServers() {
214         return getProperty(VIRTUAL_SERVERS , DEFAULT_VIRTUAL_SERVERS);
215     }
216     
217     public void setVirtualServers(String JavaDoc virtualServers) {
218         if(virtualServers != null)
219             setProperty(VIRTUAL_SERVERS, virtualServers);
220     }
221     
222     public boolean getEnable() {
223         return Boolean.valueOf(getProperty(ENABLE,DEFAULT_ENABLE)).booleanValue();
224     }
225     
226     public void setEnable(boolean enable) {
227         setProperty(ENABLE, new Boolean JavaDoc(enable).toString());
228     }
229     
230     public String JavaDoc getContextRoot() {
231         return getProperty(CONTEXT_ROOT, null);
232     }
233     
234     public void setContextRoot(String JavaDoc contextRoot) {
235         if(contextRoot != null)
236             setProperty(CONTEXT_ROOT, contextRoot);
237     }
238     
239     public String JavaDoc getName(String JavaDoc filePath) {
240         return getProperty(NAME, getDefaultComponentName(filePath));
241     }
242     
243     public void setName(String JavaDoc name) {
244         if(name != null)
245             setProperty(NAME, name);
246     }
247     
248     public String JavaDoc getDescription() {
249         return getProperty(DESCRIPTION, "");
250     }
251
252     public void setDescription(String JavaDoc description) {
253         if(description != null)
254             setProperty(DESCRIPTION, description);
255     }
256
257     public boolean getGenerateRMIStubs() {
258         return Boolean.valueOf(getProperty(GENERATE_RMI_STUBS,DEFAULT_GENERATE_RMI_STUBS)).booleanValue();
259     }
260
261     public void setGenerateRMIStubs(boolean generateRMIStubs ) {
262         setProperty(GENERATE_RMI_STUBS, new Boolean JavaDoc(generateRMIStubs).toString());
263     }
264
265     public boolean getAvailabilityEnabled() {
266         return Boolean.valueOf(getProperty(AVAILABILITY_ENABLED,DEFAULT_AVAILABILITY_ENABLED)).booleanValue();
267     }
268
269     public void setAvailabilityEnabled(boolean availabilityEnabled ) {
270         setProperty(AVAILABILITY_ENABLED, new Boolean JavaDoc(availabilityEnabled).toString());
271     }
272
273     public boolean getJavaWebStartEnabled() {
274         return Boolean.valueOf(getProperty(DEPLOY_OPTION_JAVA_WEB_START_ENABLED_KEY, DEFAULT_JAVA_WEB_START_ENABLED)).booleanValue();
275     }
276     
277     public void setJavaWebStartEnabled(boolean javaWebStartEnabled) {
278         setProperty(DEPLOY_OPTION_JAVA_WEB_START_ENABLED_KEY, new Boolean JavaDoc(javaWebStartEnabled).toString());
279     }
280
281     public String JavaDoc getLibraries() {
282         return getProperty(DEPLOY_OPTION_LIBRARIES_KEY, null );
283     }
284         
285     public void setLibraries(String JavaDoc libraries) {
286         if(libraries != null) {
287             setProperty(DEPLOY_OPTION_LIBRARIES_KEY, libraries);
288         }
289     }
290
291     public String JavaDoc getResourceAction() {
292         return getProperty(RESOURCE_ACTION, null );
293     }
294
295     public void setResourceAction(String JavaDoc resourceAction) {
296         if(resourceAction != null) {
297             setProperty(RESOURCE_ACTION, resourceAction);
298         }
299     }
300
301     public String JavaDoc getResourceTargetList() {
302         return getProperty(RESOURCE_TARGET_LIST, null );
303     }
304
305     public void setResourceTargetList(String JavaDoc resTargetList) {
306         if(resTargetList != null) {
307             setProperty(RESOURCE_TARGET_LIST, resTargetList);
308         }
309     }
310
311     public void setType(ModuleType JavaDoc type) {
312         if (type != null) {
313             setProperty(TYPE, String.valueOf(type.getValue()));
314         }
315     }
316
317     public ModuleType JavaDoc getType() {
318         String JavaDoc t = getProperty(TYPE, null);
319         if ( t != null ) {
320             return ModuleType.getModuleType((new Integer JavaDoc(t)).intValue());
321         }
322         return null;
323     }
324
325
326     public Properties JavaDoc getPropertiesForInvoke(){
327         return (Properties JavaDoc)this;
328     }
329     
330     public Properties JavaDoc prune() {
331         /*Properties propsCopy = props.clone();*/
332         remove(FORCE);
333         remove(RELOAD);
334         remove(CONTEXT_ROOT);
335         remove(PRECOMPILE_JSP);
336         remove(VERIFY);
337         remove(ENABLE);
338         remove(VIRTUAL_SERVERS);
339         remove(NAME);
340         remove(TYPE);
341         remove(ARCHIVE_NAME);
342         remove(CASCADE);
343         remove(REDEPLOY);
344         remove(GENERATE_RMI_STUBS);
345         remove(AVAILABILITY_ENABLED);
346         remove(DEPLOY_OPTION_JAVA_WEB_START_ENABLED_KEY);
347         remove(DEPLOY_OPTION_LIBRARIES_KEY);
348         remove(RESOURCE_ACTION);
349         remove(RESOURCE_TARGET_LIST);
350         return this;
351     }
352     
353     /////////////////////////////////////////////////////////////////////////
354
public String JavaDoc getDefaultContextRoot(String JavaDoc filePath) {
355         return getDefaultComponentName(filePath);
356     }
357     
358     private String JavaDoc getDefaultComponentName(String JavaDoc filePath) {
359         final String JavaDoc fileName = new File JavaDoc(filePath).getName();
360         int toIndex = fileName.lastIndexOf('.');
361         if (toIndex < 0) {
362             toIndex = fileName.length();
363         }
364         final String JavaDoc name = fileName.substring(0, toIndex);
365         //FIXME check for blank string
366
return name;
367     }
368
369     // This map is only used for public keys before AMX time,
370
// for keys after AMX time, no need to put in the table and
371
// do conversion.
372
// Initialize a key map which contains mapping for the keys
373
// defined in this file and DeploymentMgrMBean
374
// the mapping for both directions are contained
375
// for example for key A in DeploymentProperties and
376
// corresponding key B in DeploymentMgrMBean,
377
// the map contains both A->B and B->A
378
// will only work if A not equals to B
379
private static void initializeKeyMap() {
380         keyMap = new HashMap JavaDoc();
381         keyMap.put(REDEPLOY, DEPLOY_OPTION_REDEPLOY_KEY);
382         keyMap.put(DEPLOY_OPTION_REDEPLOY_KEY, REDEPLOY);
383         keyMap.put(FORCE, DEPLOY_OPTION_FORCE_KEY);
384         keyMap.put(DEPLOY_OPTION_FORCE_KEY, FORCE);
385         keyMap.put(CASCADE, DEPLOY_OPTION_CASCADE_KEY);
386         keyMap.put(DEPLOY_OPTION_CASCADE_KEY, CASCADE);
387         keyMap.put(VERIFY, DEPLOY_OPTION_VERIFY_KEY);
388         keyMap.put(DEPLOY_OPTION_VERIFY_KEY, VERIFY);
389         keyMap.put(VIRTUAL_SERVERS, DEPLOY_OPTION_VIRTUAL_SERVERS_KEY);
390         keyMap.put(DEPLOY_OPTION_VIRTUAL_SERVERS_KEY, VIRTUAL_SERVERS);
391         keyMap.put(PRECOMPILE_JSP, DEPLOY_OPTION_PRECOMPILE_JSP_KEY);
392         keyMap.put(DEPLOY_OPTION_PRECOMPILE_JSP_KEY, PRECOMPILE_JSP);
393         keyMap.put(ENABLE, DEPLOY_OPTION_ENABLE_KEY);
394         keyMap.put(DEPLOY_OPTION_ENABLE_KEY, ENABLE);
395         keyMap.put(CONTEXT_ROOT, DEPLOY_OPTION_CONTEXT_ROOT_KEY);
396         keyMap.put(DEPLOY_OPTION_CONTEXT_ROOT_KEY, CONTEXT_ROOT);
397         keyMap.put(NAME, DEPLOY_OPTION_NAME_KEY);
398         keyMap.put(DEPLOY_OPTION_NAME_KEY, NAME);
399         keyMap.put(DESCRIPTION, DEPLOY_OPTION_DESCRIPTION_KEY);
400         keyMap.put(DEPLOY_OPTION_DESCRIPTION_KEY, DESCRIPTION);
401         keyMap.put(GENERATE_RMI_STUBS, DEPLOY_OPTION_GENERATE_RMI_STUBS_KEY);
402         keyMap.put(DEPLOY_OPTION_GENERATE_RMI_STUBS_KEY, GENERATE_RMI_STUBS);
403         keyMap.put(AVAILABILITY_ENABLED, DEPLOY_OPTION_AVAILABILITY_ENABLED_KEY);
404         keyMap.put(DEPLOY_OPTION_AVAILABILITY_ENABLED_KEY, AVAILABILITY_ENABLED);
405     }
406
407     ////////////////////////////////////////////////
408
// list of properties from client to server
409
////////////////////////////////////////////////
410
public static final String JavaDoc WSDL_TARGET_HINT = "wsdlTargetHint";
411     public static final String JavaDoc TARGET = "target";
412     public static final String JavaDoc REDEPLOY = "redeploy";
413     public static final String JavaDoc DEFAULT_REDEPLOY = "false";
414     public static final String JavaDoc FORCE = "force";
415     public static final String JavaDoc DEFAULT_FORCE = "true";
416     public static final String JavaDoc RELOAD = "reload";
417     public static final String JavaDoc DEFAULT_RELOAD = "false";
418     public static final String JavaDoc CASCADE = "cascade";
419     public static final String JavaDoc DEFAULT_CASCADE = "false";
420     public static final String JavaDoc VERIFY = "verify";
421     public static final String JavaDoc DEFAULT_VERIFY = "false";
422     public static final String JavaDoc VIRTUAL_SERVERS = "virtualservers";
423     public static final String JavaDoc DEFAULT_VIRTUAL_SERVERS = null;
424     public static final String JavaDoc PRECOMPILE_JSP = "precompilejsp";
425     public static final String JavaDoc DEFAULT_PRECOMPILE_JSP = "false";
426     public static final String JavaDoc GENERATE_RMI_STUBS = "generatermistubs";
427     public static final String JavaDoc DEFAULT_GENERATE_RMI_STUBS= "false";
428     public static final String JavaDoc AVAILABILITY_ENABLED = "availabilityenabled";
429     public static final String JavaDoc DEFAULT_AVAILABILITY_ENABLED = "false";
430     public static final String JavaDoc ENABLE = "enable";
431     public static final String JavaDoc DEFAULT_ENABLE = "true";
432     public static final String JavaDoc CONTEXT_ROOT = "contextRoot";
433     public static final String JavaDoc ARCHIVE_NAME = "archiveName";
434     public static final String JavaDoc NAME = "name";
435     public static final String JavaDoc TYPE = "type";
436     public static final String JavaDoc DESCRIPTION = "description";
437     public static final String JavaDoc CLIENTJARREQUESTED = "clientJarRequested";
438     
439     ////////////////////////////////////////////////
440
// list of properties from server to client
441
////////////////////////////////////////////////
442
public static final String JavaDoc MODULE_ID = "moduleid";
443
444
445     // list of keys defined in DeploymentMgrMBean
446
public static final String JavaDoc KEY_PREFIX = "X-DeploymentMgr.";
447     public static final String JavaDoc DEPLOY_OPTION_REDEPLOY_KEY =
448         KEY_PREFIX + "Redeploy";
449     public static final String JavaDoc DEPLOY_OPTION_FORCE_KEY = KEY_PREFIX + "Force";
450     public static final String JavaDoc DEPLOY_OPTION_CASCADE_KEY = KEY_PREFIX + "Cascade";
451     public static final String JavaDoc DEPLOY_OPTION_VERIFY_KEY = KEY_PREFIX + "Verify";
452     public static final String JavaDoc DEPLOY_OPTION_VIRTUAL_SERVERS_KEY =
453         KEY_PREFIX + "VirtualServers";
454     public static final String JavaDoc DEPLOY_OPTION_PRECOMPILE_JSP_KEY =
455         KEY_PREFIX + "PrecompileJSP";
456     public static final String JavaDoc DEPLOY_OPTION_ENABLE_KEY = KEY_PREFIX + "Enable";
457     public static final String JavaDoc DEPLOY_OPTION_CONTEXT_ROOT_KEY =
458         KEY_PREFIX + "ContextRoot";
459     public static final String JavaDoc DEPLOY_OPTION_NAME_KEY = KEY_PREFIX + "Name";
460     public static final String JavaDoc DEPLOY_OPTION_DESCRIPTION_KEY =
461         KEY_PREFIX + "Description";
462     public static final String JavaDoc DEPLOY_OPTION_GENERATE_RMI_STUBS_KEY =
463         KEY_PREFIX + "GenerateRMIStubs";
464     public static final String JavaDoc DEPLOY_OPTION_AVAILABILITY_ENABLED_KEY =
465         KEY_PREFIX + "AvailabilityEnabled";
466
467
468     // here are the new keys after AMX time, no conversions needed
469
// for these keys
470
public static final String JavaDoc DEPLOY_OPTION_JAVA_WEB_START_ENABLED_KEY =
471         KEY_PREFIX + "JavaWebStartEnabled";
472     public static final String JavaDoc DEPLOY_OPTION_LIBRARIES_KEY =
473         KEY_PREFIX + "Libraries";
474     public static final String JavaDoc DEFAULT_JAVA_WEB_START_ENABLED = "true";
475
476     // resource constants
477
public static final String JavaDoc RESOURCE_ACTION = "resourceAction";
478     public static final String JavaDoc RESOURCE_TARGET_LIST = "resourceTargetList";
479
480     // possible values for resource action
481
public static final String JavaDoc RES_DEPLOYMENT = "resDeployment";
482     public static final String JavaDoc RES_CREATE_REF = "resCreateRef";
483     public static final String JavaDoc RES_DELETE_REF = "resDeleteRef";
484     public static final String JavaDoc RES_UNDEPLOYMENT = "resUndeployment";
485     public static final String JavaDoc RES_REDEPLOYMENT = "resRedeployment";
486     public static final String JavaDoc RES_NO_OP = "resNoOp";
487
488     static Map JavaDoc keyMap;
489
490     static {
491         initializeKeyMap();
492     }
493 }
494
Popular Tags