| |||||||||||||||||
Source File | Conditionals | Statements | Methods | TOTAL | |||||||||||||
Model\AttributeModel\AttributeObjectHandlerMethodCaller.cs | 0,0 % | 0,0 % | 0,0 % | 0,0 % |
|
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; | |
25 | using System.Reflection; | |
26 | using ShowX.Model.AttributeModel; | |
27 | using log4net; | |
28 | ||
29 | namespace ShowX.Model | |
30 | { | |
31 | /// <summary> | |
32 | /// AttributeObjectHandlerProxy implements mapping to IObjectHandlerMethodCaller | |
33 | /// methods based on the attribute mapping model. | |
34 | /// </summary> | |
35 | public class AttributeObjectHandlerMethodCaller : ObjectHandlerMethodCaller | |
36 | { | |
37 | private static readonly ILog log = LogManager.GetLogger( | |
38 | typeof(AttributeObjectHandlerMethodCaller)); | |
39 | ||
40 | /// <summary> | |
41 | /// Helper method to retrieve and build the Object Handler attached to a | |
42 | /// certain type. | |
43 | /// </summary> | |
44 | /// <param name="t">Type to get object handler.</param> | |
45 | /// <returns>An instance of the object handler attached to type t.</returns> | |
46 | 0 | protected override IObjectHandler BuildObjectHandlerFromType(Type t) |
47 | { | |
48 | IObjectHandlerInfo info = t.GetCustomAttributes( | |
49 | typeof(AttributeObjectHandlerInfo),true)[0] | |
50 | as IObjectHandlerInfo; | |
51 | ||
52 | if (info == null) { | |
53 | ||
54 | string errorMsg = string.Format( | |
55 | "No object handler defined for type {0}",t.Name); | |
56 | ||
57 | log.Fatal(errorMsg); | |
58 | throw new Exception(errorMsg); | |
59 | } | |
60 | ||
61 | IObjectHandler objectHandler = info.Type.InvokeMember("", | |
62 | BindingFlags.CreateInstance,null,null,null) as IObjectHandler; | |
63 | ||
64 | if (objectHandler == null) { | |
65 | ||
66 | string errorMsg = string.Format( | |
67 | "Object handler for type {0} cannot be loaded",t.Name); | |
68 | ||
69 | log.Fatal(errorMsg); | |
70 | throw new Exception(errorMsg); | |
71 | } | |
72 | ||
73 | return objectHandler; | |
74 | } | |
75 | } | |
76 | } | |
77 |
|