KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > lutris > appserver > server > StandardApplication


1 /*
2  * Enhydra Java Application Server Project
3  *
4  * The contents of this file are subject to the Enhydra Public License
5  * Version 1.1 (the "License"); you may not use this file except in
6  * compliance with the License. You may obtain a copy of the License on
7  * the Enhydra web site ( http://www.enhydra.org/ ).
8  *
9  * Software distributed under the License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
11  * the License for the specific terms governing rights and limitations
12  * under the License.
13  *
14  * The Initial Developer of the Enhydra Application Server is Lutris
15  * Technologies, Inc. The Enhydra Application Server and portions created
16  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
17  * All Rights Reserved.
18  *
19  * Contributor(s):
20  *
21  * $Id: StandardApplication.java,v 1.1 2005/07/13 11:09:06 slobodan Exp $
22  *
23  *
24  *
25  */

26 package com.lutris.appserver.server;
27
28 import java.io.IOException JavaDoc;
29 import java.lang.reflect.Constructor JavaDoc;
30 import java.lang.reflect.Method JavaDoc;
31 import java.util.Enumeration JavaDoc;
32 import java.util.Hashtable JavaDoc;
33 import java.util.Iterator JavaDoc;
34 import java.util.List JavaDoc;
35 import java.util.ListIterator JavaDoc;
36 import java.util.StringTokenizer JavaDoc;
37
38 import javax.management.Attribute JavaDoc;
39 import javax.management.AttributeChangeNotification JavaDoc;
40 import javax.management.AttributeList JavaDoc;
41 import javax.management.AttributeNotFoundException JavaDoc;
42 import javax.management.DynamicMBean JavaDoc;
43 import javax.management.InvalidAttributeValueException JavaDoc;
44 import javax.management.MBeanAttributeInfo JavaDoc;
45 import javax.management.MBeanConstructorInfo JavaDoc;
46 import javax.management.MBeanException JavaDoc;
47 import javax.management.MBeanInfo JavaDoc;
48 import javax.management.MBeanNotificationInfo JavaDoc;
49 import javax.management.MBeanOperationInfo JavaDoc;
50 import javax.management.MBeanParameterInfo JavaDoc;
51 import javax.management.MBeanServer JavaDoc;
52 import javax.management.MBeanServerFactory JavaDoc;
53 import javax.management.Notification JavaDoc;
54 import javax.management.NotificationBroadcasterSupport JavaDoc;
55 import javax.management.ObjectName JavaDoc;
56 import javax.management.ReflectionException JavaDoc;
57 import javax.management.RuntimeOperationsException JavaDoc;
58 import javax.servlet.Servlet JavaDoc;
59 import javax.servlet.ServletContext JavaDoc;
60 import javax.servlet.ServletException JavaDoc;
61 import javax.servlet.http.HttpServletRequest JavaDoc;
62 import javax.servlet.http.HttpServletResponse JavaDoc;
63
64 import org.enhydra.util.ConfigFileInterface;
65 import org.enhydra.util.DOTable;
66 import org.enhydra.util.Utils;
67 import org.enhydra.util.EafConfigMBean;
68 import org.enhydra.util.jivan.JivanFactory;
69 import org.enhydra.xml.xmlc.XMLCFactory;
70 import org.enhydra.xml.xmlc.XMLCStdFactory;
71 import org.enhydra.xml.xmlc.deferredparsing.DocumentLoaderImpl;
72 import org.enhydra.xml.xmlc.deferredparsing.XMLCDeferredParsingFactory;
73
74 import com.lutris.appserver.server.httpPresentation.ClientPageRedirectException;
75 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
76 import com.lutris.appserver.server.httpPresentation.HttpPresentationException;
77 import com.lutris.appserver.server.httpPresentation.HttpPresentationManager;
78 import com.lutris.appserver.server.session.MemoryPersistence;
79 import com.lutris.appserver.server.session.Session;
80 import com.lutris.appserver.server.session.SessionException;
81 import com.lutris.appserver.server.session.SessionManager;
82 import com.lutris.appserver.server.sessionEnhydra.StandardSessionManager;
83 import com.lutris.appserver.server.sql.DatabaseManager;
84 import com.lutris.classloader.MultiClassLoader;
85 import com.lutris.logging.EnhydraXMLCLogger;
86 import com.lutris.logging.LogChannel;
87 import com.lutris.logging.Logger;
88 import com.lutris.util.Config;
89 import com.lutris.util.KeywordValueException;
90
91 /**
92  * Default application implementation. This class provides standard start/stop
93  * services. This can be used as a base class to derive Application objects.
94  *
95  * @version $Revision: 1.1 $
96  * @author Mark Diekhans
97  */

98 public abstract class StandardApplication
99     implements Application {
100   /*
101    * Category of logger that logs on System.out.
102    */

103   private static final String JavaDoc sysConLoggerName = "SysOut";
104   private static final String JavaDoc STANDARD_DATABASE_MANAGER_CLASS_NAME =
105       "com.lutris.appserver.server.sql.StandardDatabaseManager";
106   /**
107    * Determines if a cookie with the session id is sent to the client.
108    */

109   protected boolean sendCookieForNewSession = true;
110   /**
111    * The name of the application; defaults to the unqualified
112    * class name.
113    */

114   protected String JavaDoc appName = null;
115   /**
116    * Current state of the application. Only modified by the derived
117    * application.
118    */

119   protected int state = STOPPED;
120   /**
121    * Session manager for all application sessions. A session manager
122    * manages the creation, deletion and assocation of sessions with
123    * a user.
124    */

125   protected SessionManager sessionManager;
126   /**
127    * Presentation manager instance for application. The presentation
128    * manager handles incomming http requests.
129    */

130   protected HttpPresentationManager presentationManager;
131   /**
132    * Database manager instance for application. The database manager
133    * manages logical database and is responsible for allocating
134    * connection, create transactions, etc.
135    */

136   protected DatabaseManager databaseManager;
137   /**
138    * This applications config object. Every application has a configuration
139    * object that is created from the application configuration file.
140    *
141    * @see Config
142    */

143   protected Config config;
144   /**
145    * Default URL used for application if defined in Config file. This
146    * is used to redirect the user to the preferred start page if a
147    * URL equal to the root of this application is given. By setting
148    * this to index.html, it behaves in the same way as a http server.
149    */

150   protected String JavaDoc defaultUrl;
151   /**
152    * The log channel for this application to write to.
153    */

154   protected LogChannel logChannel;
155   protected Logger logger;
156   /**
157    * The logger that logs on System.out.
158    */

159   protected static LogChannel loggerSys;
160   /**
161    * Application Data accessable through Jolt Fields.
162    */

163   protected ApplicationData data = new ApplicationData();
164   /**
165    * XMLC Factory.
166    */

167   protected XMLCFactory xmlcFactory;
168   
169   /**
170    * Jivan Factory.
171    */

172   protected JivanFactory jivanFactory;
173   
174   
175   protected MBeanServer JavaDoc server = null;
176   protected ApplicationConfigMBean appConfigMBean;
177   protected DatabaseManagerMBean databaseManagerMBean;
178   protected PresentationManagerMBean presentationManagerMBean;
179   protected SessionManagerMBean sessionManagerMBean;
180   protected DatabaseMBean databaseMBean;
181   protected TableMBean tableMBean;
182   protected ContextMBean contextMBean;
183   
184   /** DACHA & TUFA
185    * Variable which determine should we keep
186    * SessionManager in memory.
187    */

188   private boolean isMemoryPersistence = false;
189
190   /**
191    * A constructor with no arguments is required.
192    */

193   public StandardApplication() {}
194
195   /**
196    * Get the application state.
197    * N.B. Purposely not syncronized for speed.
198    *
199    * @return
200    * The application's state code.
201    */

202   public int getState() {
203     return state;
204   }
205
206   /**
207    * Tells the application if a cookie is used to bind new sessions
208    * to a client. If no cookie is set, session ID's must be
209    * communicated by means of URL rewriting.
210    * @param flag indicates whether to send a cookie or not.
211    */

212   public void setCookieForNewSession(boolean flag) {
213     sendCookieForNewSession = flag;
214   }
215
216   /**
217    * Get the application's config object.
218    *
219    * @return
220    * The application's config object.
221    */

222   public Config getConfig() {
223     return config;
224   }
225
226   /**
227    * Set the application name.
228    *
229    * @param name The new name for the application.
230    */

231   public void setName(String JavaDoc applName) {
232     appName = applName;
233   }
234
235   /**
236    * Get the application symbolic name. This is normally the
237    * package name of this application class. <P>
238    * N.B. Purposely not syncronized for speed.
239    *
240    * @return
241    * The symbolic name.
242    */

243   public String JavaDoc getName() {
244     return appName;
245   }
246
247   /**
248    * Set the <CODE>LogChannel</CODE> associated with this application.
249    *
250    * @param The <CODE>LogChannel</CODE> to write to.
251    */

252   public void setLogChannel(LogChannel chan) {
253     logChannel = chan;
254   }
255
256   /**
257    * Get the <CODE>LogChannel</CODE> associated with this application.
258    *
259    * @return The log channel or <CODE>null</CODE> if this application
260    * does not have one.
261    */

262   public LogChannel getLogChannel() {
263     return logChannel;
264   }
265
266   /**
267    * Start the application. The default method sets the state to
268    * <CODE>RUNNING</CODE>.
269    *
270    * @param appConfig
271    * Application configuration object.
272    * @exception ApplicationException
273    * If an error occurs starting the application.
274    */

275   public synchronized void startup(Config appConfig) throws
276       ApplicationException {
277     if (state == RUNNING) {
278       return; // Handle multiple threads doing a startup.
279
}
280     printCopyrightHeader();
281     /**
282      * Read config object.
283      */

284     Config sessionConfig, databaseConfig = null;
285     try {
286       if (appConfig.containsKey("Application")) {
287         defaultUrl = appConfig.getString("Application.DefaultUrl");
288       }
289       sessionConfig = (Config) appConfig.getSection("SessionManager");
290       //DACHA 12.05.2003
291
// databaseConfig = (Config)appConfig.getSection("DatabaseManager");
292
}
293     catch (KeywordValueException except) {
294       throw new ApplicationException(except);
295     }
296     //DACHA 12.05.2003 do not throw exception if databaseConfig is null
297
try {
298       databaseConfig = (Config) appConfig.getSection("DatabaseManager");
299       if (databaseConfig != null && appName != null) {
300         databaseConfig.set("DatabaseManager.AppName", (Object JavaDoc) appName);
301       }
302     } catch (KeywordValueException except) {
303       logChannel.write(Logger.DEBUG,
304                        "Application configured without DatabaseManager.");
305     }
306     
307     /**
308      * Create session manager...
309      */

310     sessionManager = createSessionManager(sessionConfig);
311     
312     /**
313      * Create database manager if required...
314      */

315     boolean hasDatabaseConfig = databaseConfig != null;
316     
317     if (hasDatabaseConfig) {
318       databaseManager = createDatabaseManager(databaseConfig);
319     }
320     
321     /**
322      * Remember config object...
323      */

324     config = appConfig;
325     
326     /**
327      * register Application Coinfiguration MBean
328      */

329     registerApplicationMBean();
330     registerSessionManagerMBean();
331     registerPresentationManagerMBean();
332     registerContextMBean();
333     
334     if (hasDatabaseConfig) {
335         registerDatabaseManagerMBean();
336         registerTableMBeans();
337         String JavaDoc [] dbNames = databaseManager.getLogicalDatabaseNames();
338         for (int i=0;i<dbNames.length;i++){
339             registerDatabaseMBean(dbNames[i]);
340         }
341     }
342     
343     state = RUNNING;
344   }
345
346   public void printCopyrightHeader() {
347     /**
348      * Print out a copyright notice. In most cases this will
349      * fulfill a third party's copyright obligations when using Enhydra.
350      */

351    }
352
353   /**
354    * Continue the startup up process with the application is in the
355    * <CODE>INCOMPLETE</CODE> state. The default method generates an
356    * error, as the application should never be in the <CODE>INCOMPLETE</CODE>
357    * state if it doesn't implment this method.
358    *
359    * @param appConfig
360    * The same <CODE>appConfig</CODE> object that was passed to
361    * <CODE>startup</CODE>.
362    * @exception ApplicationException
363    * If an error occurs restarting the application.
364    */

365   public synchronized void restartup(Config appConfig) throws
366       ApplicationException {
367     throw new ApplicationException("no support for INCOMPLETE state");
368   }
369
370   /**
371    * Shutdown the application. The default method sets the state to
372    * <CODE>STOPPED</CODE>.
373    */

374   public synchronized void shutdown() {
375     if (state == STOPPED) {
376       return; // Handle multiple threads doing a shutdown.
377
}
378     
379     // Unregister previously registered application MBeans
380
try{
381         unRegisterApplicationMBean();
382         unRegisterSessionManagerMBean();
383         unRegisterPresentationManagerMBean();
384         unRegisterDatabaseManagerMBean();
385         unRegisterContextMBean();
386         
387         if (databaseManager!=null) {
388             unRegisterTableMBeans();
389             unRegisterDatabaseManagerMBean();
390             String JavaDoc [] dbNames = databaseManager.getLogicalDatabaseNames();
391             for (int i=0;i<dbNames.length;i++){
392                 unRegisterDatabaseMBean(dbNames[i]);
393             }
394         }
395         
396     }catch (Exception JavaDoc e) {
397          logChannel.write(Logger.DEBUG, e.toString());
398     }
399     
400     if (sessionManager != null) {
401       sessionManager.shutdown();
402       sessionManager = null;
403     }
404     if (databaseManager != null) {
405       databaseManager.shutdown();
406       databaseManager = null;
407     }
408     
409     state = STOPPED;
410   }
411
412   
413   /**
414    * Shutdown the application. The default method sets the state to
415    * <CODE>STOPPED</CODE>.
416    */

417   public synchronized void shutdownWithoutMBeanUnRegistration() {
418     if (state == STOPPED) {
419       return; // Handle multiple threads doing a shutdown.
420
}
421     
422     if (sessionManager != null) {
423       sessionManager.shutdown();
424       sessionManager = null;
425     }
426     if (databaseManager != null) {
427       databaseManager.shutdown();
428       databaseManager = null;
429     }
430     
431     state = STOPPED;
432   }
433
434   /**
435    * Create the session manager to be used by this application. By
436    * default this will return the <EM>Lutris</EM> standard session manager.
437    * This method can be overwritten to create a custom session
438    * manager.
439    *
440    * @param sessionMgrConfig
441    * Configuration object containing "SessionManager" keys.
442    * This can be <CODE>null</CODE> to use defaults.
443    * @exception ApplicationException
444    * If an error occurs in creating a session manager.
445    * @return
446    * The session manager.
447    */

448   protected SessionManager createSessionManager(Config sessionMgrConfig) throws
449       ApplicationException {
450     if (sessionMgrConfig == null) {
451       sessionMgrConfig = new Config();
452     }
453     try {
454       /*DACHA & TUFA
455        * Config file specified should we keep
456        * SessionManager in memory.
457        */

458       String JavaDoc sessionMgr;
459       if (sessionMgrConfig.containsKey("Class")) {
460         sessionMgr = sessionMgrConfig.getString("Class");
461       }
462       else {
463         sessionMgr =
464             "com.lutris.appserver.server.sessionEnhydra.StandardSessionManager";
465       }
466       Class JavaDoc sessionMgrClass = Class.forName(sessionMgr);
467       Class JavaDoc[] constructorParameterTypes = new Class JavaDoc[3];
468       constructorParameterTypes[0] = Class.forName(
469           "com.lutris.appserver.server.Application");
470       constructorParameterTypes[1] = Class.forName("com.lutris.util.Config");
471       constructorParameterTypes[2] = Class.forName(
472           "com.lutris.logging.LogChannel");
473       Constructor JavaDoc sessionMgrConstructor = sessionMgrClass.getConstructor(
474           constructorParameterTypes);
475       if (sessionMgrConfig.containsKey("MemoryPersistence")) {
476         String JavaDoc mp = sessionMgrConfig.getString("MemoryPersistence");
477         if (mp.equals("true")) {
478           isMemoryPersistence = true;
479         }
480       }
481       SessionManager sm = null;
482       if (this.appName != null) {
483         sm = MemoryPersistence.getSessionManager(this.appName);
484       }
485       if (isMemoryPersistence && (sm != null)) {
486         return sm;
487       }
488       else {
489         // v. strahinja, 26 sep 2002 return new StandardSessionManager(this, sessionMgrConfig, logChannel);
490
Object JavaDoc[] parameters = new Object JavaDoc[3];
491         parameters[0] = this;
492         parameters[1] = sessionMgrConfig;
493         parameters[2] = logChannel;
494         SessionManager sessionManager = (SessionManager) sessionMgrConstructor.
495             newInstance(parameters);
496         return sessionManager;
497       }
498     }
499     catch (Exception JavaDoc except) {
500       throw new ApplicationException(except);
501     }
502   }
503
504   /**
505    * Create the database manager to be used by this application. By
506    * default this will return the <EM>Lutris</EM>
507    * <CODE>StandardDatabaseManager</CODE>.
508    * This method can be overwritten to create a custom session
509    * manager.
510    *
511    * @param databaseMgrConfig
512    * Configuration object containing "DatabaseManager" keys.
513    * @exception ApplicationException
514    * If an error occurs in creating a database manager.
515    */

516   protected DatabaseManager createDatabaseManager(Config databaseMgrConfig) throws
517       ApplicationException {
518     try {
519      String JavaDoc databaseMgr;
520      if (databaseMgrConfig.containsKey("Class")) {
521         databaseMgr = databaseMgrConfig.getString("Class");
522       }
523       else {
524         databaseMgr =
525             STANDARD_DATABASE_MANAGER_CLASS_NAME;
526       }
527       Class JavaDoc standardDbManagerClass = Class.forName(databaseMgr);
528       Class JavaDoc[] ArgClassArray = new Class JavaDoc[] {
529           Config.class
530       };
531       Object JavaDoc[] ArgObject = new Object JavaDoc[] {
532           databaseMgrConfig
533       };
534       Constructor JavaDoc standardDbManager = standardDbManagerClass.
535           getDeclaredConstructor(ArgClassArray);
536       return (DatabaseManager) (standardDbManager.newInstance(ArgObject));
537     }
538     catch (Exception JavaDoc except) {
539       throw new ApplicationException(except);
540     }
541   }
542
543   /**
544    * Create a new session for application. By default this will create
545    * the <EM>Lutris</EM> <CODE>StandardSession</CODE>.
546    * This method can be overwritten to create a custom session.
547    *
548    * @param comms
549    * Object containing request, response and redirect objects.
550    * <I>Warning: comms.session and comms.sessionData will be null.
551    * they are filled in after this method returns.</I>
552    * @return
553    * The session.
554    * @exception ApplicationException
555    * If an error occurs in creating the session.
556    */

557   protected Session createSession(HttpPresentationComms comms) throws
558       ApplicationException {
559     try {
560       return sessionManager.createSession(comms);
561     }
562     catch (Exception JavaDoc exception) {
563       throw new ApplicationException(exception);
564     }
565   }
566
567   /**
568    * Default method used by <CODE>requestPreprocessor</CODE>
569    * to ensure that a session exists and initialize the
570    * <CODE>session</CODE> and <CODE>sessionData</CODE> fields
571    * in the <CODE>HttpPresentationComms</CODE> object.
572    * New sessions are only created on requests to presentation
573    * objects, not requests for other types of files (such as gifs).
574    * This avoids allocating multiple sessions when a browser makes
575    * multiple requests for HREFs. If the session already exist, it
576    * is alwasy set in <CODE>comms</CODE><P>
577    *
578    * This normally looks up the session using a session key from
579    * a cookie.
580    *
581    * @param comms
582    * Object containing request, response and redirect objects.
583    * @exception ApplicationException
584    * If an error occurs setting up the session.
585    */

586   protected void ensureSession(HttpPresentationComms comms) throws
587       ApplicationException {
588     try {
589       if (presentationManager.isPresentationRequest(comms.request)) {
590         // FIX - verify OK
591
comms.session = StandardAppUtil.getRequestSession(comms);
592       }
593       if (comms.session != null &&
594           sessionManager.sessionExists(comms.session.getSessionKey())) {
595         /*
596          * InitializeNewSession() sets up comms.sessionData, so
597          * that it may be used if an application defines it's own
598          * version of that method (after calling the super method,
599          * it has a normal comms object to work with).
600          * Therefore, if we did not call initializeNewSession(),
601          * we have to initialize comms.sessionData here.
602          */

603         comms.sessionData = comms.session.getSessionData();
604       }
605       else {
606         if (presentationManager.isPresentationRequest(comms.request)) {
607           initializeNewSession(comms);
608         }
609       }
610     }
611     catch (HttpPresentationException except) {
612       throw new ApplicationException(except);
613     }
614     catch (SessionException except) {
615       throw new ApplicationException(except);
616     }
617   }
618
619   /**
620    * Calls application session manager's <i>passivateSession</i> method
621    * for the session associated with this request.
622    *
623    * @param comms
624    * Object containing request, response and redirect objects.
625    * @exception ApplicationException
626    * If the session manager was unable to "passivate" the session.
627    * @see com.lutris.appserver.server.session.SessionManager.passivateSession
628    */

629   public void requestPostProcessor(HttpPresentationComms comms) throws
630       ApplicationException {
631     try {
632       if (comms.session != null) {
633         comms.application.getSessionManager().passivateSession(Thread.
634             currentThread(),
635             comms.session.getSessionKey());
636       }
637     }
638     catch (SessionException e) {
639       throw new ApplicationException(e);
640     }
641   }
642
643   /**
644    * This is called when no valid session is found in an incoming request.
645    * A new session is created and added to <CODE>comms</CODE>. If
646    * sending session cookies is enabled, a cookie is created and
647    * added to the response, so future requests will be associated
648    * with the newly created session. If sending session cookies is
649    * disabled, it is the application's responsibility to include
650    * the session ID in URLs to associate further requests with the
651    * session.<P>
652    *
653    * <I>Warning:</I> At first <CODE>comms.session</CODE>
654    * and <CODE>comms.sessionData</CODE> are null. This method initializes
655    * them both.
656    *
657    * @param comms
658    * Object containing request, response and redirect objects. Session
659    * and SessionData objects are initialized.
660    * @exception ApplicationException
661    * If an error occurs setting up the session.
662    * @see #setCookieForNewSession
663    */

664   protected void initializeNewSession(HttpPresentationComms comms) throws
665       ApplicationException {
666     comms.session = createSession(comms);
667     if (sendCookieForNewSession) {
668       StandardAppUtil.bindSessionToClient(comms);
669     }
670     comms.sessionData = comms.session.getSessionData();
671   }
672
673   /**
674    * Returns the specified url rewritten to include the sessionId
675    *
676    * @param url String to urlencode
677    * @return the param url rewritten to contain the sessionId
678    */

679   public String JavaDoc encodeUrl(String JavaDoc url, String JavaDoc sessionKey) throws
680       ApplicationException {
681     return StandardAppUtil.encodeUrl(url, sessionKey);
682   }
683
684   /**
685    * Returns the specified url rewritten to include the sessionId
686    *
687    * @param url String to urlencode
688    * @return the param url rewritten to contain the sessionId
689    * @deprecated Use encodeUrl(String,String)
690    */

691   public String JavaDoc encodeUrl(String JavaDoc url, String JavaDoc sessionKey, String JavaDoc appName) throws
692       ApplicationException {
693     return StandardAppUtil.encodeUrl(url, sessionKey);
694   }
695
696   /**
697    * Default application request preprocessor. This method sets up
698    * a session data structure if a cookie is not set for the application.
699    * It doesn't require a login however. The unauthenticated session is
700    * useful for persistence in simple applications. It is possible to
701    * later force a login. If the URL is not a reference to a presentation
702    * object, then a session will not be allocated if it does not already
703    * exist. This prevents allocation of multiple sessions when a browser
704    * is requesting other objects, such as gifs, in parallel. Thus, after
705    * this function is called, it is possible for session to be null. <P>
706    *
707    * N.B. Purposely not syncronized for speed/concurrency.
708    *
709    * @param comms
710    * Object containing request, response and redirect objects.
711    * @return
712    * Always returns false, as request handling is not done.
713    * @exception Exception
714    * May throw any exception, as with a presentation object;
715    * including page redirects.
716    */

717   public boolean requestPreprocessor(HttpPresentationComms comms) throws
718       Exception JavaDoc {
719     /**
720      * Remap / ---> "defaultUrl" if defined.
721      */

722     if (defaultUrl != null) {
723       String JavaDoc ap = comms.request.getApplicationPath();
724       if (!ap.endsWith("/")) {
725         ap += "/";
726       }
727       String JavaDoc page = comms.request.getPresentationObjectPath();
728       if (!page.endsWith("/")) {
729         page += "/";
730       }
731       if (page.equals(ap)) {
732         // Don't want two slashes in a row.
733
String JavaDoc target = comms.request.getHttpServletRequest().getContextPath();
734         if (target.equals("/")) {
735           target = "";
736         }
737         target = "";
738         if (defaultUrl.startsWith("/")) {
739           target += ap + defaultUrl.substring(1);
740         }
741         else {
742           target += ap + defaultUrl;
743         }
744         // get query string and add it to target
745
String JavaDoc query = comms.request.getQueryString();
746         if (query != null) {
747           target += "?" + query;
748         }
749         
750         /**
751          * Initialize session if one doesn't exist
752          */

753         if (StandardAppUtil.getRequestSession(comms) == null){
754             initializeNewSession(comms);
755         }
756               
757         /**
758          * Set URL encoding for the first application page
759          * to enable further session propagation
760          */

761         try {
762             if (sessionManager instanceof StandardSessionManager){
763                 if (((StandardSessionManager)sessionManager).getEncodeFirstUrl()){
764                     comms.request.setRequestedSessionIdFromUrl(true);
765                 }
766             }
767         } catch (Throwable JavaDoc trowable){}
768         
769         throw new ClientPageRedirectException(target);
770       }
771     }
772     // Only need the session if we haven't redirected to a new page.
773
ensureSession(comms);
774     return false; // Proceed normally.
775
}
776
777   /**
778    * Get the <CODE>SessionManager</CODE> associated with this application.
779    *
780    * @return
781    * The session manager or <CODE>null</CODE> if the application
782    * doesn't have a <CODE>SessionManager</CODE>.
783    */

784   public SessionManager getSessionManager() {
785     return sessionManager;
786   }
787
788   /**
789    * Get the <CODE>DatabaseManager</CODE> associated with this application.
790    *
791    * @return
792    * The database manager or <CODE>null</CODE> if the application
793    * doesn't have a <CODE>DatabaseManager</CODE>.
794    */

795   public DatabaseManager getDatabaseManager() {
796     return databaseManager;
797   }
798
799   /**
800    * Get the <CODE>HttpPresentationManager</CODE> associated with this
801    * application.
802    *
803    * @return The presentation manager.
804    */

805   public HttpPresentationManager getHttpPresentationManager() {
806     return presentationManager;
807   }
808
809   /**
810    * Tells the application about the Presentation Manager running it.
811    * This is necessary because the presentation manager is created
812    * before the application.
813    *
814    * @param pm The HTTP presentation manager running this application.
815    */

816   public void setHttpPresentationManager(HttpPresentationManager pm) {
817     presentationManager = pm;
818   }
819
820   /**
821    * This is a hook that allows applications to act on requests before
822    * they enter the Enhydra framework. This implementation always returns
823    * false, so the request is processed normally. <B>Do not override this
824    * unless you absolutly have to.</B> Currently the only application
825    * that needs to is the debugger, because it needs to hand off requests
826    * to other non-Enhydra servlets. <P>
827    *
828    * In contrast, the method requestPreprocessor() is commonly overridden.
829    * It provides applications with a centeral place to put code that has
830    * to be run on every request before it is sent to the presentation
831    * objects.
832    *
833    * @param servlet
834    * The servlet we are running in.
835    * @param context
836    * The ServletContext that was used to initialize our servlet.
837    * @param request
838    * The incomming request object.
839    * @param response
840    * The incomming response object.
841    * @return
842    * True if this method handled the request, in which case no
843    * further action will be taken. Or false if normal processing
844    * should continue.
845    * @exception ServletException
846    * You are allowed to throw the same exceptions that the servlet's
847    * service() method throws.
848    * @exception IOException
849    * You are allowed to throw the same exceptions that the servlet's
850    * service() method throws.
851    */

852   public boolean servletRequestPreprocessor(Servlet JavaDoc servlet,
853                                             ServletContext JavaDoc context,
854                                             HttpServletRequest JavaDoc request,
855                                             HttpServletResponse JavaDoc response) throws
856       ServletException JavaDoc,
857       IOException JavaDoc {
858     return false;
859   }
860
861   /**
862    * Get the XMLC factory object being used by the application.
863    */

864   public XMLCFactory getXMLCFactory() {
865     return xmlcFactory;
866   }
867
868   /**
869    * Set the XMLC factory based on the deferred parsing option.
870    */

871   public void setXMLCFactory(boolean enableDeferredParsing) {
872     if (enableDeferredParsing) {
873       xmlcFactory = new XMLCDeferredParsingFactory(new DocumentLoaderImpl(),
874           (MultiClassLoader) presentationManager.getAppClassLoader(),
875           new EnhydraXMLCLogger(logChannel));
876     }
877     else {
878       xmlcFactory = new XMLCStdFactory(presentationManager.getAppClassLoader(),
879                                        new EnhydraXMLCLogger(logChannel));
880     }
881   }
882
883   /**
884    * Initializes the Jivan factory object which can be used by application.
885    * @param reload swich which indicates realoading status of Jivan generated
886    * pages in presentation layer (true = reload is on, false = reload is off)
887    */

888   public void setJivanFactory(boolean reload) {
889     this.jivanFactory = new JivanFactory(reload, this.logChannel);
890   }
891
892   /**
893    * Get the Jivan factory object being used by the application.
894    */

895   public JivanFactory getJivanFactory() {
896     return this.jivanFactory;
897   }
898   
899
900   /**
901    * Get the MBeanServer object being used by the application.
902    */

903   private MBeanServer JavaDoc findMBeanServer() throws com.lutris.appserver.server.
904
      session.SessionException {
905     MBeanServer JavaDoc mBeanServer;
906     try {
907       java.util.ArrayList JavaDoc server = MBeanServerFactory.findMBeanServer(null);
908       if (server == null) {
909         return null;
910       }
911       else {
912         mBeanServer = (MBeanServer JavaDoc) server.get(0);
913       }
914     }
915     catch (Exception JavaDoc e) {
916       throw new com.lutris.appserver.server.session.SessionException(e);
917     }
918     return mBeanServer;
919   }
920   
921   /**
922    * Get the Application Info HTML presentation.
923    */

924   public String JavaDoc toHtml() {
925     return "No Application Info";
926   }
927   
928   /**
929    * Application MBean definition section
930    *
931    * Definitions of application MBean implementations.
932    * All present MBean Implementations extend basic
933    * EafConfigMBean implementation which defines basic
934    * Config MBean actions.
935    **/

936   
937   private void registerApplicationMBean(){
938       if (appName == null) {
939         return;
940       }
941       
942       try {
943         server = findMBeanServer();
944         if (server == null) {
945           return;
946         }
947       }
948       catch (Exception JavaDoc e) {
949            logChannel.write(Logger.DEBUG, e.toString());
950       }
951
952       try {
953         String JavaDoc applicationName = appName;
954
955         ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=ApplicationConfig,name="
956                 + applicationName);
957         
958         if (!server.isRegistered(objectName)) {
959           String JavaDoc [] includes = null;
960           String JavaDoc [] excludes = {"SessionManager", "PresentationManager", "DatabaseManager"};
961           appConfigMBean = new ApplicationConfigMBean(this,objectName,null,includes,excludes);
962           server.registerMBean(appConfigMBean, objectName);
963         }
964         
965       }
966       catch (Exception JavaDoc e) {
967          logChannel.write(Logger.DEBUG, e.toString());
968         return;
969       }
970   }
971   
972   private void unRegisterApplicationMBean(){
973     if (appName == null) {
974       return;
975     }
976     
977     try {
978       server = findMBeanServer();
979       if (server == null) {
980         return;
981       }
982     }
983     catch (Exception JavaDoc e) {
984          logChannel.write(Logger.DEBUG, e.toString());
985     }
986
987     try {
988       String JavaDoc applicationName = appName;
989
990       ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=ApplicationConfig,name="
991             + applicationName);
992       
993       if (server.isRegistered(objectName)) {
994         server.unregisterMBean(objectName);
995       }
996       
997     }
998     catch (Exception JavaDoc e) {
999        logChannel.write(Logger.DEBUG, e.toString());
1000      return;
1001    }
1002  }
1003
1004  /**
1005   * Application Config MBean
1006   */

