// 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 System.Reflection; using Apache.Avalon.Framework; /// This is the Abstract class for all feature feature descriptors. /// /// /// Avalon Development Team /// /// $Revision: 1.4 $ $Date: 2004/02/28 22:15:37 $ /// [Serializable] public abstract class Descriptor { private static readonly System.String[] EMPTY_SET = new System.String[0]; /// /// The member from which this descriptor applies. /// private MemberInfo m_memberinfo; /// /// The arbitrary set of attributes associated with Component. /// private System.Collections.Specialized.NameValueCollection m_attributes; /// Creation of an abstract descriptor. /// the set of attributes to assign to the descriptor /// protected internal Descriptor(System.Collections.Specialized.NameValueCollection attributes, MemberInfo memberinfo) { m_attributes = attributes; m_memberinfo = memberinfo; } /// Return the attribute for specified key. /// /// /// the attribute key to resolve /// /// the attribute for specified key. /// public virtual System.String GetAttribute(System.String key) { if (null == m_attributes) { return null; } else { return m_attributes[key]; } } /// Returns the set of attribute names available under this descriptor. /// /// /// an array of the properties names held by the descriptor. /// public virtual System.String[] AttributeNames { get { if (null == m_attributes) { return EMPTY_SET; } else { return m_attributes.AllKeys; } } } /// /// /// public MemberInfo MemberInfo { get { return m_memberinfo; } } /// Returns the property set. /// TODO: check necessity for this operationi and if really needed return /// a cloned equivalent (i.e. disable modification) /// /// /// the property set. /// protected virtual internal System.Collections.Specialized.NameValueCollection Properties { get { return m_attributes; } } /// Return the attribute for specified key. /// /// /// the attribute key to resolve /// /// the default value to use if the value is not defined /// /// the attribute for specified key. /// public virtual System.String GetAttribute(System.String key, System.String defaultValue) { if (null == m_attributes) { return defaultValue; } else { return (m_attributes[key] == null)?defaultValue:m_attributes[key]; } } /// Compare this object with another for equality. /// the object to compare this object with /// /// TRUE if the supplied object equivalent /// public override bool Equals(System.Object other) { if (other is Descriptor) { Descriptor descriptor = (Descriptor) other; if (null == m_attributes) return null == descriptor.m_attributes; // TODO: Compare keys return m_attributes.Count == descriptor.m_attributes.Count; // return m_attributes.(descriptor.m_attributes); } return false; } /// Return the hashcode for the object. /// the hashcode value /// public override int GetHashCode() { if (m_attributes != null) { return m_attributes.GetHashCode(); } else { return 1; } } } }