Handling of calls to IAutowireProcessor.autoWire()

1 view
Skip to first unread message

Andrew Lewisohn

unread,
Mar 23, 2010, 6:55:21 PM3/23/10
to springactionscript-dev
In the 1.1 branch, the second argument to the autoWire() has been made
optional so that classes that do not have an IObjectDefinition can be
autowired based solely on metadata. However, the internals of the
DefaultAutowireProcessor make use of
getUnclaimedSimpleObjectProperties() method, which takes as its second
argument an instance of IObjectDefinition. Passing null as the second
argument prevents any fields or properties from being returned and
therefore, being autowired regardless of whether or not the Autowired
metadata exists. Are the conditions referencing the IObjectDefinition
instance just a holdover from when the argument was required, or do
they serve a purpose that I just can't figure out? I'm new to the
project so please forgive me if the reasons are obvious to everybody
else.

Roland Zwaga

unread,
Mar 24, 2010, 4:11:55 AM3/24/10
to springactio...@googlegroups.com
Hey Andrew,

when metadata and object definitions are both used for a class, the
object definition takes precedence. That way a developer can override
the behavior defined in the [Autowired] metadata by defining a
property in the object definition.
so this code:
var unclaimedProperties:Array =
getUnclaimedSimpleObjectProperties(object, objectDefinition);
for each (var field:Field in unclaimedProperties) {
if (field.hasMetaData(AUTOWIRED_ANNOTATION)) {
}
}

Will first check if any properties have been defined in the object
definition, filters these out of the list and then returns the list of
all the remaining fields. Then in the next loop each field is
examinied for the existence of the [Autowired] metadata
((field.hasMetaData(AUTOWIRED_ANNOTATION)) and will be processed
accordingly.

Hope that makes sense :)

cheers,

Roland

> --
> You received this message because you are subscribed to the Google
> Groups "springactionscript-dev" group.
> To post to this group, send email to springactio...@googlegroups.com.
> To unsubscribe from this group, send email to
> springactionscrip...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/springactionscript-dev?hl=en.
>
>

Roland Zwaga

unread,
Mar 24, 2010, 4:13:24 AM3/24/10
to springactio...@googlegroups.com
Oh,

and feel free to question every line of code you stumble upon, I'm
happy to bring you up to speed and an extra code review never hurt
anyone, should you unearth any bugs this way, it'll be an added bonus
for us :) Less bugs, yea! hehe

Roland

Andrew Lewisohn

unread,
Mar 24, 2010, 10:12:44 AM3/24/10
to springactionscript-dev
OK. But when only an instance of a class is passed, and no object
definition is passed, the getUnclaimedSimpleObjectProperties method
will only ever return an empty array. The if conditions will always
evaluate to false because objectDefinition is null, so the array of
fields returned will always be empty.

for (i = 0; i < numVariables; i++) {
variable = type.variables[i];

if (!variable.isStatic && ((objectDefinition != null) &&
(objectDefinition.properties[variable.name] === undefined))) {
result.push(variable);
}
}

var accessor:Accessor;

for (i = 0; i < type.accessors.length; i++) {
accessor = type.accessors[i];

if ((accessor.access == AccessorAccess.WRITE_ONLY || accessor.access
== AccessorAccess.READ_WRITE) && !accessor.isStatic &&
((objectDefinition != null) &&
(objectDefinition.properties[accessor.name] === undefined))) {
result.push(accessor);
}
}

I assume the purpose of the object definition conditions in those two
if statements is to filter out properties that exist in the object
definition, but only if the object definition exists. However, since
the object definition is null in this case, the code inside the if
block is never processed.

Roland

unread,
Mar 24, 2010, 12:44:45 PM3/24/10
to springactionscript-dev
hahaha, yep, I see what you mean now and I've spotted the bug.
Your assumption is indeed correct! Wonderful, you've just joined the
project
and already caught a bug, thanx :)

cheers,

Roland

Christophe Herreman

unread,
Apr 2, 2010, 7:18:47 AM4/2/10
to springactionscript-dev
Hi guys,

I committed this fix also on the trunk since it was only fixed on the
branch.

Please make sure to run the tests on the trunk and only commit your
changes if all tests have passed.

regards,
Christophe

Reply all
Reply to author
Forward
0 new messages