KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > deployment > main > ServerManager


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 package com.sun.enterprise.tools.deployment.main;
24
25 import java.rmi.RemoteException JavaDoc;
26 import java.io.*;
27 import java.util.Hashtable JavaDoc;
28 import java.util.Vector JavaDoc;
29 import java.util.Enumeration JavaDoc;
30 import java.util.Properties JavaDoc;
31 import java.util.Set JavaDoc;
32 import java.net.*;
33
34 import org.omg.CORBA.ORB JavaDoc;
35 import javax.rmi.CORBA.Tie JavaDoc;
36 import javax.rmi.PortableRemoteObject JavaDoc;
37 import javax.naming.InitialContext JavaDoc;
38 import javax.naming.Context JavaDoc;
39
40 import com.sun.enterprise.util.NotificationListener;
41 import com.sun.enterprise.util.NotificationEvent;
42 import com.sun.enterprise.util.ORBManager;
43 import com.sun.ejb.sqlgen.DBInfo;
44
45 import com.sun.enterprise.tools.deployment.backend.JarInstaller;
46 import com.sun.enterprise.tools.deployment.backend.DeploymentSession;
47 import com.sun.enterprise.tools.deployment.backend.DeploymentSessionImpl;
48 import com.sun.enterprise.util.LocalStringManagerImpl;
49 import com.sun.enterprise.deployment.Application;
50 import com.sun.enterprise.deployment.Descriptor;
51 import com.sun.enterprise.resource.ConnectorInfo;
52 import com.sun.enterprise.resource.PoolingException;
53
54 //import com.sun.enterprise.tools.deployment.ui.UIUtils;
55

56 /** This is the class that handles connections to the J2EE server from
57 ** client tools.
58 ** @author Danny Coward
59 */

