KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > admin > server > core > mbean > config > ManagedServerInstance


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 package com.sun.enterprise.admin.server.core.mbean.config;
25
26 import java.io.BufferedReader JavaDoc;
27 import java.io.File JavaDoc;
28 import java.io.FileNotFoundException JavaDoc;
29 import java.io.InputStream JavaDoc;
30 import java.io.InputStreamReader JavaDoc;
31 import java.io.IOException JavaDoc;
32 import java.net.InetAddress JavaDoc;
33 import java.util.ArrayList JavaDoc;
34 import java.util.Collection JavaDoc;
35 import java.util.HashMap JavaDoc;
36 import java.util.Enumeration JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import java.util.logging.Level JavaDoc;
39 import java.util.logging.Logger JavaDoc;
40 import java.util.Properties JavaDoc;
41 import java.util.StringTokenizer JavaDoc;
42 import java.util.Vector JavaDoc;
43
44 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
45 import javax.management.MBeanException JavaDoc;
46 import javax.management.MBeanInfo JavaDoc;
47 import javax.management.MBeanRegistration JavaDoc;
48 import javax.management.MBeanServer JavaDoc;
49 import javax.management.ObjectName JavaDoc;
50
51 import com.sun.enterprise.admin.AdminContext;
52 import com.sun.enterprise.admin.common.constant.AdminConstants;
53 import com.sun.enterprise.admin.common.constant.ConfigAttributeName;
54 import com.sun.enterprise.admin.common.constant.DeploymentConstants;
55 import com.sun.enterprise.admin.common.exception.AFException;
56 import com.sun.enterprise.admin.common.exception.AFJDBCResourceException;
57 import com.sun.enterprise.admin.common.exception.AFResourceException;
58 import com.sun.enterprise.admin.common.exception.AFRuntimeStoreException;
59 import com.sun.enterprise.admin.common.exception.ControlException;
60 import com.sun.enterprise.admin.common.exception.DeploymentException;
61 import com.sun.enterprise.admin.common.exception.IllegalStateException;
62 import com.sun.enterprise.admin.common.exception.MBeanConfigException;
63 import com.sun.enterprise.admin.common.exception.PortInUseException;
64 import com.sun.enterprise.admin.common.exception.ServerInstanceException;
65 import com.sun.enterprise.admin.common.InitConfFileBean;
66 import com.sun.enterprise.admin.common.MBeanServerFactory;
67 import com.sun.enterprise.admin.common.ObjectNameHelper;
68 import com.sun.enterprise.admin.common.ObjectNames;
69 import com.sun.enterprise.admin.common.RequestID;
70 import com.sun.enterprise.admin.common.ServerInstanceStatus;
71 import com.sun.enterprise.admin.common.Status;
72 import com.sun.enterprise.admin.event.AdminEvent;
73 import com.sun.enterprise.admin.event.AdminEventCache;
74 import com.sun.enterprise.admin.event.AdminEventListenerException;
75 import com.sun.enterprise.admin.event.AdminEventMulticaster;
76 import com.sun.enterprise.admin.event.AdminEventResult;
77 import com.sun.enterprise.admin.event.ApplicationDeployEvent;
78 import com.sun.enterprise.admin.event.BaseDeployEvent;
79 import com.sun.enterprise.admin.event.ConfigChangeEvent;
80 import com.sun.enterprise.admin.event.EventBuilder;
81 import com.sun.enterprise.admin.event.EventContext;
82 import com.sun.enterprise.admin.event.EventStack;
83 import com.sun.enterprise.admin.event.ModuleDeployEvent;
84 import com.sun.enterprise.admin.event.ResourceDeployEvent;
85 import com.sun.enterprise.admin.server.core.AdminService;
86 import com.sun.enterprise.admin.server.core.channel.AdminChannel;
87 import com.sun.enterprise.admin.server.core.channel.RMIClient;
88 import com.sun.enterprise.admin.server.core.ManualChangeManager;
89 import com.sun.enterprise.admin.server.core.mbean.config.Domain2ServerTransformer;
90 import com.sun.enterprise.admin.util.ArgChecker;
91 import com.sun.enterprise.admin.util.Assert;
92 import com.sun.enterprise.admin.util.ExceptionUtil;
93 import com.sun.enterprise.admin.util.HostAndPort;
94 import com.sun.enterprise.admin.util.StringValidator;
95 import com.sun.enterprise.config.ConfigBean;
96 import com.sun.enterprise.config.ConfigBeansFactory;
97 import com.sun.enterprise.config.ConfigContext;
98 import com.sun.enterprise.config.ConfigContext;
99 import com.sun.enterprise.config.ConfigException;
100 import com.sun.enterprise.config.ConfigFactory;
101 import com.sun.enterprise.config.ConfigFactory;
102 import com.sun.enterprise.config.serverbeans.*;
103 import com.sun.enterprise.config.serverbeans.Applications;
104 import com.sun.enterprise.config.serverbeans.J2eeApplication;
105 import com.sun.enterprise.config.serverbeans.JavaConfig;
106 import com.sun.enterprise.config.serverbeans.ServerTags;
107 import com.sun.enterprise.config.serverbeans.ServerXPathHelper;
108 import com.sun.enterprise.connectors.ConnectorRuntime;
109 import com.sun.enterprise.connectors.util.JmsRaMapping;
110 import com.sun.enterprise.deployment.archivist.Archivist;
111 import com.sun.enterprise.deployment.archivist.ArchivistFactory;
112 import com.sun.enterprise.deployment.backend.*;
113 import com.sun.enterprise.deployment.deploy.shared.AbstractArchive;
114 import com.sun.enterprise.deployment.deploy.shared.AbstractArchiveFactory;
115 import com.sun.enterprise.deployment.deploy.shared.FileArchive;
116 import com.sun.enterprise.deployment.deploy.shared.FileArchiveFactory;
117 import com.sun.enterprise.deployment.deploy.shared.JarArchiveFactory;
118 import com.sun.enterprise.instance.AppsManager;
119 import com.sun.enterprise.instance.EjbModulesManager;
120 import com.sun.enterprise.instance.InstanceDefinition;
121 import com.sun.enterprise.instance.InstanceEnvironment;
122 import com.sun.enterprise.instance.InstanceEnvironment;
123 import com.sun.enterprise.instance.ServerManager;
124 import com.sun.enterprise.instance.WebModulesManager;
125 import com.sun.enterprise.security.auth.realm.BadRealmException;
126 import com.sun.enterprise.security.auth.realm.file.FileRealm;
127 import com.sun.enterprise.security.auth.realm.NoSuchRealmException;
128 import com.sun.enterprise.security.auth.realm.NoSuchUserException;
129 import com.sun.enterprise.security.util.IASSecurityException;
130 import com.sun.enterprise.server.Constants;
131 import com.sun.enterprise.util.i18n.StringManager;
132 import com.sun.enterprise.util.io.FileUtils;
133 import com.sun.enterprise.util.net.NetUtils;
134
135
136 /**
137     The MBean that represents a managed Server Instance for iAS SE. In
138     other words it represents the <strong> management interface </strong> of
139     a Server Instance.
140     <p>
141     The MBeanServer will have as many instances of this MBean as there are
142     Server Instances <strong> created </strong> in Admin Server. Whenever a
143     Server Instance is created, MBeanServer registers an instance of
144     this MBean. Note that some of the MBeans may represent Server Instances
145     that are not running. Since there is an MBean for a Server Instance that
146     is not running, one can configure such a Server Instance and then start it.
147     <p>
148     ObjectName of this MBean is ias:type=ServerInstance, name=<instanceName>
149 */

