// 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; /// This reference defines the type of interface required /// by a component. The type corresponds to the class name of the /// interface implemented by component. Associated with each /// classname is a version object so that different versions of same /// interface can be represented. /// /// /// Avalon Development Team /// /// $Revision: 1.3 $ $Date: 2004/02/28 22:15:37 $ /// [Serializable] public sealed class ReferenceDescriptor { /// The service class. private System.Type m_type; /// Construct a service with specified name, version and attributes. /// /// /// the name of the service /// /// the version of service /// /// NullPointerException if the classname or version is null /// /// IllegalArgumentException if the classname string is invalid /// public ReferenceDescriptor(System.Type type) { if (null == (System.Object) type) { throw new System.ArgumentNullException("type"); } m_type = type; } /// /// Return classname of interface this reference refers to. /// /// the classname of the Service /// public System.Type Type { get { return m_type; } } /// Determine if specified service will match this service. /// To match a service has to have same name and must comply with version. /// /// /// the other ServiceInfo /// /// true if matches, false otherwise /// public bool Matches(ReferenceDescriptor other) { return m_type.Equals(other.m_type); } /// Determine if specified service will match this service. /// To match a service has to have same name and must comply with version. /// /// /// the other ServiceInfo /// /// true if matches, false otherwise /// public bool Matches(Service other) { return m_type.Equals(other.Reference.m_type); } /// Convert to a string of format name:version /// /// /// string describing service /// public override System.String ToString() { return Type.FullName; } /// 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 match = false; // // TODO: check validity of the following - this is // assuming the equality is equivalent to compliance // which is not true // if (other is ReferenceDescriptor) { match = ((ReferenceDescriptor) other).Matches(this); } else if (other is Service) { match = ((Service) other).Matches(this); } else if (other is ServiceDescriptor) { match = ((ServiceDescriptor) other).Reference.Matches(this); } return match; } /// Returns the cashcode. /// the hascode value /// public override int GetHashCode() { return Type.GetHashCode(); } } }