001: /*
002: * Copyright 2003 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package velosurf.sql;
018:
019: import java.util.Map;
020: import java.util.Set;
021: import java.util.Collection;
022: import java.sql.SQLException;
023:
024: import velosurf.util.Logger;
025:
026: /**
027: * A wrapper implementing the Map interface for some objets having only getters.
028: * Only <code>get(key)</code> and <code>keySet()</code> are implemented.
029: *
030: * @author <a href=mailto:claude.brisson@gmail.com>Claude Brisson</a>
031: */
032:
033: public class ReadOnlyMap implements Map<String, Object> {
034:
035: /**
036: * Constructor.
037: * @param source the wrapped row handler
038: */
039: public ReadOnlyMap(RowHandler source) {
040: this .source = source;
041: }
042:
043: /**
044: * Not implemented.
045: * @return 0
046: */
047: public int size() {
048: return 0;
049: }
050:
051: /**
052: * Not implemented.
053: * @return false
054: */
055: public boolean isEmpty() {
056: return false;
057: }
058:
059: /**
060: * Not implemented.
061: * @param key
062: * @return false
063: */
064: public boolean containsKey(Object key) {
065: return false;
066: }
067:
068: /**
069: * Not implemented.
070: * @param value
071: * @return false
072: */
073: public boolean containsValue(Object value) {
074: return false;
075: }
076:
077: /**
078: * Get a value by key.
079: * @param key value key
080: * @return value
081: */
082: public Object get(Object key) {
083: try {
084: return source.get((String) key);
085: } catch (SQLException sqle) {
086: Logger.error("Could not retrieve value of key " + key
087: + " on a " + source.getClass().getName());
088: Logger.log(sqle);
089: return null;
090: }
091: }
092:
093: /**
094: * Not implemented.
095: * @param query
096: * @param key
097: * @return null
098: */
099: public Object put(String query, Object key) {
100: return null;
101: }
102:
103: /**
104: * Not implemented.
105: * @param key
106: * @return null
107: */
108: public Object remove(Object key) {
109: return null;
110: }
111:
112: /**
113: * Not implemented.
114: * @param map
115: */
116: public void putAll(Map<? extends String, ? extends Object> map) {
117: }
118:
119: /**
120: * Not implemented.
121: */
122: public void clear() {
123: }
124:
125: /**
126: * Returns the set of keys.
127: * @return the set of keys
128: */
129: public Set<String> keySet() {
130: try {
131: return source.keySet();
132: } catch (SQLException sqle) {
133: Logger.error("Could not retrieve keyset of a "
134: + source.getClass().getName());
135: Logger.log(sqle);
136: return null;
137: }
138: }
139:
140: /**
141: * Not implemented.
142: * @return null
143: */
144: public Collection<Object> values() {
145: return null;
146: }
147:
148: /**
149: * Not implemented.
150: * @return null
151: */
152: public Set<Entry<String, Object>> entrySet() {
153: return null;
154: }
155:
156: private RowHandler source;
157: }
|