Commits

Aleksey Fomkin  committed d12bf1a

big refactoring

  • Participants
  • Parent commits 80d509e
  • Branches dev

Comments (0)

Files changed (43)

File cgml-as3-support/pom.xml

         </dependency>
     </dependencies>
 
+    <distributionManagement>
+        <repository>
+            <!-- I know, I know! -->
+            <id>yelbota-dropbox-repository</id>
+            <url>file:///Users/yelbota/Dropbox/Public/maven</url>
+        </repository>
+    </distributionManagement>
+
     <pluginRepositories>
         <pluginRepository>
             <id>sonatype</id>

File cgml-as3-support/src/main/flex/com/yarrcad/cgml/CollectionChangeBroadcaster.as

-package com.yarrcad.cgml {
-import flash.events.IEventDispatcher;
-
-import mx.collections.ArrayCollection;
-import mx.events.CollectionEvent;
-import mx.events.PropertyChangeEvent;
-
-public class CollectionChangeBroadcaster {
-
-  private var target:IEventDispatcher;
-  private var collection:ArrayCollection;
-  private var name:String;
-
-  public function CollectionChangeBroadcaster(name:String,  target:IEventDispatcher, collection:ArrayCollection) {
-
-    this.target = target;
-    this.collection = collection;
-    this.name = name;
-
-    if (collection != null)
-      collection.addEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler);
-
-    target.addEventListener(PropertyChangeEvent.PROPERTY_CHANGE, propertyChangeHanlder);
-  }
-
-  private function propertyChangeHanlder(event:PropertyChangeEvent):void {
-    if (event.source != this && event.property == name) {
-      // Remove old handler
-      if (collection != null)
-        collection.removeEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler);
-      // Resolve a property and add new handler
-      collection = target[name];
-      collection.addEventListener(CollectionEvent.COLLECTION_CHANGE, collectionChangeHandler);
-    }
-  }
-
-  private function collectionChangeHandler(event:CollectionEvent):void {
-    target.dispatchEvent(PropertyChangeEvent.createUpdateEvent(this, name, null, collection));
-  }
-
-}
-
-}

File cgml-as3-support/src/main/flex/com/yarrcad/cgml/ObjectStorage.as

-/*
- * This file is part of the CGML Compiler
- *
- * Copyright(c) 2010 Aleksey Fomkin <aleksey.fomkin@gmail.com>
- * http://bitbucket.org/yelbota/cgml-compiler
- *
- * This file may be licensed under the terms of of the
- * GNU General Public License Version 3 (the ``GPL'').
- *
- * Software distributed under the License is distributed
- * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
- * express or implied. See the GPL for the specific language
- * governing rights and limitations.
- *
- * You should have received a copy of the GPL along with this
- * program. If not, go to http://www.gnu.org/licenses/gpl.html
- * or write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-package com.yarrcad.cgml {
-
-import flash.utils.Dictionary;
-
-public class ObjectStorage {
-
-  public function ObjectStorage(parent:ObjectStorage=null) {
-    this.parent = parent;
-  }
-
-  /**
-   * Parent object table, parent object can't be
-   * modified from here.
-   */
-  private var parent:ObjectStorage;
-
-  /**
-   * Object storage
-   */
-  private var map:Array = new Array();
-
-  /**
-   * Index of object storage. It needs for fast search ids by
-   * object values
-   */
-  private var indexMap:Dictionary = new Dictionary(true);
-
-  /**
-   * Initializtion map. Objects can exeists in storage, but in might
-   * be to initialized. When object pass initialization in puts in
-   * this map.
-   */
-  private var initMap:Dictionary = new Dictionary(true);
-
-  /**
-   * @return Id for a new object.
-   */
-  public function generateId():int {
-
-    var newId:int = Math.random() * 0xFFFFFFF;
-    while (getObjectExists2(newId))
-      newId = generateId();
-
-    return newId;
-  }
-
-  /**
-   * Register new object in reference table.
-   *
-   * @param object new object.
-   * @return id of new object.
-   */
-  public function registerNewObject(object:Object):int {
-    var id:int = generateId();
-    registerObject(id, object);
-    return id;
-  }
-
-  /**
-   * Register any object in the reference table.
-   *
-   * @param id     object id
-   * @param object object
-   */
-  public function registerObject(id:int, object:Object):void {
-    map[id] = object;
-    indexMap[object] = id;
-  }
-
-  /**
-   * @param object any object
-   * @return Id of object if it's allready registred else -1.
-   */
-  public function getObjectId(object:Object):int {
-    if (parent != null) {
-      var id_i:int = parent.getObjectId(object);
-      if (id_i > -1)
-        return id_i;
-    }
-
-    var id:Object = indexMap[object];
-    return (id == null) ? -1 : int(id);
-  }
-
-  public function getObject(id:int):Object {
-    var result:Object;
-    if (parent != null)
-      result = parent.getObject(id);
-    if (result == null)
-      result = map[id];
-    return result;
-  }
-
-  public function getObjectExists(object:Object):Boolean {
-    if (parent != null)
-      return parent.getObjectExists(object) || (indexMap[object] != null);
-    else return (indexMap[object] != null);
-  }
-
-  public function getObjectExists2(id:int):Boolean {
-    if (parent != null)
-      return parent.getObjectExists2(id) || (map[id] != null);
-    else return (map[id] != null);
-  }
-
-  /**
-   * Check object marked as initialized.
-   *
-   * @param object object
-   * @return inializtion status.
-   */
-  public function getObjectInitialized(object:Object):Boolean {
-    if (parent != null)
-      return parent.getObjectInitialized(object) || initMap[object];
-    else return initMap[object];
-  }
-
-  public function setObjectInitialized(object:Object):void {
-    if (parent != null && parent.getObjectExists(object))
-      parent.setObjectInitialized(object);
-    else initMap[object] = true;
-  }
-}
-
-}

File cgml-as3-support/src/main/flex/com/yarrcad/cgml/net/Connection.as

