1 | package clarin.cmdi.componentregistry.services { |
---|
2 | import clarin.cmdi.componentregistry.browser.BrowserColumns; |
---|
3 | import clarin.cmdi.componentregistry.common.ItemDescription; |
---|
4 | |
---|
5 | import mx.collections.ArrayCollection; |
---|
6 | import mx.rpc.events.ResultEvent; |
---|
7 | import flash.events.Event; |
---|
8 | |
---|
9 | [Event(name="componentsLoaded", type="flash.events.Event")] |
---|
10 | public class ComponentListService extends BrowserService { |
---|
11 | |
---|
12 | public static const COMPONENTS_LOADED:String = "componentsLoaded"; |
---|
13 | |
---|
14 | private static var _instance:ComponentListService = new ComponentListService(); |
---|
15 | private static var _userSpaceInstance:ComponentListService = new ComponentListService(true); |
---|
16 | |
---|
17 | public function ComponentListService(userSpace:Boolean = false) { |
---|
18 | super(Config.instance.componentListUrl, userSpace); |
---|
19 | } |
---|
20 | |
---|
21 | override protected function result(resultEvent:ResultEvent):void { |
---|
22 | var resultXml:XML = resultEvent.result as XML; |
---|
23 | var nodes:XMLList = resultXml.componentDescription; |
---|
24 | |
---|
25 | var tempArray:ArrayCollection = new ArrayCollection(); |
---|
26 | for each (var node:XML in nodes) { |
---|
27 | var item:ItemDescription = new ItemDescription(); |
---|
28 | item.createComponent(node, userSpace); |
---|
29 | tempArray.addItem(item); |
---|
30 | } |
---|
31 | tempArray.sort = BrowserColumns.getInitialSortForComponents(); |
---|
32 | tempArray.refresh(); |
---|
33 | setItemDescriptions(new ArrayCollection(tempArray.toArray())); |
---|
34 | trace(itemDescriptions.length + " components are loaded"); |
---|
35 | dispatchEvent(new Event(COMPONENTS_LOADED)); |
---|
36 | // super.result(resultEvent); |
---|
37 | } |
---|
38 | |
---|
39 | public static function getInstance(userSpace:Boolean):ComponentListService { |
---|
40 | if (userSpace) { |
---|
41 | return _userSpaceInstance; |
---|
42 | } else { |
---|
43 | return _instance; |
---|
44 | } |
---|
45 | } |
---|
46 | |
---|
47 | public static function findDescription(componentId:String):ItemDescription { |
---|
48 | var result:ItemDescription = getInstance(true).lookUpDescription(componentId); |
---|
49 | if (result == null) { |
---|
50 | result = getInstance(false).lookUpDescription(componentId); |
---|
51 | } |
---|
52 | return result |
---|
53 | } |
---|
54 | |
---|
55 | |
---|
56 | } |
---|
57 | } |
---|