KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > scripting > support > StaticScriptSource


1 /*
2  * Copyright 2002-2007 the original author or authors.
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 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 JavaDoc script;
35
36     private boolean modified;
37
38
39     /**
40      * Create a new StaticScriptSource for the given script.
41      * @param script the script String
42      * @throws IllegalArgumentException if the supplied <code>script</code> is <code>null</code>
43      */

44     public StaticScriptSource(String JavaDoc script) {
45         setScript(script);
46     }
47
48
49     /**
50      * Set a fresh script String, overriding the previous script.
51      * @param script the script String
52      * @throws IllegalArgumentException if the supplied <code>script</code> is <code>null</code>
53      */

54     public synchronized void setScript(String JavaDoc script) {
55         Assert.hasText(script, "Script must not be empty");
56         this.modified = !script.equals(this.script);
57         this.script = script;
58     }
59
60
61     public synchronized String JavaDoc getScriptAsString() {
62         this.modified = false;
63         return this.script;
64     }
65
66     public synchronized boolean isModified() {
67         return this.modified;
68     }
69
70
71     public synchronized String JavaDoc toString() {
72         return this.script;
73     }
74
75 }
76
Popular Tags