KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tapestry > test > ScriptDescriptor


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.test;
16
17 import java.util.ArrayList JavaDoc;
18 import java.util.HashMap JavaDoc;
19 import java.util.List JavaDoc;
20 import java.util.Map JavaDoc;
21
22 import org.apache.hivemind.ApplicationRuntimeException;
23 import org.apache.hivemind.impl.BaseLocatable;
24
25 /**
26  * Top level object for test scripts.
27  *
28  * @author Howard Lewis Ship
29  * @since 4.0
30  */

31 public class ScriptDescriptor extends BaseLocatable
32 {
33     private String JavaDoc _contextName;
34     private String JavaDoc _rootDirectory;
35
36     private Map JavaDoc _servletDescriptors = new HashMap JavaDoc();
37     private List JavaDoc _requests = new ArrayList JavaDoc();
38
39     private ServletDescriptor _defaultServletDescriptor;
40
41     public String JavaDoc getContextName()
42     {
43         return _contextName;
44     }
45
46     public String JavaDoc getRootDirectory()
47     {
48         return _rootDirectory;
49     }
50
51     public void setContextName(String JavaDoc string)
52     {
53         _contextName = string;
54     }
55
56     public void setRootDirectory(String JavaDoc string)
57     {
58         _rootDirectory = string;
59     }
60
61     /**
62      * Gets the named servlet descriptor, or returns null.
63      */

64     public ServletDescriptor getServletDescriptor(String JavaDoc name)
65     {
66         return (ServletDescriptor) _servletDescriptors.get(name);
67     }
68
69     /**
70      * Adds a new ServletDescriptor to the script.
71      *
72      * @throws ApplicationRuntimeException if the descriptor's name
73      * duplicates an existing descriptor
74      */

75     public void addServletDescriptor(ServletDescriptor sd)
76     {
77         String JavaDoc name = sd.getName();
78
79         ServletDescriptor existing = getServletDescriptor(name);
80
81         if (existing != null)
82             throw new ApplicationRuntimeException(
83                 "Servlet descriptor '"
84                     + name
85                     + "' (at "
86                     + sd.getLocation()
87                     + ") conflicts with prior instance at "
88                     + existing.getLocation()
89                     + ".",
90                 sd.getLocation(),
91                 null);
92
93         _servletDescriptors.put(name, sd);
94
95         if (_defaultServletDescriptor == null)
96             _defaultServletDescriptor = sd;
97     }
98
99     public void addRequestDescriptor(RequestDescriptor rd)
100     {
101         _requests.add(rd);
102     }
103
104     /**
105      * @return List of {@link RequestDescriptor}
106      * @see #addRequestDescriptor(RequestDescriptor)
107      */

108     public List JavaDoc getRequestDescriptors()
109     {
110         return _requests;
111     }
112     
113     public ServletDescriptor getDefaultServletDescriptor()
114     {
115         return _defaultServletDescriptor;
116     }
117
118 }
119
Popular Tags