KickJava   Java API By Example, From Geeks To Geeks.

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


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
34 /**
35  */

36 public final class OfflineDottedNamesRegistry
37 {
38     /**
39         Maps from dotted name prefxi to ObjectName
40      */

41     private Map JavaDoc<String JavaDoc,ObjectName JavaDoc> mPrefixToObjectName;
42     
43     /**
44         Maps from ObjectName to all dotted name prefixes.
45      */

46     private Map JavaDoc<ObjectName JavaDoc,String JavaDoc> mObjectNameToPrefix;
47     
48     
49     /**
50         The legal attribute names
51      */

52     private Map JavaDoc<ObjectName JavaDoc,Set JavaDoc<String JavaDoc>> mLegalAttributes;
53     
54         public
55     OfflineDottedNamesRegistry()
56     {
57         mPrefixToObjectName = new HashMap JavaDoc<String JavaDoc,ObjectName JavaDoc>();
58         mObjectNameToPrefix = new HashMap JavaDoc<ObjectName JavaDoc,String JavaDoc>();
59         mLegalAttributes = new HashMap JavaDoc<ObjectName JavaDoc,Set JavaDoc<String JavaDoc>>();
60     }
61     
62     /**
63         Add a mapping from an ObjectName to its dotted name prefixes.
64         @param objectName the ObjectName in question
65         @param prefix one or more prefixes associated with this ObjectName
66         @param legalAttributes the legal attributes, as found in the MBeanInfo of the ObjectName
67      */

68         public synchronized void
69     addMapping(
70         final ObjectName JavaDoc objectName,
71         final String JavaDoc prefix,
72         final Set JavaDoc<String JavaDoc> legalAttributes )
73     {
74         if ( objectName == null || prefix == null )
75         {
76             throw new IllegalArgumentException JavaDoc( "null" );
77         }
78         
79         if ( mObjectNameToPrefix.containsKey( objectName ) )
80         {
81             throw new IllegalArgumentException JavaDoc( "Already registered: " + objectName );
82         }
83         
84         mObjectNameToPrefix.put( objectName, prefix );
85         mPrefixToObjectName.put( prefix, objectName );
86         mLegalAttributes.put( objectName, Collections.unmodifiableSet( legalAttributes ) );
87     }
88     
89         public synchronized void
90     removeMapping( final ObjectName JavaDoc objectName )
91     {
92         final String JavaDoc prefix = mObjectNameToPrefix.get( objectName );
93         if ( prefix != null )
94         {
95             mObjectNameToPrefix.remove( objectName );
96             mLegalAttributes.remove( objectName );
97             mPrefixToObjectName.remove( prefix );
98         }
99     }
100     
101         public String JavaDoc
102     getPrefix( final ObjectName JavaDoc objectName )
103     {
104         return mObjectNameToPrefix.get( objectName );
105     }
106     
107         public ObjectName JavaDoc
108     getObjectName( final String JavaDoc prefix )
109     {
110         return mPrefixToObjectName.get( prefix );
111     }
112     
113         public Set JavaDoc<String JavaDoc>
114     getLegalAttributes( final ObjectName JavaDoc objectName )
115     {
116         return mLegalAttributes.get( objectName );
117     }
118     
119         public Set JavaDoc<ObjectName JavaDoc>
120     getObjectNames()
121     {
122         final Set JavaDoc<ObjectName JavaDoc> result = new HashSet JavaDoc<ObjectName JavaDoc>();
123         
124         result.addAll( mObjectNameToPrefix.keySet() );
125         return result;
126     }
127     
128         public Set JavaDoc<String JavaDoc>
129     getPrefixes()
130     {
131         final Set JavaDoc<String JavaDoc> result = new HashSet JavaDoc<String JavaDoc>();
132         
133         result.addAll( mObjectNameToPrefix.values() );
134         return result;
135     }
136 }
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
Popular Tags