Source Code Cross Referenced for AdminUtil.java in  » Portal » Open-Portal » com » sun » portal » admin » common » util » 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 » Portal » Open Portal » com.sun.portal.admin.common.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: AdminUtil.java,v 1.31 2007/01/26 03:47:10 portalbld Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.admin.common.util;
014:
015:        import java.io.IOException;
016:        import java.io.File;
017:        import java.io.FileInputStream;
018:        import java.net.InetAddress;
019:        import java.net.NetworkInterface;
020:        import java.net.SocketException;
021:        import java.net.UnknownHostException;
022:        import java.util.Collections;
023:        import java.util.Enumeration;
024:        import java.util.HashMap;
025:        import java.util.Hashtable;
026:        import java.util.LinkedList;
027:        import java.util.List;
028:        import java.util.Map;
029:        import java.util.NoSuchElementException;
030:        import java.util.Properties;
031:        import java.util.StringTokenizer;
032:        import java.util.logging.Logger;
033:
034:        import javax.management.MalformedObjectNameException;
035:        import javax.management.ObjectName;
036:        import javax.management.remote.JMXConnector;
037:        import javax.management.remote.JMXConnectorFactory;
038:        import javax.management.remote.JMXServiceURL;
039:        import javax.net.ssl.TrustManager;
040:        import javax.xml.bind.JAXBContext;
041:        import javax.xml.bind.Unmarshaller;
042:
043:        import com.sun.cacao.agent.JmxClient;
044:        import com.sun.portal.admin.common.context.PSConfigContext;
045:        import com.sun.portal.admin.common.context.PSConfigContextImpl;
046:        import com.sun.portal.admin.common.context.PortalDomainContext;
047:        import com.sun.portal.admin.common.context.PortalDomainContextFactory;
048:        import com.sun.portal.util.Platform;
049:
050:        /**
051:         * This class provides misc. utility methods for Portal Admin Server
052:         * clients and MBeans.
053:         */
054:        public class AdminUtil {
055:
056:            /**
057:             * The JMX domain used by Portal Admin Server.
058:             */
059:            public static final String JMX_DOMAIN = "com.sun.portal";
060:
061:            /**
062:             * The ID of the default portal domain.
063:             */
064:            public static final String DEFAULT_DOMAIN = "defaultDomain";
065:
066:            /**
067:             * The ID of the default portal.
068:             */
069:            public static final String DEFAULT_PORTAL = "defaultPortal";
070:
071:            /**
072:             * The ID of the an upgraded (jes3 or earlier) portal.
073:             */
074:            public static final String UPGRADED_PORTAL = "Upgraded";
075:
076:            /**
077:             * The ID of the default portal server instance.
078:             */
079:            public static final String DEFAULT_INSTANCE = "defaultInstance";
080:
081:            // Keys used in the portal MBean ObjectNames
082:            public static final String KEY_TYPE = "type";
083:            public static final String KEY_ID = "name";
084:
085:            // MBean Names
086:            public static final String PORTAL_DOMAIN_MBEAN = "PortalDomain";
087:            public static final String AMOBJECTSEARCH_MBEAN = "AMObjectSearch";
088:            public static final String SSOADAPTER_MBEAN = "SSOAdapter";
089:            public static final String SCHEDULER_MBEAN = "Scheduler";
090:            public static final String PORTAL_MBEAN = "Portal";
091:            public static final String DESKTOP_DYNAMIC_MBEAN = "DesktopDynamic";
092:            public static final String PORTAL_SERVER_INSTANCE_MBEAN = "ServerInstance";
093:            public static final String DISPLAYPROFILE_MBEAN = "DisplayProfile";
094:            public static final String DPADMINWRAPPER_MBEAN = "DPAdminWrapper";
095:            public static final String MONITORING_MBEAN = "Monitoring";
096:            public static final String PORTLET_ADMIN_MBEAN = "PortletAdmin";
097:            public static final String SRA_MBEAN = "SRA";
098:            public static final String REWRITER_MBEAN = "Rewriter";
099:            public static final String SRA_MONITORING_MBEAN = "SRAMonitoring";
100:
101:            public static final String SEARCHSERVER_MBEAN = "SearchServer";
102:            public static final String SEARCH_DATABASE_MBEAN = "Database";
103:            public static final String SEARCH_ROBOT_MBEAN = "Robot";
104:            public static final String SEARCH_SITEPROBE_MBEAN = "SiteProbe";
105:            public static final String SEARCH_AUTOCLASSIFY_MBEAN = "Autoclassify";
106:            public static final String SEARCH_CATEGORY_MBEAN = "Category";
107:            public static final String PROFILER_MBEAN = "Profiler";
108:            public static final String COMMUNITYMANAGER_MBEAN = "CommunityManager";
109:            public static final String FILE_UPLOAD_DOWNLOAD_MANAGER = "UploadDownloadFileManager";
110:
111:            // The MBeans/resource types of the portal fabric MBeans.
112:            public static final String PORTAL_DOMAIN_MBEAN_TYPE = PORTAL_DOMAIN_MBEAN;
113:            public static final String SEARCHSERVER_MBEAN_TYPE = PORTAL_DOMAIN_MBEAN_TYPE
114:                    + "." + SEARCHSERVER_MBEAN;
115:            public static final String FILE_UPLOAD_DOWNLOAD_MANAGER_MBEAN_TYPE = PORTAL_DOMAIN_MBEAN_TYPE
116:                    + "." + FILE_UPLOAD_DOWNLOAD_MANAGER;
117:            public static final String AMOBJECTSEARCH_MBEAN_TYPE = PORTAL_DOMAIN_MBEAN_TYPE
118:                    + "." + AMOBJECTSEARCH_MBEAN;
119:            public static final String SSOADAPTER_MBEAN_TYPE = PORTAL_DOMAIN_MBEAN_TYPE
120:                    + "." + SSOADAPTER_MBEAN;
121:            public static final String SCHEDULER_MBEAN_TYPE = PORTAL_DOMAIN_MBEAN_TYPE
122:                    + "." + SCHEDULER_MBEAN;
123:            public static final String PORTAL_MBEAN_TYPE = PORTAL_DOMAIN_MBEAN_TYPE
124:                    + "." + PORTAL_MBEAN;
125:            public static final String PORTAL_SERVER_INSTANCE_MBEAN_TYPE = PORTAL_MBEAN_TYPE
126:                    + "." + PORTAL_SERVER_INSTANCE_MBEAN;
127:            public static final String DESKTOP_DYNAMIC_MBEAN_TYPE = PORTAL_MBEAN_TYPE
128:                    + "." + DESKTOP_DYNAMIC_MBEAN;
129:            public static final String DISPLAYPROFILE_MBEAN_TYPE = PORTAL_MBEAN_TYPE
130:                    + "." + DISPLAYPROFILE_MBEAN;
131:            public static final String DPADMINWRAPPER_MBEAN_TYPE = PORTAL_MBEAN_TYPE
132:                    + "." + DPADMINWRAPPER_MBEAN;
133:            public static final String PORTLET_ADMIN_MBEAN_TYPE = PORTAL_MBEAN_TYPE
134:                    + "." + PORTLET_ADMIN_MBEAN;
135:            public static final String MONITORING_MBEAN_TYPE = PORTAL_SERVER_INSTANCE_MBEAN_TYPE
136:                    + "." + MONITORING_MBEAN;
137:            public static final String SRA_MBEAN_TYPE = PORTAL_DOMAIN_MBEAN_TYPE
138:                    + "." + SRA_MBEAN;
139:            public static final String REWRITER_MBEAN_TYPE = PORTAL_DOMAIN_MBEAN_TYPE
140:                    + "." + REWRITER_MBEAN;
141:            public static final String SRA_MONITORING_MBEAN_TYPE = PORTAL_DOMAIN_MBEAN_TYPE
142:                    + "." + SRA_MONITORING_MBEAN;
143:
144:            public static final String SEARCH_DATABASE_MBEAN_TYPE = SEARCHSERVER_MBEAN_TYPE
145:                    + "." + SEARCH_DATABASE_MBEAN;
146:            public static final String SEARCH_ROBOT_MBEAN_TYPE = SEARCHSERVER_MBEAN_TYPE
147:                    + "." + SEARCH_ROBOT_MBEAN;
148:            public static final String SEARCH_SITEPROBE_MBEAN_TYPE = SEARCHSERVER_MBEAN_TYPE
149:                    + "." + SEARCH_SITEPROBE_MBEAN;
150:            public static final String SEARCH_AUTOCLASSIFY_MBEAN_TYPE = SEARCHSERVER_MBEAN_TYPE
151:                    + "." + SEARCH_AUTOCLASSIFY_MBEAN;
152:            public static final String SEARCH_CATEGORY_MBEAN_TYPE = SEARCHSERVER_MBEAN_TYPE
153:                    + "." + SEARCH_CATEGORY_MBEAN;
154:            public static final String PROFILER_MBEAN_TYPE = PORTAL_MBEAN_TYPE
155:                    + "." + PROFILER_MBEAN;
156:            public static final String COMMUNITYMANAGER_MBEAN_TYPE = PORTAL_MBEAN_TYPE
157:                    + "." + COMMUNITYMANAGER_MBEAN;
158:
159:            public static final int DEFAULT_UPLOAD_SIZE = 4096;
160:            public static final int DEFAULT_DOWNLOAD_SIZE = 4096;
161:
162:            private static String cacaoConfigDir = null;
163:            private static TrustManager[] tms = null;
164:
165:            /**
166:             * Returns the MBean/resource type of the parent of the
167:             * MBean/resource with the given type.  A Portal Server
168:             * MBean/resource type has the form "aaa.bbb.ccc".  In this case
169:             * "aaa.bbb" is returned.
170:             *
171:             * @param  type  the type of the MBean/resource whose parent
172:             *               MBean/resource type is to be returned.
173:             * @return the MBean/resource type of the parent;
174:             *         <code>null</code> if the given MBean/resource has no
175:             *         parent, e.g. PortalDomain.
176:             * @exception NullPointerException if type is <code>null</code>.
177:             */
178:            public static String getParentType(String type) {
179:                if (type == null) {
180:                    throw new NullPointerException("type is null.");
181:                }
182:
183:                int index = type.lastIndexOf(".");
184:                return (index >= 0) ? type.substring(0, index) : null;
185:            }
186:
187:            /**
188:             * Returns the full path of a portal server resource instance
189:             * given the full path of its parent and its ID.
190:             *
191:             * @param  parentPath  the full path of the parent resource instance.
192:             * @param  childID  the ID of the resource instance.
193:             * @return the full path of the portal server resource instance.
194:             * @exception NullPointerException if parentPath or childID is
195:             *                                 <code>null</code>.
196:             */
197:            public static List getChildPath(List parentPath, String childID) {
198:                if (parentPath == null) {
199:                    throw new NullPointerException("parentPath is null.");
200:                }
201:
202:                if (childID == null) {
203:                    throw new NullPointerException("childID is null.");
204:                }
205:
206:                LinkedList childPath = new LinkedList(parentPath);
207:                childPath.addFirst(childID);
208:                return childPath;
209:            }
210:
211:            /**
212:             * Returns the ObjectName pattern to search for the portal
213:             * resource MBeans of the given MBean/resource type under a parent
214:             * resource instance with the given path.  The returned value can
215:             * be used in <code>MBeanServerConnection.queryMBeans()</code> or
216:             * <code>MBeanServerConnection.queryNames()</code> to obtain the
217:             * portal resource MBeans.
218:             *
219:             * @param  type  the type of the MBeans to be searched.
220:             * @param  parentPath  the full path of the parent resource instance.
221:             * @return an ObjectName pattern.
222:             * @exception NullPointerException if type or parentPath is
223:             *                                 <code>null</code>.
224:             * @exception IllegalArgumentException if type and parentPath's
225:             *                                     length are inconsistent.
226:             * @exception MalformedObjectNameException if type or any element
227:             *                                         in parentPath contains
228:             *                                         an illegal character or
229:             *                                         if it does not follow
230:             *                                         the rules for quoting.
231:             */
232:            public static ObjectName getResourcesPattern(String type,
233:                    List parentPath) throws MalformedObjectNameException {
234:
235:                if (type == null) {
236:                    throw new NullPointerException("type is null.");
237:                }
238:
239:                if (parentPath == null) {
240:                    throw new NullPointerException("parentPath is null.");
241:                }
242:
243:                StringBuffer name = new StringBuffer(JMX_DOMAIN);
244:                name.append(":");
245:                name.append(KEY_TYPE + "=" + type);
246:                StringTokenizer st = new StringTokenizer(type, ".");
247:
248:                if (st.countTokens() != (parentPath.size() + 1)) {
249:                    String message = "type is inconsistent with parentPath's length.";
250:                    throw new IllegalArgumentException(message);
251:                }
252:
253:                for (int i = parentPath.size() - 1; i >= 0; i--) {
254:                    name.append(",");
255:                    String resourceID = (String) parentPath.get(i);
256:                    name
257:                            .append(st.nextToken() + "="
258:                                    + resourceID.toLowerCase());
259:                }
260:
261:                name.append(",*");
262:                return new ObjectName(name.toString());
263:            }
264:
265:            /**
266:             * Returns the ObjectName pattern to search for all the portal
267:             * resource MBeans, regardless of MBean/resource type, under a
268:             * parent MBean with the given type and path.  The returned value
269:             * can be used in <code>MBeanServerConnection.queryMBeans()</code>
270:             * or <code>MBeanServerConnection.queryNames()</code> to obtain
271:             * the portal resource MBeans.
272:             *
273:             * @param  parentType  the type of the parent resource instance.
274:             * @param  parentPath  the full path of the parent resource instance.
275:             * @return an ObjectName pattern.
276:             * @exception NullPointerException if parentType or parentPath is
277:             *                                 <code>null</code>.
278:             * @exception IllegalArgumentException if parentType and parentPath's
279:             *                                     length are inconsistent.
280:             * @exception MalformedObjectNameException if parentType or any element
281:             *                                         in parentPath contains
282:             *                                         an illegal character or
283:             *                                         if it does not follow
284:             *                                         the rules for quoting.
285:             */
286:            public static ObjectName getAllResourcesPattern(String parentType,
287:                    List parentPath) throws MalformedObjectNameException {
288:
289:                if (parentType == null) {
290:                    throw new NullPointerException("parentType is null.");
291:                }
292:
293:                if (parentPath == null) {
294:                    throw new NullPointerException("parentPath is null.");
295:                }
296:
297:                StringBuffer name = new StringBuffer(JMX_DOMAIN);
298:                name.append(":");
299:                StringTokenizer st = new StringTokenizer(parentType, ".");
300:
301:                if (st.countTokens() != parentPath.size()) {
302:                    String message = "parentType is inconsistent with parentPath's length.";
303:                    throw new IllegalArgumentException(message);
304:                }
305:
306:                for (int i = parentPath.size() - 1; i >= 0; i--) {
307:                    String resourceID = (String) parentPath.get(i);
308:                    name
309:                            .append(st.nextToken() + "="
310:                                    + resourceID.toLowerCase());
311:                    name.append(",");
312:                }
313:
314:                name.append("*");
315:                return new ObjectName(name.toString());
316:            }
317:
318:            /**
319:             * Returns the ObjectName of the portal resource MBean of the
320:             * given MBean/resource type and with the given path.
321:             *
322:             * @param  type  MBean/resource type of the portal resource MBean.
323:             * @param  path  the full portal resource identification path.
324:             *               For example, it is {domainID} for
325:             *               <code>PortalDomain</code>, {portalID, domainID}
326:             *               for <code>PortalDomain.Portal</code>, and
327:             *               {instanceID, portalID, domainID} for
328:             *               <code>PortalDomain.Portal.ServerInstance</code>.
329:             * @return the ObjectName of the portal resource MBean.
330:             * @exception NullPointerException if type or path is <code>null</code>.
331:             * @exception IllegalArgumentException if path is empty or type
332:             *                                     and path's length are inconsistent.
333:             * @exception MalformedObjectNameException if type or any element
334:             *                                         in path contains an
335:             *                                         illegal character or
336:             *                                         if it does not follow
337:             *                                         the rules for quoting.
338:             */
339:            public static ObjectName getResourceMBeanObjectName(String type,
340:                    List path) throws MalformedObjectNameException {
341:
342:                if (type == null) {
343:                    throw new NullPointerException("type is null.");
344:                }
345:
346:                if (path == null) {
347:                    throw new NullPointerException("path is null.");
348:                }
349:
350:                if (path.isEmpty()) {
351:                    throw new IllegalArgumentException("path cannot be empty.");
352:                }
353:
354:                Hashtable keyProperties = new Hashtable();
355:                keyProperties.put(KEY_TYPE, type);
356:                String resourceID = (String) path.get(0);
357:                keyProperties.put(KEY_ID, resourceID.toLowerCase());
358:                StringTokenizer st = new StringTokenizer(type, ".");
359:
360:                if (st.countTokens() != path.size()) {
361:                    String message = "type is inconsistent with path's length.";
362:                    throw new IllegalArgumentException(message);
363:                }
364:
365:                for (int i = path.size() - 1; i > 0; i--) {
366:                    resourceID = (String) path.get(i);
367:                    keyProperties.put(st.nextToken(), resourceID.toLowerCase());
368:                }
369:
370:                return new ObjectName(JMX_DOMAIN, keyProperties);
371:            }
372:
373:            /**
374:             * Returns the ObjectName pattern to search for the portal
375:             * domains.  The returned value can be used in
376:             * <code>MBeanServerConnection.queryMBeans()</code> or
377:             * <code>MBeanServerConnection.queryNames()</code> to obtain the
378:             * PortalDomainMBeans
379:             *
380:             * @return an ObjectName pattern.
381:             */
382:            public static ObjectName getPortalDomainsPattern()
383:                    throws MalformedObjectNameException {
384:
385:                return getResourcesPattern(PORTAL_DOMAIN_MBEAN_TYPE,
386:                        Collections.EMPTY_LIST);
387:            }
388:
389:            /**
390:             * Returns the ObjectName of the PortalDomainMBean with the given
391:             * portal domain ID.
392:             *
393:             * @param  domainID  portal domain ID of the PortalDomainMBean.
394:             * @return the ObjectName of the PortalDomainMBean.
395:             * @exception NullPointerException if domainID is <code>null</code>.
396:             * @exception MalformedObjectNameException if domainID contains an
397:             *                                         illegal character or if
398:             *                                         it does not follow the
399:             *                                         rules for quoting.
400:             */
401:            public static ObjectName getPortalDomainMBeanObjectName(
402:                    String domainID) throws MalformedObjectNameException {
403:
404:                if (domainID == null) {
405:                    throw new NullPointerException("domainID is null.");
406:                }
407:
408:                return getResourceMBeanObjectName(PORTAL_DOMAIN_MBEAN_TYPE,
409:                        Collections.singletonList(domainID));
410:            }
411:
412:            /**
413:             * Returns the ObjectName pattern to search for the portals in the
414:             * portal domain with the given ID.  The returned value can be
415:             * used in <code>MBeanServerConnection.queryMBeans()</code> or
416:             * <code>MBeanServerConnection.queryNames()</code> to obtain the
417:             * PortalMBeans in the portal domain with the given ID.
418:             *
419:             * @param  domainID  domain ID of the portal domain.
420:             * @return an ObjectName pattern.
421:             * @exception NullPointerException if domainID is <code>null</code>.
422:             * @exception MalformedObjectNameException if domainID contains an
423:             *                                         illegal character or if
424:             *                                         it does not follow the
425:             *                                         rules for quoting.
426:             */
427:            public static ObjectName getPortalsPattern(String domainID)
428:                    throws MalformedObjectNameException {
429:
430:                if (domainID == null) {
431:                    throw new NullPointerException("domainID is null.");
432:                }
433:
434:                return getResourcesPattern(PORTAL_MBEAN_TYPE, Collections
435:                        .singletonList(domainID));
436:            }
437:
438:            /**
439:             * Returns the ObjectName pattern to search for the searchserver in the
440:             * portal domain with the given ID.  The returned value can be
441:             * used in <code>MBeanServerConnection.queryMBeans()</code> or
442:             * <code>MBeanServerConnection.queryNames()</code> to obtain the
443:             * PortalMBeans in the portal domain with the given ID.
444:             *
445:             * @param  domainID  domain ID of the portal domain.
446:             * @return an ObjectName pattern.
447:             * @exception NullPointerException if domainID is <code>null</code>.
448:             * @exception MalformedObjectNameException if domainID contains an
449:             *                                         illegal character or if
450:             *                                         it does not follow the
451:             *                                         rules for quoting.
452:             */
453:            public static ObjectName getSearchServerPattern(String domainID)
454:                    throws MalformedObjectNameException {
455:                if (domainID == null) {
456:                    throw new NullPointerException("domainID is null.");
457:                }
458:
459:                return getResourcesPattern(SEARCHSERVER_MBEAN_TYPE, Collections
460:                        .singletonList(domainID));
461:            }
462:
463:            /**
464:             * Returns the ObjectName pattern to search for the search database
465:             * in the portal domain with the given ID. The returned value can be
466:             * used in <code>MBeanServerConnection.queryMBeans()</code> or
467:             * <code>MBeanServerConnection.queryNames()</code> to obtain the
468:             * PortalMBeans in the portal domain with the given ID.
469:             *
470:             * @param  domainID  domain ID of the portal domain.
471:             * @param  searchserverID  search server ID.
472:             * @return an ObjectName pattern.
473:             * @exception NullPointerException if domainID is <code>null</code>.
474:             * @exception MalformedObjectNameException if domainID contains an
475:             *                                         illegal character or if
476:             *                                         it does not follow the
477:             *                                         rules for quoting.
478:             */
479:            public static ObjectName getSearchDatabasePattern(String domainID,
480:                    String searchServerID) throws MalformedObjectNameException {
481:                if (domainID == null) {
482:                    throw new NullPointerException("domainID is null.");
483:                }
484:                if (searchServerID == null) {
485:                    throw new NullPointerException("searchServerID is null.");
486:                }
487:
488:                LinkedList path = new LinkedList();
489:                path.addFirst(domainID);
490:                path.addFirst(searchServerID);
491:                return getResourcesPattern(SEARCH_DATABASE_MBEAN_TYPE, path);
492:            }
493:
494:            /**
495:             * Returns the ObjectName of the PortalMBean with the given portal
496:             * ID and is in the portal domain with the given domain ID.
497:             *
498:             * @param  domainID  domain ID of the portal domain.
499:             * @param  portalID  portal ID of the PortalMBean.
500:             * @return the ObjectName of the PortalMBean.
501:             * @exception NullPointerException if domainID or portalID is
502:             *                                 <code>null</code>.
503:             * @exception MalformedObjectNameException if domainID or portalID
504:             *                                         contains an illegal
505:             *                                         character or if it does
506:             *                                         not follow the rules
507:             *                                         for quoting.
508:             */
509:            public static ObjectName getPortalMBeanObjectName(String domainID,
510:                    String portalID) throws MalformedObjectNameException {
511:
512:                if (domainID == null) {
513:                    throw new NullPointerException("domainID is null.");
514:                }
515:
516:                if (portalID == null) {
517:                    throw new NullPointerException("portalID is null.");
518:                }
519:
520:                LinkedList path = new LinkedList();
521:                path.addFirst(domainID);
522:                path.addFirst(portalID);
523:                return getResourceMBeanObjectName(PORTAL_MBEAN_TYPE, path);
524:            }
525:
526:            /**
527:             * Returns the ObjectName pattern to search for the portal server
528:             * instances in the portal with the given portal ID and in the
529:             * portal domain with the given domain ID.  The returned value can
530:             * be used in <code>MBeanServerConnection.queryMBeans()</code> or
531:             * <code>MBeanServerConnection.queryNames()</code> to obtain the
532:             * PortalServerInstanceMBeans in the portal with the given portal
533:             * ID and in the portal domain with the given domain ID.
534:             *
535:             * @param  domainID  domain ID of the portal domain.
536:             * @param  portalID  portal ID of the portal.
537:             * @return an ObjectName pattern.
538:             * @exception NullPointerException if domainID or portalID is
539:             *                                 <code>null</code>.
540:             * @exception MalformedObjectNameException if domainID or portalID
541:             *                                         contains an illegal
542:             *                                         character or if it does
543:             *                                         not follow the rules
544:             *                                         for quoting.
545:             */
546:            public static ObjectName getPortalServerInstancesPattern(
547:                    String domainID, String portalID)
548:                    throws MalformedObjectNameException {
549:
550:                if (domainID == null) {
551:                    throw new NullPointerException("domainID is null.");
552:                }
553:
554:                if (portalID == null) {
555:                    throw new NullPointerException("portalID is null.");
556:                }
557:
558:                LinkedList path = new LinkedList();
559:                path.addFirst(domainID);
560:                path.addFirst(portalID);
561:                return getResourcesPattern(PORTAL_SERVER_INSTANCE_MBEAN_TYPE,
562:                        path);
563:            }
564:
565:            /**
566:             * Returns the ObjectName of the PortalServerInstanceMBean with
567:             * the given instance ID and is in the portal with the given
568:             * portal ID and in the portal domain with the given domain ID.
569:             *
570:             * @param  domainID  domain ID of the portal domain.
571:             * @param  portalID  portal ID of the portal.
572:             * @param  instanceID  instance ID of the PortalServerInstanceMBean.
573:             * @return the ObjectName of the PortalServerInstanceMBean.
574:             * @exception NullPointerException if domainID, portalID or
575:             *                                 instanceID is <code>null</code>.
576:             * @exception MalformedObjectNameException if domainID, portalID
577:             *                                         or instanceID contains
578:             *                                         an illegal character or
579:             *                                         if it does not follow
580:             *                                         the rules for quoting.
581:             */
582:            public static ObjectName getInstanceMBeanObjectName(
583:                    String domainID, String portalID, String instanceID)
584:                    throws MalformedObjectNameException {
585:
586:                if (domainID == null) {
587:                    throw new NullPointerException("domainID is null.");
588:                }
589:
590:                if (portalID == null) {
591:                    throw new NullPointerException("portalID is null.");
592:                }
593:
594:                if (instanceID == null) {
595:                    throw new NullPointerException("instanceID is null.");
596:                }
597:
598:                LinkedList path = new LinkedList();
599:                path.addFirst(domainID);
600:                path.addFirst(portalID);
601:                path.addFirst(instanceID);
602:
603:                return getResourceMBeanObjectName(
604:                        PORTAL_SERVER_INSTANCE_MBEAN_TYPE, path);
605:            }
606:
607:            /**
608:             * Returns the ObjectName of the DisplayProfileMBean for the given portalId
609:             * and is in the portal domain with the given domain ID.
610:             *
611:             * @param  domainID  domain ID of the portal domain.
612:             * @param  portalID  portal ID of the PortalMBean.
613:             * @return the ObjectName of the PortalMBean.
614:             * @exception NullPointerException if domainID or portalID is
615:             *                                 <code>null</code>.
616:             * @exception MalformedObjectNameException if domainID or portalID
617:             *                                         contains an illegal
618:             *                                         character or if it does
619:             *                                         not follow the rules
620:             *                                         for quoting.
621:             */
622:            public static ObjectName getDisplayProfileMBeanObjectName(
623:                    String domainId, String portalId)
624:                    throws MalformedObjectNameException {
625:
626:                if (domainId == null) {
627:                    throw new NullPointerException("domainID is null.");
628:                }
629:
630:                if (portalId == null) {
631:                    throw new NullPointerException("portalID is null.");
632:                }
633:
634:                ObjectName objName = null;
635:                String resourceId = "DisplayProfile";
636:                LinkedList path = new LinkedList();
637:                path.addFirst(domainId);
638:                path.addFirst(portalId);
639:                path.addFirst(resourceId);
640:
641:                try {
642:                    objName = AdminClientUtil.getResourceMBeanObjectName(
643:                            DISPLAYPROFILE_MBEAN_TYPE, path);
644:                } catch (MalformedObjectNameException me) {
645:                    throw me;
646:                }
647:                return objName;
648:            }
649:
650:            /**
651:             * Determines if the hosts with the given names are the same.
652:             *
653:             * @param  host1  the first host to be tested for equality.
654:             * @param  host2  the second host to be tested for equality.
655:             * @return <code>true</code> if the hosts are the same;
656:             *         <code>false</code> otherwise.
657:             * @exception UnknownHostException if no IP address for the hosts
658:             *                                 could be found.
659:             */
660:            public static boolean isSameHost(String host1, String host2)
661:                    throws UnknownHostException {
662:
663:                if (host1.equals(host2)) {
664:                    return true;
665:                }
666:
667:                InetAddress[] addresses1 = InetAddress.getAllByName(host1);
668:                InetAddress[] addresses2 = InetAddress.getAllByName(host2);
669:
670:                for (int i = 0; i < addresses1.length; i++) {
671:                    for (int j = 0; j < addresses2.length; j++) {
672:                        if (addresses1[i].equals(addresses2[j])) {
673:                            return true;
674:                        }
675:                    }
676:                }
677:
678:                return false;
679:            }
680:
681:            /**
682:             * Determines if the given host is the same as the local host.
683:             *
684:             * @param  host  the host to be tested for locality.
685:             * @return <code>true</code> if the current JVM is running on the
686:             *         given host; <code>false</code> otherwise.
687:             * @exception UnknownHostException if no IP address for the host
688:             *                                 could be found.
689:             */
690:            public static boolean isLocal(String host)
691:                    throws UnknownHostException {
692:                InetAddress[] addresses = InetAddress.getAllByName(host);
693:                Enumeration networkInterfaces = null;
694:
695:                try {
696:                    networkInterfaces = NetworkInterface.getNetworkInterfaces();
697:                } catch (SocketException e) {
698:                }
699:
700:                if (networkInterfaces != null) {
701:                    while (networkInterfaces.hasMoreElements()) {
702:                        NetworkInterface networkInterface = (NetworkInterface) networkInterfaces
703:                                .nextElement();
704:
705:                        Enumeration localAddrs = networkInterface
706:                                .getInetAddresses();
707:
708:                        while (localAddrs.hasMoreElements()) {
709:                            InetAddress address = (InetAddress) localAddrs
710:                                    .nextElement();
711:
712:                            for (int i = 0; i < addresses.length; i++) {
713:                                if (addresses[i].equals(address)) {
714:                                    return true;
715:                                }
716:                            }
717:                        }
718:                    }
719:                }
720:
721:                InetAddress localHost = InetAddress.getLocalHost();
722:                String localHostName = localHost.getHostName();
723:                InetAddress[] localAddrs = InetAddress
724:                        .getAllByName(localHostName);
725:                String canonicalHostName = localHost.getCanonicalHostName();
726:                InetAddress[] localCAddrs = InetAddress
727:                        .getAllByName(canonicalHostName);
728:
729:                for (int i = 0; i < addresses.length; i++) {
730:                    if (addresses[i].equals(localHost)) {
731:                        return true;
732:                    }
733:
734:                    for (int j = 0; j < localAddrs.length; j++) {
735:                        if (addresses[i].equals(localAddrs[j])) {
736:                            return true;
737:                        }
738:                    }
739:
740:                    for (int j = 0; j < localCAddrs.length; j++) {
741:                        if (addresses[i].equals(localCAddrs[j])) {
742:                            return true;
743:                        }
744:                    }
745:                }
746:
747:                return false;
748:            }
749:
750:            /**
751:             * Returns the default portal domain context.
752:             *
753:             * @return the default portal domain context.
754:             * @exception Exception if the default portal domain context could
755:             *                      not be loaded for any reason.
756:             */
757:            public static PortalDomainContext getPortalDomainContext()
758:                    throws Exception {
759:
760:                PortalDomainContext pdc = null;
761:
762:                try {
763:                    pdc = PortalDomainContextFactory
764:                            .getPortalDomainContext(DEFAULT_DOMAIN);
765:                } catch (NoSuchElementException e) {
766:                    // The default portal domain context was not loaded, so load it.
767:                    JAXBContext jaxbContext = JAXBContext
768:                            .newInstance("com.sun.portal.admin.common.jaxb");
769:
770:                    Unmarshaller unmarshaller = jaxbContext
771:                            .createUnmarshaller();
772:                    List portalResources = new LinkedList();
773:                    PSConfigContext pscc = new PSConfigContextImpl(
774:                            DEFAULT_DOMAIN);
775:                    String fs = Platform.fs;
776:                    File dir = new File(pscc.getPSBaseDir() + fs + "admin" + fs
777:                            + "mbeans");
778:                    File[] files = dir.listFiles();
779:
780:                    for (int i = 0; i < files.length; i++) {
781:                        if (files[i].getName().endsWith("xml")) {
782:                            FileInputStream fis = new FileInputStream(files[i]);
783:                            portalResources.add(unmarshaller.unmarshal(fis));
784:                            fis.close();
785:                        }
786:                    }
787:
788:                    PortalDomainContextFactory.loadPortalDomainContext(
789:                            DEFAULT_DOMAIN, pscc, portalResources,
790:                            Logger.global);
791:
792:                    pdc = PortalDomainContextFactory
793:                            .getPortalDomainContext(DEFAULT_DOMAIN);
794:                }
795:
796:                return pdc;
797:            }
798:
799:            protected static synchronized JMXConnector getConnector(
800:                    String host, String authID, String password)
801:                    throws SecurityException, IOException {
802:
803:                if (cacaoConfigDir == null) {
804:                    try {
805:                        PSConfigContext pscc = new PSConfigContextImpl(
806:                                DEFAULT_DOMAIN);
807:                        cacaoConfigDir = pscc.getCacaoConfigDir();
808:                    } catch (IOException ioe) {
809:                        // Most likely reason is psconsole is deployed on a host where
810:                        // portal is not installed. Just ignore it and let cacao default
811:                        // to its OS specific config directory
812:                    }
813:                }
814:
815:                if (tms == null) {
816:                    String psConfigDir = null;
817:
818:                    try {
819:                        PSConfigContext pscc = new PSConfigContextImpl(
820:                                DEFAULT_DOMAIN);
821:                        psConfigDir = pscc.getPSConfigDir();
822:                    } catch (IOException e) {
823:                    }
824:
825:                    tms = new TrustManager[] { new PSX509TrustManager(
826:                            psConfigDir) };
827:                }
828:
829:                Map env = new HashMap();
830:                env.put(JmxClient.BASE_MAP_KEY + JmxClient.WELLKNOWN_KEY,
831:                        "false");
832:                env.put(JmxClient.BASE_MAP_KEY + JmxClient.SASLID_KEY, authID);
833:                env.put(JmxClient.BASE_MAP_KEY + JmxClient.SASLPASS_KEY,
834:                        password);
835:                env.put(JmxClient.TRUST_MANAGER_ARRAY_KEY, tms);
836:
837:                if (cacaoConfigDir != null) {
838:                    // Set the value of the cacao config dir into the env map
839:                    env.put(JmxClient.CACAO_CONFIG_DIR_KEY, cacaoConfigDir);
840:                }
841:
842:                JMXServiceURL url = null;
843:                try {
844:                    // try RMI first
845:                    url = new JMXServiceURL("service:jmx:"
846:                            + JmxClient.RMI_PROTOCOL + "://" + host);
847:
848:                    return JMXConnectorFactory.connect(url, env);
849:                } catch (Exception e) {
850:                    // fallback to JMXMP
851:                    url = new JMXServiceURL("service:jmx:"
852:                            + JmxClient.JMXMP_PROTOCOL + "://" + host);
853:
854:                    return JMXConnectorFactory.connect(url, env);
855:                }
856:            }
857:
858:            /**
859:             * returns true if any SRA component is installed on the local
860:             * system (SRA Core/GW/NLP/RWP).
861:             **/
862:            public static boolean isSRAInstalled(PSConfigContext cc) {
863:                String fs = Platform.fs;
864:                String libDir = cc.getPSBaseDir() + fs + "lib";
865:                String webInfLibDir = cc.getPSBaseDir() + fs + "web-src" + fs
866:                        + "WEB-INF" + fs + "lib";
867:                boolean installed = false;
868:
869:                //SRA Core - check for netletprovider.jar
870:                if (fileExists(webInfLibDir + fs + "netletprovider.jar")) {
871:                    installed = true;
872:                }
873:
874:                if (!installed) {
875:                    //SRA Common - check for gateway.jar
876:                    //Note gateway.jar is found on all GW/NLP/RWP nodes
877:                    if (fileExists(libDir + fs + "gateway.jar")) {
878:                        installed = true;
879:                    }
880:                }
881:
882:                return installed;
883:            }
884:
885:            /**
886:             * returns true if only SRA component is installed on the local
887:             * system (SRA Core/GW/NLP/RWP).
888:             **/
889:            public static boolean isOnlySRAInstalled(PSConfigContext cc) {
890:                String fs = Platform.fs;
891:                String libDir = cc.getPSBaseDir() + fs + "lib";
892:                String webInfLibDir = cc.getPSBaseDir() + fs + "web-src" + fs
893:                        + "WEB-INF" + fs + "lib";
894:                boolean installed = false;
895:
896:                //Assumes that ProdDir validation is successful
897:
898:                //Check if GW/NLP/RWP is installed
899:                //Check for gateway.jar
900:                //Note gateway.jar is found on all GW/NLP/RWP nodes
901:                if (fileExists(libDir + fs + "gateway.jar")) {
902:                    installed = true;
903:
904:                    //Now check if SRA Core is installed - check for netletprovider.jar
905:                    if (fileExists(webInfLibDir + fs + "netletprovider.jar")) {
906:                        installed = false;
907:                    }
908:                }
909:
910:                return installed;
911:            }
912:
913:            private static boolean fileExists(String fileName) {
914:                try {
915:                    File file = new File(fileName);
916:                    return file.isFile();
917:                } catch (Exception e) {
918:                    return false;
919:                }
920:            }
921:
922:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.