KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > j2ee > WebModuleImpl


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  * $Header: /cvs/glassfish/admin/mbeanapi-impl/src/java/com/sun/enterprise/management/j2ee/WebModuleImpl.java,v 1.9 2006/03/09 20:30:45 llc Exp $
26  * $Revision: 1.9 $
27  * $Date: 2006/03/09 20:30:45 $
28  */

29  
30 package com.sun.enterprise.management.j2ee;
31
32 import java.util.Map JavaDoc;
33
34 import javax.management.ObjectName JavaDoc;
35
36 import com.sun.appserv.management.j2ee.J2EETypes;
37
38 import com.sun.appserv.management.base.XTypes;
39 import com.sun.appserv.management.base.AMX;
40 import com.sun.appserv.management.base.Util;
41
42 import com.sun.appserv.management.util.misc.MapUtil;
43 import com.sun.appserv.management.util.misc.CollectionUtil;
44 import com.sun.appserv.management.util.misc.ExceptionUtil;
45 import com.sun.appserv.management.util.misc.StringUtil;
46 import com.sun.appserv.management.util.jmx.AttributeNameMapper;
47
48 import com.sun.enterprise.management.support.Delegate;
49 import com.sun.enterprise.management.support.WebModuleSupport;
50
51 import com.sun.appserv.management.j2ee.WebModule;
52 import com.sun.appserv.management.j2ee.Servlet;
53
54 /**
55  */

56 public final class WebModuleImpl extends J2EEModuleImplBase
57     // implements WebModule
58
{
59         public
60     WebModuleImpl( final Delegate delegate )
61     {
62         super( delegate );
63     }
64     
65     /**
66         MBeans of type j2eeType=WebModule have their virtual server prepended
67         to their name. For example, if the virtual server is "__asadmin", the
68         name will start with "//__asadmin/".
69      */

70         protected String JavaDoc
71     getConfigPeerName()
72     {
73         final String JavaDoc compositeName = getName();
74         
75         final String JavaDoc webModuleName = WebModuleSupport.extractWebModuleName( compositeName );
76
77         return( webModuleName );
78     }
79     
80         public boolean
81     isConfigProvider()
82     {
83         boolean isConfigProvider = super.isConfigProvider();
84         if ( super.isConfigProvider() && getObjectName() != null )
85         {
86             final String JavaDoc name = getConfigPeerName();
87             
88             /*
89                 Ugly hack for our System WebModules.
90                 // context root is being used instead of module name
91              */

92             if ( name.length() == 0 || name.equals( "asadmin" ) ||
93                 name.equals( "web1" ) )
94             {
95                 isConfigProvider = false;
96             }
97             
98         }
99         
100         return( isConfigProvider );
101     }
102     
103         protected WebModule
104     getSelfProxy()
105     {
106         return (WebModule)getSelf();
107     }
108     
109         public String JavaDoc[]
110     getservlets()
111     {
112         final Map JavaDoc<String JavaDoc,Servlet> servlets = getSelfProxy().getServletMap();
113         
114         return( CollectionUtil.toStringArray( Util.toObjectNames( servlets ).values() ) );
115     }
116     
117         public Map JavaDoc
118     getServletObjectNameMap()
119     {
120         return( getContaineeObjectNameMap( J2EETypes.SERVLET ) );
121     }
122     
123         protected String JavaDoc
124     getMonitoringPeerJ2EEType()
125     {
126         return( XTypes.WEB_MODULE_VIRTUAL_SERVER_MONITOR );
127     }
128
129
130         private final String JavaDoc
131     deduceModuleName()
132     {
133         // get the last part of the workDir; it should be the actual module name
134
final String JavaDoc workDir = getSelfProxy().getWorkDir();
135         final int index1 = workDir.lastIndexOf( "/" );
136         final int index2 = workDir.lastIndexOf( "\\" );
137         final int index = index1 > index2 ? index1 : index2;
138         
139         String JavaDoc result = null;
140         
141         if (index > 0 )
142         {
143             result = workDir.substring( index + 1, workDir.length() );
144         }
145         
146         return( result );
147     }
148      
149         protected ObjectName JavaDoc
150     queryConfigPeerFailed( final Map JavaDoc<String JavaDoc,String JavaDoc> propsMap )
151     {
152         final String JavaDoc potentialName = deduceModuleName();
153         propsMap.put( AMX.NAME_KEY, potentialName );
154         
155         final ObjectName JavaDoc result = queryProps( propsMap );
156         
157         return( result );
158     }
159     
160         protected ObjectName JavaDoc
161     queryMonitoringPeerFailed( final Map JavaDoc<String JavaDoc,String JavaDoc> propsMap )
162     {
163         final String JavaDoc selfName = getName();
164         
165         final String JavaDoc virtualServerName = WebModuleSupport.extractVirtualServerName( selfName );
166         
167         ObjectName JavaDoc result = null;
168         
169         final String JavaDoc potentialName = deduceModuleName();
170         if ( potentialName != null )
171         {
172             final String JavaDoc name = WebModuleSupport.formCompositeName( virtualServerName, potentialName );
173
174             propsMap.put( AMX.NAME_KEY, name );
175             result = queryProps( propsMap );
176         }
177         
178         return result;
179     }
180 }
181
Popular Tags