KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > DeploymentManagerProperties


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * DeploymentManagerProperties.java
21  *
22  * Created on January 5, 2004, 3:47 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.ide.j2ee;
26 import java.io.File JavaDoc;
27 import java.net.MalformedURLException JavaDoc;
28 import java.net.URL JavaDoc;
29 import java.util.ArrayList JavaDoc;
30 import java.util.List JavaDoc;
31 import org.netbeans.modules.j2ee.deployment.common.api.J2eeLibraryTypeProvider;
32 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
33 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceCreationException;
34
35 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
36 import org.netbeans.modules.j2ee.sun.api.Asenv;
37 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
38 import org.netbeans.modules.j2ee.sun.api.SunURIManager;
39 import org.netbeans.modules.j2ee.sun.ide.j2ee.ui.CustomizerSupport;
40 import org.netbeans.spi.project.libraries.LibraryImplementation;
41 import org.openide.ErrorManager;
42 import org.openide.filesystems.FileUtil;
43 import org.openide.modules.InstalledFileLocator;
44
45 /**
46  *
47  * @author ludo
48  */

49 public class DeploymentManagerProperties {
50     /**
51      * Domain property,
52      */

53     public static final String JavaDoc DOMAIN_ATTR = "DOMAIN"; //NOI18N
54

55     /**
56      * HTTP Monitor on or off property, its value is jsut before starting the server with the correct setting.
57      */

58     public static final String JavaDoc HTTP_MONITOR_ATTR = "HttpMonitorOn"; //NOI18N
59

60     /**
61      * HTTP Proxy sync up with IDE setting: on or off property, its value is just before starting the server with the correct setting.
62      */

63     public static final String JavaDoc HTTP_PROXY_SYNCHED_ATTR = "HttpProxySynced"; //NOI18N
64

65     /**
66      * directory deployment possible on or off property, .
67      */

68     public static final String JavaDoc DIRDEPLOYMENT_POSSIBLE_ATTR = "DirectoryDeploymentPossible"; //NOI18N
69
/**
70      * Password property, its value is used by the deployment manager.
71      */

72     public static final String JavaDoc PASSWORD_ATTR = "password"; //NOI18N
73

74     /**
75      * Display name property, its value is used by IDE to represent server instance.
76      */

77     public static final String JavaDoc DISPLAY_NAME_ATTR = "displayName"; //NOI18N
78
/**
79      * Location of the app server instance property, its value is used by IDE to represent server instance.
80      */

81     public static final String JavaDoc LOCATION_ATTR = "LOCATION"; //NOI18N
82

83     
84     /**
85      * HTTP port property, The port where the instance runs
86      */

87     public static final String JavaDoc HTTP_PORT_NUMBER_ATTR = "httpportnumber";
88     
89     /* AVK Instrumentation on or off
90      *
91      **/

92     public static final String JavaDoc AVK_INSTRUMENTED_ATTR = "AVKTurnedOn";
93     
94     private static final String JavaDoc PROP_SOURCES = "sources"; // NOI18N
95
private static final String JavaDoc PROP_JAVADOCS = "javadocs"; // NOI18N
96

97     private InstanceProperties instanceProperties;
98     private SunDeploymentManagerInterface SunDM;
99     
100     /** Creates a new instance of DeploymentManagerProperties */
101     public DeploymentManagerProperties(DeploymentManager JavaDoc deploymentManager) {
102         SunDM = (SunDeploymentManagerInterface)deploymentManager;
103         instanceProperties = SunURIManager.getInstanceProperties(SunDM.getPlatformRoot(),SunDM.getHost(),SunDM.getPort());
104         String JavaDoc httpport = SunDM.getNonAdminPortNumber();
105         if (httpport==null){
106             httpport ="8080";//hard code //NOI18N
107
}
108         if (instanceProperties==null){
109             try {
110                 
111                 instanceProperties = SunURIManager.createInstanceProperties(SunDM.getPlatformRoot(),SunDM.getHost(),""+SunDM.getPort(), SunDM.getUserName(),SunDM.getPassword() , SunDM.getHost()+":"+SunDM.getPort() );
112                 setHttpPortNumber( httpport);
113                 
114                 
115             } catch (InstanceCreationException e){
116                 
117             }
118         }
119         if (instanceProperties.getProperty(HTTP_PORT_NUMBER_ATTR)==null){
120             instanceProperties.setProperty(HTTP_PORT_NUMBER_ATTR, httpport);
121             
122         }
123     }
124     
125     /** Creates a new instance of DeploymentManagerProperties via a URI for deployment MAnager */
126 // public DeploymentManagerProperties(String uri) {
127
// instanceProperties = InstanceProperties.getInstanceProperties(uri);
128
//
129
// }
130
/**
131      * Getter for property domainName. Should never be null
132      * @return Value of property domainName.
133      */

134     public java.lang.String JavaDoc getDomainName() {
135         String JavaDoc retVal = ""; //NOI18N
136
if (instanceProperties==null){
137             return retVal;
138         }
139         retVal = instanceProperties.getProperty(DOMAIN_ATTR) ;
140         if (null == retVal || (retVal.trim().length() == 0)) {
141             retVal = ""; //NOI18N
142
}
143         return retVal;
144     }
145     
146     /**
147      * Setter for property domainName.
148      * @param domainName New value of property domainName.
149      */

150     public void setDomainName(java.lang.String JavaDoc domainName) {
151         instanceProperties.setProperty(DOMAIN_ATTR, domainName);
152     }
153     
154     /**
155      * Getter for property location. can be null if the dm is remote
156      * @return Value of property location.
157      */

158     public java.lang.String JavaDoc getLocation() {
159         java.io.File JavaDoc irf = SunDM.getPlatformRoot();
160         String JavaDoc installRoot = null;
161         if (null != irf && irf.exists()){
162             installRoot = irf.getAbsolutePath();
163         }
164         if (instanceProperties==null){
165             return installRoot;
166         }
167         String JavaDoc ret= instanceProperties.getProperty(LOCATION_ATTR) ;
168         if (ret==null){
169             return installRoot;
170         }
171         if (ret.equals( installRoot )){
172             //upgrade from previous semantic of this field in EA2: it was the app server location
173
//not the domain location...
174
String JavaDoc ext = (File.separatorChar == '/' ? "conf" : "bat"); // NOI18N
175
File JavaDoc asenv = new File JavaDoc(installRoot,"config/asenv."+ext); // NOI18N
176
Asenv asenvContent = new Asenv(asenv);
177             String JavaDoc defDomainsDirName = asenvContent.get(Asenv.AS_DEF_DOMAINS_PATH);
178             ret = defDomainsDirName;
179 // ret = ret +File.separator+"domains";
180
instanceProperties.setProperty(LOCATION_ATTR, ret);
181             
182         }
183         return ret;
184     }
185     
186     /**
187      * Setter for property location.
188      * @param location New value of property location.
189      */

190     public void setLocation(java.lang.String JavaDoc location) {
191         if (instanceProperties==null){
192             return;
193         }
194         instanceProperties.setProperty(LOCATION_ATTR, location);
195     }
196     
197     /**
198      * Getter for property password. can be null if the DM is a disconnected DM
199      * @return Value of property password.
200      */

201     public java.lang.String JavaDoc getPassword() {
202         if (instanceProperties==null){
203             return null;
204         }
205         return instanceProperties.getProperty(InstanceProperties.PASSWORD_ATTR) ;
206     }
207     
208     /**
209      * Setter for property password.
210      * @param password New value of property password.
211      */

212     public void setPassword(java.lang.String JavaDoc password) {
213         instanceProperties.setProperty(InstanceProperties.PASSWORD_ATTR, password);
214         
215     }
216     
217     /**
218      * Getter for property port.
219      * @return Value of property port.
220      */

221     // public int getPort() {
222
// return 0;
223
// }
224

225     /**
226      * Setter for property port.
227      * @param port New value of property port.
228      */

229     // public void setPort(int port) {
230
// }
231

232     /**
233      * Getter for property UserName. can be null for a disconnected DM.
234      * @return Value of property UserName.
235      */

236     public java.lang.String JavaDoc getUserName() {
237         if (instanceProperties==null){
238             return null;
239         }
240         return instanceProperties.getProperty(InstanceProperties.USERNAME_ATTR) ;
241     }
242     
243     /**
244      * Setter for property UserName.
245      * @param UserName New value of property UserName.
246      */

247     public void setUserName(java.lang.String JavaDoc UserName) {
248         instanceProperties.setProperty(InstanceProperties.USERNAME_ATTR, UserName);
249         
250     }
251     
252     public String JavaDoc getHttpMonitorOn() {
253         if (instanceProperties==null){
254             return "false";
255         }
256         String JavaDoc s = instanceProperties.getProperty(HTTP_MONITOR_ATTR);
257         if (s==null){
258             return "false";
259         }
260         
261         return s;
262     }
263     
264     public void setHttpMonitorOn(String JavaDoc HttpMonitorOn) {
265         instanceProperties.setProperty(HTTP_MONITOR_ATTR, HttpMonitorOn);
266     }
267     public String JavaDoc getHttpPortNumber() {
268         if (instanceProperties==null){
269             return "8080";
270         }
271         return instanceProperties.getProperty(HTTP_PORT_NUMBER_ATTR) ;
272     }
273     
274     public void setHttpPortNumber(String JavaDoc port) {
275         instanceProperties.setProperty(HTTP_PORT_NUMBER_ATTR, port);
276     }
277     
278     public String JavaDoc getDisplayName() {
279         if (instanceProperties == null) {
280             return null;
281         }
282         return instanceProperties.getProperty(InstanceProperties.DISPLAY_NAME_ATTR);
283     }
284     
285     public String JavaDoc getUrl() {
286         if (instanceProperties == null) {
287             return null;
288         }
289         return instanceProperties.getProperty(InstanceProperties.URL_ATTR);
290     }
291     
292     public InstanceProperties getInstanceProperties() {
293         return instanceProperties;
294     }
295     
296     
297     public boolean getAVKOn() {
298         if (instanceProperties == null){
299             return false;
300         }
301         String JavaDoc s = instanceProperties.getProperty(AVK_INSTRUMENTED_ATTR);
302         if (s == null){
303             return false;
304         }
305         return Boolean.valueOf(s).booleanValue();
306     }
307     
308     public void setAVKOn(boolean AVKOn) {
309         instanceProperties.setProperty(AVK_INSTRUMENTED_ATTR, Boolean.toString(AVKOn));
310     }
311
312     public void setJavadocs(List JavaDoc<URL JavaDoc> path) {
313         instanceProperties.setProperty(PROP_JAVADOCS, CustomizerSupport.buildPath(path));
314         PlatformImpl platform = (PlatformImpl) new PlatformFactory().getJ2eePlatformImpl((DeploymentManager JavaDoc) SunDM);
315         platform.notifyLibrariesChanged();
316     }
317
318     public void setSources(List JavaDoc<URL JavaDoc> path) {
319         instanceProperties.setProperty(PROP_SOURCES, CustomizerSupport.buildPath(path));
320         PlatformImpl platform = (PlatformImpl) new PlatformFactory().getJ2eePlatformImpl((DeploymentManager JavaDoc) SunDM);
321         platform.notifyLibrariesChanged();
322     }
323
324     public List JavaDoc<URL JavaDoc> getClasses() {
325         List JavaDoc data = new ArrayList JavaDoc();
326         PlatformImpl platform = (PlatformImpl) new PlatformFactory().getJ2eePlatformImpl((DeploymentManager JavaDoc) SunDM);
327         for (LibraryImplementation libImpl : platform.getLibraries()) {
328             data.addAll(libImpl.getContent(J2eeLibraryTypeProvider.VOLUME_TYPE_CLASSPATH));
329         }
330         return data;
331     }
332
333     public List JavaDoc<URL JavaDoc> getSources() {
334         String JavaDoc path = instanceProperties.getProperty(PROP_SOURCES);
335         if (path == null) {
336             return new ArrayList JavaDoc();
337         }
338         return CustomizerSupport.tokenizePath(path);
339     }
340
341     public List JavaDoc<URL JavaDoc> getJavadocs() {
342         String JavaDoc path = instanceProperties.getProperty(PROP_JAVADOCS);
343         if (path == null) {
344             ArrayList JavaDoc<URL JavaDoc> list = new ArrayList JavaDoc<URL JavaDoc>();
345             try {
346                 File JavaDoc j2eeDoc = InstalledFileLocator.getDefault().locate("docs/javaee5-doc-api.zip", null, false); // NOI18N
347
if (j2eeDoc != null) {
348                     list.add(fileToUrl(j2eeDoc));
349                 }
350             } catch (MalformedURLException JavaDoc e) {
351                 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e);
352             }
353             return list;
354         }
355         return CustomizerSupport.tokenizePath(path);
356     }
357     
358     /** Return URL representation of the specified file. */
359     private static URL JavaDoc fileToUrl(File JavaDoc file) throws MalformedURLException JavaDoc {
360         URL JavaDoc url = file.toURI().toURL();
361         if (FileUtil.isArchiveFile(url)) {
362             url = FileUtil.getArchiveRoot(url);
363         }
364         return url;
365     }
366     
367     /*
368      * return true is the IDE needs to sync up this instance with the same proxies as the IDE
369      * true by default
370      **/

