001/* 002 * Copyright (c) 2006-2011 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the Eclipse Public License v1.0 006 * which accompanies this distribution, and is available at 007 * http://www.eclipse.org/legal/epl-v10.html 008 * 009 * Contributors: 010 * bstefanescu 011 */ 012package org.nuxeo.ecm.core.event.script; 013 014import java.io.IOException; 015import java.io.Reader; 016 017import javax.script.CompiledScript; 018import javax.script.ScriptContext; 019import javax.script.ScriptEngine; 020import javax.script.ScriptException; 021 022/** 023 * Simulates a compiled script for scripts that don't support compilation. 024 * 025 * @author <a href="mailto:bs@nuxeo.com">Bogdan Stefanescu</a> 026 */ 027public class FakeCompiledScript extends CompiledScript { 028 029 protected final ScriptEngine engine; 030 031 protected final Script script; 032 033 public FakeCompiledScript(ScriptEngine engine, Script script) { 034 this.script = script; 035 this.engine = engine; 036 } 037 038 @Override 039 public Object eval(ScriptContext arg0) throws ScriptException { 040 try { 041 Reader reader = script.getReader(); 042 return engine.eval(reader, arg0); 043 } catch (IOException e) { 044 throw new ScriptException(e); 045 } 046 } 047 048 @Override 049 public ScriptEngine getEngine() { 050 return engine; 051 } 052 053}