1007  private class ApplicationConfigMBean extends EafConfigMBean{
1008    public ApplicationConfigMBean (Application application,
1009            ObjectName JavaDoc objectName, String JavaDoc prefix,
1010            String JavaDoc [] includes, String JavaDoc [] excludes){
1011        super(application,objectName,prefix,includes,excludes);
1012        buildDynamicMBeanInfo();
1013    }
1014    
1015    /**
1016     * Sets the value of the specified attribute of the Dynamic MBean.
1017     */

1018    public void setAttribute(Attribute JavaDoc attribute) throws
1019        AttributeNotFoundException JavaDoc,
1020        InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
1021      
1022        super.setAttribute(attribute);
1023        
1024        // restart without MBean UnRegistration
1025
shutdownWithoutMBeanUnRegistration();
1026        try {
1027            startup(config);
1028        }
1029        catch (Exception JavaDoc e) {
1030            logChannel.write(Logger.DEBUG, e.toString());
1031        }
1032    }
1033    
1034    /**
1035     * Allows an operation to be invoked on the Dynamic MBean.
1036     */

1037    public Object JavaDoc invoke(String JavaDoc operationName, Object JavaDoc params[],
1038                         String JavaDoc signature[]) throws MBeanException JavaDoc,
1039        ReflectionException JavaDoc {
1040      // Check operationName is not null to avoid NullPointerException later on
1041
if (operationName == null) {
1042        throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc(
1043            "Operation name cannot be null"),
1044            "Cannot invoke a null operation in " + dClassName);
1045      }
1046      // Check for a recognized operation name and call the corresponding operation
1047
if (operationName.equals("getConfig")) {
1048        return config;
1049      } else{
1050        // basic set of operations
1051
return super.invoke(operationName, params, signature);
1052      }
1053    }
1054    
1055    /**
1056     * Method returns MBean's MBeanOperationInfo Array
1057     * @return MBeanOperationInfo[]
1058     */

1059    protected MBeanOperationInfo JavaDoc[] getMBeanOperationsInfo () {
1060        MBeanParameterInfo JavaDoc[] params = null;
1061        MBeanOperationInfo JavaDoc[] dOperations = new MBeanOperationInfo JavaDoc[6];
1062        dOperations[0] = new MBeanOperationInfo JavaDoc("reset",
1063            "reset(): reset attributes to their initial values",
1064            params, "void",
1065            MBeanOperationInfo.ACTION);
1066        dOperations[1] = new MBeanOperationInfo JavaDoc("saveAttributes",
1067            "saveAttributes(): save the attribute values into the configuration file",
1068            params, "void",
1069            MBeanOperationInfo.ACTION);
1070        dOperations[2] = new MBeanOperationInfo JavaDoc("getAppInfo",
1071            "getAppInfo(): get application information",
1072            params, "String",
1073            MBeanOperationInfo.ACTION);
1074        
1075        params = new MBeanParameterInfo JavaDoc[2];
1076        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
1077                "use UNDERLINE (_) as attribute group separator.");
1078        params[1] = new MBeanParameterInfo JavaDoc("attValue","java.lang.String","Attribute value!");
1079        
1080        dOperations[3] = new MBeanOperationInfo JavaDoc("addAttribute",
1081              "addAttribute(String key, String value): add new application parameter",
1082              params, "void",
1083              MBeanOperationInfo.ACTION);
1084        
1085        params = new MBeanParameterInfo JavaDoc[1];
1086        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
1087                "use UNDERLINE (_) as attribute group separator.");
1088        
1089        dOperations[4] = new MBeanOperationInfo JavaDoc("removeAttribute",
1090              "removeAttribute(String key): remove application parameter",
1091              params, "void",
1092              MBeanOperationInfo.ACTION);
1093        
1094        params = null;
1095        
1096        dOperations[5] = new MBeanOperationInfo JavaDoc("getConfig",
1097                "getConfig(): Gets actual application Config object.",
1098                params, "com.lutris.util.Config",
1099                MBeanOperationInfo.ACTION);
1100       
1101        return dOperations;
1102    }
1103    
1104  }
1105  
1106  private void registerSessionManagerMBean(){
1107      if (appName == null) {
1108      return;
1109    }
1110    
1111      try {
1112      server = findMBeanServer();
1113      if (server == null) {
1114        return;
1115      }
1116    }
1117    catch (Exception JavaDoc e) {
1118         logChannel.write(Logger.DEBUG, e.toString());
1119    }
1120
1121    try {
1122        String JavaDoc applicationName = appName;
1123
1124      ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=SessionManager,name="
1125            + applicationName);
1126      
1127      if (!server.isRegistered(objectName)) {
1128        String JavaDoc [] includes = {"SessionManager"};
1129        String JavaDoc [] excludes = null;
1130        sessionManagerMBean = new SessionManagerMBean(this,objectName,"SessionManager",includes,excludes);
1131        server.registerMBean(sessionManagerMBean, objectName);
1132      }
1133      
1134    }
1135    catch (Exception JavaDoc e) {
1136       logChannel.write(Logger.DEBUG, e.toString());
1137      return;
1138    }
1139  }
1140  
1141  private void unRegisterSessionManagerMBean(){
1142    if (appName == null) {
1143      return;
1144    }
1145    
1146    try {
1147      server = findMBeanServer();
1148      if (server == null) {
1149        return;
1150      }
1151    }
1152    catch (Exception JavaDoc e) {
1153         logChannel.write(Logger.DEBUG, e.toString());
1154    }
1155
1156    try {
1157      String JavaDoc applicationName = appName;
1158
1159      ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=SessionManager,name="
1160            + applicationName);
1161      
1162      if (server.isRegistered(objectName)) {
1163        server.unregisterMBean(objectName);
1164      }
1165      
1166    }
1167    catch (Exception JavaDoc e) {
1168       logChannel.write(Logger.DEBUG, e.toString());
1169      return;
1170    }
1171  }
1172  
1173  /**
1174   * SessionManager MBean
1175   */

1176  private class SessionManagerMBean extends EafConfigMBean{
1177    public SessionManagerMBean (Application application,
1178            ObjectName JavaDoc objectName, String JavaDoc prefix,
1179            String JavaDoc [] includes, String JavaDoc [] excludes){
1180        super(application,objectName,prefix,includes,excludes);
1181        buildDynamicMBeanInfo();
1182    }
1183    
1184    /**
1185     * Sets the value of the specified attribute of the Dynamic MBean.
1186     */

1187    public void setAttribute(Attribute JavaDoc attribute) throws
1188        AttributeNotFoundException JavaDoc,
1189        InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
1190      
1191        super.setAttribute(attribute);
1192        
1193        // restart without MBean UnRegistration
1194
shutdownWithoutMBeanUnRegistration();
1195        try {
1196            startup(config);
1197        }
1198        catch (Exception JavaDoc e) {
1199            logChannel.write(Logger.DEBUG, e.toString());
1200        }
1201    }
1202    
1203    /**
1204     * Allows an operation to be invoked on the Dynamic MBean.
1205     */

