01: /*
02: * Copyright 2002-2007 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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 org.springframework.scripting.support;
18:
19: import org.springframework.scripting.ScriptSource;
20: import org.springframework.util.Assert;
21:
22: /**
23: * Static implementation of the
24: * {@link org.springframework.scripting.ScriptSource} interface,
25: * encapsulating a given String that contains the script source text.
26: * Supports programmatic updates of the script String.
27: *
28: * @author Rob Harrop
29: * @author Juergen Hoeller
30: * @since 2.0
31: */
32: public class StaticScriptSource implements ScriptSource {
33:
34: private String script;
35:
36: private boolean modified;
37:
38: /**
39: * Create a new StaticScriptSource for the given script.
40: * @param script the script String
41: * @throws IllegalArgumentException if the supplied <code>script</code> is <code>null</code>
42: */
43: public StaticScriptSource(String script) {
44: setScript(script);
45: }
46:
47: /**
48: * Set a fresh script String, overriding the previous script.
49: * @param script the script String
50: * @throws IllegalArgumentException if the supplied <code>script</code> is <code>null</code>
51: */
52: public synchronized void setScript(String script) {
53: Assert.hasText(script, "Script must not be empty");
54: this .modified = !script.equals(this .script);
55: this .script = script;
56: }
57:
58: public synchronized String getScriptAsString() {
59: this .modified = false;
60: return this .script;
61: }
62:
63: public synchronized boolean isModified() {
64: return this .modified;
65: }
66:
67: public String toString() {
68: return "static script";
69: }
70:
71: }
|