150
151 public class ManagedServerInstance extends ConfigMBeanBase implements ConfigAttributeName.Server
152 {
153     private HostAndPort mHostAndPort = null;
154     private int mStartMode = AdminConstants.kNonDebugMode;
155     private String JavaDoc mInstanceName = null;
156     private boolean mAutoStart = false;
157
158     public static final Logger JavaDoc sLogger =
159             Logger.getLogger(AdminConstants.kLoggerName);
160
161     private static final int CONFIG_CHANGED = 7;
162
163     /* New for 8.0 */
164     /* This flag is defined, so that we can get rid of the transformation
165      * by simply changing its value to false. Also, an attempt is made to keep
166      * this mbean independent of jaxp api in import. */

167     static final boolean PORT_DOMAIN_TO_SERVER = false; /* package access */
168     /* New for 8.0 */
169
170     /**
171      * MAPLIST array defines mapping between "external" name and its location in XML relatively base node
172      */

173     private static final String JavaDoc[][] MAPLIST =
174     {
175 /*
176         {kName , ATTRIBUTE + ServerTags.NAME},
177         // {kLocale , ATTRIBUTE + ServerTags.LOCALE},
178         {kLogRoot , ATTRIBUTE + ServerTags.LOG_ROOT},
179         {kSessionStore , ATTRIBUTE + ServerTags.SESSION_STORE},
180         {kApplicationRoot , ATTRIBUTE + ServerTags.APPLICATION_ROOT},
181         //the following attrs are from application sub element
182         {kAppDynamicReloadEnabled , ServerXPathHelper.XPATH_CONFIG +
183                      ServerXPathHelper.XPATH_SEPARATOR +
184                                      ServerTags.ADMIN_SERVICE + ServerXPathHelper.XPATH_SEPARATOR +
185                                      ServerTags.DAS_CONFIG + ServerXPathHelper.XPATH_SEPARATOR +
186                                      ATTRIBUTE + ServerTags.DYNAMIC_RELOAD_ENABLED},
187         {kAppReloadPollInterval, ServerXPathHelper.XPATH_CONFIG +
188                                      ServerXPathHelper.XPATH_SEPARATOR +
189                                      ServerTags.ADMIN_SERVICE + ServerXPathHelper.XPATH_SEPARATOR +
190                                      ServerTags.DAS_CONFIG + ServerXPathHelper.XPATH_SEPARATOR +
191                                      ATTRIBUTE + ServerTags.DYNAMIC_RELOAD_POLL_INTERVAL_IN_SECONDS},
192  */

193     };
194     /**
195      * ATTRIBUTES array specifies attributes descriptions in format defined for MBeanEasyConfig
196      */

197     private static final String JavaDoc[] ATTRIBUTES =
198     {
199 /*
200  kName + ", String, R" ,
201     // kLocale + ", String, RW" ,
202         kLogRoot + ", String, RW" ,
203         kSessionStore + ", String, RW" ,
204         kApplicationRoot + ", String, RW" ,
205         //the following attrs are from application sub element
206         kAppDynamicReloadEnabled + ", boolean, RW" ,
207         kAppReloadPollInterval + ", int, RW" ,
208 */

209  };
210
211     /**
212      * OPERATIONS array specifies operations descriptions in format defined for MBeanEasyConfig
213      */

214     private static final String JavaDoc[] OPERATIONS =
215     {
216       "start(), ACTION, ManagedServerInstance.start1.operation", //we are using non-generic property names here for providing separate definitions to each overloading method
217
"start(String[] passwords), ACTION, ManagedServerInstance.start1.operation",
218       "start(boolean debug, String[] passwords), ACTION, ManagedServerInstance.start2.operation",
219       "startInDebugMode(), ACTION",
220       "startInDebugMode(String[] passwords), ACTION",
221       "restart(), ACTION",
222       "stop(int timeoutSeconds), ACTION",
223       "getDeployedJ2EEApplications(), INFO ",
224       "getDeployedJ2EEModules(), INFO ",
225       "getEnabledJ2EEApplications(), INFO ",
226       "getDisabledJ2EEApplications(), INFO ",
227       "getEnabledJ2EEModules(), INFO ",
228       "getDisabledJ2EEModules(), INFO ",
229 // "registerDataSource(String dataSourceXMLFileName), ACTION ",
230
// "removeDataSource(String dataSourceName), ACTION ",
231
// "getDataSourceNames(), INFO ",
232
"setHttpPort(int port ), ACTION ",
233       "getHostAndPort(), INFO ",
234       "getHttpPort(), INFO ",
235       "getStatus(), INFO ",
236       "reconfigure(), ACTION ",
237       "startMonitor(), ACTION ",
238       "getMonitorableComponentNames(), INFO ",
239       "stopMonitor(), ACTION ",
240       "postRegister(Boolean registrationDone), ACTION ",
241       "preRegister(javax.management.MBeanServer server, javax.management.ObjectName name), ACTION ",
242       "postDeregister(), ACTION ",
243       "preDeregister(), ACTION ",
244 // "getCertNicknames(), INFO ",
245
"getInstanceRoot(), INFO ",
246       "getSecurityPasswordTokens(), INFO ",
247       "isRestartNeeded(), INFO",
248       "getUserNames(), INFO",
249       "getGroupNames(), INFO",
250       "getUserGroupNames(String userName), INFO",
251       "addUser(String userName, String password, String[] groupList), INFO ",
252       "removeUser(String userName), INFO ",
253       "updateUser(String userName, String password, String[] groupList), INFO ",
254     };
255
256     /**
257         Default constructor sets MBean description tables
258     */

259     public ManagedServerInstance() throws MBeanConfigException
260     {
261         this.setDescriptions(MAPLIST, ATTRIBUTES, OPERATIONS);
262     }
263
264     public ManagedServerInstance(String JavaDoc instanceName, HostAndPort hostPort,
265         boolean autoStart) throws PortInUseException,MBeanConfigException
266     {
267         this(instanceName, hostPort, autoStart, null);
268     }
269
270     public ManagedServerInstance(String JavaDoc instanceName, HostAndPort hostPort,
271         boolean autoStart, AdminContext adminContext)
272         throws PortInUseException,MBeanConfigException
273     {
274         this(); //set description tables
275
setAdminContext(adminContext);
276         initialize(ObjectNames.kServerInstance, new String JavaDoc[]{instanceName});
277
278
279         if (instanceName == null || hostPort == null)
280         {
281             throw new IllegalArgumentException JavaDoc();
282         }
283         /**
284          * This check is probably not required here. Having this check
285          * causes unnecessary problems when there is a running instance &
286          * the MBeanServer creates a new MBean for that instance (lazy
287          * MBean loading). - Ramakanth 01/25/2002 11:17pm
288          */

289         mInstanceName = instanceName;
290         mHostAndPort = hostPort;
291         mAutoStart = autoStart;
292     }
293
294     /**
295         A method to start this Server Instance asynchronously. Note that starting
296         a Server Instance is thought as a long running operation and hence
297         could be tracked for progress. Thus the method returns a RequestID that
298         can later be queried for. The MBean that represents this Server Instance
299         is already present in the MBeanServer.
300         <p>
301         By default the Server Instance will be started in non-debug mode.
302
303     */

304     public RequestID start() throws ControlException
305     {
306         return ( this.start(false, null) );
307     }
308
309     public RequestID start(String JavaDoc[] passwords) throws ControlException
310     {
311         return ( this.start(false, passwords) );
312     }
313
314     public RequestID start(boolean debug, String JavaDoc[] passwords) throws ControlException
315     {
316         try
317         {
318             if (getInstanceStatusCode() == Status.kInstanceRunningCode)
319             {
320                 String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.cannot_start_already_running" );
321                 throw new IllegalStateException JavaDoc( msg );
322             }
323             if ( debug )
324             {
325                 mStartMode = AdminConstants.kDebugMode;
326             }
327             else
328             {
329                 if (isDebug())
330                 {
331                     setDebug(false);
332                     //What's wrong in leaving the debug options?
333
setDebugOptions(null);
334                     super.getConfigContext().flush();
335                     applyConfigChanges();
336                 }
337             }
338             /* calling start script */
339             if(debug)
340             {
341                 String JavaDoc strPort = "?";
342                 try{
343                     strPort = String.valueOf(getDebugPort());
344                 }
345                 catch (Exception JavaDoc e)
346                 {
347                 }
348                 sLogger.log(Level.INFO, "mbean.start_instance_debug",
349                                new Object JavaDoc[]{mInstanceName, strPort});
350             }
351             else
352             {
353                 sLogger.log(Level.INFO, "mbean.start_instance", mInstanceName);
354             }
355
356             InstanceDefinition instance = new InstanceDefinition(mInstanceName,
357                     mHostAndPort.getPort());
358             ServerManager.instance().startServerInstance(instance,passwords);
359             /* calling start script*/
360
361         // check if the instance has started
362
//
363
sLogger.log(Level.INFO, "mbean.check_start_instance", mInstanceName);
364         long timeoutMillis = 240000;
365         long sleepTime = 2000;
366         long timeBefore = java.lang.System.currentTimeMillis();
367         long timeAfter = java.lang.System.currentTimeMillis();
368         boolean timeoutReached = false;
369         while ((! timeoutReached) &&
370            (! (getInstanceStatusCode() == Status.kInstanceRunningCode))) {
371         Thread.sleep(sleepTime);
372             timeAfter = java.lang.System.currentTimeMillis();
373         timeoutReached = (timeAfter - timeBefore) >= timeoutMillis;
374         }
375         if (timeoutReached) {
376                 sLogger.log(Level.INFO, "mbean.start_instance_timeout", mInstanceName);
377         try {
378             Long JavaDoc tLong = new Long JavaDoc(timeoutMillis/1000);
379             stop(tLong.intValue());
380         } catch (ControlException cex) {
381                 String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.timeout_reached_server_stopping_exception", mInstanceName );
382                 //throw new ControlException( msg );
383
}
384                 String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.timeout_reached_server_starting_exception", mInstanceName );
385                 throw new ControlException( msg );
386         } else {
387         sLogger.log(Level.INFO, "mbean.start_instance_success", mInstanceName);
388         }
389         //
390
}
391         catch (Exception JavaDoc e)
392         {
393             sLogger.log(Level.SEVERE,
394                     "mbean.start_instance_failed", mInstanceName);
395             sLogger.log(Level.SEVERE,
396                     "mbean.start_instance_failed_details", e);
397             throw new ControlException(e.getMessage());
398         }
399         return ( null );
400     }
401
402     /**
403      */

404     public int startInDebugMode(String JavaDoc[] passwords) throws ControlException
405     {
406         int port = -1;
407         try
408         {
409             boolean isChanged = false;
410             if (!isDebug())
411             {
412                 setDebug(true);
413                 isChanged = true;
414             }
415             port = getDebugPort();
416             if (port == -1)
417             {
418                 port = NetUtils.getFreePort();
419                 if (port == 0)
420                 {
421                     sLogger.log(Level.SEVERE, "general.free_port_failed");
422                     String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.no_free_port" );
423                     throw new Exception JavaDoc( msg );
424                 }
425                 setDebugPort(port);
426                 isChanged = true;
427             }
428             if (isChanged)
429             {
430                 super.getConfigContext().flush();
431                 applyConfigChanges();
432             }
433         }
434         catch (Exception JavaDoc e)
435         {
436             sLogger.log(Level.WARNING, "mbean.set_debug_failed", e);
437             throw new ControlException(e.getLocalizedMessage());
438         }
439         start(true, passwords);
440         return port;
441     }
442     public int startInDebugMode() throws ControlException
443     {
444         return this.startInDebugMode(null);
445     }
446
447     /**
448      * returns true if security=on for this instance (in "live" init.conf)
449      */

450     public String JavaDoc[] getSecurityPasswordTokens() throws ControlException
451     {
452         try
453         {
454             //first testing existance of password file
455
InstanceEnvironment env = new InstanceEnvironment(mInstanceName);
456             String JavaDoc pwdFileName = env.getSecurityPasswordsFilePath();
457             File JavaDoc pwdFile = new File JavaDoc(pwdFileName);
458             if(pwdFile.exists())
459                 return null;
460             //now test the security attribute in init.conf file in "live" directory
461
InitConfFileBean conf = new InitConfFileBean();
462             conf.initialise(mInstanceName, false);
463             String JavaDoc security = conf.get_mag_var(InitConfFileBean.INITCONF_SECURITY_ATTRIBUTE);
464             if(security.equalsIgnoreCase(InitConfFileBean.INITCONF_VALUE_ON))
465             {
466                 InstanceDefinition instance = new InstanceDefinition(mInstanceName,
467                         mHostAndPort.getPort());
468                 return ServerManager.instance().getSecurityTokensForInstance(instance);
469                 //FIXME: should be replaced by receiving actual tokens from security.db
470
// this temp solution is just for starting UI work
471
//return new String[]{"internal"};
472
}
473             return null;
474         }
475         catch(Exception JavaDoc e)
476         {
477             sLogger.log(Level.WARNING, "mbean.security_check_failed", e);
478             throw new ControlException(e.getMessage());
479         }
480     }
481
482     private static final int TIME_OUT_SECONDS = 120;
483
484     // i18n StringManager
485
private static StringManager localStrings =
486         StringManager.getManager( ManagedServerInstance.class );
487
488     /**
489         Restarts a running instance.
490     */

491     public RequestID restart() throws ControlException
492     {
493         RequestID reqId = null;
494         
495         String JavaDoc adminId = AdminService.getAdminService().getInstanceName();
496 /* if (mInstanceName.equals(adminId))
497         {
498             String msg = localStrings.getString( "admin.server.core.mbean.config.cannot_restart_admin_instance" );
499             throw new IllegalStateException( msg );
500         }
501 */

502         final RMIClient rmiClient = AdminChannel.getRMIClient(mInstanceName);
503
504         if (rmiClient.getInstanceStatusCode() != Status.kInstanceRunningCode)
505         {
506             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.instance_not_running_cannot_restart" );
507             throw new IllegalStateException JavaDoc( msg );
508         }
509
510         try
511         {
512             /* calling restart script */
513             sLogger.log(Level.INFO, "mbean.restart_instance", mInstanceName);
514             InstanceDefinition instance = new InstanceDefinition(
515                                                mInstanceName,
516                                                getHostAndPort().getPort());
517             ServerManager.instance().restartServerInstance(instance);
518             /*
519              * There is certain time lapse between executing the subprocess
520              * and updating the instance stub file on the disk. The following
521              * check compensates for this time lapse. Moreover this check
522              * seems to be more definitive than waiting for a random interval,
523              * say 5 seconds.
524              */

525             int i = 0; int MAX_TIMES = 3;
526             while ((rmiClient.getInstanceStatusCode() !=
527                     Status.kInstanceNotRunningCode) && (i < MAX_TIMES))
528             {
529                 Thread.currentThread().sleep(5000);
530                 i++;
531             }
532         }
533         catch (Exception JavaDoc e)
534         {
535             throw new ControlException(e.getMessage());
536         }
537         ManagedInstanceTimer tt = new ManagedInstanceTimer(
538             TIME_OUT_SECONDS, 0,
539             new TimerCallback()
540             {
541                 public boolean check() throws Exception JavaDoc
542                 {
543                     return (rmiClient.getInstanceStatusCode() ==
544                             Status.kInstanceRunningCode);
545                 }
546             } );
547         tt.run(); //synchronous
548

549         if (rmiClient.getInstanceStatusCode() != Status.kInstanceRunningCode)
550         {
551             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.timeout_while_restarting_server" );
552             try
553             {
554                 stop(TIME_OUT_SECONDS);
555             }
556             catch (ControlException ce)
557             {
558                 msg += localStrings.getString( "admin.server.core.mbean.config.server_stop_exception" );
559             }
560             throw new ControlException(msg + mInstanceName);
561         }
562
563         return reqId;
564     }
565
566     private static final class ManagedInstanceTimer implements Runnable JavaDoc
567     {
568         private final int timeOutSeconds;
569         private final TimerCallback callBack;
570         private final int startAfterSeconds;
571         private boolean timeOutReached;
572         private long startTime;
573
574         ManagedInstanceTimer(int timeOutSeconds,
575                              int startAfterSeconds,
576                              TimerCallback callBack)
577         {
578             this.timeOutSeconds = timeOutSeconds;
579             this.startAfterSeconds = startAfterSeconds;
580             this.callBack = callBack;
581             this.timeOutReached = false;
582         }
583
584         public void run()
585         {
586             startTime = java.lang.System.currentTimeMillis();
587             try
588             {
589                 Thread.currentThread().sleep(startAfterSeconds * 1000);
590                 while (!timeOutReached() && !callBack.check())
591                 {
592                     try
593                     {
594                         Thread.currentThread().sleep(1000);
595                         computeTimeOut();
596                     }
597                     catch (InterruptedException JavaDoc ie)
598                     {
599                         sLogger.warning(ie.toString());
600                         timeOutReached = true;
601                     }
602                 }
603             }
604             catch (Exception JavaDoc e)
605             {
606                 sLogger.warning(e.toString());
607                 timeOutReached = true;
608             }
609         }
610
611         private boolean timeOutReached()
612         {
613             return timeOutReached;
614         }
615
616         private void computeTimeOut()
617         {
618             long currentTime = java.lang.System.currentTimeMillis();
619             timeOutReached =
620                 ((currentTime - startTime) >= (timeOutSeconds * 1000));
621         }
622     }
623
624     interface TimerCallback
625     {
626         boolean check() throws Exception JavaDoc;
627     }
628
629     public void stop(int timeoutSeconds) throws ControlException
630     {
631         String JavaDoc adminId = AdminService.getAdminService().getInstanceName();
632         if (mInstanceName.equals(adminId))
633         {
634             sLogger.log(Level.INFO, "mbean.shutdown_started");
635             new Thread JavaDoc(new ShutdownThread(adminId)).start();
636             return;
637         }
638         if (getInstanceStatusCode() == Status.kInstanceNotRunningCode)
639         {
640             String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.not_running_cannot_stop" );
641             throw new IllegalStateException JavaDoc( msg );
642         }
643
644         /* calling stop script */
645         try
646         {
647             sLogger.log(Level.INFO, "mbean.stop_instance", mInstanceName);
648             InstanceDefinition instance = new InstanceDefinition(mInstanceName,
649                     mHostAndPort.getPort());
650             ServerManager.instance().stopServerInstance(instance);
651
652         // check if the instance has stopped
653
//
654
sLogger.log(Level.INFO, "mbean.check_stop_instance", mInstanceName);
655         long timeoutMillis = (timeoutSeconds * 1000);
656         long sleepTime = 2000;
657         long timeBefore = java.lang.System.currentTimeMillis();
658         long timeAfter = java.lang.System.currentTimeMillis();
659         boolean timeoutReached = false;
660             while ((! timeoutReached) &&
661                (! (getInstanceStatusCode() == Status.kInstanceNotRunningCode))) {
662         Thread.sleep(sleepTime);
663             timeAfter = java.lang.System.currentTimeMillis();
664         timeoutReached = (timeAfter - timeBefore) >= timeoutMillis;
665         }
666         if (timeoutReached) {
667                 sLogger.log(Level.INFO, "mbean.stop_instance_timeout", mInstanceName);
668                 String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.timeout_while_stopping_server", mInstanceName );
669                 throw new ControlException( msg );
670         } else {
671         sLogger.log(Level.INFO, "mbean.stop_instance_success", mInstanceName);
672         }
673         //
674
}
675         catch (Exception JavaDoc e)
676         {
677             sLogger.log(Level.SEVERE,
678                     "mbean.stop_instance_failed", mInstanceName);
679             throw new ControlException(e.getMessage());
680         }
681         /* calling stop script*/
682     }
683     
684     /**
685         Returns the names of deployed applications to this server instance.
686     */

687     public String JavaDoc[] getDeployedJ2EEApplications() throws ServerInstanceException
688     {
689         String JavaDoc[] apps = new String JavaDoc[0];
690         try
691         {
692             sLogger.log(Level.FINE, "mbean.list_components");
693             ConfigContext serverContext = getConfigContext(mInstanceName);
694             Applications appsConfigBean =
695                 (Applications) ConfigBeansFactory.getConfigBeanByXPath(
696                     serverContext, ServerXPathHelper.XPATH_APPLICATIONS);
697             J2eeApplication[] j2eeApps = appsConfigBean.getJ2eeApplication();
698             if (j2eeApps != null)
699             {
700                 apps = new String JavaDoc[j2eeApps.length];
701                 for(int i=0; i<j2eeApps.length; i++)
702                 {
703                     apps[i] = j2eeApps[i].getName();
704                 }
705             }
706         }
707         catch (Exception JavaDoc e)
708         {
709             sLogger.log(Level.WARNING, "mbean.list_failed", e);
710             throw new ServerInstanceException(e.getLocalizedMessage());
711         }
712         return ( apps );
713     }
714
715     /**
716     */

717     public String JavaDoc[] getDeployedJ2EEModules() throws ServerInstanceException
718     {
719         String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.not_supported_yet" );
720         throw new UnsupportedOperationException JavaDoc( msg );
721     }
722
723     /**
724      * Returns an array of standalone ejb module names that are deployed to
725      * this server instance.
726      * @return an array of deployed ejb module names. Returns an array of 0
727      * length if none are deployed.
728      * @throws ServerinstanceException
729      */

730     public String JavaDoc[] getDeployedEJBModules() throws ServerInstanceException
731     {
732         String JavaDoc[] ejbModules = new String JavaDoc[0];
733         try
734         {
735             sLogger.log(Level.FINE, "mbean.list_components");
736             ConfigContext serverContext = getConfigContext(mInstanceName);
737             Applications appsConfigBean =
738                 (Applications) ConfigBeansFactory.getConfigBeanByXPath(
739                     serverContext, ServerXPathHelper.XPATH_APPLICATIONS);
740             EjbModule[] modules = appsConfigBean.getEjbModule();
741             if (modules != null)
742             {
743                 ejbModules = new String JavaDoc[modules.length];
744                 for(int i=0; i<modules.length; i++)
745                 {
746                     ejbModules[i] = modules[i].getName();
747                 }
748             }
749         }
750         catch (Exception JavaDoc e)
751         {
752             sLogger.log(Level.WARNING, "mbean.list_failed", e);
753             throw new ServerInstanceException(e.getLocalizedMessage());
754         }
755         return ejbModules;
756     }
757
758     /**
759      * Returns an array of standalone war module names that are deployed to
760      * this server instance.
761      * @return an array of deployed web module names. Returns an array of 0
762      * length if none are deployed.
763      * @throws ServerinstanceException
764      */

765     public String JavaDoc[] getDeployedWebModules() throws ServerInstanceException
766     {
767         String JavaDoc[] webModules = new String JavaDoc[0];
768         try
769         {
770             sLogger.log(Level.FINE, "mbean.list_components");
771             ConfigContext serverContext = getConfigContext(mInstanceName);
772             Applications appsConfigBean =
773                 (Applications) ConfigBeansFactory.getConfigBeanByXPath(
774                     serverContext, ServerXPathHelper.XPATH_APPLICATIONS);
775             WebModule[] modules = appsConfigBean.getWebModule();
776             if (modules != null)
777             {
778                 webModules = new String JavaDoc[modules.length];
779                 for(int i=0; i<modules.length; i++)
780                 {
781                     webModules[i] = modules[i].getName();
782                 }
783             }
784         }
785         catch (Exception JavaDoc e)
786         {
787             sLogger.log(Level.WARNING, "mbean.list_failed", e);
788             throw new ServerInstanceException(e.getLocalizedMessage());
789         }
790         return webModules;
791     }
792
793     /**
794      * Returns an array of deployed connectors.
795      * @return an array of deployed connectors. Returns an array of 0 length
796      * if none are deployed.
797      * @throws ServerinstanceException
798      */

799     public String JavaDoc[] getDeployedConnectors() throws ServerInstanceException
800     {
801         String JavaDoc[] connectors = new String JavaDoc[0];
802         try
803         {
804             sLogger.log(Level.FINE, "mbean.list_components");
805             ConfigContext serverContext = getConfigContext(mInstanceName);
806             Applications appsConfigBean =
807                 (Applications) ConfigBeansFactory.getConfigBeanByXPath(
808                     serverContext, ServerXPathHelper.XPATH_APPLICATIONS);
809             ConnectorModule[] connectorConfigBeans =
810                                     appsConfigBean.getConnectorModule();
811             if (connectorConfigBeans != null)
812             {
813                 connectors = new String JavaDoc[connectorConfigBeans.length];
814                 for(int i = 0; i < connectors.length; i++)
815                 {
816                     connectors[i] = connectorConfigBeans[i].getName();
817                 }
818             }
819         }
820         catch (Exception JavaDoc e)
821         {
822             sLogger.log(Level.WARNING, "mbean.list_failed", e);
823             throw new ServerInstanceException(e.getLocalizedMessage());
824         }
825         return connectors;
826     }
827
828     /**
829     */

830     public String JavaDoc[] getEnabledJ2EEApplications() throws ServerInstanceException
831     {
832         return ( null );
833     }
834
835     /**
836     */

837     public String JavaDoc[] getDisabledJ2EEApplications() throws ServerInstanceException
838     {
839         return ( null );
840     }
841
842     /**
843     */

844     public String JavaDoc[] getEnabledJ2EEModules() throws ServerInstanceException
845     {
846         return ( null );
847     }
848
849     /**
850     */

851     public String JavaDoc[] getDisabledJ2EEModules() throws ServerInstanceException
852     {
853         return ( null );
854     }
855
856
857     /**
858     */

859     public void createResource(String JavaDoc resourceXMLFile)
860         throws AFResourceException
861     {
862         try
863         {
864            ResourcesXMLParser allResources =
865                 new ResourcesXMLParser(resourceXMLFile);
866             Iterator JavaDoc resourceIter = allResources.getResources();
867             while (resourceIter.hasNext())
868             {
869                 Resource resource = (Resource) resourceIter.next();
870                 if (resource.getType() == Resource.JDBC_RESOURCE)
871                 {
872                     Properties JavaDoc attributes = resource.getAttributes();
873                     String JavaDoc jndiName =
874                         attributes.getProperty( ResourcesXMLParser.JNDI_NAME);
875                     String JavaDoc poolName =
876                         attributes.getProperty( ResourcesXMLParser.POOL_NAME);
877                     createJDBCResource(jndiName, poolName);
878                     addJDBCResourceAttribute(resource, attributes, jndiName);
879                 }
880                 else if (resource.getType() == Resource.JMS_RESOURCE)
881                 {
882                     Properties JavaDoc attributes = resource.getAttributes();
883                     String JavaDoc jndiName =
884                         attributes.getProperty( ResourcesXMLParser.JNDI_NAME);
885                     String JavaDoc resType =
886                         attributes.getProperty(ResourcesXMLParser.RES_TYPE);
887 /* String factoryClass =
888                         attributes.getProperty(ResourcesXMLParser.FACTORY_CLASS);
889 */

890                     createJMSResource(jndiName, resType, new Properties JavaDoc()/*, factoryClass*/);
891                     addJMSResourceAttribute(resource, attributes, jndiName);
892
893                 }
894                 else if (resource.getType() == Resource.EXT_JNDI_RESOURCE)
895                 {
896                     Properties JavaDoc attributes = resource.getAttributes();
897                     String JavaDoc jndiName =
898                         attributes.getProperty(ResourcesXMLParser.JNDI_NAME);
899                     String JavaDoc jndiLookupName =
900                         attributes.getProperty(ResourcesXMLParser.JNDI_LOOKUP);
901                     String JavaDoc resType =
902                         attributes.getProperty(ResourcesXMLParser.RES_TYPE);
903                     String JavaDoc factoryClass =
904                         attributes.getProperty(ResourcesXMLParser.FACTORY_CLASS);
905
906                     createJNDIResource(jndiName, jndiLookupName, resType,
907                                         factoryClass);
908                     addJNDIResourceAttribute(resource, attributes, jndiName);
909                 }
910                 else if (resource.getType() == Resource.PERSISTENCE_RESOURCE)
911                 {
912                     Properties JavaDoc attributes = resource.getAttributes();
913                     String JavaDoc jndiName =
914                         attributes.getProperty(ResourcesXMLParser.JNDI_NAME);
915
916                     //Bug# 4661145
917
createPersistenceManagerFactoryResource(jndiName);
918                     addPersistenceManagerFactoryAttribute(resource,
919                                                           attributes,
920                                                           jndiName);
921                 }
922                 else if (resource.getType() == Resource.MAIL_RESOURCE)
923                 {
924                     Properties JavaDoc attributes = resource.getAttributes();
925                     String JavaDoc jndiName =
926                         attributes.getProperty(ResourcesXMLParser.JNDI_NAME);
927                     String JavaDoc host =
928                         attributes.getProperty(ResourcesXMLParser.MAIL_HOST);
929                     String JavaDoc user =
930                         attributes.getProperty(ResourcesXMLParser.MAIL_USER);
931                     String JavaDoc fromAddress = attributes.getProperty(
932                                     ResourcesXMLParser.MAIL_FROM_ADDRESS);
933                     createJavaMailResource(jndiName, host, user, fromAddress);
934                     addJavaMailAttribute(resource, attributes, jndiName);
935                 }
936                 else if (resource.getType() == Resource.CUSTOM_RESOURCE)
937                 {
938                     Properties JavaDoc attributes = resource.getAttributes();
939                     String JavaDoc jndiName =
940                         attributes.getProperty(ResourcesXMLParser.JNDI_NAME);
941                     String JavaDoc resType =
942                         attributes.getProperty(ResourcesXMLParser.RES_TYPE);
943                     String JavaDoc factoryClass =
944                         attributes.getProperty(ResourcesXMLParser.FACTORY_CLASS);
945
946                     createCustomResource(jndiName, resType, factoryClass);
947                     addCustomResourceAttribute(resource, attributes, jndiName);
948                 }
949                 else if (resource.getType() == Resource.JDBC_CONN_POOL)
950                 {
951                     Properties JavaDoc attributes = resource.getAttributes();
952                     String JavaDoc name = attributes.getProperty(
953                                     ResourcesXMLParser.CONNECTION_POOL_NAME);
954                     String JavaDoc datasourceClass =
955                         attributes.getProperty(ResourcesXMLParser.DATASOURCE_CLASS);
956
957                     createJDBCConnectionPool(name, datasourceClass);
958                     addJDBCConnectionPoolAttribute(resource, attributes, name);
959                 }
960             }
961         }
962         catch (Exception JavaDoc e)
963         {
964             throw new AFResourceException(e.getMessage());
965         }
966     }
967
968
969     public void createJDBCConnectionPool(String JavaDoc id,
970                                          String JavaDoc datasourceClassName)
971         throws AFResourceException
972     {
973         ArgChecker.checkValid(id, "id",
974                               StringValidator.getInstance()); //noi18n
975
ArgChecker.checkValid(datasourceClassName, "datasourceClassName",
976                               StringValidator.getInstance()); //noi18n
977

978         try
979         {
980             sLogger.log(Level.FINE, "mbean.create_resource", id);
981             ConfigContext serverContext = getConfigContext(mInstanceName);
982             Resources resourcesBean =
983                 (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
984                                             ServerXPathHelper.XPATH_RESOURCES);
985             JdbcConnectionPool resource = new JdbcConnectionPool();
986             resource.setName(id);
987             resource.setDatasourceClassname(datasourceClassName);
988             resourcesBean.addJdbcConnectionPool(resource);
989             serverContext.flush();
990
991         }
992         catch (Exception JavaDoc e)
993         {
994             sLogger.log(Level.WARNING, "mbean.create_resource_failed", e);
995             throw new AFResourceException(e.getLocalizedMessage());
996         }
997     }
998
999     private void addJDBCConnectionPoolAttribute(Resource resource,
1000                                                Properties JavaDoc attributes,
1001                                                String JavaDoc name)
1002                 throws AFResourceException
1003    {
1004        try
1005        {
1006            ConfigContext serverContext = getConfigContext(mInstanceName);
1007            Resources resourcesBean =
1008                      (Resources)ConfigBeansFactory.getConfigBeanByXPath(
1009                      serverContext,
1010                      ServerXPathHelper.XPATH_RESOURCES);
1011            JdbcConnectionPool jdbc_pool_resource =
1012                               resourcesBean.getJdbcConnectionPoolByName(name);
1013            String JavaDoc sSteadyPoolSize =
1014                   attributes.getProperty(ResourcesXMLParser.STEADY_POOL_SIZE);
1015            String JavaDoc sMaxPoolSize =
1016                   attributes.getProperty(ResourcesXMLParser.MAX_POOL_SIZE);
1017            String JavaDoc sMaxWaitTimeInMillis =
1018                   attributes.getProperty(
1019                   ResourcesXMLParser.MAX_WAIT_TIME_IN_MILLIS);
1020            String JavaDoc sPoolSizeQuantity =
1021                   attributes.getProperty(ResourcesXMLParser.POOL_SIZE_QUANTITY);
1022            String JavaDoc sIdleTimeoutInSec =
1023                   attributes.getProperty(
1024                   ResourcesXMLParser.IDLE_TIME_OUT_IN_SECONDS);
1025            String JavaDoc sIsConnectionValidationRequired =
1026                   attributes.getProperty(
1027                   ResourcesXMLParser.IS_CONNECTION_VALIDATION_REQUIRED);
1028            String JavaDoc sConnectionValidationMethod =
1029                   attributes.getProperty(
1030                   ResourcesXMLParser.CONNECTION_VALIDATION_METHOD);
1031            String JavaDoc sFailAllConnection =
1032                   attributes.getProperty(
1033                   ResourcesXMLParser.FAIL_ALL_CONNECTIONS);
1034            String JavaDoc sValidationTableName =
1035                   attributes.getProperty(
1036                   ResourcesXMLParser.VALIDATION_TABLE_NAME);
1037            String JavaDoc sResType =
1038                   attributes.getProperty(
1039                   ResourcesXMLParser.RES_TYPE);
1040            String JavaDoc sTransIsolationLevel =
1041                   attributes.getProperty(
1042                   ResourcesXMLParser.TRANS_ISOLATION_LEVEL);
1043            String JavaDoc sIsIsolationLevelQuaranteed =
1044                   attributes.getProperty(
1045                   ResourcesXMLParser.IS_ISOLATION_LEVEL_GUARANTEED);
1046
1047            if (sSteadyPoolSize != null) {
1048                jdbc_pool_resource.setSteadyPoolSize(sSteadyPoolSize);
1049            }
1050            if (sMaxPoolSize != null) {
1051                jdbc_pool_resource.setMaxPoolSize(sMaxPoolSize);
1052            }
1053            if (sMaxWaitTimeInMillis != null) {
1054                jdbc_pool_resource.setMaxWaitTimeInMillis(sMaxWaitTimeInMillis);
1055            }
1056            if (sPoolSizeQuantity != null) {
1057                jdbc_pool_resource.setPoolResizeQuantity(sPoolSizeQuantity);
1058            }
1059            if (sIdleTimeoutInSec != null) {
1060                jdbc_pool_resource.setIdleTimeoutInSeconds(sIdleTimeoutInSec);
1061            }
1062            if (sIsConnectionValidationRequired != null) {
1063                jdbc_pool_resource.setIsConnectionValidationRequired(
1064                                   Boolean.valueOf(sIsConnectionValidationRequired).booleanValue());
1065            }
1066            if (sConnectionValidationMethod != null) {
1067                jdbc_pool_resource.setConnectionValidationMethod(
1068                                   sConnectionValidationMethod);
1069            }
1070            if (sFailAllConnection != null) {
1071                jdbc_pool_resource.setFailAllConnections(Boolean.valueOf(
1072                                   sFailAllConnection).booleanValue());
1073            }
1074            if (sValidationTableName != null) {
1075                jdbc_pool_resource.setValidationTableName(sValidationTableName);
1076            }
1077            if (sResType != null) {
1078                jdbc_pool_resource.setResType(sResType);
1079            }
1080            if (sTransIsolationLevel != null) {
1081                jdbc_pool_resource.setTransactionIsolationLevel(
1082                                   sTransIsolationLevel);
1083            }
1084            if (sIsIsolationLevelQuaranteed != null) {
1085                jdbc_pool_resource.setIsIsolationLevelGuaranteed(
1086                     Boolean.valueOf(sIsIsolationLevelQuaranteed).booleanValue());
1087            }
1088
1089            //description
1090
String JavaDoc sDescription = resource.getDescription();
1091            if (sDescription != null) {
1092                jdbc_pool_resource.setDescription(sDescription);
1093            }
1094            //element property
1095
ElementProperty[] epArray = resource.getElementProperty();
1096            if (epArray != null) {
1097                for (int ii=0; ii<epArray.length; ii++)
1098                   jdbc_pool_resource.addElementProperty(epArray[ii]);
1099            }
1100            serverContext.flush();
1101        }
1102        catch (Exception JavaDoc e)
1103        {
1104            throw new AFResourceException(e.getLocalizedMessage());
1105        }
1106    }
1107
1108    public void deleteJDBCConnectionPool(String JavaDoc poolName)
1109        throws AFResourceException
1110    {
1111        ArgChecker.checkValid(poolName, "poolName",
1112                              StringValidator.getInstance()); //noi18n
1113
sLogger.log(Level.FINE, "mbean.delele_jdbc_pool", poolName);
1114        try
1115        {
1116            ConfigContext serverContext = getConfigContext(mInstanceName);
1117            Resources resourcesBean =
1118                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1119                                            ServerXPathHelper.XPATH_RESOURCES);
1120            JdbcConnectionPool resource =
1121                resourcesBean.getJdbcConnectionPoolByName(poolName);
1122            //Bug# 4682650
1123
if (resource == null)
1124            {
1125                String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", poolName );
1126                throw new Exception JavaDoc( msg );
1127            }
1128            resourcesBean.removeJdbcConnectionPool(resource);
1129            serverContext.flush();
1130        }
1131        catch (Exception JavaDoc e)
1132        {
1133            sLogger.log(Level.WARNING, "mbean.delete_jdbc_pool_failed", e);
1134            throw new AFResourceException(e.getLocalizedMessage());
1135        }
1136    }
1137
1138    public String JavaDoc[] listJDBCConnectionPools() throws AFException
1139    {
1140        String JavaDoc[] sa = null;
1141        try
1142        {
1143            sLogger.log(Level.FINE, "mbean.list_components");
1144            ConfigContext serverContext = getConfigContext(mInstanceName);
1145            Resources resourcesBean =
1146                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1147                                            ServerXPathHelper.XPATH_RESOURCES);
1148            JdbcConnectionPool[] connectionPools = resourcesBean.getJdbcConnectionPool();
1149            if (connectionPools != null)
1150            {
1151                sa = new String JavaDoc[connectionPools.length];
1152                for(int i=0; i<connectionPools.length; i++)
1153                {
1154                    sa[i] = connectionPools[i].getName();
1155                }
1156            }
1157        }
1158        catch (Exception JavaDoc e)
1159        {
1160            sLogger.log(Level.WARNING, "mbean.list_failed", e);
1161            throw new AFException(e.getLocalizedMessage());
1162        }
1163        return sa;
1164    }
1165
1166    /**
1167     * Registers a jdbc datasource with the given jndiName & properties.
1168     */

