Source Code Cross Referenced for JonasBaseAction.java in  » J2EE » JOnAS-4.8.6 » org » objectweb » jonas » webapp » jonasadmin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » JOnAS 4.8.6 » org.objectweb.jonas.webapp.jonasadmin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * JOnAS: Java(TM) Open Application Server
003:         * Copyright (C) 1999-2004 Bull S.A.
004:         * Contact: jonas-team@objectweb.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: JonasBaseAction.java 9713 2006-10-10 13:58:14Z durieuxp $
023:         * --------------------------------------------------------------------------
024:         */package org.objectweb.jonas.webapp.jonasadmin;
025:
026:        import java.io.File;
027:        import java.io.IOException;
028:        import java.util.ArrayList;
029:        import java.util.List;
030:        import java.util.Properties;
031:        import java.util.StringTokenizer;
032:
033:        import javax.management.ObjectName;
034:        import javax.servlet.ServletException;
035:        import javax.servlet.http.HttpServletRequest;
036:        import javax.servlet.http.HttpServletResponse;
037:        import javax.servlet.http.HttpSession;
038:
039:        import org.apache.struts.Globals;
040:        import org.apache.struts.action.Action;
041:        import org.apache.struts.action.ActionMessage;
042:        import org.apache.struts.action.ActionMessages;
043:        import org.apache.struts.action.ActionForm;
044:        import org.apache.struts.action.ActionForward;
045:        import org.apache.struts.action.ActionMapping;
046:        import org.apache.struts.util.MessageResources;
047:
048:        import org.objectweb.jonas.common.Log;
049:        import org.objectweb.jonas.jmx.J2eeObjectName;
050:        import org.objectweb.jonas.jmx.JonasManagementRepr;
051:        import org.objectweb.jonas.webapp.taglib.TreeControl;
052:        import org.objectweb.jonas.webapp.taglib.TreeControlNode;
053:        import org.objectweb.util.monolog.api.BasicLevel;
054:        import org.objectweb.util.monolog.api.Logger;
055:
056:        /**
057:         * @author Michel-Ange ANTON
058:         * @author Florent Benoit (changes for struts 1.2.2)
059:         */
060:
061:        public abstract class JonasBaseAction extends Action {
062:
063:            // ----------------------------------------------------- Constants
064:
065:            public static final int DEPTH_DOMAIN = 1;
066:            public static final int DEPTH_SERVER = 2;
067:
068:            // --------------------------------------------------------- Instance Variables
069:
070:            /**
071:             * The MessageResources we will be retrieving messages from.
072:             */
073:            protected MessageResources m_Resources = null;
074:            protected HttpSession m_Session = null;
075:            protected ActionMessages m_Errors = null;
076:            protected WhereAreYou m_WhereAreYou = null;
077:
078:            // --------------------------------------------------------- Public Methods
079:
080:            public abstract ActionForward executeAction(
081:                    ActionMapping p_Mapping, ActionForm p_Form,
082:                    HttpServletRequest p_Request, HttpServletResponse p_Response)
083:                    throws IOException, ServletException;
084:
085:            /**
086:             * Process the specified HTTP request, and create the corresponding HTTP
087:             * response (or forward to another web component that will create it).
088:             * Return an <code>ActionForward</code> instance describing where and how
089:             * control should be forwarded, or <code>null</code> if the response has
090:             * already been completed.
091:             *
092:             * @param p_Mapping The ActionMapping used to select this instance
093:             * @param p_Form The optional ActionForm bean for this request (if any)
094:             * @param p_Request The HTTP request we are processing
095:             * @param p_Response The HTTP response we are creating
096:             *
097:             * @return The forward where redirect
098:             *
099:             * @exception IOException if an input/output error occurs
100:             * @exception ServletException if a servlet exception occurs
101:             */
102:            public ActionForward execute(ActionMapping p_Mapping,
103:                    ActionForm p_Form, HttpServletRequest p_Request,
104:                    HttpServletResponse p_Response) throws IOException,
105:                    ServletException {
106:
107:                ActionForward oActionForward = null;
108:
109:                // Instance variables
110:                initialize(p_Request);
111:
112:                // Verify that a instance of WhereAreYou object exists
113:                if (m_WhereAreYou == null) {
114:                    oActionForward = (p_Mapping.findForward("Main Index"));
115:                } else {
116:                    oActionForward = executeAction(p_Mapping, p_Form,
117:                            p_Request, p_Response);
118:                }
119:                return oActionForward;
120:            }
121:
122:            /**
123:             * Initialize the instance variables.
124:             * @param p_Request The HTTP request we are processing
125:             */
126:            protected void initialize(HttpServletRequest p_Request) {
127:                // Acquire the resources that we need
128:                m_Session = p_Request.getSession();
129:                if (m_Resources == null) {
130:                    m_Resources = (MessageResources) getServlet()
131:                            .getServletContext().getAttribute(
132:                                    Globals.MESSAGES_KEY);
133:                }
134:                m_Errors = new ActionMessages();
135:                m_WhereAreYou = (WhereAreYou) m_Session
136:                        .getAttribute(WhereAreYou.SESSION_NAME);
137:
138:            }
139:
140:            /**
141:             * Return the name of the branch in the tree for the selected node.
142:             *
143:             * @param p_Width Depth of the branch
144:             * @return The branch name
145:             */
146:            protected String getTreeBranchName(int p_Width) {
147:                StringBuffer sb = new StringBuffer();
148:                try {
149:                    StringTokenizer st = new StringTokenizer(m_WhereAreYou
150:                            .getSelectedNameNode(), WhereAreYou.NODE_SEPARATOR);
151:                    for (int i = 0; (st.hasMoreTokens() && (i < p_Width)); i++) {
152:                        if (i > 0) {
153:                            sb.append(WhereAreYou.NODE_SEPARATOR);
154:                        }
155:                        sb.append(st.nextToken());
156:                    }
157:                } catch (NullPointerException e) {
158:                    // none action
159:                }
160:                return sb.toString();
161:            }
162:
163:            /**
164:             * Add a global error in <code>m_Errors</code>instance of <code>m_ErrorsActionMessages</code>
165:             * and log it.
166:             *
167:             * @param p_Throwable Error to add
168:             */
169:            protected void addGlobalError(Throwable p_Throwable) {
170:                String sMessResource;
171:                String sMessageError = p_Throwable.getMessage();
172:                if (sMessageError == null) {
173:                    sMessResource = m_Resources.getMessage("error.global.log",
174:                            p_Throwable.getClass().getName());
175:                    //getServlet().log(sMessResource, p_Throwable);
176:                    Logger logger = Log.getLogger(Log.JONAS_ADMIN_PREFIX);
177:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
178:                        logger.log(BasicLevel.DEBUG, sMessResource);
179:                    }
180:                    m_Errors.add("error.global", new ActionMessage(
181:                            "error.global", p_Throwable.getClass().getName()));
182:                } else {
183:                    sMessResource = m_Resources.getMessage(
184:                            "error.global.message.log", p_Throwable.getClass()
185:                                    .getName(), sMessageError);
186:                    //getServlet().log(sMessResource, p_Throwable);
187:                    Logger logger = Log.getLogger(Log.JONAS_ADMIN_PREFIX);
188:                    if (logger.isLoggable(BasicLevel.DEBUG)) {
189:                        logger.log(BasicLevel.DEBUG, sMessResource);
190:                    }
191:                    m_Errors.add("error.global", new ActionMessage(
192:                            "error.global.message", p_Throwable.getClass()
193:                                    .getName(), sMessageError));
194:                }
195:            }
196:
197:            /**
198:             * MBean <code>ObjectName</code> accessor.
199:             *
200:             * @param p_ObjectName Instance of ObjectName to access to MBean
201:             * @param ps_AttrName Attribute name of MBean
202:             * @return The value of attribute
203:             */
204:            protected String getStringAttribute(ObjectName p_ObjectName,
205:                    String ps_AttrName) {
206:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
207:                String s = (String) JonasManagementRepr.getAttribute(
208:                        p_ObjectName, ps_AttrName, pServer);
209:                return s;
210:            }
211:
212:            /**
213:             * MBean <code>ObjectName</code> accessor.
214:             *
215:             * @param p_ObjectName Instance of ObjectName to access to MBean
216:             * @param ps_AttrName Attribute name of MBean
217:             * @return The value of attribute
218:             */
219:            protected String[] getStringArrayAttribute(ObjectName p_ObjectName,
220:                    String ps_AttrName) {
221:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
222:                String[] s = (String[]) JonasManagementRepr.getAttribute(
223:                        p_ObjectName, ps_AttrName, pServer);
224:                return s;
225:            }
226:
227:            /**
228:             * MBean <code>ObjectName</code> accessor.
229:             *
230:             * @param p_ObjectName Instance of ObjectName to access to MBean
231:             * @param ps_AttrName Attribute name of MBean
232:             * @param p_Value Value to write
233:             */
234:            protected void setStringAttribute(ObjectName p_ObjectName,
235:                    String ps_AttrName, String p_Value) {
236:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
237:                JonasManagementRepr.setAttribute(p_ObjectName, ps_AttrName,
238:                        p_Value, pServer);
239:            }
240:
241:            /**
242:             * MBean <code>ObjectName</code> accessor.
243:             *
244:             * @param p_ObjectName Instance of ObjectName to access to MBean
245:             * @param ps_AttrName Attribute name of MBean
246:             * @return The value of attribute
247:             */
248:            protected int getIntegerAttribute(ObjectName p_ObjectName,
249:                    String ps_AttrName) {
250:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
251:                try {
252:                    Integer o = (Integer) JonasManagementRepr.getAttribute(
253:                            p_ObjectName, ps_AttrName, pServer);
254:                    return o.intValue();
255:                } catch (Exception e) {
256:                    // None
257:                }
258:                return 0;
259:            }
260:
261:            /**
262:             * MBean <code>ObjectName</code> accessor.
263:             *
264:             * @param p_ObjectName Instance of ObjectName to access to MBean
265:             * @param ps_AttrName Attribute name of MBean
266:             * @return The value of attribute
267:             */
268:            protected String toStringIntegerAttribute(ObjectName p_ObjectName,
269:                    String ps_AttrName) {
270:                String serverName = m_WhereAreYou.getCurrentJonasServerName();
271:                try {
272:                    Integer o = (Integer) JonasManagementRepr.getAttribute(
273:                            p_ObjectName, ps_AttrName, serverName);
274:                    return o.toString();
275:                } catch (Exception e) {
276:                    // None
277:                }
278:                return null;
279:            }
280:
281:            /**
282:             * MBean <code>ObjectName</code> accessor.
283:             *
284:             * @param p_ObjectName Instance of ObjectName to access to MBean
285:             * @param ps_AttrName Attribute name of MBean
286:             * @param p_Value Value to write
287:             */
288:            protected void setIntegerAttribute(ObjectName p_ObjectName,
289:                    String ps_AttrName, int p_Value) {
290:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
291:                JonasManagementRepr.setAttribute(p_ObjectName, ps_AttrName,
292:                        new Integer(p_Value), pServer);
293:            }
294:
295:            /**
296:             * MBean <code>ObjectName</code> accessor.
297:             *
298:             * @param p_ObjectName Instance of ObjectName to access to MBean
299:             * @param ps_AttrName Attribute name of MBean
300:             * @param p_Value Value to write
301:             */
302:            protected void setIntegerAttribute(ObjectName p_ObjectName,
303:                    String ps_AttrName, String p_Value) {
304:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
305:                if ((p_Value != null) && (p_Value.length() > 0)) {
306:                    JonasManagementRepr.setAttribute(p_ObjectName, ps_AttrName,
307:                            new Integer(p_Value), pServer);
308:                }
309:            }
310:
311:            /**
312:             * MBean <code>ObjectName</code> accessor.
313:             *
314:             * @param p_ObjectName Instance of ObjectName to access to MBean
315:             * @param ps_AttrName Attribute name of MBean
316:             * @return The value of attribute
317:             */
318:            protected long getLongAttribute(ObjectName p_ObjectName,
319:                    String ps_AttrName) {
320:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
321:                try {
322:                    Long o = (Long) JonasManagementRepr.getAttribute(
323:                            p_ObjectName, ps_AttrName, pServer);
324:                    return o.longValue();
325:                } catch (Exception e) {
326:                    // None
327:                }
328:                return 0;
329:            }
330:
331:            /**
332:             * MBean <code>ObjectName</code> accessor.
333:             *
334:             * @param p_ObjectName Instance of ObjectName to access to MBean
335:             * @param ps_AttrName Attribute name of MBean
336:             * @return The value of attribute
337:             */
338:            protected String toStringLongAttribute(ObjectName p_ObjectName,
339:                    String ps_AttrName) {
340:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
341:                try {
342:                    Long o = (Long) JonasManagementRepr.getAttribute(
343:                            p_ObjectName, ps_AttrName, pServer);
344:                    return o.toString();
345:                } catch (Exception e) {
346:                    // None
347:                }
348:                return null;
349:            }
350:
351:            /**
352:             * MBean <code>ObjectName</code> accessor.
353:             *
354:             * @param p_ObjectName Instance of ObjectName to access to MBean
355:             * @param ps_AttrName Attribute name of MBean
356:             * @param p_Value Value to write
357:             */
358:            protected void setLongAttribute(ObjectName p_ObjectName,
359:                    String ps_AttrName, long p_Value) {
360:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
361:                JonasManagementRepr.setAttribute(p_ObjectName, ps_AttrName,
362:                        new Long(p_Value), pServer);
363:            }
364:
365:            /**
366:             * MBean <code>ObjectName</code> accessor.
367:             *
368:             * @param p_ObjectName Instance of ObjectName to access to MBean
369:             * @param ps_AttrName Attribute name of MBean
370:             * @return The value of attribute
371:             */
372:            protected long getShortAttribute(ObjectName p_ObjectName,
373:                    String ps_AttrName) {
374:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
375:                try {
376:                    Short o = (Short) JonasManagementRepr.getAttribute(
377:                            p_ObjectName, ps_AttrName, pServer);
378:                    return o.longValue();
379:                } catch (Exception e) {
380:                    // None
381:                }
382:                return 0;
383:            }
384:
385:            /**
386:             * MBean <code>ObjectName</code> accessor.
387:             *
388:             * @param p_ObjectName Instance of ObjectName to access to MBean
389:             * @param ps_AttrName Attribute name of MBean
390:             * @return The value of attribute
391:             */
392:            protected String toStringShortAttribute(ObjectName p_ObjectName,
393:                    String ps_AttrName) {
394:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
395:                try {
396:                    Short o = (Short) JonasManagementRepr.getAttribute(
397:                            p_ObjectName, ps_AttrName, pServer);
398:                    return o.toString();
399:                } catch (Exception e) {
400:                    // None
401:                }
402:                return null;
403:            }
404:
405:            /**
406:             * MBean <code>ObjectName</code> accessor.
407:             *
408:             * @param p_ObjectName Instance of ObjectName to access to MBean
409:             * @param ps_AttrName Attribute name of MBean
410:             * @param p_Value Value to write
411:             */
412:            protected void setShortAttribute(ObjectName p_ObjectName,
413:                    String ps_AttrName, long p_Value) {
414:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
415:                JonasManagementRepr.setAttribute(p_ObjectName, ps_AttrName,
416:                        new Long(p_Value), pServer);
417:            }
418:
419:            /**
420:             * MBean <code>ObjectName</code> accessor.
421:             *
422:             * @param p_ObjectName Instance of ObjectName to access to MBean
423:             * @param ps_AttrName Attribute name of MBean
424:             * @return The value of attribute
425:             */
426:            protected boolean getBooleanAttribute(ObjectName p_ObjectName,
427:                    String ps_AttrName) {
428:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
429:                try {
430:                    Boolean o = (Boolean) JonasManagementRepr.getAttribute(
431:                            p_ObjectName, ps_AttrName, pServer);
432:                    return o.booleanValue();
433:                } catch (Exception e) {
434:                    // None
435:                }
436:                return false;
437:            }
438:
439:            /**
440:             * MBean <code>ObjectName</code> accessor.
441:             *
442:             * @param p_ObjectName Instance of ObjectName to access to MBean
443:             * @param ps_AttrName Attribute name of MBean
444:             * @return The value of attribute
445:             */
446:            protected String toStringBooleanAttribute(ObjectName p_ObjectName,
447:                    String ps_AttrName) {
448:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
449:                try {
450:                    Boolean o = (Boolean) JonasManagementRepr.getAttribute(
451:                            p_ObjectName, ps_AttrName, pServer);
452:                    return o.toString();
453:                } catch (Exception e) {
454:                    // None
455:                }
456:                return null;
457:            }
458:
459:            /**
460:             * MBean <code>ObjectName</code> accessor.
461:             *
462:             * @param p_ObjectName Instance of ObjectName to access to MBean
463:             * @param ps_AttrName Attribute name of MBean
464:             * @param p_Value Value to write
465:             */
466:            protected void setBooleanAttribute(ObjectName p_ObjectName,
467:                    String ps_AttrName, boolean p_Value) {
468:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
469:                JonasManagementRepr.setAttribute(p_ObjectName, ps_AttrName,
470:                        new Boolean(p_Value), pServer);
471:            }
472:
473:            /**
474:             * MBean <code>ObjectName</code> accessor.
475:             *
476:             * @param p_ObjectName Instance of ObjectName to access to MBean
477:             * @param ps_AttrName Attribute name of MBean
478:             * @return The value of attribute
479:             */
480:            protected List getListAttribute(ObjectName p_ObjectName,
481:                    String ps_AttrName) {
482:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
483:                try {
484:                    return ((List) JonasManagementRepr.getAttribute(
485:                            p_ObjectName, ps_AttrName, pServer));
486:                } catch (Exception e) {
487:                    // None
488:                }
489:                return new ArrayList();
490:            }
491:
492:            /**
493:             * Properties accessor.
494:             *
495:             * @param p_Props Instance of Properties
496:             * @param ps_AttrName Attribute name of Properties
497:             * @return The value of attribute
498:             */
499:            protected String getStringAttribute(Properties p_Props,
500:                    String ps_AttrName) {
501:                return p_Props.getProperty(ps_AttrName);
502:            }
503:
504:            /**
505:             * Properties accessor.
506:             *
507:             * @param p_Props Instance of Properties
508:             * @param ps_AttrName Attribute name of Properties
509:             * @param p_Default The returned value if the attribute don't exists in the properties
510:             * @return The value of attribute
511:             */
512:            protected String getStringAttribute(Properties p_Props,
513:                    String ps_AttrName, String p_Default) {
514:                return p_Props.getProperty(ps_AttrName, p_Default);
515:            }
516:
517:            /**
518:             * Properties accessor.
519:             *
520:             * @param p_Props Instance of Properties
521:             * @param ps_AttrName Attribute name of Properties
522:             * @param p_Value Value to write
523:             */
524:            protected void setStringAttribute(Properties p_Props,
525:                    String ps_AttrName, String p_Value) {
526:                if (p_Value != null) {
527:                    p_Props.setProperty(ps_AttrName, p_Value);
528:                }
529:            }
530:
531:            /**
532:             * Properties accessor.
533:             *
534:             * @param p_Props Instance of Properties
535:             * @param ps_AttrName Attribute name of Properties
536:             * @param p_Value Value to write
537:             * @param p_Default The forced value if the value is null or empty
538:             */
539:            protected void setStringAttribute(Properties p_Props,
540:                    String ps_AttrName, String p_Value, String p_Default) {
541:                if ((p_Value != null) && (p_Value.length() == 0)) {
542:                    p_Props.setProperty(ps_AttrName, p_Default);
543:                } else {
544:                    p_Props.setProperty(ps_AttrName, p_Value);
545:                }
546:            }
547:
548:            /**
549:             * Properties accessor.
550:             *
551:             * @param p_Props Instance of Properties
552:             * @param ps_AttrName Attribute name of Properties
553:             * @return The value of attribute (return 0 if attribute don't exists)
554:             */
555:            protected int getIntegerAttribute(Properties p_Props,
556:                    String ps_AttrName) {
557:                return getIntegerAttribute(p_Props, ps_AttrName, 0);
558:            }
559:
560:            /**
561:             * Properties accessor.
562:             *
563:             * @param p_Props Instance of Properties
564:             * @param ps_AttrName Attribute name of Properties
565:             * @param p_Default The returned value if the attribute don't exists in the properties
566:             * @return The value of attribute
567:             */
568:            protected int getIntegerAttribute(Properties p_Props,
569:                    String ps_AttrName, int p_Default) {
570:                try {
571:                    String s = getStringAttribute(p_Props, ps_AttrName);
572:                    if (s != null) {
573:                        return Integer.parseInt(s);
574:                    }
575:                } catch (Exception e) {
576:                    // None
577:                }
578:                return p_Default;
579:            }
580:
581:            /**
582:             * Properties accessor.
583:             *
584:             * @param p_Props Instance of Properties
585:             * @param ps_AttrName Attribute name of Properties
586:             * @param p_Value Value to write
587:             */
588:            protected void setIntegerAttribute(Properties p_Props,
589:                    String ps_AttrName, int p_Value) {
590:                p_Props.setProperty(ps_AttrName, String.valueOf(p_Value));
591:            }
592:
593:            /**
594:             * Properties accessor.
595:             *
596:             * @param p_Props Instance of Properties
597:             * @param ps_AttrName Attribute name of Properties
598:             * @return The value of attribute (return 0 if attribute don't exists)
599:             */
600:            protected long getLongAttribute(Properties p_Props,
601:                    String ps_AttrName) {
602:                return getLongAttribute(p_Props, ps_AttrName, 0L);
603:            }
604:
605:            /**
606:             * Properties accessor.
607:             *
608:             * @param p_Props Instance of Properties
609:             * @param ps_AttrName Attribute name of Properties
610:             * @param p_Default The returned value if the attribute don't exists in the properties
611:             * @return The value of attribute
612:             */
613:            protected long getLongAttribute(Properties p_Props,
614:                    String ps_AttrName, long p_Default) {
615:                try {
616:                    String s = getStringAttribute(p_Props, ps_AttrName);
617:                    if (s != null) {
618:                        return Long.parseLong(s);
619:                    }
620:                } catch (Exception e) {
621:                    // None
622:                }
623:                return p_Default;
624:            }
625:
626:            /**
627:             * Properties accessor.
628:             *
629:             * @param p_Props Instance of Properties
630:             * @param ps_AttrName Attribute name of Properties
631:             * @param p_Value Value to write
632:             */
633:            protected void setLongAttribute(Properties p_Props,
634:                    String ps_AttrName, long p_Value) {
635:                p_Props.setProperty(ps_AttrName, String.valueOf(p_Value));
636:            }
637:
638:            /**
639:             * Properties accessor.
640:             *
641:             * @param p_Props Instance of Properties
642:             * @param ps_AttrName Attribute name of Properties
643:             * @return The value of attribute (return false if attribute don't exists)
644:             */
645:            protected boolean getBooleanAttribute(Properties p_Props,
646:                    String ps_AttrName) {
647:                return getBooleanAttribute(p_Props, ps_AttrName, false);
648:            }
649:
650:            /**
651:             * Properties accessor.
652:             *
653:             * @param p_Props Instance of Properties
654:             * @param ps_AttrName Attribute name of Properties
655:             * @param p_Default The returned value if the attribute don't exists in the properties
656:             * @return The value of attribute
657:             */
658:            protected boolean getBooleanAttribute(Properties p_Props,
659:                    String ps_AttrName, boolean p_Default) {
660:                try {
661:                    String s = getStringAttribute(p_Props, ps_AttrName);
662:                    if (s != null) {
663:                        return Boolean.getBoolean(s);
664:                    }
665:                } catch (Exception e) {
666:                    // None
667:                }
668:                return p_Default;
669:            }
670:
671:            /**
672:             * Properties accessor.
673:             *
674:             * @param p_Props Instance of Properties
675:             * @param ps_AttrName Attribute name of Properties
676:             * @param p_Value Value to write
677:             */
678:            protected void setBooleanAttribute(Properties p_Props,
679:                    String ps_AttrName, boolean p_Value) {
680:                p_Props.setProperty(ps_AttrName, String.valueOf(p_Value));
681:            }
682:
683:            protected Properties getPropsFromString(String ps_Props) {
684:                // Clean the string
685:                String sProps = ps_Props.trim();
686:                sProps = removeChar(sProps, '\r');
687:                sProps = removeChar(sProps, '\n');
688:                Properties sp = new Properties();
689:                StringTokenizer st = new StringTokenizer(sProps, ",");
690:                while (st.hasMoreTokens()) {
691:                    String token = st.nextToken();
692:                    int pos = token.indexOf("=");
693:                    String propName = token.substring(0, pos);
694:                    String propValue = token.substring(pos + 1);
695:                    sp.setProperty(propName, propValue);
696:                }
697:                return sp;
698:            }
699:
700:            /**
701:             * Remove a specific character in a String
702:             * Do not use replaceAll as it is a JDK 1.4 method
703:             * @param string the given string
704:             * @param c character to remove in the String
705:             * @return a string
706:             */
707:            protected static String removeChar(String string, char c) {
708:                StringBuffer sb = new StringBuffer();
709:                sb.setLength(string.length());
710:                int i = 0;
711:                for (int j = 0; j < string.length(); j++) {
712:                    char cur = string.charAt(j);
713:                    if (cur != c) {
714:                        sb.setCharAt(i++, cur);
715:                    }
716:                }
717:                return sb.toString();
718:            }
719:
720:            /**
721:             * Refresh the management tree.
722:             *
723:             * @throws Exception
724:             */
725:            protected void refreshServerTree(HttpServletRequest p_Request)
726:                    throws Exception {
727:                // Get current tree
728:                TreeControl oControl = m_WhereAreYou.getTreeControl();
729:                // tree root
730:                TreeControlNode root = oControl.getRoot();
731:                // domain node
732:                TreeControlNode domainNode = oControl.findNode("domain");
733:                if (domainNode != null) {
734:                    // Enable auto-refresh mode
735:                    oControl.enableAutoRefresh();
736:                    // Remove node
737:                    domainNode.remove();
738:                    // Build node and his children
739:                    JonasTreeBuilder oBuilder = new JonasTreeBuilder();
740:                    oBuilder.getDomain(root, m_Resources, p_Request);
741:                    // Disable auto-refresh mode
742:                    oControl.disableAutoRefresh();
743:                }
744:            }
745:
746:            /**
747:             * Refresh the domain deployment nodes of the tree.
748:             * @param p_Request
749:             * @throws Exception
750:             */
751:            protected void refreshDomainDeployTree(HttpServletRequest p_Request)
752:                    throws Exception {
753:                // Get current tree
754:                TreeControl oControl = m_WhereAreYou.getTreeControl();
755:                TreeControlNode domainNode = oControl.findNode("domain");
756:                if (domainNode != null) {
757:                    // Enable auto-refresh mode
758:                    oControl.enableAutoRefresh();
759:                    // Remove node
760:                    // Build node and his children
761:                    JonasTreeBuilder oBuilder = new JonasTreeBuilder();
762:                    oBuilder.getDomainDeploy(oControl.findNode("domain"),
763:                            m_Resources, p_Request);
764:                    // Disable auto-refresh mode
765:                    oControl.disableAutoRefresh();
766:                }
767:
768:            }
769:
770:            /**
771:             * Refresh the domain monitoring nodes of the tree.
772:             * @param p_Request
773:             * @throws Exception
774:             */
775:            protected void refreshDomainMonitoringTree(
776:                    HttpServletRequest p_Request) throws Exception {
777:                // Get current tree
778:                TreeControl oControl = m_WhereAreYou.getTreeControl();
779:                String domainName = m_WhereAreYou.getCurrentDomainName();
780:                String serverName = m_WhereAreYou.getCurrentJonasServerName();
781:                TreeControlNode domainNode = oControl.findNode("domain");
782:                if (domainNode != null) {
783:                    // Enable auto-refresh mode
784:                    oControl.enableAutoRefresh();
785:                    // Remove node
786:                    // Build node and his children
787:                    JonasTreeBuilder oBuilder = new JonasTreeBuilder();
788:                    oBuilder.getMonitoring(oControl.findNode("domain"),
789:                            m_Resources, p_Request, domainName, serverName);
790:                    // Disable auto-refresh mode
791:                    oControl.disableAutoRefresh();
792:                }
793:
794:            }
795:
796:            /**
797:             *
798:             * @return the current server's JONAS_BASE
799:             */
800:            protected String getJonasBase() {
801:                String pDomain = m_WhereAreYou.getCurrentDomainName();
802:                String pServer = m_WhereAreYou.getCurrentJonasServerName();
803:                ObjectName j2eeServerOn = J2eeObjectName.J2EEServer(pDomain,
804:                        pServer);
805:                String jonasBase = getStringAttribute(j2eeServerOn, "jonasBase");
806:                if (!jonasBase.endsWith(File.separator)) {
807:                    jonasBase = jonasBase.concat(File.separator);
808:                }
809:                return jonasBase;
810:            }
811:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.