60
61 public class ServerManager
62 {
63     private static final String JavaDoc OMG_ORB_INIT_PORT_PROPERTY =
64     "org.omg.CORBA.ORBInitialPort"; // NOI18N
65
private static final String JavaDoc OMG_ORB_INIT_HOST_PROPERTY =
66     "org.omg.CORBA.ORBInitialHost"; // NOI18N
67
private static final String JavaDoc DEFAULT_ORB_INIT_HOST = "localhost"; // NOI18N
68
private static final String JavaDoc DEFAULT_ORB_INIT_PORT = "1050"; // NOI18N
69

70     /* -------------------------------------------------------------------------
71     ** Localization
72     */

73
74     private static LocalStringManagerImpl localStrings =
75         new LocalStringManagerImpl(ServerManager.class);
76
77     /* -------------------------------------------------------------------------
78     ** Notification types
79     */

80
81     /* generic type */
82     public static String JavaDoc NOTIFICATION_TYPE = "ServerManager"; // NOI18N
83

84     /** server listener added/removed */
85     public static String JavaDoc SERVER_LISTENER_ADDED = "serverListenerAdded"; // NOI18N
86
public static String JavaDoc SERVER_LISTENER_REMOVED = "serverListenerRemoved"; // NOI18N
87

88     /** server added/removed/selected */
89     public static String JavaDoc SERVER_ADDED = "addServer"; // NOI18N
90
public static String JavaDoc SERVER_REMOVED = "removeServer"; // NOI18N
91
public static String JavaDoc SERVER_SELECTED = "setCurrentServer"; // NOI18N
92

93     /** application delpoyed/undeployed */
94     public static String JavaDoc APP_DEPLOYED = "deployedApplication"; // NOI18N
95
public static String JavaDoc APP_UNDEPLOYED = "undeployedApplication"; // NOI18N
96
public static String JavaDoc SA_DEPLOYED = "deployedApplication"; // NOI18N
97
public static String JavaDoc SA_UNDEPLOYED = "undeployedStandAlone"; // NOI18N
98

99     /* -----
100     */

101
102     private static String JavaDoc LOCAL_SERVER = "local"; // NOI18N
103
/** "localhost";*/ // NOI18N
104

105     public static String JavaDoc SERVER_PROPERTY = "name"; // NOI18N
106

107     public static String JavaDoc LOCAL_HOST = "localhost"; // NOI18N
108
private static String JavaDoc SERVERS_FILENAME = "servers"; // NOI18N
109

110     private File preferencesDirectory;
111     private Vector JavaDoc listeners = new Vector JavaDoc();
112     private Hashtable JavaDoc serverNameToListenerMap = new Hashtable JavaDoc();
113     private String JavaDoc currentServer;
114     private Context JavaDoc initialContext;
115     
116     /** Construct a new server manager which restores and saves its state
117     ** to the given
118     * directory.*/

119     public ServerManager(File preferencesDirectory)
120     {
121     this.preferencesDirectory = preferencesDirectory;
122     }
123
124     /* -------------------------------------------------------------------------
125     ** Undeploy App & Deployed notification
126     */

127
128 // /** The undeploy method.*/
129
// public void uninstall(String appName, String serverName)
130
// throws ServerException
131
// {
132
// System.out.println("*** 'uninstall' is obsolete, please use 'undeployApplication' ***");
133
// Thread.dumpStack();
134
// this.undeployApplication(appName, serverName);
135
// }
136
//
137
// public void uninstall(Object appList[], String serverName)
138
// throws ServerException
139
// {
140
// System.out.println("*** 'uninstall' is obsolete, please use 'undeployApplication' ***");
141
// Thread.dumpStack();
142
// this.undeployApplication(appList, serverName);
143
// }
144

145     /** The undeploy method.*/
146     public void undeployApplication(String JavaDoc applicationName, String JavaDoc serverName)
147         throws ServerException
148     {
149     JarInstaller installer = this.getJarInstaller(serverName);
150     try {
151         installer.undeployApplication(applicationName);
152         this.changed(APP_UNDEPLOYED, applicationName);
153     } catch (Throwable JavaDoc t) {
154         throw new ServerException(localStrings.getLocalString(
155       "enterprise.tools.deployment.main.erroruninstallingapplicationfromserver",
156         "Error uninstalling {0} from {1}",
157                 new Object JavaDoc[] {applicationName, serverName}));
158     }
159     
160     }
161
162     public void undeployApplication(Object JavaDoc appList[], String JavaDoc serverName)
163         throws ServerException
164     {
165     for (int i = 0; i < appList.length; i++) {
166         if (appList[i] instanceof String JavaDoc) {
167             this.undeployApplication((String JavaDoc)appList[i], serverName);
168         } else {
169         // XXX this should never occur
170
}
171     }
172     }
173
174     /* called by DeploymentManager when an app has been successfully deployed */
175     public void deployedApplication(Application app)
176     {
177     this.changed(APP_DEPLOYED, app.getName());
178     }
179
180     /* -------------------------------------------------------------------------
181     ** Undeploy Connectors
182     */

183
184     public void undeployConnector(String JavaDoc rarName, String JavaDoc serverName)
185         throws ServerException
186     {
187     JarInstaller installer = this.getJarInstaller(serverName);
188     try {
189         installer.undeployConnector(rarName);
190         this.changed(SA_UNDEPLOYED, rarName);
191     } catch (Throwable JavaDoc t) {
192         throw new ServerException(localStrings.getLocalString(
193       "enterprise.tools.deployment.main.erroruninstallingapplicationfromserver",
194         "Error uninstalling {0} from {1}",
195                 new Object JavaDoc[] { rarName, serverName }));
196     }
197     }
198
199     public void undeployConnector(Object JavaDoc rarList[], String JavaDoc serverName)
200         throws ServerException
201     {
202     for (int i = 0; i < rarList.length; i++) {
203         if (rarList[i] instanceof String JavaDoc) {
204             this.undeployConnector((String JavaDoc)rarList[i], serverName);
205         } else {
206         // XXX this should never occur
207
}
208     }
209     }
210
211     /* called by DeploymentManager when an app has been successfully deployed */
212     public void deployedStandAlone(Descriptor desc)
213     {
214     this.changed(SA_DEPLOYED, desc.getName());
215     }
216
217     /* -------------------------------------------------------------------------
218     ** add/remove server
219     */

220
221     /** Connect to a new server by hostnamne*/
222     public void addServer(String JavaDoc serverName)
223     throws ServerException
224     {
225     JarInstaller jarInstaller = this.getJarInstaller(serverName);
226     if (serverNameToListenerMap.containsKey(serverName)) {
227         // already present
228
this.setCurrentServer(serverName);
229         this.changed(SERVER_SELECTED, serverName);
230     } else {
231         ServerListener serverListener = null;
232         try {
233         serverListener = this.createServerListener(serverName);
234         jarInstaller.addRemoteNotificationListener(serverListener);
235         } catch (Exception JavaDoc e) {
236         System.out.println(localStrings.getLocalString(
237                   "enterprise.tools.deployment.main.errorgettingserverlistener",
238           "Error getting server listener"));
239         }
240         serverNameToListenerMap.put(serverName, serverListener);
241         this.setCurrentServer(serverName);
242         this.changed(SERVER_ADDED, serverName);
243     }
244     }
245
246     /** Disconnect from new server by hostname*/
247     public void removeServer(String JavaDoc hostName)
248     {
249     if (serverNameToListenerMap.containsKey(hostName)) {
250         ServerListener serverListener =
251                 (ServerListener)serverNameToListenerMap.get(hostName);
252         try {
253         serverNameToListenerMap.remove(hostName);
254         if ((this.getCurrentServer() != null) &&
255                     this.getCurrentServer().equals(hostName)) {
256             this.currentServer = null;
257         }
258         this.changed(SERVER_REMOVED, hostName);
259         JarInstaller jarInstaller = this.getJarInstaller(hostName);
260         jarInstaller.removeRemoteNotificationListener(serverListener);
261         } catch (Exception JavaDoc e) {
262         // leave for debug
263
//System.out.println("Error removing notification listener from server");
264
}
265     }
266     }
267     
268     /** Return the name of the current server in this manager.*/
269     public String JavaDoc getCurrentServer()
270     {
271     if ((this.currentServer != null) &&
272             serverNameToListenerMap.containsKey(this.currentServer)) {
273         return currentServer;
274     }
275     return null;
276     }
277     
278     /** Set the name of the current server in this manager.*/
279     public void setCurrentServer(String JavaDoc serverName)
280     {
281     this.currentServer = serverName;
282     String JavaDoc notificationString = ""; // NOI18N
283
if (serverName != null) {
284         notificationString = serverName;
285     }
286     this.changed(SERVER_SELECTED, notificationString);
287     }
288     
289     
290     /** Returns a list of server names. */
291     public Vector JavaDoc getServerNames()
292     {
293     Vector JavaDoc v = new Vector JavaDoc();
294     for (Enumeration JavaDoc e = this.serverNameToListenerMap.keys();
295             e.hasMoreElements();) {
296         v.addElement(e.nextElement());
297     }
298     return v;
299     }
300
301     /* -------------------------------------------------------------------------
302     ** add/remove notification listeners
303     */

304     
305     /** add a notificationlistsner for server changes. */
306     public void addNotificationListener(NotificationListener nl)
307     {
308     listeners.addElement(nl);
309     this.changed(SERVER_LISTENER_ADDED, ""); // NOI18N
310
}
311     
312     /** removes a notificationlistsner for server changes. */
313     public void removeNotificationListener(NotificationListener nl)
314     {
315     this.listeners.removeElement(nl);
316     this.changed(SERVER_LISTENER_REMOVED, ""); // NOI18N
317
}
318     
319     /** Force an update of listeners.*/
320     protected void changed()
321     {
322     Vector JavaDoc listenersClone = null;
323     synchronized (listeners) {
324         listenersClone = (Vector JavaDoc)listeners.clone();
325     }
326     for (Enumeration JavaDoc e = listenersClone.elements(); e.hasMoreElements();) {
327         NotificationListener nl = (NotificationListener) e.nextElement();
328         nl.notification(new NotificationEvent(this, NOTIFICATION_TYPE));
329     }
330     }
331     
332     protected void changed(String JavaDoc type, String JavaDoc name)
333     {
334     Vector JavaDoc listenersClone = null;
335     synchronized (listeners) {
336         listenersClone = (Vector JavaDoc)listeners.clone();
337     }
338     NotificationEvent event = new NotificationEvent(this, type,
339             SERVER_PROPERTY, name);
340     for (Enumeration JavaDoc e = listenersClone.elements(); e.hasMoreElements();) {
341         NotificationListener nl = (NotificationListener) e.nextElement();
342         nl.notification(event);
343     }
344     
345     }
346
347     /* -------------------------------------------------------------------------
348     ** support fo application deployment
349     */

350
351    /**
352     * Creates a Session object for listening to and managing deployment
353     * progress reports.
354     */

355     public DeploymentSession createDeploymentSession(String JavaDoc serverName)
356         throws Exception JavaDoc
357     {
358     try {
359         DeploymentSession ds = new DeploymentSessionImpl();
360         PortableRemoteObject.exportObject(ds);
361         Tie JavaDoc servantsTie = javax.rmi.CORBA.Util.getTie(ds);
362         servantsTie.orb(ORBManager.getORB());
363         return ds;
364     } catch (Throwable JavaDoc t) {
365         throw new ServerException(localStrings.getLocalString(
366         "enterprise.tools.deployment.main.couldnotgetorbforserver",
367         "Couldn't get orb for ({0}) {1}",
368                 new Object JavaDoc[] {"createDeploymentSession",serverName})); // NOI18N
369
}
370     }
371     
372     private ServerListener createServerListener(String JavaDoc serverName)
373         throws Exception JavaDoc
374     {
375     try {
376         ServerListener listener = new ServerListener(this);
377         PortableRemoteObject.exportObject(listener);
378         Tie JavaDoc servantsTie = javax.rmi.CORBA.Util.getTie(listener);
379         servantsTie.orb(ORBManager.getORB());
380         return listener;
381     } catch (Throwable JavaDoc t) {
382         throw new ServerException(localStrings.getLocalString(
383         "enterprise.tools.deployment.main.couldnotgetorbforserver",
384         "Couldn't get orb for ({0}) {1}",
385         new Object JavaDoc[] {"createCallBack", serverName})); // NOI18N
386
}
387     
388     
389     }
390     
391     public boolean isInstalled(String JavaDoc applicationName, String JavaDoc serverName)
392     throws ServerException
393     {
394     JarInstaller installer = this.getJarInstaller(serverName);
395     if (installer != null) {
396         try {
397         Vector JavaDoc applicationNames = installer.getApplicationNames();
398         for (int i = 0; i < applicationNames.size(); i++) {
399             if (applicationName.equals(applicationNames.elementAt(i))) {
400             return true;
401             }
402         }
403         } catch (Throwable JavaDoc t) {
404         throw new ServerException(localStrings.getLocalString(
405        "enterprise.tools.deployment.main.couldnotapplicationlistfromserver",
406             "Couldn't get application list from {0}",
407             new Object JavaDoc[] {serverName}));
408         }
409     }
410     return false;
411     }
412     
413     /**
414      * Return a vector of application names.
415      */

416
417      public Vector JavaDoc getApplicationNamesForServer(String JavaDoc serverName)
418          throws ServerException
419      {
420     Vector JavaDoc v = null;
421     if (serverName == null) {
422         return v;
423     }
424     JarInstaller installer = this.getJarInstaller(serverName);
425     if (installer != null) {
426         try {
427         v = installer.getApplicationNames();
428         } catch (RemoteException JavaDoc re) {
429         throw new ServerException(localStrings.getLocalString(
430      "enterprise.tools.deployment.main.errorgettingappnamefromserverwithreason",
431             "Error obtaining application names from {0} \n reason {1}",
432                     new Object JavaDoc[] {serverName,re.getMessage()}));
433         }
434     }
435     return v;
436      }
437
438      public Vector JavaDoc getApplicationNames()
439          throws ServerException
440      {
441         return this.getApplicationNamesForServer(getCurrentServer());
442      }
443     
444     /**
445      * Return a vector of connector names.
446      */

447
448     public Vector JavaDoc getConnectorNamesForServer(String JavaDoc serverName)
449     throws ServerException
450     {
451     Vector JavaDoc v = null;
452     if (serverName != null) {
453         JarInstaller installer = this.getJarInstaller(serverName);
454         if (installer != null) {
455             try {
456             v = new Vector JavaDoc();
457                 ConnectorInfo ci = installer.listConnectors();
458                 for (int i = 0; i < ci.connectors.length; i++) {
459                 v.add(ci.connectors[i].toString());
460                     }
461             } catch (Exception JavaDoc re) {
462             throw new ServerException(
463             localStrings.getLocalString(
464      "enterprise.tools.deployment.main.errorgettingappnamefromserverwithreason",
465             "Error obtaining application names from {0} \n reason {1}",
466                     new Object JavaDoc[] { serverName, re.toString() }));
467             }
468         }
469     }
470     return v;
471     }
472
473     public Vector JavaDoc getConnectorNames()
474     throws ServerException
475     {
476         return this.getConnectorNamesForServer(getCurrentServer());
477     }
478     
479     /**
480      * Return a vector of connection-factory names.
481      */

482
483     public Vector JavaDoc getConnectionFactoriesForServer(String JavaDoc serverName)
484     throws ServerException
485     {
486     Vector JavaDoc v = null;
487     if (serverName != null) {
488         JarInstaller installer = this.getJarInstaller(serverName);
489         if (installer != null) {
490             try {
491             v = new Vector JavaDoc();
492                 ConnectorInfo ci = installer.listConnectors();
493                 for (int i = 0; i < ci.connectionFactories.length; i++) {
494                 v.add(ci.connectionFactories[i].toString());
495                     }
496             } catch (Exception JavaDoc re) {
497             throw new ServerException(localStrings.getLocalString(
498      "enterprise.tools.deployment.main.errorgettingappnamefromserverwithreason",
499             "Error obtaining application names from {0} \n reason {1}",
500                     new Object JavaDoc[] { serverName, re.toString() }));
501             }
502         }
503     }
504     return v;
505     }
506
507     public Vector JavaDoc getConnectionFactories()
508          throws ServerException
509     {
510         return this.getConnectionFactoriesForServer(getCurrentServer());
511     }
512
513     /**
514      * Return a set of EnvironmentProperties that represents
515      * the configuration properties of a connection factory
516      * @param AppName Name of application (can be null if the adapter
517      * is deployed standalone)
518      * @param connectorName Name of resource adapter
519      */

520     public Set JavaDoc getConnectionFactoryPropertyTemplate(String JavaDoc appName,
521                                                     String JavaDoc connectorName)
522         throws RemoteException JavaDoc, PoolingException, ServerException {
523
524         String JavaDoc serverName = getCurrentServer();
525         JarInstaller installer = this.getJarInstaller(serverName);
526         return installer.getConnectionFactoryPropertyTemplate
527             (appName, connectorName);
528     }
529
530
531
532     public void addConnectionFactory(String JavaDoc appName,
533                                      String JavaDoc connectorName,
534                                      String JavaDoc jndiName,
535                                      String JavaDoc xaRecoveryUser,
536                                      String JavaDoc xaRecoveryPassword,
537                                      Properties JavaDoc props)
538         throws RemoteException JavaDoc, PoolingException, ServerException {
539
540         String JavaDoc serverName = getCurrentServer();
541         JarInstaller installer = this.getJarInstaller(serverName);
542         installer.addConnectionFactory(appName, connectorName,
543                                        jndiName, xaRecoveryUser,
544                                        xaRecoveryPassword, props);
545     }
546
547     public void removeConnectionFactory(String JavaDoc jndiName)
548         throws RemoteException JavaDoc, PoolingException, ServerException {
549
550         String JavaDoc serverName = getCurrentServer();
551         JarInstaller installer = this.getJarInstaller(serverName);
552         installer.removeConnectionFactory(jndiName);
553     }
554
555     public Set JavaDoc listConnectorResources()
556         throws RemoteException JavaDoc, ServerException {
557         String JavaDoc serverName = getCurrentServer();
558         JarInstaller installer = this.getJarInstaller(serverName);
559         Set JavaDoc res = installer.listConnectorResources();
560         return res;
561     }
562
563     /**
564      * Return a server by name. return null if there is no server of that
565      * name.
566      */

567     public JarInstaller getServerForName(String JavaDoc serverName)
568     throws ServerException
569     {
570     return this.getJarInstaller(serverName);
571     }
572
573     private JarInstaller getJarInstaller(String JavaDoc serverName)
574     throws ServerException
575     {
576     try {
577         if ( serverName.equalsIgnoreCase("local") ) // NOI18N
578
serverName = "localhost"; // NOI18N
579

580             String JavaDoc initialPort = System.getProperty(OMG_ORB_INIT_PORT_PROPERTY);
581             if (initialPort == null)
582                 initialPort = String.valueOf(ORBManager.getORBInitialPort());
583
584             String JavaDoc corbaName = "corbaname:iiop:" + serverName + ":" + // NOI18N
585
initialPort + "#" + JarInstaller.JNDI_NAME; // NOI18N
586

587             /* IASRI 4691307 commented out by Anissa.
588              * The following code throws exception from the ORBManager and since we don't need any server
589              * connection for AT, we will not perform this step.
590              *
591             Object objref = getIC().lookup(corbaName);
592             Object o = PortableRemoteObject.narrow(objref, JarInstaller.class);
593         JarInstaller installer = (JarInstaller) o;
594         return installer;
595             * end of IASRI 4691307
596              */

597             
598         throw new ServerException(""); //NOI18N
599

600     } catch (Throwable JavaDoc t) {
601         String JavaDoc msg = localStrings.getLocalString(
602         "enterprise.tools.deployment.main.couldnotconnecttoserver",
603                 "Couldn''t connect to {0}",
604         new Object JavaDoc[] { serverName });
605         //System.err.println(msg); // IASRI 4691307
606
//UIUtils.printException(msg, t);
607
throw new ServerException(msg);
608     }
609     }
610     
611     private Context JavaDoc getIC()
612     {
613     if ( initialContext == null ) {
614         Hashtable JavaDoc env = new Hashtable JavaDoc();
615         env.put("java.naming.corba.orb", ORBManager.getORB()); // NOI18N
616
try {
617         initialContext = new InitialContext JavaDoc(env);
618         } catch ( Exception JavaDoc ex ) {
619         ex.printStackTrace();
620         }
621     }
622     return initialContext;
623     }
624
625     /** Return information about the database under the given server.*/
626     public DBInfo getDBInfo(String JavaDoc serverName)
627     throws ServerException
628     {
629     try {
630         if ( serverName.equalsIgnoreCase("local") ) // NOI18N
631
serverName = "localhost"; // NOI18N
632

633             String JavaDoc initialPort = System.getProperty(OMG_ORB_INIT_PORT_PROPERTY);
634             if (initialPort == null)
635                 initialPort = String.valueOf(ORBManager.getORBInitialPort());
636             
637         String JavaDoc corbaName = "corbaname:iiop:" + serverName + ":" + // NOI18N
638
initialPort + "#" + DBInfo.JNDI_NAME; // NOI18N
639

640             Object JavaDoc objref = getIC().lookup(corbaName);
641             Object JavaDoc o = PortableRemoteObject.narrow(objref, DBInfo.class);
642         DBInfo info = (DBInfo) o;
643         return info;
644     } catch (Throwable JavaDoc t) {
645         throw new ServerException(localStrings.getLocalString(
646         "enterprise.tools.deployment.main.couldnotgetdbinfofromserver",
647         "Could not get db info from the J2EE server {0}",
648         new Object JavaDoc[] {serverName}));
649     }
650     
651     }
652     
653     /** Reconnect to all the servers I knew about in the last session.*/
654     public Hashtable JavaDoc restoreFromUserHome()
655     throws IOException
656     {
657     Hashtable JavaDoc badServerNamesToExceptions = new Hashtable JavaDoc();
658     File serversFile = new File(preferencesDirectory, SERVERS_FILENAME);
659     if (serversFile.exists()) {
660         FileInputStream fis = new FileInputStream(serversFile);
661         Properties JavaDoc servers = new Properties JavaDoc();
662         servers.load(fis);
663         fis.close();
664         for (Enumeration JavaDoc e = servers.propertyNames();
665         e.hasMoreElements();) {
666         String JavaDoc serverName = (String JavaDoc) e.nextElement();
667         try {
668             this.addServer(serverName);
669         } catch (Throwable JavaDoc ex) {
670             badServerNamesToExceptions.put(badServerNamesToExceptions,
671             ex);
672         }
673         }
674     }
675     return badServerNamesToExceptions;
676     }
677
678     /** Save my current state to my directory.*/
679     public void saveToUserHome()
680     throws IOException
681     {
682     File serversFile = new File(preferencesDirectory, SERVERS_FILENAME);
683     FileOutputStream fos = new FileOutputStream(serversFile);
684     Properties JavaDoc serversP = new Properties JavaDoc();
685     for (Enumeration JavaDoc e = this.getServerNames().elements();
686         e.hasMoreElements();) {
687         String JavaDoc nextServer = (String JavaDoc) e.nextElement();
688         serversP.put(nextServer, nextServer);
689     }
690     serversP.store(fos, "J2EE Servers"); // NOI18N
691
if( fos != null ) {
692             fos.close();
693         }
694     }
695     
696     /** My pretty format. */
697     private String JavaDoc printList()
698     {
699     String JavaDoc s = "Server Manager "; // NOI18N
700
for (Enumeration JavaDoc e = this.getServerNames().elements();
701         e.hasMoreElements();) {
702         s = s + "\n\t" + e.nextElement(); // NOI18N
703
}
704     return s;
705     }
706
707     /** My pretty format as a STring.*/
708     public String JavaDoc toString()
709     {
710     return "ServerManager"; // NOI18N
711
}
712     
713 }
714
715
Popular Tags