KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > junit > script > MockScriptProcessor


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package org.apache.tapestry.junit.script;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.List JavaDoc;
19
20 import org.apache.hivemind.Resource;
21 import org.apache.tapestry.IScriptProcessor;
22 import org.apache.tapestry.util.IdAllocator;
23
24 /**
25  * Used by {@link org.apache.tapestry.junit.script.TestScript}.
26  *
27  * @author Howard Lewis Ship
28  * @since 3.0
29  */

30 public class MockScriptProcessor implements IScriptProcessor
31 {
32     private StringBuffer JavaDoc _body;
33
34     private StringBuffer JavaDoc _initialization;
35
36     private List JavaDoc _externalScripts;
37
38     private IdAllocator _idAllocator = new IdAllocator();
39
40     public void addBodyScript(String JavaDoc script)
41     {
42         if (_body == null)
43             _body = new StringBuffer JavaDoc();
44
45         _body.append(script);
46     }
47
48     public String JavaDoc getBody()
49     {
50         if (_body == null)
51             return null;
52
53         return _body.toString();
54     }
55
56     public void addInitializationScript(String JavaDoc script)
57     {
58         if (_initialization == null)
59             _initialization = new StringBuffer JavaDoc();
60
61         _initialization.append(script);
62     }
63
64     public String JavaDoc getInitialization()
65     {
66         if (_initialization == null)
67             return null;
68
69         return _initialization.toString();
70     }
71
72     public void addExternalScript(Resource scriptResource)
73     {
74         if (_externalScripts == null)
75             _externalScripts = new ArrayList JavaDoc();
76
77         _externalScripts.add(scriptResource);
78     }
79
80     public Resource[] getExternalScripts()
81     {
82         if (_externalScripts == null)
83             return null;
84
85         int count = _externalScripts.size();
86
87         return (Resource[]) _externalScripts.toArray(new Resource[count]);
88     }
89
90     public String JavaDoc getUniqueString(String JavaDoc baseValue)
91     {
92         return _idAllocator.allocateId(baseValue);
93     }
94
95 }
Popular Tags