KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.management.MBeanServer JavaDoc;
33
34 import com.sun.appserv.management.base.DottedNames;
35 import com.sun.appserv.management.base.AMXDebug;
36
37
38 /**
39  */

40 public final class OfflineDottedNamesMgr
41 {
42     private final OfflineDottedNamesRegistry mRegistry;
43     private final OfflineDottedNamePrefixes mPrefixes;
44     private final MBeanServer JavaDoc mServer;
45     
46         public
47     OfflineDottedNamesMgr( final MBeanServer JavaDoc server )
48     {
49         mServer = server;
50         
51         mRegistry = new OfflineDottedNamesRegistry();
52         mPrefixes = OfflineDottedNamePrefixes.getInstance();
53     }
54     
55         private void
56     debug( final Object JavaDoc o )
57     {
58         AMXDebug.getInstance().getOutput( "OfflineDottedNamesMgr" ).println( o );
59     }
60     
61         private String JavaDoc
62     getPrefix( final String JavaDoc dottedName )
63     {
64         final int idx = dottedName.lastIndexOf( dottedName );
65         if ( idx <= 0 )
66         {
67             throw new IllegalArgumentException JavaDoc( dottedName );
68         }
69         return dottedName.substring( 0, idx - 1 );
70     }
71     
72         private String JavaDoc
73     getAttrName( final String JavaDoc dottedName )
74     {
75         final String JavaDoc prefix = getPrefix( dottedName );
76         
77         return dottedName.substring( prefix.length() + 1, dottedName.length() );
78     }
79     
80         public void
81     refresh()
82     {
83         // nothing to do--we're always "live"
84
}
85     
86         public Object JavaDoc[]
87     dottedNameGet( final String JavaDoc[] names )
88     {
89         final Object JavaDoc[] results = new Object JavaDoc[ names.length ];
90         
91         for( int i = 0; i < names.length; ++i )
92         {
93             try
94             {
95                 results[ i ] = dottedNameGet( names[ i ] );
96             }
97             catch( Exception JavaDoc e )
98             {
99                 results[ i ] = e;
100             }
101         }
102         
103         return results;
104     }
105     
106     private final String JavaDoc WILD_ALL = "*";
107     
108         public Object JavaDoc
109     dottedNameGet( final String JavaDoc dottedName )
110     {
111         final String JavaDoc prefix = getPrefix( dottedName );
112         final ObjectName JavaDoc objectName = mRegistry.getObjectName( prefix );
113         
114         if ( objectName == null )
115         {
116             throw new IllegalArgumentException JavaDoc( dottedName );
117         }
118         
119         final String JavaDoc attrName = getAttrName( dottedName );
120         
121         debug( "dottedNameGet: " + dottedName + ", prefix = " + prefix +
122             "attrName = " + attrName );
123         
124         Object JavaDoc value = null;
125         try
126         {
127             value = mServer.getAttribute( objectName, attrName );
128         }
129         catch( Exception JavaDoc e )
130         {
131             value = e;
132         }
133         debug( "dottedNameGet: " + dottedName + " = " + value );
134         return value;
135     }
136     
137         public Object JavaDoc[]
138     dottedNameList( final String JavaDoc[] names )
139     {
140         return new String JavaDoc[0];
141     }
142     
143         public Object JavaDoc[]
144     dottedNameSet( final String JavaDoc[] nameValuePairs )
145     {
146         for( final String JavaDoc pair : nameValuePairs )
147         {
148         }
149         throw new UnsupportedOperationException JavaDoc( "dottedNameSet" );
150     }
151     
152 }
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
Popular Tags