-package com.yarrcad.cgml.net {
-
-import com.yarrcad.cgml.net.events.ConnectionEvent;
-
-import flash.events.Event;
-import flash.events.EventDispatcher;
-import flash.events.IOErrorEvent;
-import flash.events.ProgressEvent;
-import flash.events.SecurityErrorEvent;
-import flash.net.Socket;
-import flash.utils.ByteArray;
-
-[Event(type="com.yarrcad.cgml.net.events.ConnectionEvent", name="packet")]
-[Event(name="securityError", type="flash.events.SecurityErrorEvent")]
-[Event(name="ioError", type="flash.events.IOErrorEvent")]
-[Event(name="connect", type="flash.events.Event")]
-[Event(name="close", type="flash.events.Event")]
-
-public class Connection extends EventDispatcher {
-
-    private var socket:Socket;
-    private var packetStack:PacketStack;
-
-    public function Connection() {
-        socket = new Socket();
-        socket.addEventListener(ProgressEvent.SOCKET_DATA, socket_socketDataHandler)
-        socket.addEventListener(Event.CONNECT, forwardEvent);
-        socket.addEventListener(IOErrorEvent.IO_ERROR, forwardEvent);
-        socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, forwardEvent);
-        socket.addEventListener(Event.CLOSE, forwardEvent);
-
-        packetStack = new PacketStack();
-    }
-
-    public function connect(host:String, port:int):void {
-        socket.connect(host, port);
-    }
-
-    public function get connected():Boolean {
-        return socket.connected;
-    }
-
-    public function sendBytes(body:ByteArray):void {
-        body.position = 0;
-        socket.writeUnsignedInt(body.length);
-        socket.writeBytes(body);
-        socket.flush();
-    }
-
-    public function close():void {
-        if (socket.connected)
-            socket.close();
-        dispatchEvent(new Event(Event.CLOSE));
-    }
-
-    private function forwardEvent(event:Event):void {
-        dispatchEvent(event.clone());
-    }
-
-    private function socket_socketDataHandler(event:ProgressEvent):void {
-        packetStack.processInput(socket);
-        while (packetStack.size > 0) {
-            dispatchEvent(new ConnectionEvent(ConnectionEvent.PACKET, packetStack.take()));
-        }
-    }
-}
-
-}

File cgml-as3-support/src/main/flex/com/yarrcad/cgml/net/PacketStack.as

-package com.yarrcad.cgml.net {
-
-import com.yarrcad.cgml.net.errors.PacketStackError;
-
-import flash.events.Event;
-import flash.events.EventDispatcher;
-import flash.utils.ByteArray;
-import flash.utils.IDataInput;
-
-public class PacketStack extends EventDispatcher {
-
-    private var packets:Vector.<ByteArray>;
-    private var knownPacketLength:int = -1;
-    private var buffer:ByteArray;
-
-    public function PacketStack() {
-        packets = new Vector.<ByteArray>();
-        buffer = new ByteArray();
-    }
-
-    public function processInput(input:IDataInput):void {
-        if (knownPacketLength > -1) {
-
-            // We already know packet length. So lets read out.
-            const assumeLength:int = knownPacketLength - buffer.length;
-            const toRead:int = assumeLength > input.bytesAvailable
-                    ? input.bytesAvailable
-                    : assumeLength;
-
-            if (toRead > 0)
-                input.readBytes(buffer, buffer.length, toRead);
-
-            // Check packet length
-            if (buffer.length >= knownPacketLength) {
-                // Yeha! Packet complete.
-                // Call user handler and reset the buffer.
-                buffer.position = 0;
-                packets.push(buffer);
-                buffer = new ByteArray();
-                knownPacketLength = -1;
-                processInput(input);
-            }
-        } else if (input.bytesAvailable >= 4) {
-            // Can read length of packet
-            knownPacketLength = input.readUnsignedInt();
-            processInput(input);
-        }
-    }
-
-    [Bindable("sizeChange")]
-
-    public function get size():uint {
-        return packets.length;
-    }
-
-    public function take():ByteArray {
-        if (packets.length > 0) {
-            var result:ByteArray = packets.shift();
-            dispatchEvent(new Event("sizeChange"));
-            return result;
-        }
-        else throw new PacketStackError(PacketStackError.NO_PACKETS_AVALIABLE);
-    }
-}
-
-}

File cgml-as3-support/src/main/flex/com/yarrcad/cgml/net/errors/PacketStackError.as

-package com.yarrcad.cgml.net.errors {
-
-public class PacketStackError extends Error {
-
-    public static const NO_PACKETS_AVALIABLE:String = "No packets avaliable";
-
-    public function PacketStackError(message:String) {
-        super(message);
-    }
-}
-
-}

File cgml-as3-support/src/main/flex/com/yarrcad/cgml/net/events/ConnectionEvent.as

-package com.yarrcad.cgml.net.events {
-
-import flash.events.Event;
-import flash.utils.ByteArray;
-
-public class ConnectionEvent extends Event {
-
-    public static const PACKET:String = "packet";
-
-    public var bytes:ByteArray;
-
-    public function ConnectionEvent(type:String, bytes:ByteArray, bubbles:Boolean = false, cancelable:Boolean = false) {
-        super(type, bubbles, cancelable);
-        this.bytes = bytes;
-    }
-}
-
-}

File cgml-as3-support/src/main/flex/com/yarrcad/cgml/option/OptionBool.as

