This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
/
PropertyInjectionPoint.as
62 lines (54 loc) · 2.17 KB
/
PropertyInjectionPoint.as
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
* Copyright (c) 2009 the original author or authors
*
* Permission is hereby granted to use, modify, and distribute this file
* in accordance with the terms of the license agreement accompanying it.
*/
package org.swiftsuspenders.injectionpoints
{
import flash.utils.getDefinitionByName;
import org.swiftsuspenders.InjectionConfig;
import org.swiftsuspenders.Injector;
import org.swiftsuspenders.InjectorError;
public class PropertyInjectionPoint extends InjectionPoint
{
/*******************************************************************************************
* private properties *
*******************************************************************************************/
private var propertyName : String;
private var propertyType : String;
private var m_injectionConfig : InjectionConfig;
/*******************************************************************************************
* public methods *
*******************************************************************************************/
public function PropertyInjectionPoint(node : XML, injector : Injector)
{
super(node, injector);
}
override public function applyInjection(target : Object, injector : Injector) : Object
{
var injection : Object = m_injectionConfig.getResponse(injector);
if (injection == null)
{
throw(
new InjectorError(
'Injector is missing a rule to handle injection into target ' + target +
'. Target dependency: ' + propertyType
)
);
}
target[propertyName] = injection;
return target;
}
/*******************************************************************************************
* protected methods *
*******************************************************************************************/
override protected function initializeInjection(node : XML, injector : Injector) : void
{
propertyType = node.parent().@type.toString();
propertyName = node.parent().@name.toString();
m_injectionConfig = injector.getMapping(Class(injector.getApplicationDomain().getDefinition(propertyType)),
node.arg.attribute('value').toString());
}
}
}