1169    public void createJDBCResource(String JavaDoc jndiName,
1170                                   String JavaDoc poolName)
1171        throws AFResourceException
1172    {
1173        ArgChecker.checkValid(jndiName, "jndiName",
1174                              StringValidator.getInstance()); //noi18n
1175
ArgChecker.checkValid(poolName, "poolName",
1176                              StringValidator.getInstance()); //noi18n
1177
try
1178        {
1179            sLogger.log(Level.FINE, "mbean.create_resource", jndiName);
1180            ConfigContext serverContext = getConfigContext(mInstanceName);
1181            Resources resourcesBean =
1182                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1183                                            ServerXPathHelper.XPATH_RESOURCES);
1184            JdbcResource resource = new JdbcResource();
1185            resource.setJndiName(jndiName);
1186            resource.setPoolName(poolName);
1187            //resource.setEnabled(true);
1188
resourcesBean.addJdbcResource(resource);
1189        createResourceRef(jndiName);
1190            serverContext.flush();
1191
1192        }
1193        catch (Exception JavaDoc e)
1194        {
1195            sLogger.log(Level.WARNING, "mbean.create_resource_failed", e);
1196            throw new AFResourceException(e.getLocalizedMessage());
1197        }
1198    }
1199
1200    private void createResourceRef(String JavaDoc name) throws Exception JavaDoc {
1201            ConfigContext serverContext = getConfigContext(mInstanceName);
1202        // add reference in PE case
1203
Server JavaDoc server = ServerBeansFactory.getServerBean(serverContext);
1204        ResourceRef rr = new ResourceRef();
1205        rr.setRef(name);
1206        server.addResourceRef(rr);
1207        // end add ref
1208

1209    }
1210
1211    private void deleteResourceRef(String JavaDoc name) throws Exception JavaDoc {
1212            ConfigContext serverContext = getConfigContext(mInstanceName);
1213        // add reference in PE case
1214
Server JavaDoc server = ServerBeansFactory.getServerBean(serverContext);
1215        ResourceRef rr = server.getResourceRefByRef(name);
1216        if(rr != null) {
1217            server.removeResourceRef(rr);
1218        }
1219    }
1220
1221    private void addJDBCResourceAttribute(Resource resource,
1222                                          Properties JavaDoc attributes,
1223                                          String JavaDoc jndiName)
1224                 throws AFResourceException
1225    {
1226        //adding rest of the attributes
1227
try
1228        {
1229            ConfigContext serverContext = getConfigContext(mInstanceName);
1230            Resources resourcesBean =
1231                      (Resources)ConfigBeansFactory.getConfigBeanByXPath(
1232                      serverContext, ServerXPathHelper.XPATH_RESOURCES);
1233            JdbcResource jdbc_resource =
1234                         resourcesBean.getJdbcResourceByJndiName(jndiName);
1235//ms1 String enabledName =
1236
//ms1 attributes.getProperty(ResourcesXMLParser.ENABLED);
1237
//ms1 if (enabledName != null) {
1238
//ms1 jdbc_resource.setEnabled(Boolean.valueOf(enabledName).booleanValue());
1239
//ms1 } //if
1240
//description
1241
String JavaDoc sDescription = resource.getDescription();
1242            if (sDescription != null) {
1243                jdbc_resource.setDescription(sDescription);
1244            }
1245            //element property
1246
/*
1247            ElementProperty[] epArray = resource.getElementProperty();
1248            if (epArray != null) {
1249                for (int ii=0; ii<epArray.length; ii++)
1250                   jdbc_resource.addElementProperty(epArray[ii]);
1251            }
1252            */

1253
1254            serverContext.flush();
1255        }
1256        catch (Exception JavaDoc e)
1257        {
1258            throw new AFResourceException(e.getLocalizedMessage());
1259        }
1260    }
1261
1262    public void deleteJDBCResource(String JavaDoc jndiName) throws AFResourceException
1263    {
1264        ArgChecker.checkValid(jndiName, "jndiName",
1265                              StringValidator.getInstance()); //noi18n
1266
try
1267        {
1268            sLogger.log(Level.FINE, "mbean.delete_resource", jndiName);
1269            ConfigContext serverContext = getConfigContext(mInstanceName);
1270            Resources resourcesBean =
1271                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1272                                            ServerXPathHelper.XPATH_RESOURCES);
1273            JdbcResource resource =
1274                resourcesBean.getJdbcResourceByJndiName(jndiName);
1275            //Bug# 4682650
1276
if (resource == null)
1277            {
1278                String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName );
1279                throw new Exception JavaDoc( msg );
1280            }
1281            resourcesBean.removeJdbcResource(resource);
1282            deleteResourceRef(jndiName);
1283            serverContext.flush();
1284        }
1285        catch (Exception JavaDoc e)
1286        {
1287            sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e);
1288            throw new AFResourceException(e.getLocalizedMessage());
1289        }
1290    }
1291
1292    public String JavaDoc[] listJDBCResources() throws AFException
1293    {
1294        String JavaDoc[] sa = null;
1295        try
1296        {
1297            sLogger.log(Level.FINE, "mbean.list_components");
1298            ConfigContext serverContext = getConfigContext(mInstanceName);
1299            Resources resourcesBean =
1300                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1301                                            ServerXPathHelper.XPATH_RESOURCES);
1302            JdbcResource[] jdbcResources = resourcesBean.getJdbcResource();
1303            if (jdbcResources != null)
1304            {
1305                sa = new String JavaDoc[jdbcResources.length];
1306                for(int i=0; i<jdbcResources.length; i++)
1307                {
1308                    sa[i] = jdbcResources[i].getJndiName();
1309                }
1310            }
1311        }
1312        catch (Exception JavaDoc e)
1313        {
1314            sLogger.log(Level.WARNING, "mbean.list_failed", e);
1315            throw new AFException(e.getLocalizedMessage());
1316        }
1317        return sa;
1318    }
1319
1320    /**
1321     * Registers a Java Mail resource.
1322     */

