|
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 |
|
21 namespace SymbianTree |
|
22 { |
|
23 public class SymDocument : SymNodeAddAsChild |
|
24 { |
|
25 #region Constructors |
|
26 public SymDocument() |
|
27 : this( Granularity ) |
|
28 { |
|
29 } |
|
30 |
|
31 public SymDocument( int aGranularity ) |
|
32 : this( aGranularity, null ) |
|
33 { |
|
34 } |
|
35 |
|
36 public SymDocument( object aData ) |
|
37 : this( Granularity, aData ) |
|
38 { |
|
39 } |
|
40 |
|
41 public SymDocument( int aGranularity, object aData ) |
|
42 : base( aData ) |
|
43 { |
|
44 iCurrentNode = this; |
|
45 CreateChildrenListNow( aGranularity ); |
|
46 } |
|
47 #endregion |
|
48 |
|
49 #region API |
|
50 public void SerializeToXml( string aFileName ) |
|
51 { |
|
52 if ( File.Exists( aFileName ) ) |
|
53 { |
|
54 File.Delete( aFileName ); |
|
55 } |
|
56 |
|
57 using ( XmlTextWriter writer = new XmlTextWriter( aFileName, System.Text.Encoding.UTF8 ) ) |
|
58 { |
|
59 writer.Formatting = Formatting.Indented; |
|
60 // |
|
61 try |
|
62 { |
|
63 base.Serialize( writer ); |
|
64 } |
|
65 catch ( XmlException ) |
|
66 { |
|
67 } |
|
68 } |
|
69 } |
|
70 |
|
71 public void MakeParentCurrent() |
|
72 { |
|
73 System.Diagnostics.Debug.Assert( CurrentNode.HasParent ); |
|
74 CurrentNode = CurrentNode.Parent; |
|
75 } |
|
76 #endregion |
|
77 |
|
78 #region Properties |
|
79 public SymNode CurrentNode |
|
80 { |
|
81 get { return iCurrentNode; } |
|
82 set |
|
83 { |
|
84 iPreviousCurrentNode = iCurrentNode; |
|
85 iCurrentNode = value; |
|
86 } |
|
87 } |
|
88 |
|
89 public SymNode PreviousCurrentNode |
|
90 { |
|
91 get { return iPreviousCurrentNode; } |
|
92 } |
|
93 #endregion |
|
94 |
|
95 #region Data members |
|
96 private SymNode iCurrentNode; |
|
97 private SymNode iPreviousCurrentNode; |
|
98 #endregion |
|
99 } |
|
100 } |