This repository has been archived by the owner on Jul 3, 2019. It is now read-only.
/
PropertyInjectionPoint.as
76 lines (68 loc) · 2.44 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*
* 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.Dictionary;
import org.swiftsuspenders.InjectionConfig;
import org.swiftsuspenders.Injector;
import org.swiftsuspenders.InjectorError;
public class PropertyInjectionPoint extends InjectionPoint
{
/*******************************************************************************************
* private properties *
*******************************************************************************************/
private var mappings : Dictionary;
private var propertyName : String;
private var propertyType : String;
/*******************************************************************************************
* public methods *
*******************************************************************************************/
public function PropertyInjectionPoint(node : XML, injectorMappings : Dictionary)
{
super(node, injectorMappings);
}
override public function applyInjection(target : Object, singletons : Dictionary) : Object
{
var config : InjectionConfig = mappings[propertyType];
if (!config)
{
throw(
new InjectorError(
'Injector is missing a rule to handle injection into target ' + target +
'. Target dependency: ' + propertyType
)
);
}
var injection : Object = config.getResponse(singletons);
target[propertyName] = injection;
return target;
}
/*******************************************************************************************
* protected methods *
*******************************************************************************************/
override protected function initializeInjection(node : XML, injectorMappings : Dictionary) : void
{
var mappings : Dictionary;
if (node.hasOwnProperty('arg') && node.arg.(@key == 'name').length)
{
injectionName = node.arg.@value.toString();
mappings = injectorMappings[injectionName];
if (!mappings)
{
mappings = injectorMappings[injectionName] = new Dictionary();
}
}
else
{
mappings = injectorMappings;
}
this.mappings = mappings;
propertyType = node.parent().@type.toString();
propertyName = node.parent().@name.toString();
}
}
}