/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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.
*/
using System;
using System.Configuration;
using System.Globalization;
using System.ServiceModel.Channels;
using System.ServiceModel.Configuration;
namespace Apache.NMS.WCF
{
///
/// Configuration element for the , allowing the overriding of default values.
///
public class NmsBindingElement : StandardBindingElement
{
#region Constructors
///
/// Initializes a new instance of the class.
///
public NmsBindingElement()
: this(null)
{
}
///
/// Initializes a new instance of the class.
///
/// Name of the configuration.
public NmsBindingElement(string configurationName)
: base(configurationName)
{
}
#endregion
#region Public properties
///
/// Gets or sets the name of the message destination.
///
/// The name of the message destination.
[ConfigurationProperty(NmsConfigurationStrings.Destination, IsRequired = true)]
public string Destination
{
get { return (string) base[NmsConfigurationStrings.Destination]; }
set { base[NmsConfigurationStrings.Destination] = value; }
}
///
/// Gets or sets the type of the message destination.
///
/// The type of the message destination (may be either queue or topic, and temporary
/// or permanent versions of either).
[ConfigurationProperty(NmsConfigurationStrings.DestinationType, DefaultValue = NmsConfigurationDefaults.Destination)]
public DestinationType DestinationType
{
get { return (DestinationType) Enum.Parse(typeof(DestinationType), base[NmsConfigurationStrings.DestinationType].ToString(), true); }
set { base[NmsConfigurationStrings.DestinationType] = value; }
}
#endregion
#region Protected methods
///
/// Gets a instance that contains a collection of objects that can be attributes or objects of this configuration element.
///
///
/// A instance that contains a collection of objects that can be attributes or objects of this configuration element.
protected override ConfigurationPropertyCollection Properties
{
get
{
ConfigurationPropertyCollection properties = base.Properties;
properties.Add(new ConfigurationProperty(NmsConfigurationStrings.Destination, typeof(string), null, ConfigurationPropertyOptions.IsRequired));
properties.Add(new ConfigurationProperty(NmsConfigurationStrings.DestinationType, typeof(DestinationType), NmsConfigurationDefaults.Destination));
return properties;
}
}
///
/// Initializes this binding configuration element with the content of the specified binding.
///
/// A binding.
///
/// is null.
/// The type of this binding element is different from the type specified by .
protected override void InitializeFrom(Binding binding)
{
base.InitializeFrom(binding);
NmsBinding nmsBinding = (NmsBinding) binding;
Destination = nmsBinding.Destination;
DestinationType = nmsBinding.DestinationType;
}
///
/// Called when the content of a specified binding element is applied to this binding configuration element.
///
/// A binding.
protected override void OnApplyConfiguration(Binding binding)
{
if(binding == null)
{
throw new ArgumentNullException("binding");
}
if(binding.GetType() != typeof(NmsBinding))
{
throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "Invalid type for binding. Expected tpye: {0}. Type passed in: {1}.", typeof(NmsBinding).AssemblyQualifiedName, binding.GetType().AssemblyQualifiedName));
}
NmsBinding nmsBinding = (NmsBinding) binding;
nmsBinding.Destination = Destination;
nmsBinding.DestinationType = DestinationType;
}
///
/// When overridden in a derived class, gets the object that represents the custom binding element.
///
///
/// A object that represents the custom binding type.
///
protected override Type BindingElementType
{
get { return typeof(NmsBinding); }
}
#endregion
}
}