crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianXmlInputLib/Parser/Nodes/SXILParserNodeCollection.cs
changeset 0 818e61de6cd1
equal deleted inserted replaced
-1:000000000000 0:818e61de6cd1
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 * 
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 using System;
       
    18 using System.IO;
       
    19 using System.Xml;
       
    20 using System.Text;
       
    21 using System.Collections.Generic;
       
    22 using SymbianTree;
       
    23 using SymbianUtils;
       
    24 using SymbianXmlInputLib.Elements;
       
    25 
       
    26 namespace SymbianXmlInputLib.Parser.Nodes
       
    27 {
       
    28     public class SXILParserNodeCollection
       
    29     {
       
    30         #region Constructors
       
    31         public SXILParserNodeCollection()
       
    32         {
       
    33         }
       
    34         #endregion
       
    35 
       
    36         #region API
       
    37         public void Clear()
       
    38         {
       
    39             iNodes.Clear();
       
    40         }
       
    41 
       
    42         internal void Add( SXILParserNode aParser )
       
    43         {
       
    44             int hash = aParser.GetHashCode();
       
    45             if ( iNodes.ContainsKey( hash ) )
       
    46             {
       
    47                 throw new Exception( "The specified parser node already exists" );
       
    48             }
       
    49             iNodes.Add( hash, aParser );
       
    50         }
       
    51         #endregion
       
    52 
       
    53         #region Properties
       
    54         #endregion
       
    55 
       
    56         #region Internal methods
       
    57         private SXILParserNode this[ string aName ]
       
    58         {
       
    59             get
       
    60             {
       
    61                 SXILParserNode ret = null;
       
    62                 //
       
    63                 int hash = aName.GetHashCode();
       
    64                 if ( iNodes.ContainsKey( hash ) )
       
    65                 {
       
    66                     ret = iNodes[ hash ];
       
    67                 }
       
    68                 //
       
    69                 return ret;
       
    70             }
       
    71         }
       
    72 
       
    73         internal bool XmlParse( XmlNode aNode, SXILParser aMasterParser )
       
    74         {
       
    75             bool handled = false;
       
    76             //
       
    77             SXILParserNode child = this[ aNode.Name ];
       
    78             if ( child != null )
       
    79             {
       
    80                 child.Parser = aMasterParser;
       
    81                 child.XmlParse( aNode );
       
    82                 handled = true;
       
    83             }
       
    84             else
       
    85             {
       
    86                 // No direct name-based match, check for multi entries
       
    87                 foreach ( KeyValuePair<int, SXILParserNode> kvp in iNodes )
       
    88                 {
       
    89                     SXILParserNode parserNode = kvp.Value;
       
    90                     bool isMulti = parserNode.IsMulti;
       
    91                     if ( isMulti )
       
    92                     {
       
    93                         bool canHandle = parserNode.CanHandle( aNode );
       
    94                         if ( canHandle )
       
    95                         {
       
    96                             parserNode.Parser = aMasterParser;
       
    97                             parserNode.XmlParse( aNode );
       
    98                             handled = true;
       
    99                             break;
       
   100                         }
       
   101                     }
       
   102                 }
       
   103             }
       
   104             //
       
   105             return handled;
       
   106         }
       
   107         #endregion
       
   108 
       
   109         #region Internal methods
       
   110         private Dictionary<int, SXILParserNode> iNodes = new Dictionary<int, SXILParserNode>();
       
   111         #endregion
       
   112     }
       
   113 }