1 /*
2 * Copyright 2011 FatWire Corporation. All Rights Reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package com.fatwire.gst.foundation.groovy.spring;
18
19 import javax.servlet.ServletContext;
20
21 import org.springframework.web.context.support.WebApplicationObjectSupport;
22
23 import COM.FutureTense.Interfaces.ICS;
24
25 import com.fatwire.gst.foundation.groovy.DiskGroovyLoader;
26 import com.fatwire.gst.foundation.groovy.GroovyLoader;
27
28 /**
29 * Loader for groovy script classes, configured via spring and ServletContext
30 *
31 * @author Dolf Dijkstra
32 * @since Mar 28, 2011
33 */
34 /*
35 * alternative method:
36 * http://groovy.codehaus.org/Alternate+Spring-Groovy-Integration
37 */
38 public class SpringDiskGroovyLoader extends WebApplicationObjectSupport implements GroovyLoader {
39 private DiskGroovyLoader groovyLoader;
40 private String configPath;
41 private int minimumRecompilationInterval = 0;
42
43 public SpringDiskGroovyLoader() {
44 super();
45
46 }
47
48 /*
49 * (non-Javadoc)
50 *
51 * @seeorg.springframework.web.context.support.WebApplicationObjectSupport#
52 * initServletContext(javax.servlet.ServletContext)
53 */
54 @Override
55 protected void initServletContext(ServletContext servletContext) {
56 groovyLoader = new DiskGroovyLoader();
57 groovyLoader.setConfigPath(configPath);
58 groovyLoader.setMinimumRecompilationInterval(minimumRecompilationInterval);
59 groovyLoader.bootEngine(getConfigPath());
60
61 }
62
63 /*
64 * (non-Javadoc)
65 *
66 * @see
67 * com.fatwire.gst.foundation.groovy.spring.GroovyLoader#load(java.lang.
68 * String)
69 */
70 @Override
71 public Object load(ICS ics,String name) throws Exception {
72
73 return groovyLoader.load(ics,name);
74 }
75
76 /**
77 * @return the configPath
78 */
79 public String getConfigPath() {
80 return configPath;
81 }
82
83 /**
84 * @param configPath the configPath to set
85 */
86 public void setConfigPath(String configPath) {
87 this.configPath = configPath;
88 }
89
90 /**
91 * @return the minimumRecompilationInterval
92 */
93 public int getMinimumRecompilationInterval() {
94 return minimumRecompilationInterval;
95 }
96
97 /**
98 * Sets the minimumRecompilationInterval of the GroovyScriptEngine
99 * configuration.
100 *
101 * @param minimumRecompilationInterval the minimumRecompilationInterval to
102 * set
103 */
104 public void setMinimumRecompilationInterval(int minimumRecompilationInterval) {
105 this.minimumRecompilationInterval = minimumRecompilationInterval;
106
107 if (groovyLoader != null) {
108 groovyLoader.setMinimumRecompilationInterval(minimumRecompilationInterval);
109 }
110 }
111
112 }