1323    public void createJavaMailResource(String JavaDoc jndiName,
1324                                       String JavaDoc host,
1325                                       String JavaDoc user,
1326                                       String JavaDoc fromAddress)
1327        throws AFResourceException
1328    {
1329        ArgChecker.checkValid(jndiName, "jndiName",
1330                              StringValidator.getInstance()); //noi18n
1331
ArgChecker.checkValid(host, "host",
1332                              StringValidator.getInstance()); //noi18n
1333
ArgChecker.checkValid(user, "user",
1334                              StringValidator.getInstance()); //noi18n
1335
ArgChecker.checkValid(fromAddress, "fromAddress",
1336                              StringValidator.getInstance()); //noi18n
1337
try
1338        {
1339            sLogger.log(Level.FINE, "mbean.create_resource", jndiName);
1340            ConfigContext serverContext = getConfigContext(mInstanceName);
1341            Resources resourcesBean =
1342                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1343                                            ServerXPathHelper.XPATH_RESOURCES);
1344            MailResource resource = new MailResource();
1345            resource.setJndiName(jndiName);
1346            resource.setHost(host);
1347            resource.setUser(user);
1348            resource.setFrom(fromAddress);
1349//ms1 resource.setEnabled(true);
1350
resourcesBean.addMailResource(resource);
1351        createResourceRef(jndiName);
1352            serverContext.flush();
1353
1354        }
1355        catch (Exception JavaDoc e)
1356        {
1357            sLogger.log(Level.FINE, "mbean.create_resource_failed", e);
1358            throw new AFResourceException(e.getLocalizedMessage());
1359        }
1360    }
1361
1362    private void addJavaMailAttribute(Resource resource,
1363                                      Properties JavaDoc attributes,
1364                                      String JavaDoc jndiName)
1365                 throws AFResourceException
1366    {
1367        //adding rest of the attributes
1368
try
1369        {
1370            ConfigContext serverContext = getConfigContext(mInstanceName);
1371            Resources resourcesBean =
1372                      (Resources)ConfigBeansFactory.getConfigBeanByXPath(
1373                      serverContext,
1374                      ServerXPathHelper.XPATH_RESOURCES);
1375            MailResource mail_resource = resourcesBean.getMailResourceByJndiName(jndiName);
1376            String JavaDoc sStoreProto =
1377                   attributes.getProperty(ResourcesXMLParser.MAIL_STORE_PROTO);
1378            String JavaDoc sStoreProtoClass =
1379                   attributes.getProperty(ResourcesXMLParser.MAIL_STORE_PROTO_CLASS);
1380            String JavaDoc sTransProto =
1381                   attributes.getProperty(ResourcesXMLParser.MAIL_TRANS_PROTO);
1382            String JavaDoc sTransProtoClass =
1383                   attributes.getProperty(ResourcesXMLParser.MAIL_TRANS_PROTO_CLASS);
1384            String JavaDoc sDebug =
1385                   attributes.getProperty(ResourcesXMLParser.MAIL_DEBUG);
1386//ms1 String sEnabled =
1387
//ms1 attributes.getProperty(ResourcesXMLParser.ENABLED);
1388

1389            if (sStoreProto != null) {
1390                mail_resource.setStoreProtocol(sStoreProto);
1391            }
1392            if (sStoreProtoClass != null) {
1393                mail_resource.setStoreProtocolClass(sStoreProtoClass);
1394            }
1395            if (sTransProto != null ) {
1396                mail_resource.setTransportProtocol(sTransProto);
1397            }
1398            if (sTransProtoClass != null) {
1399                mail_resource.setTransportProtocolClass(sTransProtoClass);
1400            }
1401            if (sDebug != null) {
1402                mail_resource.setDebug(Boolean.valueOf(sDebug).booleanValue());
1403            }
1404//ms1 if (sEnabled != null) {
1405
//ms1 mail_resource.setEnabled(Boolean.valueOf(sEnabled).booleanValue());
1406
//ms1 }
1407
//description
1408
String JavaDoc sDescription = resource.getDescription();
1409            if (sDescription != null) {
1410                mail_resource.setDescription(sDescription);
1411             }
1412             //element property
1413
ElementProperty[] epArray = resource.getElementProperty();
1414             if (epArray != null) {
1415                for (int ii=0; ii<epArray.length; ii++)
1416                   mail_resource.addElementProperty(epArray[ii]);
1417             }
1418             serverContext.flush();
1419         }
1420         catch (Exception JavaDoc e)
1421         {
1422             throw new AFResourceException(e.getLocalizedMessage());
1423         }
1424    }
1425
1426    public void deleteJavaMailResource(String JavaDoc jndiName)
1427        throws AFResourceException
1428    {
1429        ArgChecker.checkValid(jndiName, "jndiName",
1430                              StringValidator.getInstance()); //noi18n
1431
try
1432        {
1433            sLogger.log(Level.FINE, "mbean.delete_resource", jndiName);
1434            ConfigContext serverContext = getConfigContext(mInstanceName);
1435            Resources resourcesBean =
1436                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1437                                            ServerXPathHelper.XPATH_RESOURCES);
1438            MailResource resource =
1439                resourcesBean.getMailResourceByJndiName(jndiName);
1440            //Bug# 4682650
1441
if (resource == null)
1442            {
1443                String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName );
1444                throw new Exception JavaDoc( msg );
1445            }
1446            resourcesBean.removeMailResource(resource);
1447            deleteResourceRef(jndiName);
1448            serverContext.flush();
1449        }
1450        catch (Exception JavaDoc e)
1451        {
1452            sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e);
1453            throw new AFResourceException(e.getLocalizedMessage());
1454        }
1455    }
1456
1457    public String JavaDoc[] listJavaMailResources() throws AFException
1458    {
1459        String JavaDoc[] sa = null;
1460        try
1461        {
1462            sLogger.log(Level.FINE, "mbean.list_components");
1463            ConfigContext serverContext = getConfigContext(mInstanceName);
1464            Resources resourcesBean =
1465                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1466                                            ServerXPathHelper.XPATH_RESOURCES);
1467            MailResource[] mailResources = resourcesBean.getMailResource();
1468            if (mailResources != null)
1469            {
1470                sa = new String JavaDoc[mailResources.length];
1471                for(int i=0; i<mailResources.length; i++)
1472                {
1473                    sa[i] = mailResources[i].getJndiName();
1474                }
1475            }
1476        }
1477        catch (Exception JavaDoc e)
1478        {
1479            sLogger.log(Level.WARNING, "mbean.list_failed", e);
1480            throw new AFException(e.getLocalizedMessage());
1481        }
1482        return sa;
1483    }
1484    
1485
1486    public void createJMSResource(String JavaDoc jndiName,
1487                                  String JavaDoc resourceType
1488                                  /* String factoryClassName*/)
1489        throws AFResourceException
1490    {
1491        createJMSResource(jndiName, resourceType, new Properties JavaDoc());
1492    }
1493    
1494
1495    public void createJMSResource(String JavaDoc jndiName,
1496                                  String JavaDoc resourceType,
1497                                  Properties JavaDoc props/*,
1498                                  String factoryClassName*/
)
1499        throws AFResourceException
1500    {
1501        ArgChecker.checkValid(jndiName, "jndiName",
1502                              StringValidator.getInstance()); //noi18n
1503
/*ArgChecker.checkValid(factoryClassName, "factoryClassName",
1504                              StringValidator.getInstance()); //noi18n */

1505        ArgChecker.checkValid(resourceType, "resourceType",
1506                              StringValidator.getInstance()); //noi18n
1507

1508        try
1509        {
1510            sLogger.log(Level.FINE, "mbean.create_resource", jndiName);
1511            ConfigContext serverContext = getConfigContext(mInstanceName);
1512            Resources resourcesBean =
1513                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1514                                            ServerXPathHelper.XPATH_RESOURCES);
1515        JmsRaMapping ramap = ConnectorRuntime.getRuntime().getJmsRaMapping();
1516
1517                /* Map MQ properties to Resource adapter properties */
1518        Enumeration JavaDoc en = props.keys();
1519        Properties JavaDoc properties = new Properties JavaDoc();
1520            while (en.hasMoreElements()) {
1521            String JavaDoc key = (String JavaDoc) en.nextElement();
1522            String JavaDoc raKey = ramap.getMappedName(key);
1523            if (raKey == null) raKey = key;
1524            properties.put(raKey, (String JavaDoc) props.get(key));
1525        }
1526
1527                // Add a connector-connection-pool & a connector-resource
1528
String JavaDoc raName = ConnectorRuntime.getRuntime().DEFAULT_JMS_ADAPTER;
1529
1530                if (resourceType.equalsIgnoreCase("javax.jms.TopicConnectionFactory") ||
1531                    resourceType.equalsIgnoreCase("javax.jms.QueueConnectionFactory"))
1532                {
1533                    String JavaDoc defPoolName = ConnectorRuntime.getRuntime().getDefaultPoolName(jndiName);
1534                    com.sun.enterprise.config.serverbeans.ConnectorConnectionPool conPool =
1535                        new com.sun.enterprise.config.serverbeans.ConnectorConnectionPool();
1536                    conPool.setResourceAdapterName(raName);
1537                    conPool.setConnectionDefinitionName(resourceType);
1538                    conPool.setName(defPoolName);
1539                    conPool.setMaxPoolSize("250");
1540                    conPool.setSteadyPoolSize("1");
1541                    resourcesBean.addConnectorConnectionPool(conPool);
1542                    
1543                    // Add connector-resource
1544
com.sun.enterprise.config.serverbeans.ConnectorResource resource =
1545                        new com.sun.enterprise.config.serverbeans.ConnectorResource();
1546                    resource.setJndiName(jndiName);
1547                    resource.setPoolName(defPoolName);
1548                    //if (description != null) resource.setDescription(description);
1549
//resource.setEnabled(true);
1550
// Add the property elements.
1551
if (properties != null) {
1552                        Enumeration JavaDoc e = properties.keys();
1553                        String JavaDoc n,v;
1554                        ElementProperty el = null;
1555                        while (e.hasMoreElements()) {
1556                            n = (String JavaDoc) e.nextElement();
1557                            v = (String JavaDoc) properties.get(n);
1558                            el = new ElementProperty();
1559                el.setName(n);
1560                            el.setValue(v);
1561                            conPool.addElementProperty(el);
1562                        }
1563                    }
1564                    resourcesBean.addConnectorResource(resource);
1565                createResourceRef(jndiName);
1566                }
1567                else {
1568                    // create admin object
1569
addAdminObject(resourceType, properties, raName, jndiName);
1570                }
1571                
1572            serverContext.flush();
1573
1574        }
1575        catch (Exception JavaDoc e)
1576        {
1577            sLogger.log(Level.WARNING, "mbean.create_resource_failed", e);
1578            throw new AFResourceException(e.getLocalizedMessage());
1579        }
1580    }
1581
1582
1583    private void addJMSResourceAttribute(Resource resource,
1584                                         Properties JavaDoc attributes,
1585                                         String JavaDoc jndiName)
1586                 throws AFResourceException
1587    {
1588/*
1589        //adding rest of the attributes
1590        try
1591        {
1592            ConfigContext serverContext = getConfigContext(mInstanceName);
1593            Resources resourcesBean =
1594                     (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1595                      ServerXPathHelper.XPATH_RESOURCES);
1596            JmsResource jms_resource =
1597                        resourcesBean.getJmsResourceByJndiName(jndiName);
1598//ms1 String enabledName =
1599//ms1 attributes.getProperty( ResourcesXMLParser.ENABLED);
1600//ms1 if (enabledName != null) {
1601//ms1 jms_resource.setEnabled(Boolean.valueOf(enabledName).booleanValue());
1602//ms1 }
1603            //description
1604            String sDescription = resource.getDescription();
1605            if (sDescription != null) {
1606                jms_resource.setDescription(sDescription);
1607            }
1608            //element property
1609                ElementProperty[] epArray = resource.getElementProperty();
1610            if (epArray != null) {
1611                for (int ii=0; ii<epArray.length; ii++)
1612                   jms_resource.addElementProperty(epArray[ii]);
1613            }
1614
1615            serverContext.flush();
1616        }
1617        catch (Exception e)
1618        {
1619            throw new AFResourceException(e.getLocalizedMessage());
1620        }
1621*/

1622    }
1623
1624 
1625   public void deleteJMSResource(String JavaDoc jndiName)
1626        throws AFResourceException
1627    {
1628        ArgChecker.checkValid(jndiName, "jndiName",
1629                              StringValidator.getInstance()); //noi18n
1630
try
1631        {
1632                // delete the connector-resource & its pool if the resource is referencing
1633
// its default jms connector connection pool.
1634
ConfigContext serverContext = getConfigContext(mInstanceName);
1635                Resources resourcesBean =
1636                    (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1637                                                ServerXPathHelper.XPATH_RESOURCES);
1638                com.sun.enterprise.config.serverbeans.ConnectorResource resource =
1639                    resourcesBean.getConnectorResourceByJndiName(jndiName);
1640
1641                if (resource == null)
1642                {
1643                    // delete any admin objects with this jndi name
1644
deleteAdminObject(jndiName);
1645                /*
1646                    String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName );
1647                    throw new Exception( msg );
1648                */

1649                } else {
1650                    String JavaDoc defPoolName = ConnectorRuntime.getRuntime().getDefaultPoolName(jndiName);
1651                    if (resource.getPoolName().equals(defPoolName)) {
1652                        resourcesBean.removeConnectorResource(resource);
1653                        deleteConnectorConnectionPool(defPoolName);
1654                    }
1655            }
1656                
1657                serverContext.flush();
1658        }
1659        catch (Exception JavaDoc e)
1660        {
1661            sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e);
1662            throw new AFResourceException(e.getLocalizedMessage());
1663        }
1664    }
1665
1666
1667    public String JavaDoc[] listJMSResources() throws AFException
1668    {
1669        String JavaDoc[] sa = null;
1670/*
1671        try
1672        {
1673            sLogger.log(Level.FINE, "mbean.list_components");
1674            ConfigContext serverContext = getConfigContext(mInstanceName);
1675            Resources resourcesBean =
1676                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1677                                            ServerXPathHelper.XPATH_RESOURCES);
1678            JmsResource[] jmsResources = resourcesBean.getJmsResource();
1679            if (jmsResources != null)
1680            {
1681                sa = new String[jmsResources.length];
1682                for(int i=0; i<jmsResources.length; i++)
1683                {
1684                    sa[i] = jmsResources[i].getJndiName();
1685                }
1686            }
1687        }
1688        catch (Exception e)
1689        {
1690            sLogger.log(Level.WARNING, "mbean.list_failed", e);
1691            throw new AFException(e.getLocalizedMessage());
1692        }
1693        return sa;
1694*/

1695    return null;
1696    }
1697
1698    public void createJNDIResource(String JavaDoc jndiName,
1699                                   String JavaDoc jndiLookupName,
1700                                   String JavaDoc resourceType,
1701                                   String JavaDoc factoryClass)
1702        throws AFResourceException
1703    {
1704        ArgChecker.checkValid(jndiName, "jndiName",
1705                              StringValidator.getInstance()); //noi18n
1706
ArgChecker.checkValid(jndiLookupName, "jndiLookupName",
1707                              StringValidator.getInstance()); //noi18n
1708
ArgChecker.checkValid(resourceType, "resourceType",
1709                              StringValidator.getInstance()); //noi18n
1710
ArgChecker.checkValid(factoryClass, "factoryClass",
1711                              StringValidator.getInstance()); //noi18n
1712

1713        try
1714        {
1715            sLogger.log(Level.FINE, "mbean.create_resource", jndiName);
1716            ConfigContext serverContext = getConfigContext(mInstanceName);
1717            Resources resourcesBean =
1718                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1719                                            ServerXPathHelper.XPATH_RESOURCES);
1720            ExternalJndiResource resource =
1721                new ExternalJndiResource();
1722            resource.setJndiName(jndiName);
1723            resource.setJndiLookupName(jndiLookupName);
1724            resource.setResType(resourceType);
1725            resource.setFactoryClass(factoryClass);
1726//ms1 resource.setEnabled(true);
1727
resourcesBean.addExternalJndiResource(resource);
1728        createResourceRef(jndiName);
1729            serverContext.flush();
1730
1731        }
1732        catch (Exception JavaDoc e)
1733        {
1734            sLogger.log(Level.WARNING, "mbean.create_resource_failed", e);
1735            throw new AFResourceException(e.getLocalizedMessage());
1736        }
1737    }
1738
1739    private void addJNDIResourceAttribute(Resource resource,
1740                                          Properties JavaDoc attributes,
1741                                          String JavaDoc jndiName)
1742                 throws AFResourceException
1743    {
1744        try
1745        {
1746            ConfigContext serverContext = getConfigContext(mInstanceName);
1747            Resources resourcesBean =
1748                      (Resources)ConfigBeansFactory.getConfigBeanByXPath(
1749                       serverContext,
1750                       ServerXPathHelper.XPATH_RESOURCES);
1751            ExternalJndiResource jndi_resource =
1752                                 resourcesBean.getExternalJndiResourceByJndiName(jndiName);
1753//ms1 String sEnabled =
1754
//ms1 attributes.getProperty(ResourcesXMLParser.ENABLED);
1755
//ms1 if (sEnabled != null) {
1756
//ms1 jndi_resource.setEnabled(Boolean.valueOf(sEnabled).booleanValue());
1757
//ms1 }
1758
//description
1759
String JavaDoc sDescription = resource.getDescription();
1760            if (sDescription != null) {
1761                jndi_resource.setDescription(sDescription);
1762            }
1763            //element property
1764
ElementProperty[] epArray = resource.getElementProperty();
1765            if (epArray != null) {
1766                for (int ii=0; ii<epArray.length; ii++)
1767                   jndi_resource.addElementProperty(epArray[ii]);
1768            }
1769            serverContext.flush();
1770        }
1771        catch (Exception JavaDoc e)
1772        {
1773            throw new AFResourceException(e.getLocalizedMessage());
1774        }
1775    }
1776
1777    public void deleteJNDIResource(String JavaDoc jndiName) throws AFResourceException
1778    {
1779        ArgChecker.checkValid(jndiName, "jndiName",
1780                              StringValidator.getInstance()); //noi18n
1781
try
1782        {
1783            sLogger.log(Level.FINE, "mbean.delete_resource", jndiName);
1784            ConfigContext serverContext = getConfigContext(mInstanceName);
1785            Resources resourcesBean =
1786                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1787                                            ServerXPathHelper.XPATH_RESOURCES);
1788            ExternalJndiResource resource =
1789                resourcesBean.getExternalJndiResourceByJndiName(jndiName);
1790            //Bug# 4682650
1791
if (resource == null)
1792            {
1793                String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName );
1794                throw new Exception JavaDoc( msg );
1795            }
1796            resourcesBean.removeExternalJndiResource(resource);
1797            deleteResourceRef(jndiName);
1798            serverContext.flush();
1799        }
1800        catch (Exception JavaDoc e)
1801        {
1802            sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e);
1803            throw new AFResourceException(e.getLocalizedMessage());
1804        }
1805    }
1806
1807    public String JavaDoc[] listJNDIResources() throws AFException
1808    {
1809        String JavaDoc[] sa = null;
1810        try
1811        {
1812            sLogger.log(Level.FINE, "mbean.list_components");
1813            ConfigContext serverContext = getConfigContext(mInstanceName);
1814            Resources resourcesBean =
1815                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1816                                            ServerXPathHelper.XPATH_RESOURCES);
1817            ExternalJndiResource[] jndiResources = resourcesBean.getExternalJndiResource();
1818            if (jndiResources != null)
1819            {
1820                sa = new String JavaDoc[jndiResources.length];
1821                for(int i=0; i<jndiResources.length; i++)
1822                {
1823                    sa[i] = jndiResources[i].getJndiName();
1824                }
1825            }
1826        }
1827        catch (Exception JavaDoc e)
1828        {
1829            sLogger.log(Level.WARNING, "mbean.list_failed", e);
1830            throw new AFException(e.getLocalizedMessage());
1831        }
1832        return sa;
1833    }
1834
1835    /**
1836     */

1837    public void createPersistenceManagerFactoryResource(String JavaDoc jndiName)
1838        throws AFResourceException
1839    {
1840        ArgChecker.checkValid(jndiName, "jndiName",
1841                              StringValidator.getInstance()); //noi18n
1842

1843        try
1844        {
1845            sLogger.log(Level.FINE, "mbean.create_resource", jndiName);
1846            ConfigContext serverContext = getConfigContext(mInstanceName);
1847            Resources resourcesBean =
1848                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1849                                            ServerXPathHelper.XPATH_RESOURCES);
1850            PersistenceManagerFactoryResource resource =
1851                new PersistenceManagerFactoryResource();
1852            resource.setJndiName(jndiName);
1853            //resource.setFactoryClass(factoryClassName);
1854
//resource.setJdbcResourceJndiName(jdbcResJndiName);
1855
//ms1 resource.setEnabled(true);
1856
resourcesBean.addPersistenceManagerFactoryResource(resource);
1857        createResourceRef(jndiName);
1858            serverContext.flush();
1859
1860        }
1861        catch (Exception JavaDoc e)
1862        {
1863            sLogger.log(Level.WARNING, "mbean.create_resource_failed", e);
1864            throw new AFResourceException(e.getLocalizedMessage());
1865        }
1866    }
1867
1868    private void addPersistenceManagerFactoryAttribute(Resource resource,
1869                                                       Properties JavaDoc attributes,
1870                                                       String JavaDoc jndiName)
1871                 throws AFResourceException
1872    {
1873        try
1874        {
1875            ConfigContext serverContext = getConfigContext(mInstanceName);
1876            Resources resourcesBean =
1877                      (Resources)ConfigBeansFactory.getConfigBeanByXPath(
1878                      serverContext,
1879                      ServerXPathHelper.XPATH_RESOURCES);
1880            PersistenceManagerFactoryResource pmf_resource =
1881                      resourcesBean.getPersistenceManagerFactoryResourceByJndiName(jndiName);
1882            String JavaDoc factoryClass =
1883                   attributes.getProperty(ResourcesXMLParser.FACTORY_CLASS);
1884            String JavaDoc resName =
1885                   attributes.getProperty(ResourcesXMLParser.JDBC_RESOURCE_JNDI_NAME);
1886            String JavaDoc sEnabled =
1887                   attributes.getProperty(ResourcesXMLParser.ENABLED);
1888            if (factoryClass != null) {
1889                pmf_resource.setFactoryClass(factoryClass);
1890            }
1891            if (resName != null) {
1892                pmf_resource.setJdbcResourceJndiName(resName);
1893            }
1894//ms1 if (sEnabled != null) {
1895
//ms1 pmf_resource.setEnabled(Boolean.valueOf(sEnabled).booleanValue());
1896
//ms1 }
1897
//description
1898
String JavaDoc sDescription = resource.getDescription();
1899            if (sDescription != null) {
1900                pmf_resource.setDescription(sDescription);
1901            }
1902            //element property
1903
ElementProperty[] epArray = resource.getElementProperty();
1904            if (epArray != null) {
1905                for (int ii=0; ii<epArray.length; ii++)
1906                   pmf_resource.addElementProperty(epArray[ii]);
1907            }
1908            serverContext.flush();
1909        }
1910        catch (Exception JavaDoc e)
1911        {
1912            throw new AFResourceException(e.getLocalizedMessage());
1913        }
1914    }
1915
1916    public void deletePersistenceManagerFactoryResource(String JavaDoc jndiName)
1917        throws AFResourceException
1918    {
1919        ArgChecker.checkValid(jndiName, "jndiName",
1920                              StringValidator.getInstance()); //noi18n
1921
try
1922        {
1923            sLogger.log(Level.FINE, "mbean.delete_resource", jndiName);
1924            ConfigContext serverContext = getConfigContext(mInstanceName);
1925            Resources resourcesBean =
1926                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1927                                            ServerXPathHelper.XPATH_RESOURCES);
1928            PersistenceManagerFactoryResource resource = resourcesBean.
1929                getPersistenceManagerFactoryResourceByJndiName(jndiName);
1930            //Bug# 4682650
1931
if (resource == null)
1932            {
1933                String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource" );
1934                throw new Exception JavaDoc( msg );
1935            }
1936            resourcesBean.removePersistenceManagerFactoryResource(resource);
1937            deleteResourceRef(jndiName);
1938            serverContext.flush();
1939        }
1940        catch (Exception JavaDoc e)
1941        {
1942            sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e);
1943            throw new AFResourceException(e.getLocalizedMessage());
1944        }
1945    }
1946
1947    public String JavaDoc[] listPersistenceManagerFactoryResources()
1948        throws AFException
1949    {
1950        String JavaDoc[] sa = null;
1951        try
1952        {
1953            sLogger.log(Level.FINE, "mbean.list_components");
1954            ConfigContext serverContext = getConfigContext(mInstanceName);
1955            Resources resourcesBean =
1956                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1957                                            ServerXPathHelper.XPATH_RESOURCES);
1958            PersistenceManagerFactoryResource[] pmFactoryResources =
1959                resourcesBean.getPersistenceManagerFactoryResource();
1960            if (pmFactoryResources != null)
1961            {
1962                sa = new String JavaDoc[pmFactoryResources.length];
1963                for(int i=0; i<pmFactoryResources.length; i++)
1964                {
1965                    sa[i] = pmFactoryResources[i].getJndiName();
1966                }
1967            }
1968        }
1969        catch (Exception JavaDoc e)
1970        {
1971            sLogger.log(Level.WARNING, "mbean.list_failed", e);
1972            throw new AFException(e.getLocalizedMessage());
1973        }
1974        return sa;
1975    }
1976
1977    public void createCustomResource(String JavaDoc jndiName,
1978                                     String JavaDoc resourceType,
1979                                     String JavaDoc factoryClass)
1980        throws AFResourceException
1981    {
1982        ArgChecker.checkValid(jndiName, "jndiName",
1983                              StringValidator.getInstance()); //noi18n
1984
ArgChecker.checkValid(factoryClass, "factoryClass",
1985                              StringValidator.getInstance()); //noi18n
1986
ArgChecker.checkValid(resourceType, "resourceType",
1987                              StringValidator.getInstance()); //noi18n
1988

1989        try
1990        {
1991            sLogger.log(Level.FINE, "mbean.create_resource", jndiName);
1992            ConfigContext serverContext = getConfigContext(mInstanceName);
1993            Resources resourcesBean =
1994                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
1995                                            ServerXPathHelper.XPATH_RESOURCES);
1996            CustomResource resource = new CustomResource();
1997            resource.setJndiName(jndiName);
1998            resource.setResType(resourceType);
1999            resource.setFactoryClass(factoryClass);
2000//ms1 resource.setEnabled(true);
2001
resourcesBean.addCustomResource(resource);
2002        createResourceRef(jndiName);
2003            serverContext.flush();
2004        }
2005        catch (Exception JavaDoc e)
2006        {
2007            sLogger.log(Level.WARNING, "mbean.create_resource_failed", e);
2008            throw new AFResourceException(e.getLocalizedMessage());
2009        }
2010    }
2011
2012    private void addCustomResourceAttribute(Resource resource,
2013                                            Properties JavaDoc attributes,
2014                                            String JavaDoc jndiName)
2015                 throws AFResourceException
2016    {
2017        try
2018        {
2019            ConfigContext serverContext = getConfigContext(mInstanceName);
2020            Resources resourcesBean =
2021            (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
2022                       ServerXPathHelper.XPATH_RESOURCES);
2023            CustomResource custom_resource =
2024                           resourcesBean.getCustomResourceByJndiName(jndiName);
2025            String JavaDoc sEnabled =
2026                   attributes.getProperty(ResourcesXMLParser.ENABLED);
2027//ms1 if (sEnabled != null) {
2028
//ms1 custom_resource.setEnabled(Boolean.valueOf(sEnabled).booleanValue());
2029
//ms1 }
2030
//description
2031
String JavaDoc sDescription = resource.getDescription();
2032            if (sDescription != null) {
2033                custom_resource.setDescription(sDescription);
2034            }
2035            //element property
2036
ElementProperty[] epArray = resource.getElementProperty();
2037            if (epArray != null) {
2038                for (int ii=0; ii<epArray.length; ii++)
2039                   custom_resource.addElementProperty(epArray[ii]);
2040            }
2041            serverContext.flush();
2042        }
2043        catch (Exception JavaDoc e)
2044        {
2045            throw new AFResourceException(e.getLocalizedMessage());
2046        }
2047    }
2048
2049    public void deleteCustomResource(String JavaDoc jndiName)
2050        throws AFResourceException
2051    {
2052        ArgChecker.checkValid(jndiName, "jndiName",
2053                              StringValidator.getInstance()); //noi18n
2054
try
2055        {
2056            sLogger.log(Level.FINE, "mbean.delete_resource", jndiName);
2057            ConfigContext serverContext = getConfigContext(mInstanceName);
2058            Resources resourcesBean =
2059                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
2060                                            ServerXPathHelper.XPATH_RESOURCES);
2061            CustomResource resource =
2062                resourcesBean.getCustomResourceByJndiName(jndiName);
2063            //Bug# 4682650
2064
if (resource == null)
2065            {
2066                String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName );
2067                throw new Exception JavaDoc( msg );
2068            }
2069            resourcesBean.removeCustomResource(resource);
2070            deleteResourceRef(jndiName);
2071            serverContext.flush();
2072        }
2073        catch (Exception JavaDoc e)
2074        {
2075            sLogger.log(Level.WARNING, "mbean.delete_resource_failed", e);
2076            throw new AFResourceException(e.getLocalizedMessage());
2077        }
2078    }
2079
2080    public String JavaDoc[] listCustomResources() throws AFException
2081    {
2082        String JavaDoc[] sa = null;
2083        try
2084        {
2085            sLogger.log(Level.FINE, "mbean.list_components");
2086            ConfigContext serverContext = getConfigContext(mInstanceName);
2087            Resources resourcesBean =
2088                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
2089                                            ServerXPathHelper.XPATH_RESOURCES);
2090            CustomResource[] customResources = resourcesBean.getCustomResource();
2091            if (customResources != null)
2092            {
2093                sa = new String JavaDoc[customResources.length];
2094                for(int i=0; i<customResources.length; i++)
2095                {
2096                    sa[i] = customResources[i].getJndiName();
2097                }
2098            }
2099        }
2100        catch (Exception JavaDoc e)
2101        {
2102            sLogger.log(Level.WARNING, "mbean.list_failed", e);
2103            throw new AFException(e.getLocalizedMessage());
2104        }
2105        return sa;
2106    }
2107
2108    /**
2109    */

