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.fatwire.gst.foundation.groovy.DiskGroovyLoader;
24 import com.fatwire.gst.foundation.groovy.GroovyLoader;
25
26 /**
27 * Loader for groovy script classes, configured via spring and ServletContext
28 *
29 * @author Dolf Dijkstra
30 * @since Mar 28, 2011
31 */
32 /*
33 * alternative method:
34 * http://groovy.codehaus.org/Alternate+Spring-Groovy-Integration
35 */
36 public class SpringDiskGroovyLoader extends WebApplicationObjectSupport implements GroovyLoader {
37 private DiskGroovyLoader groovyLoader;
38 private String configPath;
39 private int minimumRecompilationInterval = 0;
40
41 public SpringDiskGroovyLoader() {
42 super();
43
44 }
45
46 /*
47 * (non-Javadoc)
48 *
49 * @seeorg.springframework.web.context.support.WebApplicationObjectSupport#
50 * initServletContext(javax.servlet.ServletContext)
51 */
52 @Override
53 protected void initServletContext(ServletContext servletContext) {
54 groovyLoader = new DiskGroovyLoader();
55 groovyLoader.setConfigPath(configPath);
56 groovyLoader.setMinimumRecompilationInterval(minimumRecompilationInterval);
57 groovyLoader.bootEngine(getConfigPath());
58
59 }
60
61 /*
62 * (non-Javadoc)
63 *
64 * @see
65 * com.fatwire.gst.foundation.groovy.spring.GroovyLoader#load(java.lang.
66 * String)
67 */
68 @Override
69 public Object load(String name) throws Exception {
70
71 return groovyLoader.load(name);
72 }
73
74 /**
75 * @return the configPath
76 */
77 public String getConfigPath() {
78 return configPath;
79 }
80
81 /**
82 * @param configPath the configPath to set
83 */
84 public void setConfigPath(String configPath) {
85 this.configPath = configPath;
86 }
87
88 /**
89 * @return the minimumRecompilationInterval
90 */
91 public int getMinimumRecompilationInterval() {
92 return minimumRecompilationInterval;
93 }
94
95 /**
96 * Sets the minimumRecompilationInterval of the GroovyScriptEngine
97 * configuration.
98 *
99 * @param minimumRecompilationInterval the minimumRecompilationInterval to
100 * set
101 */
102 public void setMinimumRecompilationInterval(int minimumRecompilationInterval) {
103 this.minimumRecompilationInterval = minimumRecompilationInterval;
104
105 if (groovyLoader != null) {
106 groovyLoader.setMinimumRecompilationInterval(minimumRecompilationInterval);
107 }
108 }
109
110 }