1 | package clarin.cmdi.componentregistry.editor.model { |
---|
2 | import clarin.cmdi.componentregistry.common.ChangeTrackingCMDElement; |
---|
3 | import clarin.cmdi.componentregistry.common.ComponentMD; |
---|
4 | import clarin.cmdi.componentregistry.common.XmlAble; |
---|
5 | import clarin.cmdi.componentregistry.editor.ValueSchemeItem; |
---|
6 | import clarin.cmdi.componentregistry.editor.ValueSchemePopUp; |
---|
7 | |
---|
8 | import mx.collections.ArrayCollection; |
---|
9 | |
---|
10 | public class CMDAttribute implements XmlAble, ValueSchemeInterface, ChangeTrackingCMDElement { |
---|
11 | //No Attributes |
---|
12 | |
---|
13 | //Elements |
---|
14 | public var name:String; |
---|
15 | private var type:String; |
---|
16 | public var conceptLink:String; |
---|
17 | private var _valueSchemePattern:String; //pattern |
---|
18 | private var _valueSchemeEnumeration:ArrayCollection; // enumeration |
---|
19 | |
---|
20 | private var changed:Boolean = false; |
---|
21 | private var _changeTracking:Boolean = false; |
---|
22 | |
---|
23 | public function CMDAttribute() { |
---|
24 | } |
---|
25 | |
---|
26 | public static function createEmptyAttribute():CMDAttribute { |
---|
27 | var result:CMDAttribute = new CMDAttribute(); |
---|
28 | result.valueSchemeSimple = ValueSchemePopUp.DEFAULT_VALUE; |
---|
29 | return result; |
---|
30 | } |
---|
31 | |
---|
32 | public function set changeTracking(value:Boolean):void{ |
---|
33 | _changeTracking = value; |
---|
34 | } |
---|
35 | |
---|
36 | public function setChanged(value:Boolean):void { |
---|
37 | if(_changeTracking) { |
---|
38 | this.changed = value; |
---|
39 | } |
---|
40 | } |
---|
41 | |
---|
42 | public function get hasChanged():Boolean{ |
---|
43 | return changed; |
---|
44 | } |
---|
45 | |
---|
46 | public function get valueSchemeSimple():String { |
---|
47 | return this.type |
---|
48 | } |
---|
49 | |
---|
50 | public function set valueSchemeSimple(valueSchemeSimple:String):void { |
---|
51 | this.type = valueSchemeSimple; |
---|
52 | setChanged(true); |
---|
53 | } |
---|
54 | |
---|
55 | public function get valueSchemeEnumeration():ArrayCollection { |
---|
56 | return this._valueSchemeEnumeration |
---|
57 | } |
---|
58 | |
---|
59 | public function set valueSchemeEnumeration(valueSchemeEnumeration:ArrayCollection):void { |
---|
60 | this._valueSchemeEnumeration = valueSchemeEnumeration; |
---|
61 | setChanged(true); |
---|
62 | } |
---|
63 | |
---|
64 | public function get valueSchemePattern():String { |
---|
65 | return this._valueSchemePattern; |
---|
66 | } |
---|
67 | |
---|
68 | public function set valueSchemePattern(valueSchemePattern:String):void { |
---|
69 | this._valueSchemePattern = valueSchemePattern; |
---|
70 | setChanged(true); |
---|
71 | } |
---|
72 | |
---|
73 | public function toXml():XML { |
---|
74 | var result:XML = <Attribute></Attribute>; |
---|
75 | result.appendChild(<Name>{name}</Name>); |
---|
76 | if (conceptLink) { |
---|
77 | result.appendChild(<ConceptLink>{conceptLink}</ConceptLink>); |
---|
78 | } |
---|
79 | if (valueSchemePattern) { |
---|
80 | result.appendChild(<ValueScheme><pattern>{valueSchemePattern}</pattern></ValueScheme>); |
---|
81 | } else if (valueSchemeEnumeration) { |
---|
82 | var enumerationScheme:XML = <enumeration></enumeration>; |
---|
83 | for each (var item:ValueSchemeItem in valueSchemeEnumeration) { |
---|
84 | enumerationScheme.appendChild(<item {ComponentMD.APP_INFO}={item.appInfo} {ComponentMD.CONCEPTLINK}={item.conceptLink}>{item.item}</item>); |
---|
85 | } |
---|
86 | result.appendChild(<ValueScheme>{enumerationScheme}</ValueScheme>); |
---|
87 | } else { |
---|
88 | result.appendChild(<Type>{type}</Type>); |
---|
89 | } |
---|
90 | |
---|
91 | return result |
---|
92 | } |
---|
93 | } |
---|
94 | } |
---|