1 22 package org.jboss.metadata.plugins.repository.basic; 23 24 import java.util.HashSet ; 25 import java.util.Map ; 26 import java.util.Set ; 27 import java.util.concurrent.ConcurrentHashMap ; 28 29 import org.jboss.metadata.plugins.repository.AbstractMetaDataRepository; 30 import org.jboss.metadata.plugins.repository.visitor.ChildrenMetaDataRepositoryVisitor; 31 import org.jboss.metadata.spi.repository.MutableMetaDataRepository; 32 import org.jboss.metadata.spi.repository.visitor.MetaDataRepositoryVisitor; 33 import org.jboss.metadata.spi.retrieval.MetaDataRetrieval; 34 import org.jboss.metadata.spi.scope.ScopeKey; 35 36 42 public class BasicMetaDataRepository extends AbstractMetaDataRepository implements MutableMetaDataRepository 43 { 44 45 private Map <ScopeKey, MetaDataRetrieval> retrievals = new ConcurrentHashMap <ScopeKey, MetaDataRetrieval>(); 46 47 public MetaDataRetrieval getMetaDataRetrieval(ScopeKey key) 48 { 49 return retrievals.get(key); 50 } 51 52 public Set <ScopeKey> getChildren(ScopeKey key) 53 { 54 if (key == null) 55 return retrievals.keySet(); 56 57 ChildrenMetaDataRepositoryVisitor visitor = new ChildrenMetaDataRepositoryVisitor(key); 58 return matchScopes(visitor); 59 } 60 61 public Set <ScopeKey> matchScopes(MetaDataRepositoryVisitor visitor) 62 { 63 Set <ScopeKey> result = new HashSet <ScopeKey>(); 64 for (ScopeKey repositoryKey : retrievals.keySet()) 65 { 66 if (visitor.matchScope(this, repositoryKey)) 67 result.add(repositoryKey); 68 } 69 return result; 70 } 71 72 public MetaDataRetrieval addMetaDataRetrieval(MetaDataRetrieval retrieval) 73 { 74 if (retrieval == null) 75 throw new IllegalArgumentException ("Null retrieval"); 76 ScopeKey key = retrieval.getScope(); 77 key.freeze(); 78 return retrievals.put(key, retrieval); 79 } 80 81 public MetaDataRetrieval removeMetaDataRetrieval(ScopeKey key) 82 { 83 if (key == null) 84 throw new IllegalArgumentException ("Null key"); 85 return retrievals.remove(key); 86 } 87 } 88 | Popular Tags |