1 /***
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is pow2WebGui library.
13 *
14 * The Initial Owner of the Original Code is Power Of Two S.R.L.
15 * Portions created by Power Of Two S.R.L. are Copyright (C) Power Of Two S.R.L.
16 * All Rights Reserved.
17 *
18 * Contributor(s):
19 */
20
21 package com.pow2.webgui;
22
23 import java.util.HashMap;
24
25
26
27 import com.pow2.util.ReflectionUtil;
28 import com.pow2.webgui.contentprovider.BaseContentProvider;
29
30
31 /***
32 * WidgetInfo class.
33 *
34 * @author Luca Fossato
35 * @created 1 luglio 2002
36 */
37 public class WidgetInfo
38 {
39 /*** Log4j category */
40
41
42 private String name;
43 private String className;
44 private HashMap drawerMap;
45 private HashMap contentProviderMap;
46
47
48 /***
49 * Default constructor.
50 */
51 public WidgetInfo()
52 {
53 drawerMap = new HashMap();
54 contentProviderMap = new HashMap();
55 }
56
57
58 /***
59 * Gets the className attribute of the WidgetInfo object
60 *
61 * @return The className value
62 */
63 public String getClassName()
64 {
65 return className;
66 }
67
68
69 /***
70 * Gets the name attribute of the WidgetInfo object
71 *
72 * @return The name value
73 */
74 public String getName()
75 {
76 return name;
77 }
78
79
80 /***
81 * Sets the className attribute of the WidgetInfo object
82 *
83 * @param className The new className value
84 */
85 public void setClassName(String className)
86 {
87 this.className = className;
88 }
89
90
91 /***
92 * Sets the name attribute of the WidgetInfo object
93 *
94 * @param name The new name value
95 */
96 public void setName(String name)
97 {
98 this.name = name;
99 }
100
101
102 /***
103 * Get the ContentProvider instance registered using the input key.
104 *
105 * @param key the key used to register the ContentProvider class name into
106 * the contentProvider map
107 * @return the ContentProvider instance registered using the input key
108 * @exception Exception if any error occurs
109 */
110 public BaseContentProvider getContentProvider(String key, Widget w) throws Exception
111 {
112 BaseContentProvider cp = null;
113 String cpName = null;
114
115 if ((cpName = (String)contentProviderMap.get(key)) == null)
116 throw new Exception("cannot retrieve the contentProvider having key [" + key + "]");
117
118
119 return (BaseContentProvider)ReflectionUtil.instanceObject(cpName, new Class[]{Widget.class}, new Object[]{w});
120 }
121
122
123 /***
124 * Set a contentProvider class name into the drawer map.
125 *
126 * @param key the key used to register the contentProvider into the map
127 * @param className the contentProvider class name
128 */
129 public void setContentProvider(String key, String className)
130 {
131 contentProviderMap.put(key, className);
132 }
133
134
135 /***
136 * Get the WidgetDrawer instance registered using the input key.
137 *
138 * @param key the key used to register the WidgetDrawer class name into
139 * the drawerMap
140 * @return the WidgetDrawer instance registered using the input key
141 * @exception Exception if any error occurs
142 */
143 public WidgetDrawer getWidgetDrawer(String key, Widget w) throws Exception
144 {
145 WidgetDrawer d = null;
146 String dName = null;
147
148 if ((dName = (String)drawerMap.get(key)) == null)
149 throw new Exception("cannot retrieve the drawer having key [" + key + "]");
150
151
152 return (WidgetDrawer)ReflectionUtil.instanceObject(dName, new Class[]{Widget.class}, new Object[]{w});
153 }
154
155
156 /***
157 * Set a widgetDrawer class name into the drawer map.
158 *
159 * @param key the key used to register the drawer into the map
160 * @param className the WidgetDrawer class name
161 */
162 public void setWidgetDrawer(String key, String className)
163 {
164 drawerMap.put(key, className);
165 }
166 }