KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > vfs > metadata > ResourceLookup


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.vfs.metadata;
20
21 import java.util.Collection JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.Set JavaDoc;
24
25 /**
26  * The ResourceLookup class provides a store of objects which can be
27  * requested out by either their full path or their fully qualified name,
28  * i.e. their namespace#name.
29  *
30  * @author Matthew Large
31  * @version $Revision: 1.1 $
32  *
33  */

34 public class ResourceLookup {
35
36     /**
37      * Map of fully qualified names to objects.
38      */

39     HashMap JavaDoc m_qnameLookup = null;
40     
41     /**
42      * Map of full paths to objects.
43      */

44     HashMap JavaDoc m_hrefLookup = null;
45     
46     /**
47      * Map of fully qualified names to full paths.
48      */

49     HashMap JavaDoc m_qname2href = null;
50     
51     /**
52      * Map of full paths to fully qualified names.
53      */

54     HashMap JavaDoc m_href2qname = null;
55
56     /**
57      * Constructs a new ResoruceLookup
58      *
59      * @param nInitialSize Initial size
60      */

61     public ResourceLookup(int nInitialSize) {
62         super();
63         m_qnameLookup = new HashMap JavaDoc(nInitialSize);
64         m_hrefLookup = new HashMap JavaDoc(nInitialSize);
65         m_qname2href = new HashMap JavaDoc(nInitialSize);
66         m_href2qname = new HashMap JavaDoc(nInitialSize);
67     }
68     
69     /**
70      * Adds a new object to the lookup.
71      *
72      * @param sQName Fully qualified name
73      * @param sHREF Full path
74      * @param obj Object
75      */

76     public void put(String JavaDoc sQName, String JavaDoc sHREF, Object JavaDoc obj) {
77         this.m_qnameLookup.put(sQName, obj);
78         this.m_hrefLookup.put(sHREF, obj);
79         this.m_qname2href.put(sQName, sHREF);
80         this.m_href2qname.put(sHREF, sQName);
81     }
82     
83     /**
84      * Returns a fully qualified name for a given full path.
85      *
86      * @param sHref Full path
87      * @return Fully qualified name or null if not found
88      */

89     public String JavaDoc getQName(String JavaDoc sHref) {
90         return (String JavaDoc) this.m_href2qname.get(sHref);
91     }
92     
93     /**
94      * Returns a full path for a given fully qualified name.
95      *
96      * @param sQName Fully qualified name
97      * @return Full path or null if not found
98      */

99     public String JavaDoc getHref(String JavaDoc sQName) {
100         return (String JavaDoc) this.m_qname2href.get(sQName);
101     }
102     
103     /**
104      * Returns an object for a given fully qualified name.
105      *
106      * @param sQName Fully qualified name
107      * @return Object or null if not found
108      */

109     public Object JavaDoc getByQName(String JavaDoc sQName) {
110         return this.m_qnameLookup.get(sQName);
111     }
112     
113     /**
114      * Returns an object for a given full path.
115      *
116      * @param sHREF Full path
117      * @return Object or null if not found
118      */

119     public Object JavaDoc getByHREF(String JavaDoc sHREF) {
120         return this.m_hrefLookup.get(sHREF);
121     }
122     
123     /**
124      * Removes an object for a given fully qualified name.
125      *
126      * @param sQName Fully qualified name
127      */

128     public void removeByQName(String JavaDoc sQName) {
129         Object JavaDoc obj = this.m_qnameLookup.get(sQName);
130         if(obj!=null) {
131             this.m_qnameLookup.remove(obj);
132             this.m_hrefLookup.remove(obj);
133         }
134     }
135     
136     /**
137      * Remove an object for a given full path.
138      *
139      * @param sHREF Full path
140      */

141     public void removeByHREF(String JavaDoc sHREF) {
142         Object JavaDoc obj = this.m_hrefLookup.get(sHREF);
143         if(obj!=null) {
144             Object JavaDoc objcheck = this.m_hrefLookup.remove(sHREF);
145             if(objcheck==null) {
146                 System.err.println("Object removal for href[" + sHREF + "] is null!!! " + this.m_hrefLookup.keySet());
147             }
148             objcheck = this.m_qnameLookup.remove(((Property)obj).getNamespace()+"#"+((Property)obj).getName());
149             if(objcheck==null) {
150                 System.err.println("Object removal for href[" + ((Property)obj).getNamespace()+"#"+((Property)obj).getName() + "] is null!!! " + this.m_qnameLookup.keySet());
151             }
152         }
153     }
154     
155     /**
156      * Removes a given object.
157      *
158      * @param obj Object
159      */

160     public void remove(Object JavaDoc obj) {
161         this.m_qnameLookup.remove(obj);
162         this.m_hrefLookup.remove(obj);
163     }
164     
165     /**
166      * Returns all the values in this ResourceLookup.
167      *
168      * @return Collection of objects
169      */

170     public Collection JavaDoc getValues() {
171         return this.m_hrefLookup.values();
172     }
173     
174     /**
175      * Returns all the fully qualified names in this ResourceLookup.
176      *
177      * @return Set of fully qualified names
178      */

179     public Set JavaDoc getQNameKeySet() {
180         return this.m_qnameLookup.keySet();
181     }
182     
183     /**
184      * Returns all the full paths in this ResoruceLookup.
185      *
186      * @return Set of full paths
187      */

188     public Set JavaDoc getHREFKeySet() {
189         return this.m_hrefLookup.keySet();
190     }
191
192 }
193
Popular Tags