1206    public Object JavaDoc invoke(String JavaDoc operationName, Object JavaDoc params[],
1207                         String JavaDoc signature[]) throws MBeanException JavaDoc,
1208        ReflectionException JavaDoc {
1209        // PresentationManager additional functionalities
1210
if (operationName.equals("sessionExists")) {
1211            boolean temp = false;
1212            try {
1213                if (params!=null && params.length==1){
1214                    temp = sessionManager.sessionExists((String JavaDoc)params[0]);
1215                }
1216                return new Boolean JavaDoc(temp);
1217            }catch (Exception JavaDoc e) {
1218              throw new MBeanException JavaDoc(e);
1219            }
1220        } else if (operationName.equals("activeSessionCount")) {
1221            int temp = 0;
1222            try {
1223                temp = sessionManager.activeSessionCount();
1224                return new Integer JavaDoc(temp);
1225            }catch (Exception JavaDoc e){
1226                throw new MBeanException JavaDoc(e);
1227            }
1228        } else if (operationName.equals("getSessionKeys")) {
1229            Enumeration JavaDoc temp = null;
1230            try {
1231                temp = sessionManager.getSessionKeys();
1232                return temp;
1233            }catch (Exception JavaDoc e){
1234                throw new MBeanException JavaDoc(e);
1235            }
1236        } else if (operationName.equals("getSession")) {
1237            Session temp = null;
1238            try {
1239                if (params!=null && params.length==1){
1240                    temp = sessionManager.getSession((String JavaDoc)params[0]);
1241                }
1242                return temp;
1243            }catch (Exception JavaDoc e){
1244                throw new MBeanException JavaDoc(e);
1245            }
1246        } else if (operationName.equals("getSessionManager")) {
1247            try {
1248                return sessionManager;
1249            }catch (Exception JavaDoc e){
1250                throw new MBeanException JavaDoc(e);
1251            }
1252        } else if (operationName.equals("getEncodeUrlState")) {
1253            try {
1254                return sessionManager.getEncodeUrlState();
1255            }catch (Exception JavaDoc e){
1256                throw new MBeanException JavaDoc(e);
1257            }
1258        } else if (operationName.equals("createSession")) {
1259            try {
1260                Session sesion = null;
1261                if (params!=null && params.length==1){
1262                    sesion = sessionManager.createSession((String JavaDoc)params[0]);
1263                }
1264                return sesion;
1265            }catch (Exception JavaDoc e){
1266                throw new MBeanException JavaDoc(e);
1267            }
1268        } else if (operationName.equals("deleteSession")) {
1269            try {
1270                if (params!=null && params.length==1){
1271                    sessionManager.deleteSession((String JavaDoc)params[0]);
1272                }
1273                return null;
1274            }catch (Exception JavaDoc e){
1275                throw new MBeanException JavaDoc(e);
1276            }
1277        } else{
1278            // basic set of operations
1279
return super.invoke(operationName, params, signature);
1280        }
1281    }
1282    
1283    /**
1284     * Method returns MBean's MBeanOperationInfo Array
1285     * @return MBeanOperationInfo[]
1286     */

1287    protected MBeanOperationInfo JavaDoc[] getMBeanOperationsInfo () {
1288        
1289        boolean includeAdditional = true;
1290        if (hashAttrib.containsKey("Class")){
1291            String JavaDoc value = (String JavaDoc) hashAttrib.get("Class");
1292            if ("com.lutris.appserver.server.sessionContainerAdapter.ContainerAdapterSessionManager".equals(value)
1293                    ||"com.lutris.appserver.server.sessionContainerAdapter.JmxContainerAdapterSessionManager".equals(value)){
1294                includeAdditional = false;
1295            }
1296        }
1297        
1298        MBeanParameterInfo JavaDoc[] params = null;
1299        MBeanOperationInfo JavaDoc[] dOperations = null;
1300        if (includeAdditional){
1301            dOperations = new MBeanOperationInfo JavaDoc[13];
1302        } else {
1303            dOperations = new MBeanOperationInfo JavaDoc[7];
1304        }
1305        
1306        dOperations[0] = new MBeanOperationInfo JavaDoc("reset",
1307            "reset(): reset attributes to their initial values",
1308            params, "void",
1309            MBeanOperationInfo.ACTION);
1310        dOperations[1] = new MBeanOperationInfo JavaDoc("saveAttributes",
1311            "saveAttributes(): save the attribute values into the configuration file",
1312            params, "void",
1313            MBeanOperationInfo.ACTION);
1314        dOperations[2] = new MBeanOperationInfo JavaDoc("getAppInfo",
1315            "getAppInfo(): get application information",
1316            params, "String",
1317            MBeanOperationInfo.ACTION);
1318        
1319        params = new MBeanParameterInfo JavaDoc[2];
1320        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
1321                "use UNDERLINE (_) as attribute group separator.");
1322        params[1] = new MBeanParameterInfo JavaDoc("attValue","java.lang.String","Attribute value!");
1323        
1324        dOperations[3] = new MBeanOperationInfo JavaDoc("addAttribute",
1325              "addAttribute(String key, String value): add new application parameter",
1326              params, "void",
1327              MBeanOperationInfo.ACTION);
1328        
1329        params = new MBeanParameterInfo JavaDoc[1];
1330        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
1331                "use UNDERLINE (_) as attribute group separator.");
1332        
1333        dOperations[4] = new MBeanOperationInfo JavaDoc("removeAttribute",
1334              "removeAttribute(String key): remove application parameter",
1335              params, "void",
1336              MBeanOperationInfo.ACTION);
1337        
1338        params = null;
1339        
1340        dOperations[5] = new MBeanOperationInfo JavaDoc("getSessionManager",
1341                "getSessionManager(): " +
1342                "Get an SessionManager object.",
1343                params, "com.lutris.appserver.server.session.SessionManager",
1344                MBeanOperationInfo.ACTION);
1345        
1346        dOperations[6] = new MBeanOperationInfo JavaDoc("getEncodeUrlState",
1347                "getEncodeUrlState(): " +
1348                "Get the value indicating the url encoding status.",
1349                params, "com.lutris.appserver.server.session.SessionManager",
1350                MBeanOperationInfo.ACTION);
1351        
1352        if (includeAdditional){
1353            dOperations[7] = new MBeanOperationInfo JavaDoc("activeSessionCount",
1354                    "activeSessionCount(): " +
1355                    "Gets the number of currently active sessions.",
1356                    params, "int",
1357                    MBeanOperationInfo.ACTION);
1358            
1359            dOperations[8] = new MBeanOperationInfo JavaDoc("getSessionKeys",
1360                    "getSessionKeys(): " +
1361                    "Get an enumeration of all session keys. ",
1362                    params, "java.util.Enumeration",
1363                    MBeanOperationInfo.ACTION);
1364            
1365            params = new MBeanParameterInfo JavaDoc[1];
1366            params[0] = new MBeanParameterInfo JavaDoc("sessionKey","java.lang.String",
1367                    "The String used to reference a Session object.");
1368            
1369            dOperations[9] = new MBeanOperationInfo JavaDoc("sessionExists",
1370                    "sessionExists(String sessionKey): " +
1371                    "Returns whether the Session object " +
1372                    "associated with the specified session key exists",
1373                    params, "boolean",
1374                    MBeanOperationInfo.ACTION);
1375            
1376            dOperations[10] = new MBeanOperationInfo JavaDoc("getSession",
1377                    "getSession(String sessionKey): " +
1378                    "Returns the Session object associated with the " +
1379                    "specified session key. The session is put in the " +
1380                    "ACTIVE state.",
1381                    params, "com.lutris.appserver.server.session.Session",
1382                    MBeanOperationInfo.ACTION);
1383            
1384            dOperations[11] = new MBeanOperationInfo JavaDoc("createSession",
1385                    "createSession(String sessionKey): " +
1386                    "Create a new Session object and an associated " +
1387                    "unique random key. No <CODE>User</CODE> object is " +
1388                    "initially associated with the session",
1389                    params, "com.lutris.appserver.server.session.Session",
1390                    MBeanOperationInfo.ACTION);
1391            
1392            dOperations[12] = new MBeanOperationInfo JavaDoc("deleteSession",
1393                    "deleteSession(String sessionKey): " +
1394                    "Removes a session from the manager.",
1395                    params, "com.lutris.appserver.server.session.Session",
1396                    MBeanOperationInfo.ACTION);
1397        }
1398        return dOperations;
1399    }
1400    
1401  }
1402  
1403
1404  private void registerPresentationManagerMBean(){
1405      if (appName == null) {
1406      return;
1407    }
1408    
1409      try {
1410      server = findMBeanServer();
1411      if (server == null) {
1412        return;
1413      }
1414    }
1415    catch (Exception JavaDoc e) {
1416         logChannel.write(Logger.DEBUG, e.toString());
1417    }
1418
1419    try {
1420        String JavaDoc applicationName = appName;
1421
1422      ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=PresentationManager,name="
1423            + applicationName);
1424      
1425      if (!server.isRegistered(objectName)) {
1426        String JavaDoc [] includes = {"PresentationManager"};
1427        String JavaDoc [] excludes = null;
1428        presentationManagerMBean = new PresentationManagerMBean(this,objectName,"PresentationManager",includes,excludes);
1429        server.registerMBean(presentationManagerMBean, objectName);
1430      }
1431      
1432    }
1433    catch (Exception JavaDoc e) {
1434       logChannel.write(Logger.DEBUG, e.toString());
1435      return;
1436    }
1437  }
1438
1439  private void unRegisterPresentationManagerMBean(){
1440    if (appName == null) {
1441      return;
1442    }
1443    
1444    try {
1445      server = findMBeanServer();
1446      if (server == null) {
1447        return;
1448      }
1449    }
1450    catch (Exception JavaDoc e) {
1451         logChannel.write(Logger.DEBUG, e.toString());
1452    }
1453
1454    try {
1455      String JavaDoc applicationName = appName;
1456
1457      ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=PresentationManager,name="
1458            + applicationName);
1459      
1460      if (server.isRegistered(objectName)) {
1461        server.unregisterMBean(objectName);
1462      }
1463      
1464    }
1465    catch (Exception JavaDoc e) {
1466       logChannel.write(Logger.DEBUG, e.toString());
1467      return;
1468    }
1469  }
1470  
1471  /**
1472   * PresentationManager MBean
1473   */

1474  private class PresentationManagerMBean extends EafConfigMBean{
1475    
1476    /**
1477     * PresentationManager MBean Constructor method
1478     */

1479    public PresentationManagerMBean (Application application,
1480            ObjectName JavaDoc objectName, String JavaDoc prefix,
1481            String JavaDoc [] includes, String JavaDoc [] excludes){
1482        super(application,objectName,prefix,includes,excludes);
1483        buildDynamicMBeanInfo();
1484    }
1485    
1486    /**
1487     * Sets the value of the specified attribute of the Dynamic MBean.
1488     */

1489    public void setAttribute(Attribute JavaDoc attribute) throws
1490        AttributeNotFoundException JavaDoc,
1491        InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
1492      
1493        super.setAttribute(attribute);
1494        
1495        // restart without MBean UnRegistration
1496
shutdownWithoutMBeanUnRegistration();
1497        try {
1498            startup(config);
1499        }
1500        catch (Exception JavaDoc e) {
1501            logChannel.write(Logger.DEBUG, e.toString());
1502        }
1503    }
1504    
1505    /**
1506     * Allows an operation to be invoked on the Dynamic MBean.
1507     */

1508    public Object JavaDoc invoke(String JavaDoc operationName, Object JavaDoc params[],
1509                         String JavaDoc signature[]) throws MBeanException JavaDoc,
1510        ReflectionException JavaDoc {
1511        // PresentationManager additional functionalities
1512
if (operationName.equals("flushCache")) {
1513            try {
1514              presentationManager.flushCache();
1515            }catch (Exception JavaDoc e) {
1516              throw new MBeanException JavaDoc(e);
1517            }
1518            return null;
1519        } else if (operationName.equals("sizeofPOCache")) {
1520            int temp = 0;
1521            try {
1522                temp = presentationManager.sizeofPOCache();
1523            }catch (Exception JavaDoc e) {
1524              throw new MBeanException JavaDoc(e);
1525            }
1526            return new Integer JavaDoc(temp);
1527        } else if (operationName.equals("sizeofResourceCache")) {
1528            int temp = 0;
1529            try {
1530              temp = presentationManager.sizeofResourceCache();
1531            }catch (Exception JavaDoc e) {
1532              throw new MBeanException JavaDoc(e);
1533            }
1534            return new Integer JavaDoc(temp);
1535        } else if (operationName.equals("addMimeType")) {
1536            if (params!=null && params.length==2){
1537                presentationManager.addMimeType((String JavaDoc)params[0],(String JavaDoc)params[1]);
1538            }
1539            return null;
1540        } else if (operationName.equals("getPresentationManager")) {
1541            try {
1542                return presentationManager;
1543            }catch (Exception JavaDoc e) {
1544                throw new MBeanException JavaDoc(e);
1545            }
1546        } else{
1547            // basic set of operations
1548
return super.invoke(operationName, params, signature);
1549        }
1550    }
1551    
1552    /**
1553     * Method returns MBeanOperationInfo
1554     * @return MBeanOperationInfo[]
1555     */

1556    protected MBeanOperationInfo JavaDoc[] getMBeanOperationsInfo () {
1557        MBeanParameterInfo JavaDoc[] params = null;
1558        MBeanOperationInfo JavaDoc[] dOperations = new MBeanOperationInfo JavaDoc[10];
1559        dOperations[0] = new MBeanOperationInfo JavaDoc("reset",
1560            "reset(): reset attributes to their initial values",
1561            params, "void",
1562            MBeanOperationInfo.ACTION);
1563        dOperations[1] = new MBeanOperationInfo JavaDoc("saveAttributes",
1564            "saveAttributes(): save the attribute values into the configuration file",
1565            params, "void",
1566            MBeanOperationInfo.ACTION);
1567        dOperations[2] = new MBeanOperationInfo JavaDoc("getAppInfo",
1568            "getAppInfo(): get application information",
1569            params, "String",
1570            MBeanOperationInfo.ACTION);
1571        
1572        params = new MBeanParameterInfo JavaDoc[2];
1573        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
1574                "use UNDERLINE (_) as attribute group separator.");
1575        params[1] = new MBeanParameterInfo JavaDoc("attValue","java.lang.String","Attribute value!");
1576        
1577        dOperations[3] = new MBeanOperationInfo JavaDoc("addAttribute",
1578              "addAttribute(String key, String value): add new application parameter",
1579              params, "void",
1580              MBeanOperationInfo.ACTION);
1581        
1582        params = new MBeanParameterInfo JavaDoc[1];
1583        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
1584                "use UNDERLINE (_) as attribute group separator.");
1585        
1586        dOperations[4] = new MBeanOperationInfo JavaDoc("removeAttribute",
1587              "removeAttribute(String key): remove application parameter",
1588              params, "void",
1589              MBeanOperationInfo.ACTION);
1590        
1591        params = null;
1592        
1593        dOperations[5] = new MBeanOperationInfo JavaDoc("getPresentationManager",
1594                "getPresentationManager(): Gets actual PresentationManager object reference.",
1595                params, "com.lutris.appserver.server.httpPresentation.HttpPresentationManager",
1596                MBeanOperationInfo.ACTION);
1597        
1598        dOperations[6] = new MBeanOperationInfo JavaDoc("flushCache",
1599                "flushCache(): Flush the presentation object and resource caches",
1600                params, "void",
1601                MBeanOperationInfo.ACTION);
1602        
1603        dOperations[7] = new MBeanOperationInfo JavaDoc("sizeofPOCache",
1604                "sizeofPOCache(): the number of entries in the cache or 0 is disabled",
1605                params, "int",
1606                MBeanOperationInfo.ACTION);
1607        
1608        dOperations[8] = new MBeanOperationInfo JavaDoc("sizeofResourceCache",
1609                "sizeofResourceCache(): number of entries in the cache or 0 is disabled",
1610                params, "int",
1611                MBeanOperationInfo.ACTION);
1612        
1613        params = new MBeanParameterInfo JavaDoc[2];
1614        params[0] = new MBeanParameterInfo JavaDoc("mimeType","java.lang.String",
1615                "Mime Type you want to add!");
1616        params[1] = new MBeanParameterInfo JavaDoc("extension","java.lang.String",
1617                "Extension of Mime Type you want to add!");
1618        
1619        dOperations[9] = new MBeanOperationInfo JavaDoc("addMimeType",
1620              "addMimeType(String mimeType, String extension): Add a new mime type to extension mapping.",
1621              params, "void",
1622              MBeanOperationInfo.ACTION);
1623       
1624        return dOperations;
1625    }
1626    
1627  }
1628  
1629
1630  private void registerDatabaseManagerMBean(){
1631      if (appName == null) {
1632      return;
1633    }
1634    
1635      try {
1636      server = findMBeanServer();
1637      if (server == null) {
1638        return;
1639      }
1640    }
1641    catch (Exception JavaDoc e) {
1642         logChannel.write(Logger.DEBUG, e.toString());
1643    }
1644
1645    try {
1646        String JavaDoc applicationName = appName;
1647
1648      ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=DatabaseManager,name="
1649            + applicationName);
1650      
1651      if (!server.isRegistered(objectName)) {
1652        String JavaDoc [] includes = {"DatabaseManager"};
1653        String JavaDoc [] excludes = {"DatabaseManager_DB"};
1654        databaseManagerMBean = new DatabaseManagerMBean(this,objectName,"DatabaseManager",includes,excludes);
1655        server.registerMBean(databaseManagerMBean, objectName);
1656      }
1657      
1658    }
1659    catch (Exception JavaDoc e) {
1660       logChannel.write(Logger.DEBUG, e.toString());
1661      return;
1662    }
1663  }
1664
1665  private void unRegisterDatabaseManagerMBean(){
1666    if (appName == null) {
1667      return;
1668    }
1669    
1670    try {
1671      server = findMBeanServer();
1672      if (server == null) {
1673        return;
1674      }
1675    }
1676    catch (Exception JavaDoc e) {
1677         logChannel.write(Logger.DEBUG, e.toString());
1678    }
1679
1680    try {
1681      String JavaDoc applicationName = appName;
1682
1683      ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=DatabaseManager,name="
1684            + applicationName);
1685      
1686      if (server.isRegistered(objectName)) {
1687        server.unregisterMBean(objectName);
1688      }
1689      
1690    }
1691    catch (Exception JavaDoc e) {
1692       logChannel.write(Logger.DEBUG, e.toString());
1693      return;
1694    }
1695  }
1696
1697  /**
1698   * DatabaseManager MBean
1699   */

1700  private class DatabaseManagerMBean extends EafConfigMBean{
1701    public DatabaseManagerMBean (Application application,
1702            ObjectName JavaDoc objectName, String JavaDoc prefix,
1703            String JavaDoc [] includes, String JavaDoc [] excludes){
1704        super(application,objectName,prefix,includes,excludes);
1705        buildDynamicMBeanInfo();
1706    }
1707    
1708    /**
1709     * Sets the value of the specified attribute of the Dynamic MBean.
1710     */

1711    public void setAttribute(Attribute JavaDoc attribute) throws
1712        AttributeNotFoundException JavaDoc,
1713        InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
1714      
1715        super.setAttribute(attribute);
1716        
1717        // restart without MBean UnRegistration
1718
shutdownWithoutMBeanUnRegistration();
1719        try {
1720            startup(config);
1721        }
1722        catch (Exception JavaDoc e) {
1723            logChannel.write(Logger.DEBUG, e.toString());
1724        }
1725    }
1726    
1727    /**
1728     * Allows an operation to be invoked on the Dynamic MBean.
1729     */

