







































Module('ca.carleton.gcrc.mvc.model','$Revision: 2028 $',function(mod){
var modObservable=imprt('ca.carleton.gcrc.mvc.observable');












mod.Model=Class(modObservable.Observable,function(publ,priv,supr){



publ.__init__=function(){

supr.__init__.call(this);



this._attributesByType={};
}





























publ.DefineAttribute=function(attributeName_,initialValue_,postSetFunction_,validatingFunction_){
var attributeObject={};
attributeObject.value=initialValue_;
attributeObject.postSet=postSetFunction_;
attributeObject.validate=validatingFunction_;

this._attributesByType[attributeName_]=attributeObject;
}












publ.IsValidAttributeValue=function(attributeName_,value_){
var attributeObject=this._attributesByType[attributeName_];
if(null==attributeObject){
throw('Attribute undefined: '+attributeName_);
return false;
}

if(null!=attributeObject.validate){
return attributeObject.validate.call(this,value_);
}


return true;
}














publ.SetAttribute=function(attributeName_,value_){
var attributeObject=this._attributesByType[attributeName_];
if(null==attributeObject){
alert('Attribute undefined: '+attributeName_);
return false;
}



if(attributeObject.value!=value_){

if(null!=attributeObject.validate){
var valid=attributeObject.validate.call(this,value_,attributeName_);
if(false==valid){
return false;
}
}


attributeObject.value=value_;


this.CallObservers(attributeName_,value_);


if(null!=attributeObject.postSet){
attributeObject.postSet.call(this,value_,attributeName_);
}
}

return true;
}







publ.GetAttribute=function(attributeName_){
var attributeObject=this._attributesByType[attributeName_];
if(null==attributeObject){
throw('Attribute undefined: '+attributeName_);
return null;
}

return attributeObject.value;
}

});
});