// Copyright 2003-2004 The Apache Software Foundation // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. namespace Apache.Avalon.Meta { using System; using Apache.Avalon.Framework; /// A descriptor that describes dependency information for /// a particular Component. This class contains information /// about; /// /// ///

Also associated with each dependency is a set of arbitrary /// attributes that can be used to store extra information /// about dependency. See {@link InfoDescriptor} for example /// of how to declare the container specific attributes.

/// ///

Possible uses for the attributes are to declare container /// specific constraints of component. For example a dependency on /// a Corba ORB may also require that the Corba ORB contain the /// TimeServer and PersistenceStateService at initialization. Or it /// may require that the componenet be multi-thread safe or that /// it is persistent etc. These are all container specific /// demands.

///
[Serializable] public sealed class DependencyDescriptor : Descriptor { /// The name the component uses to lookup dependency. private System.String m_key; /// The service class/interface that the dependency must provide. private ReferenceDescriptor m_service; /// True if dependency is optional, false otherwise. private bool m_optional; /// Creation of a new dependency descriptor using the default 1.0 version /// the role name that will be used by the type when looking up a service /// /// the interface service /// public DependencyDescriptor(System.String role, System.Type service, System.Reflection.MemberInfo memberinfo) : this(role, new ReferenceDescriptor( service ), memberinfo ) { } /// Creation of a new dependency descriptor. /// the role name that will be used by the type when looking up a service /// /// the version insterface service reference /// public DependencyDescriptor(System.String role, ReferenceDescriptor service, System.Reflection.MemberInfo memberinfo) : this(role, service, false, null, memberinfo) { } /// Creation of a new dependency descriptor. /// the role name that will be used by the type when looking up a service /// /// the version insterface service reference /// /// TRUE if this depedency is optional /// /// a set of attributes to associate with the dependency /// public DependencyDescriptor(System.String role, ReferenceDescriptor service, bool optional, System.Collections.Specialized.NameValueCollection attributes, System.Reflection.MemberInfo memberinfo) : base(attributes, memberinfo) { if (null == (System.Object) role) { throw new System.NullReferenceException("role"); } if (null == service) { throw new System.NullReferenceException("service"); } m_key = role; m_service = service; m_optional = optional; } /// Return the name the component uses to lookup the dependency. /// /// /// the name the component uses to lookup the dependency. /// public System.String Key { get { return m_key; } } /// Return the service interface descriptor that describes the /// dependency that the provider provides. /// /// /// a reference to service reference that describes the fulfillment /// obligations that must be met by a service provider. /// /// use getReference() /// public ReferenceDescriptor Service { get { return m_service; } } /// Return true if dependency is optional, false otherwise. /// /// /// true if dependency is optional, false otherwise. /// public bool Optional { get { return m_optional; } } /// Return true if dependency is required, false otherwise. /// /// /// true if dependency is required, false otherwise. /// public bool Required { get { return !Optional; } } public override System.String ToString() { return "[" + Key + "] " + Service; } /// Compare this object with another for equality. /// the object to compare this object with /// /// TRUE if the supplied object is a reference, service, or service /// descriptor that matches this objct in terms of classname and version /// public override bool Equals(System.Object other) { bool isEqual = base.Equals(other) && other is DependencyDescriptor; if (other is DependencyDescriptor) { DependencyDescriptor dep = (DependencyDescriptor) other; isEqual = isEqual && m_optional == dep.m_optional; isEqual = isEqual && m_service.Equals(dep.m_service); } return isEqual; } /// Return the hashcode for the object. /// the hashcode value /// public override int GetHashCode() { int hash = base.GetHashCode(); hash ^= m_service.GetHashCode(); return hash; } } }