All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cfml.parsing.cfscript.script.CFLockStatement Maven / Gradle / Ivy

There is a newer version: 2.11.0
Show newest version
package cfml.parsing.cfscript.script;

import java.util.HashSet;
import java.util.List;
import java.util.Map;

import cfml.parsing.cfscript.CFExpression;
import cfml.parsing.cfscript.CFIdentifier;
import cfml.parsing.reporting.ParseException;
import cfml.parsing.util.ArrayBuilder;

public class CFLockStatement extends CFParsedAttributeStatement implements java.io.Serializable {
	
	private static final long serialVersionUID = 1L;
	
	private CFScriptStatement body;
	
	private static HashSet supportedAttributes;
	
	static {
		supportedAttributes = new HashSet();
		supportedAttributes.add("TYPE");
		supportedAttributes.add("TIMEOUT");
		supportedAttributes.add("NAME");
		supportedAttributes.add("SCOPE");
		supportedAttributes.add("THROWONTIMEOUT");
	}
	
	public CFLockStatement(org.antlr.v4.runtime.Token _t, Map _attr, CFScriptStatement _body) {
		super(_t, _attr);
		
		validateAttributes(_t, supportedAttributes);
		
		body = _body;
	}
	
	public void validate() {
		// minimal requirement is the timeout attribute
		if (!containsAttribute("TIMEOUT"))
			throw new ParseException(token, "Lock requires the TIMEOUT attribute");
		
		if (containsAttribute("NAME") && containsAttribute("SCOPE"))
			throw new ParseException(token, "Invalid Attributes: specify either SCOPE or NAME, but not both");
	}
	
	@Override
	public String Decompile(int indent) {
		validate();
		
		StringBuilder sb = new StringBuilder();
		sb.append("lock ");
		DecompileAttributes(sb);
		sb.append(body.Decompile(0));
		
		return sb.toString();
	}
	
	public CFScriptStatement getBody() {
		return body;
	}
	
	public static HashSet getSupportedAttributes() {
		return supportedAttributes;
	}
	
	@Override
	public List decomposeScript() {
		return ArrayBuilder.createCFScriptStatement(body);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy