package com.hammurapi.common;

import javax.script.*;
import java.util.List;
import java.util.Arrays;

public class TokenExpanderScriptEngineFactory implements javax.script.ScriptEngineFactory {
	final List<String> extensions = Arrays.asList("token", "txt");

	final List<String> mimeTypes = Arrays.asList("application/x-token-expander");

	final List<String> names = Arrays.asList("tokenexpander");

	public String getEngineName() {
		return "Token Expander Engine";
	}

	public String getEngineVersion() {
		return "1.0";
	}

	public List<String> getExtensions() {
		return extensions;
	}

	public List<String> getMimeTypes() {
		return mimeTypes;
	}

	public List<String> getNames() {
		return names;
	}

	public String getLanguageName() {
		return "TokenExpander";
	}

	public String getLanguageVersion() {
		return "1.0";
	}

	public Object getParameter(String param) {
		if (param.equals(ScriptEngine.ENGINE))
			return getEngineName();
		if (param.equals(ScriptEngine.ENGINE_VERSION))
			return getEngineVersion();
		if (param.equals(ScriptEngine.NAME))
			return getEngineName();
		if (param.equals(ScriptEngine.LANGUAGE))
			return getLanguageName();
		if (param.equals(ScriptEngine.LANGUAGE_VERSION))
			return getLanguageVersion();
		if (param.equals("THREADING"))
			return "MULTITHREADED";

		return null;
	}

	public String getMethodCallSyntax(String objectName, String methodName,	String... args) {
		return null;
	}

	public String getOutputStatement(String message) {
		return null;
	}

	public String getProgram(String... statements) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < statements.length; i++) {
			sb.append(statements[i]);
		}
		return sb.toString();
	}

	public ScriptEngine getScriptEngine() {
		return new TokenExpanderScriptEngine();
	}

	// End impl ScriptEngineFactory
}
