1 50 51 package org.apache.avalon.meta.info; 52 53 import java.util.Properties ; 54 55 import org.apache.avalon.framework.Version; 56 57 82 public final class DependencyDescriptor extends Descriptor 83 { 84 85 private static final Version DEFAULT_VERSION = Version.getVersion( "1.0" ); 86 87 88 91 private final String m_key; 92 93 96 private final ReferenceDescriptor m_service; 97 98 101 private final boolean m_optional; 102 103 108 public DependencyDescriptor( final String role, String service ) 109 { 110 this( role, service, DEFAULT_VERSION ); 111 } 112 113 118 public DependencyDescriptor( final String role, String service, Version version ) 119 { 120 this( role, new ReferenceDescriptor( service, version ), false, null ); 121 } 122 123 128 public DependencyDescriptor( final String role, 129 final ReferenceDescriptor service ) 130 { 131 this( role, service, false, null ); 132 } 133 134 141 public DependencyDescriptor( final String role, 142 final ReferenceDescriptor service, 143 final boolean optional, 144 final Properties attributes ) 145 { 146 super( attributes ); 147 148 if ( null == role ) 149 { 150 throw new NullPointerException ( "role" ); 151 } 152 153 if ( null == service ) 154 { 155 throw new NullPointerException ( "service" ); 156 } 157 158 m_key = role; 159 m_service = service; 160 m_optional = optional; 161 } 162 163 168 public String getKey() 169 { 170 return m_key; 171 } 172 173 181 public ReferenceDescriptor getService() 182 { 183 return m_service; 184 } 185 186 193 public ReferenceDescriptor getReference() 194 { 195 return m_service; 196 } 197 198 203 public boolean isOptional() 204 { 205 return m_optional; 206 } 207 208 213 public boolean isRequired() 214 { 215 return !isOptional(); 216 } 217 218 public String toString() 219 { 220 return "[" + getKey() + "] " + getReference(); 221 } 222 223 229 public boolean equals( Object other ) 230 { 231 boolean isEqual = super.equals( other ) && other instanceof DependencyDescriptor; 232 if ( other instanceof DependencyDescriptor ) 233 { 234 DependencyDescriptor dep = (DependencyDescriptor) other; 235 236 isEqual = isEqual && m_optional == dep.m_optional; 237 isEqual = isEqual && m_service.equals( dep.m_service ); 238 } 239 240 return isEqual; 241 } 242 243 247 public int hashCode() 248 { 249 int hash = super.hashCode(); 250 hash >>>= 13; 251 hash ^= m_service.hashCode(); 252 hash >>>= ( m_optional ) ? 1 : 0; 253 254 return hash; 255 } 256 257 } 258 | Popular Tags |