/*
* 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.ServiceModel.Channels;
using System.ServiceModel.Configuration;
namespace Apache.NMS.WCF
{
///
/// Configuration section for NMS.
///
public class NmsTransportElement : BindingElementExtensionElement
{
#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 Configuration overrides
///
/// When overridden in a derived class, gets the object that represents the custom binding element.
///
///
/// A object that represents the custom binding type.
///
public override Type BindingElementType
{
get { return typeof(NmsTransportBindingElement); }
}
///
/// When overridden in a derived class, returns a custom binding element object.
///
///
/// A custom object.
///
protected override BindingElement CreateBindingElement()
{
NmsTransportBindingElement bindingElement = new NmsTransportBindingElement();
this.ApplyConfiguration(bindingElement);
return bindingElement;
}
#endregion
///
/// Applies the content of a specified binding element to this binding configuration element.
///
/// A binding element.
///
/// is null.
public override void ApplyConfiguration(BindingElement bindingElement)
{
base.ApplyConfiguration(bindingElement);
NmsTransportBindingElement nmsBindingElement = (NmsTransportBindingElement) bindingElement;
nmsBindingElement.Destination = Destination;
nmsBindingElement.DestinationType = DestinationType;
}
///
/// Copies the content of the specified configuration element to this configuration element.
///
/// The configuration element to be copied.
///
/// is null.
/// The configuration file is read-only.
public override void CopyFrom(ServiceModelExtensionElement from)
{
base.CopyFrom(from);
NmsTransportElement source = (NmsTransportElement) from;
Destination = source.Destination;
DestinationType = source.DestinationType;
}
///
/// Initializes this binding configuration section with the content of the specified binding element.
///
/// A binding element.
protected override void InitializeFrom(BindingElement bindingElement)
{
base.InitializeFrom(bindingElement);
NmsTransportBindingElement nmsBindingElement = (NmsTransportBindingElement) bindingElement;
Destination = nmsBindingElement.Destination;
DestinationType = nmsBindingElement.DestinationType;
}
///
/// Gets the collection of properties.
///
///
///
/// The of properties for the 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;
}
}
}
}