-/*
- * This file is part of the CGML Compiler
- *
- * Copyright(c) 2010 Aleksey Fomkin <aleksey.fomkin@gmail.com>
- * http://bitbucket.org/yelbota/cgml-compiler
- *
- * This file may be licensed under the terms of of the
- * GNU General Public License Version 3 (the ``GPL'').
- *
- * Software distributed under the License is distributed
- * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
- * express or implied. See the GPL for the specific language
- * governing rights and limitations.
- *
- * You should have received a copy of the GPL along with this
- * program. If not, go to http://www.gnu.org/licenses/gpl.html
- * or write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-package com.yarrcad.cgml.option {
-
-public class OptionBool {
-  public var value:Boolean;
-
-  public function OptionBool(value:Boolean) {
-    this.value = value;
-  }
-}
-
-}

File cgml-as3-support/src/main/flex/com/yarrcad/cgml/option/OptionFloat.as

-/*
- * This file is part of the CGML Compiler
- *
- * Copyright(c) 2010 Aleksey Fomkin <aleksey.fomkin@gmail.com>
- * http://bitbucket.org/yelbota/cgml-compiler
- *
- * This file may be licensed under the terms of of the
- * GNU General Public License Version 3 (the ``GPL'').
- *
- * Software distributed under the License is distributed
- * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
- * express or implied. See the GPL for the specific language
- * governing rights and limitations.
- *
- * You should have received a copy of the GPL along with this
- * program. If not, go to http://www.gnu.org/licenses/gpl.html
- * or write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-package com.yarrcad.cgml.option {
-
-public class OptionFloat {
-  public var value:Number;
-
-  public function OptionFloat(value:Number) {
-    this.value = value;
-  }
-}
-
-}

File cgml-as3-support/src/main/flex/com/yarrcad/cgml/option/OptionInt.as

-/*
- * This file is part of the CGML Compiler
- *
- * Copyright(c) 2010 Aleksey Fomkin <aleksey.fomkin@gmail.com>
- * http://bitbucket.org/yelbota/cgml-compiler
- *
- * This file may be licensed under the terms of of the
- * GNU General Public License Version 3 (the ``GPL'').
- *
- * Software distributed under the License is distributed
- * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
- * express or implied. See the GPL for the specific language
- * governing rights and limitations.
- *
- * You should have received a copy of the GPL along with this
- * program. If not, go to http://www.gnu.org/licenses/gpl.html
- * or write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-package com.yarrcad.cgml.option {
-
-public class OptionInt {
-  public var value:int;
-
-  public function OptionInt(value:int) {
-    this.value = value;
-  }
-}
-
-}

File cgml-as3-support/src/main/flex/com/yelbota/cgml/ObjectStorage.as

+/*
+ * This file is part of the CGML Compiler
+ *
+ * Copyright(c) 2010 Aleksey Fomkin <aleksey.fomkin@gmail.com>
+ * http://bitbucket.org/yelbota/cgml-compiler
+ *
+ * This file may be licensed under the terms of of the
+ * GNU General Public License Version 3 (the ``GPL'').
+ *
+ * Software distributed under the License is distributed
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the GPL for the specific language
+ * governing rights and limitations.
+ *
+ * You should have received a copy of the GPL along with this
+ * program. If not, go to http://www.gnu.org/licenses/gpl.html
+ * or write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+package com.yelbota.cgml {
+
+import flash.utils.Dictionary;
+
+public class ObjectStorage {
+
+  public function ObjectStorage(parent:ObjectStorage=null) {
+    this.parent = parent;
+  }
+
+  /**
+   * Parent object table, parent object can't be
+   * modified from here.
+   */
+  private var parent:ObjectStorage;
+
+  /**
+   * Object storage
+   */
+  private var map:Array = new Array();
+
+  /**
+   * Index of object storage. It needs for fast search ids by
+   * object values
+   */
+  private var indexMap:Dictionary = new Dictionary(true);
+
+  /**
+   * Initializtion map. Objects can exeists in storage, but in might
+   * be to initialized. When object pass initialization in puts in
+   * this map.
+   */
+  private var initMap:Dictionary = new Dictionary(true);
+
+  /**
+   * @return Id for a new object.
+   */
+  public function generateId():int {
+
+    var newId:int = Math.random() * 0xFFFFFFF;
+    while (getObjectExists2(newId))
+      newId = generateId();
+
+    return newId;
+  }
+
+  /**
+   * Register new object in reference table.
+   *
+   * @param object new object.
+   * @return id of new object.
+   */
+  public function registerNewObject(object:Object):int {
+    var id:int = generateId();
+    registerObject(id, object);
+    return id;
+  }
+
+  /**
+   * Register any object in the reference table.
+   *
+   * @param id     object id
+   * @param object object
+   */
+  public function registerObject(id:int, object:Object):void {
+    map[id] = object;
+    indexMap[object] = id;
+  }
+
+  /**
+   * @param object any object
+   * @return Id of object if it's allready registred else -1.
+   */
+  public function getObjectId(object:Object):int {
+    if (parent != null) {
+      var id_i:int = parent.getObjectId(object);
+      if (id_i > -1)
+        return id_i;
+    }
+
+    var id:Object = indexMap[object];
+    return (id == null) ? -1 : int(id);
+  }
+
+  public function getObject(id:int):Object {
+    var result:Object;
+    if (parent != null)
+      result = parent.getObject(id);
+    if (result == null)
+      result = map[id];
+    return result;
+  }
+
+  public function getObjectExists(object:Object):Boolean {
+    if (parent != null)
+      return parent.getObjectExists(object) || (indexMap[object] != null);
+    else return (indexMap[object] != null);
+  }
+
+  public function getObjectExists2(id:int):Boolean {
+    if (parent != null)
+      return parent.getObjectExists2(id) || (map[id] != null);
+    else return (map[id] != null);
+  }
+
+  /**
+   * Check object marked as initialized.
+   *
+   * @param object object
+   * @return inializtion status.
+   */
+  public function getObjectInitialized(object:Object):Boolean {
+    if (parent != null)
+      return parent.getObjectInitialized(object) || initMap[object];
+    else return initMap[object];
+  }
+
+  public function setObjectInitialized(object:Object):void {
+    if (parent != null && parent.getObjectExists(object))
+      parent.setObjectInitialized(object);
+    else initMap[object] = true;
+  }
+}
+
+}

File cgml-as3-support/src/main/flex/com/yelbota/cgml/net/Connection.as

