// Copyright 2003-2004 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 Apache.Avalon.Container.Configuration
{
using System;
using System.Xml;
using System.IO;
using Apache.Avalon.Framework;
///
/// Keeps the container configuration.
///
public class ContainerConfiguration
{
private IConfiguration m_configuration;
///
/// Constructs a ContainerConfiguration with an optional parent.
///
/// The ContainerConfiguration parent. Can be null
public ContainerConfiguration(ContainerConfiguration parent)
{
}
///
/// Constructs a ContainerConfiguration with an optional parent.
///
/// The ContainerConfiguration parent. Can be null
/// XmlNode to be parsed.
public ContainerConfiguration(ContainerConfiguration parent, XmlNode section) : this( parent )
{
if ( section == null )
{
throw new ArgumentNullException( "section" );
}
Deserialize( section );
}
///
/// Constructs a ContainerConfiguration with the
/// to be parsed.
///
/// The ContainerConfiguration parent. Can be null
/// XmlNode to be parsed.
public ContainerConfiguration(XmlNode section) : this(null, section)
{
}
///
/// Constructs a ContainerConfiguration with the filename containing
/// the xml to be parsed.
///
/// The filename to be parsed.
public ContainerConfiguration(String filename) : this(null as ContainerConfiguration)
{
ParseFromFile(filename);
}
///
/// Parses a configuration file. Looks for a node
/// 'configuration/avalon.container'
///
/// The xml full file name
private void ParseFromFile(String filename)
{
XmlTextReader reader = new XmlTextReader(
new FileStream(filename, FileMode.Open, FileAccess.Read));
XmlDocument doc = new XmlDocument() ;
doc.Load(reader);
XmlNode avalonNode =
doc.SelectSingleNode("configuration/" + ContainerConfigurationSectionHandler.Section);
Deserialize( avalonNode );
}
///
///
///
///
private void Deserialize( XmlNode section )
{
m_configuration = DefaultConfigurationSerializer.Deserialize( section );
}
///
///
///
public IConfiguration Configuration
{
get
{
return m_configuration;
}
}
}
}