01: /* ComponentInfo.java
02:
03: {{IS_NOTE
04: Purpose:
05:
06: Description:
07:
08: History:
09: Aug 10, 2007 11:37:02 AM 2007, Created by Dennis.Chen
10: }}IS_NOTE
11:
12: Copyright (C) 2007 Potix Corporation. All Rights Reserved.
13:
14: {{IS_RIGHT
15: This program is distributed under GPL Version 2.0 in the hope that
16: it will be useful, but WITHOUT ANY WARRANTY.
17: }}IS_RIGHT
18: */
19: package org.zkoss.jsf.zul.impl;
20:
21: import java.util.HashMap;
22: import java.util.LinkedList;
23: import java.util.List;
24: import java.util.Map;
25:
26: /**
27: *
28: * This Class handle information for ZULJSF Components, for construct ZULJSF Component tree.
29: *
30: * @author Dennis.Chen
31: *
32: */
33: /*package*/class ComponentInfo {
34:
35: /**
36: * keep parent-children relation.
37: */
38: private Map childrenMap = new HashMap();
39:
40: /**
41: * keep temporary id - component relation.
42: */
43: private Map componentMap = new HashMap();
44:
45: /**
46: * Add component - child mapping for zuljsf component.
47: * @param parent a parent
48: * @param child the children.
49: */
50: /*package*/void addChildInfo(AbstractComponent parent,
51: AbstractComponent child) {
52: List children = (List) childrenMap.get(parent);
53: if (children == null) {
54: children = new LinkedList();
55: childrenMap.put(parent, children);
56: }
57: if (children.indexOf(child) == -1) {
58: children.add(child);
59: }
60: }
61:
62: /**
63: * get children of parent
64: * @param parent the parent
65: * @return
66: */
67: /*package*/List getChildrenInfo(AbstractComponent parent) {
68: return (List) childrenMap.get(parent);
69: }
70:
71: /**
72: * register ZULJSF Component to ComponentInfo, a temporary id will be associated to this component
73: * @param comp a component
74: * @return a temporary id for this ComponentInfo.
75: */
76: /*package*/String registerComponent(AbstractComponent comp) {
77: String nid = nextId();
78: componentMap.put(nid, comp);
79: return nid;
80: }
81:
82: /**
83: * get back the Component with temporary id
84: * @param a temporary id.
85: * @return
86: */
87: /*package*/AbstractComponent getRegistedComponent(String nid) {
88: return (AbstractComponent) componentMap.get(nid);
89: }
90:
91: private int nextid = 1;
92:
93: synchronized private String nextId() {
94: return "c_" + (nextid++);
95:
96: }
97:
98: }
|