1 23 package com.sun.enterprise.management.offline; 24 25 import java.util.Map ; 26 import java.util.HashMap ; 27 import java.util.Set ; 28 import java.util.HashSet ; 29 import java.util.Collections ; 30 31 import javax.management.ObjectName ; 32 33 34 36 public final class OfflineDottedNamesRegistry 37 { 38 41 private Map <String ,ObjectName > mPrefixToObjectName; 42 43 46 private Map <ObjectName ,String > mObjectNameToPrefix; 47 48 49 52 private Map <ObjectName ,Set <String >> mLegalAttributes; 53 54 public 55 OfflineDottedNamesRegistry() 56 { 57 mPrefixToObjectName = new HashMap <String ,ObjectName >(); 58 mObjectNameToPrefix = new HashMap <ObjectName ,String >(); 59 mLegalAttributes = new HashMap <ObjectName ,Set <String >>(); 60 } 61 62 68 public synchronized void 69 addMapping( 70 final ObjectName objectName, 71 final String prefix, 72 final Set <String > legalAttributes ) 73 { 74 if ( objectName == null || prefix == null ) 75 { 76 throw new IllegalArgumentException ( "null" ); 77 } 78 79 if ( mObjectNameToPrefix.containsKey( objectName ) ) 80 { 81 throw new IllegalArgumentException ( "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 objectName ) 91 { 92 final String 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 102 getPrefix( final ObjectName objectName ) 103 { 104 return mObjectNameToPrefix.get( objectName ); 105 } 106 107 public ObjectName 108 getObjectName( final String prefix ) 109 { 110 return mPrefixToObjectName.get( prefix ); 111 } 112 113 public Set <String > 114 getLegalAttributes( final ObjectName objectName ) 115 { 116 return mLegalAttributes.get( objectName ); 117 } 118 119 public Set <ObjectName > 120 getObjectNames() 121 { 122 final Set <ObjectName > result = new HashSet <ObjectName >(); 123 124 result.addAll( mObjectNameToPrefix.keySet() ); 125 return result; 126 } 127 128 public Set <String > 129 getPrefixes() 130 { 131 final Set <String > result = new HashSet <String >(); 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 |