2110    public void setHttpPort(int port)
2111    {
2112    }
2113
2114    public HostAndPort getHostAndPort() throws ServerInstanceException
2115    {
2116        return getHostAndPort(false);
2117    }
2118        
2119    public HostAndPort getHostAndPort(boolean securityEnabled) throws ServerInstanceException
2120    {
2121        HostAndPort hAndp = null;
2122        try
2123        {
2124//ms1 Server server = (Server) super.getBaseConfigBean();
2125
Config config = (Config) super.getConfigBeanByXPath(ServerXPathHelper.XPATH_CONFIG);
2126            HttpService https = config.getHttpService();
2127
2128            HttpListener[] hlArray = https.getHttpListener();
2129            //check not needed since there should always be atleast 1 httplistener
2130
//if you don't find one, use first one.
2131
HttpListener ls = hlArray[0];
2132            //default is the first one that is enabled.
2133
for(int i = 0;i<hlArray.length;i++) {
2134                if(hlArray[i].isEnabled() && (hlArray[i].isSecurityEnabled()==securityEnabled)) {
2135                    ls = hlArray[i];
2136                    break;
2137                }
2138            }
2139
2140            String JavaDoc port = ls.getPort();
2141            int intPort = Integer.parseInt (port);
2142            hAndp = new HostAndPort(ls.getServerName(), intPort);
2143        }
2144        catch (Exception JavaDoc e)
2145        {
2146            throw new ServerInstanceException(e.getLocalizedMessage());
2147        }
2148        return hAndp;
2149    }
2150
2151    public int getHttpPort()
2152    {
2153        return 9000;
2154    }
2155
2156    public ServerInstanceStatus getStatus() throws ControlException
2157    {
2158        int statusCode = getInstanceStatusCode();
2159        ServerInstanceStatus status = new ServerInstanceStatus(statusCode);
2160        //Bug# 4686443
2161
if (isDebug())
2162        {
2163            status.setDebug(true);
2164            try
2165            {
2166                status.setDebugPort(getDebugPort());
2167            }
2168            catch (Exception JavaDoc e)
2169            {
2170                sLogger.finest
2171                ("Problem with getting port:ManagedServerInstance:getStatus");
2172                throw new ControlException(e.getLocalizedMessage());
2173            }
2174        }
2175        sLogger.exiting(getClass().getName(), "getStatus",
2176                        status.getStatusString()); //noi18n
2177
return ( status );
2178    }
2179
2180    /**
2181     * Is instance restart required. Restart is required if dynamic
2182     * reconfiguration on the instance could not be dones and the user has
2183     * not restarted the instance since then.
2184     */

2185    public boolean isRestartNeeded()
2186    {
2187        AdminEventCache cache = AdminEventCache.getInstance(mInstanceName);
2188        boolean restartRequired = cache.isInstanceRestartNeeded();
2189        if(restartRequired)
2190        {
2191            RMIClient rc = AdminChannel.getRMIClient(mInstanceName);
2192            if(!rc.isAlive())
2193                restartRequired = false;
2194        }
2195        return restartRequired;
2196    }
2197
2198    private boolean isAlive()
2199    {
2200        boolean alive = false;
2201        RMIClient serverInstancePinger = AdminChannel.
2202                getRMIClient(mInstanceName);
2203
2204        alive = serverInstancePinger.isAlive();
2205        return ( alive );
2206    }
2207
2208    private int getInstanceStatusCode() {
2209        int statusCode = Status.kInstanceNotRunningCode;
2210        RMIClient serverInstancePinger = AdminChannel.getRMIClient(mInstanceName);
2211        statusCode = serverInstancePinger.getInstanceStatusCode();
2212        return statusCode;
2213    }
2214
2215    /**
2216        Issues a notification to this Server Instance, so that it reads the
2217        configuration file. It may be that the modified
2218        configuration can't be completely applied to the Server Instance
2219        without restarting it. In such cases, the user has to restart it.
2220        The configuration parameters that do not require the Instance restart
2221        will take effect immediately.
2222    */

2223    public void reconfigure()
2224    {
2225    }
2226
2227    /**
2228     * Is apply needed to publish changes in backup area to live config.
2229     * The method returns true if there are changes to server.xml, init.conf,
2230     * obj.conf or mime types fules in backup area.
2231     */

2232
2233    public boolean isApplyNeeded() throws ServerInstanceException
2234    {
2235        return isApplyNeeded(true);
2236    }
2237
2238
2239    /**
2240     * checkAllFiles: if false will only check server xml for changes
2241     * if true will check all files server.xml, conf, mime.type, acl etc files
2242     */

2243    public boolean isApplyNeeded(boolean checkAllFiles) throws ServerInstanceException
2244    {
2245        boolean applyNeeded = false;
2246        try
2247        {
2248            ConfigContext serverContext = getConfigContext(mInstanceName);
2249            applyNeeded = serverContext.isChanged();
2250        }
2251        catch (ConfigException e)
2252        {
2253            throw new ServerInstanceException(e.getMessage());
2254        }
2255        if (!applyNeeded && checkAllFiles) {
2256            InstanceEnvironment ie = new InstanceEnvironment(mInstanceName);
2257            applyNeeded = ie.hasRealmsKeyConfFileChanged();
2258        }
2259        return applyNeeded;
2260    }
2261
2262    /**
2263     * Copies the file from backup directory to the real config directory
2264     * so that the configuration is stored on disk.
2265     * There is no guarantee of any transactional support.
2266     * @return true: restart is required.
2267     */

2268    public boolean overwriteConfigChanges() throws ServerInstanceException
2269    {
2270        try {
2271            return applyChanges(true);
2272    } catch (AFRuntimeStoreException e) {
2273            InstanceEnvironment ie = new InstanceEnvironment(mInstanceName);
2274
2275             if(ie.canReloadManualXmlChanges()) {
2276        try {
2277                    ie.useManualServerXmlChanges();
2278                    reloadAfterChange(ie);
2279        } catch(ConfigException ce) {
2280            // Sorry cant do anything.
2281
}
2282                return true;
2283             } else {
2284        throw e;
2285         }
2286    }
2287
2288    }
2289    /**
2290     * Copies the file from backup directory to the real config directory
2291     * so that the configuration is stored on disk.
2292     * There is no guarantee of any transactional support.
2293     * @return True means requires restart.
2294     */

2295    public boolean applyConfigChanges() throws ServerInstanceException
2296    {
2297        return applyChanges(false);
2298    }
2299
2300    private boolean applyChanges(boolean force) throws ServerInstanceException
2301    {
2302        boolean requiresRestart = false;
2303        try
2304        {
2305            InstanceEnvironment instanceEnv = new InstanceEnvironment(mInstanceName);
2306            /* TOMCAT_BEGIN Ramakanth*/
2307            boolean hasConfChanges = false;
2308            boolean hasMimeChanges = false;
2309            hasConfChanges = instanceEnv.hasRealmsKeyConfFileChanged();
2310            /* TOMCAT_END Ramakanth*/
2311
2312            instanceEnv.applyChangesFromBackup(force);
2313            // multicastEvent(CONFIG_CHANGED, null);
2314
/* New for 8.0 - temporary - gen server.xml b4 notif */
2315            /* This call most likely goes away */
2316            this.transform(instanceEnv);
2317            /* New for 8.0 - temporary - gen server.xml b4 notif */
2318            
2319            /* TOMCAT_BEGIN Ramakanth*/
2320            requiresRestart = sendNotificationOnApply(hasConfChanges, hasMimeChanges);
2321            /* TOMCAT_END Ramakanth*/
2322        }
2323        catch (ConfigException e)
2324        {
2325            throw new ServerInstanceException(e.getMessage());
2326        }
2327        return requiresRestart;
2328    }
2329
2330    public boolean canApplyConfigChanges() throws ConfigException {
2331        boolean b = false;
2332        InstanceEnvironment ie = new InstanceEnvironment(mInstanceName);
2333        if(AdminService.ENABLE_PERFORMANCE_THREAD) {
2334            b = (!ManualChangeManager.hasHotChanged(mInstanceName));
2335        } else {
2336            b = (!ie.hasHotChanged());
2337        }
2338        if((!b) && ie.canReloadManualXmlChanges()) {
2339            ie.useManualServerXmlChanges();
2340            reloadAfterChange(ie);
2341            boolean requiresRestart = ie.restartRequired();
2342            if (requiresRestart) {
2343                // The instance was not started after manual config changes, so
2344
// persist the restart required state.
2345
AdminEventCache cache =
2346                        AdminEventCache.getInstance(mInstanceName);
2347                cache.setRestartNeeded(true);
2348            }
2349            return true;
2350        }
2351        return b;
2352    }
2353
2354    void reloadAfterChange(InstanceEnvironment instanceEnv) throws ConfigException
2355    {
2356        // 2. unregister all instance related mbeans
2357
MBeanServer JavaDoc mbs = MBeanServerFactory.getMBeanServer();
2358        ObjectName JavaDoc[] objectNames = ObjectNameHelper.getInstanceRelatedMBeans(mbs, mInstanceName);
2359        for(int i=0; i<objectNames.length; i++)
2360        {
2361            try
2362            {
2363                mbs.unregisterMBean(objectNames[i]);
2364            }
2365            catch(Exception JavaDoc e)
2366            {
2367                sLogger.log(Level.WARNING, "Exception: ", e);
2368            }
2369        }
2370        // 3. Message to Config to refresh contexts
2371
String JavaDoc fileUrl = instanceEnv.getBackupConfigFilePath();
2372        ConfigFactory.removeConfigContext(fileUrl);
2373
2374            /*
2375            //Refresh true is a poor man's solution
2376            ConfigContext ctx = ConfigFactory.createConfigContext(instanceEnv.getBackupConfigFilePath());
2377            ctx.refresh(true);
2378             */

2379    }
2380
2381    public boolean useManualConfigChanges() throws ServerInstanceException
2382    {
2383        boolean requiresRestart = false;
2384        try
2385        {
2386            InstanceEnvironment instanceEnv = new InstanceEnvironment(mInstanceName);
2387
2388            // 1. copy from hot to back
2389
instanceEnv.useManualConfigChanges();
2390
2391            reloadAfterChange(instanceEnv);
2392
2393            // multicastEvent(CONFIG_CHANGED, null);
2394
/* New for 8.0 - temporary */
2395            this.transform(instanceEnv);
2396            /* New for 8.0 - temporary */
2397            requiresRestart = instanceEnv.restartRequired();
2398            if (requiresRestart) {
2399                // The instance was not started after manual config changes, so
2400
// persist the restart required state.
2401
AdminEventCache cache =
2402                        AdminEventCache.getInstance(mInstanceName);
2403                cache.setRestartNeeded(true);
2404            }
2405        }
2406        catch (ConfigException e)
2407        {
2408            throw new ServerInstanceException(e.getMessage());
2409        }
2410        return requiresRestart;
2411    }
2412    /**
2413        Initiates the monitoring process for this Server Instance. Note that
2414        various components within the Server Instance will actually provide
2415        the monitoring data. This method however establishes the underlying
2416        infrastructure and basic configuration of monitoring system. Following
2417        are the essential things accomplished by this method:
2418        <li> Establish the live monitor connection with running Server Instance.
2419        <li> Read the configuration store to know the various components
2420            that can be monitored. (e.g. EJB Container, Web Container etc.)
2421        <li> Register one MonitorMBean per monitorable component
2422            in Admin Server's MBeanServer.
2423        <li> Instruct all the core containers to prepare for giving out the
2424            named monitoring data.
2425        <p>
2426        Object Name of each Monitor MBean is:
2427        ias:type=monitor, MonitorComponent=<ComponentName>
2428    */

2429    public void startMonitor()
2430    {
2431    }
2432
2433    /**
2434        Gets a list of names of components that are monitorable. This will
2435        most likely be stored in a configuration store.
2436
2437        @return String[] list of names of monitorable components
2438    */

2439    public String JavaDoc[] getMonitorableComponentNames()
2440    {
2441        return ( null );
2442    }
2443
2444    /**
2445        Stops the monitoring process for this Server Instance. Following are
2446        the consequences of this:
2447        <li> deregister all the Monitor MBeans.
2448        <li> Instruct all the monitoring data releasing core containers
2449            to stop releasing data.
2450        <li> Release the monitor link between Admin Server and this Server
2451        Instance.
2452    */

2453    public void stopMonitor()
2454    {
2455    }
2456
2457    /**
2458     */

2459    public void createLifeCycleModule(String JavaDoc moduleName, String JavaDoc className)
2460        throws AFException
2461    {
2462        ArgChecker.checkValid(moduleName, "moduleName",
2463                              StringValidator.getInstance()); //noi18n
2464
ArgChecker.checkValid(className, "className",
2465                              StringValidator.getInstance()); //noi18n
2466

2467        try
2468        {
2469            sLogger.log(Level.FINEST, "mbean.create_lifecycle", moduleName);
2470            ConfigContext serverContext = getConfigContext(mInstanceName);
2471            Applications applicationsConfigBean =
2472                (Applications) ConfigBeansFactory.getConfigBeanByXPath(
2473                    serverContext,
2474                    ServerXPathHelper.XPATH_APPLICATIONS);
2475            LifecycleModule module = new LifecycleModule();
2476            module.setName(moduleName);
2477            module.setClassName(className);
2478//ms1 module.setEnabled(true); //Enabling by default
2479
applicationsConfigBean.addLifecycleModule(module);
2480        createResourceRef(moduleName);
2481            serverContext.flush();
2482        }
2483        catch (Exception JavaDoc e)
2484        {
2485            sLogger.log(Level.WARNING, "mbean.create_lifecycle_failed", e);
2486            throw new AFException(e.getMessage());
2487        }
2488    }
2489
2490    /**
2491     */

2492    public void deleteLifeCycleModule(String JavaDoc moduleName) throws AFException
2493    {
2494        ArgChecker.checkValid(moduleName, "moduleName",
2495                              StringValidator.getInstance()); //noi18n
2496
try
2497        {
2498            sLogger.log(Level.FINEST, "mbean.delete_lifecycle", moduleName);
2499            ConfigContext serverContext = getConfigContext(mInstanceName);
2500            Applications applicationsConfigBean =
2501                (Applications) ConfigBeansFactory.getConfigBeanByXPath(
2502                    serverContext,
2503                    ServerXPathHelper.XPATH_APPLICATIONS);
2504            LifecycleModule module =
2505                applicationsConfigBean.getLifecycleModuleByName(moduleName);
2506            applicationsConfigBean.removeLifecycleModule(module);
2507            deleteResourceRef(moduleName);
2508            serverContext.flush();
2509        }
2510        catch (Exception JavaDoc e)
2511        {
2512            sLogger.log(Level.WARNING, "mbean.delete_lifecycle_failed", e);
2513            throw new AFException(e.getMessage());
2514        }
2515    }
2516
2517    /**
2518     */

2519    public String JavaDoc[] listLifeCycleModules() throws AFException
2520    {
2521        String JavaDoc[] modules = new String JavaDoc[0];
2522        try
2523        {
2524            sLogger.log(Level.FINEST, "mbean.list_components");
2525            ConfigContext serverContext = getConfigContext(mInstanceName);
2526            Applications applicationsConfigBean =
2527                (Applications) ConfigBeansFactory.getConfigBeanByXPath(
2528                    serverContext,
2529                    ServerXPathHelper.XPATH_APPLICATIONS);
2530            LifecycleModule[] lifecycleConfigBeans =
2531                applicationsConfigBean.getLifecycleModule();
2532            if ((lifecycleConfigBeans != null) &&
2533                (lifecycleConfigBeans.length > 0))
2534            {
2535                modules = new String JavaDoc[lifecycleConfigBeans.length];
2536                for (int i = 0; i < lifecycleConfigBeans.length; i++)
2537                {
2538                    modules[i] = lifecycleConfigBeans[i].getName();
2539                }
2540            }
2541        }
2542        catch (Exception JavaDoc e)
2543        {
2544            sLogger.log(Level.WARNING, "mbean.list_failed", e);
2545            throw new AFException(e.getMessage());
2546        }
2547        return modules;
2548    }
2549
2550    /**
2551     * Returns the location of the client stub jar that is generated by EJBC
2552     * during deployment of the given application.
2553     * @param appName application or module name by which an application
2554     * or an EJB module has been deployed.
2555     * @param int appType The type of the application whether it is an EAR
2556     * or EJB Jar.
2557     * @return Returns the absolute path to the client-stub-jar file.
2558     * @throws AFException
2559     */

