// 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 a value that must be placed /// in components Context. It contains information about; /// /// /// /// Avalon Development Team /// /// $Revision: 1.4 $ $Date: 2004/02/28 22:15:37 $ /// [Serializable] public sealed class EntryDescriptor : Descriptor { /// The name the component uses to lookup entry. private System.String m_key; /// The class/interface of the Entry. private Type m_type; /// True if entry is optional, false otherwise. private bool m_optional; /// Immutable state of the entry. private bool m_volatile; /// An alias to a key. private System.String m_alias; /// Construct an non-volotile required Entry. /// the context entry key /// /// the classname of the context entry /// /// NullPointerException if the key or type value are null /// public EntryDescriptor(System.String key, Type type, System.Reflection.MemberInfo memberinfo) : this(key, type, false, memberinfo) { } /// Construct an non-volotile Entry. /// the context entry key /// /// the classname of the context entry /// /// TRUE if this is an optional entry /// /// NullPointerException if the key or type value are null /// public EntryDescriptor(System.String key, Type type, bool optional, System.Reflection.MemberInfo memberinfo) : this(key, type, optional, false, memberinfo) { } /// Construct an Entry. /// the context entry key /// /// the classname of the context entry /// /// TRUE if this is an optional entry /// /// TRUE if the entry is consider to be immutable /// /// NullPointerException if the key or type value are null /// public EntryDescriptor(System.String key, System.Type type, bool optional, bool isVolatile, System.Reflection.MemberInfo memberinfo) : this(key, type, optional, isVolatile, null, memberinfo) { } /// Construct an Entry. /// the context entry key /// /// the classname of the context entry /// /// TRUE if this is an optional entry /// /// TRUE if the entry is is volatile /// /// an alternative key used by the component to reference the key /// /// NullPointerException if the key or type value are null /// public EntryDescriptor(System.String key, System.Type type, bool optional, bool isVolatile, System.String alias, System.Reflection.MemberInfo memberinfo) : base(null, memberinfo) { if (null == key) { throw new System.ArgumentNullException("key"); } if (null == type) { throw new System.ArgumentNullException("type"); } m_key = key; m_type = type; m_optional = optional; m_volatile = isVolatile; m_alias = alias; } /// Return the key that Component uses to lookup entry. /// /// /// the key that Component uses to lookup entry. /// public System.String Key { get { return m_key; } } /// Return the alias that Component uses to lookup the entry. /// If no alias is declared, the standard lookup key will be /// returned. /// /// /// the alias to the key. /// public System.String Alias { get { if ((System.Object) m_alias != null) { return m_alias; } else { return m_key; } } } /// Return the key type of value that is stored in Context. /// /// /// the key type of value that is stored in Context. /// public System.Type Type { get { return m_type; } } /// Return true if entry is optional, false otherwise. /// /// /// true if entry is optional, false otherwise. /// public bool Optional { get { return m_optional; } } /// Return true if entry is required, false otherwise. /// /// /// true if entry is required, false otherwise. /// public bool Required { get { return !Optional; } } /// Return true if entry is volotile. /// /// /// the volatile state of the entry /// public bool Volatile { get { return m_volatile; } } /// Test is the supplied object is equal to this object. /// the object to compare with this instance /// /// true if the object are equivalent /// public override bool Equals(System.Object other) { bool isEqual = other is EntryDescriptor; if (isEqual) { EntryDescriptor entry = (EntryDescriptor) other; isEqual = isEqual && m_key.Equals(entry.m_key); isEqual = isEqual && m_type.Equals(entry.m_type); isEqual = isEqual && m_optional == entry.m_optional; isEqual = isEqual && m_volatile == entry.m_volatile; if (null == (System.Object) m_alias) { isEqual = isEqual && null == (System.Object) entry.m_alias; } else { isEqual = isEqual && m_alias.Equals(entry.m_alias); } } return isEqual; } /// Return the hashcode for the object. /// the hashcode value /// public override int GetHashCode() { int hash = base.GetHashCode(); hash ^= m_key.GetHashCode(); hash ^= m_type.GetHashCode(); hash ^= ((null != (System.Object) m_alias)?m_alias.GetHashCode():0); return hash; } } }