1 /** 2 License: 3 Boost Software License - Version 1.0 - August 17th, 2003 4 5 Permission is hereby granted, free of charge, to any person or organization 6 obtaining a copy of the software and accompanying documentation covered by 7 this license (the "Software") to use, reproduce, display, distribute, 8 execute, and transmit the Software, and to prepare derivative works of the 9 Software, and to permit third-parties to whom the Software is furnished to 10 do so, all subject to the following: 11 12 The copyright notices in the Software and this entire statement, including 13 the above license grant, this restriction and the following disclaimer, 14 must be included in all copies of the Software, in whole or in part, and 15 all derivative works of the Software, unless such copies or derivative 16 works are solely in the form of machine-executable object code generated by 17 a source language processor. 18 19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 DEALINGS IN THE SOFTWARE. 26 27 Authors: 28 aermicioi 29 **/ 30 module aermicioi.aedi_property_reader.helper.help_decorating_factory; 31 32 import aermicioi.aedi_property_reader.convertor_factory; 33 import aermicioi.aedi.storage.decorator; 34 import aermicioi.aedi.exception.di_exception; 35 import aermicioi.aedi.factory.factory; 36 import aermicioi.aedi.storage.locator; 37 import std.range; 38 39 /** 40 A decorating factory that on exceptions chains help decorating exception to signal 41 help decorating container to throw help messages if enabled. 42 **/ 43 class HelpDecoratingFactory(T : Factory!Z, Z) : 44 Factory!Z, 45 MutableDecorator!T 46 { 47 private { 48 49 T decorated_; 50 } 51 52 public { 53 @property { 54 /** 55 Set the decorated object for decorator. 56 57 Params: 58 decorated = decorated data 59 60 Returns: 61 this 62 **/ 63 HelpDecoratingFactory!T decorated(T decorated) @safe nothrow { 64 this.decorated_ = decorated; 65 66 return this; 67 } 68 69 /** 70 Get the decorated object. 71 72 Returns: 73 T decorated object 74 **/ 75 T decorated() @safe nothrow { 76 return this.decorated_; 77 } 78 79 /** 80 Get the type info of T that is created. 81 82 Returns: 83 TypeInfo object of created component. 84 **/ 85 TypeInfo type() { 86 return this.decorated.type; 87 } 88 89 /** 90 Set a locator to object. 91 92 Params: 93 locator = the locator that is set to oject. 94 95 Returns: 96 LocatorAware. 97 **/ 98 HelpDecoratingFactory!T locator(Locator!() locator) @safe nothrow { 99 this.decorated.locator = locator; 100 101 return this; 102 } 103 } 104 105 /** 106 Instantiates component of type Z. 107 108 Throws: 109 HelpDecoratingException when an exception from underlying factory is thrown. 110 111 Returns: 112 Z instantiated component. 113 **/ 114 Z factory() { 115 try { 116 return this.decorated.factory; 117 } catch (Exception e) { 118 import aermicioi.aedi_property_reader.helper.help_decorating_exception : HelpDecoratingException; 119 120 throw new HelpDecoratingException("Error occured in help managed factory", e); 121 } 122 } 123 } 124 } 125 126 /** 127 A decorating factory that on exceptions chains help decorating exception to signal 128 help decorating container to throw help messages if enabled. 129 **/ 130 class HelpDecoratingConvertorFactory(T : ConvertorFactory!(FromType, ToType), FromType, ToType) : 131 ConvertorFactory!(FromType, ToType), 132 MutableDecorator!T 133 { 134 private { 135 T decorated_; 136 } 137 138 public { 139 @property { 140 141 /** 142 Set the decorated object for decorator. 143 144 Params: 145 decorated = decorated data 146 147 Returns: 148 this 149 **/ 150 HelpDecoratingConvertorFactory!T decorated(T decorated) @safe nothrow { 151 this.decorated_ = decorated; 152 153 return this; 154 } 155 156 /** 157 Get the decorated object. 158 159 Returns: 160 T decorated object 161 **/ 162 T decorated() @safe nothrow { 163 return this.decorated_; 164 } 165 166 /** 167 Set convertible 168 169 Params: 170 convertible = data that the factory should convert into ToType component 171 Returns: 172 ConvertorFactory!(FromType, ToType) 173 **/ 174 HelpDecoratingConvertorFactory!T convertible(string convertible) @safe nothrow { 175 this.decorated.convertible = convertible; 176 177 return this; 178 } 179 180 /** 181 Get convertible data 182 183 Returns: 184 FromType 185 **/ 186 string convertible() @safe nothrow { 187 return this.decorated.convertible; 188 } 189 190 /** 191 Set a locator to object. 192 193 Params: 194 locator = the locator that is set to oject. 195 196 Returns: 197 LocatorAware. 198 **/ 199 HelpDecoratingConvertorFactory!T locator(Locator!() locator) @safe nothrow { 200 this.decorated.locator = locator; 201 202 return this; 203 } 204 205 /** 206 Get the type info of T that is created. 207 208 Returns: 209 TypeInfo object of created component. 210 **/ 211 TypeInfo type() { 212 return this.decorated.type; 213 } 214 } 215 216 /** 217 Instantiates component of type ToType. 218 219 Throws: 220 HelpDecoratingException when an exception from underlying factory is thrown. 221 222 Returns: 223 ToType instantiated component. 224 **/ 225 ToType factory() { 226 try { 227 return this.decorated.factory; 228 } catch (Exception e) { 229 import aermicioi.aedi_property_reader.helper.help_decorating_exception : HelpDecoratingException; 230 231 throw new HelpDecoratingException("Error occured in help managed factory", e); 232 } 233 } 234 } 235 }