// 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.Composition.Data
{
using System;
/// Description of a set of categories.
///
///
///
///
/// Avalon Development Team
///
/// $Revision: 1.2 $ $Date: 2004/02/28 22:15:36 $
///
[Serializable]
public class CategoriesDirective : CategoryDirective
{
/// The root category hierachy.
private CategoryDirective[] m_categories;
/// Create a CategoriesDirective instance.
public CategoriesDirective():this("")
{
}
/// Create a CategoriesDirective instance.
///
///
/// the base category name
///
public CategoriesDirective(System.String name):this(name, null, null, new CategoryDirective[0])
{
}
/// Create a CategoriesDirective instance.
///
///
/// the categories to include in the directive
///
public CategoriesDirective(CategoryDirective[] categories):this("", null, null, categories)
{
}
/// Create a CategoriesDirective instance.
///
///
/// the base category name
///
/// the default logging priority
///
/// the default logging target
///
/// the logging category descriptors
///
public CategoriesDirective(System.String name, System.String priority, System.String target, CategoryDirective[] categories):base(name, priority, target)
{
if (categories == null)
{
m_categories = new CategoryDirective[0];
}
else
{
m_categories = categories;
}
}
/// Return a named category.
///
///
/// the category name
///
/// the category declaration
///
public virtual CategoryDirective getCategoryDirective(System.String name)
{
for (int i = 0; i < m_categories.Length; i++)
{
CategoryDirective category = m_categories[i];
if (category.Name.ToUpper().Equals(name.ToUpper()))
{
return category;
}
}
return null;
}
/// Test this object for equality with the suppplied object.
///
///
/// TRUE if this object equals the supplied object
/// else FALSE
///
public override bool Equals(System.Object other)
{
bool isEqual = other is CategoriesDirective;
if (isEqual)
isEqual = base.Equals(other);
if (isEqual)
{
CategoriesDirective cat = (CategoriesDirective) other;
if (isEqual)
isEqual = m_categories.Length == cat.m_categories.Length;
if (isEqual)
{
for (int i = 0; i < m_categories.Length && isEqual; i++)
{
isEqual = m_categories[i].Equals(cat.m_categories[i]);
}
}
}
return isEqual;
}
/// Return the hashcode for the object.
/// the cashcode
///
public override int GetHashCode()
{
int hash = base.GetHashCode();
for (int i = 0; i < m_categories.Length; i++)
{
hash ^= m_categories[i].GetHashCode();
}
return hash;
}
/// Return the set of logging categories.
///
///
/// the set of category declarations
///
public virtual CategoryDirective[] Categories
{
get
{
return m_categories;
}
}
}
}