KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > client > MapConverter


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.appserv.management.client;
24
25 import java.util.Map JavaDoc;
26 import java.io.Serializable JavaDoc;
27
28 import com.sun.appserv.management.deploy.DeploymentSupport;
29 import com.sun.appserv.management.ext.wsmgmt.MessageTrace;
30 import com.sun.appserv.management.ext.wsmgmt.MessageTraceImpl;
31
32 import static com.sun.appserv.management.base.
33
                MapCapable.MAP_CAPABLE_CLASS_NAME_KEY;
34 import static com.sun.appserv.management.deploy.
35
                DeploymentProgress.DEPLOYMENT_PROGRESS_CLASS_NAME;
36 import static com.sun.appserv.management.deploy.DeploymentSource.
37
                DEPLOYMENT_SOURCE_CLASS_NAME;
38 import static com.sun.appserv.management.deploy.DeploymentStatus.
39
                DEPLOYMENT_STATUS_CLASS_NAME;
40
41 /**
42     Converts Maps obtained from the server back into their
43     proprietary (non-standard) java types.
44  */

45 public final class MapConverter
46 {
47     private MapConverter() {}
48     
49     /**
50         Of course there are more elaborate ways to do this, but given the small
51         number of conversions, this straightforward approach is best.
52      */

53         private static Object JavaDoc
54     doConvert( final Map JavaDoc<String JavaDoc,Serializable JavaDoc> m )
55     {
56         Object JavaDoc result = m; // don't convert, by default
57

58         final String JavaDoc interfaceName = (String JavaDoc)m.get(MAP_CAPABLE_CLASS_NAME_KEY);
59         if ( interfaceName != null )
60         {
61             if ( DEPLOYMENT_PROGRESS_CLASS_NAME.equals( interfaceName ) )
62             {
63                 result = DeploymentSupport.mapToDeploymentProgress( m );
64             }
65             else if ( DEPLOYMENT_SOURCE_CLASS_NAME.equals( interfaceName ) )
66             {
67                 result = DeploymentSupport.mapToDeploymentSource( m );
68             }
69             else if ( DEPLOYMENT_STATUS_CLASS_NAME.equals( interfaceName ) )
70             {
71                 result = DeploymentSupport.mapToDeploymentStatus( m );
72             }
73             else if ( MessageTrace.CLASS_NAME.equals( interfaceName ) )
74             {
75                 result = new MessageTraceImpl( m, MessageTrace.class.getName());
76             }
77             else
78             {
79                 // That's OK, we just leave it as a Map
80
}
81         }
82         return result;
83     }
84     
85     
86     /**
87         This form should be used where the appropriate class is not
88         known in advance.
89      */

90         public static Object JavaDoc
91     convert( final Map JavaDoc<String JavaDoc,Serializable JavaDoc> m )
92     {
93         return doConvert( m );
94     }
95     
96     /**
97         This form should be used where the appropriate class is known
98         in advance.
99      */

100         public static <T> T
101     convertToClass(
102         final Map JavaDoc<String JavaDoc,Serializable JavaDoc> m,
103         final Class JavaDoc<T> theClass )
104     {
105         return theClass.cast( doConvert( m ) );
106     }
107 }
108
109
110
111
112
113
Popular Tags