Example #1
0
        /// <summary>  Read a configuration file into memory.
        /// 
        /// </summary>
        /// <param name="file">The path to the configuration file
        /// </param>
        /// <param name="validate">true to validate the configuration file
        /// 
        /// </param>
        /// <returns> A DOM Document encapsulating the configuration file. This
        /// object may also be obtained by calling <c>getDocument</c>
        /// </returns>
        /// <exception cref="IOException">  thrown if an error occurs reading the file
        /// </exception>
        /// <exception cref="AdkMappingException">  thrown if an error occurs parsing any
        /// <c>&lt;mappings&gt;</c> elements
        /// </exception>
        /// <exception cref="AdkConfigException">  thrown if the configuration file fails
        /// to parse or is not valid when validation is turned on
        /// 
        /// </exception>
        /// <seealso cref="Document">
        /// </seealso>
        public virtual XmlDocument Read( string file,
                                         bool validate )
        {
            try {
                fSrc = new FileInfo( file );
                // TODO: Implement validation if the validate flag is true
                if ( validate ) {
                    throw new NotImplementedException
                        ( "Document validation is not yet implemented" );
                }
                else {
                    fDoc = new XmlDocument();
                    fDoc.Load( fSrc.FullName );
                }
            }
            catch ( Exception ex ) {
                throw new AdkConfigException( ex.Message, ex );
            }

            //  Build the Mappings object
            fMappings = new Mappings();
            fMappings.Populate( fDoc, RootNode );
            return fDoc;
        }
        /**
         * Returns a new mappings root, with the passed-in Mappings copied into it
         * as a child, obtained by using the Mappings.copy() method
         *
         * @param root
         *            The set of mappings to be copied into the new root
         * @return
         */
        private Mappings getCopyFromDOM( Mappings mappingSet )
        {
            XmlDocument dom = new XmlDocument();
            dom.LoadXml( "<agent/>" );
            XmlNode mappingsNode = dom.ImportNode( mappingSet.XmlElement, true );
            dom.DocumentElement.AppendChild( mappingsNode );

            Mappings newRoot = new Mappings();
            newRoot.Populate( dom, (XmlElement) mappingsNode );
            return newRoot;
        }