KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > management > offline > OfflineDottedNamePrefixes


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.offline;
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.Collections JavaDoc;
30
31 import javax.management.ObjectName JavaDoc;
32
33 import static com.sun.appserv.management.base.XTypes.*;
34 import static com.sun.appserv.management.base.AMX.*;
35
36
37 /**
38  */

39 public final class OfflineDottedNamePrefixes
40 {
41     private final Map JavaDoc<String JavaDoc,String JavaDoc[]> mTemplates;
42     
43         private
44     OfflineDottedNamePrefixes( )
45     {
46         mTemplates = initTemplates();
47     }
48     
49     private static OfflineDottedNamePrefixes INSTANCE = null;
50     
51         public static synchronized OfflineDottedNamePrefixes
52     getInstance()
53     {
54         if ( INSTANCE == null )
55         {
56             INSTANCE = new OfflineDottedNamePrefixes();
57         }
58         return INSTANCE;
59     }
60     
61     static private final String JavaDoc VAR = "$";
62     static private final String JavaDoc PAR = "^";
63     static private final String JavaDoc PART_DELIM = ".";
64     
65         private static String JavaDoc
66     PAR( final String JavaDoc s )
67     {
68         return PAR + s;
69     }
70     
71         private static String JavaDoc
72     VAR( final String JavaDoc s )
73     {
74         return VAR + s;
75     }
76     
77         private static String JavaDoc
78     varName( final String JavaDoc s )
79     {
80         if ( ! s.startsWith( VAR ) )
81         {
82             throw new IllegalArgumentException JavaDoc( s );
83         }
84         
85         return s.substring( VAR.length(), s.length() );
86     }
87     
88     private static final String JavaDoc NAME_VAR = VAR( NAME_KEY );
89
90     static private final Object JavaDoc[] TEMPLATES = new Object JavaDoc[]
91     {
92         DOMAIN_CONFIG, new String JavaDoc[] { "domain" },
93         CONFIG_CONFIG, new String JavaDoc[] { NAME_VAR },
94         STANDALONE_SERVER_CONFIG, new String JavaDoc[] { NAME_VAR },
95         HTTP_SERVICE_CONFIG, new String JavaDoc[] { VAR( CONFIG_CONFIG ), "http-service" },
96         IIOP_SERVICE_CONFIG, new String JavaDoc[] { VAR( CONFIG_CONFIG ), "iiop-service" },
97         ADMIN_SERVICE_CONFIG, new String JavaDoc[] { VAR( CONFIG_CONFIG ), "admin-service" },
98         JAVA_CONFIG, new String JavaDoc[] { VAR( CONFIG_CONFIG ), "java" },
99         AVAILABILITY_SERVICE_CONFIG, new String JavaDoc[] { VAR( CONFIG_CONFIG ), "availability" },
100         EJB_CONTAINER_CONFIG, new String JavaDoc[] { VAR( CONFIG_CONFIG ), "ejb-container" },
101         
102         HTTP_LISTENER_CONFIG, new String JavaDoc[] { PAR( HTTP_SERVICE_CONFIG ), "listeners", NAME_VAR },
103         ACCESS_LOG_CONFIG, new String JavaDoc[] { PAR( HTTP_SERVICE_CONFIG ), "access-log"},
104         KEEP_ALIVE_CONFIG, new String JavaDoc[] { PAR( HTTP_SERVICE_CONFIG ), "keep-alive"},
105         REQUEST_PROCESSING_CONFIG, new String JavaDoc[] { PAR( HTTP_SERVICE_CONFIG ), "request-processing" },
106         CONNECTION_POOL_CONFIG, new String JavaDoc[] { PAR( HTTP_SERVICE_CONFIG ), "connection-pool" },
107         HTTP_PROTOCOL_CONFIG, new String JavaDoc[] { PAR( HTTP_SERVICE_CONFIG ), "http-protocol" },
108         HTTP_FILE_CACHE_CONFIG, new String JavaDoc[] { PAR( HTTP_SERVICE_CONFIG ), "file-cache" },
109         VIRTUAL_SERVER_CONFIG, new String JavaDoc[] { PAR( HTTP_SERVICE_CONFIG ), "virtual-servers", NAME_VAR },
110     };
111     
112     
113         private Map JavaDoc<String JavaDoc,String JavaDoc[]>
114     initTemplates()
115     {
116         final Map JavaDoc<String JavaDoc,String JavaDoc[]> templates = new HashMap JavaDoc<String JavaDoc,String JavaDoc[]>();
117         
118         for( int i = 0; i < TEMPLATES.length; i += 2 )
119         {
120             final String JavaDoc j2eeType = (String JavaDoc)TEMPLATES[ i ];
121             final String JavaDoc[] template = (String JavaDoc[])TEMPLATES[ i + 1 ];
122             
123             templates.put( j2eeType, template );
124         }
125         
126         return templates;
127     }
128         
129         private String JavaDoc
130     concat(
131         final String JavaDoc prefix,
132         final String JavaDoc part )
133     {
134         String JavaDoc result = null;
135         
136         if ( prefix == null || prefix.length() == 0 )
137         {
138             result = part;
139         }
140         else
141         {
142             result = prefix + PART_DELIM + part;
143         }
144         return( result );
145     }
146     
147         private String JavaDoc[]
148     getTemplate( final String JavaDoc j2eeType )
149     {
150         return mTemplates.get( j2eeType );
151     }
152     
153         public String JavaDoc
154     getPrefix( final ObjectName JavaDoc objectName )
155     {
156         final String JavaDoc j2eeType = objectName.getKeyProperty( J2EE_TYPE_KEY );
157         if ( j2eeType == null )
158         {
159             throw new IllegalArgumentException JavaDoc( "" + objectName );
160         }
161         
162         String JavaDoc prefix = null;
163
164         final String JavaDoc[] template = getTemplate( j2eeType );
165         if ( template != null )
166         {
167             for( final String JavaDoc part : template )
168             {
169                 String JavaDoc value = null;
170                 
171                 if ( part.startsWith( VAR ) )
172                 {
173                     final String JavaDoc prop = varName( part );
174                     value = objectName.getKeyProperty( prop );
175                     if ( value == null )
176                     {
177                         throw new IllegalArgumentException JavaDoc(
178                             "No property " + prop + " in " + objectName );
179                     }
180                 }
181                 else
182                 {
183                     value = part;
184                 }
185                 
186                 prefix = concat( prefix, value );
187             }
188         }
189         
190         return prefix;
191     }
192 }
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
Popular Tags