1 16 17 package org.apache.jetspeed.om.registry.base; 18 19 import org.apache.jetspeed.om.registry.RegistryEntry; 20 import org.apache.jetspeed.om.registry.InvalidEntryException; 21 import java.util.Map; 22 import java.util.TreeMap; 23 import java.util.Iterator; 24 import java.util.Enumeration; 25 import java.util.Vector; 26 27 34 public class BaseRegistry implements LocalRegistry 35 { 36 protected static final boolean DEBUG = false; 37 38 protected Map entries = new TreeMap(); 39 40 41 public int getEntryCount() 42 { 43 return this.entries.size(); 44 } 45 46 47 public RegistryEntry getEntry( String name ) throws InvalidEntryException 48 { 49 50 RegistryEntry entry = null; 51 52 if (name != null) 53 { 54 entry = (RegistryEntry)this.entries.get( name ) ; 55 } 56 57 if (entry == null) 58 { 59 throw new InvalidEntryException( InvalidEntryException.ENTRY_DOES_NOT_EXIST+" "+name ); 60 } 61 62 return entry; 63 } 64 65 68 public void setEntry( RegistryEntry entry ) throws InvalidEntryException 69 { 70 synchronized (this) 71 { 72 73 if ( this.hasEntry( entry.getName() ) == false ) 74 { 75 throw new InvalidEntryException( InvalidEntryException.ENTRY_DOES_NOT_EXIST+" "+entry.getName()); 76 } 77 78 this.entries.put( entry.getName(), entry ); 79 } 80 } 81 82 85 public void addEntry( RegistryEntry entry ) throws InvalidEntryException 86 { 87 88 synchronized (this) 89 { 90 if ( this.hasEntry( entry.getName() ) ) 91 { 92 throw new InvalidEntryException( InvalidEntryException.ENTRY_ALREADY_PRESENT ); 93 } 94 95 this.entries.put( entry.getName(), entry ); 96 } 97 } 98 99 102 public boolean hasEntry( String name ) 103 { 104 return this.entries.containsKey( name ); 105 } 106 107 110 public void removeEntry( String name ) 111 { 112 synchronized(this) 113 { 114 this.entries.remove( name ); 115 } 116 } 117 118 121 122 public void removeEntry( RegistryEntry entry ) 123 { 124 synchronized(this) 125 { 126 this.entries.remove( entry.getName() ); 127 } 128 } 129 130 133 public Enumeration getEntries() 134 { 135 Vector v = null; 136 137 synchronized (this) 138 { 139 v = new Vector(this.entries.values()); 141 } 142 143 return v.elements(); 144 } 145 146 149 public Iterator listEntryNames() 150 { 151 return entries.keySet().iterator(); 152 } 153 154 157 public RegistryEntry[] toArray() 158 { 159 160 Enumeration enum = getEntries(); 161 Vector v = new Vector(); 162 163 while( enum.hasMoreElements() ) 164 { 165 v.addElement( enum.nextElement() ); 166 } 167 168 RegistryEntry[] entries = new RegistryEntry[ v.size() ]; 169 v.copyInto( entries ); 170 return entries; 171 172 } 173 174 180 public RegistryEntry createEntry() 181 { 182 return new BaseRegistryEntry(); 183 } 184 185 186 188 195 public void setLocalEntry( RegistryEntry entry ) throws InvalidEntryException 196 { 197 synchronized (this) 198 { 199 200 if ( this.hasEntry( entry.getName() ) == false ) 201 { 202 throw new InvalidEntryException( InvalidEntryException.ENTRY_DOES_NOT_EXIST+" "+entry.getName()); 203 } 204 205 this.entries.put( entry.getName(), entry ); 206 } 207 } 208 209 216 public void addLocalEntry( RegistryEntry entry ) throws InvalidEntryException 217 { 218 219 synchronized (this) 220 { 221 if ( this.hasEntry( entry.getName() ) ) 222 { 223 throw new InvalidEntryException( InvalidEntryException.ENTRY_ALREADY_PRESENT ); 224 } 225 226 this.entries.put( entry.getName(), entry ); 227 } 228 } 229 230 237 public void removeLocalEntry( String name ) 238 { 239 synchronized(this) 240 { 241 this.entries.remove( name ); 242 } 243 } 244 245 252 public void removeLocalEntry( RegistryEntry entry ) 253 { 254 synchronized(this) 255 { 256 this.entries.remove( entry.getName() ); 257 } 258 } 259 260 } 261 | Popular Tags |