ymikulski    2002/08/13 05:58:24

  Added:       csframework/src/cs/Component ComponentException.cs
                        DefaultComponentManager.cs IComponentManager.cs
                        IComposable.cs IRecomposable.cs
  Log:
  no message
  
  Revision  Changes    Path
  1.1                  
jakarta-avalon-excalibur/csframework/src/cs/Component/ComponentException.cs
  
  Index: ComponentException.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.Component
  {
        
        /// <summary>
        ///     The exception thrown to indicate a problem with components.
        /// It is usually thrown by <see cref="IComponentManager"/>. 
        /// </summary>
        public class ComponentException: Exception
        {
                /// <summary>
                /// Constructs a new <c>ComponentException</c> instance.
                /// </summary>
                public ComponentException(): this(null)
                {
                }
  
                /// <summary>
                /// Constructs a new <c>ComponentException</c> instance.
                /// </summary>
                /// <param name="message">The Detail message for this 
exception.</param>
                public ComponentException(string message): this(message, null)
                {
                }
                
                /// <summary>
                /// Constructs a new <c>ComponentException</c> instance.
                /// </summary>
                /// <param name="message">The Detail message for this 
exception.</param>
                /// <param name="inner">The Root cause of the exception.</param>
                public ComponentException(string message, Exception inner): 
base(message, inner)
                {
                }
        }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/csframework/src/cs/Component/DefaultComponentManager.cs
  
  Index: DefaultComponentManager.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.Component
  {
        
        /// <summary>
        /// This class is a static implementation of a <see cref="IComponentManager"/>.
        /// Allow ineritance and extension so you can generate a tree of
        /// <see cref="IComponentManager"/> each defining component scope.
        /// </summary>
        public class DefaultComponentManager: IComponentManager, IEnumerable
        {
                private Hashtable components = new Hashtable();
                private IComponentManager parent;
                private bool readOnly;
  
                /// <summary>
                /// Constructs <see cref="IComponentManager"/> with no parent.
                /// </summary>
                public DefaultComponentManager(): this(null)
                {
                }
                
                /// <summary>
                /// Constructs <see cref="IComponentManager"/> with specified parent.
                /// </summary>
                /// <param name="parent">The <see cref="IComponentManager"/>'s 
parent</param>
                public DefaultComponentManager(IComponentManager parent)
                {
                        this.parent = parent;
                }
                
                /// <summary>
                /// Gets parent.
                /// </summary>
                /// <value>The Parent component manager of this <see 
cref="IComponentManager"/> instance.</value>
                protected IComponentManager Parent
                {
                        get
                        {
                                return parent;
                        }
                }
  
                /// <summary>
                /// Gets a value indicating whether the <see 
cref="IComponentManager"/> is read-only.
                /// </summary>
                /// <value>True if the <see cref="IComponentManager"/> 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 ComponentException( 
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
                        {
                                Release(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="IComponentManager"/> 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="IComponentManager"/> 
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 IComponentManager handled pooling, it would be
                        // returned to the pool here.
                }
  
                public void MakeReadOnly()
                {
                        readOnly = true;
                }
  
                protected void CheckReadOnly()
                {
                        if( IsReadOnly )
                        {
                                throw new ComponentException( "ComponentManager is 
read only and can not be modified" );
                        }
                }
  
                public IEnumerator GetEnumerator()
                {
                        return components.GetEnumerator(); 
                }
  
                /// <summary>
                /// Build a human readable representation of <see 
cref="IComponentManager"/>.
                /// </summary>
                /// <returns>
                /// A Human readable representation of <see cref="IComponentManager"/>.
                /// </returns>
                public override string ToString()
                {
                        StringBuilder buffer = new StringBuilder();
                        buffer.Append("Components: ");
                        
                        foreach( object component in components.Values) 
                        {
                                buffer.AppendFormat( "[ {0} ]", component);
                        }
  
                        return buffer.ToString();
                }
        }
  }
  
  
  1.1                  
jakarta-avalon-excalibur/csframework/src/cs/Component/IComponentManager.cs
  
  Index: IComponentManager.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.Component
  {
        
        /// <summary>
        /// A <c>IComponentManager</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 IComponentManager
        {
                /// <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="IComponentManager"/> 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="IComponentManager"/> 
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/Component/IComposable.cs
  
  Index: IComposable.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.Component
  {
        /// <summary>
        /// A composer is a class that need to connect to software components using
        ///     a "role" abstraction, thus not depending on particular implementations
        /// but on behavioral interfaces.
        /// The contract surrounding a <code>IComposable</code> is that it is a user.
        /// The <code>IComposable</code> is able to use <code>Components</code> managed
        /// by the <code>ComponentManager</code> it was initialized with. As part
        /// of the contract with the system, the instantiating entity must call
        /// the <code>Compose</code> method before the <code>IComposable</code>
        /// can be considered valid.
        /// </summary>
        public interface IComposable
        {
                /// <summary>
                /// Pass the <see cref="IComponentManager"/> to the 
<code>composer</code>.
                /// The <code>IComposable</code> implementation should use the 
specified
                /// <see cref="IComponentManager"/> to acquire the components it needs 
for
                /// execution.
                /// </summary>
                /// <param name="componentManager">
                /// The <see cref="IComponentManager"/> which this
                /// <code>IComposable</code> uses.
                /// </param>
                void Compose(IComponentManager componentManager);
        }
  }
  
  
  
  1.1                  
jakarta-avalon-excalibur/csframework/src/cs/Component/IRecomposable.cs
  
  Index: IRecomposable.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.Component
  {
        /// <summary>
        /// Extends composer to allow recomposing.
        /// </summary>
        public interface IRecomposable: IComposable
        {
                /// <summary>
                /// Repass the <see cref="IComponentManager"/> to the 
<code>composer</code>.
                /// The <see cref="IComposable"/> implementation should use the 
specified
                /// <see cref="IComponentManager"/> to acquire the components it needs 
for
                /// execution. It should also drop references to any components it 
                /// retrieved from old <see cref="IComponentManager"/>.
                /// </summary>
                /// <param name="componentManager">
                /// The <see cref="IComponentManager"/> which this
                /// <code>IComposable</code> uses.
                /// </param>
                void Recompose(IComponentManager componentManager);
        }
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to