+package com.yelbota.cgml.net {
+
+import com.yelbota.cgml.net.events.ConnectionEvent;
+
+import flash.events.Event;
+import flash.events.EventDispatcher;
+import flash.events.IOErrorEvent;
+import flash.events.ProgressEvent;
+import flash.events.SecurityErrorEvent;
+import flash.net.Socket;
+import flash.utils.ByteArray;
+
+[Event(type="com.yelbota.cgml.net.events.ConnectionEvent", name="packet")]
+[Event(name="securityError", type="flash.events.SecurityErrorEvent")]
+[Event(name="ioError", type="flash.events.IOErrorEvent")]
+[Event(name="connect", type="flash.events.Event")]
+[Event(name="close", type="flash.events.Event")]
+
+public class Connection extends EventDispatcher {
+
+    private var socket:Socket;
+    private var packetStack:PacketQueue;
+
+    public function Connection() {
+        socket = new Socket();
+        socket.addEventListener(ProgressEvent.SOCKET_DATA, socket_socketDataHandler)
+        socket.addEventListener(Event.CONNECT, forwardEvent);
+        socket.addEventListener(IOErrorEvent.IO_ERROR, forwardEvent);
+        socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, forwardEvent);
+        socket.addEventListener(Event.CLOSE, forwardEvent);
+
+        packetStack = new PacketQueue();
+    }
+
+    public function connect(host:String, port:int):void {
+        socket.connect(host, port);
+    }
+
+    public function get connected():Boolean {
+        return socket.connected;
+    }
+
+    public function sendBytes(body:ByteArray):void {
+        body.position = 0;
+        socket.writeUnsignedInt(body.length);
+        socket.writeBytes(body);
+        socket.flush();
+    }
+
+    public function close():void {
+        if (socket.connected)
+            socket.close();
+        dispatchEvent(new Event(Event.CLOSE));
+    }
+
+    private function forwardEvent(event:Event):void {
+        dispatchEvent(event.clone());
+    }
+
+    private function socket_socketDataHandler(event:ProgressEvent):void {
+        packetStack.processInput(socket);
+        while (packetStack.size > 0) {
+            dispatchEvent(new ConnectionEvent(ConnectionEvent.PACKET, packetStack.take()));
+        }
+    }
+}
+
+}

File cgml-as3-support/src/main/flex/com/yelbota/cgml/net/PacketQueue.as

+package com.yelbota.cgml.net {
+
+import com.yelbota.cgml.net.errors.PacketStackError;
+
+import flash.events.Event;
+import flash.events.EventDispatcher;
+import flash.utils.ByteArray;
+import flash.utils.IDataInput;
+
+public class PacketQueue extends EventDispatcher {
+
+    private static const sizeChanged:Event = new Event("sizeChanged");
+
+    private var packets:Vector.<ByteArray>;
+    private var knownPacketLength:int = -1;
+    private var buffer:ByteArray;
+
+    public function PacketQueue() {
+        packets = new Vector.<ByteArray>();
+        buffer = new ByteArray();
+    }
+
+    /**
+     * @param input
+     * @return true if packet
+     */
+    public function processInput(input:IDataInput):void {
+        if (knownPacketLength > -1) {
+
+            // We already know packet length. So lets read out.
+            const assumeLength:int = knownPacketLength - buffer.length;
+            const toRead:int = assumeLength > input.bytesAvailable
+                    ? input.bytesAvailable
+                    : assumeLength;
+
+            if (toRead > 0)
+                input.readBytes(buffer, buffer.length, toRead);
+
+            // Check packet length
+            if (buffer.length >= knownPacketLength) {
+                // Yeha! Packet complete.
+                // Call user handler and reset the buffer.
+                buffer.position = 0;
+                packets.push(buffer);
+                if (hasEventListener(sizeChanged.type))
+                    dispatchEvent(sizeChanged);
+                buffer = new ByteArray();
+                knownPacketLength = -1;
+                processInput(input);
+            }
+        } else if (input.bytesAvailable >= 4) {
+            // Can read length of packet
+            knownPacketLength = input.readUnsignedInt();
+            processInput(input);
+        }
+    }
+
+    [Bindable("sizeChanged")]
+
+    public function get size():uint {
+        return packets.length;
+    }
+
+    public function take():ByteArray {
+        if (packets.length > 0) {
+            var result:ByteArray = packets.shift();
+            if (hasEventListener(sizeChanged.type))
+                dispatchEvent(sizeChanged);
+            return result;
+        }
+        else throw new PacketStackError(PacketStackError.NO_PACKETS_AVALIABLE);
+    }
+}
+
+}

File cgml-as3-support/src/main/flex/com/yelbota/cgml/net/errors/PacketStackError.as

+package com.yelbota.cgml.net.errors {
+
+public class PacketStackError extends Error {
+
+    public static const NO_PACKETS_AVALIABLE:String = "No packets avaliable";
+
+    public function PacketStackError(message:String) {
+        super(message);
+    }
+}
+
+}

File cgml-as3-support/src/main/flex/com/yelbota/cgml/net/events/ConnectionEvent.as

+package com.yelbota.cgml.net.events {
+
+import flash.events.Event;
+import flash.utils.ByteArray;
+
+public class ConnectionEvent extends Event {
+
+    public static const PACKET:String = "packet";
+
+    public var bytes:ByteArray;
+
+    public function ConnectionEvent(type:String, bytes:ByteArray, bubbles:Boolean = false, cancelable:Boolean = false) {
+        super(type, bubbles, cancelable);
+        this.bytes = bytes;
+    }
+}
+
+}

File cgml-as3-support/src/main/flex/com/yelbota/cgml/option/OptionBool.as