2560    public String JavaDoc getClientStubJarLocation(String JavaDoc appName, int appType)
2561        throws AFException
2562    {
2563        ArgChecker.checkValid(appName, "appName", //noi18n
2564
StringValidator.getInstance());
2565        if ((appType != DeploymentConstants.EAR) &&
2566            (appType != DeploymentConstants.EJB))
2567        {
2568            String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.expected_application_type" );
2569            throw new AFException( msg );
2570        }
2571        String JavaDoc clientJarLocation = null;
2572        try
2573        {
2574            ConfigContext serverContext = getConfigContext(mInstanceName);
2575            InstanceEnvironment iEnv = new InstanceEnvironment(mInstanceName);
2576            Applications applicationsConfigBean =
2577                (Applications) ConfigBeansFactory.getConfigBeanByXPath(
2578                    serverContext, ServerXPathHelper.XPATH_APPLICATIONS);
2579            String JavaDoc appLocation = null;
2580            switch (appType)
2581            {
2582                case DeploymentConstants.EAR :
2583                    J2eeApplication app = applicationsConfigBean.
2584                                            getJ2eeApplicationByName(appName);
2585                    AppsManager appsManager = new AppsManager(iEnv);
2586                    appLocation = appsManager.getGeneratedXMLLocation(appName);
2587
2588                    // for upgrade scenario, we fall back to the original
2589
// location
2590
if (appLocation == null ||
2591                        !FileUtils.safeIsDirectory(appLocation)) {
2592                        appLocation = app.getLocation();
2593                    }
2594                    break;
2595                case DeploymentConstants.EJB :
2596                    EjbModule module = applicationsConfigBean.
2597                                            getEjbModuleByName(appName);
2598                    EjbModulesManager ejbManager = new EjbModulesManager(iEnv);
2599                    appLocation = ejbManager.getGeneratedXMLLocation(appName);
2600
2601                    // for upgrade scenario, we fall back to the original
2602
// location
2603
if (appLocation == null ||
2604                        !FileUtils.safeIsDirectory(appLocation)) {
2605                        appLocation = module.getLocation();
2606                    }
2607                    break;
2608            }
2609            clientJarLocation = appLocation + java.io.File.separator +
2610                                appName + AdminConstants.CLIENT_JAR;
2611            sLogger.log(Level.INFO, "mbean.cl_jar_loc", clientJarLocation);
2612        }
2613        catch (Exception JavaDoc e)
2614        {
2615            throw new AFException(e.getLocalizedMessage());
2616        }
2617        return clientJarLocation;
2618    }
2619
2620   /**
2621     * Returns the location of the client stub jar that is generated by EJBC
2622     * during deployment of the given application.
2623     * @param appName application or module name by which an application
2624     * or an EJB module has been deployed.
2625     * @param int appType The type of the application whether it is an EAR
2626     * or EJB Jar.
2627     * @return Returns the absolute path to the client-stub-jar file.
2628     * @throws AFException
2629     */

2630    public String JavaDoc getWsdlFileLocation(String JavaDoc appName, String JavaDoc moduleName, int appType, String JavaDoc wsdlFileUri)
2631        throws AFException
2632    {
2633        ArgChecker.checkValid(appName, "appName", //noi18n
2634
StringValidator.getInstance());
2635        if ((appType != DeploymentConstants.EAR) &&
2636            (appType != DeploymentConstants.EJB) &&
2637            (appType != DeploymentConstants.WAR))
2638        {
2639        String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.expected_application_type" );
2640            throw new AFException( msg );
2641        }
2642        String JavaDoc wsdlFileLocation = null;
2643        try
2644        {
2645            ConfigContext serverContext = getConfigContext(mInstanceName);
2646            InstanceEnvironment iEnv = new InstanceEnvironment(mInstanceName);
2647            Applications applicationsConfigBean =
2648                (Applications) ConfigBeansFactory.getConfigBeanByXPath(
2649                    serverContext, ServerXPathHelper.XPATH_APPLICATIONS);
2650            String JavaDoc appLocation = null;
2651            AbstractArchive moduleArchive = null;
2652            switch (appType)
2653            {
2654                case DeploymentConstants.EAR :
2655                    AppsManager appsManager = new AppsManager(iEnv);
2656                    appLocation = appsManager.getGeneratedXMLLocation(appName);
2657                    if (appLocation == null || !FileUtils.safeIsDirectory(appLocation)) {
2658                        J2eeApplication app = applicationsConfigBean.
2659                                            getJ2eeApplicationByName(appName);
2660                        appLocation = app.getLocation();
2661                    }
2662                    break;
2663                case DeploymentConstants.EJB :
2664                    EjbModulesManager ejbManager = new EjbModulesManager(iEnv);
2665                    appLocation = ejbManager.getGeneratedXMLLocation(appName);
2666                    if (appLocation == null || !FileUtils.safeIsDirectory(appLocation)) {
2667                        EjbModule module = applicationsConfigBean.
2668                                            getEjbModuleByName(appName);
2669                        appLocation = module.getLocation();
2670                    }
2671                    break;
2672                case DeploymentConstants.WAR:
2673                    WebModulesManager webManager = new WebModulesManager(iEnv);
2674                    appLocation = webManager.getGeneratedXMLLocation(appName);
2675                    if (appLocation == null || !FileUtils.safeIsDirectory(appLocation)) {
2676                        WebModule webModule = applicationsConfigBean.
2677                                            getWebModuleByName(appName);
2678                        appLocation = webModule.getLocation();
2679                    }
2680                    break;
2681            }
2682            
2683            FileArchive appArchive = new FileArchive();
2684            appArchive.open(appLocation);
2685            if (moduleName!=null) {
2686                moduleArchive = appArchive.getEmbeddedArchive(moduleName);
2687            } else {
2688                moduleArchive = appArchive;
2689            }
2690            wsdlFileLocation = moduleArchive.getArchiveUri() + java.io.File.separator +
2691                                wsdlFileUri.replace('/', java.io.File.separatorChar);
2692        }
2693        catch (Exception JavaDoc e)
2694        {
2695            throw new AFException(e.getLocalizedMessage());
2696        }
2697        return wsdlFileLocation;
2698    }
2699
2700/* Implementation of MBeanRegistration - STARTS */
2701
2702    /**
2703     * Allows the MBean to perform any operations needed after having been
2704     * registered in the MBean server or after the registration has failed.
2705     *
2706     * @param registrationDone Indicates whether or not the MBean has been successfully registered in
2707     * the MBean server. The value false means that the registration phase has failed.
2708     */

2709    public void postRegister(Boolean JavaDoc registrationDone)
2710    {
2711    }
2712
2713    /**
2714     * Allows the MBean to perform any operations it needs before being registered
2715     * in the MBean server. If the name of the MBean is not specified, the
2716     * MBean can provide a name for its registration. If any exception is
2717     * raised, the MBean will not be registered in the MBean server.
2718     *
2719     * @param server The MBean server in which the MBean will be registered.
2720     * @param name The object name of the MBean.
2721     *
2722     * @return The name of the MBean registered.
2723     *
2724     * @exception java.lang.Exception This exception should be caught by the MBean server and re-thrown
2725     * as an <CODE>MBeanRegistrationException</CODE>.
2726     */

2727    public ObjectName JavaDoc preRegister(MBeanServer JavaDoc server, ObjectName JavaDoc name) throws
2728        Exception JavaDoc
2729    {
2730        ObjectName JavaDoc serverInstanceMBeanObjectName = null;
2731        serverInstanceMBeanObjectName = new ObjectName JavaDoc("ias:type=serverinstance, name=");
2732        return ( serverInstanceMBeanObjectName );
2733    }
2734
2735    /**
2736     * Allows the MBean to perform any operations needed after having been
2737     * de-registered in the MBean server.
2738     */

2739    public void postDeregister()
2740    {
2741    }
2742
2743    /**
2744     * Allows the MBean to perform any operations it needs before being de-registered
2745     * by the MBean server.
2746     *
2747     * @exception java.langException This exception should be caught by the MBean server and re-thrown
2748     * as an <CODE>MBeanRegistrationException</CODE>.
2749     */

2750    public void preDeregister() throws Exception JavaDoc
2751    {
2752    }
2753
2754    /* Implementation of MBeanRegistration - ENDS */
2755
2756    /**
2757            Register the MBean that represents the application and all the other
2758            MBeans within the application.
2759    */

2760
2761    private void registerApplicationMBean(String JavaDoc archiveName)
2762        throws MBeanException JavaDoc
2763    {
2764        ObjectName JavaDoc appObjectName =
2765            ObjectNames.getApplicationObjectName(mInstanceName, archiveName);
2766        MBeanServer JavaDoc mbs = MBeanServerFactory.getMBeanServer();
2767        if (!mbs.isRegistered(appObjectName))
2768        {
2769            try
2770            {
2771                ManagedJ2EEApplication app =
2772                    new ManagedJ2EEApplication(mInstanceName, archiveName,
2773                            this.getAdminContext());
2774
2775                mbs.registerMBean(app, appObjectName);
2776            }
2777            catch (javax.management.InstanceAlreadyExistsException JavaDoc iae)
2778            {
2779                ExceptionUtil.ignoreException(iae);
2780            }
2781            catch (Exception JavaDoc e)
2782            {
2783                throw new MBeanException JavaDoc(e);
2784            }
2785        }
2786    }
2787
2788    private void registerEJBModuleMBean(String JavaDoc archiveName)
2789        throws MBeanException JavaDoc
2790    {
2791        ObjectName JavaDoc moduleObjectName =
2792            ObjectNames.getEjbModuleObjectName(mInstanceName, archiveName);
2793        MBeanServer JavaDoc mbs = MBeanServerFactory.getMBeanServer();
2794        if (!mbs.isRegistered(moduleObjectName))
2795        {
2796            try
2797            {
2798                ManagedStandaloneJ2EEEjbJarModule module =
2799                    new ManagedStandaloneJ2EEEjbJarModule(mInstanceName,
2800                            archiveName, this.getAdminContext());
2801                mbs.registerMBean(module, moduleObjectName);
2802            }
2803            catch (javax.management.InstanceAlreadyExistsException JavaDoc iae)
2804            {
2805                ExceptionUtil.ignoreException(iae);
2806            }
2807            catch (Exception JavaDoc e)
2808            {
2809                throw new MBeanException JavaDoc(e);
2810            }
2811        }
2812    }
2813
2814    private void registerWebModuleMBean(String JavaDoc archiveName)
2815    {
2816        ObjectName JavaDoc moduleObjectName =
2817            ObjectNames.getWebModuleObjectName(mInstanceName, archiveName);
2818        MBeanServer JavaDoc mbs = MBeanServerFactory.getMBeanServer();
2819        if (!mbs.isRegistered(moduleObjectName))
2820        {
2821            /*Debug.println("registerWebModuleMBean " +
2822                          moduleObjectName.toString());
2823            */

2824        }
2825    }
2826
2827    private void registerConnectorModuleMBean(String JavaDoc archiveName)
2828    {
2829        ObjectName JavaDoc moduleObjectName = ObjectNames.getConnectorModuleObjectName(
2830                                        mInstanceName, archiveName);
2831        MBeanServer JavaDoc mbs = MBeanServerFactory.getMBeanServer();
2832        if (!mbs.isRegistered(moduleObjectName))
2833        {
2834            /*Debug.println("registerConnectorModuleMBean " +
2835                          moduleObjectName.toString());
2836            */

2837        }
2838    }
2839
2840    /*
2841    private void unregisterApplicationMBean(String appName)
2842        throws javax.management.InstanceNotFoundException
2843    {
2844        ObjectName appObjectName =
2845            ObjectNames.getApplicationObjectName(mInstanceName, appName);
2846        MBeanServer mbs = MBeanServerFactory.getMBeanServer();
2847        mbs.unregisterMBean(appObjectName);
2848    }
2849
2850    private void unregisterModuleMBean(String moduleName, int moduleType)
2851        throws javax.management.InstanceNotFoundException
2852    {
2853        ObjectName moduleObjectName = null;
2854        switch (moduleType)
2855        {
2856            case DeploymentConstants.EJB :
2857                moduleObjectName = ObjectNames.getEjbModuleObjectName(
2858                                    mInstanceName, moduleName);
2859                break;
2860            case DeploymentConstants.WAR :
2861                moduleObjectName = ObjectNames.getWebModuleObjectName(
2862                                    mInstanceName, moduleName);
2863                break;
2864            case DeploymentConstants.RAR :
2865                moduleObjectName = ObjectNames.getConnectorModuleObjectName(
2866                                    mInstanceName, moduleName);
2867                break;
2868        }
2869        Assert.assertit((moduleObjectName != null), "null object name"); //i18n
2870        MBeanServer mbs = MBeanServerFactory.getMBeanServer();
2871        mbs.unregisterMBean(moduleObjectName);
2872    }
2873    */

2874
2875    ConfigContext getConfigContext(String JavaDoc instanceName)
2876        throws ConfigException
2877    {
2878        /*
2879        InstanceEnvironment instanceEnvironment =
2880            new InstanceEnvironment(instanceName);
2881        */

2882        /*Everything should be set from the backup file */
2883        /*
2884        String fileUrl = instanceEnvironment.getBackupConfigFilePath();
2885        ConfigContext configContext =
2886            ConfigFactory.createConfigContext(fileUrl);
2887        return configContext;
2888        */

2889        return getConfigContext();
2890    }
2891
2892    /**
2893        Get module type string used ModuleDeployEvent using the integer
2894        constants used by deployment backend
2895    */

2896
2897    private String JavaDoc getModuleTypeString(int moduleType)
2898    {
2899        String JavaDoc moduleTypeString = null;
2900        switch (moduleType)
2901        {
2902            case DeploymentConstants.EJB :
2903                moduleTypeString = ModuleDeployEvent.TYPE_EJBMODULE;
2904                break;
2905            case DeploymentConstants.WAR :
2906                moduleTypeString = ModuleDeployEvent.TYPE_WEBMODULE;
2907                break;
2908            case DeploymentConstants.RAR :
2909                moduleTypeString = ModuleDeployEvent.TYPE_CONNECTOR;
2910                break;
2911        }
2912        return moduleTypeString;
2913    }
2914
2915    /**
2916        Convenience method to multicast events. This method is being used to
2917        events other than ModuleDeployEvent.
2918    */

2919
2920    private boolean multicastEvent(int eventType, String JavaDoc entityName)
2921        throws DeploymentException
2922    {
2923        return multicastEvent(eventType, entityName, null);
2924    }
2925
2926    public boolean multicastEvent(int eventType, String JavaDoc entityName,
2927            String JavaDoc moduleType) throws DeploymentException {
2928        return multicastEvent(eventType, entityName, moduleType, false);
2929    }
2930
2931    /**
2932        Multicasts the event to the respective listeners. The listeners are
2933        multicast from here even if the instance is not running. The
2934        AdminEventMulticaster should take care of it.
2935        @return true if the instance is up and event was sent and successfully
2936            handled or if the instance is down, false otherwise.
2937    */

2938    public boolean multicastEvent(int eventType, String JavaDoc entityName,
2939          String JavaDoc moduleType , boolean cascade) throws DeploymentException {
2940        return multicastEvent(eventType, entityName, moduleType, cascade, false, null);
2941    }
2942
2943                                                                                                                                               
2944    /**
2945     * Multicasts the event to the respective listeners. The listeners are
2946     * multicast from here even if the instance is not running. The
2947     * AdminEventMulticaster should take care of it.
2948     * @return true if the instance is up and event was sent and successfully
2949     * handled or if the instance is down, false otherwise.
2950     */

2951    public boolean multicastEvent(int eventType, String JavaDoc entityName,
2952           String JavaDoc moduleType , boolean cascade, boolean forceDeploy, String JavaDoc targetName) throws DeploymentException
2953    {
2954        String JavaDoc name = getInstanceName();
2955        AdminEvent event = null;
2956        EventBuilder builder = new EventBuilder();
2957
2958        //XXX Can we put the following 4 lines be done in the EventBuilder?
2959
EventStack stack = EventContext.getEventStackFromThreadLocal();
2960        ConfigContext ctx = stack.getConfigContext();
2961        stack.setTarget(targetName);
2962        stack.setConfigChangeList(ctx.getConfigChangeList());
2963
2964        try{
2965            if (eventType == BaseDeployEvent.APPLICATION_DEPLOYED)
2966            {
2967                event = builder.createApplicationDeployEvent(
2968                    BaseDeployEvent.DEPLOY, entityName, false, forceDeploy);
2969            }
2970            else if (eventType == BaseDeployEvent.APPLICATION_UNDEPLOYED)
2971            {
2972                event = builder.createApplicationDeployEvent(
2973                    BaseDeployEvent.UNDEPLOY, entityName, cascade, forceDeploy);
2974            }
2975            else if (eventType == BaseDeployEvent.APPLICATION_REDEPLOYED)
2976            {
2977                event = builder.createApplicationDeployEvent(
2978                    BaseDeployEvent.REDEPLOY, entityName, false, forceDeploy);
2979            }
2980            else if (eventType == BaseDeployEvent.MODULE_DEPLOYED)
2981            {
2982                event = builder.createModuleDeployEvent(
2983                    BaseDeployEvent.DEPLOY, entityName, moduleType, cascade, forceDeploy);
2984            }
2985            else if (eventType == BaseDeployEvent.MODULE_UNDEPLOYED)
2986            {
2987                event = builder.createModuleDeployEvent(
2988                    BaseDeployEvent.UNDEPLOY, entityName, moduleType, cascade, forceDeploy);
2989            }
2990            else if (eventType == BaseDeployEvent.MODULE_REDEPLOYED)
2991            {
2992                event = builder.createModuleDeployEvent(
2993                    BaseDeployEvent.REDEPLOY, entityName, moduleType);
2994            }
2995            else if (eventType == BaseDeployEvent.APPLICATION_ENABLE)
2996            {
2997                event = builder.createApplicationDeployEvent(
2998                    BaseDeployEvent.ENABLE, entityName, false, forceDeploy);
2999            }
3000            else if (eventType == BaseDeployEvent.APPLICATION_DISABLE)
3001            {
3002                event = builder.createApplicationDeployEvent(
3003                    BaseDeployEvent.DISABLE, entityName, false, forceDeploy);
3004            }
3005            else if(eventType == BaseDeployEvent.MODULE_ENABLE)
3006            {
3007                event = builder.createModuleDeployEvent(
3008                    BaseDeployEvent.ENABLE, entityName, moduleType, false, forceDeploy);
3009            }
3010            else if(eventType == BaseDeployEvent.MODULE_DISABLE)
3011            {
3012                event = builder.createModuleDeployEvent(
3013                    BaseDeployEvent.DISABLE, entityName, moduleType, false, forceDeploy);
3014            }
3015            else if(eventType == BaseDeployEvent.APPLICATION_REFERENCED)
3016            {
3017                      event = builder.createApplicationDeployEvent(
3018                    BaseDeployEvent.ADD_REFERENCE, entityName, false, forceDeploy);
3019            }
3020            else if(eventType == BaseDeployEvent.APPLICATION_UNREFERENCED)
3021            {
3022                    event = builder.createApplicationDeployEvent(
3023                    BaseDeployEvent.REMOVE_REFERENCE, entityName, false, forceDeploy);
3024            }
3025            else if (eventType == CONFIG_CHANGED)
3026            {
3027                event = builder.createConfigChangeEvent(targetName, null);
3028            }
3029            else
3030            {
3031                String JavaDoc msg =
3032                    localStrings.getString( "admin.server.core.mbean.config.no_such_event",
3033                                            new Integer JavaDoc(eventType) );
3034                throw new RuntimeException JavaDoc( msg );
3035            }
3036        } catch (ConfigException ex) {
3037            DeploymentException de = new DeploymentException(ex.getMessage());
3038            de.initCause(ex);
3039            throw de;
3040        }
3041
3042        //set target destination for the event
3043
if (targetName != null) {
3044            event.setTargetDestination(targetName);
3045        }
3046
3047        /* New for 8.0 - temporary */
3048        this.transform(new InstanceEnvironment(name));
3049        /* New for 8.0 - temporary */
3050
3051        if (event instanceof ApplicationDeployEvent
3052                || event instanceof ModuleDeployEvent) {
3053            AdminEventCache.populateConfigChange(getConfigContext(), event);
3054        }
3055        int statusCode = getInstanceStatusCode();
3056        if (statusCode == Status.kInstanceStoppingCode || statusCode == Status.kInstanceNotRunningCode) {
3057            sLogger.log(Level.INFO, "mbean.inst_down_skip_event", mInstanceName);
3058            return true;
3059        }
3060        if (sLogger.isLoggable(Level.FINEST)) {
3061            sLogger.log(Level.FINEST, "mbean.event_sent", event.getEventInfo());
3062        } else {
3063            sLogger.log(Level.INFO, "mbean.send_event", event.toString());
3064        }
3065
3066        AdminEventResult multicastResult =
3067                AdminEventMulticaster.multicastEvent(event);
3068        sLogger.log(Level.FINE, "mbean.event_res",
3069                multicastResult.getResultCode());
3070        sLogger.log(Level.INFO, "mbean.event_reply",
3071                multicastResult.getAllMessagesAsString());
3072        boolean eventSuccess = true;
3073        if (!AdminEventResult.SUCCESS.equals(multicastResult.getResultCode())) {
3074            AdminEventCache cache =
3075                    AdminEventCache.getInstance(mInstanceName);
3076            cache.setRestartNeeded(true);
3077
3078            // if there is an exception thrown when loading modules
3079
// rethrow the exception
3080
AdminEventListenerException ale = null;
3081            ale = multicastResult.getFirstAdminEventListenerException();
3082            if (ale != null) {
3083                sLogger.log(Level.WARNING, "mbean.event_failed",
3084                    ale.getMessage());
3085                DeploymentException de =
3086                    new DeploymentException(ale.getMessage());
3087                de.initCause(ale);
3088                throw de;
3089            }
3090        }
3091        return eventSuccess;
3092    }
3093
3094    public String JavaDoc getInstanceName() {
3095        return mInstanceName;
3096    }
3097
3098    /**
3099     * Processes the pending events.
3100     * @param confFilesChanged true if cgi changes were done to init.conf,
3101     * or obj.conf
3102     * @param mimeFilesChanged true if cgi changes were done to mime file(s).
3103     * @return Returns true if any of the changes require a server restart,
3104     * false otherwise. If the instance is not running, the method returns
3105     * false. If instance goes down prior to completion of all
3106     * notifications, the method returns true.
3107     */

