001 package org.apache.fulcrum.yaafi.framework.role; 002 003 import java.util.ArrayList; 004 import java.util.Collection; 005 import java.util.Iterator; 006 007 import org.apache.fulcrum.yaafi.framework.util.ToStringBuilder; 008 import org.apache.fulcrum.yaafi.framework.util.Validate; 009 010 /* 011 * Licensed to the Apache Software Foundation (ASF) under one 012 * or more contributor license agreements. See the NOTICE file 013 * distributed with this work for additional information 014 * regarding copyright ownership. The ASF licenses this file 015 * to you under the Apache License, Version 2.0 (the 016 * "License"); you may not use this file except in compliance 017 * with the License. You may obtain a copy of the License at 018 * 019 * http://www.apache.org/licenses/LICENSE-2.0 020 * 021 * Unless required by applicable law or agreed to in writing, 022 * software distributed under the License is distributed on an 023 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 024 * KIND, either express or implied. See the License for the 025 * specific language governing permissions and limitations 026 * under the License. 027 */ 028 029 030 /** 031 * Interface exposed by the ServiceContainerImpl 032 * 033 * @author <a href="mailto:siegfried.goeschl@it20one.at">Siegfried Goeschl</a> 034 */ 035 036 public class RoleEntryImpl implements RoleEntry 037 { 038 /** the name of the service component to be used for the service lookup */ 039 private String name; 040 041 /** the name of the implementation class of the service component */ 042 private String implementationClazzName; 043 044 /** the short name of the service component to lookup the configuration */ 045 private String shorthand; 046 047 /** do we incarnate the instance of the service component during start-up? */ 048 private boolean isEarlyInit; 049 050 /** a description for the service component if any */ 051 private String description; 052 053 /** the type of service component, e.g. "avalon" */ 054 private String componentType; 055 056 /** the type of service component if any, e.g. "merlin", "phoenix" or "fortress*/ 057 private String componentFlavour; 058 059 /** do we use a dynamic proxy when invoking the service */ 060 private boolean hasDynamicProxy; 061 062 /** the list of interceptors to be invoked when using a dynamic proxy */ 063 private ArrayList interceptorList; 064 065 /** the optional category for creating a logger */ 066 private String logCategory; 067 068 /** 069 * YAAFI role entry 070 * 071 * @param name the name of the service component to be used for the service lookup 072 * @param defaultClass the name of the implementation class of the service component 073 * @param shorthand the short name of the service component 074 * @param earlyInit do we incarnate the instance of the service component during start-up? 075 * @param description a description for the service component if any 076 * @param componentType the type of service component 077 * @param componentFlavour the flavour of the gicen component type 078 * @param hasProxy create a dynamic proxy 079 * @param interceptorList the list of service interceptor to be invoked 080 * @param logCategory the category for creating the logger 081 */ 082 public RoleEntryImpl( String name, 083 String defaultClass, 084 String shorthand, 085 boolean earlyInit, 086 String description, 087 String componentType, 088 String componentFlavour, 089 boolean hasProxy, 090 ArrayList interceptorList, 091 String logCategory 092 ) 093 { 094 Validate.notEmpty(name,"name"); 095 Validate.notEmpty(defaultClass,"defaultClass"); 096 Validate.notEmpty(shorthand,"shorthand"); 097 Validate.notEmpty(componentType,"componentType"); 098 Validate.notEmpty(componentFlavour,"componentFlavour"); 099 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 }