| |||||||||||||||||
| Source File | Conditionals | Statements | Methods | TOTAL | |||||||||||||
| Model\XmlModel\XmlViewCollection.cs | 50,0 % | 80,0 % | 75,0 % | 76,2 % |
|
||||||||||||
| 1 | #region Copyright | |
| 2 | /* | |
| 3 | ShowX. Maps business objects into presentation layer. | |
| 4 | Copyright (C) 2005 Jesus Diaz. | |
| 5 | ||
| 6 | This library is free software; you can redistribute it and/or | |
| 7 | modify it under the terms of the GNU Lesser General Public | |
| 8 | License as published by the Free Software Foundation; either | |
| 9 | version 2.1 of the License, or (at your option) any later version. | |
| 10 | ||
| 11 | This library is distributed in the hope that it will be useful, | |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 14 | Lesser General Public License for more details. | |
| 15 | ||
| 16 | You should have received a copy of the GNU Lesser General Public | |
| 17 | License along with this library; if not, write to the Free Software | |
| 18 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
| 19 | ||
| 20 | For project details see: http://showx.sourceforge.net | |
| 21 | */ | |
| 22 | #endregion | |
| 23 | ||
| 24 | using System.Collections; | |
| 25 | using System.Xml; | |
| 26 | ||
| 27 | namespace ShowX.Model.XmlModel | |
| 28 | { | |
| 29 | /// <summary> | |
| 30 | /// XmlViewCollection implements IViewCollection for the Xml model. | |
| 31 | /// </summary> | |
| 32 | public class XmlViewCollection : IViewCollection | |
| 33 | { | |
| 34 | private Hashtable viewCollection; | |
| 35 | private int defaultViewIndex; | |
| 36 | ||
| 37 | /// <summary> | |
| 38 | /// Default constructor. Build an empty view collection. | |
| 39 | /// </summary> | |
| 40 | 18 | public XmlViewCollection() |
| 41 | { | |
| 42 | 18 | viewCollection = new Hashtable(); |
| 43 | 18 | defaultViewIndex = -1; |
| 44 | } | |
| 45 | ||
| 46 | /// <summary> | |
| 47 | /// Constructor. Builds the view collection. | |
| 48 | /// </summary> | |
| 49 | /// <param name="viewNode">Xml node to read view information.</param> | |
| 50 | 10 | public XmlViewCollection(XmlNode viewNode) |
| 51 | { | |
| 52 | 10 | bool isDefaultPropertyFound = false; |
| 53 | ||
| 54 | 10 | string defaultValueName = (viewNode |
| 55 | .Attributes[XmlMappingFileConst.viewsDefaultViewAttr] == null) | |
| 56 | ? null | |
| 57 | : viewNode.Attributes[XmlMappingFileConst.viewsDefaultViewAttr].Value; | |
| 58 | ||
| 59 | 10 | int i = 0; |
| 60 | 10 | viewCollection = new Hashtable(); |
| 61 | ||
| 62 | 10 | foreach (XmlNode node in viewNode.ChildNodes) { |
| 63 | ||
| 64 | 20 | XmlView view = new XmlView(node); |
| 65 | 20 | this.viewCollection.Add(view.Name,view); |
| 66 | ||
| 67 | 20 | if (!isDefaultPropertyFound && defaultValueName != null && |
| 68 | view.Name == defaultValueName) { | |
| 69 | ||
| 70 | 0 | isDefaultPropertyFound = true; |
| 71 | 0 | defaultViewIndex = i; |
| 72 | } | |
| 73 | else | |
| 74 | 20 | i++; |
| 75 | } | |
| 76 | } | |
| 77 | ||
| 78 | #region IViewCollection Members | |
| 79 | ||
| 80 | /// <summary> | |
| 81 | /// Returns the default view for the selected class, or null if: | |
| 82 | /// <li> | |
| 83 | /// <ul>There's no views defined for this class.</ul> | |
| 84 | /// <ul>There's no default view defined for this class.</ul> | |
| 85 | /// </li> | |
| 86 | /// </summary> | |
| 87 | 0 | public IView DefaultView |
| 88 | { | |
| 89 | get | |
| 90 | { | |
| 91 | return (defaultViewIndex < 0) | |
| 92 | ? null | |
| 93 | : viewCollection[defaultViewIndex] as IView; | |
| 94 | } | |
| 95 | } | |
| 96 | ||
| 97 | /// <summary> | |
| 98 | /// Returns the views defined for this class. | |
| 99 | /// </summary> | |
| 100 | public Hashtable Views | |
| 101 | { | |
| 102 | 71 | get |
| 103 | { | |
| 104 | 71 | return this.viewCollection; |
| 105 | } | |
| 106 | } | |
| 107 | ||
| 108 | #endregion | |
| 109 | } | |
| 110 | } | |
| 111 |
|
||||||||