KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ibatis > sqlmap > engine > mapping > result > Discriminator


1 package com.ibatis.sqlmap.engine.mapping.result;
2
3 import com.ibatis.sqlmap.engine.impl.SqlMapExecutorDelegate;
4
5 import java.util.Map JavaDoc;
6 import java.util.HashMap JavaDoc;
7 import java.util.Iterator JavaDoc;
8
9 /**
10  * Created by IntelliJ IDEA.
11  * User: cbegin
12  * Date: May 13, 2005
13  * Time: 11:11:05 PM
14  * To change this template use File | Settings | File Templates.
15  */

16 public class Discriminator {
17
18   private SqlMapExecutorDelegate delegate;
19   private ResultMapping resultMapping;
20   private Map JavaDoc subMaps;
21
22   public Discriminator(SqlMapExecutorDelegate delegate, ResultMapping resultMapping) {
23     this.delegate = delegate;
24     this.resultMapping = resultMapping;
25   }
26
27   public void setResultMapping(ResultMapping resultMapping) {
28     this.resultMapping = resultMapping;
29   }
30
31   public ResultMapping getResultMapping() {
32     return resultMapping;
33   }
34
35   public void addSubMap(String JavaDoc discriminatorValue, String JavaDoc resultMapName) {
36     if (subMaps == null) {
37       subMaps = new HashMap JavaDoc();
38     }
39     subMaps.put(discriminatorValue, resultMapName);
40   }
41
42   public ResultMap getSubMap(String JavaDoc s) {
43     return (ResultMap) subMaps.get(s);
44   }
45
46   public void bindSubMaps() {
47     if (subMaps != null) {
48       Iterator JavaDoc keys = subMaps.keySet().iterator();
49       while (keys.hasNext()) {
50         Object JavaDoc key = keys.next();
51         Object JavaDoc id = subMaps.get(key);
52         if(id instanceof String JavaDoc) {
53           subMaps.put(key, delegate.getResultMap((String JavaDoc)id));
54         }
55       }
56     }
57   }
58
59 }
60
Popular Tags