Separate Halcyon (rendering) into standalone target without Flex dependency; JavaScri...
[potlatch2.git] / net / systemeD / halcyon / connection / Entity.as
1 package net.systemeD.halcyon.connection {
2
3     import flash.events.EventDispatcher;
4
5     public class Entity extends EventDispatcher {
6         private var _id:Number;
7         private var _version:uint;
8         private var tags:Object = {};
9
10         public function Entity(id:Number, version:uint, tags:Object) {
11             this._id = id;
12             this._version = version;
13             this.tags = tags;
14         }
15
16         public function get id():Number {
17             return _id;
18         }
19
20         public function get version():uint {
21             return _version;
22         }
23
24         public function hasTags():Boolean {
25             for (var key:String in tags)
26                 return true;
27             return false;
28         }
29
30         public function getTag(key:String):String {
31             return tags[key];
32         }
33
34         public function setTag(key:String, value:String):void {
35             var old:String = tags[key];
36             if ( old != value ) {
37                 if ( value == null || value == "" )
38                     delete tags[key];
39                 else
40                     tags[key] = value;
41                 dispatchEvent(new TagEvent(Connection.TAG_CHANGE, this, key, key, old, value));
42             }
43         }
44
45         public function renameTag(oldKey:String, newKey:String):void {
46             var value:String = tags[oldKey];
47             if ( oldKey != newKey ) {
48                 delete tags[oldKey];
49                 tags[newKey] = value;
50                 dispatchEvent(new TagEvent(Connection.TAG_CHANGE, this, oldKey, newKey, value, value));
51             }
52         }
53
54         public function getTagList():TagList {
55             return new TagList(tags);
56         }
57
58         public function getTagsCopy():Object {
59             var copy:Object = {};
60             for (var key:String in tags )
61                 copy[key] = tags[key];
62             return copy;
63         }
64
65         public function getTagArray():Array {
66             var copy:Array = [];
67             for (var key:String in tags )
68                 copy.push(new Tag(this, key, tags[key]));
69             return copy;
70         }
71
72                 public function getType():String {
73                         return '';
74                 }
75
76     }
77
78 }