View Javadoc
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   * Licensed to the Apache Software Foundation (ASF) under one
12   * or more contributor license agreements.  See the NOTICE file
13   * distributed with this work for additional information
14   * regarding copyright ownership.  The ASF licenses this file
15   * to you under the Apache License, Version 2.0 (the
16   * "License"); you may not use this file except in compliance
17   * with the License.  You may obtain a copy of the License at
18   *
19   *   http://www.apache.org/licenses/LICENSE-2.0
20   *
21   * Unless required by applicable law or agreed to in writing,
22   * software distributed under the License is distributed on an
23   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
24   * KIND, either express or implied.  See the License for the
25   * specific language governing permissions and limitations
26   * under the License.
27   */
28  
29  /**
30   * Interface exposed by the ServiceContainerImpl
31   *
32   * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a>
33   */
34  
35  public class RoleEntryImpl implements RoleEntry {
36  	/** the name of the service component to be used for the service lookup */
37  	private String name;
38  
39  	/** the name of the implementation class of the service component */
40  	private String implementationClazzName;
41  
42  	/** the short name of the service component to lookup the configuration */
43  	private String shorthand;
44  
45  	/** do we incarnate the instance of the service component during start-up? */
46  	private boolean isEarlyInit;
47  
48  	/** a description for the service component if any */
49  	private String description;
50  
51  	/** the type of service component, e.g. "avalon" */
52  	private String componentType;
53  
54  	/**
55  	 * the type of service component if any, e.g. "merlin", "phoenix" or "fortress
56  	 */
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<String> 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
72  	 *                         service lookup
73  	 * @param defaultClass     the name of the implementation class of the service
74  	 *                         component
75  	 * @param shorthand        the short name of the service component
76  	 * @param earlyInit        do we incarnate the instance of the service component
77  	 *                         during start-up?
78  	 * @param description      a description for the service component if any
79  	 * @param componentType    the type of service component
80  	 * @param componentFlavour the flavour of the gicen component type
81  	 * @param hasProxy         create a dynamic proxy
82  	 * @param interceptorList  the list of service interceptor to be invoked
83  	 * @param logCategory      the category for creating the logger
84  	 */
85  	public RoleEntryImpl(String name, String defaultClass, String shorthand, boolean earlyInit, String description,
86  			String componentType, String componentFlavour, boolean hasProxy, ArrayList<String> interceptorList,
87  			String logCategory) {
88  		Validate.notEmpty(name, "name");
89  		Validate.notEmpty(defaultClass, "defaultClass");
90  		Validate.notEmpty(shorthand, "shorthand");
91  		Validate.notEmpty(componentType, "componentType");
92  		Validate.notEmpty(componentFlavour, "componentFlavour");
93  		Validate.notNull(interceptorList, "interceptorList");
94  		Validate.notEmpty(logCategory, "logCategory");
95  
96  		this.name = name;
97  		this.implementationClazzName = defaultClass;
98  		this.shorthand = shorthand;
99  		this.isEarlyInit = earlyInit;
100 		this.description = description;
101 		this.componentType = componentType;
102 		this.componentFlavour = componentFlavour;
103 		this.hasDynamicProxy = hasProxy;
104 		this.interceptorList = interceptorList;
105 		this.logCategory = logCategory;
106 	}
107 
108 	/**
109 	 * @return Returns the componentType.
110 	 */
111 	public String getComponentType() {
112 		return componentType;
113 	}
114 
115 	/**
116 	 * @return Returns the description.
117 	 */
118 	public String getDescription() {
119 		return description;
120 	}
121 
122 	/**
123 	 * @return Returns the implementationClazzName.
124 	 */
125 	public String getImplementationClazzName() {
126 		return implementationClazzName;
127 	}
128 
129 	/**
130 	 * @return Returns the isEarlyInit.
131 	 */
132 	public boolean isEarlyInit() {
133 		return isEarlyInit;
134 	}
135 
136 	/**
137 	 * @return Returns the name.
138 	 */
139 	public String getName() {
140 		return name;
141 	}
142 
143 	/**
144 	 * @return Returns the shorthand.
145 	 */
146 	public String getShorthand() {
147 		return shorthand;
148 	}
149 
150 	/**
151 	 * @return Returns the componentFlavour.
152 	 */
153 	public String getComponentFlavour() {
154 		return componentFlavour;
155 	}
156 
157 	/**
158 	 * @return Returns the hasDynamicProxy.
159 	 */
160 	public boolean hasDynamicProxy() {
161 		return hasDynamicProxy;
162 	}
163 
164 	/**
165 	 * @param hasProxy The hasDynamicProxy to set.
166 	 */
167 	public void setHasDynamicProxy(boolean hasProxy) {
168 		this.hasDynamicProxy = hasProxy;
169 	}
170 
171 	/**
172 	 * Determines if the given name of the interceptor is already defined.
173 	 *
174 	 * @param interceptorName the name of the interceptor
175 	 * @return true if it is already defined
176 	 */
177 	public boolean hasInterceptor(String interceptorName) {
178 		String currInterceptorName = null;
179 		Iterator<String> iterator = this.interceptorList.iterator();
180 
181 		while (iterator.hasNext()) {
182 			currInterceptorName = iterator.next();
183 
184 			if (currInterceptorName.equals(interceptorName)) {
185 				return true;
186 			}
187 		}
188 
189 		return false;
190 	}
191 
192 	/**
193 	 * Adds all given interceptors but avoiding duplicates.
194 	 *
195 	 * @param collection the interceptors to be added
196 	 */
197 	public void addInterceptors(Collection<?> collection) {
198 		String currInterceptorName = null;
199 		Iterator<?> iterator = collection.iterator();
200 
201 		while (iterator.hasNext()) {
202 			currInterceptorName = (String) iterator.next();
203 
204 			if (this.hasInterceptor(currInterceptorName) == false) {
205 				this.interceptorList.add(currInterceptorName);
206 			}
207 		}
208 	}
209 
210 	/**
211 	 * @return Returns the interceptorList.
212 	 */
213 	public String[] getInterceptorList() {
214 		return interceptorList.toArray(new String[interceptorList.size()]);
215 	}
216 
217 	/**
218 	 * @return Returns the logCategory.
219 	 */
220 	public String getLogCategory() {
221 		return logCategory;
222 	}
223 
224 	/**
225 	 * @see java.lang.Object#toString()
226 	 */
227 	public String toString() {
228 		ToStringBuilder toStringBuilder = new ToStringBuilder(this);
229 		toStringBuilder.append("name", this.name);
230 		toStringBuilder.append("shorthand", this.shorthand);
231 		toStringBuilder.append("implementationClazzName", this.implementationClazzName);
232 		toStringBuilder.append("isEarlyInit", this.isEarlyInit);
233 		toStringBuilder.append("hasDynamicProxy", this.hasDynamicProxy);
234 		toStringBuilder.append("componentType", this.componentType);
235 		toStringBuilder.append("componentFlavour", this.componentFlavour);
236 		toStringBuilder.append("interceptorList", this.interceptorList);
237 		toStringBuilder.append("logCategory", this.logCategory);
238 		toStringBuilder.append("description", this.description);
239 		return toStringBuilder.toString();
240 	}
241 }