1 | package clarin.cmdi.componentregistry.services { |
---|
2 | import clarin.cmdi.componentregistry.common.ItemDescription; |
---|
3 | |
---|
4 | import mx.collections.ArrayCollection; |
---|
5 | import mx.rpc.events.ResultEvent; |
---|
6 | |
---|
7 | public class ComponentListService extends BrowserService { |
---|
8 | |
---|
9 | |
---|
10 | private static var _instance:ComponentListService = new ComponentListService(); |
---|
11 | |
---|
12 | public function ComponentListService() { |
---|
13 | super(Config.instance.componentListUrl); |
---|
14 | if (_instance != null) { |
---|
15 | throw new Error("Service can only be accessed through ComponentListService.instance"); |
---|
16 | } |
---|
17 | } |
---|
18 | |
---|
19 | override protected function result(resultEvent:ResultEvent):void { |
---|
20 | var resultXml:XML = resultEvent.result as XML; |
---|
21 | var nodes:XMLList = resultXml.componentDescription; |
---|
22 | |
---|
23 | var tempArray:Array = new Array(); |
---|
24 | for each (var node:XML in nodes) { |
---|
25 | var item:ItemDescription = new ItemDescription(); |
---|
26 | item.createComponent(node); |
---|
27 | tempArray[tempArray.length] = item; |
---|
28 | } |
---|
29 | setItemDescriptions(new ArrayCollection(tempArray)); |
---|
30 | } |
---|
31 | |
---|
32 | public static function get instance():ComponentListService { |
---|
33 | return _instance; |
---|
34 | } |
---|
35 | |
---|
36 | /** |
---|
37 | * Looks up itemDescription, returns null if not found. |
---|
38 | */ |
---|
39 | public function lookUpDescription(componentId:String):ItemDescription { |
---|
40 | for each (var item:ItemDescription in unFilteredItemDescriptions) { |
---|
41 | if (item.id == componentId) { |
---|
42 | return item; |
---|
43 | } |
---|
44 | } |
---|
45 | return null; |
---|
46 | } |
---|
47 | } |
---|
48 | } |
---|