1 /**
2 * $Id: BaseAbstractResourceManager.java 77 2006-12-15 21:36:03Z maldito_orco $
3 * $Revision: 77 $
4 * $Date: 2006-12-15 18:36:03 -0300 (Fri, 15 Dec 2006) $
5 *
6 * =========================================================================
7 *
8 * Copyright 2005 Tubo
9 *
10 * Licensed under the Apache License, Version 2.0 (the "License");
11 * you may not use this file except in compliance with the License.
12 * You may obtain a copy of the License at
13 *
14 * http://www.apache.org/licenses/LICENSE-2.0
15 *
16 * Unless required by applicable law or agreed to in writing, software
17 * distributed under the License is distributed on an "AS IS" BASIS,
18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19 * See the License for the specific language governing permissions and
20 * limitations under the License.
21 */
22 package org.tubo.resource.baseimpl;
23
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28 import org.tubo.resource.ResourceManager;
29 import org.tubo.resource.Manager;
30 import org.tubo.resource.flow.FlowExecutor;
31 import org.tubo.resource.component.ComponentManager;
32 import org.tubo.resource.consumer.ConsumerManager;
33 import org.tubo.configuration.def.Configuration;
34 import org.tubo.configuration.def.ConsumerDef;
35 import org.tubo.exception.TuboResourceException;
36 import org.tubo.exception.ExceptionManager;
37 import org.tubo.exception.TuboException;
38
39 import java.util.List;
40 import java.util.Iterator;
41 import java.util.ArrayList;
42 import java.util.Map;
43
44 /**
45 * Created: Aug 31, 2006, 6:47:45 PM
46 * Last Modification Date: $Date: 2006-12-15 18:36:03 -0300 (Fri, 15 Dec 2006) $
47 *
48 * @author maldito_orco (maldito_orco@users.sourceforge.net)
49 * @version $Revision: 77 $
50 */
51 public abstract class BaseAbstractResourceManager implements ResourceManager {
52 public static final String RCS_ID = "$Id: BaseAbstractResourceManager.java 77 2006-12-15 21:36:03Z maldito_orco $";
53 private static Log log = LogFactory.getLog(BaseAbstractResourceManager.class);
54
55 /** Tubo configuration */
56 private Configuration configuration = null;
57
58 /**
59 * Default constructor protected. Used by test cases.
60 * Don't change. USED ONLY BY TEST CASES!
61 * @throws TuboResourceException
62 */
63 protected BaseAbstractResourceManager() throws TuboException {
64 }
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 /**
124 * Get Configuration object of this resource manager
125 * @return Configuration
126 */
127 public Configuration getConfiguration() throws TuboException {
128 return configuration;
129 }
130
131
132 public void setConfiguration(Configuration configuration) {
133 this.configuration = configuration;
134 }
135
136 /**
137 * Return consumer manager identified by id
138 * @param id ConsumerManager identificator
139 * @return A COnsumerManager
140 */
141 public ConsumerManager getConsumerManager(String id) throws TuboException {
142
143
144 Manager manager = getManager(id);
145
146
147 ConsumerManager consumerManager;
148
149
150 if (manager instanceof ConsumerManager) {
151
152
153 consumerManager = (ConsumerManager)manager;
154 }
155 else
156 throw getExceptionManager().getException(1300,id);
157
158
159 return consumerManager;
160 }
161
162 public List getConsumerManagers() throws TuboException {
163
164
165 List managers = new ArrayList();
166
167
168 Map defs = configuration.getConsumerDefs();
169
170
171 for (Iterator it=defs.values().iterator(); it.hasNext();) {
172 ConsumerDef def = (ConsumerDef)it.next();
173 ConsumerManager manager = getConsumerManager(def.getId());
174 managers.add(manager);
175 }
176
177
178 return managers;
179 }
180
181 /**
182 * This method returns a ComponentManager identified by id
183 * @param id ConsumerManager identifier
184 * @return a ConsumerManager instance
185 */
186 public ComponentManager getComponentManager(String id) throws TuboException {
187
188
189 Manager manager = getManager(id);
190
191
192 ComponentManager componentManager;
193
194
195 if (manager instanceof ComponentManager) {
196
197
198 componentManager = (ComponentManager)manager;
199 }
200 else
201 throw getExceptionManager().getException(1301,id);
202
203
204 return componentManager;
205 }
206
207 }