summaryrefslogtreecommitdiffstats
path: root/src/main/java/com/btr/proxy/selector/pac/ScriptAvailability.java
blob: d7f6e04adbf854dfab1c5a09ba889fe9c5b3d39b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package com.btr.proxy.selector.pac;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/****************************************************************************
 * Utility to check availablility of javax.script
 * 
 * @author Bernd Rosstauscher (proxyvole@rosstauscher.de) Copyright 2009
 ***************************************************************************/
abstract class ScriptAvailability {
	
	/*************************************************************************
	 * Checks whether javax.script is available or not.
	 * Completely done per Reflection to allow compilation under Java 1.5
	 * @return true if javax.script is available; false otherwise
	 ************************************************************************/
	public static boolean isJavaxScriptingAvailable() {
		Object engine = null;
		try {
			Class<?> managerClass = Class.forName("javax.script.ScriptEngineManager");
			Method m = managerClass.getMethod("getEngineByMimeType", String.class);
			engine = m.invoke(managerClass.newInstance(), "text/javascript");
		} catch (ClassNotFoundException e) {
			// javax.script not available
		} catch (NoSuchMethodException e) {
			// javax.script not available
		} catch (IllegalAccessException e) {
			// javax.script not available
		} catch (InvocationTargetException e) {
			// javax.script not available
		} catch (InstantiationException e) {
			// javax.script not available
		}

		return engine != null;
	}

	/*************************************************************************
	 * Constructor
	 ************************************************************************/
	
	ScriptAvailability() {
		super();
	}
}