using System.Collections; /* * Copyright 2003-2005 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 Agility.Core { /// /// A {@link IChain} represents a configured list of /// {@link ICommand}s that will be executed in order to perform processing /// on a specified {@link IContext}. /// /// ///

Each included {@link ICommand} will be /// executed in turn, until either one of them returns true, /// one of the executed {@link ICommand}s throws an Exception, /// or the end of the chain has been reached. The {@link IChain} itself will /// return the return value of the last {@link ICommand} that was executed /// (if no exception was thrown), or rethrow the thrown Exception.

/// ///

Note that {@link IChain} extends {@link ICommand}, so that the two can /// be used interchangeably when a {@link ICommand} is expected. This makes it /// easy to assemble workflows in a hierarchical manner by combining subchains /// into an overall processing chain.

/// ///

To protect applications from evolution of this interface, specialized /// implementations of {@link IChain} should generally be created by extending /// the provided base class {@link Agility.Core.Chain}) /// rather than directly implementing this interface.

/// ///

{@link IChain} implementations should be designed in a thread-safe /// manner, suitable for execution on multiple threads simultaneously. In /// general, this implies that the state information identifying which /// {@link ICommand} is currently being executed should be maintained in a /// local variable inside the Execute method, rather than /// in an instance variable. The {@link ICommand}s in a {@link IChain} may be /// configured (via calls to AddCommand) at any time before /// the Execute() method of the {@link IChain} is first called. /// After that, the configuration of the {@link IChain} is frozen.

///
public interface IChain : ICommand { /// /// Add a {@link ICommand} to the list of {@link ICommand}s that will /// be called in turn when this {@link IChain}'s Execute() /// method is called. /// /// ///

Once Execute has been called /// at least once, it is no longer possible to add additional /// {@link ICommand}s; instead, an Exception will be thrown.

///
void AddCommand(ICommand command); /// /// Add a IList of {@link ICommand}s to the list of {@link ICommand}s. /// /// /// Although rendered as a property, this member does add a Command to the list, /// without overwritign any existing commands, unless keys conflicts. /// If key conflict, the last one added wins. /// IList AddCommands { set; } /// /// Execute the processing represented by this {@link IChain}. /// /// ///

Processing uses the following algorithm:

/// ///
/// The {@link IContext} to be processed by this /// {@link IChain} /// true if the processing of this {@link IContext} /// is complete, or false if further processing /// of this {@link IContext} can be delegated to a subsequent /// {@link ICommand} in an enclosing {@link IChain} new bool Execute(IContext context); } }