~manishsinha/wadlav/trunk

« back to all changes in this revision

Viewing changes to LpNet.WadlAv/WadlLoader.cs

  • Committer: Manish Sinha
  • Date: 2010-05-06 20:23:41 UTC
  • Revision ID: manishsinha27@gmail.com-20100506202341-2choardcs9y3kvwp
FIRST COMMIT
* Added WADL schema and schema code file
* Created WadlLoader
* Created WadlAvUtils
* Added HttpMethod and LanguageConstructType Enums

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*********************************************************************
 
2
 * The MIT License (MIT)
 
3
 * 
 
4
 * Copyright (c) 2010 Manish Sinha <mail@manishsinha.net>
 
5
 * 
 
6
 * Permission is hereby granted, free of charge, to any person
 
7
 * obtaining a copy of this software and associated documentation
 
8
 * files (the "Software"), to deal in the Software without
 
9
 * restriction, including without limitation the rights to use,
 
10
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 
11
 * copies of the Software, and to permit persons to whom the
 
12
 * Software is furnished to do so, subject to the following
 
13
 * conditions:
 
14
 
 
15
 * The above copyright notice and this permission notice shall be
 
16
 * included in all copies or substantial portions of the Software.
 
17
 * 
 
18
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
19
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 
20
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
21
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 
22
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 
23
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 
25
 * OTHER DEALINGS IN THE SOFTWARE.
 
26
 ********************************************************************/
 
27
 
 
28
 
 
29
namespace LpNet.WadlAv
 
30
{
 
31
    using System.IO;
 
32
    using System.Xml.Serialization;
 
33
    using Interface;
 
34
    using Resource;
 
35
 
 
36
    /// <summary>
 
37
    /// Implements ILoader which is entrusted with loading a WADL file as per the schema
 
38
    /// </summary>
 
39
    public class WadlLoader : ILoader
 
40
    {
 
41
        #region ILoader Members
 
42
 
 
43
        /// <summary>
 
44
        /// Load the WADL file.
 
45
        /// </summary>
 
46
        /// <param name="wadlData">The WADL string</param>
 
47
        /// <returns>An instance of application (WADL Root Node)</returns>
 
48
        public application Load(string wadlData)
 
49
        {
 
50
            // Create an XML Serializer for the type - 'application'
 
51
            XmlSerializer serializer = new XmlSerializer(typeof(application));
 
52
 
 
53
            StringReader strReader = new StringReader(wadlData);
 
54
 
 
55
            // Try to deserilaize and type-cast the resulting type to application
 
56
            application wadlInst = serializer.Deserialize(strReader) as application;
 
57
 
 
58
            // Close the Stream
 
59
            strReader.Close();
 
60
 
 
61
            return wadlInst;
 
62
        }
 
63
 
 
64
        /// <summary>
 
65
        /// Load the WADL file.
 
66
        /// Possible Exceptions: 
 
67
        /// 1) FileNotFoundException for non-existing file
 
68
        /// 2) IOException for invalid characters in the file path
 
69
        /// </summary>
 
70
        /// <param name="filePath">The WADL file path</param>
 
71
        /// <returns>An instance of application (WADL Root Node)</returns>
 
72
        public application Load(FileInfo filePath)
 
73
        {
 
74
            // Create an XML Serializer for the type - 'application'
 
75
            XmlSerializer serializer = new XmlSerializer(typeof(application));
 
76
 
 
77
            // Open the stream with the provided file
 
78
            StreamReader reader = new StreamReader(filePath.FullName);
 
79
 
 
80
            // Try to deserilaize and type-cast the resulting type to application
 
81
            application wadlInst = serializer.Deserialize(reader) as application;
 
82
 
 
83
            // Close the Stream
 
84
            reader.Close();
 
85
 
 
86
            return wadlInst;
 
87
        }
 
88
 
 
89
        #endregion
 
90
    }
 
91
}