define([
	"dojo/_base/kernel",
	"dojo/_base/lang",
	"dojo/Stateful"
], function(kernel, lang, Stateful){


	//target prop may refer to an object path
	var get = function(/*dojo/Stateful*/ target, /*String*/ targetProp, /*boolean*/ create){
		var path = targetProp.split(".");
		if (path.length)
		{
			var tmp=target;
			for (var i=0; i<path.length; i++)
			{
				if (i==path.length - 1)
				{
					//last path segment
					return tmp.get(path[i]);
				}
				else
				{
					var s = tmp.get(path[i]);
					if (s && s.get)
					{
						tmp=s;
					}
					else
					{
						if (create)
						{
							//if it does not exist create a new stateful
							var n = new Stateful();
							tmp.set(path[i], n);
							tmp = n;							
						}
						else {
							return undefined;
						}
					}
				}
			}
		}
		return undefined;
	};

	return lang.setObject("obno.model.resource.get", get);
});