1730    public Object JavaDoc invoke(String JavaDoc operationName, Object JavaDoc params[],
1731                         String JavaDoc signature[]) throws MBeanException JavaDoc,
1732        ReflectionException JavaDoc {
1733      // Check operationName is not null to avoid NullPointerException later on
1734
if (operationName == null) {
1735        throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc(
1736            "Operation name cannot be null"),
1737            "Cannot invoke a null operation in " + dClassName);
1738      }
1739      // Check for a recognized operation name and call the corresponding operation
1740
if (operationName.equals("Toggle_EnableOrDisable_Cache")) {
1741        try {
1742            return enableDisableCaching();
1743        }catch (Exception JavaDoc e) {
1744            throw new MBeanException JavaDoc(e);
1745        }
1746      } else if (operationName.equals("Enable_Cache")) {
1747        try {
1748            return enableCaching();
1749        }catch (Exception JavaDoc e) {
1750            throw new MBeanException JavaDoc(e);
1751        }
1752      } else if (operationName.equals("Disable_Cache")) {
1753        try {
1754            return disableCaching();
1755        }catch (Exception JavaDoc e) {
1756            throw new MBeanException JavaDoc(e);
1757        }
1758      } else if (operationName.equals("Refresh_Cache")) {
1759        try {
1760            return refreshCache();
1761        }catch (Exception JavaDoc e) {
1762            throw new MBeanException JavaDoc(e);
1763        }
1764      } else if (operationName.equals("Refresh_Statistics")) {
1765        try {
1766            return refreshStatistics();
1767        }catch (Exception JavaDoc e) {
1768            throw new MBeanException JavaDoc(e);
1769        }
1770      } else if (operationName.equals("getDatabaseManager")) {
1771        return databaseManager;
1772      } else{
1773        // basic set of operations
1774
return super.invoke(operationName, params, signature);
1775      }
1776    }
1777    
1778    /**
1779     * Method returns MBean's MBeanOperationInfo Array
1780     * @return MBeanOperationInfo[]
1781     */

1782    protected MBeanOperationInfo JavaDoc[] getMBeanOperationsInfo () {
1783        MBeanParameterInfo JavaDoc[] params = null;
1784        MBeanOperationInfo JavaDoc[] dOperations = new MBeanOperationInfo JavaDoc[11];
1785        dOperations[0] = new MBeanOperationInfo JavaDoc("reset",
1786            "reset(): reset attributes to their initial values",
1787            params, "void",
1788            MBeanOperationInfo.ACTION);
1789        dOperations[1] = new MBeanOperationInfo JavaDoc("saveAttributes",
1790            "saveAttributes(): save the attribute values into the configuration file",
1791            params, "void",
1792            MBeanOperationInfo.ACTION);
1793        dOperations[2] = new MBeanOperationInfo JavaDoc("getAppInfo",
1794            "getAppInfo(): get application information",
1795            params, "String",
1796            MBeanOperationInfo.ACTION);
1797        
1798        params = new MBeanParameterInfo JavaDoc[2];
1799        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
1800                "use UNDERLINE (_) as attribute group separator.");
1801        params[1] = new MBeanParameterInfo JavaDoc("attValue","java.lang.String","Attribute value!");
1802        
1803        dOperations[3] = new MBeanOperationInfo JavaDoc("addAttribute",
1804              "addAttribute(String key, String value): add new application parameter",
1805              params, "void",
1806              MBeanOperationInfo.ACTION);
1807        
1808        params = new MBeanParameterInfo JavaDoc[1];
1809        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
1810                "use UNDERLINE (_) as attribute group separator.");
1811        
1812        dOperations[4] = new MBeanOperationInfo JavaDoc("removeAttribute",
1813              "removeAttribute(String key): remove application parameter",
1814              params, "void",
1815              MBeanOperationInfo.ACTION);
1816        
1817        params = null;
1818        
1819        dOperations[5] = new MBeanOperationInfo JavaDoc("getDatabaseManager",
1820                "getDatabaseManager(): Gets actual application DatabaseManager object.",
1821                params, "com.lutris.appserver.server.sql.DatabaseManager",
1822                MBeanOperationInfo.ACTION);
1823        
1824        dOperations[6] = new MBeanOperationInfo JavaDoc("Refresh_Cache",
1825                "refreshCache(): Refresh DatabaseManager Cache.",
1826                params, "java.lang.String",
1827                MBeanOperationInfo.ACTION);
1828        
1829        dOperations[7] = new MBeanOperationInfo JavaDoc("Refresh_Statistics",
1830                "refreshStatistics(): Refresh DatabaseManager Statistics.",
1831                params, "java.lang.String",
1832                MBeanOperationInfo.ACTION);
1833        
1834        dOperations[8] = new MBeanOperationInfo JavaDoc("Enable_Cache",
1835                "enableCaching(): Enables DatabaseManager Cache Status.",
1836                params, "java.lang.String",
1837                MBeanOperationInfo.ACTION);
1838        
1839        dOperations[9] = new MBeanOperationInfo JavaDoc("Disable_Cache",
1840                "disableCaching(): Disables DatabaseManager Cache Status.",
1841                params, "java.lang.String",
1842                MBeanOperationInfo.ACTION);
1843        
1844        dOperations[10] = new MBeanOperationInfo JavaDoc("Toggle_EnableOrDisable_Cache",
1845                "enableDisableCaching(): Toggles DatabaseManager Cache Status.",
1846                params, "java.lang.String",
1847                MBeanOperationInfo.ACTION);
1848       
1849        return dOperations;
1850    }
1851    
1852    private String JavaDoc enableDisableCaching() {
1853        String JavaDoc retString = TableMBean.TABLE +
1854        TableMBean.CAPTION + TableMBean.BOLD +
1855        TableMBean.COLOUR + TableMBean.BLUE +
1856        "DatabaseManagar" + TableMBean.E_COLOUR +
1857        TableMBean.E_BOLD + TableMBean.E_CAPTION;
1858        
1859        int length = tableMBeans.size();
1860        Enumeration JavaDoc objectNames = tableMBeans.keys();
1861        for (int i=0;i<length;i++){
1862            String JavaDoc keyName = (String JavaDoc) objectNames.nextElement();
1863            retString = retString+TableMBean.ROW;
1864            TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName);
1865            retString = retString+TableMBean.DATA+
1866            TableMBean.BOLD + TableMBean.COLOUR +
1867            TableMBean.BLUE + keyName +
1868            TableMBean.E_COLOUR + TableMBean.E_BOLD +
1869            TableMBean.E_DATA;
1870                
1871            retString = retString+TableMBean.DATA+
1872            tableMBean.enableDisableCaching()+TableMBean.E_DATA;
1873        }
1874        
1875        retString = retString+TableMBean.E_TABLE;
1876        
1877        return retString;
1878    }
1879 
1880    private String JavaDoc enableCaching() {
1881        String JavaDoc retString = null;
1882        int length = tableMBeans.size();
1883        Enumeration JavaDoc objectNames = tableMBeans.keys();
1884        for (int i=0;i<length;i++){
1885            String JavaDoc keyName = (String JavaDoc) objectNames.nextElement();
1886            TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName);
1887            retString = tableMBean.enableCaching();
1888        }
1889        return retString;
1890    }
1891    
1892    private String JavaDoc disableCaching() {
1893        String JavaDoc retString = null;
1894        int length = tableMBeans.size();
1895        Enumeration JavaDoc objectNames = tableMBeans.keys();
1896        for (int i=0;i<length;i++){
1897            String JavaDoc keyName = (String JavaDoc) objectNames.nextElement();
1898            TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName);
1899            retString = tableMBean.disableCaching();
1900        }
1901        return retString;
1902    }
1903
1904    private String JavaDoc refreshCache() {
1905        String JavaDoc retString = null;
1906        int length = tableMBeans.size();
1907        Enumeration JavaDoc objectNames = tableMBeans.keys();
1908        for (int i=0;i<length;i++){
1909            String JavaDoc keyName = (String JavaDoc) objectNames.nextElement();
1910            TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName);
1911            retString = tableMBean.refreshCache();
1912        }
1913        return retString;
1914    }
1915    
1916    private String JavaDoc refreshStatistics() {
1917        String JavaDoc retString = null;
1918        int length = tableMBeans.size();
1919        Enumeration JavaDoc objectNames = tableMBeans.keys();
1920        for (int i=0;i<length;i++){
1921            String JavaDoc keyName = (String JavaDoc) objectNames.nextElement();
1922            TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName);
1923            retString = tableMBean.refreshStatistics();
1924        }
1925        return retString;
1926    }
1927  }
1928  
1929
1930  private void registerDatabaseMBean(String JavaDoc dbName){
1931      if (appName == null) {
1932      return;
1933    }
1934    
1935      try {
1936      server = findMBeanServer();
1937      if (server == null) {
1938        return;
1939      }
1940    }
1941    catch (Exception JavaDoc e) {
1942         logChannel.write(Logger.DEBUG, e.toString());
1943    }
1944
1945    try {
1946        String JavaDoc applicationName = appName;
1947
1948      ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=Database-"+dbName+",name=" + applicationName);
1949      
1950      if (!server.isRegistered(objectName)) {
1951        String JavaDoc [] includes = {"DatabaseManager_DB_"+dbName};
1952        
1953        String JavaDoc [] excludes;
1954        
1955        int length = tableMBeans.size();
1956        java.util.Vector JavaDoc temp = new java.util.Vector JavaDoc();
1957        Enumeration JavaDoc keys = tableMBeans.keys();
1958        for (int i=0;i<length;i++){
1959            String JavaDoc key = (String JavaDoc) keys.nextElement();
1960            if (key.startsWith(dbName)){
1961                temp.add(key);
1962            }
1963        }
1964        
1965        if (temp.isEmpty()){
1966            excludes = null;
1967        } else {
1968            excludes = new String JavaDoc [temp.size()];
1969            for (int i=0;i<temp.size();i++){
1970                excludes[i]="DatabaseManager_DB_"+(String JavaDoc)temp.elementAt(i);
1971            }
1972        }
1973        
1974        databaseMBean = new DatabaseMBean(dbName,this,objectName,"DatabaseManager_DB_"+dbName,includes,excludes);
1975        server.registerMBean(databaseMBean, objectName);
1976      }
1977      
1978    }
1979    catch (Exception JavaDoc e) {
1980       logChannel.write(Logger.DEBUG, e.toString());
1981      return;
1982    }
1983  }
1984
1985  private void unRegisterDatabaseMBean(String JavaDoc dbName){
1986    if (appName == null) {
1987      return;
1988    }
1989    
1990    try {
1991      server = findMBeanServer();
1992      if (server == null) {
1993        return;
1994      }
1995    }
1996    catch (Exception JavaDoc e) {
1997         logChannel.write(Logger.DEBUG, e.toString());
1998    }
1999
2000    try {
2001      String JavaDoc applicationName = appName;
2002
2003      ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=Database-"+dbName+",name=" + applicationName);
2004      
2005      if (server.isRegistered(objectName)) {
2006        server.unregisterMBean(objectName);
2007      }
2008      
2009    }
2010    catch (Exception JavaDoc e) {
2011       logChannel.write(Logger.DEBUG, e.toString());
2012      return;
2013    }
2014  }
2015  
2016  
2017  /**
2018   * Database MBean
2019   */

2020  private class DatabaseMBean extends EafConfigMBean{
2021    
2022    protected String JavaDoc dbName = null;
2023    
2024    public DatabaseMBean (Application application,
2025            ObjectName JavaDoc objectName, String JavaDoc prefix,
2026            String JavaDoc [] includes, String JavaDoc [] excludes){
2027        super(application,objectName,prefix,includes,excludes);
2028        buildDynamicMBeanInfo();
2029    }
2030    
2031    public DatabaseMBean (String JavaDoc dbName,
2032            Application application,
2033            ObjectName JavaDoc objectName, String JavaDoc prefix,
2034            String JavaDoc [] includes, String JavaDoc [] excludes){
2035        super(application,objectName,prefix,includes,excludes);
2036        this.dbName = dbName;
2037        buildDynamicMBeanInfo();
2038    }
2039    
2040    /**
2041     * Sets the value of the specified attribute of the Dynamic MBean.
2042     */

2043    public void setAttribute(Attribute JavaDoc attribute) throws
2044        AttributeNotFoundException JavaDoc,
2045        InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
2046      
2047        super.setAttribute(attribute);
2048        
2049        // restart without MBean UnRegistration
2050
shutdownWithoutMBeanUnRegistration();
2051        try {
2052            startup(config);
2053        }
2054        catch (Exception JavaDoc e) {
2055            logChannel.write(Logger.DEBUG, e.toString());
2056        }
2057    }
2058    
2059    /**
2060     * Allows an operation to be invoked on the Dynamic MBean.
2061     */

2062    public Object JavaDoc invoke(String JavaDoc operationName, Object JavaDoc params[],
2063                         String JavaDoc signature[]) throws MBeanException JavaDoc,
2064        ReflectionException JavaDoc {
2065      // Check operationName is not null to avoid NullPointerException later on
2066
if (operationName == null) {
2067        throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc(
2068            "Operation name cannot be null"),
2069            "Cannot invoke a null operation in " + dClassName);
2070      }
2071      // Check for a recognized operation name and call the corresponding operation
2072
if (operationName.equals("Toggle_EnableOrDisable_Cache")) {
2073        try {
2074            return enableDisableCaching();
2075        }catch (Exception JavaDoc e) {
2076            throw new MBeanException JavaDoc(e);
2077        }
2078      } else if (operationName.equals("Enable_Cache")) {
2079        try {
2080            return enableCaching();
2081        }catch (Exception JavaDoc e) {
2082            throw new MBeanException JavaDoc(e);
2083        }
2084      } else if (operationName.equals("Disable_Cache")) {
2085        try {
2086            return disableCaching();
2087        }catch (Exception JavaDoc e) {
2088            throw new MBeanException JavaDoc(e);
2089        }
2090      } else if (operationName.equals("Refresh_Cache")) {
2091        try {
2092            return refreshCache();
2093        }catch (Exception JavaDoc e) {
2094            throw new MBeanException JavaDoc(e);
2095        }
2096      } else if (operationName.equals("Refresh_Statistics")) {
2097        try {
2098            return refreshStatistics();
2099        }catch (Exception JavaDoc e) {
2100            throw new MBeanException JavaDoc(e);
2101        }
2102      } else if (operationName.equals("getDatabase")) {
2103        try {
2104            return databaseManager.findLogicalDatabase(dbName);
2105        }catch (Exception JavaDoc e) {
2106            throw new MBeanException JavaDoc(e);
2107        }
2108      } else{
2109        // basic set of operations
2110
return super.invoke(operationName, params, signature);
2111      }
2112    }
2113    
2114    /**
2115     * Method returns MBean's MBeanConstructorInfo Array
2116     * @return MBeanConstructorInfo[]
2117     */

2118    protected MBeanConstructorInfo JavaDoc[] getMBeanConstructorInfo () {
2119        MBeanParameterInfo JavaDoc[] dParameters = new MBeanParameterInfo JavaDoc[6];
2120        dParameters[0] = new MBeanParameterInfo JavaDoc("dbName","java.lang.String","Database Name");
2121        dParameters[1] = new MBeanParameterInfo JavaDoc("application","com.lutris.appserver.server.Application","Application Object");
2122        dParameters[2] = new MBeanParameterInfo JavaDoc("objectName","javax.management.ObjectName","MBean Name Object");
2123        dParameters[3] = new MBeanParameterInfo JavaDoc("prefix","java.lang.String","Configuration Parameter Prefix");
2124        dParameters[4] = new MBeanParameterInfo JavaDoc("includes","java.lang.reflect.Array","Array of internal parameter prefixes to include");
2125        dParameters[5] = new MBeanParameterInfo JavaDoc("excludes","java.lang.reflect.Array","Array of internal parameter prefixes to exclude");
2126        
2127        MBeanConstructorInfo JavaDoc[] dConstructors = new MBeanConstructorInfo JavaDoc[1];
2128        dConstructors[0] = new MBeanConstructorInfo JavaDoc("DatabaseMBean",
2129            "ConfigMBean Object Constructor",
2130            dParameters);
2131        
2132        return dConstructors;
2133    }
2134    
2135    /**
2136     * Method returns MBean's MBeanOperationInfo Array
2137     * @return MBeanOperationInfo[]
2138     */

