//-----------------------------------------------------------------------
//
// Copyright (c) Outercurve Foundation. All rights reserved.
//
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.OpenId.Extensions {
using System.Collections.Generic;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OpenId.ChannelElements;
using DotNetOpenAuth.OpenId.Messages;
///
/// An OpenID extension factory that only delegates extension
/// instantiation requests to other factories.
///
internal class OpenIdExtensionFactoryAggregator : IOpenIdExtensionFactory {
///
/// The list of factories this factory delegates to.
///
private List factories = new List(2);
///
/// Initializes a new instance of the class.
///
internal OpenIdExtensionFactoryAggregator() {
}
///
/// Gets the extension factories that this aggregating factory delegates to.
///
/// A list of factories. May be empty, but never null.
internal IList Factories {
get { return this.factories; }
}
#region IOpenIdExtensionFactory Members
///
/// Creates a new instance of some extension based on the received extension parameters.
///
/// The type URI of the extension.
/// The parameters associated specifically with this extension.
/// The OpenID message carrying this extension.
/// A value indicating whether this extension is being received at the OpenID Provider.
///
/// An instance of if the factory recognizes
/// the extension described in the input parameters; null otherwise.
///
///
/// This factory method need only initialize properties in the instantiated extension object
/// that are not bound using .
///
public IOpenIdMessageExtension Create(string typeUri, IDictionary data, IProtocolMessageWithExtensions baseMessage, bool isProviderRole) {
foreach (var factory in this.factories) {
IOpenIdMessageExtension result = factory.Create(typeUri, data, baseMessage, isProviderRole);
if (result != null) {
return result;
}
}
return null;
}
#endregion
///
/// Loads the default factory and additional ones given by the configuration.
///
/// A new instance of .
internal static OpenIdExtensionFactoryAggregator LoadFromConfiguration() {
var factoriesElement = DotNetOpenAuth.Configuration.OpenIdElement.Configuration.ExtensionFactories;
var aggregator = new OpenIdExtensionFactoryAggregator();
aggregator.Factories.Add(new StandardOpenIdExtensionFactory());
aggregator.factories.AddRange(factoriesElement.CreateInstances(false, null));
return aggregator;
}
}
}