3108    private boolean sendNotificationOnApply(boolean confFilesChanged,
3109            boolean mimeFilesChanged) throws ConfigException {
3110        ConfigContext context = getConfigContext(mInstanceName);
3111        AdminEventCache cache =
3112                AdminEventCache.getInstance(mInstanceName);
3113        ArrayList JavaDoc changeList = context.getConfigChangeList();
3114        context.resetConfigChangeList();
3115        cache.processConfigChangeList(changeList, confFilesChanged,
3116                mimeFilesChanged);
3117        ArrayList JavaDoc eventList = cache.getAndResetCachedEvents();
3118        if (getInstanceStatusCode() != Status.kInstanceRunningCode) {
3119            sLogger.log(Level.INFO, "mbean.inst_down_skip_event", mInstanceName);
3120            return false;
3121        }
3122        boolean requiresRestart = cache.isInstanceRestartNeeded();
3123        Iterator JavaDoc iter = eventList.iterator();
3124        while (iter.hasNext()) {
3125            AdminEvent event = (AdminEvent)iter.next();
3126            if (sLogger.isLoggable(Level.FINEST)) {
3127                sLogger.log(Level.FINEST, "mbean.event_sent",
3128                        event.getEventInfo());
3129            } else {
3130                sLogger.log(Level.INFO, "mbean.send_event", event.toString());
3131            }
3132            AdminEventResult result = AdminEventMulticaster.multicastEvent(event);
3133            sLogger.log(Level.FINE, "mbean.event_res", result.getResultCode());
3134            sLogger.log(Level.FINEST, "mbean.event_reply",
3135                    result.getAllMessagesAsString());
3136            if (!AdminEventResult.SUCCESS.equals(result.getResultCode()))
3137            {
3138                requiresRestart = true;
3139                cache.setRestartNeeded(true);
3140                // DEBUGing - Mahesh
3141
sLogger.log(Level.INFO, "applyChanges: AdminEventMulticaster.multiCastEvent indicates serverRestart=true , resultCode=" + result.getResultCode(), event.toString());
3142                sLogger.log(Level.WARNING, "mbean.notif_failed");
3143            }
3144        }
3145        return requiresRestart;
3146    }
3147
3148    /**
3149     * Deletes a file from the temporary location.
3150     * Deletes the given file only if it is in the temporary location.
3151     */

3152    private void deleteFile(String JavaDoc filePath)
3153    {
3154        File JavaDoc f = new File JavaDoc(filePath);
3155        if (f.exists())
3156        {
3157            File JavaDoc parentDir = f.getParentFile();
3158            File JavaDoc tmpDir = new File JavaDoc(AdminService.getAdminService().
3159                    getTempDirPath(), mInstanceName);
3160            /* note that the above call may return a null */
3161            if (tmpDir != null && tmpDir.equals(parentDir))
3162            {
3163                boolean couldDelete = f.delete();
3164                if (couldDelete)
3165                {
3166                    sLogger.log(Level.FINE, "mbean.delete_temp_file_ok", filePath);
3167                }
3168                else
3169                {
3170                    sLogger.log(Level.INFO, "mbean.delete_temp_file_failed", filePath);
3171                }
3172            }
3173        }
3174    }
3175
3176    private boolean isAppExists(String JavaDoc appName, int appType)
3177    {
3178        ConfigBean appConfigBean = null;
3179        try
3180        {
3181            ConfigContext serverContext = super.getConfigContext();
3182            Applications applicationsConfigBean =
3183                (Applications) ConfigBeansFactory.getConfigBeanByXPath(
3184                                    serverContext,
3185                                    ServerXPathHelper.XPATH_APPLICATIONS);
3186            if (applicationsConfigBean != null)
3187            {
3188                switch (appType)
3189                {
3190                    case DeploymentConstants.EAR :
3191                    {
3192                        appConfigBean = applicationsConfigBean.
3193                                            getJ2eeApplicationByName(appName);
3194                        break;
3195                    }
3196                    case DeploymentConstants.EJB :
3197                    {
3198                        appConfigBean = applicationsConfigBean.
3199                                            getEjbModuleByName(appName);
3200                        break;
3201                    }
3202                    case DeploymentConstants.WAR :
3203                    {
3204                        appConfigBean = applicationsConfigBean.
3205                                            getWebModuleByName(appName);
3206                        break;
3207                    }
3208                    case DeploymentConstants.RAR :
3209                    {
3210                        appConfigBean = applicationsConfigBean.
3211                                            getConnectorModuleByName(appName);
3212                        break;
3213                    }
3214                }
3215            }
3216        }
3217        catch (Exception JavaDoc e)
3218        {
3219            sLogger.log(Level.WARNING, "appexists failed", e); //noi18N
3220
}
3221        return (appConfigBean != null);
3222    }
3223    
3224    /**
3225     * @return true if a module identified with the module name and it's
3226     * type is already deployed in this app server instance
3227     */

3228    private boolean isAppExists(String JavaDoc moduleName, ModuleType JavaDoc moduleType)
3229    {
3230        ConfigBean moduleConfigBean = null;
3231        try
3232        {
3233            ConfigContext serverContext = super.getConfigContext();
3234            Applications applicationsConfigBean =
3235                (Applications) ConfigBeansFactory.getConfigBeanByXPath(
3236                                    serverContext,
3237                                    ServerXPathHelper.XPATH_APPLICATIONS);
3238            if (applicationsConfigBean != null)
3239            {
3240                if (moduleType.equals(ModuleType.EAR))
3241                {
3242                    moduleConfigBean = applicationsConfigBean.
3243                                        getJ2eeApplicationByName(moduleName);
3244        } else
3245                if (moduleType.equals(ModuleType.EJB))
3246                {
3247                        moduleConfigBean = applicationsConfigBean.
3248                                            getEjbModuleByName(moduleName);
3249        } else
3250                if (moduleType.equals(ModuleType.WAR))
3251                {
3252                        moduleConfigBean = applicationsConfigBean.
3253                                            getWebModuleByName(moduleName);
3254        } else
3255                if (moduleType.equals(ModuleType.RAR))
3256                {
3257                        moduleConfigBean = applicationsConfigBean.
3258                                            getConnectorModuleByName(moduleName);
3259        }
3260            }
3261        }
3262        catch (Exception JavaDoc e)
3263        {
3264            sLogger.log(Level.WARNING, "appexists failed", e); //noi18N
3265
}
3266        return (moduleConfigBean != null);
3267    }
3268    
3269
3270
3271    /**
3272     * Checks the debug-enabled attribute of java-config in server.xml.
3273     */

3274    private final boolean isDebug()
3275    {
3276        boolean isDebug = false;
3277        try
3278        {
3279            JavaConfig jvmConfig = getJavaConfigBean();
3280            String JavaDoc value = jvmConfig.getAttributeValue(
3281                                ServerTags.DEBUG_ENABLED);
3282            if (value != null)
3283            {
3284                isDebug = Boolean.valueOf(value).booleanValue();
3285            }
3286        }
3287        catch (Exception JavaDoc e)
3288        {
3289            sLogger.log(Level.WARNING, "mbean.is_debug_failed", e);
3290        }
3291        return isDebug;
3292    }
3293
3294    /**
3295     * Sets the debug-enabled attribute of the java-config element.
3296     */

3297    private final void setDebug(boolean debug) throws Exception JavaDoc
3298    {
3299        JavaConfig jvmConfig = getJavaConfigBean();
3300        String JavaDoc value = String.valueOf(debug);
3301        jvmConfig.setAttributeValue(ServerTags.DEBUG_ENABLED, value);
3302    }
3303
3304    /**
3305     * Sets the debug-options attribute of the java-config element.
3306     */

3307    private final void setDebugOptions(String JavaDoc options) throws Exception JavaDoc
3308    {
3309        JavaConfig jvmConfig = getJavaConfigBean();
3310        jvmConfig.setAttributeValue(ServerTags.DEBUG_OPTIONS, options);
3311    }
3312
3313    /**
3314     * Gets the debug-options attribute of the java-config element.
3315     */

3316    private final String JavaDoc getDebugOptions() throws Exception JavaDoc
3317    {
3318        JavaConfig jvmConfig = getJavaConfigBean();
3319        return jvmConfig.getAttributeValue(ServerTags.DEBUG_OPTIONS);
3320    }
3321
3322    /**
3323     * Gets the default value of the debug-options attribute.
3324     */

3325    private final String JavaDoc getDefaultDebugOptions() throws Exception JavaDoc
3326    {
3327        return JavaConfig.getDefaultAttributeValue(ServerTags.DEBUG_OPTIONS);
3328    }
3329
3330    private final int getDebugPort() throws Exception JavaDoc
3331    {
3332        int debugPort = -1;
3333        final String JavaDoc debugOptions = getDebugOptions();
3334        if (debugOptions != null)
3335        {
3336            int index = debugOptions.indexOf("-Xrunjdwp");
3337            if (index >= 0)
3338            {
3339                final String JavaDoc jdwpOption = debugOptions.substring(index);
3340                index = jdwpOption.indexOf("address=");
3341                if (index >= 0)
3342                {
3343                    final String JavaDoc nvPairs = jdwpOption.substring(index);
3344                    StringTokenizer JavaDoc optionTok =
3345                            new StringTokenizer JavaDoc(nvPairs, "=, ");
3346                    optionTok.nextToken(); //Skip 'address' token
3347
String JavaDoc portValue = optionTok.nextToken();
3348                    debugPort = Integer.parseInt(portValue);
3349                }
3350            }
3351        }
3352        return debugPort;
3353    }
3354
3355    /**
3356     * Sets the debug port in debug-options attribute.
3357     */

3358    private final void setDebugPort(int port) throws Exception JavaDoc
3359    {
3360        StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
3361        String JavaDoc debugOptions = getDefaultDebugOptions();
3362        StringTokenizer JavaDoc strTok = new StringTokenizer JavaDoc(debugOptions, " ");
3363        while (strTok.hasMoreTokens())
3364        {
3365            String JavaDoc option = strTok.nextToken();
3366            sb.append(option);
3367            if (option.startsWith("-Xrunjdwp"))
3368            {
3369                sb.append(",address=" + port);
3370            }
3371            if (strTok.hasMoreTokens())
3372            {
3373                sb.append(' ');
3374            }
3375        }
3376        debugOptions = sb.toString();
3377        //Remove the following statement once dtd is changed
3378
//to include these as default options.
3379
debugOptions += " -Xnoagent -Djava.compiler=NONE";
3380        sLogger.log(Level.INFO, "mbean.debug_options", debugOptions);
3381        setDebugOptions(debugOptions);
3382    }
3383
3384    private final JavaConfig getJavaConfigBean() throws Exception JavaDoc
3385    {
3386//ms1 Server server = (Server) super.getBaseConfigBean();
3387
//ms1 assert server != null;
3388
Config config = (Config) super.getConfigBeanByXPath(ServerXPathHelper.XPATH_CONFIG);
3389        JavaConfig jvmConfig = config.getJavaConfig();
3390        jvmConfig.setConfigContext(super.getConfigContext());
3391        return jvmConfig;
3392    }
3393
3394
3395    // ****************************************************************************
3396
//Security Realms keyfile operations
3397
// ****************************************************************************
3398
private FileRealm getInstanceRealmKeyFile() throws MBeanConfigException
3399    {
3400        InstanceEnvironment env = new InstanceEnvironment(mInstanceName);
3401        try
3402        {
3403            return new FileRealm(env.getBackupRealmsKeyFilePath());
3404        }
3405        catch(BadRealmException bre)
3406        {
3407            //String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
3408
throw new MBeanConfigException(bre.getMessage());
3409        }
3410        catch(NoSuchRealmException nsr)
3411        {
3412            //String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_realm", mInstanceName);
3413
throw new MBeanConfigException(nsr.getMessage());
3414        }
3415
3416    }
3417    private void saveInstanceRealmKeyFile(FileRealm realm) throws MBeanConfigException
3418    {
3419        InstanceEnvironment env = new InstanceEnvironment(mInstanceName);
3420        try
3421        {
3422            final String JavaDoc filePath = env.getBackupRealmsKeyFilePath();
3423            sLogger.log(Level.INFO, "filerealm.write", filePath);
3424            realm.writeKeyFile(filePath);
3425        }
3426        catch(IOException JavaDoc ioe)
3427        {
3428            //String msg = localStrings.getString( "admin.server.core.mbean.config.realm_io_error", mInstanceName);
3429
sLogger.log(Level.WARNING, "filerealm.writeerror", ioe);
3430            throw new MBeanConfigException(ioe.getMessage());
3431        }
3432    }
3433
3434
3435    private String JavaDoc[] convertEnumerationToStringArray(Enumeration JavaDoc e)
3436    {
3437        ArrayList JavaDoc list = new ArrayList JavaDoc();
3438        while(e.hasMoreElements())
3439            list.add(e.nextElement());
3440        return (String JavaDoc[])list.toArray(new String JavaDoc[list.size()]);
3441    }
3442
3443    /**
3444     * Returns names of all the users from instance realm keyfile
3445     */

3446    public String JavaDoc[] getUserNames() throws MBeanConfigException
3447    {
3448        FileRealm realm = getInstanceRealmKeyFile();
3449        try
3450        {
3451            return convertEnumerationToStringArray(realm.getUserNames());
3452        }
3453        catch(BadRealmException bre)
3454        {
3455            //String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
3456
throw new MBeanConfigException(bre.getMessage());
3457        }
3458    }
3459
3460    /**
3461     * Returns names of all the groups from the instance realm keyfile
3462     */

3463    public String JavaDoc[] getGroupNames() throws MBeanConfigException
3464    {
3465        FileRealm realm = getInstanceRealmKeyFile();
3466        try
3467        {
3468            return convertEnumerationToStringArray(realm.getGroupNames());
3469        }
3470        catch(BadRealmException bre)
3471        {
3472            //String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
3473
throw new MBeanConfigException(bre.getMessage());
3474        }
3475    }
3476
3477    /**
3478     * Returns the name of all the groups that this user belongs to from the instance realm keyfile
3479     */

3480    public String JavaDoc[] getUserGroupNames(String JavaDoc userName) throws MBeanConfigException
3481    {
3482        FileRealm realm = getInstanceRealmKeyFile();
3483        try
3484        {
3485            return convertEnumerationToStringArray(realm.getGroupNames(userName));
3486        }
3487        catch(NoSuchUserException nse)
3488        {
3489            //String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_user", mInstanceName, userName);
3490
throw new MBeanConfigException(nse.getMessage());
3491        }
3492    }
3493
3494    /**
3495     * Adds new user to file realm. User cannot exist already.
3496     */

3497    public void addUser(String JavaDoc userName, String JavaDoc password, String JavaDoc[] groupList) throws MBeanConfigException
3498    {
3499        FileRealm realm = getInstanceRealmKeyFile();
3500        try
3501        {
3502            realm.addUser(userName, password, groupList);
3503            saveInstanceRealmKeyFile(realm);
3504        }
3505        catch(BadRealmException bre)
3506        {
3507            //String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
3508
throw new MBeanConfigException(bre.getMessage());
3509        }
3510        catch(IASSecurityException ise)
3511        {
3512            //String msg = localStrings.getString( "admin.server.core.mbean.config.security_exception", mInstanceName, userName, bre.getMessage());
3513
throw new MBeanConfigException(ise.getMessage());
3514        }
3515
3516    }
3517
3518    /**
3519     * Remove user from file realm. User must exist.
3520     */

3521    public void removeUser(String JavaDoc userName) throws MBeanConfigException
3522    {
3523        FileRealm realm = getInstanceRealmKeyFile();
3524        try
3525        {
3526            realm.removeUser(userName);
3527            saveInstanceRealmKeyFile(realm);
3528        }
3529        catch(NoSuchUserException nse)
3530        {
3531            //String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_user", mInstanceName, userName);
3532
throw new MBeanConfigException(nse.getMessage());
3533        }
3534    }
3535
3536    /**
3537     * Update data for an existing user. User must exist. This is equivalent to calling removeUser() followed by addUser().
3538     */

3539    public void updateUser(String JavaDoc userName, String JavaDoc password, String JavaDoc[] groupList) throws MBeanConfigException
3540    {
3541        FileRealm realm = getInstanceRealmKeyFile();
3542        try
3543        {
3544            realm.updateUser(userName, userName, password, groupList);
3545            saveInstanceRealmKeyFile(realm);
3546        }
3547        catch(BadRealmException bre)
3548        {
3549            //String msg = localStrings.getString( "admin.server.core.mbean.config.bad_realm", mInstanceName);
3550
throw new MBeanConfigException(bre.getMessage());
3551        }
3552        catch(NoSuchUserException nse)
3553        {
3554            //String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_user", mInstanceName, userName);
3555
throw new MBeanConfigException(nse.getMessage());
3556        }
3557        catch(IASSecurityException ise)
3558        {
3559            //String msg = localStrings.getString( "admin.server.core.mbean.config.security_exception", mInstanceName, userName, bre.getMessage());
3560
throw new MBeanConfigException(ise.getMessage());
3561        }
3562    }
3563
3564    /**
3565     * this private method is for testing deployed file or directory
3566     * throws exception if null-name or wrong type
3567     */

3568    private void testDeployedFile(String JavaDoc archiveName, boolean bDirectory) throws DeploymentException
3569    {
3570        if(archiveName==null)
3571        {
3572            String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.deploy_null_name");
3573            throw new DeploymentException(msg);
3574        }
3575        File JavaDoc f = new File JavaDoc(archiveName);
3576        if(bDirectory && !f.isDirectory())
3577        {
3578            String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.deploy_not_directory", archiveName);
3579            throw new DeploymentException(msg);
3580        }
3581        else
3582            if(!bDirectory && !f.isFile())
3583            {
3584                String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.deploy_not_file", archiveName);
3585                throw new DeploymentException(msg);
3586            }
3587    }
3588
3589    /**
3590     * Returns Instance dir path
3591     */

3592    public String JavaDoc getInstanceRoot()
3593    {
3594        InstanceEnvironment env = new InstanceEnvironment(mInstanceName);
3595        return env.getInstancesRoot();
3596    }
3597
3598    /** This method checks if any of the virtual servers has the given web
3599     * module as default-web-module. If yes, it throws exception.
3600     * @param webModuleName the name of the web module.
3601     * @throws ConfigException if any of the virtual servers has this web
3602     * module as default-web-module.
3603     */