371         public boolean isSyncHttpProxyOn() {
372         if (instanceProperties == null){
373             return true;//true by default
374
}
375         String JavaDoc s = instanceProperties.getProperty(HTTP_PROXY_SYNCHED_ATTR);
376         if (s == null){
377             return true;//true by default
378
}
379         return Boolean.valueOf(s).booleanValue();
380     }
381     
382     public void setSyncHttpProxyOn(boolean syncHttpProxyOn) {
383         instanceProperties.setProperty(HTTP_PROXY_SYNCHED_ATTR, Boolean.toString(syncHttpProxyOn));
384     }
385     
386     /*
387      * return true is this instance can utilized directory deployment for Web Apps (for now)
388      * true by default
389      **/

390         public boolean isDirectoryDeploymentPossible() {
391         if (instanceProperties == null){
392             return true;//true by default
393
}
394         String JavaDoc s = instanceProperties.getProperty(DIRDEPLOYMENT_POSSIBLE_ATTR);
395         if (s == null){
396             return true;//true by default
397
}
398         return Boolean.valueOf(s).booleanValue();
399     }
400     
401     public void setDirectoryDeploymentPossible(boolean dirpossible) {
402         instanceProperties.setProperty(DIRDEPLOYMENT_POSSIBLE_ATTR, Boolean.toString(dirpossible));
403     }}
404
Popular Tags