KickJava   Java API By Example, From Geeks To Geeks.

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


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  
29 package com.sun.enterprise.management.support;
30
31 import java.util.logging.Logger JavaDoc;
32 import java.util.Set JavaDoc;
33 import java.util.Map JavaDoc;
34 import java.util.HashMap JavaDoc;
35 import java.util.HashSet JavaDoc;
36 import java.util.Iterator JavaDoc;
37 import java.util.Collections JavaDoc;
38
39 import javax.management.ObjectName JavaDoc;
40 import javax.management.MBeanRegistrationException JavaDoc;
41 import javax.management.InstanceAlreadyExistsException JavaDoc;
42
43
44 import com.sun.enterprise.management.support.oldconfig.OldProps;
45
46 import com.sun.appserv.management.DomainRoot;
47 import com.sun.appserv.management.base.Util;
48 import com.sun.appserv.management.base.XTypes;
49 import com.sun.appserv.management.base.AMX;
50 import com.sun.appserv.management.base.SystemInfo;
51
52 import com.sun.appserv.management.config.ServerConfig;
53 import com.sun.appserv.management.config.DomainConfig;
54
55 import com.sun.appserv.management.util.jmx.JMXUtil;
56 import com.sun.appserv.management.util.misc.GSetUtil;
57 import com.sun.appserv.management.util.misc.ClassUtil;
58 import com.sun.appserv.management.util.misc.StringUtil;
59
60 import com.sun.appserv.management.j2ee.J2EETypes;
61
62
63 /**
64     Loads MBeans.
65  */

