KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > support > oldconfig > OldProps


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 package com.sun.enterprise.management.support.oldconfig;
24
25 import java.util.Map JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Set JavaDoc;
28 import java.util.HashSet JavaDoc;
29 import java.util.List JavaDoc;
30 import java.util.Collections JavaDoc;
31
32 import javax.management.ObjectName JavaDoc;
33
34
35 import com.sun.appserv.management.util.misc.ListUtil;
36 import com.sun.appserv.management.util.misc.TypeCast;
37 import com.sun.appserv.management.util.jmx.JMXUtil;
38
39 import com.sun.appserv.management.base.AMX;
40 import com.sun.appserv.management.base.AMXDebug;
41 import com.sun.appserv.management.base.XTypes;
42 import com.sun.enterprise.management.support.ObjectNames;
43 import com.sun.enterprise.management.support.TypeInfo;
44 import com.sun.enterprise.management.support.TypeInfos;
45 import com.sun.enterprise.management.support.OldTypeToJ2EETypeMapper;
46
47 import com.sun.appserv.management.util.stringifier.SmartStringifier;
48
49 /**
50     Extracts relevant properties from "old" ObjectNames.
51  */

52 public final class OldProps
53 {
54     private final ObjectName JavaDoc mObjectName;
55     private final Map JavaDoc<String JavaDoc,String JavaDoc> mValues;
56     
57     private static final String JavaDoc SERVER_CONFIG_KEY = "ServerConfig";
58     
59         private static void
60     debug( final Object JavaDoc o )
61     {
62         AMXDebug.getInstance().getOutput( "OldProps" ).println( o );
63     }
64     
65     /**
66         These are the possible key values in an old ObjectName that
67         contain the name of the config element.
68      */

69     static private final List JavaDoc<String JavaDoc> POSSIBLE_NAME_KEYS = Collections.unmodifiableList(
70         ListUtil.newListFromArray( new String JavaDoc[]
71     {
72         "name",
73         "id",
74         "ref",
75         "thread-pool-id",
76         "jndi-name",
77         "resource-adapter-name",
78         "provider-id",
79         "connector-resource-jndi-name",
80         "auth-layer",
81     } ));
82     
83         public static List JavaDoc<String JavaDoc>
84     getPossibleNameKeys()
85     {
86         return POSSIBLE_NAME_KEYS;
87     }
88
89     
90         public ObjectName JavaDoc
91     getOldObjectName()
92     {
93         return( mObjectName );
94     }
95     
96     /**
97         Get a String consisting of all new properties suitable for use
98         in creating a new ObjectName.
99      */

100         public String JavaDoc
101     getNewProps()
102     {
103         return( JMXUtil.mapToProps( mValues ) );
104     }
105     
106     /**
107         Determine the name of an item from the old ObjectName.
108      */

109         private String JavaDoc
110     getOldName( final ObjectName JavaDoc oldObjectName )
111     {
112         String JavaDoc oldName = null;
113         
114         for( final String JavaDoc key : getPossibleNameKeys() )
115         {
116             oldName = oldObjectName.getKeyProperty( key );
117             if ( oldName != null )
118             {
119                 break;
120             }
121         }
122         
123         // special case for 'root' mbean, which is monitoring root
124
if ( oldName == null && oldObjectName.getKeyProperty( "type" ).equals( "root" ) )
125         {
126             oldName = oldObjectName.getKeyProperty( "server" );
127         }
128         
129         return( oldName );
130     }
131     
132         private static String JavaDoc
133     toString( final Object JavaDoc o )
134     {
135         return( SmartStringifier.toString( o ) );
136     }
137     
138     /**
139         Find the first key that is present in the ObjectName
140         
141         @return first key present in the ObjectName
142      */

143         public static Set JavaDoc
144     j2eeTypesToOldTypes(
145         final Set JavaDoc<String JavaDoc> j2eeTypes,
146         final OldTypeToJ2EETypeMapper mapper)
147     {
148         final Set JavaDoc<String JavaDoc> old = new HashSet JavaDoc<String JavaDoc>();
149         
150         String JavaDoc match = null;
151         for ( final String JavaDoc j2eeType : j2eeTypes )
152         {
153             final String JavaDoc oldType = mapper.j2eeTypeToOldType( j2eeType );
154             if ( oldType != null )
155             {
156                 old.add( oldType );
157             }
158         }
159         
160         return( old );
161     }
162     
163     
164
165         public
166     OldProps(
167         final ObjectName JavaDoc oldObjectName,
168         final OldTypeToJ2EETypeMapper mapper)
169     {
170         mObjectName = oldObjectName;
171         mValues = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
172         
173         // determine the new type from the old
174
final String JavaDoc j2eeType = mapper.oldObjectNameToJ2EEType( oldObjectName );
175         if ( j2eeType == null )
176         {
177             throw new IllegalArgumentException JavaDoc( "" + oldObjectName );
178         }
179         mValues.put( AMX.J2EE_TYPE_KEY, j2eeType );
180         
181         // determine the name
182
final String JavaDoc oldName = getOldName( oldObjectName );
183         final String JavaDoc name = oldName != null ?
184             oldName : ObjectNames.getSingletonName( j2eeType );
185         mValues.put( AMX.NAME_KEY, name );
186         
187         final Set JavaDoc<String JavaDoc> keys = TypeCast.asSet(oldObjectName.getKeyPropertyList().keySet());
188         for( final String JavaDoc prop : keys )
189         {
190             final String JavaDoc newType = mapper.oldTypeToJ2EEType( prop, oldObjectName );
191             
192             if ( newType != null )
193             {
194                 mValues.put( newType, oldObjectName.getKeyProperty( prop ) );
195             }
196         }
197         
198         // special-cases
199

200         if ( j2eeType.equals( XTypes.JMX_CONNECTOR_CONFIG ) )
201         {
202             /*
203                 JMX_CONNECTOR_CONFIG MBean has two possible parents,
204                 but neither is present in the old "jmx-connector" mbean,
205                 which screws things up for itself and its children (SSL_CONFIG).
206              */

207             if ( mValues.containsKey( XTypes.CONFIG_CONFIG ) )
208             {
209                 mValues.put( XTypes.ADMIN_SERVICE_CONFIG,
210                     ObjectNames.getSingletonName( XTypes.ADMIN_SERVICE_CONFIG ) );
211             }
212             else if ( mValues.containsKey( XTypes.NODE_AGENT_CONFIG ) )
213             {
214                 // OK
215
}
216             else
217             {
218                 throw new IllegalArgumentException JavaDoc( "unrecognized ObjectName for jmx-connector" );
219             }
220         }
221         else if ( j2eeType.equals( XTypes.SSL_CONFIG ) )
222         {
223             if ( mValues.containsKey( XTypes.NODE_AGENT_CONFIG ) )
224             {
225                 /**
226                     Old object name for "node-agent/jmx-connector/ssl" doesnot
227                     have jmx-connector property.
228                  */

229                 mValues.put( XTypes.JMX_CONNECTOR_CONFIG,
230                     ObjectNames.getSingletonName( XTypes.JMX_CONNECTOR_CONFIG ) );
231             }
232             else if ( mValues.containsKey( XTypes.JMX_CONNECTOR_CONFIG ) )
233             {
234                 mValues.put( XTypes.ADMIN_SERVICE_CONFIG,
235                     ObjectNames.getSingletonName( XTypes.ADMIN_SERVICE_CONFIG ) );
236             }
237             else if ( mValues.containsKey( XTypes.CONFIG_CONFIG ) &&
238                         !mValues.containsKey( XTypes.HTTP_LISTENER_CONFIG ) &&
239                         !mValues.containsKey( XTypes.IIOP_LISTENER_CONFIG ) )
240             {
241                 mValues.put( XTypes.IIOP_SERVICE_CONFIG,
242                     ObjectNames.getSingletonName( XTypes.IIOP_SERVICE_CONFIG ) );
243             }
244         }
245         else if ( j2eeType.equals( XTypes.AUTH_REALM_CONFIG ) )
246         {
247             /*
248                 AUTH_REALM_CONFIG MBean has two possible parents,
249                 but neither is present in the old "auth-realm" mbean when it
250                 is a child of security service.
251              */

252             if ( mValues.containsKey( XTypes.CONFIG_CONFIG ) )
253             {
254                 mValues.put( XTypes.SECURITY_SERVICE_CONFIG,
255                     ObjectNames.getSingletonName( XTypes.SECURITY_SERVICE_CONFIG ) );
256             }
257             else if ( mValues.containsKey( XTypes.NODE_AGENT_CONFIG ) )
258             {
259                 // OK
260
}
261             else
262             {
263                 throw new IllegalArgumentException JavaDoc( "unrecognized ObjectName for ssl or jmx-connector" );
264             }
265          }
266     }
267     
268     
269     
270 }
271     
272
273
274
275
276
277
278
Popular Tags