001: /*
002: * ========================================================================
003: *
004: * Copyright 2003-2004 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.internal;
021:
022: import org.apache.cactus.WebRequest;
023:
024: /**
025: * Encapsulates the Cactus-specific parameters added to a request.
026: *
027: * @version $Id: RequestDirectives.java 238991 2004-05-22 11:34:50Z vmassol $
028: */
029: public class RequestDirectives {
030: /**
031: * The WebRequest that the directives modifies.
032: */
033: private WebRequest underlyingRequest;
034:
035: /**
036: * @param theRequest The WebRequest to read directives from or
037: * apply directives to.
038: */
039: public RequestDirectives(WebRequest theRequest) {
040: this .underlyingRequest = theRequest;
041: }
042:
043: /**
044: * @param theName name of the test class.
045: */
046: public void setClassName(String theName) {
047: addDirective(HttpServiceDefinition.CLASS_NAME_PARAM, theName);
048: }
049:
050: /**
051: * @param theName The name of the wrapped test.
052: */
053: public void setWrappedTestName(String theName) {
054: addDirective(HttpServiceDefinition.WRAPPED_CLASS_NAME_PARAM,
055: theName);
056: }
057:
058: /**
059: * @param theName name of the test method to execute.
060: */
061: public void setMethodName(String theName) {
062: addDirective(HttpServiceDefinition.METHOD_NAME_PARAM, theName);
063: }
064:
065: /**
066: * @param theService The service to request of the redirector.
067: */
068: public void setService(ServiceEnumeration theService) {
069: addDirective(HttpServiceDefinition.SERVICE_NAME_PARAM,
070: theService.toString());
071: }
072:
073: /**
074: * @param isAutoSession A "boolean string" indicating
075: * whether or not to use the
076: * autoSession option.
077: */
078: public void setAutoSession(String isAutoSession) {
079: addDirective(HttpServiceDefinition.AUTOSESSION_NAME_PARAM,
080: isAutoSession);
081: }
082:
083: /**
084: * Adds a cactus-specific command to the URL of the WebRequest
085: * The URL is used to allow the user to send whatever he wants
086: * in the request body. For example a file, ...
087: *
088: * @param theName The name of the directive to add
089: * @param theValue The directive value
090: * @throws IllegalArgumentException If the directive name is invalid
091: */
092: private void addDirective(String theName, String theValue)
093: throws IllegalArgumentException {
094: if (!theName.startsWith(HttpServiceDefinition.COMMAND_PREFIX)) {
095: throw new IllegalArgumentException(
096: "Cactus directives must begin" + " with ["
097: + HttpServiceDefinition.COMMAND_PREFIX
098: + "]. The offending directive was ["
099: + theName + "]");
100: }
101: underlyingRequest.addParameter(theName, theValue,
102: WebRequest.GET_METHOD);
103: }
104:
105: }
|