+/*
+ * This file is part of the CGML Compiler
+ *
+ * Copyright(c) 2010 Aleksey Fomkin <aleksey.fomkin@gmail.com>
+ * http://bitbucket.org/yelbota/cgml-compiler
+ *
+ * This file may be licensed under the terms of of the
+ * GNU General Public License Version 3 (the ``GPL'').
+ *
+ * Software distributed under the License is distributed
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the GPL for the specific language
+ * governing rights and limitations.
+ *
+ * You should have received a copy of the GPL along with this
+ * program. If not, go to http://www.gnu.org/licenses/gpl.html
+ * or write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+package com.yelbota.cgml.option {
+
+public class OptionBool {
+  public var value:Boolean;
+
+  public function OptionBool(value:Boolean) {
+    this.value = value;
+  }
+}
+
+}

File cgml-as3-support/src/main/flex/com/yelbota/cgml/option/OptionFloat.as

+/*
+ * This file is part of the CGML Compiler
+ *
+ * Copyright(c) 2010 Aleksey Fomkin <aleksey.fomkin@gmail.com>
+ * http://bitbucket.org/yelbota/cgml-compiler
+ *
+ * This file may be licensed under the terms of of the
+ * GNU General Public License Version 3 (the ``GPL'').
+ *
+ * Software distributed under the License is distributed
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the GPL for the specific language
+ * governing rights and limitations.
+ *
+ * You should have received a copy of the GPL along with this
+ * program. If not, go to http://www.gnu.org/licenses/gpl.html
+ * or write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+package com.yelbota.cgml.option {
+
+public class OptionFloat {
+  public var value:Number;
+
+  public function OptionFloat(value:Number) {
+    this.value = value;
+  }
+}
+
+}

File cgml-as3-support/src/main/flex/com/yelbota/cgml/option/OptionInt.as

+/*
+ * This file is part of the CGML Compiler
+ *
+ * Copyright(c) 2010 Aleksey Fomkin <aleksey.fomkin@gmail.com>
+ * http://bitbucket.org/yelbota/cgml-compiler
+ *
+ * This file may be licensed under the terms of of the
+ * GNU General Public License Version 3 (the ``GPL'').
+ *
+ * Software distributed under the License is distributed
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the GPL for the specific language
+ * governing rights and limitations.
+ *
+ * You should have received a copy of the GPL along with this
+ * program. If not, go to http://www.gnu.org/licenses/gpl.html
+ * or write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+package com.yelbota.cgml.option {
+
+public class OptionInt {
+  public var value:int;
+
+  public function OptionInt(value:int) {
+    this.value = value;
+  }
+}
+
+}

File cgml-as3-support/src/test/flex/com/yarrcad/cgml/net/PacketStackTest.as

-package com.yarrcad.cgml.net {
-
-import flash.utils.ByteArray;
-
-import org.flexunit.asserts.assertFalse;
-import org.flexunit.asserts.assertTrue;
-
-public class PacketStackTest {
-
-    private static function v2b(v:Vector.<int>):ByteArray {
-        var ba:ByteArray = new ByteArray();
-        for each (var i:int in v)
-            ba.writeByte(i);
-        ba.position = 0;
-        return ba;
-    }
-
-    [Test]
-    public function testProcessData1():void {
-        var bytes:ByteArray = v2b(new <int>[0, 0]);
-        var o:PacketStack = new PacketStack();
-        o.processInput(bytes);
-
-        assertFalse("2 bytes is not packet.", o.size > 0);
-    }
-
-    [Test]
-    public function testProcessData4():void {
-        var bytes:ByteArray = v2b(new <int>[0, 0, 0, 0, 0, 0, 0, 0]);
-        var o:PacketStack = new PacketStack();
-        o.processInput(bytes);
-        assertTrue("There is must be two packet with zero length.", o.size == 2);
-    }
-
-    [Test]
-    public function testProcessData5():void {
-        var bytes:ByteArray = new ByteArray();
-        bytes.writeInt(2);
-        bytes.writeByte(0);
-        bytes.position = 0;
-
-        var o:PacketStack = new PacketStack();
-        o.processInput(bytes);
-
-        assertFalse("Packet length is 2 bytes, but 1 byte written.", o.size > 0);
-    }
-
-    [Test]
-    public function testProcessData6():void {
-        var bytes:ByteArray = new ByteArray();
-        bytes.writeInt(2);
-        bytes.writeShort(0);
-        bytes.position = 0;
-
-        var o:PacketStack = new PacketStack();
-        o.processInput(bytes);
-
-        assertTrue(
-                "Packet length is 2 bytes, and 2 byte written. This is correct packet",
-                o.size == 1 && o.take().length == 2
-        );
-    }
-
-    [Test]
-    public function testProcessDataBroken():void {
-
-        var o:PacketStack = new PacketStack();
-        var bytes:ByteArray = new ByteArray();
-        bytes.writeInt(7);
-        bytes.writeBytes(v2b(new <int>[1, 2, 3, 4, 5, 6])); // пакет не заканчивается
-        bytes.position = 0;
-
-        o.processInput(bytes);
-
-        bytes = new ByteArray()
-        bytes.writeByte(0); // добиваем первый пакет
-        bytes.writeInt(10);
-        bytes.writeByte(0); // второй пакет не заканчивается
-        bytes.position = 0;
-
-        o.processInput(bytes);
-
-        bytes = new ByteArray();
-        bytes.writeBytes(v2b(new <int>[2, 3, 4, 5, 6, 7, 8, 9, 0])); // добиваем второй пакет
-        bytes.position = 0;
-
-        o.processInput(bytes);
-
-        assertTrue(
-                "Two packets was sent in different times. Query works correctly ",
-                o.size == 2
-        );
-    }
-}
-
-}

File cgml-as3-support/src/test/flex/com/yelbota/cgml/net/PacketQueueTest.as

+package com.yelbota.cgml.net {
+
+import flash.utils.ByteArray;
+
+import org.flexunit.asserts.assertFalse;
+import org.flexunit.asserts.assertTrue;
+
+public class PacketQueueTest {
+
+    private static function v2b(v:Vector.<int>):ByteArray {
+        var ba:ByteArray = new ByteArray();
+        for each (var i:int in v)
+            ba.writeByte(i);
+        ba.position = 0;
+        return ba;
+    }
+
+    [Test]
+    public function testProcessData1():void {
+        var bytes:ByteArray = v2b(new <int>[0, 0]);
+        var o:PacketQueue = new PacketQueue();
+        o.processInput(bytes);
+
+        assertFalse("2 bytes is not packet.", o.size > 0);
+    }
+
+    [Test]
+    public function testProcessData4():void {
+        var bytes:ByteArray = v2b(new <int>[0, 0, 0, 0, 0, 0, 0, 0]);
+        var o:PacketQueue = new PacketQueue();
+        o.processInput(bytes);
+        assertTrue("There is must be two packet with zero length.", o.size == 2);
+    }
+
+    [Test]
+    public function testProcessData5():void {
+        var bytes:ByteArray = new ByteArray();
+        bytes.writeInt(2);
+        bytes.writeByte(0);
+        bytes.position = 0;
+
+        var o:PacketQueue = new PacketQueue();
+        o.processInput(bytes);
+
+        assertFalse("Packet length is 2 bytes, but 1 byte written.", o.size > 0);
+    }
+
+    [Test]
+    public function testProcessData6():void {
+        var bytes:ByteArray = new ByteArray();
+        bytes.writeInt(2);
+        bytes.writeShort(0);
+        bytes.position = 0;
+
+        var o:PacketQueue = new PacketQueue();
+        o.processInput(bytes);
+
+        assertTrue(
+                "Packet length is 2 bytes, and 2 byte written. This is correct packet",
+                o.size == 1 && o.take().length == 2
+        );
+    }
+
+    [Test]
+    public function testProcessDataBroken():void {
+
+        var o:PacketQueue = new PacketQueue();
+        var bytes:ByteArray = new ByteArray();
+        bytes.writeInt(7);
+        bytes.writeBytes(v2b(new <int>[1, 2, 3, 4, 5, 6])); // пакет не заканчивается
+        bytes.position = 0;
+
+        o.processInput(bytes);
+
+        bytes = new ByteArray()
+        bytes.writeByte(0); // добиваем первый пакет
+        bytes.writeInt(10);
+        bytes.writeByte(0); // второй пакет не заканчивается
+        bytes.position = 0;
+
+        o.processInput(bytes);
+
+        bytes = new ByteArray();
+        bytes.writeBytes(v2b(new <int>[2, 3, 4, 5, 6, 7, 8, 9, 0])); // добиваем второй пакет
+        bytes.position = 0;
+
+        o.processInput(bytes);
+
+        assertTrue(
+                "Two packets was sent in different times. Query works correctly ",
+                o.size == 2
+        );
+    }
+}
+
+}

File cgml-java-support/src/main/java/com/yarrcad/cg/ObjectStorage.java

-/*
- * This file is part of the CGML Compiler
- *
- * Copyright(c) 2010 Aleksey Fomkin <aleksey.fomkin@gmail.com>
- * http://bitbucket.org/yelbota/cgml-compiler
- *
- * This file may be licensed under the terms of of the
- * GNU General Public License Version 3 (the ``GPL'').
- *
- * Software distributed under the License is distributed
- * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
- * express or implied. See the GPL for the specific language
- * governing rights and limitations.
- *
- * You should have received a copy of the GPL along with this
- * program. If not, go to http://www.gnu.org/licenses/gpl.html
- * or write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-package com.yarrcad.cg;
-
-import java.util.HashMap;
-import java.util.Random;
-
-/**
- * Object storage is place, where readers and writers collect
- * declared objects.
- *
- * @author Aleksey Fomkin
- */
-@SuppressWarnings("unused")
-public final class ObjectStorage {
-
-    /**
-     * Object storage
-     */
-    private HashMap<Integer, Object> map = new HashMap<Integer, Object>();
-
-    /**
-     * Index of object storage. It needs for fast search ids by
-     * object values
-     */
-    private HashMap<Object, Integer> indexMap = new HashMap<Object, Integer>();
-
-    /**
-     * Initializtion map. Objects can exeists in storage, but in might
-     * be to initialized. When object pass initialization in puts in
-     * this map.
-     */
-    private HashMap<Object, Boolean> initMap = new HashMap<Object, Boolean>();
-
-    /**
-     * Parent object table, parent object can't be
-     * modified from here.
-     */
-    private ObjectStorage parent;
-
-    public ObjectStorage(ObjectStorage parent) {
-        this.parent = parent;
-    }
-
-    public ObjectStorage() {
-
-    }
-
-    /**
-     * @return Id for a new object.
-     */
-    public int generateId() {
-
-        Random random = new Random();
-
-        int id = random.nextInt();
-        while (getObjectExists(id))
-            id = random.nextInt();
-
-        return id;
-    }
-
-    /**
-     * Register new object in reference table.
-     *
-     * @param object new object.
-     * @return id of new object.
-     */
-    public int registerNewObject(Object object) {
-        int id = generateId();
-        registerObject(id, object);
-        return id;
-    }
-
-    /**
-     * Register any object in the reference table.
-     *
-     * @param id     object id
-     * @param object object
-     */
-    public void registerObject(int id, Object object) {
-        map.put(id, object);
-        indexMap.put(object, id);
-    }
-
-    /**
-     * @param object any object
-     * @return Id of object if it's allready registred.
-     */
-    public int getObjectId(Object object) throws ObjectNotRegistred {
-        if (parent != null) {
-            Integer id = indexMap.get(object);
-            if (id != null)
-                return id;
-        }
-
-        Integer id = indexMap.get(object);
-        if (id == null) {
-            throw new ObjectNotRegistred();
-        }
-        else return id;
-    }
-
-    public Object getObject(int id) {
-        if (parent != null && parent.getObjectExists(id))
-            return parent.getObject(id);
-        else return map.get(id);
-    }
-
-    public boolean getObjectExists(int id) {
-        if (parent != null)
-            return parent.getObjectExists(id) || map.containsKey(id);
-        else return map.containsKey(id);
-    }
-
-    public boolean getObjectExists(Object object) {
-        if (parent != null)
-            return parent.getObjectExists(object) || map.containsValue(object);
-        else return map.containsValue(object);
-    }
-
-    /**
-     * Check object marked as initialized.
-     *
-     * @param object object
-     * @return inializtion status.
-     */
-    public boolean getObjectInitialized(Object object) {
-        if (parent != null && getObjectExists(object))
-            return parent.getObjectInitialized(object);
-        else {
-            Boolean b = initMap.get(object);
-            return (b == null) ? false : b;
-        }
-    }
-
-    public void setObjectInitialized(Object object) {
-        if (parent != null && getObjectExists(object))
-            parent.setObjectInitialized(object);
-        else initMap.put(object, true);
-    }
-
-    public class ObjectNotRegistred extends Exception {
-    }
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/rpc/AbstractSender.java

-package com.yarrcad.cg.rpc;
-
-import com.yarrcad.cg.ObjectStorage;
-
-public abstract class AbstractSender<T> {
-
-    private T serverInterface;
-    private ObjectStorage objectStorage;
-
-    protected T getServerInterface() {
-        return serverInterface;
-    }
-
-    protected ObjectStorage getObjectStorage() {
-        return objectStorage;
-    }
-
-    public AbstractSender(T serverInterface, ObjectStorage objectStorage) {
-        this.serverInterface = serverInterface;
-        this.objectStorage = objectStorage;
-    }
-
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/rpc/PacketExchange.java

-package com.yarrcad.cg.rpc;
-
-public interface PacketExchange {
-    byte[] send(byte[] data);
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/rpc/PacketExchangeAsync.java

-package com.yarrcad.cg.rpc;
-
-public interface PacketExchangeAsync {
-    void send(byte[] data, RawPacketHandler handler);
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/rpc/PacketHandler.java

-package com.yarrcad.cg.rpc;
-
-public interface PacketHandler<T> {
-    void process(T packet);
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/rpc/RawPacketHandler.java

-package com.yarrcad.cg.rpc;
-
-import java.io.IOException;
-
-public interface RawPacketHandler {
-    void process(byte[] packet) throws IOException;
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/rpc/ServerInterface.java

-package com.yarrcad.cg.rpc;
-
-public interface ServerInterface {
-    PacketExchange startPacketExchange();
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/rpc/ServerInterfaceAsync.java

-package com.yarrcad.cg.rpc;
-
-public interface ServerInterfaceAsync {
-    PacketExchangeAsync startPacketExchange();
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/rpc/socket/PacketQueue.java

-package com.yarrcad.cg.rpc.socket;
-
-import java.io.DataInputStream;
-import java.io.IOException;
-import java.util.LinkedList;
-
-public class PacketQueue extends LinkedList<byte[]> {
-
-	private byte[] buffer = new byte[0];
-	private int knownPacketLength = -1;
-
-	public void processInput(DataInputStream input) throws IOException {
-		if (knownPacketLength > -1) {
-			// We allready know packet length
-			// So lets read out.
-			int toRead = Math.min(input.available(), knownPacketLength - buffer.length);
-			byte[] newBuffer = new byte[buffer.length + toRead];
-			input.read(newBuffer, buffer.length, toRead);
-			System.arraycopy(buffer, 0, newBuffer, 0, buffer.length);
-			buffer = newBuffer;
-			// Check packet length
-			if (buffer.length >= knownPacketLength) {
-				// Yeha! Packet complete.
-				// Call user handler and reset the buffer.
-				add(buffer);
-				buffer = new byte[0];
-				knownPacketLength = -1;
-				processInput(input);
-			}
-		} else if (input.available() >= 4) {
-			// Can read length of packet
-			knownPacketLength = input.readInt();
-			processInput(input);
-		}
-	}
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/yaml/MarkedError.java

-package com.yarrcad.cg.yaml;
-
-import org.yaml.snakeyaml.error.Mark;
-
-public class MarkedError {
-	private Mark mark;
-	private String message;
-	
-	public MarkedError(String message, Mark mark) {
-		this.message = message;
-		this.mark = mark;
-	}
-
-	public Mark getMark() {
-		return mark;
-	}
-
-	public String getMessage() {
-		return message;
-	}
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/yaml/MarkedErrorException.java

-package com.yarrcad.cg.yaml;
-
-import org.yaml.snakeyaml.error.Mark;
-
-@SuppressWarnings("serial")
-public class MarkedErrorException extends Throwable {
-	private Mark mark; 
-	public Mark getMark() {
-		return mark;
-	}
-	
-	public MarkedErrorException(String message, Mark mark) {
-		super(message);
-		this.mark = mark;
-	}
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/yaml/ReferenceWrongTypeException.java

-package com.yarrcad.cg.yaml;
-
-import org.yaml.snakeyaml.error.Mark;
-
-/**
- * Throws when reference and target field has incompatible types.
- */
-@SuppressWarnings("unused")
-public class ReferenceWrongTypeException extends MarkedErrorException {
-
-    public ReferenceWrongTypeException(String s, Mark mark) {
-        super(s, mark);
-    }
-}

File cgml-java-support/src/main/java/com/yarrcad/cg/yaml/YamlReferenceTable.java

-/*
- * This file is part of the CGML Compiler
- *
- * Copyright(c) 2010 Aleksey Fomkin <aleksey.fomkin@gmail.com>
- * http://bitbucket.org/yelbota/cgml-compiler
- *
- * This file may be licensed under the terms of of the
- * GNU General Public License Version 3 (the ``GPL'').
- *
- * Software distributed under the License is distributed
- * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
- * express or implied. See the GPL for the specific language
- * governing rights and limitations.
- *
- * You should have received a copy of the GPL along with this
- * program. If not, go to http://www.gnu.org/licenses/gpl.html
- * or write to the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-package com.yarrcad.cg.yaml;
-
-import com.yarrcad.cg.ObjectStorage;
-import org.yaml.snakeyaml.error.Mark;
-
-import java.lang.reflect.Field;
-import java.util.LinkedList;
-import java.util.List;
-
-public class YamlReferenceTable {
-
-    /**
-     * Throws then reference is not found.
-     */
-    public class NoRefecenceException extends MarkedErrorException {
-        public NoRefecenceException(String s, Mark mark) {
-            super(s, mark);
-        }
-    }
-
-    private class YamlReference {
-
-        private Mark mark;
-        private Object object;
-        private String name;
-
-        public YamlReference(Object object, String name, Mark mark) {
-            this.object = object;
-            this.mark = mark;
-            this.name = name;
-        }
-    }
-
-    /**
-     * In the YAML readeds we have places, where declared objects are
-     * used. User can write invalid code and we must tell him about it.
-     */
-    private List<YamlReference> yamlReferenceList = new LinkedList<YamlReference>();
-
-    /**
-     * Object storage
-     */
-    private ObjectStorage objectStorage;
-
-    /**
-     * Constructor
-     * @param objectStorage true object table.
-     */
-    @SuppressWarnings("unused")
-    public YamlReferenceTable(ObjectStorage objectStorage) {
-        this.objectStorage = objectStorage;
-    }
-
-    /**
-     * Uses in generaged yaml readers. Adds reference declaration.
-     * @param object link to object from object storage.
-     * @param mark place in the YAML document
-     */
-    @SuppressWarnings("unused")
-    public void registerReference(Object object, String name, Mark mark) {
-        yamlReferenceList.add(new YamlReference(object, name, mark));
-    }
-
-    /**
-     * Reference validation.
-     * @throws NoRefecenceException Then object follow the reference is not initialized.
-     */
-    @SuppressWarnings("unused")
-    public void checkReferences() throws NoRefecenceException {
-        for (YamlReference reference : yamlReferenceList) {
-            // Check object is initialized
-            if (!objectStorage.getObjectInitialized(reference.object)) {
-                // If we don't know the name. It can't be but anyway lets check.
-                if (reference.name == null) {
-                    try {
-                        reference.name = "@" + objectStorage.getObjectId(reference.object);
-                    } catch (ObjectStorage.ObjectNotRegistred objectNotRegistred) {
-                        throw new RuntimeException("YAML reference to unknown object. Please contact with developers.");
-                    }
-                }
-                throw new NoRefecenceException(reference.name + " doesn't initialized.", reference.mark);
-            }
-        }
-    }
-}

File cgml-java-support/src/main/java/com/yelbota/cgml/DataStream.java

+package com.yelbota.cgml;
+
+import java.util.List;
+
+public interface DataStream {
+
+    enum BasicType {
+        BYTE,
+        INT,
+        SHORT,
+        INT64,
+        UBYTE,
+        USHORT,
+        DOUBLE,
+        BOOL,
+        STRING,
+        BUFFER;
+    }
+
+    byte[] readBuffer();
+    byte[] readOptionBuffer();
+
+    String readString();
+    String readOptionString();
+
+    int readInt();
+    byte readByte();
+    short readShort();
+    long readInt64();
+    short readUByte();
+    int readUShort();
+    double readDouble();
+    boolean readBool();
+
+    Integer readOptionInt();
+    Byte readOptionByte();
+    Short readOptionShort();
+    Long readOptionInt64();
+    Short readOptionUByte();
+    Integer readOptionUShort();
+    Double readOptionDouble();
+    Boolean readOptionBool();
+
+    <T> List<T> readBList(BasicType type);
+    <T> List<T> readSList(BasicType type);
+    <T> List<T> readList(BasicType type);
+    <T extends DataStreamReader> List<T> readBList(Class<T> clazz);
+    <T extends DataStreamReader> List<T> readSList(Class<T> clazz);
+    <T extends DataStreamReader> List<T> readList(Class<T> clazz);
+    <T extends DataStreamReader> T readObject(Class<T> clazz);
+
+    <T> List<T> readOptionBList(BasicType type);
+    <T> List<T> readOptionSList(BasicType type);
+    <T> List<T> readOptionList(BasicType type);
+    <T extends DataStreamReader> List<T> readOptionBList(Class<T> clazz);
+    <T extends DataStreamReader> List<T> readOptionSList(Class<T> clazz);
+    <T extends DataStreamReader> List<T> readOptionList(Class<T> clazz);
+    <T extends DataStreamReader> T readOptionObject(Class<T> clazz);
+}

File cgml-java-support/src/main/java/com/yelbota/cgml/DataStreamReader.java

+package com.yelbota.cgml;
+
+public interface DataStreamReader {
+    void read(DataStream stream);
+}

File cgml-java-support/src/main/java/com/yelbota/cgml/ObjectStorage.java

+/*
+ * This file is part of the CGML Compiler
+ *
+ * Copyright(c) 2010 Aleksey Fomkin <aleksey.fomkin@gmail.com>
+ * http://bitbucket.org/yelbota/cgml-compiler
+ *
+ * This file may be licensed under the terms of of the
+ * GNU General Public License Version 3 (the ``GPL'').
+ *
+ * Software distributed under the License is distributed
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the GPL for the specific language
+ * governing rights and limitations.
+ *
+ * You should have received a copy of the GPL along with this
+ * program. If not, go to http://www.gnu.org/licenses/gpl.html
+ * or write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+package com.yelbota.cgml;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Random;
+
+/**
+ * Object storage is place, where readers and writers collect
+ * declared objects.
+ *
+ * @author Aleksey Fomkin
+ */
+@SuppressWarnings("unused")
+public final class ObjectStorage {
+
+    /**
+     * Object storage
+     */
+    private HashMap<Integer, Object> map = new HashMap<Integer, Object>();
+
+    /**
+     * Index of object storage. It needs for fast search ids by
+     * object values
+     */
+    private HashMap<Object, Integer> indexMap = new HashMap<Object, Integer>();
+
+    /**
+     * Initializtion map. Objects can exeists in storage, but in might
+     * be to initialized. When object pass initialization in puts in
+     * this map.
+     */
+    private HashMap<Object, Boolean> initMap = new HashMap<Object, Boolean>();
+
+    /**
+     * Parent object table, parent object can't be
+     * modified from here.
+     */
+    private ObjectStorage parent;
+
+    public ObjectStorage(ObjectStorage parent) {
+        this.parent = parent;
+    }
+
+    public ObjectStorage() {
+
+    }
+
+    /**
+     * @return Id for a new object.
+     */
+    public int generateId() {
+
+        Random random = new Random();
+
+        int id = random.nextInt();
+        while (getObjectExists(id))
+            id = random.nextInt();
+
+        return id;
+    }
+
+    /**
+     * Register new object in reference table.
+     *
+     * @param object new object.
+     * @return id of new object.
+     */
+    public int registerNewObject(Object object) {
+        int id = generateId();
+        registerObject(id, object);
+        return id;
+    }
+