You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ym...@apache.org on 2002/08/19 20:44:30 UTC
cvs commit: jakarta-avalon-excalibur/csframework/src/cs/Service ServiceException.cs IServiceSelector.cs IServiceManager.cs IServiceable.cs DefaultServiceSelector.cs DefaultServiceManager.cs
ymikulski 2002/08/19 11:44:30
Added: csframework/src/cs/Service ServiceException.cs
IServiceSelector.cs IServiceManager.cs
IServiceable.cs DefaultServiceSelector.cs
DefaultServiceManager.cs
Log:
no message
Revision Changes Path
1.1 jakarta-avalon-excalibur/csframework/src/cs/Service/ServiceException.cs
Index: ServiceException.cs
===================================================================
///
/// Copyright (C) The Apache Software Foundation. All rights reserved.
///
/// This software is published under the terms of the Apache Software License
/// version 1.1, a copy of which has been included with this distribution in
/// the LICENSE.txt file.
///
using System;
namespace Apache.Avalon.Service
{
/// <summary>
/// The Exception thrown to indicate a problem with service.
/// </summary>
/// <remarks>
/// It is usually thrown by <see cref="IServiceManager"/>
/// or <see cref="IServiceSelector"/>.
/// </remarks>
public class ServiceException: Exception
{
private string role;
/// <summary>
/// Constructs a new <c>ServiceException</c> instance.
/// </summary>
public ServiceException(): this(null)
{
}
/// <summary>
/// Constructs a new <c>ServiceException</c> instance.
/// </summary>
/// <param name="message">The Detail message for this exception.</param>
public ServiceException(string message): this(null, message)
{
}
/// <summary>
/// Constructs a new <c>ServiceException</c> instance.
/// </summary>
/// <param name="role">The Role that caused the exception.</param>
/// <param name="message">The Detail message for this exception.</param>
public ServiceException(string role, string message): this(role, message, null)
{
}
/// <summary>
/// Constructs a new <c>ServiceException</c> instance.
/// </summary>
/// <param name="message">The Detail message for this exception.</param>
/// <param name="inner">The Root cause of the exception.</param>
public ServiceException(string message, Exception inner): this(null, message, inner)
{
}
/// <summary>
/// Constructs a new <c>ServiceException</c> instance.
/// </summary>
/// <param name="role">The Role that caused the exception.</param>
/// <param name="message">The Detail message for this exception.</param>
/// <param name="inner">The Root cause of the exception.</param>
public ServiceException(string role, string message, Exception inner): base(message, inner)
{
this.role = role;
}
/// <summary>
/// Gets the role that caused the exception.
/// </summary>
/// <value>The Role that caused the exception.</value>
public string Role
{
get
{
return role;
}
}
}
}
1.1 jakarta-avalon-excalibur/csframework/src/cs/Service/IServiceSelector.cs
Index: IServiceSelector.cs
===================================================================
///
/// Copyright (C) The Apache Software Foundation. All rights reserved.
///
/// This software is published under the terms of the Apache Software License
/// version 1.1, a copy of which has been included with this distribution in
/// the LICENSE.txt file.
///
using System;
namespace Apache.Avalon.Service
{
/// <summary>
/// A <code>IServiceSelector</code> selects components based on a
/// supplied policy. The contract is that all the components implement the
/// same role.
/// </summary>
public interface IServiceSelector
{
/// <summary>
/// Gets the component associated with the given policy.
/// </summary>
/// <exception cref="ServiceException"></exception>
object this[object policy]
{
get;
}
/// <summary>
/// Check to see if a component exists relative to the supplied policy.
/// </summary>
/// <param name="policy">the selection criteria</param>
/// <returns>True if the component is available, false if it not.</returns>
bool Contains(object policy);
/// <summary>
/// Return the component when you are finished with it.
/// This allows the <see cref="IServiceSelector"/> to handle
/// the End-Of-Life Lifecycle events associated with the component.
/// </summary>
/// <remarks>
/// Please note, that no Exceptions should be thrown at this point.
/// This is to allow easy use of the <see cref="IServiceSelector"/> system without
/// having to trap Exceptions on a release.
/// </remarks>
/// <param name="component">The component we are releasing.</param>
void Release(object component);
}
}
1.1 jakarta-avalon-excalibur/csframework/src/cs/Service/IServiceManager.cs
Index: IServiceManager.cs
===================================================================
///
/// Copyright (C) The Apache Software Foundation. All rights reserved.
///
/// This software is published under the terms of the Apache Software License
/// version 1.1, a copy of which has been included with this distribution in
/// the LICENSE.txt file.
///
using System;
namespace Apache.Avalon.Service
{
/// <summary>
/// A <c>IServiceManager</c> selects components based on a
/// role. The contract is that all the components implement the
/// differing roles and there is one component per role.
/// <para>
/// Roles are usually the full interface name. A role is better understood
/// by the analogy of a play. There are many different roles in a script.
/// Any actor or actress can play any given part and you get
/// the same results (phrases said, movements made, etc.). The exact
/// nuances of the performance is different.
/// </para>
/// </summary>
public interface IServiceManager
{
/// <summary>
/// Gets the component associated with the given role.
/// </summary>
object this[string role]
{
get;
}
/// <summary>
/// Checks to see if a component exists for a role.
/// </summary>
/// <param name="role">A String identifying the role to check.</param>
/// <returns>True if the component exists; otherwise, false.</returns>
bool Contains(string role);
/// <summary>
/// Return the component when you are finished with it.
/// This allows the <see cref="IServiceManager"/> to handle
/// the End-Of-Life Lifecycle events associated with the component.
/// </summary>
/// <remarks>
/// Please note, that no Exceptions should be thrown at this point.
/// This is to allow easy use of the <see cref="IServiceManager"/> system without
/// having to trap Exceptions on a release.
/// </remarks>
/// <param name="component">The component we are releasing.</param>
void Release(object component);
}
}
1.1 jakarta-avalon-excalibur/csframework/src/cs/Service/IServiceable.cs
Index: IServiceable.cs
===================================================================
///
/// Copyright (C) The Apache Software Foundation. All rights reserved.
///
/// This software is published under the terms of the Apache Software License
/// version 1.1, a copy of which has been included with this distribution in
/// the LICENSE.txt file.
///
using System;
namespace Apache.Avalon.Service
{
/// <summary>
/// A Composable is a class that need to connect to software components using
/// "role" abstraction, thus not depending on particular implementations
/// but on behavioral interfaces.
///
/// The contract surrounding a <c>IServiceable</c> is that it is a user.
/// The <c>IServiceable</c> is able to use <c>object</c>s managed
/// by the <see cref="IServiceManager"/>IServiceManager</see> it was initialized with.
/// As part of the contract with the system, the instantiating entity must call
/// the <c>Service( IServiceManager manager )</c> method before the <c>IServiceable</c>
/// can be considered valid.
/// </summary>
public interface IServiceable
{
/// <summary>
/// Pass the <see cref="IServiceManager"/>IServiceManager</see>
/// to the <code>IServiceable</code>.
///
/// The <code>IServiceable</code> implementation should use the specified
/// <see cref="IServiceManager"/>IServiceManager</see>
/// to acquire the components it needs for execution.
/// </summary>
/// <param name="manager">
/// The <see cref="IServiceManager"/>IServiceManager</see> which
/// this <code>IServiceable</code> uses.
/// </param>
/// <exception cref="ServiceException">if an error occurs</exception>
void Service( IServiceManager manager );
}
}
1.1 jakarta-avalon-excalibur/csframework/src/cs/Service/DefaultServiceSelector.cs
Index: DefaultServiceSelector.cs
===================================================================
///
/// Copyright (C) The Apache Software Foundation. All rights reserved.
///
/// This software is published under the terms of the Apache Software License
/// version 1.1, a copy of which has been included with this distribution in
/// the LICENSE.txt file.
///
using System;
using System.Collections;
using System.Text;
namespace Apache.Avalon.Service
{
/// <summary>
/// This is the default implementation of the <see cref="IServiceSelector"/>.
/// </summary>
public class DefaultServiceSelector: IServiceSelector, IEnumerable
{
private Hashtable components = new Hashtable();
private bool readOnly;
public DefaultServiceSelector()
{
}
/// <summary>
/// Gets a value indicating whether the <see cref="IServiceSelector"/> is read-only.
/// </summary>
/// <value>True if the <see cref="IServiceSelector"/> is read-only; otherwise, false.</value>
public bool IsReadOnly
{
get
{
return readOnly;
}
}
public object this[object policy]
{
get
{
object component = components[policy];
if (component == null)
{
throw new ServiceException(string.Format("Unable to provide implementation for {0}.", policy));
}
return component;
}
set
{
CheckReadOnly();
components[policy] = value;
}
}
/// <summary>
/// Returns whether a component exists or not.
/// </summary>
/// <param name="policy">The policy to retrieve a component</param>
/// <returns>True if the component is available, false if it not.</returns>
public bool Contains(object policy)
{
bool componentContains = false;
try
{
Release(this[policy]);
componentContains = true;
}
catch (Exception)
{
// Ignore all exceptions -- we want to know a yes or no answer.
}
return componentContains;
}
/// <summary>
/// Return the component when you are finished with it.
/// This allows the <see cref="IServiceManager"/> to handle
/// the End-Of-Life Lifecycle events associated with the component.
/// </summary>
/// <remarks>
/// Please note, that no Exceptions should be thrown at this point.
/// This is to allow easy use of the <see cref="IServiceManager"/> system without
/// having to trap Exceptions on a release.
/// </remarks>
/// <param name="component">The component we are releasing.</param>
public void Release(object component)
{
// If the IServiceManager handled pooling, it would be
// returned to the pool here.
}
public void MakeReadOnly()
{
readOnly = true;
}
protected void CheckReadOnly()
{
if( IsReadOnly )
{
throw new ServiceException( "ServiceSelector is read only and can not be modified" );
}
}
public IEnumerator GetEnumerator()
{
return components.GetEnumerator();
}
public override string ToString()
{
StringBuilder buffer = new StringBuilder();
buffer.Append("Services: ");
foreach( object component in components.Values)
{
buffer.AppendFormat( "[ {0} ]", component);
}
return buffer.ToString();
}
}
}
1.1 jakarta-avalon-excalibur/csframework/src/cs/Service/DefaultServiceManager.cs
Index: DefaultServiceManager.cs
===================================================================
///
/// Copyright (C) The Apache Software Foundation. All rights reserved.
///
/// This software is published under the terms of the Apache Software License
/// version 1.1, a copy of which has been included with this distribution in
/// the LICENSE.txt file.
///
using System;
using System.Collections;
using System.Text;
namespace Apache.Avalon.Service
{
/// <summary>
/// This class is a static implementation of a <see cref="IServiceManager"/>.
/// Allow ineritance and extension so you can generate a tree of
/// <see cref="IServiceManager"/> each defining object scope.
/// </summary>
public class DefaultServiceManager: IServiceManager, IEnumerable
{
private Hashtable components = new Hashtable();
private IServiceManager parent;
private bool readOnly;
/// <summary>
/// Constructs <see cref="IServiceManager"/> with no parent.
/// </summary>
public DefaultServiceManager(): this(null)
{
}
/// <summary>
/// Constructs <see cref="IServiceManager"/> with specified parent.
/// </summary>
/// <param name="parent">The <see cref="IServiceManager"/>'s parent</param>
public DefaultServiceManager(IServiceManager parent)
{
this.parent = parent;
}
/// <summary>
/// Gets parent.
/// </summary>
/// <value>The Parent component manager of this <see cref="IServiceManager"/> instance.</value>
protected IServiceManager Parent
{
get
{
return parent;
}
}
/// <summary>
/// Gets a value indicating whether the <see cref="IServiceManager"/> is read-only.
/// </summary>
/// <value>True if the <see cref="IServiceManager"/> is read-only; otherwise, false.</value>
public bool IsReadOnly
{
get
{
return readOnly;
}
}
/// <summary>
/// Gets the component associated with the given role.
/// </summary>
public object this[string role]
{
get
{
object component = components[role];
if (component == null)
{
if (Parent == null)
{
throw new ServiceException(role, string.Format("Unable to provide implementation for {0}.", role));
}
else
{
component = Parent[role];
}
}
return component;
}
set
{
CheckReadOnly();
components[role] = value;
}
}
/// <summary>
/// Checks to see if a component exists for a role.
/// </summary>
/// <param name="role">A String identifying the role to check.</param>
/// <returns>True if the component exists; otherwise, false.</returns>
public bool Contains(string role)
{
bool componentContains = false;
try
{
object component = this[role];
componentContains = true;
}
catch (Exception)
{
// Ignore all exceptions -- we want to know a yes or no answer.
}
return componentContains;
}
/// <summary>
/// Return the component when you are finished with it.
/// This allows the <see cref="IServiceManager"/> to handle
/// the End-Of-Life Lifecycle events associated with the component.
/// </summary>
/// <remarks>
/// Please note, that no Exceptions should be thrown at this point.
/// This is to allow easy use of the <see cref="IServiceManager"/> system without
/// having to trap Exceptions on a release.
/// </remarks>
/// <param name="component">The component we are releasing.</param>
public void Release(object component)
{
// If the IServiceManager handled pooling, it would be
// returned to the pool here.
}
public void MakeReadOnly()
{
readOnly = true;
}
protected void CheckReadOnly()
{
if( IsReadOnly )
{
throw new ServiceException( "ServiceManager is read only and can not be modified" );
}
}
public IEnumerator GetEnumerator()
{
return components.GetEnumerator();
}
/// <summary>
/// Build a human readable representation of <see cref="IServiceManager"/>.
/// </summary>
/// <returns>
/// A Human readable representation of <see cref="IServiceManager"/>.
/// </returns>
public override string ToString()
{
StringBuilder buffer = new StringBuilder();
buffer.Append("Services: ");
foreach( object component in components.Values)
{
buffer.AppendFormat( "[ {0} ]", component);
}
return buffer.ToString();
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: cvs commit: jakarta-avalon-excalibur/csframework/...
Posted by Nicola Ken Barozzi <ni...@apache.org>.
ymikulski@apache.org wrote:
> ymikulski 2002/08/19 11:44:30
>
> Added: csframework/src/cs/Service ServiceException.cs
> IServiceSelector.cs IServiceManager.cs
> IServiceable.cs DefaultServiceSelector.cs
> DefaultServiceManager.cs
> Log:
> no message
Please always comment commits, thanks :-)
--
Nicola Ken Barozzi nicolaken@apache.org
- verba volant, scripta manent -
(discussions get forgotten, just code remains)
---------------------------------------------------------------------
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>