1 /*
2 * ========================================================================
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one or more
5 * contributor license agreements. See the NOTICE file distributed with
6 * this work for additional information regarding copyright ownership.
7 * The ASF licenses this file to You under the Apache License, Version 2.0
8 * (the "License"); you may not use this file except in compliance with
9 * the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 * ========================================================================
20 */
21 package org.apache.cactus.internal;
22
23 import org.apache.cactus.WebRequest;
24
25 /**
26 * Encapsulates the Cactus-specific parameters added to a request.
27 *
28 * @version $Id: RequestDirectives.java 238991 2004-05-22 11:34:50Z vmassol $
29 */
30 public class RequestDirectives
31 {
32 /**
33 * The WebRequest that the directives modifies.
34 */
35 private WebRequest underlyingRequest;
36
37 /**
38 * @param theRequest The WebRequest to read directives from or
39 * apply directives to.
40 */
41 public RequestDirectives(WebRequest theRequest)
42 {
43 this.underlyingRequest = theRequest;
44 }
45
46 /**
47 * @param theName name of the test class.
48 */
49 public void setClassName(String theName)
50 {
51 addDirective(HttpServiceDefinition.CLASS_NAME_PARAM, theName);
52 }
53
54 /**
55 * @param theName The name of the wrapped test.
56 */
57 public void setWrappedTestName(String theName)
58 {
59 addDirective(HttpServiceDefinition.WRAPPED_CLASS_NAME_PARAM, theName);
60 }
61
62 /**
63 * @param theName name of the test method to execute.
64 */
65 public void setMethodName(String theName)
66 {
67 addDirective(HttpServiceDefinition.METHOD_NAME_PARAM, theName);
68 }
69
70 /**
71 * @param theService The service to request of the redirector.
72 */
73 public void setService(ServiceEnumeration theService)
74 {
75 addDirective(HttpServiceDefinition.SERVICE_NAME_PARAM,
76 theService.toString());
77 }
78
79 /**
80 * @param isAutoSession A "boolean string" indicating
81 * whether or not to use the
82 * autoSession option.
83 */
84 public void setAutoSession(String isAutoSession)
85 {
86 addDirective(HttpServiceDefinition.AUTOSESSION_NAME_PARAM,
87 isAutoSession);
88 }
89
90 /**
91 * Adds a cactus-specific command to the URL of the WebRequest
92 * The URL is used to allow the user to send whatever he wants
93 * in the request body. For example a file, ...
94 *
95 * @param theName The name of the directive to add
96 * @param theValue The directive value
97 * @throws IllegalArgumentException If the directive name is invalid
98 */
99 private void addDirective(String theName, String theValue)
100 throws IllegalArgumentException
101 {
102 if (!theName.startsWith(HttpServiceDefinition.COMMAND_PREFIX))
103 {
104 throw new IllegalArgumentException("Cactus directives must begin"
105 + " with [" + HttpServiceDefinition.COMMAND_PREFIX
106 + "]. The offending directive was [" + theName + "]");
107 }
108 underlyingRequest.addParameter(theName, theValue,
109 WebRequest.GET_METHOD);
110 }
111
112 }