2139    protected MBeanOperationInfo JavaDoc[] getMBeanOperationsInfo () {
2140        MBeanParameterInfo JavaDoc[] params = null;
2141        MBeanOperationInfo JavaDoc[] dOperations = new MBeanOperationInfo JavaDoc[11];
2142        dOperations[0] = new MBeanOperationInfo JavaDoc("reset",
2143            "reset(): reset attributes to their initial values",
2144            params, "void",
2145            MBeanOperationInfo.ACTION);
2146        dOperations[1] = new MBeanOperationInfo JavaDoc("saveAttributes",
2147            "saveAttributes(): save the attribute values into the configuration file",
2148            params, "void",
2149            MBeanOperationInfo.ACTION);
2150        dOperations[2] = new MBeanOperationInfo JavaDoc("getAppInfo",
2151            "getAppInfo(): get application information",
2152            params, "String",
2153            MBeanOperationInfo.ACTION);
2154        
2155        params = new MBeanParameterInfo JavaDoc[2];
2156        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
2157                "use UNDERLINE (_) as attribute group separator.");
2158        params[1] = new MBeanParameterInfo JavaDoc("attValue","java.lang.String","Attribute value!");
2159        
2160        dOperations[3] = new MBeanOperationInfo JavaDoc("addAttribute",
2161              "addAttribute(String key, String value): add new application parameter",
2162              params, "void",
2163              MBeanOperationInfo.ACTION);
2164        
2165        params = new MBeanParameterInfo JavaDoc[1];
2166        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
2167                "use UNDERLINE (_) as attribute group separator.");
2168        
2169        dOperations[4] = new MBeanOperationInfo JavaDoc("removeAttribute",
2170              "removeAttribute(String key): remove application parameter",
2171              params, "void",
2172              MBeanOperationInfo.ACTION);
2173        
2174        params = null;
2175        
2176        dOperations[5] = new MBeanOperationInfo JavaDoc("getDatabase",
2177                "getDatabase(): Gets actual Database object.",
2178                params, "com.lutris.appserver.server.sql.LogicalDatabase",
2179                MBeanOperationInfo.ACTION);
2180        
2181        dOperations[6] = new MBeanOperationInfo JavaDoc("Refresh_Cache",
2182                "refreshCache(): Refresh Database Cache.",
2183                params, "java.lang.String",
2184                MBeanOperationInfo.ACTION);
2185        
2186        dOperations[7] = new MBeanOperationInfo JavaDoc("Refresh_Statistics",
2187                "refreshStatistics(): Refresh Database Statistics.",
2188                params, "java.lang.String",
2189                MBeanOperationInfo.ACTION);
2190        
2191        dOperations[8] = new MBeanOperationInfo JavaDoc("Enable_Cache",
2192                "enableCaching(): Enables Database Cache Status.",
2193                params, "java.lang.String",
2194                MBeanOperationInfo.ACTION);
2195        
2196        dOperations[9] = new MBeanOperationInfo JavaDoc("Disable_Cache",
2197                "disableCaching(): Disables Database Cache Status.",
2198                params, "java.lang.String",
2199                MBeanOperationInfo.ACTION);
2200        
2201        dOperations[10] = new MBeanOperationInfo JavaDoc("Toggle_EnableOrDisable_Cache",
2202                "enableDisableCaching(): Toggles Database Cache Status.",
2203                params, "java.lang.String",
2204                MBeanOperationInfo.ACTION);
2205        
2206        return dOperations;
2207    }
2208    
2209    
2210    private String JavaDoc enableDisableCaching() {
2211        String JavaDoc retString = TableMBean.TABLE +
2212        TableMBean.CAPTION + TableMBean.BOLD +
2213        TableMBean.COLOUR + TableMBean.BLUE +
2214        "Database " + dbName + TableMBean.E_COLOUR +
2215        TableMBean.E_BOLD + TableMBean.E_CAPTION;
2216        
2217        int length = tableMBeans.size();
2218        Enumeration JavaDoc objectNames = tableMBeans.keys();
2219        for (int i=0;i<length;i++){
2220            String JavaDoc keyName = (String JavaDoc) objectNames.nextElement();
2221            if (keyName.startsWith(dbName+DOT)) {
2222                retString = retString+TableMBean.ROW;
2223                TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName);
2224                retString = retString+TableMBean.DATA+
2225                TableMBean.BOLD + TableMBean.COLOUR +
2226                TableMBean.BLUE + tableMBean.tableName +
2227                TableMBean.E_COLOUR + TableMBean.E_BOLD +
2228                TableMBean.E_DATA;
2229                
2230                retString = retString+TableMBean.DATA+
2231                tableMBean.enableDisableCaching()+TableMBean.E_DATA;
2232            }
2233        }
2234        
2235        retString = retString+TableMBean.E_TABLE;
2236        
2237        return retString;
2238    }
2239 
2240    private String JavaDoc enableCaching() {
2241        String JavaDoc retString = null;
2242        int length = tableMBeans.size();
2243        Enumeration JavaDoc objectNames = tableMBeans.keys();
2244        for (int i=0;i<length;i++){
2245            String JavaDoc keyName = (String JavaDoc) objectNames.nextElement();
2246            if (keyName.startsWith(dbName+DOT)) {
2247                TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName);
2248            retString = tableMBean.enableCaching();
2249            }
2250        }
2251        return retString;
2252    }
2253    
2254    private String JavaDoc disableCaching() {
2255        String JavaDoc retString = null;
2256        int length = tableMBeans.size();
2257        Enumeration JavaDoc objectNames = tableMBeans.keys();
2258        for (int i=0;i<length;i++){
2259            String JavaDoc keyName = (String JavaDoc) objectNames.nextElement();
2260            if (keyName.startsWith(dbName+DOT)) {
2261                TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName);
2262                retString = tableMBean.disableCaching();
2263            }
2264        }
2265        return retString;
2266    }
2267
2268    private String JavaDoc refreshCache() {
2269        String JavaDoc retString = null;
2270        int length = tableMBeans.size();
2271        Enumeration JavaDoc objectNames = tableMBeans.keys();
2272        for (int i=0;i<length;i++){
2273            String JavaDoc keyName = (String JavaDoc) objectNames.nextElement();
2274            if (keyName.startsWith(dbName+DOT)) {
2275                TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName);
2276                retString = tableMBean.refreshCache();
2277            }
2278        }
2279        return retString;
2280    }
2281    
2282    private String JavaDoc refreshStatistics() {
2283        String JavaDoc retString = null;
2284        int length = tableMBeans.size();
2285        Enumeration JavaDoc objectNames = tableMBeans.keys();
2286        for (int i=0;i<length;i++){
2287            String JavaDoc keyName = (String JavaDoc) objectNames.nextElement();
2288            if (keyName.startsWith(dbName+DOT)) {
2289                TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName);
2290                retString = tableMBean.refreshStatistics();
2291            }
2292        }
2293        return retString;
2294    }
2295
2296  }
2297  
2298  
2299  
2300  protected Hashtable JavaDoc tableMBeans = new Hashtable JavaDoc();
2301  
2302  private void registerTableMBeans() {
2303        List JavaDoc listDOClasses = Utils.getCachedDOClassesForApplication(config,
2304        this.getClass().getClassLoader());
2305        ListIterator JavaDoc li = listDOClasses.listIterator();
2306        //tableMBeans = new Hashtable();
2307
try {
2308            while (li.hasNext()) {
2309                DOTable tableDBClassName = (DOTable) li.next();
2310                registerTableMBean(tableDBClassName);
2311            
2312            }
2313        } catch (Exception JavaDoc e) {
2314            logChannel.write(Logger.DEBUG, e.toString());
2315        }
2316    }
2317
2318  private void registerTableMBean(DOTable tableDBClassName){
2319    if (appName == null) {
2320      return;
2321    }
2322    
2323    try {
2324      server = findMBeanServer();
2325      if (server == null) {
2326        return;
2327      }
2328    }
2329    catch (Exception JavaDoc e) {
2330         logChannel.write(Logger.DEBUG, e.toString());
2331    }
2332
2333    try {
2334      String JavaDoc applicationName = appName;
2335        
2336      String JavaDoc dbName = tableDBClassName.getDBName();
2337      
2338      String JavaDoc tableName = tableDBClassName.getTableName();
2339
2340      ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=Database.Table-"+dbName+"."+tableName+",name=" + applicationName);
2341      
2342      if (!server.isRegistered(objectName)) {
2343        tableMBean = new TableMBean(tableDBClassName,this,objectName);
2344        tableMBeans.put(dbName+"_"+tableName,tableMBean);
2345        server.registerMBean(tableMBean, objectName);
2346      }
2347      
2348    }
2349    catch (Exception JavaDoc e) {
2350       logChannel.write(Logger.DEBUG, e.toString());
2351      return;
2352    }
2353  }
2354
2355  private void unRegisterTableMBeans(){
2356    if (appName == null) {
2357        return;
2358    }
2359      
2360    try {
2361        server = findMBeanServer();
2362        if (server == null) {
2363          return;
2364        }
2365    } catch (Exception JavaDoc e) {
2366           logChannel.write(Logger.DEBUG, e.toString());
2367    }
2368      
2369    try {
2370      String JavaDoc applicationName = appName;
2371      int length = tableMBeans.size();
2372      Enumeration JavaDoc objectNames = tableMBeans.keys();
2373      for (int i=0;i<length;i++){
2374        String JavaDoc keyName = (String JavaDoc) objectNames.nextElement();
2375        TableMBean tableMBean = (TableMBean)tableMBeans.get(keyName);
2376        ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=Database.Table-"+tableMBean.getDbName()+"."+tableMBean.getTableName()+",name=" + applicationName);
2377          
2378        if (server.isRegistered(objectName)) {
2379            server.unregisterMBean(objectName);
2380        }
2381      }
2382      tableMBeans.clear();
2383    }
2384    catch (Exception JavaDoc e) {
2385       logChannel.write(Logger.DEBUG, e.toString());
2386      return;
2387    }
2388  }
2389  
2390  private static class TableMBConst {
2391    static Class JavaDoc cacheConstantClass;
2392    static int DATA_CACHE;
2393    static int SIMPLE_QUERY_CACHE;
2394    static int COMPLEX_QUERY_CACHE;
2395    static int QUERY_CACHING;
2396    
2397    static Class JavaDoc[] NOCLASS_ARR = {};
2398    
2399    static final String JavaDoc[] CACHE_STAT_TYPE = {
2400            "Data_Struct_", "Simple_Query_", "Complex_Query_"};
2401    
2402    static final String JavaDoc cacheParameters[] = {
2403            "reserveFactor","CachePercentage",
2404            "initialCondition", "maxCacheSize",
2405            "maxSimpleCacheSize", "maxComplexCacheSize",
2406            "InitialDSCacheSize", "InitialCacheFetchSize"
2407    };
2408    static String JavaDoc cacheDefaults[] = {
2409            "0", "-1.0", "*", "0", "0", "0", "-1", "0"
2410    };
2411    
2412    static{
2413        try {
2414            cacheConstantClass = Class.forName(
2415                "org.enhydra.dods.cache.CacheConstants");
2416            DATA_CACHE = (cacheConstantClass.getField(
2417                "DATA_CACHE")).getInt(null);
2418            SIMPLE_QUERY_CACHE = (cacheConstantClass.getField(
2419                "SIMPLE_QUERY_CACHE")).getInt(null);
2420            COMPLEX_QUERY_CACHE = (cacheConstantClass.getField(
2421                "COMPLEX_QUERY_CACHE")).getInt(null);
2422            QUERY_CACHING = (cacheConstantClass.getField(
2423                "QUERY_CACHING")).getInt(null);
2424        } catch (Exception JavaDoc e) {
2425            e.printStackTrace();
2426        }
2427    }
2428  }
2429  
2430  /**
2431   * Table MBean
2432   */

2433  private class TableMBean extends EafConfigMBean{
2434    
2435    protected DOTable doTable = null;
2436    protected String JavaDoc tableName = null;
2437    protected String JavaDoc dbName = null;
2438    protected Class JavaDoc tableClass = null;
2439    protected Object JavaDoc cfgAdmin = null;
2440    protected int levelOfCaching;
2441      
2442    static final String JavaDoc CLASS_DODS = "org.enhydra.dods.DODS";
2443    static final String JavaDoc REGISTER = "register";
2444    static final String JavaDoc CLASS_DBMANAGER =
2445        "com.lutris.appserver.server.sql.DatabaseManager";
2446    static final String JavaDoc GET_CONFIGURATION_ADMINISTRATION =
2447        "getConfigurationAdministration";
2448    static final String JavaDoc READ_CACHE_CONFIGURATION =
2449        "readCacheConfiguration";
2450    static final String JavaDoc CLASS_CONFIGURATION_ADMINISTRATION =
2451        "org.enhydra.dods.cache.ConfigurationAdministration";
2452    
2453    static final String JavaDoc CLASS_STATISTICS =
2454        "org.enhydra.dods.statistics.Statistics";
2455    static final String JavaDoc CLASS_CACHE_STATISTICS =
2456        "org.enhydra.dods.statistics.CacheStatistics";
2457    static final String JavaDoc GET_STATISTICS_TYPE = "getStatisticsType";
2458    
2459    static final String JavaDoc CACHE_DOT = "cache_";
2460    static final String JavaDoc PRC = " %";
2461    static final String JavaDoc CLEAR = "clear";
2462    
2463    static final String JavaDoc GET_LEVEL_OF_CACHING = "getLevelOfCaching";
2464    static final String JavaDoc IS_DISABLED = "isDisabled";
2465    static final String JavaDoc GET_TYPE = "getCacheType";
2466    
2467    static final String JavaDoc GET_RESERVE_FACTOR = "getReserveFactor";
2468    static final String JavaDoc GET_CACHE_PERCENTAGE = "getCachePercentage";
2469    static final String JavaDoc SET_CACHE_PERCENTAGE = "setCachePercentage";
2470    static final String JavaDoc GET_INITIAL_FETCH_SIZE = "getInitialCacheFetchSize";
2471    static final String JavaDoc SET_INITIAL_FETCH_SIZE = "setInitialCacheFetchSize";
2472    static final String JavaDoc GET_INITIAL_DS_SIZE = "getInitialDSCacheSize";
2473    static final String JavaDoc SET_INITIAL_DS_SIZE = "setInitialDSCacheSize";
2474    static final String JavaDoc GET_INITIAL_QUERY_CACHE = "getInitialQueryCache";
2475    static final String JavaDoc GET_CACHE_ADMINISTRATION = "getCacheAdministration";
2476    static final String JavaDoc SET_RESERVE_FACTOR = "setReserveFactor";
2477    static final String JavaDoc SET_INITIAL_QUERY_CACHE = "setInitialQueryCache";
2478    static final String JavaDoc GET_MAX_CACHE_SIZE = "getMaxCacheSize";
2479    static final String JavaDoc CLASS_CACHE_ADMINISTRATION =
2480        "org.enhydra.dods.cache.CacheAdministration";
2481    static final String JavaDoc CLASS_UPDATE_CONFIGURATION_ADMINISTRATION =
2482        "org.enhydra.dods.cache.UpdateConfigurationAdministration";
2483    static final String JavaDoc SET_MAX_CACHE_SIZE = "setMaxCacheSize";
2484    
2485    
2486    static final String JavaDoc EMPTY = "";
2487    static final String JavaDoc TABLE = "<TABLE border=3>";
2488    static final String JavaDoc E_TABLE = "</TABLE>";
2489    static final String JavaDoc COLOUR = "<SPAN STYLE='color:";
2490    static final String JavaDoc E_COLOUR = "</SPAN>";
2491    static final String JavaDoc BLUE = "blue'>";
2492    static final String JavaDoc RED = "red'>";
2493    static final String JavaDoc GREEN = "green'>";
2494    static final String JavaDoc BOLD = "<B>";
2495    static final String JavaDoc E_BOLD = "</B>";
2496    static final String JavaDoc CAPTION = "<CAPTION>";
2497    static final String JavaDoc E_CAPTION = "</CAPTION>";
2498    static final String JavaDoc ROW = "<TR>";
2499    static final String JavaDoc E_ROW = "</TR>";
2500    static final String JavaDoc DATA = "<TD>";
2501    static final String JavaDoc E_DATA = "</TD>";
2502    
2503    static final String JavaDoc CACHE_NOT_ACTIVE = "Cache is not configured";
2504    static final String JavaDoc CACHE_STAT_FOR = "Cache Statistics for ";
2505    
2506    static final String JavaDoc CACHE_ACCESS_NUM = "CacheAccessNum";
2507    static final String JavaDoc CACHE_HITS_NUM = "CacheHitsNum";
2508    static final String JavaDoc USED_PERCENTS = "UsedPercents";
2509    static final String JavaDoc CACHE_HITS_PERCENTS = "CacheHitsPercents";
2510    
2511    static final String JavaDoc ENABLE = "enableCaching";
2512    static final String JavaDoc ENABLED = "Caching has been enabled";
2513    static final String JavaDoc DISABLE = "disableCaching";
2514    static final String JavaDoc DISABLED = "Caching has been disabled";
2515    
2516    static final String JavaDoc REFRESH = "refreshCache";
2517    static final String JavaDoc REFRESHED = "Caching has been refreshed";
2518    static final String JavaDoc STATISTICREFRESH = "refreshStatistics";
2519    static final String JavaDoc STATISTICREFRESHED = "Statistics have been refreshed";
2520    
2521    static final String JavaDoc GET_CACHE_STATISTICS = "getCacheStatistics";
2522    static final String JavaDoc CLEAR_STATISTICS = "clearStatistics";
2523    static final String JavaDoc GET_CACHE_ACCESS_NUM = "getCacheAccessNum";
2524    static final String JavaDoc GET_CACHE_HITS_NUM = "getCacheHitsNum";
2525    static final String JavaDoc GET_USED_PERCENTS = "getUsedPercents";
2526    static final String JavaDoc GET_CACHE_HITS_PERCENTS = "getCacheHitsPercents";
2527    
2528    static final String JavaDoc TABLE_STAT_FOR = "Table Statistics for ";
2529    
2530    static final String JavaDoc STATISTCS_TYPE = "StatisticsType";
2531    static final String JavaDoc INSERT_NUM = "InsertNum";
2532    static final String JavaDoc UPDATE_NUM = "UpdateNum";
2533    static final String JavaDoc DELETE_NUM = "DeleteNum";
2534    static final String JavaDoc DML_NUM = "DMLNum";
2535    static final String JavaDoc LAZY_LOADING_NUM = "LazyLoadingNum";
2536    static final String JavaDoc START_TIME = "StartTime";
2537    static final String JavaDoc STOP_TIME = "StopTime";
2538    static final String JavaDoc QUERY_NUM = "QueryNum";
2539    static final String JavaDoc QUERY_BY_OID_NUM = "QueryByOIdNum";
2540    static final String JavaDoc QUERY_AVERAGE_TIME = "QueryAverageTime";
2541    static final String JavaDoc QUERY_BY_OID_AVERAGE_TIME = "QueryByOIdAverageTime";
2542    
2543    static final String JavaDoc GET_INSERT_NUM = "getInsertNum";
2544    static final String JavaDoc GET_UPDATE_NUM = "getUpdateNum";
2545    static final String JavaDoc GET_DELETE_NUM = "getDeleteNum";
2546    static final String JavaDoc GET_DML_NUM = "getDMLNum";
2547    static final String JavaDoc GET_LAZY_LOADING_NUM = "getLazyLoadingNum";
2548    static final String JavaDoc GET_START_TIME = "getStartTime";
2549    static final String JavaDoc GET_STOP_TIME = "getStopTime";
2550    static final String JavaDoc GET_QUERY_NUM = "getQueryNum";
2551    static final String JavaDoc GET_QUERY_BY_OID_NUM = "getQueryByOIdNum";
2552    static final String JavaDoc GET_QUERY_AVERAGE_TIME = "getQueryAverageTime";
2553    static final String JavaDoc GET_QUERY_BY_OID_AVERAGETIME =
2554        "getQueryByOIdAverageTime";
2555    
2556    static final String JavaDoc GET_DODS_CACHE_TABLE_NAME = "getCacheDodsTableName";
2557    
2558    public TableMBean (Application application,
2559            ObjectName JavaDoc objectName, String JavaDoc prefix,
2560            String JavaDoc [] includes, String JavaDoc [] excludes){
2561        super(application,objectName,prefix,includes,excludes);
2562        buildDynamicMBeanInfo();
2563    }
2564    
2565    public TableMBean (DOTable tableDBClassName, Application application,
2566            ObjectName JavaDoc objectName){
2567        
2568        try {
2569            Method JavaDoc mth;
2570            mth = Class.forName(CLASS_DODS).getMethod(REGISTER,
2571                new Class JavaDoc[] {Class.forName(CLASS_DBMANAGER)});
2572            mth.invoke(null, new Object JavaDoc[] { (Object JavaDoc) databaseManager});
2573            
2574            doTable = tableDBClassName;
2575            tableName = doTable.getTableName();
2576            dbName = doTable.getDBName();
2577            tableClass = doTable.getCls();
2578            
2579            mth = tableClass.getMethod(GET_DODS_CACHE_TABLE_NAME,
2580                    new Class JavaDoc[] {});
2581            tableName = (mth.invoke(null, new Object JavaDoc[] {})).toString();
2582            
2583            mth = tableClass.getMethod(GET_CONFIGURATION_ADMINISTRATION,
2584                    new Class JavaDoc[] {});
2585            cfgAdmin = mth.invoke(null, new Object JavaDoc[] {});
2586        
2587        } catch (Exception JavaDoc e) {
2588          e.printStackTrace();
2589        }
2590        
2591        String JavaDoc [] includes = {"DatabaseManager_DB_"+dbName+"_"+tableName};
2592        String JavaDoc [] excludes = null;
2593        
2594        String JavaDoc prefix = "DatabaseManager_DB_"+dbName+"_"+tableName;
2595        
2596        super.init(application,objectName,prefix,includes,excludes);
2597        
2598        levelOfCaching = getLevelOfCaching();
2599        // initialization of obligate caching parameters
2600
hashAttrib.put(CACHE_DOT+"cachingStatus",getCachingStatus());
2601        hashAttrib.put(CACHE_DOT+"cachingType",getCacheType());
2602        hashAttrib.put(CACHE_DOT+"levelOfCaching",new Integer JavaDoc(levelOfCaching));
2603        
2604        if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[0])){
2605            hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[0],getReserveFactor());
2606            initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[0],getReserveFactor());
2607        }
2608        if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[1])){
2609            hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[1],getCachePercentage());
2610            initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[1],getCachePercentage());
2611        }
2612        if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[2])){
2613            hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[2],getInitialCondition());
2614            initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[2],getInitialCondition());
2615        }
2616        if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[3])){
2617            hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[3],getMaxCacheSize());
2618            initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[3],getMaxCacheSize());
2619        }
2620        if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[4])){
2621            hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[4],getMaxSimpleCacheSize());
2622            initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[4],getMaxSimpleCacheSize());
2623        }
2624        if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[5])){
2625            hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[5],getMaxComplexCacheSize());
2626            initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[5],getMaxComplexCacheSize());
2627        }
2628        if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[6])){
2629            hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[6],getInitialDSCacheSize());
2630            initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[6],getInitialDSCacheSize());
2631        }
2632        if (!hashAttrib.containsKey(CACHE_DOT+TableMBConst.cacheParameters[7])){
2633            hashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[7],getInitialCacheFetchSize());
2634            initHashAttrib.put(CACHE_DOT+TableMBConst.cacheParameters[7],getInitialCacheFetchSize());
2635        }
2636        
2637        buildDynamicMBeanInfo();
2638    }
2639    
2640    /**
2641     * Allows the value of the specified attribute of the Dynamic MBean to be obtained.
2642     */

