1
/*********************************************************************
2
* The MIT License (MIT)
4
* Copyright (c) 2010 Manish Sinha <mail@manishsinha.net>
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
15
* The above copyright notice and this permission notice shall be
16
* included in all copies or substantial portions of the Software.
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
********************************************************************/
29
namespace LpNet.WadlAv
32
using System.Xml.Serialization;
37
/// Implements ILoader which is entrusted with loading a WADL file as per the schema
39
public class WadlLoader : ILoader
41
#region ILoader Members
44
/// Load the WADL file.
46
/// <param name="wadlData">The WADL string</param>
47
/// <returns>An instance of application (WADL Root Node)</returns>
48
public application Load(string wadlData)
50
// Create an XML Serializer for the type - 'application'
51
XmlSerializer serializer = new XmlSerializer(typeof(application));
53
StringReader strReader = new StringReader(wadlData);
55
// Try to deserilaize and type-cast the resulting type to application
56
application wadlInst = serializer.Deserialize(strReader) as application;
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
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)
74
// Create an XML Serializer for the type - 'application'
75
XmlSerializer serializer = new XmlSerializer(typeof(application));
77
// Open the stream with the provided file
78
StreamReader reader = new StreamReader(filePath.FullName);
80
// Try to deserilaize and type-cast the resulting type to application
81
application wadlInst = serializer.Deserialize(reader) as application;