Created
March 14, 2010 18:19
-
-
Save bclinkinbeard/332127 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package processors | |
{ | |
import flight.binding.Bind; | |
import flight.binding.Binding; | |
import org.swizframework.core.Bean; | |
import org.swizframework.processors.BaseMetadataProcessor; | |
import org.swizframework.reflection.IMetadataTag; | |
import org.swizframework.reflection.MetadataArg; | |
public class FlightBindingProcessor extends BaseMetadataProcessor | |
{ | |
public static const BIND:String = "Bind"; | |
public function FlightBindingProcessor() | |
{ | |
super([BIND]); | |
} | |
protected var bindings:Dictionary = new Dictionary(); | |
override public function setUpMetadataTag(metadataTag:IMetadataTag, bean:Bean):void | |
{ | |
/* | |
Flight binding requires a reference to a target and a source | |
as well as the properties which should be bound together | |
For the target reference, the bean returns a reference to the target's parent, | |
so we use the parent as the target reference then we combine metadata.host and targetProperty | |
to create the targetPath | |
The source reference and property come from a string, such as | |
"model.data", so we just split the string and fetch the source reference | |
from the beanFactory by name | |
*/ | |
//target logic | |
var targetParent:* = bean.source; | |
var target:String = metadataTag.host.name; | |
var targetPropertyArg:MetadataArg = metadataTag.getArg("targetProperty"); | |
var targetPropertyBeanName:String = targetPropertyArg.value; | |
var targetPath:String = target + "." + targetPropertyBeanName; | |
//source logic | |
var sourceArg:MetadataArg = metadataTag.getArg("source"); | |
var sourceBeanName:String = sourceArg.value; | |
var sourceInstanceName:String = sourceBeanName.split(".")[0]; | |
var source:* = beanFactory.getBeanByName(sourceInstanceName).source; | |
var sourcePropertyName:String = sourceBeanName.split(".")[1]; | |
//Flight binding | |
var binding:Binding = Bind.addBinding(targetParent, targetPath, source, sourcePropertyName); | |
// make sure an array exists for this bean's bindings | |
bindings[ bean ] ||= []; | |
Array( bindings[ bean ] ).push( binding ); | |
} | |
override public function tearDownMetadataTag(metadataTag:IMetadataTag, bean:Bean):void | |
{ | |
// make sure an array exists for this bean's bindings | |
var beanBindings:Array = bindings[ bean ]; | |
for each( var b:Binding in beanBindings ) | |
{ | |
if( b.target == metadataTag.host.name ) | |
{ | |
b.release(); | |
b = null; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment