//================================= CLASS CONSTRUCTOR ========================================
function DnlCompositeEntity()
{
//MEMBER VARIABLES
 this.children = null;

 this.initialize();
}

//====================================== STATIC ==============================================
//CONSTANTS

//DERIVATION FOR >>> DnlCompositeEntity WITH BASE ELEMENT <<<
DnlCompositeEntity.prototype = new DnlEntity();
DnlCompositeEntity.prototype.constructor = DnlCompositeEntity;
DnlCompositeEntity.superclass = DnlEntity.prototype;

//====================================== MEMBERS =============================================
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ GETTER/SETTER ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ METHODS ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
DnlCompositeEntity.prototype.setDefaults = function()
{
 this.children = null;
}

DnlCompositeEntity.prototype.initialize = function()
{
 DnlCompositeEntity.superclass.initialize();
 this.children = new Array();
}

DnlCompositeEntity.prototype.query = function(icallback)
{
 var
  tmpRet = null,
  ret = null;

 ret = new Array();
 tmpRet = DnlCompositeEntity.superclass.query(icallback);
 if (tmpRet != null)
  ret = ret.concat(tmpRet);
 for (var i=0;i<this.children.length;i++)
 {
  tmpRet = this.children[i].query(icallback);
  if (tmpRet != null)
   ret = ret.concat(tmpRet);
 }
 return ret;
}

DnlCompositeEntity.prototype.add = function(ientity)
{
 this.children.push(ientity);
 ientity.setPosition(this.children.length-1);
 ientity.setParent(this);
}

DnlCompositeEntity.prototype.onChildRemoved = function(ientity)
{
 var
  entityPosition = ientity.getPosition();

 for (var i=entityPosition;i<this.children.length;i++)
  this.children[i] = this.children[i+1];
 this.children.splice(this.children.length-1,1);
}

DnlCompositeEntity.prototype.getChildCount = function()
{
 return this.children.length;
}

DnlCompositeEntity.prototype.getChild = function(iposition)
{
 return this.children[iposition];
}

DnlCompositeEntity.prototype.getChildById = function(iid)
{
 for (var i=0;i<this.children.length;i++)
 {
  if (this.children[i].getId() == iid)
   return this.children[i];
 }
 return null;
}

DnlCompositeEntity.prototype.finalize = function()
{
//Finalizing all children ...
 for (var i=0;i<this.children.length;i++)
  this.children[i].finalize();
 this.children.splice(0,this.children.length);
//Finalizing self ...
 DnlCompositeEntity.superclass.finalize();
 this.setDefaults();
}
