KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > param > SqlValueMap


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.param;
14
15 import java.util.Collection JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Map JavaDoc;
18 import java.util.Set JavaDoc;
19
20 /**
21  * implements a map that maps to the sqlValue property of
22  * the SessionParam's in the SessionParamPool.
23  * Not all methods are implemented but enough to use
24  * the map as a generic target for wcf forms.
25  * <p />
26  * In a wcf:form xml definition, e.g. you can set the modelReference
27  * attribute to "sqlValue.foo". Then the user will be able to
28  * change the sqlValue of the SessionParam named "foo".
29  * <p/>
30  * If you put a value into the map, the corresponding SqlParam
31  * will be created.
32  *
33  * @author av
34  */

35 public class SqlValueMap implements Map JavaDoc {
36   
37   private SessionParamPool pool;
38
39   SqlValueMap(SessionParamPool pool) {
40     this.pool = pool;
41   }
42
43   public int size() {
44     return pool.size();
45   }
46
47   public void clear() {
48     pool.clear();
49   }
50   
51   public boolean isEmpty() {
52     return pool.isEmpty();
53   }
54
55   public boolean containsKey(Object JavaDoc key) {
56     return pool.getParam(String.valueOf(key)) != null;
57   }
58
59   public boolean containsValue(Object JavaDoc value) {
60     throw new UnsupportedOperationException JavaDoc();
61   }
62
63   public Collection JavaDoc values() {
64     throw new UnsupportedOperationException JavaDoc();
65   }
66
67   public void putAll(Map JavaDoc t) {
68     for (Iterator JavaDoc it = t.entrySet().iterator(); it.hasNext();) {
69       Map.Entry JavaDoc e = (Entry) it.next();
70       this.put(e.getKey(), e.getValue());
71     }
72   }
73
74   public Set JavaDoc entrySet() {
75     throw new UnsupportedOperationException JavaDoc();
76   }
77
78   public Set JavaDoc keySet() {
79     throw new UnsupportedOperationException JavaDoc();
80   }
81
82   public Object JavaDoc get(Object JavaDoc key) {
83     SessionParam p = pool.getParam((String JavaDoc)key);
84     if (p == null)
85       return null;
86     return p.getSqlValue();
87   }
88
89   public Object JavaDoc remove(Object JavaDoc key) {
90     SessionParam p = (SessionParam) pool.removeParam(String.valueOf(key));
91     if (p == null)
92       return null;
93     return p.getSqlValue();
94   }
95
96   public Object JavaDoc put(Object JavaDoc key, Object JavaDoc value) {
97     SessionParam p = (SessionParam) pool.getParam(String.valueOf(key));
98     if (p == null)
99       p = new SessionParam();
100     Object JavaDoc ret = p.getSqlValue();
101     p.setName(String.valueOf(key));
102     p.setSqlValue(value);
103     pool.setParam(p);
104     return ret;
105   }
106
107 }
108
Popular Tags