asunit4 4.2.2.pre → 4.2.3.pre
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +26 -0
- data/bin/AsUnit-4.1.2.swc +0 -0
- data/bin/AsUnit-4.2.3.pre.swc +0 -0
- data/bin/AsUnitRunner.swf +0 -0
- data/bin/Flex4AsUnitRunner.swf +0 -0
- data/build.xml +42 -2
- data/lib/SwiftSuspenders-v1.5.1.swc +0 -0
- data/lib/flexUnitTasks.jar +0 -0
- data/pkg/sprout-asunit4-library-4.1.2.gem +0 -0
- data/rakefile.rb +4 -1
- data/sprout/lib/asunit4.rb +1 -1
- data/src/asunit/asserts/assertMatches.as +6 -0
- data/src/asunit/asserts/assertThrowsWithMessage.as +5 -0
- data/src/asunit/core/AsUnitCore.as +42 -88
- data/src/asunit/core/FlashBuilderCore.as +2 -2
- data/src/asunit/core/FlashDevelopCore.as +1 -1
- data/src/asunit/core/FlexUnitCICore.as +17 -0
- data/src/asunit/core/TextCore.as +36 -54
- data/src/asunit/framework/Assert.as +76 -11
- data/src/asunit/framework/Async.as +1 -1
- data/src/asunit/framework/IResult.as +1 -6
- data/src/asunit/framework/IRunListener.as +0 -3
- data/src/asunit/framework/IRunner.as +0 -3
- data/src/asunit/framework/IRunnerFactory.as +3 -3
- data/src/asunit/framework/ITestListener.as +1 -2
- data/src/asunit/framework/Method.as +82 -80
- data/src/asunit/framework/Result.as +3 -24
- data/src/asunit/framework/RunnerFactory.as +13 -34
- data/src/asunit/framework/SuiteIterator.as +28 -22
- data/src/asunit/framework/TestCase.as +8 -3
- data/src/asunit/printers/FlashBuilderPrinter.as +25 -83
- data/src/asunit/printers/FlashDevelopPrinter.as +1 -2
- data/src/asunit/printers/FlexUnitCIPrinter.as +181 -0
- data/src/asunit/printers/TextPrinter.as +17 -46
- data/src/asunit/printers/XMLPrinter.as +127 -0
- data/src/asunit/runners/LegacyRunner.as +6 -1
- data/src/asunit/runners/SuiteRunner.as +30 -66
- data/src/asunit/runners/TestRunner.as +90 -255
- data/test/AllTests.as +9 -4
- data/test/AsUnitCIRunner.as +18 -0
- data/test/AsUnitRunner.as +2 -0
- data/test/AsUnitRunnerCS3.fla +0 -0
- data/test/asunit/core/AsUnitCoreTest.as +33 -15
- data/test/asunit/framework/AssertEqualsArraysIgnoringOrderTest.as +14 -0
- data/test/asunit/framework/AssertThrowsWithMessageTest.as +50 -0
- data/test/asunit/framework/AsyncTest.as +0 -4
- data/test/asunit/framework/ProceedOnEventTest.as +1 -2
- data/test/asunit/framework/ResultObserverTest.as +61 -0
- data/test/asunit/framework/RunnerFactoryTest.as +7 -9
- data/test/asunit/framework/VisualTestCaseTest.as +2 -26
- data/test/asunit/printers/FlashBuilderPrinterTest.as +18 -0
- data/test/asunit/printers/XMLPrinterTest.as +131 -0
- data/test/asunit/runners/LegacyRunnerTest.as +4 -4
- data/test/asunit/runners/SuiteRunnerTest.as +10 -7
- data/test/asunit/runners/TestRunnerAsyncMethodTest.as +9 -7
- data/test/asunit/runners/TestRunnerErrorMethodTest.as +1 -1
- data/test/asunit/runners/TestRunnerExpectsErrorTest.as +2 -2
- data/test/asunit/runners/TestRunnerExpectsErrorWithMessageTest.as +125 -0
- data/test/asunit/runners/TestRunnerIgnoredMethodTest.as +2 -3
- data/test/asunit/runners/TestRunnerTest.as +4 -27
- data/test/asunit/support/{CustomTestRunner.as → CustomSuiteRunner.as} +7 -3
- data/test/asunit/support/InjectionVerification.as +2 -30
- data/test/asunit/support/SuiteWithCustomRunner.as +1 -1
- data/vendor/as3injection/org/swiftsuspenders/InjectionConfig.as +78 -0
- data/vendor/as3injection/org/swiftsuspenders/InjectionType.as +16 -0
- data/vendor/as3injection/org/swiftsuspenders/Injector.as +376 -0
- data/vendor/as3injection/org/swiftsuspenders/InjectorError.as +17 -0
- data/vendor/as3injection/org/swiftsuspenders/Reflector.as +95 -0
- data/vendor/as3injection/org/swiftsuspenders/getConstructor.as +33 -0
- data/vendor/as3injection/org/swiftsuspenders/injectionpoints/ConstructorInjectionPoint.as +94 -0
- data/vendor/as3injection/org/swiftsuspenders/injectionpoints/InjectionPoint.as +35 -0
- data/vendor/as3injection/org/swiftsuspenders/injectionpoints/MethodInjectionPoint.as +122 -0
- data/vendor/as3injection/org/swiftsuspenders/injectionpoints/NoParamsConstructorInjectionPoint.as +24 -0
- data/vendor/as3injection/org/swiftsuspenders/injectionpoints/PostConstructInjectionPoint.as +52 -0
- data/vendor/as3injection/org/swiftsuspenders/injectionpoints/PropertyInjectionPoint.as +62 -0
- data/vendor/as3injection/org/swiftsuspenders/injectionresults/InjectClassResult.as +33 -0
- data/vendor/as3injection/org/swiftsuspenders/injectionresults/InjectOtherRuleResult.as +34 -0
- data/vendor/as3injection/org/swiftsuspenders/injectionresults/InjectSingletonResult.as +43 -0
- data/vendor/as3injection/org/swiftsuspenders/injectionresults/InjectValueResult.as +33 -0
- data/vendor/as3injection/org/swiftsuspenders/injectionresults/InjectionResult.as +26 -0
- metadata +44 -19
- data/bin/AsUnit-4.2.1.pre.swc +0 -0
- data/bin/AsUnit-4.2.2.pre.swc +0 -0
- data/src/asunit/framework/CallbackBridge.as +0 -175
- data/src/asunit/framework/ITestResult.as +0 -21
- data/src/asunit/framework/InjectionDelegate.as +0 -96
- data/src/asunit/framework/MessageBridge.as +0 -24
- data/src/asunit/framework/TestObserver.as +0 -12
- data/test/asunit/framework/CallbackBridgeTest.as +0 -73
- data/test/asunit/framework/InjectionDelegateTest.as +0 -79
- data/test/asunit/support/AnnotatedSubClass.as +0 -18
- data/test/asunit/support/AnnotatedSuperClass.as +0 -15
- data/test/asunit/support/FakeRunner.as +0 -32
- data/test/asunit/support/InjectTimeoutOnAsync.as +0 -14
- data/test/asunit/support/TestForFakeRunner.as +0 -14
@@ -1,17 +1,21 @@
|
|
1
1
|
package asunit.support {
|
2
2
|
|
3
|
-
import asunit.framework.CallbackBridge;
|
4
3
|
import asunit.framework.IResult;
|
5
|
-
|
4
|
+
import asunit.framework.IRunnerFactory;
|
5
|
+
import asunit.runners.SuiteRunner;
|
6
6
|
|
7
7
|
import flash.display.DisplayObjectContainer;
|
8
8
|
|
9
|
-
public class
|
9
|
+
public class CustomSuiteRunner extends SuiteRunner {
|
10
10
|
|
11
11
|
// Used so that test cases can
|
12
12
|
// verify that this custom runner
|
13
13
|
// worked.
|
14
14
|
public static var runCalledCount:int;
|
15
|
+
|
16
|
+
public function CustomSuiteRunner(factory:IRunnerFactory = null) {
|
17
|
+
super(factory);
|
18
|
+
}
|
15
19
|
|
16
20
|
override public function run(testClass:Class, testMethod:String=null, visualContext:DisplayObjectContainer=null):void {
|
17
21
|
runCalledCount++;
|
@@ -17,42 +17,14 @@ package asunit.support {
|
|
17
17
|
[Inject]
|
18
18
|
public var context:Sprite;
|
19
19
|
|
20
|
-
[Inject(someString="stringValue", someBoolean=false, someNumber=23.4, someInt=-23, someUInt=25)]
|
21
|
-
public var custom:CustomParameters;
|
22
|
-
|
23
|
-
[Test]
|
24
|
-
public function injectedShouldReceiveUIntValue():void {
|
25
|
-
assertSame(25, custom.someUInt);
|
26
|
-
}
|
27
|
-
|
28
|
-
[Test]
|
29
|
-
public function injectedShouldReceiveIntegerValue():void {
|
30
|
-
assertSame(-23, custom.someInt);
|
31
|
-
}
|
32
|
-
|
33
|
-
[Test]
|
34
|
-
public function injectedShouldReceiveNumberValue():void {
|
35
|
-
assertSame(23.4, custom.someNumber);
|
36
|
-
}
|
37
|
-
|
38
|
-
[Test]
|
39
|
-
public function injectedShouldReceiveBooleanValue():void {
|
40
|
-
assertSame(false, custom.someBoolean);
|
41
|
-
}
|
42
|
-
|
43
|
-
[Test]
|
44
|
-
public function injectedShouldReceiveStringValue():void {
|
45
|
-
assertEquals("stringValue", custom.someString);
|
46
|
-
}
|
47
|
-
|
48
20
|
[Test]
|
49
21
|
public function verifyDisplayObjectInjection():void {
|
50
|
-
assertNotNull("DisplayObject should
|
22
|
+
assertNotNull("DisplayObject should exist", context);
|
51
23
|
}
|
52
24
|
|
53
25
|
[Test]
|
54
26
|
public function verifyDisplayObjectAttachedToStage():void {
|
55
|
-
assertNotNull("DisplayObjects
|
27
|
+
assertNotNull("DisplayObjects should be attached to stage", context.stage);
|
56
28
|
}
|
57
29
|
|
58
30
|
[Test]
|
@@ -0,0 +1,78 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2009 the original author or authors
|
3
|
+
*
|
4
|
+
* Permission is hereby granted to use, modify, and distribute this file
|
5
|
+
* in accordance with the terms of the license agreement accompanying it.
|
6
|
+
*/
|
7
|
+
|
8
|
+
package org.swiftsuspenders
|
9
|
+
{
|
10
|
+
import org.swiftsuspenders.injectionresults.InjectionResult;
|
11
|
+
|
12
|
+
public class InjectionConfig
|
13
|
+
{
|
14
|
+
/*******************************************************************************************
|
15
|
+
* public properties *
|
16
|
+
*******************************************************************************************/
|
17
|
+
public var request : Class;
|
18
|
+
public var injectionName : String;
|
19
|
+
|
20
|
+
|
21
|
+
/*******************************************************************************************
|
22
|
+
* private properties *
|
23
|
+
*******************************************************************************************/
|
24
|
+
private var m_injector : Injector;
|
25
|
+
private var m_result : InjectionResult;
|
26
|
+
|
27
|
+
|
28
|
+
/*******************************************************************************************
|
29
|
+
* public methods *
|
30
|
+
*******************************************************************************************/
|
31
|
+
public function InjectionConfig(request : Class, injectionName : String)
|
32
|
+
{
|
33
|
+
this.request = request;
|
34
|
+
this.injectionName = injectionName;
|
35
|
+
}
|
36
|
+
|
37
|
+
public function getResponse(injector : Injector) : Object
|
38
|
+
{
|
39
|
+
if (m_result)
|
40
|
+
{
|
41
|
+
return m_result.getResponse(m_injector || injector);
|
42
|
+
}
|
43
|
+
var parentConfig : InjectionConfig =
|
44
|
+
(m_injector || injector).getAncestorMapping(request, injectionName);
|
45
|
+
if (parentConfig)
|
46
|
+
{
|
47
|
+
return parentConfig.getResponse(injector);
|
48
|
+
}
|
49
|
+
return null;
|
50
|
+
}
|
51
|
+
|
52
|
+
public function hasResponse(injector : Injector) : Boolean
|
53
|
+
{
|
54
|
+
if (m_result)
|
55
|
+
{
|
56
|
+
return true;
|
57
|
+
}
|
58
|
+
var parentConfig : InjectionConfig =
|
59
|
+
(m_injector || injector).getAncestorMapping(request, injectionName);
|
60
|
+
return parentConfig != null;
|
61
|
+
}
|
62
|
+
|
63
|
+
public function hasOwnResponse() : Boolean
|
64
|
+
{
|
65
|
+
return m_result != null;
|
66
|
+
}
|
67
|
+
|
68
|
+
public function setResult(result : InjectionResult) : void
|
69
|
+
{
|
70
|
+
m_result = result;
|
71
|
+
}
|
72
|
+
|
73
|
+
public function setInjector(injector : Injector) : void
|
74
|
+
{
|
75
|
+
m_injector = injector;
|
76
|
+
}
|
77
|
+
}
|
78
|
+
}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2009 the original author or authors
|
3
|
+
*
|
4
|
+
* Permission is hereby granted to use, modify, and distribute this file
|
5
|
+
* in accordance with the terms of the license agreement accompanying it.
|
6
|
+
*/
|
7
|
+
|
8
|
+
package org.swiftsuspenders
|
9
|
+
{
|
10
|
+
public class InjectionType
|
11
|
+
{
|
12
|
+
public static const VALUE : int = 0;
|
13
|
+
public static const CLASS : int = 1;
|
14
|
+
public static const SINGLETON : int = 2;
|
15
|
+
}
|
16
|
+
}
|
@@ -0,0 +1,376 @@
|
|
1
|
+
/*
|
2
|
+
* Copyright (c) 2009-2010 the original author or authors
|
3
|
+
*
|
4
|
+
* Permission is hereby granted to use, modify, and distribute this file
|
5
|
+
* in accordance with the terms of the license agreement accompanying it.
|
6
|
+
*/
|
7
|
+
|
8
|
+
package org.swiftsuspenders
|
9
|
+
{
|
10
|
+
import flash.system.ApplicationDomain;
|
11
|
+
import flash.utils.Dictionary;
|
12
|
+
import flash.utils.Proxy;
|
13
|
+
import flash.utils.describeType;
|
14
|
+
import flash.utils.getDefinitionByName;
|
15
|
+
import flash.utils.getQualifiedClassName;
|
16
|
+
|
17
|
+
import org.swiftsuspenders.injectionpoints.ConstructorInjectionPoint;
|
18
|
+
import org.swiftsuspenders.injectionpoints.InjectionPoint;
|
19
|
+
import org.swiftsuspenders.injectionpoints.MethodInjectionPoint;
|
20
|
+
import org.swiftsuspenders.injectionpoints.NoParamsConstructorInjectionPoint;
|
21
|
+
import org.swiftsuspenders.injectionpoints.PostConstructInjectionPoint;
|
22
|
+
import org.swiftsuspenders.injectionpoints.PropertyInjectionPoint;
|
23
|
+
import org.swiftsuspenders.injectionresults.InjectClassResult;
|
24
|
+
import org.swiftsuspenders.injectionresults.InjectOtherRuleResult;
|
25
|
+
import org.swiftsuspenders.injectionresults.InjectSingletonResult;
|
26
|
+
import org.swiftsuspenders.injectionresults.InjectValueResult;
|
27
|
+
|
28
|
+
public class Injector
|
29
|
+
{
|
30
|
+
/*******************************************************************************************
|
31
|
+
* private properties *
|
32
|
+
*******************************************************************************************/
|
33
|
+
private var m_parentInjector : Injector;
|
34
|
+
private var m_applicationDomain:ApplicationDomain;
|
35
|
+
private var m_mappings : Dictionary;
|
36
|
+
private var m_injectionPointLists : Dictionary;
|
37
|
+
private var m_constructorInjectionPoints : Dictionary;
|
38
|
+
private var m_attendedToInjectees : Dictionary;
|
39
|
+
private var m_xmlMetadata : XML;
|
40
|
+
|
41
|
+
|
42
|
+
/*******************************************************************************************
|
43
|
+
* public methods *
|
44
|
+
*******************************************************************************************/
|
45
|
+
public function Injector(xmlConfig : XML = null)
|
46
|
+
{
|
47
|
+
m_mappings = new Dictionary();
|
48
|
+
m_injectionPointLists = new Dictionary();
|
49
|
+
m_constructorInjectionPoints = new Dictionary();
|
50
|
+
m_attendedToInjectees = new Dictionary(true);
|
51
|
+
m_xmlMetadata = xmlConfig;
|
52
|
+
}
|
53
|
+
|
54
|
+
public function mapValue(whenAskedFor : Class, useValue : Object, named : String = "") : *
|
55
|
+
{
|
56
|
+
var config : InjectionConfig = getMapping(whenAskedFor, named);
|
57
|
+
config.setResult(new InjectValueResult(useValue));
|
58
|
+
return config;
|
59
|
+
}
|
60
|
+
|
61
|
+
public function mapClass(
|
62
|
+
whenAskedFor : Class, instantiateClass : Class, named : String = "") : *
|
63
|
+
{
|
64
|
+
var config : InjectionConfig = getMapping(whenAskedFor, named);
|
65
|
+
config.setResult(new InjectClassResult(instantiateClass));
|
66
|
+
return config;
|
67
|
+
}
|
68
|
+
|
69
|
+
public function mapSingleton(whenAskedFor : Class, named : String = "") : *
|
70
|
+
{
|
71
|
+
return mapSingletonOf(whenAskedFor, whenAskedFor, named);
|
72
|
+
}
|
73
|
+
|
74
|
+
public function mapSingletonOf(
|
75
|
+
whenAskedFor : Class, useSingletonOf : Class, named : String = "") : *
|
76
|
+
{
|
77
|
+
var config : InjectionConfig = getMapping(whenAskedFor, named);
|
78
|
+
config.setResult(new InjectSingletonResult(useSingletonOf));
|
79
|
+
return config;
|
80
|
+
}
|
81
|
+
|
82
|
+
public function mapRule(whenAskedFor : Class, useRule : *, named : String = "") : *
|
83
|
+
{
|
84
|
+
var config : InjectionConfig = getMapping(whenAskedFor, named);
|
85
|
+
config.setResult(new InjectOtherRuleResult(useRule));
|
86
|
+
return useRule;
|
87
|
+
}
|
88
|
+
|
89
|
+
public function getMapping(whenAskedFor : Class, named : String = "") : InjectionConfig
|
90
|
+
{
|
91
|
+
var requestName : String = getQualifiedClassName(whenAskedFor);
|
92
|
+
var config : InjectionConfig = m_mappings[requestName + '#' + named];
|
93
|
+
if (!config)
|
94
|
+
{
|
95
|
+
config = m_mappings[requestName + '#' + named] =
|
96
|
+
new InjectionConfig(whenAskedFor, named);
|
97
|
+
}
|
98
|
+
return config;
|
99
|
+
}
|
100
|
+
|
101
|
+
public function injectInto(target : Object) : void
|
102
|
+
{
|
103
|
+
if (m_attendedToInjectees[target])
|
104
|
+
{
|
105
|
+
return;
|
106
|
+
}
|
107
|
+
m_attendedToInjectees[target] = true;
|
108
|
+
|
109
|
+
//get injection points or cache them if this target's class wasn't encountered before
|
110
|
+
var injectionPoints : Array;
|
111
|
+
|
112
|
+
var ctor : Class = getConstructor(target);
|
113
|
+
|
114
|
+
injectionPoints = m_injectionPointLists[ctor] || getInjectionPoints(ctor);
|
115
|
+
|
116
|
+
var length : int = injectionPoints.length;
|
117
|
+
for (var i : int = 0; i < length; i++)
|
118
|
+
{
|
119
|
+
var injectionPoint : InjectionPoint = injectionPoints[i];
|
120
|
+
injectionPoint.applyInjection(target, this);
|
121
|
+
}
|
122
|
+
|
123
|
+
}
|
124
|
+
|
125
|
+
public function instantiate(clazz:Class):*
|
126
|
+
{
|
127
|
+
var injectionPoint : InjectionPoint = m_constructorInjectionPoints[clazz];
|
128
|
+
if (!injectionPoint)
|
129
|
+
{
|
130
|
+
getInjectionPoints(clazz);
|
131
|
+
injectionPoint = m_constructorInjectionPoints[clazz];
|
132
|
+
}
|
133
|
+
var instance : * = injectionPoint.applyInjection(clazz, this);
|
134
|
+
injectInto(instance);
|
135
|
+
return instance;
|
136
|
+
}
|
137
|
+
|
138
|
+
public function unmap(clazz : Class, named : String = "") : void
|
139
|
+
{
|
140
|
+
var mapping : InjectionConfig = getConfigurationForRequest(clazz, named);
|
141
|
+
if (!mapping)
|
142
|
+
{
|
143
|
+
throw new InjectorError('Error while removing an injector mapping: ' +
|
144
|
+
'No mapping defined for class ' + getQualifiedClassName(clazz) +
|
145
|
+
', named "' + named + '"');
|
146
|
+
}
|
147
|
+
mapping.setResult(null);
|
148
|
+
}
|
149
|
+
|
150
|
+
public function hasMapping(clazz : Class, named : String = '') : Boolean
|
151
|
+
{
|
152
|
+
var mapping : InjectionConfig = getConfigurationForRequest(clazz, named);
|
153
|
+
if (!mapping)
|
154
|
+
{
|
155
|
+
return false;
|
156
|
+
}
|
157
|
+
return mapping.hasResponse(this);
|
158
|
+
}
|
159
|
+
|
160
|
+
public function getInstance(clazz : Class, named : String = '') : *
|
161
|
+
{
|
162
|
+
var mapping : InjectionConfig = getConfigurationForRequest(clazz, named);
|
163
|
+
if (!mapping || !mapping.hasResponse(this))
|
164
|
+
{
|
165
|
+
throw new InjectorError('Error while getting mapping response: ' +
|
166
|
+
'No mapping defined for class ' + getQualifiedClassName(clazz) +
|
167
|
+
', named "' + named + '"');
|
168
|
+
}
|
169
|
+
return mapping.getResponse(this);
|
170
|
+
}
|
171
|
+
|
172
|
+
public function createChildInjector(applicationDomain:ApplicationDomain=null) : Injector
|
173
|
+
{
|
174
|
+
var injector : Injector = new Injector();
|
175
|
+
injector.setApplicationDomain(applicationDomain);
|
176
|
+
injector.setParentInjector(this);
|
177
|
+
return injector;
|
178
|
+
}
|
179
|
+
|
180
|
+
public function setApplicationDomain(applicationDomain:ApplicationDomain):void
|
181
|
+
{
|
182
|
+
m_applicationDomain = applicationDomain;
|
183
|
+
}
|
184
|
+
|
185
|
+
public function getApplicationDomain():ApplicationDomain
|
186
|
+
{
|
187
|
+
return m_applicationDomain ? m_applicationDomain : ApplicationDomain.currentDomain;
|
188
|
+
}
|
189
|
+
|
190
|
+
public function setParentInjector(parentInjector : Injector) : void
|
191
|
+
{
|
192
|
+
//restore own map of worked injectees if parent injector is removed
|
193
|
+
if (m_parentInjector && !parentInjector)
|
194
|
+
{
|
195
|
+
m_attendedToInjectees = new Dictionary(true);
|
196
|
+
}
|
197
|
+
m_parentInjector = parentInjector;
|
198
|
+
//use parent's map of worked injectees
|
199
|
+
if (parentInjector)
|
200
|
+
{
|
201
|
+
m_attendedToInjectees = parentInjector.attendedToInjectees;
|
202
|
+
}
|
203
|
+
}
|
204
|
+
|
205
|
+
public function getParentInjector() : Injector
|
206
|
+
{
|
207
|
+
return m_parentInjector;
|
208
|
+
}
|
209
|
+
|
210
|
+
|
211
|
+
/*******************************************************************************************
|
212
|
+
* internal methods *
|
213
|
+
*******************************************************************************************/
|
214
|
+
internal function getAncestorMapping(
|
215
|
+
whenAskedFor : Class, named : String = null) : InjectionConfig
|
216
|
+
{
|
217
|
+
var parent : Injector = m_parentInjector;
|
218
|
+
while (parent)
|
219
|
+
{
|
220
|
+
var parentConfig : InjectionConfig =
|
221
|
+
parent.getConfigurationForRequest(whenAskedFor, named, false);
|
222
|
+
if (parentConfig && parentConfig.hasOwnResponse())
|
223
|
+
{
|
224
|
+
return parentConfig;
|
225
|
+
}
|
226
|
+
parent = parent.getParentInjector();
|
227
|
+
}
|
228
|
+
return null;
|
229
|
+
}
|
230
|
+
|
231
|
+
internal function get attendedToInjectees() : Dictionary
|
232
|
+
{
|
233
|
+
return m_attendedToInjectees;
|
234
|
+
}
|
235
|
+
|
236
|
+
|
237
|
+
/*******************************************************************************************
|
238
|
+
* private methods *
|
239
|
+
*******************************************************************************************/
|
240
|
+
private function getInjectionPoints(clazz : Class) : Array
|
241
|
+
{
|
242
|
+
var description : XML = describeType(clazz);
|
243
|
+
var injectionPoints : Array = [];
|
244
|
+
m_injectionPointLists[clazz] = injectionPoints;
|
245
|
+
m_injectionPointLists[description.@name.toString()] = injectionPoints;
|
246
|
+
var node : XML;
|
247
|
+
|
248
|
+
// This is where we have to wire in the XML...
|
249
|
+
if(m_xmlMetadata)
|
250
|
+
{
|
251
|
+
createInjectionPointsFromConfigXML(description);
|
252
|
+
addParentInjectionPoints(description, injectionPoints);
|
253
|
+
}
|
254
|
+
|
255
|
+
var injectionPoint : InjectionPoint;
|
256
|
+
//get constructor injections
|
257
|
+
node = description.factory.constructor[0];
|
258
|
+
if (node)
|
259
|
+
{
|
260
|
+
m_constructorInjectionPoints[clazz] =
|
261
|
+
new ConstructorInjectionPoint(node, clazz, this);
|
262
|
+
}
|
263
|
+
else
|
264
|
+
{
|
265
|
+
m_constructorInjectionPoints[clazz] = new NoParamsConstructorInjectionPoint();
|
266
|
+
}
|
267
|
+
//get injection points for variables
|
268
|
+
for each (node in description.factory.*.
|
269
|
+
(name() == 'variable' || name() == 'accessor').metadata.(@name == 'Inject'))
|
270
|
+
{
|
271
|
+
injectionPoint = new PropertyInjectionPoint(node, this);
|
272
|
+
injectionPoints.push(injectionPoint);
|
273
|
+
}
|
274
|
+
|
275
|
+
//get injection points for methods
|
276
|
+
for each (node in description.factory.method.metadata.(@name == 'Inject'))
|
277
|
+
{
|
278
|
+
injectionPoint = new MethodInjectionPoint(node, this);
|
279
|
+
injectionPoints.push(injectionPoint);
|
280
|
+
}
|
281
|
+
|
282
|
+
//get post construct methods
|
283
|
+
var postConstructMethodPoints : Array = [];
|
284
|
+
for each (node in description.factory.method.metadata.(@name == 'PostConstruct'))
|
285
|
+
{
|
286
|
+
injectionPoint = new PostConstructInjectionPoint(node, this);
|
287
|
+
postConstructMethodPoints.push(injectionPoint);
|
288
|
+
}
|
289
|
+
if (postConstructMethodPoints.length > 0)
|
290
|
+
{
|
291
|
+
postConstructMethodPoints.sortOn("order", Array.NUMERIC);
|
292
|
+
injectionPoints.push.apply(injectionPoints, postConstructMethodPoints);
|
293
|
+
}
|
294
|
+
|
295
|
+
return injectionPoints;
|
296
|
+
}
|
297
|
+
|
298
|
+
private function getConfigurationForRequest(
|
299
|
+
clazz : Class, named : String, traverseAncestors : Boolean = true) : InjectionConfig
|
300
|
+
{
|
301
|
+
var requestName : String = getQualifiedClassName(clazz);
|
302
|
+
var config:InjectionConfig = m_mappings[requestName + '#' + named];
|
303
|
+
if(!config && traverseAncestors &&
|
304
|
+
m_parentInjector && m_parentInjector.hasMapping(clazz, named))
|
305
|
+
{
|
306
|
+
config = getAncestorMapping(clazz, named);
|
307
|
+
}
|
308
|
+
return config;
|
309
|
+
}
|
310
|
+
|
311
|
+
private function createInjectionPointsFromConfigXML(description : XML) : void
|
312
|
+
{
|
313
|
+
var node : XML;
|
314
|
+
//first, clear out all "Inject" metadata, we want a clean slate to have the result
|
315
|
+
//work the same in the Flash IDE and MXMLC
|
316
|
+
for each (node in description..metadata.(@name=='Inject' || @name=='PostConstruct'))
|
317
|
+
{
|
318
|
+
delete node.parent().metadata.(@name=='Inject' || @name=='PostConstruct')[0];
|
319
|
+
}
|
320
|
+
|
321
|
+
//now, we create the new injection points based on the given xml file
|
322
|
+
var className:String = description.factory.@type;
|
323
|
+
for each (node in m_xmlMetadata.type.(@name == className).children())
|
324
|
+
{
|
325
|
+
var metaNode : XML = <metadata/>;
|
326
|
+
if (node.name() == 'postconstruct')
|
327
|
+
{
|
328
|
+
metaNode.@name = 'PostConstruct';
|
329
|
+
if (node.@order.length())
|
330
|
+
{
|
331
|
+
metaNode.appendChild(<arg key='order' value={node.@order}/>);
|
332
|
+
}
|
333
|
+
}
|
334
|
+
else
|
335
|
+
{
|
336
|
+
metaNode.@name = 'Inject';
|
337
|
+
if (node.@injectionname.length())
|
338
|
+
{
|
339
|
+
metaNode.appendChild(<arg key='name' value={node.@injectionname}/>);
|
340
|
+
}
|
341
|
+
for each (var arg : XML in node.arg)
|
342
|
+
{
|
343
|
+
metaNode.appendChild(<arg key='name' value={arg.@injectionname}/>);
|
344
|
+
}
|
345
|
+
}
|
346
|
+
var typeNode : XML;
|
347
|
+
if (node.name() == 'constructor')
|
348
|
+
{
|
349
|
+
typeNode = description.factory[0];
|
350
|
+
}
|
351
|
+
else
|
352
|
+
{
|
353
|
+
typeNode = description.factory.*.(attribute('name') == node.@name)[0];
|
354
|
+
if (!typeNode)
|
355
|
+
{
|
356
|
+
throw new InjectorError('Error in XML configuration: Class "' + className +
|
357
|
+
'" doesn\'t contain the instance member "' + node.@name + '"');
|
358
|
+
}
|
359
|
+
}
|
360
|
+
typeNode.appendChild(metaNode);
|
361
|
+
}
|
362
|
+
}
|
363
|
+
|
364
|
+
private function addParentInjectionPoints(description : XML, injectionPoints : Array) : void
|
365
|
+
{
|
366
|
+
var parentClassName : String = description.factory.extendsClass.@type[0];
|
367
|
+
if (!parentClassName)
|
368
|
+
{
|
369
|
+
return;
|
370
|
+
}
|
371
|
+
var parentInjectionPoints : Array = m_injectionPointLists[parentClassName] ||
|
372
|
+
getInjectionPoints(Class(getDefinitionByName(parentClassName)));
|
373
|
+
injectionPoints.push.apply(injectionPoints, parentInjectionPoints);
|
374
|
+
}
|
375
|
+
}
|
376
|
+
}
|