KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > support > WebModuleSupport


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * Copyright 2004-2005 Sun Microsystems, Inc. All rights reserved.
26  * Use is subject to license terms.
27  */

28 package com.sun.enterprise.management.support;
29
30
31 import javax.management.ObjectName JavaDoc;
32
33 import com.sun.appserv.management.util.misc.StringUtil;
34 import com.sun.appserv.management.util.jmx.JMXUtil;
35
36 /**
37  */

38 public final class WebModuleSupport
39 {
40     private WebModuleSupport() {}
41     
42     /**
43         Used to prefix a virtual server name for a j2eeType=WebModule
44      */

45     public static final String JavaDoc VIRTUAL_SERVER_PREFIX = "//";
46     
47     /**
48         Used to terminate a virtual server name for a j2eeType=WebModule
49      */

50     public static final String JavaDoc VIRTUAL_SERVER_DELIM = "/";
51     
52         public static boolean
53     isLegalVirtualServerName( final String JavaDoc candidate )
54     {
55         return (! candidate.startsWith( VIRTUAL_SERVER_PREFIX ) ) &&
56             ( candidate.indexOf( VIRTUAL_SERVER_DELIM ) < 0 );
57     }
58     
59         public static String JavaDoc
60     formCompositeName(
61         final String JavaDoc virtualServerName,
62         final String JavaDoc webModuleName )
63     {
64         return VIRTUAL_SERVER_PREFIX + virtualServerName + VIRTUAL_SERVER_DELIM + webModuleName;
65     }
66     
67     
68     /**
69         WebModule names are of the form //<virtual-server-name>/<web-module-name>.
70         Extract the virtual-server-name portion
71         @see #extractWebModuleName
72      */

73         public static String JavaDoc
74     extractVirtualServerName( final String JavaDoc compositeName )
75     {
76         if ( ! compositeName.startsWith( VIRTUAL_SERVER_PREFIX ) )
77         {
78             throw new IllegalArgumentException JavaDoc( compositeName );
79         }
80         
81         final String JavaDoc temp =
82             StringUtil.stripPrefix( compositeName, VIRTUAL_SERVER_PREFIX );
83         final int delimIdx = temp.indexOf( VIRTUAL_SERVER_DELIM );
84         if ( delimIdx < 0 )
85         {
86             throw new IllegalArgumentException JavaDoc( compositeName );
87         }
88         
89         final String JavaDoc virtualServerName = temp.substring( 0, delimIdx );
90         
91         return virtualServerName;
92     }
93     
94     /**
95         WebModule names are of the form //<virtual-server-name>/<web-module-name>.
96         Extract the web-module-name portion
97         @see #extractVirtualServerName
98      */

99         public static String JavaDoc
100     extractWebModuleName( final String JavaDoc compositeName )
101     {
102         final String JavaDoc virtualServerName = extractVirtualServerName( compositeName );
103         
104         final String JavaDoc prefix =
105             VIRTUAL_SERVER_PREFIX + virtualServerName + VIRTUAL_SERVER_DELIM;
106     
107         String JavaDoc name = compositeName.substring( prefix.length(), compositeName.length() );
108         if ( name.length() == 0 )
109         {
110             name = virtualServerName + ".default";
111         }
112         
113         return name;
114     }
115
116         public static String JavaDoc
117     getWebModuleName( final ObjectName JavaDoc oldObjectName )
118     {
119         final String JavaDoc webModule = oldObjectName.getKeyProperty( "web-module" );
120         final String JavaDoc standaloneWebModule = oldObjectName.getKeyProperty( "standalone-web-module" );
121         
122         String JavaDoc webModuleName = null;
123         if ( standaloneWebModule != null )
124         {
125             webModuleName = extractWebModuleName( standaloneWebModule );
126         }
127         else if ( webModule != null )
128         {
129             webModuleName = extractWebModuleName( webModule );
130         }
131         else
132         {
133             throw new IllegalArgumentException JavaDoc( JMXUtil.toString( oldObjectName ) );
134         }
135         
136         return( webModuleName );
137     }
138     
139     /** the category=monitor,type=web-module name is {@link #JWS_APP_CLIENTS_WEB_MODULE_MONITOR_NAME} */
140     public static final String JavaDoc JWS_APP_CLIENTS_WEB_MODULE_NAME = "//server/__JWSappclients";
141     
142     /** the category=runtime,type=WebModule name is {@link #JWS_APP_CLIENTS_WEB_MODULE_NAME} */
143     public static final String JavaDoc JWS_APP_CLIENTS_WEB_MODULE_MONITOR_NAME = "//server/sys";
144     
145     //
146
}
147
148
Popular Tags