KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > internal > RequestDirectives


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

20 package org.apache.cactus.internal;
21
22 import org.apache.cactus.WebRequest;
23
24 /**
25  * Encapsulates the Cactus-specific parameters added to a request.
26  *
27  * @version $Id: RequestDirectives.java,v 1.1 2004/05/22 11:34:47 vmassol Exp $
28  */

29 public class RequestDirectives
30 {
31     /**
32      * The WebRequest that the directives modifies.
33      */

34     private WebRequest underlyingRequest;
35
36     /**
37      * @param theRequest The WebRequest to read directives from or
38      * apply directives to.
39      */

40     public RequestDirectives(WebRequest theRequest)
41     {
42         this.underlyingRequest = theRequest;
43     }
44
45     /**
46      * @param theName name of the test class.
47      */

48     public void setClassName(String JavaDoc theName)
49     {
50         addDirective(HttpServiceDefinition.CLASS_NAME_PARAM, theName);
51     }
52
53     /**
54      * @param theName The name of the wrapped test.
55      */

56     public void setWrappedTestName(String JavaDoc theName)
57     {
58         addDirective(HttpServiceDefinition.WRAPPED_CLASS_NAME_PARAM, theName);
59     }
60
61     /**
62      * @param theName name of the test method to execute.
63      */

64     public void setMethodName(String JavaDoc theName)
65     {
66         addDirective(HttpServiceDefinition.METHOD_NAME_PARAM, theName);
67     }
68
69     /**
70      * @param theService The service to request of the redirector.
71      */

72     public void setService(ServiceEnumeration theService)
73     {
74         addDirective(HttpServiceDefinition.SERVICE_NAME_PARAM,
75             theService.toString());
76     }
77
78     /**
79      * @param isAutoSession A "boolean string" indicating
80      * whether or not to use the
81      * autoSession option.
82      */

83     public void setAutoSession(String JavaDoc isAutoSession)
84     {
85         addDirective(HttpServiceDefinition.AUTOSESSION_NAME_PARAM,
86             isAutoSession);
87     }
88
89     /**
90      * Adds a cactus-specific command to the URL of the WebRequest
91      * The URL is used to allow the user to send whatever he wants
92      * in the request body. For example a file, ...
93      *
94      * @param theName The name of the directive to add
95      * @param theValue The directive value
96      * @throws IllegalArgumentException If the directive name is invalid
97      */

98     private void addDirective(String JavaDoc theName, String JavaDoc theValue)
99         throws IllegalArgumentException JavaDoc
100     {
101         if (!theName.startsWith(HttpServiceDefinition.COMMAND_PREFIX))
102         {
103             throw new IllegalArgumentException JavaDoc("Cactus directives must begin"
104                 + " with [" + HttpServiceDefinition.COMMAND_PREFIX
105                 + "]. The offending directive was [" + theName + "]");
106         }
107         underlyingRequest.addParameter(theName, theValue,
108             WebRequest.GET_METHOD);
109     }
110
111 }
112
Popular Tags