01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package de.schlund.pfixcore.scriptedflow;
20:
21: import java.util.HashMap;
22: import java.util.Map;
23:
24: import de.schlund.pfixcore.scriptedflow.compiler.Compiler;
25: import de.schlund.pfixcore.scriptedflow.compiler.CompilerException;
26: import de.schlund.pfixcore.scriptedflow.vm.Script;
27: import de.schlund.pfixxml.resources.FileResource;
28: import de.schlund.pfixxml.resources.ResourceUtil;
29:
30: /**
31: * Stores configuration for scripted flows.
32: *
33: * @author Sebastian Marsching <sebastian.marsching@1und1.de>
34: */
35: public class ScriptedFlowConfigImpl implements ScriptedFlowConfig {
36: private class Triple {
37: long mtime = -1;
38:
39: FileResource file = null;
40:
41: Script script = null;
42: }
43:
44: private Map<String, Triple> scripts = new HashMap<String, Triple>();
45:
46: /* (non-Javadoc)
47: * @see de.schlund.pfixcore.scriptedflow.ScriptedFlowConfig#getScript(java.lang.String)
48: */
49: public Script getScript(String name) throws CompilerException {
50: Triple t = this .scripts.get(name);
51: if (t == null) {
52: return null;
53: }
54: synchronized (t) {
55: if (t.script == null || t.file.lastModified() > t.mtime) {
56: if (!t.file.exists()) {
57: throw new CompilerException(
58: "Scripted flow "
59: + name
60: + " is defined but corresponding file does not exist");
61: }
62: t.mtime = t.file.lastModified();
63: t.script = Compiler.compile(t.file);
64: }
65: return t.script;
66: }
67: }
68:
69: public void addScript(String name, String path) {
70: Triple t = new Triple();
71: t.file = ResourceUtil.getFileResourceFromDocroot(path);
72: scripts.put(name, t);
73: }
74: }
|