KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > plugins > repository > basic > BasicMetaDataRepository


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2006, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.metadata.plugins.repository.basic;
23
24 import java.util.HashSet JavaDoc;
25 import java.util.Map JavaDoc;
26 import java.util.Set JavaDoc;
27 import java.util.concurrent.ConcurrentHashMap JavaDoc;
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 /**
37  * BasicMetaDataRepository.
38  *
39  * @author <a HREF="adrian@jboss.com">Adrian Brock</a>
40  * @version $Revision: 46146 $
41  */

42 public class BasicMetaDataRepository extends AbstractMetaDataRepository implements MutableMetaDataRepository
43 {
44    /** The retrievals */
45    private Map JavaDoc<ScopeKey, MetaDataRetrieval> retrievals = new ConcurrentHashMap JavaDoc<ScopeKey, MetaDataRetrieval>();
46    
47    public MetaDataRetrieval getMetaDataRetrieval(ScopeKey key)
48    {
49       return retrievals.get(key);
50    }
51
52    public Set JavaDoc<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 JavaDoc<ScopeKey> matchScopes(MetaDataRepositoryVisitor visitor)
62    {
63       Set JavaDoc<ScopeKey> result = new HashSet JavaDoc<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 JavaDoc("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 JavaDoc("Null key");
85       return retrievals.remove(key);
86    }
87 }
88
Popular Tags