KickJava   Java API By Example, From Geeks To Geeks.

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


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 /*
30  * $Header: /cvs/glassfish/admin/mbeanapi-impl/src/java/com/sun/enterprise/management/support/OldTypesBase.java,v 1.5 2006/03/09 20:30:48 llc Exp $
31  * $Revision: 1.5 $
32  * $Date: 2006/03/09 20:30:48 $
33  */

34
35 package com.sun.enterprise.management.support;
36
37 import java.util.Map JavaDoc;
38 import java.util.HashMap JavaDoc;
39 import java.util.Iterator JavaDoc;
40
41 import javax.management.ObjectName JavaDoc;
42
43 import com.sun.appserv.management.base.XTypes;
44
45
46  
47 /**
48     Maps an AMX j2eeType to/from and "old" (8.0) type.
49     
50     See {@link com.sun.appserv.management.base.XTypes}
51  */

52 abstract class OldTypesBase implements OldTypeToJ2EETypeMapper
53 {
54     final Map JavaDoc<String JavaDoc,String JavaDoc> mOldTypeToJ2EETypeMap;
55     final Map JavaDoc<String JavaDoc,String JavaDoc> mJ2EETypeToOldTypeMap;
56     
57     OldTypesBase()
58     {
59         mOldTypeToJ2EETypeMap = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
60         mJ2EETypeToOldTypeMap = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
61         initMap();
62     }
63     
64         void
65     add(
66         final String JavaDoc j2eeType,
67         final String JavaDoc oldType )
68     {
69         mOldTypeToJ2EETypeMap.put( oldType, j2eeType );
70         mJ2EETypeToOldTypeMap.put( j2eeType, oldType );
71     }
72     
73     /**
74         These are delegates that require a config name only, no other keys
75         other than category=config
76      */

77     abstract void initMap();
78     
79     /**
80         Determine the j2eeType associated with the ObjectName for an "old"
81         config MBean
82         
83         @param oldObjectName
84      */

85         public String JavaDoc
86     oldTypeToJ2EEType(
87         final String JavaDoc oldType,
88         final ObjectName JavaDoc oldObjectName )
89     {
90         String JavaDoc j2eeType = null;
91         
92         if ( oldType.equals( oldObjectName.getKeyProperty( OLD_TYPE_PROP ) ) )
93         {
94             j2eeType = oldObjectNameToJ2EEType( oldObjectName );
95         }
96         else
97         {
98             j2eeType = mOldTypeToJ2EETypeMap.get( oldType );
99         }
100         return( j2eeType );
101     }
102     
103     /**
104         Determine the j2eeType associated with the ObjectName for an "old"
105         config MBean
106         
107         @param oldObjectName
108      */

109         public String JavaDoc
110     oldObjectNameToJ2EEType( final ObjectName JavaDoc oldObjectName )
111     {
112         final String JavaDoc oldType = oldObjectName.getKeyProperty( OLD_TYPE_PROP );
113         if ( oldType == null )
114         {
115             System.err.println( "no j2eeType for: " + oldObjectName );
116             throw new IllegalArgumentException JavaDoc( oldObjectName.toString() );
117         }
118         
119         String JavaDoc j2eeType = null;
120     
121     /*
122         if ( oldType.equals( "ssl" ) )
123         {
124             // ambiguous without parent
125             if ( oldObjectName.getKeyProperty( "ssl-client-config" ) != null )
126             {
127                 j2eeType = XTypes.IIOP_SSL_CLIENT_CONFIG;
128             }
129             else
130             {
131                 j2eeType = XTypes.SSL_CONFIG;
132             }
133         }
134         else
135     */

136         {
137             j2eeType = mOldTypeToJ2EETypeMap.get( oldType );
138             if ( j2eeType == null )
139             {
140                 throw new IllegalArgumentException JavaDoc( oldType );
141             }
142         }
143         
144         assert( j2eeType != null );
145         return( j2eeType );
146     }
147     
148     public final static String JavaDoc OLD_TYPE_PROP = "type";
149     
150     /**
151         By default, the mapping is done using only the OLD_TYPE_PROP field.
152      */

153         public String JavaDoc
154     oldTypeToJ2EEType( final ObjectName JavaDoc objectName )
155     {
156         return oldTypeToJ2EEType( objectName.getKeyProperty( OLD_TYPE_PROP ) );
157     }
158     
159         public String JavaDoc
160     oldTypeToJ2EEType( final String JavaDoc oldType )
161     {
162         return mOldTypeToJ2EETypeMap.get(oldType);
163     }
164     
165         public String JavaDoc
166     j2eeTypeToOldType( final String JavaDoc j2eeType )
167     {
168         return mJ2EETypeToOldTypeMap.get( j2eeType );
169     }
170
171         public Map JavaDoc<String JavaDoc,String JavaDoc>
172     oldPropsToNewProps( final Map JavaDoc<String JavaDoc,String JavaDoc> oldProps )
173     {
174         final Map JavaDoc<String JavaDoc,String JavaDoc> newProps = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
175         for( final String JavaDoc oldProp : oldProps.keySet() )
176         {
177             final String JavaDoc newProp =mOldTypeToJ2EETypeMap.get( oldProp );
178             if ( newProp != null )
179             {
180                 newProps.put( newProp, oldProps.get( oldProp ) );
181             }
182         }
183         return newProps;
184     }
185 }
186
187
188
189
190
191
192
193
194
Popular Tags