mate-objectbuilder

OK!

I had time to play some with Mate and my example, and I finally got a scheme
that may just work without using a 'global' Singleton instance reference. Yes
I can be slow, but ...

So here is what I have:

1) Main MXML loading a MainUIViews MXML with a simple mx:List.
2) Main also has a MainEventMap MXML.
3) MainDataManager MXML to store system state data.
4) The normal other stuff like events, utilities, vos, etc...

So the MainEventMap first instantiates my MainDataModel into Mate's cache. This 
eliminates my need for the Singleton.getInatance() method, ...hopefully. Once 
instantiated, the XML data is ordered, HTTPServiceInvoker - here just an XML file.

//-------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<EventMap xmlns:mx="http://www.adobe.com/2006/mxml"
	xmlns="http://mate.asfusion.com/" >
	
	<mx:Script>
		<![CDATA[
			import views.*;
			import models.*;
			
			import mx.events.FlexEvent;
			import mx.collections.XMLListCollection;
			import mx.controls.Alert;
			
			// Event map local utility functions.
			private function XMLResultsConverter( xml:XML ):XMLListCollection
			{ return( new XMLListCollection(  xml..image ) ); }

			private function XMLServiceFault( fault:String ):Alert
			{ return Alert.show("Error: ...bad HTTP call. /n"+fault); }
		]]>
	</mx:Script>
	
	<Debugger level="{Debugger.ALL}" />

	<!-- FlexEvent.PREINITIALIZE -->
	<EventHandlers type="{FlexEvent.PREINITIALIZE}" debug="false" >
		<ObjectBuilder generator="{MainDataManager}" >
			<Properties globalDispatcher="{scope.dispatcher}" />
		</ObjectBuilder>
	</EventHandlers>

	<!-- FlexEvent.CREATION_COMPLETE -->
	<EventHandlers type="{FlexEvent.CREATION_COMPLETE}" debug="false" >
		<HTTPServiceInvoker id="get_XML_db" url="./image_db.xml"
				useProxy="false" resultFormat="e4x" debug="false" >
			<resultHandlers>
				<InlineInvoker method="XMLResultsConverter" arguments="{[resultObject]}" />
				<ObjectBuilder generator="{MainDataManager}" >
					<Properties XMLDataLC="{lastReturn}" />
				</ObjectBuilder>
			</resultHandlers>

			<faultHandlers>
				<InlineInvoker method="XMLServiceFault" arguments="{[fault]}" />
				<ObjectBuilder generator="{MainDataManager}" >
					<Properties alert="{lastReturn}" />
				</ObjectBuilder>
			</faultHandlers>
		</HTTPServiceInvoker>
	</EventHandlers>
		
	<!-- BINDINGS: XML Data Injector -->
	<Injectors target="{MainUIViews}" >
		<PropertyInjector targetKey="XMLDataLC" source="{MainDataManager}" sourceKey="XMLDataLC" />
	</Injectors>

</EventMap>
//-------------------------------------------

In the resultHandlers, I first use an InlineInvoker that simply converts the 
resultObject, XML, to an XMLListCollection that is passed along as the 
SmartObject, lastReturn. 

The next step is an ObjectBuilder using the cached MainDataModel to store this 
XMLListCollection. In the MainDataModel I used getters/setters and bind them:

[Bindable] public dynamic class MainDataManager implements IEventDispatcher
{
	//-------------------------------------------
	// Main UI views model data storage elements...
	private var _XMLDataLC:XMLListCollection;
	public function get XMLDataLC( ):XMLListCollection
	{ return _XMLDataLC as XMLListCollection; }
	public function set XMLDataLC( value:XMLListCollection ):void
	{ _XMLDataLC = value as XMLListCollection; }
	//-------------------------------------------

Now in the MainUIViews, I have added a bindable local variable, XMLDataLC, which 
is used as the data provider for my MX:List:

	<mx:Script>
		<![CDATA[
			import mx.collections.XMLListCollection;

			[Bindable] public var XMLDataLC:XMLListCollection = new XMLListCollection();
		]]>
	</mx:Script>
	
	<!-- Simple list of images -->
	<mx:List id="mainDataList" width="300" height="400"
		dataProvider="{XMLDataLC}" labelField="file" />
		
Finally, the injectors in the MainEventMap push the image file data into the list:

	<!-- BINDINGS: XML Data Injector -->
	<Injectors target="{MainUIViews}" >
		<PropertyInjector targetKey="XMLDataLC" source="{MainDataManager}" sourceKey="XMLDataLC" />
	</Injectors>


Well, so far, it all works thanks to the help that all have provided. TY

I hope that this is as it was meant.
Comments welcomed.


Greg


http://www.gypsytrader.com/mate/post01.txt
http://www.gypsytrader.com/mate/image_db.xml
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值