3604    private void checkWebModuleReferences(String JavaDoc webModuleName)
3605        throws ConfigException
3606    {
3607        ArrayList JavaDoc virtualServerIds = new ArrayList JavaDoc();
3608
3609        ConfigContext context = super.getConfigContext();
3610//ms1 Server rootElement = ServerBeansFactory.getServerBean(context);
3611
Config config = (Config) super.getConfigBeanByXPath(ServerXPathHelper.XPATH_CONFIG);
3612        HttpService httpService = config.getHttpService();
3613            VirtualServer[] virtualServers = httpService.getVirtualServer();
3614            for (int j = 0; j < virtualServers.length; j++)
3615            {
3616                VirtualServer aServer = virtualServers[j];
3617                String JavaDoc defWebModule = aServer.getDefaultWebModule();
3618                if ((defWebModule != null) &&
3619                    (defWebModule.equals(webModuleName)))
3620                {
3621                    virtualServerIds.add(aServer.getId());
3622                }
3623            }
3624        if (!virtualServerIds.isEmpty())
3625        {
3626            throw new ConfigException(localStrings.getString(
3627            "admin.server.core.mbean.config.def_web_module_refs_exist",
3628            virtualServerIds.toString(), webModuleName));
3629        }
3630    }
3631
3632    private void setDeployDirOwner(DeploymentRequest request,
3633            InstanceEnvironment env) {
3634        //Need an alternative. Ramakanth. 04/23/2003
3635
/*
3636        try {
3637            String instanceUser = env.getInstanceUser();
3638            File deployDir = request.getDeployedDirectory();
3639            chownDir(deployDir, instanceUser);
3640            File stubsDir = request.getStubsDirectory();
3641            chownDir(stubsDir, instanceUser);
3642            File jspDir = request.getJSPDirectory();
3643            chownDir(jspDir, instanceUser);
3644        } catch (Throwable t) {
3645            sLogger.log(Level.WARNING, "mbean.deploy_chown_failed",
3646                    t.getMessage());
3647            sLogger.log(Level.FINE, "general.unexpected_exception", t);
3648        }
3649*/

3650    }
3651
3652    private void chownDir(File JavaDoc dir, String JavaDoc user) {
3653        if (dir == null || user == null || user.trim().equals("")) {
3654            return;
3655        }
3656        String JavaDoc err = null;
3657        /*installConfig is removed and we need better alternative */
3658        /*
3659        installConfig cfg = new installConfig();
3660        err = cfg.chownDir(dir.getAbsolutePath(), user);
3661        if (err != null) {
3662            sLogger.log(Level.WARNING, err);
3663        }
3664        */

3665    }
3666    
3667    // BEGIN S1AS8_CONNECTORS_CLI_COMMANDS
3668
public void addAdminObject(String JavaDoc type, Properties JavaDoc properties, String JavaDoc raName, String JavaDoc jndiName)
3669        throws AFResourceException
3670    {
3671        /*
3672        ArgChecker.checkValid(id, "id",
3673                              StringValidator.getInstance()); //noi18n
3674        ArgChecker.checkValid(datasourceClassName, "datasourceClassName",
3675                              StringValidator.getInstance()); //noi18n
3676        */

3677
3678        try
3679        {
3680            sLogger.log(Level.FINE, "mbean.create_admin_object_resource", jndiName);
3681            ConfigContext serverContext = getConfigContext(mInstanceName);
3682            Resources resourcesBean =
3683                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
3684                                            ServerXPathHelper.XPATH_RESOURCES);
3685            AdminObjectResource resource = new AdminObjectResource();
3686            resource.setJndiName(jndiName);
3687            resource.setResType(type);
3688            resource.setResAdapter(raName);
3689            resourcesBean.addAdminObjectResource(resource);
3690            // Add the property elements.
3691
Enumeration JavaDoc e = properties.keys();
3692            String JavaDoc n, v;
3693            ElementProperty el = null;
3694            while (e.hasMoreElements()) {
3695                n = (String JavaDoc) e.nextElement();
3696                v = (String JavaDoc) properties.get(n);
3697                el = new ElementProperty();
3698                el.setName(n);
3699                el.setValue(v);
3700                resource.addElementProperty(el);
3701            }
3702        createResourceRef(jndiName);
3703            serverContext.flush();
3704
3705        }
3706        catch (Exception JavaDoc e)
3707        {
3708            sLogger.log(Level.WARNING, "mbean.create_resource_failed", e);
3709            throw new AFResourceException(e.getLocalizedMessage());
3710        }
3711    }
3712
3713    public void deleteAdminObject(String JavaDoc jndiName)
3714    throws AFResourceException
3715    {
3716        /*
3717        ArgChecker.checkValid(poolName, "poolName",
3718                              StringValidator.getInstance()); //noi18n
3719         **/

3720        sLogger.log(Level.FINE, "mbean.delele_admin_object", jndiName);
3721        try
3722        {
3723            ConfigContext serverContext = getConfigContext(mInstanceName);
3724            Resources resourcesBean =
3725                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
3726                                            ServerXPathHelper.XPATH_RESOURCES);
3727            com.sun.enterprise.config.serverbeans.AdminObjectResource resource =
3728                resourcesBean.getAdminObjectResourceByJndiName(jndiName);
3729
3730            if (resource == null)
3731            {
3732                String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName );
3733                throw new Exception JavaDoc( msg );
3734            }
3735            resourcesBean.removeAdminObjectResource(resource);
3736        deleteResourceRef(jndiName);
3737            serverContext.flush();
3738        }
3739        catch (Exception JavaDoc e)
3740        {
3741            sLogger.log(Level.WARNING, "mbean.delete_connector_connection_pool_failed", e);
3742            throw new AFResourceException(e.getLocalizedMessage());
3743        }
3744    }
3745    
3746    public String JavaDoc[] listAdminObjects() throws AFException
3747    {
3748        String JavaDoc[] sa = null;
3749        try
3750        {
3751            sLogger.log(Level.FINE, "mbean.list_components");
3752            ConfigContext serverContext = getConfigContext(mInstanceName);
3753            Resources resourcesBean =
3754                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
3755                                            ServerXPathHelper.XPATH_RESOURCES);
3756            com.sun.enterprise.config.serverbeans.AdminObjectResource[] resources =
3757                resourcesBean.getAdminObjectResource();
3758            if (resources != null)
3759            {
3760                sa = new String JavaDoc[resources.length];
3761                for(int i=0; i<resources.length; i++)
3762                {
3763                    sa[i] = resources[i].getJndiName();
3764                }
3765            }
3766        }
3767        catch (Exception JavaDoc e)
3768        {
3769            sLogger.log(Level.WARNING, "mbean.list_failed", e);
3770            throw new AFException(e.getLocalizedMessage());
3771        }
3772        return sa;
3773    }
3774    
3775    
3776    
3777
3778    public void createConnectorConnectionPool(String JavaDoc raName, String JavaDoc conDefn, String JavaDoc steadyPoolSize,
3779                String JavaDoc maxPoolSize, String JavaDoc maxWaitTime, String JavaDoc poolResizeQty, String JavaDoc idleTimeout,
3780                Boolean JavaDoc failAllConns, Properties JavaDoc properties, String JavaDoc poolName)
3781        throws AFResourceException
3782    {
3783        /*
3784        ArgChecker.checkValid(id, "id",
3785                              StringValidator.getInstance()); //noi18n
3786        ArgChecker.checkValid(datasourceClassName, "datasourceClassName",
3787                              StringValidator.getInstance()); //noi18n
3788        */

3789
3790        try
3791        {
3792            sLogger.log(Level.FINE, "mbean.create_connector_connection_pool", poolName);
3793            ConfigContext serverContext = getConfigContext(mInstanceName);
3794            Resources resourcesBean =
3795                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
3796                                            ServerXPathHelper.XPATH_RESOURCES);
3797            com.sun.enterprise.config.serverbeans.ConnectorConnectionPool conPool =
3798                new com.sun.enterprise.config.serverbeans.ConnectorConnectionPool();
3799            conPool.setResourceAdapterName(raName);
3800            conPool.setConnectionDefinitionName(conDefn);
3801            if (steadyPoolSize != null) conPool.setSteadyPoolSize(steadyPoolSize);
3802            if (maxPoolSize != null) conPool.setMaxPoolSize(maxPoolSize);
3803            if (maxWaitTime != null) conPool.setMaxWaitTimeInMillis(maxWaitTime);
3804            if (poolResizeQty != null) conPool.setPoolResizeQuantity(poolResizeQty);
3805            if (idleTimeout != null) conPool.setIdleTimeoutInSeconds(idleTimeout);
3806            if (failAllConns != null) conPool.setFailAllConnections(failAllConns.booleanValue());
3807            conPool.setName(poolName);
3808            resourcesBean.addConnectorConnectionPool(conPool);
3809            // Add the property elements.
3810
if (properties != null) {
3811                Enumeration JavaDoc e = properties.keys();
3812                String JavaDoc n, v;
3813                ElementProperty el = null;
3814                while (e.hasMoreElements()) {
3815                    n = (String JavaDoc) e.nextElement();
3816                    v = (String JavaDoc) properties.get(n);
3817                    el = new ElementProperty();
3818                    el.setName(n);
3819                    el.setValue(v);
3820                    conPool.addElementProperty(el);
3821                }
3822            }
3823            serverContext.flush();
3824
3825        }
3826        catch (Exception JavaDoc e)
3827        {
3828            sLogger.log(Level.WARNING, "mbean.create_resource_failed", e);
3829            throw new AFResourceException(e.getLocalizedMessage());
3830        }
3831    }
3832    
3833    public void deleteConnectorConnectionPool(String JavaDoc poolName)
3834        throws AFResourceException
3835    {
3836        ArgChecker.checkValid(poolName, "poolName",
3837                              StringValidator.getInstance()); //noi18n
3838
sLogger.log(Level.FINE, "mbean.delele_connector_connection_pool", poolName);
3839        try
3840        {
3841            ConfigContext serverContext = getConfigContext(mInstanceName);
3842            Resources resourcesBean =
3843                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
3844                                            ServerXPathHelper.XPATH_RESOURCES);
3845            com.sun.enterprise.config.serverbeans.ConnectorConnectionPool resource =
3846                resourcesBean.getConnectorConnectionPoolByName(poolName);
3847
3848            if (resource == null)
3849            {
3850            /*
3851        String msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", poolName );
3852                throw new Exception( msg );
3853            */

3854            }
3855            resourcesBean.removeConnectorConnectionPool(resource);
3856            serverContext.flush();
3857        }
3858        catch (Exception JavaDoc e)
3859        {
3860            sLogger.log(Level.WARNING, "mbean.delete_connector_connection_pool_failed", e);
3861            throw new AFResourceException(e.getLocalizedMessage());
3862        }
3863    }
3864
3865    public String JavaDoc[] listConnectorConnectionPools() throws AFException
3866    {
3867        String JavaDoc[] sa = null;
3868        try
3869        {
3870            sLogger.log(Level.FINE, "mbean.list_components");
3871            ConfigContext serverContext = getConfigContext(mInstanceName);
3872            Resources resourcesBean =
3873                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
3874                                            ServerXPathHelper.XPATH_RESOURCES);
3875            com.sun.enterprise.config.serverbeans.ConnectorConnectionPool[] connectionPools =
3876                resourcesBean.getConnectorConnectionPool();
3877            if (connectionPools != null)
3878            {
3879                sa = new String JavaDoc[connectionPools.length];
3880                for(int i=0; i<connectionPools.length; i++)
3881                {
3882                    sa[i] = connectionPools[i].getName();
3883                }
3884            }
3885        }
3886        catch (Exception JavaDoc e)
3887        {
3888            sLogger.log(Level.WARNING, "mbean.list_failed", e);
3889            throw new AFException(e.getLocalizedMessage());
3890        }
3891        return sa;
3892    }
3893    
3894    /**
3895     * Registers a connector resource with the given jndiName & properties.
3896     */

3897    public void createConnectorResource(String JavaDoc jndiName, String JavaDoc poolName, String JavaDoc description,
3898                                   Boolean JavaDoc enabled, Properties JavaDoc properties )
3899        throws AFResourceException
3900    {
3901        /*
3902        ArgChecker.checkValid(jndiName, "jndiName",
3903                              StringValidator.getInstance()); //noi18n
3904        ArgChecker.checkValid(poolName, "poolName",
3905                              StringValidator.getInstance()); //noi18n
3906         */

3907        try
3908        {
3909            sLogger.log(Level.FINE, "mbean.create_resource", jndiName);
3910            ConfigContext serverContext = getConfigContext(mInstanceName);
3911            Resources resourcesBean =
3912                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
3913                                            ServerXPathHelper.XPATH_RESOURCES);
3914            /*
3915            com.sun.enterprise.config.serverbeans.ConnectorConnectionPool poolResource =
3916                resourcesBean.getConnectorConnectionPoolByName(poolName);
3917            if (poolResource == null)
3918                throw new AFResourceException("mbean.create_resource : non-existent poolname : " + poolName);
3919             */

3920                
3921            com.sun.enterprise.config.serverbeans.ConnectorResource resource =
3922                new com.sun.enterprise.config.serverbeans.ConnectorResource();
3923            resource.setJndiName(jndiName);
3924            resource.setPoolName(poolName);
3925            if (description != null) resource.setDescription(description);
3926            //resource.setEnabled(true);
3927
resourcesBean.addConnectorResource(resource);
3928            // Add the property elements
3929
if (properties != null) {
3930                Enumeration JavaDoc e = properties.keys();
3931                String JavaDoc n, v;
3932                ElementProperty el = null;
3933                while (e.hasMoreElements()) {
3934                    n = (String JavaDoc) e.nextElement();
3935                    v = (String JavaDoc) properties.get(n);
3936                    el = new ElementProperty();
3937                    el.setName(n);
3938                    el.setValue(v);
3939                    resource.addElementProperty(el);
3940                }
3941            }
3942        createResourceRef(jndiName);
3943            serverContext.flush();
3944
3945        }
3946        catch (Exception JavaDoc e)
3947        {
3948            sLogger.log(Level.WARNING, "mbean.create_resource_failed", e);
3949            throw new AFResourceException(e.getLocalizedMessage());
3950        }
3951    }
3952    
3953    public void deleteConnectorResource(String JavaDoc jndiName)
3954        throws AFResourceException
3955    {
3956        /*
3957        ArgChecker.checkValid(poolName, "poolName",
3958                              StringValidator.getInstance()); //noi18n
3959         */

3960        sLogger.log(Level.FINE, "mbean.delete_connector_resource", jndiName);
3961        try
3962        {
3963            ConfigContext serverContext = getConfigContext(mInstanceName);
3964            Resources resourcesBean =
3965                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
3966                                            ServerXPathHelper.XPATH_RESOURCES);
3967            com.sun.enterprise.config.serverbeans.ConnectorResource resource =
3968                resourcesBean.getConnectorResourceByJndiName(jndiName);
3969
3970            if (resource == null)
3971            {
3972                String JavaDoc msg = localStrings.getString( "admin.server.core.mbean.config.no_such_resource", jndiName );
3973                throw new Exception JavaDoc( msg );
3974            }
3975            resourcesBean.removeConnectorResource(resource);
3976        deleteResourceRef(jndiName);
3977            serverContext.flush();
3978        }
3979        catch (Exception JavaDoc e)
3980        {
3981            sLogger.log(Level.WARNING, "mbean.delete_connector_connection_pool_failed", e);
3982            throw new AFResourceException(e.getLocalizedMessage());
3983        }
3984    }
3985    
3986    public String JavaDoc[] listConnectorResources() throws AFException
3987    {
3988        String JavaDoc[] sa = null;
3989        try
3990        {
3991            sLogger.log(Level.FINE, "mbean.list_components");
3992            ConfigContext serverContext = getConfigContext(mInstanceName);
3993            Resources resourcesBean =
3994                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
3995                                            ServerXPathHelper.XPATH_RESOURCES);
3996            com.sun.enterprise.config.serverbeans.ConnectorResource[] resources =
3997                resourcesBean.getConnectorResource();
3998            if (resources != null)
3999            {
4000                sa = new String JavaDoc[resources.length];
4001                for(int i=0; i<resources.length; i++)
4002                {
4003                    sa[i] = resources[i].getJndiName();
4004                }
4005            }
4006        }
4007        catch (Exception JavaDoc e)
4008        {
4009            sLogger.log(Level.WARNING, "mbean.list_failed", e);
4010            throw new AFException(e.getLocalizedMessage());
4011        }
4012        return sa;
4013    }
4014    /* temporary method */
4015    private void transform(InstanceEnvironment ie) {
4016        if (PORT_DOMAIN_TO_SERVER) {
4017            final String JavaDoc domainXMLPath = ie.getConfigFilePath();
4018            final String JavaDoc serverXMLPath = java.lang.System.getProperty(Constants.IAS_ROOT)
4019                + "/"
4020                + ie.getName()
4021                + "/config/"
4022                + ie.kServerXMLFileName;
4023            new Domain2ServerTransformer(domainXMLPath, serverXMLPath).transform();
4024        }
4025         
4026    }
4027    /* temporary method */
4028    public String JavaDoc[] listConnectorJMSResources(String JavaDoc type) throws AFException
4029    {
4030        Vector JavaDoc v = new Vector JavaDoc();
4031        String JavaDoc[] sa = null;
4032        int j = 0;
4033        try
4034        {
4035            sLogger.log(Level.FINE, "mbean.list_jms_resources");
4036            ConfigContext serverContext = getConfigContext(mInstanceName);
4037            Resources resourcesBean =
4038                (Resources)ConfigBeansFactory.getConfigBeanByXPath(serverContext,
4039                                            ServerXPathHelper.XPATH_RESOURCES);
4040            // Look for connector-resource elements
4041
if (type == null || type.equals("javax.jms.TopicConnectionFactory") ||
4042                type.equals("javax.jms.QueueConnectionFactory")) {
4043                com.sun.enterprise.config.serverbeans.ConnectorResource[] resources =
4044                    resourcesBean.getConnectorResource();
4045                if (resources != null)
4046                {
4047                    sa = new String JavaDoc[resources.length];
4048                    for(int i=0; i<resources.length; i++)
4049                    {
4050                        String JavaDoc jndiName = resources[i].getJndiName();
4051                        String JavaDoc defPoolName = ConnectorRuntime.getRuntime().getDefaultPoolName(jndiName);
4052                        if (resources[i].getPoolName().equals(defPoolName) ) {
4053                            com.sun.enterprise.config.serverbeans.ConnectorConnectionPool poolResource =
4054                                    resourcesBean.getConnectorConnectionPoolByName(defPoolName);
4055                            if (type == null || (poolResource != null && poolResource.getConnectionDefinitionName().equals(type))) {
4056                                v.addElement(resources[i].getJndiName());
4057                             }
4058                        }
4059                    }
4060                }
4061            }
4062            // Look for admin-object elements
4063
if (type == null || type.equals("javax.jms.Topic") ||
4064                type.equals("javax.jms.Queue")) {
4065                com.sun.enterprise.config.serverbeans.AdminObjectResource[] resources =
4066                    resourcesBean.getAdminObjectResource();
4067                if (resources != null)
4068                {
4069                    sa = new String JavaDoc[resources.length];
4070                    for(int i=0; i<resources.length; i++)
4071                    {
4072                        if (type == null || resources[i].getResType().equals(type)) {
4073                            v.addElement(resources[i].getJndiName());
4074                        }
4075                    }
4076                }
4077            }
4078
4079        }
4080        catch (Exception JavaDoc e)
4081        {
4082            sLogger.log(Level.WARNING, "mbean.list_jms_resources_failed", e);
4083            throw new AFException(e.getLocalizedMessage());
4084        }
4085        sa = new String JavaDoc[v.size()];
4086        for (int k = 0; k < sa.length; k++)
4087                sa[k] = (String JavaDoc) v.elementAt(k);
4088        return sa;
4089    }
4090
4091
4092
4093}
4094
Popular Tags