2643    public Object JavaDoc getAttribute(String JavaDoc attribute_name) throws
2644        AttributeNotFoundException JavaDoc,
2645        MBeanException JavaDoc, ReflectionException JavaDoc {
2646      // Check attribute_name is not null to avoid NullPointerException later on
2647
if (attribute_name == null) {
2648        throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc(
2649            "Attribute name cannot be null"),
2650            "Cannot invoke a getter of " + dClassName +
2651            " with null attribute name");
2652      }
2653      
2654      if ((CACHE_DOT+"levelOfCaching").equals(attribute_name)){
2655            try{
2656                hashAttrib.put(attribute_name,new Integer JavaDoc(getLevelOfCaching()).toString());
2657            }catch (Exception JavaDoc e) {
2658                throw new MBeanException JavaDoc(e);
2659            }
2660      } else if ((CACHE_DOT+"cachingType").equals(attribute_name)){
2661            try{
2662                hashAttrib.put(attribute_name,getCacheType());
2663            }catch (Exception JavaDoc e) {
2664                throw new MBeanException JavaDoc(e);
2665            }
2666      } else if ((CACHE_DOT+"cachingStatus").equals(attribute_name)){
2667            try{
2668                hashAttrib.put(attribute_name,getCachingStatus());
2669            }catch (Exception JavaDoc e) {
2670                throw new MBeanException JavaDoc(e);
2671            }
2672      } else if ((CACHE_DOT+TableMBConst.cacheParameters[0]).equals(attribute_name)){
2673        try{
2674            hashAttrib.put(attribute_name,getReserveFactor());
2675        }catch (Exception JavaDoc e) {
2676            throw new MBeanException JavaDoc(e);
2677        }
2678      } else if ((CACHE_DOT+TableMBConst.cacheParameters[1]).equals(attribute_name)){
2679        try{
2680            hashAttrib.put(attribute_name,getCachePercentage());
2681        }catch (Exception JavaDoc e) {
2682            throw new MBeanException JavaDoc(e);
2683        }
2684      } else if ((CACHE_DOT+TableMBConst.cacheParameters[2]).equals(attribute_name)){
2685        try{
2686            hashAttrib.put(attribute_name,getInitialCondition());
2687        }catch (Exception JavaDoc e) {
2688            throw new MBeanException JavaDoc(e);
2689        }
2690      } else if ((CACHE_DOT+TableMBConst.cacheParameters[3]).equals(attribute_name)){
2691        try{
2692            hashAttrib.put(attribute_name,getMaxCacheSize());
2693        }catch (Exception JavaDoc e) {
2694            throw new MBeanException JavaDoc(e);
2695        }
2696      } else if ((CACHE_DOT+TableMBConst.cacheParameters[4]).equals(attribute_name)){
2697        try{
2698            hashAttrib.put(attribute_name,getMaxSimpleCacheSize());
2699        }catch (Exception JavaDoc e) {
2700            throw new MBeanException JavaDoc(e);
2701        }
2702      } else if ((CACHE_DOT+TableMBConst.cacheParameters[5]).equals(attribute_name)){
2703        try{
2704            hashAttrib.put(attribute_name,getMaxComplexCacheSize());
2705        }catch (Exception JavaDoc e) {
2706            throw new MBeanException JavaDoc(e);
2707        }
2708      } else if ((CACHE_DOT+TableMBConst.cacheParameters[6]).equals(attribute_name)){
2709        try{
2710            hashAttrib.put(attribute_name,getInitialDSCacheSize());
2711        }catch (Exception JavaDoc e) {
2712            throw new MBeanException JavaDoc(e);
2713        }
2714      } else if ((CACHE_DOT+TableMBConst.cacheParameters[7]).equals(attribute_name)){
2715        try{
2716            hashAttrib.put(attribute_name,getInitialCacheFetchSize());
2717        }catch (Exception JavaDoc e) {
2718            throw new MBeanException JavaDoc(e);
2719        }
2720      }
2721      
2722      // Check for a recognized attribute_name and call the corresponding getter
2723
try {
2724        return hashAttrib.get(attribute_name);
2725      }
2726      catch (Exception JavaDoc e) {
2727        // If attribute_name has not been recognized throw an AttributeNotFoundException
2728
throw (new AttributeNotFoundException JavaDoc("Cannot find " +
2729                attribute_name + " attribute in " + dClassName));
2730      }
2731    }
2732    
2733    /**
2734     * Sets the value of the specified attribute of the Dynamic MBean.
2735     */

2736    public void setAttribute(Attribute JavaDoc attribute) throws
2737        AttributeNotFoundException JavaDoc,
2738        InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
2739      
2740      // Check attribute is not null to avoid NullPointerException later on
2741
if (attribute == null) {
2742        throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc(
2743            "Attribute cannot be null"),
2744            "Cannot invoke a setter of " + dClassName +
2745            " with null attribute");
2746      }
2747      
2748      String JavaDoc name = attribute.getName();
2749      String JavaDoc value = (String JavaDoc) attribute.getValue();
2750      
2751      boolean cacheAttribute = false;
2752      
2753      if ((CACHE_DOT+TableMBConst.cacheParameters[0]).equals(name)){
2754        try{
2755            setReserveFactor(value);
2756            cacheAttribute = true;
2757        }catch (Exception JavaDoc e) {
2758            throw new MBeanException JavaDoc(e);
2759        }
2760      } else if ((CACHE_DOT+TableMBConst.cacheParameters[1]).equals(name)){
2761        try{
2762            setCachePercentage(value);
2763            cacheAttribute = true;
2764        }catch (Exception JavaDoc e) {
2765            throw new MBeanException JavaDoc(e);
2766        }
2767      } else if ((CACHE_DOT+TableMBConst.cacheParameters[2]).equals(name)){
2768        try{
2769            setInitialCondition(value);
2770            cacheAttribute = true;
2771        }catch (Exception JavaDoc e) {
2772            throw new MBeanException JavaDoc(e);
2773        }
2774      } else if ((CACHE_DOT+TableMBConst.cacheParameters[3]).equals(name)){
2775        try{
2776            setMaxCacheSize(value);
2777            cacheAttribute = true;
2778        }catch (Exception JavaDoc e) {
2779            throw new MBeanException JavaDoc(e);
2780        }
2781      } else if ((CACHE_DOT+TableMBConst.cacheParameters[4]).equals(name)){
2782        try{
2783            setMaxSimpleCacheSize(value);
2784            cacheAttribute = true;
2785        }catch (Exception JavaDoc e) {
2786            throw new MBeanException JavaDoc(e);
2787        }
2788      } else if ((CACHE_DOT+TableMBConst.cacheParameters[5]).equals(name)){
2789        try{
2790            setMaxComplexCacheSize(value);
2791            cacheAttribute = true;
2792        }catch (Exception JavaDoc e) {
2793            throw new MBeanException JavaDoc(e);
2794        }
2795      } else if ((CACHE_DOT+TableMBConst.cacheParameters[6]).equals(name)){
2796        try{
2797            setInitialDSCacheSize(value);
2798            cacheAttribute = true;
2799        }catch (Exception JavaDoc e) {
2800            throw new MBeanException JavaDoc(e);
2801        }
2802      } else if ((CACHE_DOT+TableMBConst.cacheParameters[7]).equals(name)){
2803        try{
2804            setInitialCacheFetchSize(value);
2805            cacheAttribute = true;
2806        }catch (Exception JavaDoc e) {
2807            throw new MBeanException JavaDoc(e);
2808        }
2809      }
2810      
2811      // set parameter hashAttrib and config value
2812
super.setAttribute(attribute);
2813      
2814      if (!cacheAttribute){
2815        //restart without MBean UnRegistration
2816
shutdownWithoutMBeanUnRegistration();
2817        try {
2818            startup(config);
2819        }
2820        catch (Exception JavaDoc e) {
2821            logChannel.write(Logger.DEBUG, e.toString());
2822        }
2823      }
2824    }
2825    
2826    /**
2827     * -----------------------------------------------------
2828     * ADDITIONALL PROTECTED METHODS
2829     * -----------------------------------------------------
2830     */

2831    
2832    /**
2833     * Method returns MBean's MBeanConstructorInfo Array
2834     * @return MBeanConstructorInfo[]
2835     */

2836    protected MBeanConstructorInfo JavaDoc[] getMBeanConstructorInfo () {
2837        MBeanParameterInfo JavaDoc[] dParameters = new MBeanParameterInfo JavaDoc[3];
2838        dParameters[0] = new MBeanParameterInfo JavaDoc("doTable","org.enhydra.util.DOTable","DOTable Object");
2839        dParameters[1] = new MBeanParameterInfo JavaDoc("application","com.lutris.appserver.server.Application","Application Object");
2840        dParameters[2] = new MBeanParameterInfo JavaDoc("objectName","javax.management.ObjectName","MBean Name Object");
2841        
2842        MBeanConstructorInfo JavaDoc[] dConstructors = new MBeanConstructorInfo JavaDoc[1];
2843        dConstructors[0] = new MBeanConstructorInfo JavaDoc("TableMBean",
2844            "ConfigMBean Object Constructor",
2845            dParameters);
2846        
2847        return dConstructors;
2848    }
2849
2850    
2851    /**
2852     * Method returns MBean's MBeanAttributeInfo Array
2853     * @return MBeanAttributeInfo[]
2854     */

2855    protected MBeanAttributeInfo JavaDoc[] getMBeanAttributesInfo () {
2856        int length = hashAttrib.size();
2857        MBeanAttributeInfo JavaDoc[] dAttributes = new MBeanAttributeInfo JavaDoc[length];
2858        Enumeration JavaDoc keys = hashAttrib.keys();
2859        for (int i = 0; i < length; i++) {
2860          String JavaDoc attName = (String JavaDoc) keys.nextElement();
2861          String JavaDoc attDesc = new String JavaDoc(attName + " configuration parameter!");
2862          
2863          if ((CACHE_DOT+"cachingStatus").equals(attName)||(CACHE_DOT+"cachingType").equals(attName)
2864                ||(CACHE_DOT+"levelOfCaching").equals(attName)){
2865            dAttributes[i] = new MBeanAttributeInfo JavaDoc(attName, "java.lang.String",
2866                    attDesc, true, false, false);
2867          }else {
2868            dAttributes[i] = new MBeanAttributeInfo JavaDoc(attName, "java.lang.String",
2869                    attDesc, true, true, false);
2870          }
2871        }
2872        return dAttributes;
2873    }
2874    
2875    
2876    /**
2877     * Allows an operation to be invoked on the Dynamic MBean.
2878     */

2879    public Object JavaDoc invoke(String JavaDoc operationName, Object JavaDoc params[],
2880                         String JavaDoc signature[]) throws MBeanException JavaDoc,
2881        ReflectionException JavaDoc {
2882      // Check operationName is not null to avoid NullPointerException later on
2883
if (operationName == null) {
2884        throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc(
2885            "Operation name cannot be null"),
2886            "Cannot invoke a null operation in " + dClassName);
2887      }
2888      // Check for a recognized operation name and call the corresponding operation
2889
if (operationName.equals("Toggle_EnableOrDisable_Cache")) {
2890        try {
2891            return enableDisableCaching();
2892        }catch (Exception JavaDoc e) {
2893            throw new MBeanException JavaDoc(e);
2894        }
2895      } else if (operationName.equals("Get_Table_Data_Struct_Statistics")) {
2896        try {
2897            return getDoCacheStatistics(0);
2898        }catch (Exception JavaDoc e) {
2899            throw new MBeanException JavaDoc(e);
2900        }
2901      } else if (operationName.equals("Get_Table_Simple_Query_Statistics")) {
2902        try {
2903            return getDoCacheStatistics(1);
2904        }catch (Exception JavaDoc e) {
2905            throw new MBeanException JavaDoc(e);
2906        }
2907      } else if (operationName.equals("Get_Table_Complex_Query_Statistics")) {
2908        try {
2909            return getDoCacheStatistics(2);
2910        }catch (Exception JavaDoc e) {
2911            throw new MBeanException JavaDoc(e);
2912        }
2913      } else if (operationName.equals("Get_Table_Statistics")) {
2914        try {
2915            return getAllDoCacheStatistics();
2916        }catch (Exception JavaDoc e) {
2917            throw new MBeanException JavaDoc(e);
2918        }
2919      } else if (operationName.equals("Clear_Table_Data_Struct_Statistics")) {
2920        try {
2921            clearDoCacheStatistics(0);
2922            return null;
2923        }catch (Exception JavaDoc e) {
2924            throw new MBeanException JavaDoc(e);
2925        }
2926      } else if (operationName.equals("Clear_Table_Simple_Query_Statistics")) {
2927        try {
2928            clearDoCacheStatistics(1);
2929            return null;
2930        }catch (Exception JavaDoc e) {
2931            throw new MBeanException JavaDoc(e);
2932        }
2933      } else if (operationName.equals("Clear_Table_Complex_Query_Statistics")) {
2934        try {
2935            clearDoCacheStatistics(2);
2936            return null;
2937        }catch (Exception JavaDoc e) {
2938            throw new MBeanException JavaDoc(e);
2939        }
2940      } else if (operationName.equals("Clear_Table_Statistics")) {
2941        try {
2942            clearAllDoStatistics();
2943            return null;
2944        }catch (Exception JavaDoc e) {
2945            throw new MBeanException JavaDoc(e);
2946        }
2947      } else if (operationName.equals("Enable_Cache")) {
2948        try {
2949            return enableCaching();
2950        }catch (Exception JavaDoc e) {
2951            throw new MBeanException JavaDoc(e);
2952        }
2953      } else if (operationName.equals("Disable_Cache")) {
2954        try {
2955            return disableCaching();
2956        }catch (Exception JavaDoc e) {
2957            throw new MBeanException JavaDoc(e);
2958        }
2959      } else if (operationName.equals("Refresh_Cache")) {
2960        try {
2961            return refreshCache();
2962        }catch (Exception JavaDoc e) {
2963            throw new MBeanException JavaDoc(e);
2964        }
2965      } else if (operationName.equals("Refresh_Statistics")) {
2966        try {
2967            return refreshStatistics();
2968        }catch (Exception JavaDoc e) {
2969            throw new MBeanException JavaDoc(e);
2970        }
2971      } else{
2972        // basic set of operations
2973
return super.invoke(operationName, params, signature);
2974      }
2975    }
2976    
2977    /**
2978     * Method returns MBean's MBeanOperationInfo Array
2979     * @return MBeanOperationInfo[]
2980     */

2981    protected MBeanOperationInfo JavaDoc[] getMBeanOperationsInfo () {
2982        MBeanParameterInfo JavaDoc[] params = null;
2983        MBeanOperationInfo JavaDoc[] dOperations = new MBeanOperationInfo JavaDoc[18];
2984        dOperations[0] = new MBeanOperationInfo JavaDoc("reset",
2985            "reset(): reset attributes to their initial values",
2986            params, "void",
2987            MBeanOperationInfo.ACTION);
2988        dOperations[1] = new MBeanOperationInfo JavaDoc("saveAttributes",
2989            "saveAttributes(): save the attribute values into the configuration file",
2990            params, "void",
2991            MBeanOperationInfo.ACTION);
2992        dOperations[2] = new MBeanOperationInfo JavaDoc("getAppInfo",
2993            "getAppInfo(): get application information",
2994            params, "String",
2995            MBeanOperationInfo.ACTION);
2996        
2997        params = new MBeanParameterInfo JavaDoc[2];
2998        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
2999                "use UNDERLINE (_) as attribute group separator.");
3000        params[1] = new MBeanParameterInfo JavaDoc("attValue","java.lang.String","Attribute value!");
3001        
3002        dOperations[3] = new MBeanOperationInfo JavaDoc("addAttribute",
3003              "addAttribute(String key, String value): add new application parameter",
3004              params, "void",
3005              MBeanOperationInfo.ACTION);
3006        
3007        params = new MBeanParameterInfo JavaDoc[1];
3008        params[0] = new MBeanParameterInfo JavaDoc("attKey","java.lang.String","Attribute name! Please, " +
3009                "use UNDERLINE (_) as attribute group separator.");
3010        
3011        dOperations[4] = new MBeanOperationInfo JavaDoc("removeAttribute",
3012              "removeAttribute(String key): remove application parameter",
3013              params, "void",
3014              MBeanOperationInfo.ACTION);
3015        
3016        params = null;
3017        
3018        dOperations[5] = new MBeanOperationInfo JavaDoc("Refresh_Cache",
3019                "refreshCache(): Refresh Table Cache.",
3020                params, "java.lang.String",
3021                MBeanOperationInfo.ACTION);
3022        
3023        dOperations[6] = new MBeanOperationInfo JavaDoc("Refresh_Statistics",
3024                "refreshStatistics(): Refresh Table Statistics.",
3025                params, "java.lang.String",
3026                MBeanOperationInfo.ACTION);
3027        
3028        dOperations[7] = new MBeanOperationInfo JavaDoc("Get_Table_Statistics",
3029                "getAllDoCacheStatistics(): Get Table Statistics.",
3030                params, "java.lang.String",
3031                MBeanOperationInfo.ACTION);
3032        
3033        dOperations[8] = new MBeanOperationInfo JavaDoc("Get_Table_Data_Struct_Statistics",
3034                "getDoCacheStatistics(0): Get Table Data Struct Statistics.",
3035                params, "java.lang.String",
3036                MBeanOperationInfo.ACTION);
3037        
3038        dOperations[9] = new MBeanOperationInfo JavaDoc("Get_Table_Simple_Query_Statistics",
3039                "getDoCacheStatistics(1): Get Table Simple Query Statistics.",
3040                params, "java.lang.String",
3041                MBeanOperationInfo.ACTION);
3042        
3043        dOperations[10] = new MBeanOperationInfo JavaDoc("Get_Table_Complex_Query_Statistics",
3044                "getDoCacheStatistics(2): Get Table Complex Query Statistics.",
3045                params, "java.lang.String",
3046                MBeanOperationInfo.ACTION);
3047        
3048        dOperations[11] = new MBeanOperationInfo JavaDoc("Clear_Table_Data_Struct_Statistics",
3049                "clearDoCacheStatistics(0): Clear Table Data Struct Statistics.",
3050                params, "void",
3051                MBeanOperationInfo.ACTION);
3052        
3053        dOperations[12] = new MBeanOperationInfo JavaDoc("Clear_Table_Simple_Query_Statistics",
3054                "clearDoCacheStatistics(1): Clear Table Simple Query Statistics.",
3055                params, "void",
3056                MBeanOperationInfo.ACTION);
3057        
3058        dOperations[13] = new MBeanOperationInfo JavaDoc("Clear_Table_Complex_Query_Statistics",
3059                "clearDoCacheStatistics(2): Clear Table Complex Query Statistics.",
3060                params, "void",
3061                MBeanOperationInfo.ACTION);
3062        
3063        dOperations[14] = new MBeanOperationInfo JavaDoc("Clear_Table_Statistics",
3064                "clearAllDoStatistics(): Clear Table Statistics.",
3065                params, "void",
3066                MBeanOperationInfo.ACTION);
3067        
3068        dOperations[15] = new MBeanOperationInfo JavaDoc("Enable_Cache",
3069                "enableCaching(): Enables Table Cache Status.",
3070                params, "java.lang.String",
3071                MBeanOperationInfo.ACTION);
3072        
3073        dOperations[16] = new MBeanOperationInfo JavaDoc("Disable_Cache",
3074                "disableCaching(): Disables Table Cache Status.",
3075                params, "java.lang.String",
3076                MBeanOperationInfo.ACTION);
3077        
3078        dOperations[17] = new MBeanOperationInfo JavaDoc("Toggle_EnableOrDisable_Cache",
3079                "enableDisableCaching(): Toggles Table Cache Status.",
3080                params, "java.lang.String",
3081                MBeanOperationInfo.ACTION);
3082        
3083        return dOperations;
3084    }
3085    
3086    /**
3087     * Operation: reset attributes to their initial values
3088     */