66 final class LoaderOfOld77 extends LoaderOfOld
67 {
68     private final String JavaDoc mAMXJMXDomain;
69     /**
70         Whether this process is the DAS.
71      */

72     private final boolean mIsDAS;
73     
74     LoaderOfOld77( final Loader loader )
75     {
76         super( loader );
77         
78         mAMXJMXDomain = loader.getAMXJMXDomainName();
79         
80         final SystemInfo systemInfo = loader.getDomainRoot().getSystemInfo();
81         mIsDAS = systemInfo.supportsFeature( SystemInfo.RUNNING_IN_DAS_FEATURE );
82     }
83     
84         public Set JavaDoc<ObjectName JavaDoc>
85     findAllOldCandidates()
86     {
87         final ObjectName JavaDoc pattern = JMXUtil.newObjectName( "com.sun.appserv", JMXUtil.WILD_ALL );
88         final Set JavaDoc<ObjectName JavaDoc> all = JMXUtil.queryNames( getMBeanServer(), pattern, null );
89         
90         final Set JavaDoc<ObjectName JavaDoc> results = new HashSet JavaDoc<ObjectName JavaDoc>();
91         for( final ObjectName JavaDoc objectName : all )
92         {
93             if ( shouldSync( objectName ) )
94             {
95                 results.add( objectName );
96             }
97         }
98         
99         return( results );
100     }
101
102     
103     
104
105         private boolean
106     isOld77ObjectName( final ObjectName JavaDoc objectName )
107     {
108         final String JavaDoc j2eeType = objectName.getKeyProperty( "j2eeType" );
109         
110         boolean ret = ( j2eeType != null &&
111             ! objectName.getDomain().equals( mAMXJMXDomain ) );
112
113             return ret;
114     }
115     
116     /**
117      */

118     public static final Set JavaDoc SYNC_TYPES = GSetUtil.newUnmodifiableStringSet(
119             J2EETypes.J2EE_DOMAIN,
120             J2EETypes.J2EE_SERVER,
121             J2EETypes.J2EE_APPLICATION,
122             J2EETypes.APP_CLIENT_MODULE,
123             J2EETypes.EJB_MODULE,
124             J2EETypes.WEB_MODULE,
125             J2EETypes.RESOURCE_ADAPTER_MODULE,
126             J2EETypes.RESOURCE_ADAPTER,
127             J2EETypes.ENTITY_BEAN,
128             J2EETypes.STATEFUL_SESSION_BEAN,
129             J2EETypes.STATELESS_SESSION_BEAN,
130             J2EETypes.MESSAGE_DRIVEN_BEAN,
131             J2EETypes.SERVLET,
132             J2EETypes.JAVA_MAIL_RESOURCE,
133             J2EETypes.JCA_RESOURCE,
134             J2EETypes.JCA_CONNECTION_FACTORY,
135             J2EETypes.JCA_MANAGED_CONNECTION_FACTORY,
136             J2EETypes.JDBC_RESOURCE,
137             J2EETypes.JDBC_DATA_SOURCE,
138             J2EETypes.JDBC_DRIVER,
139             J2EETypes.JMS_RESOURCE,
140             J2EETypes.JNDI_RESOURCE,
141             J2EETypes.JTA_RESOURCE,
142             J2EETypes.RMI_IIOP_RESOURCE,
143             J2EETypes.URL_RESOURCE,
144             J2EETypes.JVM,
145             J2EETypes.WEB_SERVICE_ENDPOINT );
146     
147     
148     
149         protected Set JavaDoc
150     getNeedsSupport()
151     {
152         return( Collections.EMPTY_SET );
153     }
154
155         protected Set JavaDoc
156     getIgnoreTypes()
157     {
158         return( Collections.EMPTY_SET );
159     }
160     
161         private boolean
162     isValidCompositeWebModuleName( final String JavaDoc compositeName )
163     {
164         boolean valid = false;
165         
166         try
167         {
168             final String JavaDoc webModuleName = WebModuleSupport.extractWebModuleName( compositeName );
169         
170             // An empty name is valid, too, if it's the default web module.
171
valid = true;
172         }
173         catch( Exception JavaDoc e )
174         {
175         }
176         return valid;
177     }
178     
179         private boolean
180     hasValidWebModuleName( final ObjectName JavaDoc objectName )
181     {
182         boolean isValid = true;
183         
184         final String JavaDoc j2eeType = Util.getJ2EEType( objectName );
185             
186         // Our WebModule names are of the form //<virtual-server-name>/<web-module-name>.
187
// some of them are "defective" and lack a <web-module-name> part
188
// no empty web-module names allowed (bug in underlying MBean naming), see bug #6180648
189
if ( j2eeType.equals( J2EETypes.SERVLET ) )
190         {
191             final String JavaDoc compositeName = objectName.getKeyProperty( J2EETypes.WEB_MODULE );
192             isValid = isValidCompositeWebModuleName( compositeName );
193         }
194         else if (j2eeType.equals( J2EETypes.WEB_SERVICE_ENDPOINT))
195         {
196             // check if this web service endpoint belong to EJB module
197
final String JavaDoc ejbModName = objectName.getKeyProperty( J2EETypes.EJB_MODULE);
198             if (ejbModName != null)
199             {
200                 isValid = true;
201             }
202             else
203             {
204                 final String JavaDoc compositeName = objectName.getKeyProperty( J2EETypes.WEB_MODULE );
205                 isValid = isValidCompositeWebModuleName( compositeName );
206             }
207         }
208         else if ( j2eeType.equals( J2EETypes.WEB_MODULE ) )
209         {
210             final String JavaDoc compositeName = objectName.getKeyProperty( AMX.NAME_KEY );
211             isValid = isValidCompositeWebModuleName( compositeName );
212         }
213         
214         return( isValid );
215     }
216
217         public boolean
218     isOldMBean( final ObjectName JavaDoc objectName )
219     {
220         boolean shouldSync = isOld77ObjectName( objectName );
221         
222         if ( shouldSync )
223         {
224             final String JavaDoc j2eeType = Util.getJ2EEType( objectName );
225             shouldSync = SYNC_TYPES.contains( j2eeType );
226         
227             if ( shouldSync && ! hasValidWebModuleName( objectName ) )
228             {
229                 // the MBean will load just fine, but other downstream problems will occur
230
shouldSync = false;
231         
232                 getLogger().warning(
233                     "Not registering AMX MBean against old MBean " + StringUtil.quote( objectName ) +
234                     " due to malformed composite WebModule name." );
235             }
236         }
237         
238         return( shouldSync );
239     }
240     
241     /**
242         Containment keys specified by JSR 77 ObjectNames which we must preserve
243         from old to new ObjectName
244      */

245     private final static String JavaDoc[] CONTAINMENT_KEYS_77 = new String JavaDoc[]
246     {
247         AMX.NAME_KEY,
248         AMX.J2EE_TYPE_KEY,
249         J2EETypes.J2EE_DOMAIN,
250         J2EETypes.J2EE_SERVER,
251         J2EETypes.J2EE_APPLICATION,
252         J2EETypes.EJB_MODULE,
253         J2EETypes.WEB_MODULE,
254         J2EETypes.RESOURCE_ADAPTER_MODULE,
255         J2EETypes.JDBC_RESOURCE,
256         J2EETypes.JCA_RESOURCE,
257         J2EETypes.WEB_SERVICE_ENDPOINT,
258     };
259     
260         private Map JavaDoc<String JavaDoc,String JavaDoc>
261     getOld77Props( final ObjectName JavaDoc oldObjectName )
262     {
263         final Map JavaDoc<String JavaDoc,String JavaDoc> m = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
264         
265         for( int i = 0; i < CONTAINMENT_KEYS_77.length; ++i )
266         {
267             final String JavaDoc key = CONTAINMENT_KEYS_77[ i ];
268             
269             final String JavaDoc value = oldObjectName.getKeyProperty( key );
270             if ( value != null )
271             {
272                 m.put( key, value );
273             }
274         }
275         
276         return( m );
277     }
278     
279     /**
280         JSR77 has some inconsistent approaches to its containment hierarchy; it omits
281         implied parents, which causes headaches for generic navigation. This routine
282         accounts for those issues.
283      */

284         protected ObjectName JavaDoc
285     oldToNewObjectName( final ObjectName JavaDoc oldObjectName )
286     {
287         final String JavaDoc j2eeType = Util.getJ2EEType( oldObjectName );
288         final String JavaDoc j2eeDomainName = getAMXJMXDomainName();
289         
290         final Map JavaDoc<String JavaDoc,String JavaDoc> propsMap = getOld77Props( oldObjectName );
291         if ( j2eeType.equals( J2EETypes.J2EE_DOMAIN ) )
292         {
293             // name must be changed to match domain
294
propsMap.put( AMX.NAME_KEY, j2eeDomainName );
295         }
296         else if ( j2eeType.equals( J2EETypes.J2EE_SERVER ) )
297         {
298         }
299         else
300         {
301             // everything else has a parent
302
}
303
304         
305         final String JavaDoc props = JMXUtil.mapToProps( propsMap );
306         
307         final ObjectName JavaDoc newName = Util.newObjectName( j2eeDomainName, props );
308         
309         return( newName );
310     }
311
312
313     
314         private final boolean
315     serverRunningInDAS( final String JavaDoc serverName )
316     {
317         boolean runningInDAS = false;
318         
319         if ( mIsDAS )
320         {
321             // Simplifying assumption: only one server runs in DAS
322
runningInDAS = true;
323         }
324         
325         return( runningInDAS );
326     }
327     
328         protected Class JavaDoc
329     getImplClass(
330         final ObjectName JavaDoc newObjectName,
331         final ObjectName JavaDoc oldObjectName )
332     {
333         Class JavaDoc implClass = super.getImplClass( newObjectName, oldObjectName );
334         
335         final boolean isJ2EEServer =
336             Util.getJ2EEType( newObjectName ).equals( J2EETypes.J2EE_SERVER );
337         if ( isJ2EEServer )
338         {
339             // it's a J2EEServer; determine if it's running in the DAS itself
340
// in which case we need a different impl
341
final String JavaDoc serverName = Util.getName( newObjectName );
342             final boolean isAdminServer = serverRunningInDAS( serverName );
343             if ( isAdminServer )
344             {
345             
346                 try
347                 {
348                     implClass =
349                     ClassUtil.getClassFromName( "com.sun.enterprise.management.j2ee.DASJ2EEServerImpl");
350                 }
351                 catch (ClassNotFoundException JavaDoc cnfe)
352                 {
353                     try
354                     {
355                     implClass = ClassUtil.getClassFromName(
356                         "com.sun.enterprise.management.j2ee.J2EEServerImpl" );
357                     }
358                     catch( ClassNotFoundException JavaDoc e )
359                     {
360                         throw new RuntimeException JavaDoc( e );
361                     }
362                 }
363             }
364             getLogger().fine(
365                 "LoaderOfOld77.getImplClass: Using J2EEServer impl of class: " +
366                 implClass.getName() +
367                 " for server " + serverName );
368             
369         }
370         
371         return( implClass );
372     }
373
374 }
375
Popular Tags