1 package org.apache.fulcrum.yaafi.framework.role;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Iterator;
6
7 import org.apache.fulcrum.yaafi.framework.util.ToStringBuilder;
8 import org.apache.fulcrum.yaafi.framework.util.Validate;
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30 /**
31 * Interface exposed by the ServiceContainerImpl
32 *
33 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
34 */
35
36 public class RoleEntryImpl implements RoleEntry
37 {
38 /** the name of the service component to be used for the service lookup */
39 private String name;
40
41 /** the name of the implementation class of the service component */
42 private String implementationClazzName;
43
44 /** the short name of the service component to lookup the configuration */
45 private String shorthand;
46
47 /** do we incarnate the instance of the service component during start-up? */
48 private boolean isEarlyInit;
49
50 /** a description for the service component if any */
51 private String description;
52
53 /** the type of service component, e.g. "avalon" */
54 private String componentType;
55
56 /** the type of service component if any, e.g. "merlin", "phoenix" or "fortress*/
57 private String componentFlavour;
58
59 /** do we use a dynamic proxy when invoking the service */
60 private boolean hasDynamicProxy;
61
62 /** the list of interceptors to be invoked when using a dynamic proxy */
63 private ArrayList interceptorList;
64
65 /** the optional category for creating a logger */
66 private String logCategory;
67
68 /**
69 * YAAFI role entry
70 *
71 * @param name the name of the service component to be used for the service lookup
72 * @param defaultClass the name of the implementation class of the service component
73 * @param shorthand the short name of the service component
74 * @param earlyInit do we incarnate the instance of the service component during start-up?
75 * @param description a description for the service component if any
76 * @param componentType the type of service component
77 * @param componentFlavour the flavour of the gicen component type
78 * @param hasProxy create a dynamic proxy
79 * @param interceptorList the list of service interceptor to be invoked
80 * @param logCategory the category for creating the logger
81 */
82 public RoleEntryImpl( String name,
83 String defaultClass,
84 String shorthand,
85 boolean earlyInit,
86 String description,
87 String componentType,
88 String componentFlavour,
89 boolean hasProxy,
90 ArrayList interceptorList,
91 String logCategory
92 )
93 {
94 Validate.notEmpty(name,"name");
95 Validate.notEmpty(defaultClass,"defaultClass");
96 Validate.notEmpty(shorthand,"shorthand");
97 Validate.notEmpty(componentType,"componentType");
98 Validate.notEmpty(componentFlavour,"componentFlavour");
99 Validate.notNull(interceptorList,"interceptorList");
100 Validate.notEmpty(logCategory,"logCategory");
101
102 this.name = name;
103 this.implementationClazzName = defaultClass;
104 this.shorthand = shorthand;
105 this.isEarlyInit = earlyInit;
106 this.description = description;
107 this.componentType = componentType;
108 this.componentFlavour = componentFlavour;
109 this.hasDynamicProxy = hasProxy;
110 this.interceptorList = interceptorList;
111 this.logCategory = logCategory;
112 }
113
114 /**
115 * @return Returns the componentType.
116 */
117 public String getComponentType()
118 {
119 return componentType;
120 }
121
122 /**
123 * @return Returns the description.
124 */
125 public String getDescription()
126 {
127 return description;
128 }
129
130 /**
131 * @return Returns the implementationClazzName.
132 */
133 public String getImplementationClazzName()
134 {
135 return implementationClazzName;
136 }
137
138 /**
139 * @return Returns the isEarlyInit.
140 */
141 public boolean isEarlyInit()
142 {
143 return isEarlyInit;
144 }
145
146 /**
147 * @return Returns the name.
148 */
149 public String getName()
150 {
151 return name;
152 }
153
154 /**
155 * @return Returns the shorthand.
156 */
157 public String getShorthand()
158 {
159 return shorthand;
160 }
161
162 /**
163 * @return Returns the componentFlavour.
164 */
165 public String getComponentFlavour()
166 {
167 return componentFlavour;
168 }
169
170 /**
171 * @return Returns the hasDynamicProxy.
172 */
173 public boolean hasDynamicProxy()
174 {
175 return hasDynamicProxy;
176 }
177
178 /**
179 * @param hasProxy The hasDynamicProxy to set.
180 */
181 public void setHasDynamicProxy(boolean hasProxy)
182 {
183 this.hasDynamicProxy = hasProxy;
184 }
185
186 /**
187 * Determines if the given name of the interceptor is already defined.
188 *
189 * @param interceptorName the name of the interceptor
190 * @return true if it is already defined
191 */
192 public boolean hasInterceptor( String interceptorName )
193 {
194 String currInterceptorName = null;
195 Iterator iterator = this.interceptorList.iterator();
196
197 while( iterator.hasNext() )
198 {
199 currInterceptorName = (String) iterator.next();
200
201 if( currInterceptorName.equals(interceptorName) )
202 {
203 return true;
204 }
205 }
206
207 return false;
208 }
209
210 /**
211 * Adds all given interceptors but avoiding duplicates.
212 *
213 * @param collection the interceptors to be added
214 */
215 public void addInterceptors( Collection collection )
216 {
217 String currInterceptorName = null;
218 Iterator iterator = collection.iterator();
219
220 while( iterator.hasNext() )
221 {
222 currInterceptorName = (String) iterator.next();
223
224 if( this.hasInterceptor(currInterceptorName) == false )
225 {
226 this.interceptorList.add(currInterceptorName);
227 }
228 }
229 }
230
231 /**
232 * @return Returns the interceptorList.
233 */
234 public String[] getInterceptorList()
235 {
236 return (String[]) interceptorList.toArray(
237 new String[interceptorList.size()]
238 );
239 }
240
241 /**
242 * @return Returns the logCategory.
243 */
244 public String getLogCategory()
245 {
246 return logCategory;
247 }
248
249 /**
250 * @see java.lang.Object#toString()
251 */
252 public String toString()
253 {
254 ToStringBuilder toStringBuilder = new ToStringBuilder(this);
255 toStringBuilder.append("name",this.name);
256 toStringBuilder.append("shorthand",this.shorthand);
257 toStringBuilder.append("implementationClazzName",this.implementationClazzName);
258 toStringBuilder.append("isEarlyInit",this.isEarlyInit);
259 toStringBuilder.append("hasDynamicProxy",this.hasDynamicProxy);
260 toStringBuilder.append("componentType",this.componentType);
261 toStringBuilder.append("componentFlavour",this.componentFlavour);
262 toStringBuilder.append("interceptorList",this.interceptorList);
263 toStringBuilder.append("logCategory",this.logCategory);
264 toStringBuilder.append("description",this.description);
265 return toStringBuilder.toString();
266 }
267 }