3089    public void reset() throws AttributeNotFoundException JavaDoc {
3090      super.reset();
3091      try {
3092          setReserveFactor((String JavaDoc)hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[0]));
3093          setCachePercentage((String JavaDoc)hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[1]));
3094          setInitialCondition((String JavaDoc)hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[2]));
3095          setMaxCacheSize((String JavaDoc)hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[3]));
3096          setMaxSimpleCacheSize((String JavaDoc)hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[4]));
3097          setMaxComplexCacheSize((String JavaDoc)hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[5]));
3098          setInitialDSCacheSize((String JavaDoc)hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[6]));
3099          setInitialCacheFetchSize((String JavaDoc)hashAttrib.get(CACHE_DOT+TableMBConst.cacheParameters[7]));
3100      } catch (Exception JavaDoc ex){
3101        ex.printStackTrace();
3102      }
3103    }
3104
3105    /*
3106     * -----------------------------------------------------
3107     * PRIVATE METHODS
3108     * -----------------------------------------------------
3109     */

3110    
3111    private int getLevelOfCaching() {
3112        int levelOfCaching = 0;
3113        try {
3114          Method JavaDoc mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION).
3115              getMethod(GET_LEVEL_OF_CACHING, new Class JavaDoc[] {});
3116          levelOfCaching = ( (Integer JavaDoc) mth.invoke(cfgAdmin, new Object JavaDoc[] {})).
3117              intValue();
3118        } catch (Exception JavaDoc e) {
3119          e.printStackTrace();
3120        }
3121        return levelOfCaching;
3122    }
3123    
3124    private String JavaDoc getCachingStatus() {
3125        if (isCachingDisabled()){
3126            return "DISABLED";
3127        }else {
3128            return "ENABLED";
3129        }
3130    }
3131
3132    private boolean isCachingDisabled() {
3133        boolean ret = true;
3134        try {
3135          Method JavaDoc mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION).
3136              getMethod(IS_DISABLED, new Class JavaDoc[] {});
3137          ret = ( (Boolean JavaDoc) mth.invoke(cfgAdmin, new Object JavaDoc[] {})).booleanValue();
3138        } catch (Exception JavaDoc e) {
3139          e.printStackTrace();
3140        }
3141        return ret;
3142    }
3143
3144    private String JavaDoc getCacheType() {
3145        String JavaDoc ret = null;
3146        try {
3147          Method JavaDoc mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION).
3148              getMethod(GET_TYPE, new Class JavaDoc[] {});
3149          ret = ( (String JavaDoc) mth.invoke(cfgAdmin, new Object JavaDoc[] {}));
3150        } catch (Exception JavaDoc e) {
3151          e.printStackTrace();
3152        }
3153        return ret;
3154    }
3155
3156    private String JavaDoc getCachePercentage() {
3157      double cachePercentage = 0;
3158      try {
3159        Method JavaDoc mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION).
3160            getMethod(GET_CACHE_PERCENTAGE, new Class JavaDoc[] {});
3161        cachePercentage = ( (Double JavaDoc) mth.invoke(cfgAdmin, new Object JavaDoc[] {})).
3162            doubleValue();
3163      } catch (Exception JavaDoc e) {
3164          logChannel.write(Logger.DEBUG, e.toString());
3165      }
3166      return String.valueOf(cachePercentage);
3167    }
3168    
3169    private String JavaDoc setCachePercentage(String JavaDoc value) throws Exception JavaDoc {
3170        String JavaDoc oldValue = getCachePercentage();
3171        if (!value.equals(oldValue)) {
3172            Method JavaDoc mth = Class.forName(CLASS_UPDATE_CONFIGURATION_ADMINISTRATION).
3173            getMethod(SET_CACHE_PERCENTAGE,
3174                      new Class JavaDoc[] {Class.forName(
3175                            CLASS_CONFIGURATION_ADMINISTRATION), Double.TYPE});
3176            mth.invoke(null, new Object JavaDoc[] {cfgAdmin, new Double JavaDoc(value)});
3177        }
3178        return oldValue;
3179      }
3180
3181    private String JavaDoc getInitialCacheFetchSize() {
3182      int fetchSize = 0;
3183      try {
3184        Method JavaDoc mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION).
3185            getMethod(GET_INITIAL_FETCH_SIZE, new Class JavaDoc[] {});
3186        fetchSize = ( (Integer JavaDoc) mth.invoke(cfgAdmin, new Object JavaDoc[] {})).
3187            intValue();
3188      } catch (Exception JavaDoc e) {
3189          logChannel.write(Logger.DEBUG, e.toString());
3190      }
3191      return String.valueOf(fetchSize);
3192    }
3193    
3194    private String JavaDoc setInitialCacheFetchSize(String JavaDoc value) throws Exception JavaDoc {
3195        String JavaDoc oldValue = getInitialCacheFetchSize();
3196        if (!value.equals(oldValue)) {
3197          Method JavaDoc mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION).
3198              getMethod(SET_INITIAL_FETCH_SIZE,
3199                        new Class JavaDoc[] {Integer.TYPE});
3200          mth.invoke(cfgAdmin, new Object JavaDoc[] {new Integer JavaDoc(value)});
3201        }
3202        return oldValue;
3203      }
3204
3205    private String JavaDoc getInitialDSCacheSize() {
3206      int dsSize = 0;
3207      try {
3208        Method JavaDoc mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION).
3209            getMethod(GET_INITIAL_DS_SIZE, new Class JavaDoc[] {});
3210        dsSize = ( (Integer JavaDoc) mth.invoke(cfgAdmin, new Object JavaDoc[] {})).
3211            intValue();
3212      } catch (Exception JavaDoc e) {
3213          logChannel.write(Logger.DEBUG, e.toString());
3214      }
3215      return String.valueOf(dsSize);
3216    }
3217    
3218    private String JavaDoc setInitialDSCacheSize(String JavaDoc value) throws Exception JavaDoc {
3219        String JavaDoc oldValue = getInitialDSCacheSize();
3220        if (!value.equals(oldValue)) {
3221          Method JavaDoc mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION).
3222              getMethod(SET_INITIAL_DS_SIZE,
3223                        new Class JavaDoc[] {Integer.TYPE});
3224          mth.invoke(cfgAdmin, new Object JavaDoc[] {new Integer JavaDoc(value)});
3225        }
3226        return oldValue;
3227    }
3228    
3229    private String JavaDoc getReserveFactor() {
3230      double reserveFactor = 0;
3231      try {
3232        Method JavaDoc mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION).
3233            getMethod(GET_RESERVE_FACTOR, new Class JavaDoc[] {});
3234        reserveFactor = ( (Double JavaDoc) mth.invoke(cfgAdmin, new Object JavaDoc[] {})).
3235            doubleValue();
3236      } catch (Exception JavaDoc e) {
3237         logChannel.write(Logger.DEBUG, e.toString());
3238      }
3239      return String.valueOf(reserveFactor);
3240    }
3241    
3242    private String JavaDoc setReserveFactor(String JavaDoc value) throws Exception JavaDoc {
3243        String JavaDoc oldValue = getReserveFactor();
3244        if (!value.equals(oldValue)) {
3245          Method JavaDoc mth = Class.forName(CLASS_UPDATE_CONFIGURATION_ADMINISTRATION).
3246              getMethod(SET_RESERVE_FACTOR,
3247                        new Class JavaDoc[] {Class.forName(
3248              CLASS_CONFIGURATION_ADMINISTRATION), Double.TYPE});
3249          mth.invoke(null, new Object JavaDoc[] {cfgAdmin, new Double JavaDoc(value)});
3250        }
3251        return oldValue;
3252    }
3253    
3254    private String JavaDoc getInitialCondition() {
3255      String JavaDoc initialCondition = null;
3256      try {
3257        Method JavaDoc mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION).
3258            getMethod(GET_INITIAL_QUERY_CACHE, new Class JavaDoc[] {});
3259        initialCondition = (String JavaDoc) mth.invoke(cfgAdmin, new Object JavaDoc[] {});
3260        if (initialCondition == null) {
3261          initialCondition = TableMBConst.cacheDefaults[2];
3262        }
3263      } catch (Exception JavaDoc e) {
3264          logChannel.write(Logger.DEBUG, e.toString());
3265      }
3266      return initialCondition;
3267    }
3268    
3269    private String JavaDoc setInitialCondition(String JavaDoc value) throws Exception JavaDoc {
3270        String JavaDoc oldValue = getInitialCondition();
3271        if (!value.equals(oldValue)) {
3272          Method JavaDoc mth = Class.forName(CLASS_UPDATE_CONFIGURATION_ADMINISTRATION).
3273              getMethod(SET_INITIAL_QUERY_CACHE,
3274                        new Class JavaDoc[] {Class.forName(
3275              CLASS_CONFIGURATION_ADMINISTRATION),
3276                        Class.forName("java.lang.String")});
3277          mth.invoke(null, new Object JavaDoc[] {cfgAdmin, value});
3278        }
3279        return oldValue;
3280      }
3281
3282    private Object JavaDoc getCacheAdministration(int i) {
3283      Object JavaDoc ret = null;
3284      try {
3285        Method JavaDoc mth = Class.forName(CLASS_CONFIGURATION_ADMINISTRATION).
3286            getMethod(GET_CACHE_ADMINISTRATION,
3287                      new Class JavaDoc[] {Integer.TYPE});
3288        ret = mth.invoke(cfgAdmin, new Object JavaDoc[] {new Integer JavaDoc(i)});
3289      } catch (Exception JavaDoc e) {
3290          logChannel.write(Logger.DEBUG, e.toString());
3291      }
3292      return ret;
3293    }
3294
3295    private String JavaDoc getMaxCacheSize() {
3296      String JavaDoc ret = null;
3297      try {
3298        Object JavaDoc cacheAdmin = getCacheAdministration(TableMBConst.DATA_CACHE);
3299        Method JavaDoc mth = Class.forName(CLASS_CACHE_ADMINISTRATION).
3300            getMethod(GET_MAX_CACHE_SIZE, new Class JavaDoc[] {});
3301        int maxCacheSize = ( (Integer JavaDoc) mth.invoke(cacheAdmin, new Object JavaDoc[] {})).
3302            intValue();
3303        ret = String.valueOf(maxCacheSize);
3304      } catch (Exception JavaDoc e) {
3305          logChannel.write(Logger.DEBUG, e.toString());
3306      }
3307      return ret;
3308    }
3309    
3310    private String JavaDoc setMaxCacheSize(String JavaDoc value) throws Exception JavaDoc {
3311        String JavaDoc oldValue = getMaxCacheSize();
3312        if (!value.equals(oldValue)) {
3313          Object JavaDoc cacheAdmin = getCacheAdministration(TableMBConst.DATA_CACHE);
3314          Method JavaDoc mth = Class.forName(CLASS_UPDATE_CONFIGURATION_ADMINISTRATION).
3315              getMethod(SET_MAX_CACHE_SIZE,
3316                        new Class JavaDoc[] {Class.forName(CLASS_CACHE_ADMINISTRATION),
3317                        Integer.TYPE});
3318          mth.invoke(null, new Object JavaDoc[] {cacheAdmin, new Integer JavaDoc(value)});
3319        }
3320        return oldValue;
3321    }
3322
3323    private String JavaDoc getMaxSimpleCacheSize() {
3324      String JavaDoc ret = null;
3325      try {
3326        Object JavaDoc cacheAdmin = getCacheAdministration(TableMBConst.SIMPLE_QUERY_CACHE);
3327        Method JavaDoc mth = Class.forName(CLASS_CACHE_ADMINISTRATION).
3328            getMethod(GET_MAX_CACHE_SIZE, new Class JavaDoc[] {});
3329        int maxCacheSize = ( (Integer JavaDoc) mth.invoke(cacheAdmin, new Object JavaDoc[] {})).
3330            intValue();
3331        ret = String.valueOf(maxCacheSize);
3332      } catch (Exception JavaDoc e) {
3333          logChannel.write(Logger.DEBUG, e.toString());
3334      }
3335      return ret;
3336    }
3337    
3338    private String JavaDoc setMaxSimpleCacheSize(String JavaDoc value) throws Exception JavaDoc {
3339        String JavaDoc oldValue = getMaxSimpleCacheSize();
3340        if (!value.equals(oldValue)) {
3341          Object JavaDoc cacheAdmin = getCacheAdministration(TableMBConst.SIMPLE_QUERY_CACHE);
3342          Method JavaDoc mth = Class.forName(
3343                                     CLASS_UPDATE_CONFIGURATION_ADMINISTRATION).
3344              getMethod(SET_MAX_CACHE_SIZE,
3345                        new Class JavaDoc[] {Class.forName(
3346                                      CLASS_CACHE_ADMINISTRATION),
3347                                      Integer.TYPE});
3348          mth.invoke(null, new Object JavaDoc[] {cacheAdmin, new Integer JavaDoc(value)});
3349        }
3350        return oldValue;
3351      }
3352
3353    private String JavaDoc getMaxComplexCacheSize() {
3354      String JavaDoc ret = null;
3355      try {
3356        Object JavaDoc cacheAdmin = getCacheAdministration(TableMBConst.COMPLEX_QUERY_CACHE);
3357        Method JavaDoc mth = Class.forName(CLASS_CACHE_ADMINISTRATION).
3358            getMethod(GET_MAX_CACHE_SIZE, new Class JavaDoc[] {});
3359        int maxCacheSize = ( (Integer JavaDoc) mth.invoke(cacheAdmin, new Object JavaDoc[] {})).
3360            intValue();
3361        ret = String.valueOf(maxCacheSize);
3362      } catch (Exception JavaDoc e) {
3363            logChannel.write(Logger.DEBUG, e.toString());
3364      }
3365      return ret;
3366    }
3367    
3368    private String JavaDoc setMaxComplexCacheSize(String JavaDoc value) throws Exception JavaDoc {
3369        String JavaDoc oldValue = getMaxComplexCacheSize();
3370        if (!value.equals(oldValue)) {
3371          Object JavaDoc cacheAdmin = getCacheAdministration(TableMBConst.COMPLEX_QUERY_CACHE);
3372          Method JavaDoc mth = Class.forName(CLASS_UPDATE_CONFIGURATION_ADMINISTRATION).
3373              getMethod(SET_MAX_CACHE_SIZE,
3374                        new Class JavaDoc[] {Class.forName(CLASS_CACHE_ADMINISTRATION),
3375                        Integer.TYPE});
3376          mth.invoke(null, new Object JavaDoc[] {cacheAdmin, new Integer JavaDoc(value)});
3377        }
3378        return oldValue;
3379    }
3380    
3381    private String JavaDoc enableDisableCaching() {
3382        String JavaDoc retString = null;
3383        try {
3384          Method JavaDoc mth;
3385          if (isCachingDisabled()) {
3386            mth = tableClass.getMethod(ENABLE,
3387                    TableMBConst.NOCLASS_ARR);
3388            retString = BOLD + COLOUR + GREEN +
3389                ENABLED +
3390                E_COLOUR + E_BOLD;
3391          }
3392          else {
3393            mth = tableClass.getMethod(DISABLE,
3394                    TableMBConst.NOCLASS_ARR);
3395            retString = BOLD + COLOUR + RED +
3396                DISABLED +
3397                E_COLOUR + E_BOLD;
3398          }
3399
3400          mth.invoke(null, new Object JavaDoc[] {});
3401
3402        } catch (Exception JavaDoc e) {
3403           logChannel.write(Logger.DEBUG, e.toString());
3404        }
3405        return retString;
3406    }
3407 
3408    private String JavaDoc enableCaching() {
3409        String JavaDoc retString = null;
3410        try {
3411          Method JavaDoc mth;
3412          mth = tableClass.getMethod(ENABLE,
3413                    TableMBConst.NOCLASS_ARR);
3414          retString = BOLD + COLOUR + GREEN +
3415                ENABLED +
3416                E_COLOUR + E_BOLD;
3417          mth.invoke(null, new Object JavaDoc[] {});
3418
3419        } catch (Exception JavaDoc e) {
3420           logChannel.write(Logger.DEBUG, e.toString());
3421        }
3422        return retString;
3423    }
3424
3425    
3426    private String JavaDoc disableCaching() {
3427        String JavaDoc retString = null;
3428        try {
3429          Method JavaDoc mth;
3430          mth = tableClass.getMethod(DISABLE,
3431                    TableMBConst.NOCLASS_ARR);
3432          retString = BOLD + COLOUR + RED +
3433                DISABLED +
3434                E_COLOUR + E_BOLD;
3435          
3436          mth.invoke(null, new Object JavaDoc[] {});
3437        } catch (Exception JavaDoc e) {
3438           logChannel.write(Logger.DEBUG, e.toString());
3439        }
3440        return retString;
3441    }
3442    
3443    private String JavaDoc refreshCache() {
3444        String JavaDoc retString = null;
3445        try {
3446          Method JavaDoc mth;
3447          mth = tableClass.getMethod(REFRESH,
3448                    TableMBConst.NOCLASS_ARR);
3449          retString = BOLD + COLOUR + BLUE +
3450                REFRESHED +
3451                E_COLOUR + E_BOLD;
3452          
3453          mth.invoke(null, new Object JavaDoc[] {});
3454        } catch (Exception JavaDoc e) {
3455           logChannel.write(Logger.DEBUG, e.toString());
3456        }
3457        return retString;
3458    }
3459    
3460    private String JavaDoc refreshStatistics() {
3461        String JavaDoc retString = null;
3462        try {
3463          Method JavaDoc mth;
3464          mth = tableClass.getMethod(STATISTICREFRESH,
3465                    TableMBConst.NOCLASS_ARR);
3466          retString = BOLD + COLOUR + BLUE +
3467                STATISTICREFRESHED +
3468                E_COLOUR + E_BOLD;
3469          
3470          mth.invoke(null, new Object JavaDoc[] {});
3471        } catch (Exception JavaDoc e) {
3472           logChannel.write(Logger.DEBUG, e.toString());
3473        }
3474        return retString;
3475    }
3476
3477    private String JavaDoc cachingDisabled() {
3478        String JavaDoc retString = null;
3479        if (isCachingDisabled()) {
3480          retString = BOLD + COLOUR + RED +
3481              DISABLED +
3482              E_COLOUR + E_BOLD;
3483        }
3484        return retString;
3485    }
3486    
3487    private String JavaDoc cachingActive(int type) {
3488        String JavaDoc retString = null;
3489        if(type == 0) {
3490        int value = (new Integer JavaDoc(getMaxCacheSize())).intValue();
3491        if (value<1) {
3492          retString = BOLD + COLOUR + RED +
3493              CACHE_NOT_ACTIVE +
3494              E_COLOUR + E_BOLD;
3495        }
3496        return retString;
3497       }
3498       else if(type == 1) {
3499        int value = (new Integer JavaDoc(getMaxSimpleCacheSize())).intValue();
3500        if (value<1) {
3501          retString = BOLD + COLOUR + RED +
3502              CACHE_NOT_ACTIVE +
3503              E_COLOUR + E_BOLD;
3504        }
3505        return retString;
3506       }
3507       else if(type == 2) {
3508        int value = (new Integer JavaDoc(getMaxComplexCacheSize())).intValue();
3509        if (value < 1) {
3510          retString = BOLD + COLOUR + RED +
3511              CACHE_NOT_ACTIVE +
3512              E_COLOUR + E_BOLD;
3513        }
3514        return retString;
3515       }
3516       return retString;
3517      }
3518    
3519    private String JavaDoc getDoCacheStatistics(int type) {
3520      String JavaDoc retString = cachingActive(type);
3521      if (retString != null) {
3522        return retString;
3523      }
3524      try {
3525        Method JavaDoc mth = tableClass.getMethod("get_statistics",
3526                TableMBConst.NOCLASS_ARR);
3527        Object JavaDoc tableStat = mth.invoke(null, new Object JavaDoc[] {});
3528
3529        mth = Class.forName(CLASS_STATISTICS).getMethod(
3530            GET_CACHE_STATISTICS,
3531            new Class JavaDoc[] {Integer.TYPE});
3532        Object JavaDoc stat = mth.invoke(tableStat, new Object JavaDoc[] {new Integer JavaDoc(type)});
3533        retString = TABLE + CAPTION + BOLD +
3534            COLOUR + BLUE + TableMBConst.CACHE_STAT_TYPE[type] +
3535            CACHE_STAT_FOR + tableClass.getName() +
3536            E_COLOUR + E_BOLD + E_CAPTION;
3537
3538        mth = Class.forName(CLASS_CACHE_STATISTICS).getMethod(
3539            GET_CACHE_ACCESS_NUM,
3540            TableMBConst.NOCLASS_ARR);
3541
3542        retString += ROW + DATA;
3543        retString += CACHE_ACCESS_NUM + E_DATA;
3544        retString += DATA;
3545        retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3546            E_DATA + E_ROW;
3547        mth = Class.forName(CLASS_CACHE_STATISTICS).getMethod(
3548            GET_CACHE_HITS_NUM,
3549            TableMBConst.NOCLASS_ARR);
3550
3551        retString += ROW + DATA;
3552        retString += CACHE_HITS_NUM + E_DATA;
3553        retString += DATA;
3554        retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3555            E_DATA + E_ROW;
3556
3557        mth = Class.forName(CLASS_CACHE_STATISTICS).getMethod(
3558            GET_USED_PERCENTS,
3559            TableMBConst.NOCLASS_ARR);
3560
3561        retString += ROW + DATA;
3562        retString += USED_PERCENTS + E_DATA;
3563        retString += DATA;
3564        retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3565            PRC +
3566            E_DATA + E_ROW;
3567
3568        mth = Class.forName(CLASS_CACHE_STATISTICS).getMethod(
3569            GET_CACHE_HITS_PERCENTS,
3570            TableMBConst.NOCLASS_ARR);
3571
3572        retString += ROW + DATA;
3573        retString += CACHE_HITS_PERCENTS + E_DATA;
3574        retString += DATA;
3575        retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3576            PRC +
3577            E_DATA + E_ROW;
3578        retString += E_TABLE;
3579        return retString;
3580
3581      }
3582      catch (Exception JavaDoc e) {
3583        e.printStackTrace();
3584        return "ERROR: " + e.getLocalizedMessage();
3585      }
3586    }
3587    
3588    private String JavaDoc getAllDoCacheStatistics() {
3589      String JavaDoc retString = null;
3590      retString = TABLE + ROW + DATA;
3591      int nParam;
3592      if (levelOfCaching == TableMBConst.QUERY_CACHING) {
3593        nParam = 3;
3594      }
3595      else {
3596        nParam = 1;
3597      }
3598      for (int i = 0; i < nParam; i++) {
3599        retString += DATA;
3600        retString += getDoCacheStatistics(i);
3601        retString += E_DATA;
3602      }
3603      retString += E_ROW + E_TABLE;
3604      return retString;
3605    }
3606    
3607    private String JavaDoc getDOStatistics() {
3608        try {
3609          Method JavaDoc mth = tableClass.getMethod("get_statistics",
3610                                            new Class JavaDoc[] {});
3611
3612          Object JavaDoc stat = mth.invoke(null, new Object JavaDoc[] {});
3613          Class JavaDoc statClass = Class.forName(CLASS_STATISTICS);
3614
3615          String JavaDoc retString = TABLE + CAPTION + BOLD +
3616              COLOUR + BLUE + TABLE_STAT_FOR +
3617              tableClass.getName() + E_COLOUR + E_BOLD +
3618              E_CAPTION;
3619
3620          mth = statClass.getMethod(GET_STATISTICS_TYPE,
3621                                    new Class JavaDoc[] {});
3622
3623          retString = retString + ROW + DATA;
3624          retString += STATISTCS_TYPE + E_DATA;
3625          retString += DATA;
3626          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3627              E_DATA + E_ROW;
3628
3629          mth = statClass.getMethod(GET_INSERT_NUM,
3630                                    new Class JavaDoc[] {});
3631
3632          retString += ROW + DATA;
3633          retString += INSERT_NUM + E_DATA;
3634          retString += DATA;
3635          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3636              E_DATA + E_ROW;
3637
3638          mth = statClass.getMethod(GET_UPDATE_NUM,
3639                                    new Class JavaDoc[] {});
3640
3641          retString += ROW + DATA;
3642          retString += UPDATE_NUM + E_DATA;
3643          retString += DATA;
3644          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3645              E_DATA + E_ROW;
3646
3647          mth = statClass.getMethod(GET_DELETE_NUM,
3648                                    new Class JavaDoc[] {});
3649
3650          retString += ROW + DATA;
3651          retString += DELETE_NUM + E_DATA;
3652          retString += DATA;
3653          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3654              E_DATA + E_ROW;
3655
3656          mth = statClass.getMethod(GET_DML_NUM,
3657                                    new Class JavaDoc[] {});
3658
3659          retString += ROW + DATA;
3660          retString += DML_NUM + E_DATA;
3661          retString += DATA;
3662          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3663              E_DATA + E_ROW;
3664
3665          mth = statClass.getMethod(GET_LAZY_LOADING_NUM,
3666                                    new Class JavaDoc[] {});
3667
3668          retString += ROW + DATA;
3669          retString += LAZY_LOADING_NUM + E_DATA;
3670          retString += DATA;
3671          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3672              E_DATA + E_ROW;
3673
3674          mth = statClass.getMethod(GET_START_TIME,
3675                                    new Class JavaDoc[] {});
3676
3677          retString += ROW + DATA;
3678          retString += START_TIME + E_DATA;
3679          retString += DATA;
3680          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3681              E_DATA + E_ROW;
3682
3683          mth = statClass.getMethod(GET_STOP_TIME,
3684                                    new Class JavaDoc[] {});
3685
3686          retString += ROW + DATA;
3687          retString += STOP_TIME + E_DATA;
3688          retString += DATA;
3689          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3690              E_DATA + E_ROW;
3691
3692          mth = statClass.getMethod(GET_QUERY_NUM,
3693                                    new Class JavaDoc[] {});
3694
3695          retString += ROW + DATA;
3696          retString += QUERY_NUM + E_DATA;
3697          retString += DATA;
3698          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3699              E_DATA + E_ROW;
3700
3701          mth = statClass.getMethod(GET_QUERY_BY_OID_NUM,
3702                                    new Class JavaDoc[] {});
3703
3704          retString += ROW + DATA;
3705          retString += QUERY_BY_OID_NUM + E_DATA;
3706          retString += DATA;
3707          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3708              E_DATA + E_ROW;
3709
3710          mth = statClass.getMethod(GET_QUERY_AVERAGE_TIME,
3711                                    new Class JavaDoc[] {});
3712
3713          retString += ROW + DATA;
3714          retString += QUERY_AVERAGE_TIME + E_DATA;
3715          retString += DATA;
3716          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3717              E_DATA + E_ROW;
3718
3719          mth = statClass.getMethod(GET_QUERY_BY_OID_AVERAGETIME,
3720                                    new Class JavaDoc[] {});
3721
3722          retString += ROW + DATA;
3723          retString += QUERY_BY_OID_AVERAGE_TIME +
3724              E_DATA;
3725          retString += DATA;
3726          retString += mth.invoke(stat, new Object JavaDoc[] {}) +
3727              E_DATA + E_ROW;
3728          retString = retString + E_TABLE;
3729
3730          return retString;
3731        }
3732        catch (Exception JavaDoc e) {
3733          return "ERROR: " + e.getLocalizedMessage();
3734        }
3735      }
3736    
3737    private void clearDoCacheStatistics(int type) {
3738        try {
3739          Method JavaDoc mth = tableClass.getMethod("get_statistics",
3740                TableMBConst.NOCLASS_ARR);
3741
3742          Object JavaDoc tableStat = mth.invoke(null, new Object JavaDoc[] {});
3743          mth = Class.forName(CLASS_STATISTICS).getMethod(
3744              GET_CACHE_STATISTICS,
3745              new Class JavaDoc[] {Integer.TYPE});
3746          Object JavaDoc stat = mth.invoke(tableStat, new Object JavaDoc[] {new Integer JavaDoc(type)});
3747          mth = Class.forName(CLASS_CACHE_STATISTICS).getMethod(
3748              CLEAR_STATISTICS,
3749              TableMBConst.NOCLASS_ARR);
3750          mth.invoke(stat, new Object JavaDoc[] {});
3751        }
3752        catch (Exception JavaDoc e) {
3753            logChannel.write(Logger.DEBUG, e.toString());
3754        }
3755      }
3756    
3757    private void clearAllDoStatistics() {
3758        try {
3759          Method JavaDoc mth = tableClass.getMethod("get_statistics",
3760                TableMBConst.NOCLASS_ARR);
3761
3762          Object JavaDoc tableStat = mth.invoke(null, new Object JavaDoc[] {});
3763          mth = Class.forName(CLASS_STATISTICS).getMethod(CLEAR,
3764                TableMBConst.NOCLASS_ARR);
3765          mth.invoke(tableStat, new Object JavaDoc[] {});
3766
3767        }
3768        catch (Exception JavaDoc e) {
3769            logChannel.write(Logger.DEBUG, e.toString());
3770        }
3771      }
3772    
3773    public String JavaDoc getTableName(){
3774        return tableName;
3775    }
3776    
3777    public String JavaDoc getDbName(){
3778        return dbName;
3779    }
3780  }
3781  
3782  private void registerContextMBean(){
3783    if (appName == null) {
3784      return;
3785    }
3786    
3787    try {
3788      server = findMBeanServer();
3789      if (server == null) {
3790        return;
3791      }
3792    }
3793    catch (Exception JavaDoc e) {
3794         logChannel.write(Logger.DEBUG, e.toString());
3795    }
3796
3797    try {
3798      String JavaDoc applicationName = appName;
3799      ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=Context,name=" + applicationName);
3800      if (!server.isRegistered(objectName)) {
3801        
3802        contextMBean = new ContextMBean(this);
3803        if (contextMBean!=null){
3804            server.registerMBean(contextMBean, objectName);
3805        }
3806      }
3807    }
3808    catch (Exception JavaDoc e) {
3809       e.printStackTrace();
3810        logChannel.write(Logger.DEBUG, e.toString());
3811      return;
3812    }
3813  }
3814
3815  private void unRegisterContextMBean(){
3816    if (appName == null) {
3817      return;
3818    }
3819    
3820    try {
3821      server = findMBeanServer();
3822      if (server == null) {
3823        return;
3824      }
3825    } catch (Exception JavaDoc e) {
3826         logChannel.write(Logger.DEBUG, e.toString());
3827    }
3828
3829    try {
3830      String JavaDoc applicationName = appName;
3831      ObjectName JavaDoc objectName = new ObjectName JavaDoc("EnhydraApplications:type=Context,name=" + applicationName);
3832      if (server.isRegistered(objectName)) {
3833        server.unregisterMBean(objectName);
3834      }
3835      contextMBean = null;
3836    } catch (Exception JavaDoc e) {
3837       logChannel.write(Logger.DEBUG, e.toString());
3838       return;
3839    }
3840  }
3841    
3842  public class ContextMBean implements DynamicMBean JavaDoc {
3843    
3844    private String JavaDoc appName = null;
3845    private String JavaDoc appContext = null;
3846    private String JavaDoc appRealContext = null;
3847    
3848    protected String JavaDoc dClassName = this.getClass().getName();
3849    protected MBeanInfo JavaDoc dMBeanInfo = null;
3850    
3851    public ContextMBean (Application application) {
3852        appName = application.getName();
3853        try{
3854          appRealContext = application.getHttpPresentationManager().getServletContext().getRealPath("/");
3855          appContext = application.getHttpPresentationManager().getServletContext().getServletContextName();
3856          if (appContext == null){
3857              if (appRealContext.endsWith(java.io.File.separator)) {
3858                appContext = appRealContext.substring(0,appRealContext.length()-1);
3859              }else{
3860                appContext = appRealContext;
3861              }
3862              int temp = appContext.lastIndexOf(java.io.File.separator);
3863              if (temp!=-1)
3864                  appContext = appContext.substring(temp+1);
3865          }
3866          
3867        } catch (Exception JavaDoc except){
3868            except.printStackTrace();
3869        }
3870        
3871        buildDynamicMBeanInfo();
3872    }
3873    
3874    public String JavaDoc getAppContext(){
3875        return appContext;
3876    }
3877    
3878    public String JavaDoc getAppRealContext(){
3879        return appRealContext;
3880    }
3881    
3882    public String JavaDoc getAppName(){
3883        return appName;
3884    }
3885    
3886    public void buildDynamicMBeanInfo(){
3887        // MBeanInfo initialization
3888
dMBeanInfo = new MBeanInfo JavaDoc(dClassName, getDescription(),
3889                getMBeanAttributesInfo(), getMBeanConstructorInfo(),
3890                getMBeanOperationsInfo(), getMBeanNotificationInfo());
3891    }
3892
3893    /**
3894     * -----------------------------------------------------
3895     * ADDITIONALL PROTECTED METHODS
3896     * -----------------------------------------------------
3897     */

3898    
3899    /**
3900     * Method returns MBean's MBeanAttributeInfo Array
3901     * @return MBeanAttributeInfo[]
3902     */

3903    protected MBeanAttributeInfo JavaDoc[] getMBeanAttributesInfo () {
3904        MBeanAttributeInfo JavaDoc[] dAttributes = new MBeanAttributeInfo JavaDoc[0];
3905        return dAttributes;
3906    }
3907    
3908    /**
3909     * Method returns MBean's MBeanOperationInfo Array
3910     * @return MBeanOperationInfo[]
3911     */

3912    protected MBeanOperationInfo JavaDoc[] getMBeanOperationsInfo () {
3913        MBeanParameterInfo JavaDoc[] params = null;
3914        MBeanOperationInfo JavaDoc[] dOperations = new MBeanOperationInfo JavaDoc[3];
3915        dOperations[0] = new MBeanOperationInfo JavaDoc("getAppName",
3916            "getAppName(): returns ApplicationName",
3917            params, "java.lang.String",
3918            MBeanOperationInfo.ACTION);
3919        dOperations[1] = new MBeanOperationInfo JavaDoc("getAppContext",
3920            "getAppContext(): returns value of appliation context",
3921            params, "java.lang.String",
3922            MBeanOperationInfo.ACTION);
3923        dOperations[2] = new MBeanOperationInfo JavaDoc("getAppRealContext",
3924                "getAppRealContext(): returns value of appliation real context",
3925                params, "java.lang.String",
3926                MBeanOperationInfo.ACTION);
3927       
3928        return dOperations;
3929    }
3930    
3931    /**
3932     * Method returns MBean's MBeanNotificationInfo Array
3933     * @return MBeanNotificationInfo[]
3934     */

3935    protected MBeanNotificationInfo JavaDoc[] getMBeanNotificationInfo () {
3936        MBeanNotificationInfo JavaDoc[] dNotifications = new MBeanNotificationInfo JavaDoc[0];
3937        return dNotifications;
3938    }
3939    
3940    /**
3941     * Method returns MBean's MBeanConstructorInfo Array
3942     * @return MBeanConstructorInfo[]
3943     */

3944    protected MBeanConstructorInfo JavaDoc[] getMBeanConstructorInfo () {
3945        MBeanParameterInfo JavaDoc[] dParameters = new MBeanParameterInfo JavaDoc[1];
3946        dParameters[0] = new MBeanParameterInfo JavaDoc("application","com.lutris.appserver.server.Application","Application Object");
3947        
3948        MBeanConstructorInfo JavaDoc[] dConstructors = new MBeanConstructorInfo JavaDoc[1];
3949        dConstructors[0] = new MBeanConstructorInfo JavaDoc("ContextMBean",
3950            "Context MBean Object Constructor",
3951            dParameters);
3952        
3953        return dConstructors;
3954    }
3955    
3956    /**
3957     * Method returns MBean's description
3958     * @return String
3959     */

3960    protected String JavaDoc getDescription (){
3961        String JavaDoc dDescription = "Dynamic MBean offers application base context data";
3962        return dDescription;
3963    }
3964    
3965    /*
3966     * -----------------------------------------------------
3967     * IMPLEMENTATION OF THE DynamicMBean INTERFACE
3968     * -----------------------------------------------------
3969     */

3970    
3971    /**
3972     * Allows the value of the specified attribute of the Dynamic MBean to be obtained.
3973     */

3974    public Object JavaDoc getAttribute(String JavaDoc attribute_name) throws
3975        AttributeNotFoundException JavaDoc,
3976        MBeanException JavaDoc, ReflectionException JavaDoc {
3977      // not implemented
3978
return null;
3979    }
3980
3981    /**
3982     * Sets the value of the specified attribute of the Dynamic MBean.
3983     */

3984    public void setAttribute(Attribute JavaDoc attribute) throws
3985        AttributeNotFoundException JavaDoc,
3986        InvalidAttributeValueException JavaDoc, MBeanException JavaDoc, ReflectionException JavaDoc {
3987      //not implemented
3988
}
3989    
3990    /**
3991     * Sets the values of several attributes of the Dynamic MBean, and returns the
3992     * list of attributes that have been set.
3993     */

3994    public AttributeList JavaDoc setAttributes(AttributeList JavaDoc attributes) {
3995        // Check attributes is not null to avoid NullPointerException later on
3996
// not implemented
3997
return null;
3998    }
3999    
4000    /**
4001     * get the values of several attributes of the Dynamic MBean.
4002     */

4003    public AttributeList JavaDoc getAttributes(String JavaDoc[] attributeNames) {
4004
4005      // Check attributeNames is not null to avoid NullPointerException later on
4006
// not implemented
4007
return null;
4008    }
4009    
4010    /**
4011     * This method provides the exposed attributes and operations of the Dynamic MBean.
4012     * It provides this information using an MBeanInfo object.
4013     */

4014    public MBeanInfo JavaDoc getMBeanInfo() {
4015      // return the information we want to expose for management:
4016
// the dMBeanInfo private field has been built at instanciation time,
4017
return dMBeanInfo;
4018    }
4019    
4020    
4021    /**
4022     * -----------------------------------------------------
4023     * ADDITIONALL PUBLIC METHODS
4024     * -----------------------------------------------------
4025     */

4026    
4027    /**
4028     * Allows an operation to be invoked on the Dynamic MBean.
4029     */

4030    public Object JavaDoc invoke(String JavaDoc operationName, Object JavaDoc params[],
4031                         String JavaDoc signature[]) throws MBeanException JavaDoc,
4032        ReflectionException JavaDoc {
4033      // Check operationName is not null to avoid NullPointerException later on
4034
if (operationName == null) {
4035        throw new RuntimeOperationsException JavaDoc(new IllegalArgumentException JavaDoc(
4036            "Operation name cannot be null"),
4037            "Cannot invoke a null operation in " + dClassName);
4038      }
4039      // Check for a recognized operation name and call the corresponding operation
4040
if (operationName.equals("getAppName")) {
4041        return getAppName();
4042      } else if (operationName.equals("getAppContext")) {
4043        return getAppContext();
4044      } else if (operationName.equals("getAppRealContext")) {
4045          return getAppRealContext();
4046      } else {
4047        // unrecognized operation name:
4048
throw new ReflectionException JavaDoc(new NoSuchMethodException JavaDoc(operationName),
4049                                      "Cannot find the operation " +
4050                                      operationName + " in " + dClassName);
4051      }
4052    }
4053    
4054  }
4055}
Popular Tags