/* ************************************************************************
#
#  DivConq
#
#  http://divconq.com/
#
#  Copyright:
#    Copyright 2012 eTimeline, LLC. All rights reserved.
#
#  License:
#    See the license.txt file in the project's top-level directory for details.
#
#  Authors:
#    * Andy White
#
************************************************************************ */
package divconq.script.mutator;

import divconq.script.Activity;
import divconq.script.IMutator;
import divconq.script.StackEntry;
import divconq.struct.ScalarStruct;
import divconq.struct.Struct;
import divconq.xml.XElement;

public class SetMutator implements IMutator {
	// only works on scalars

	@Override
	public void mutate(Activity activity, StackEntry stack, XElement code, Struct dest) {
		Struct sref = stack.refFromSource(code, "Value", dest.getType()); 
		
		// resolve value only works with scalars
		if ((dest == null) || !(dest instanceof ScalarStruct)) {
			// TODO log
			return;
		}
		
		((ScalarStruct) dest).adaptValue(sref);
	}
}
