// 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 class contains the meta information about a particular
/// service. It contains a set of attributes qualifying the service;
///
///
/// Avalon Development Team
///
/// $Revision: 1.4 $ $Date: 2004/02/28 22:15:37 $
///
[Serializable]
public class Service : Descriptor
{
//=========================================================================
// state
//=========================================================================
/// The service reference.
private ReferenceDescriptor m_reference;
/// The optional context entry criteria.
private EntryDescriptor[] m_entries;
//=========================================================================
// constructor
//=========================================================================
/// Creation of a new Service instance using a classname and
/// supplied properties argument.
///
///
/// the versioned classname
///
public Service(ReferenceDescriptor reference) :
this(reference, null, null)
{
}
/// Creation of a new Service instance using a classname and
/// supplied properties argument.
///
///
/// the versioned classname
///
/// the set of attributes to assign to the descriptor
///
public Service(ReferenceDescriptor reference, EntryDescriptor[] entries) :
this(reference, entries, null)
{
}
/// Creation of a new Service instance using a classname and
/// supplied properties argument.
///
///
/// the versioned classname
///
/// the set of attributes to assign to the descriptor
///
public Service(ReferenceDescriptor reference, System.Collections.Specialized.NameValueCollection attributes) :
this(reference, null, attributes)
{
}
/// Creation of a new Service instance using a classname and
/// supplied properties argument.
///
///
/// the versioned classname
///
/// the set of optional context entries
///
/// the set of attributes to assign to the descriptor
///
public Service(ReferenceDescriptor reference, EntryDescriptor[] entries,
System.Collections.Specialized.NameValueCollection attributes) :
base(attributes, null)
{
if (reference == null)
{
throw new System.NullReferenceException("reference");
}
m_reference = reference;
if (entries == null)
{
m_entries = new EntryDescriptor[0];
}
else
{
m_entries = entries;
}
}
//=========================================================================
// implementation
//=========================================================================
/// Determine if supplied reference will match this service.
/// To match a service has to have same classname and must comply with version.
///
///
/// the reference descriptor
///
/// true if matches, false otherwise
///
public virtual bool Matches(ReferenceDescriptor reference)
{
return m_reference.Matches(reference);
}
/// Return the hashcode for this service defintion.
/// the hashcode value
///
public override int GetHashCode()
{
return m_reference.GetHashCode();
}
/// Compare this object to the supplied object for equality.
/// the object to compare to this object
///
/// true if this object matches the supplied object
/// in terms of service classname and version
///
public override bool Equals(System.Object other)
{
bool match = false;
if (other is ReferenceDescriptor)
{
match = Matches((ReferenceDescriptor) other);
}
else if (other is Service)
{
Service ref_Renamed = (Service) other;
match = ref_Renamed.Type.Equals(Type);
}
return match;
}
/// Returns a string representation of the service.
/// a string representation
///
public override System.String ToString()
{
return Reference.ToString();
}
/// Return the service classname key.
/// the service classname
///
public virtual System.Type Type
{
get
{
return m_reference.Type;
}
}
/// Return the service reference.
/// the reference
///
public virtual ReferenceDescriptor Reference
{
get
{
return m_reference;
}
}
/// Return the entries declared by the service.
///
///
/// the entry descriptors
///
public virtual EntryDescriptor[] Entries
{
get
{
return m_entries;
}
}
}
}