| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| MethodFactory |
|
| 3.0;3 |
| 1 | /* | |
| 2 | * Copyright 1999-2002,2004 The Apache Software Foundation. | |
| 3 | * | |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | * you may not use this file except in compliance with the License. | |
| 6 | * You may obtain a copy of the License at | |
| 7 | * | |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | * | |
| 10 | * Unless required by applicable law or agreed to in writing, software | |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | * See the License for the specific language governing permissions and | |
| 14 | * limitations under the License. | |
| 15 | */ | |
| 16 | package org.apache.commons.latka.http; | |
| 17 | ||
| 18 | import java.net.URL; | |
| 19 | ||
| 20 | import org.apache.commons.httpclient.HttpMethod; | |
| 21 | import org.apache.commons.httpclient.methods.GetMethod; | |
| 22 | import org.apache.commons.httpclient.methods.PostMethod; | |
| 23 | import org.apache.commons.httpclient.methods.HeadMethod; | |
| 24 | ||
| 25 | /** | |
| 26 | * This factory provides a single point to obtain | |
| 27 | * implementations of HttpMethod base. | |
| 28 | * | |
| 29 | * @version $Revision $ | |
| 30 | */ | |
| 31 | public final class MethodFactory { | |
| 32 | ||
| 33 | /** | |
| 34 | * Private default constructor | |
| 35 | */ | |
| 36 | 0 | private MethodFactory() { |
| 37 | 0 | } |
| 38 | ||
| 39 | /** | |
| 40 | * Creates and returns an object implementing the | |
| 41 | * HttpMethod interface. | |
| 42 | * | |
| 43 | * @param method - method type to create | |
| 44 | * @return HttpMethod instance | |
| 45 | */ | |
| 46 | public static HttpMethod getInstance(int method, URL url) { | |
| 47 | 0 | HttpMethod httpMethod = null; |
| 48 | 0 | switch (method) { |
| 49 | case Request.HTTP_METHOD_GET: | |
| 50 | 0 | httpMethod = new GetMethod(url.getPath()); |
| 51 | 0 | break; |
| 52 | case Request.HTTP_METHOD_POST: | |
| 53 | 0 | httpMethod = new PostMethod(url.getPath()); |
| 54 | 0 | break; |
| 55 | case Request.HTTP_METHOD_HEAD: | |
| 56 | 0 | httpMethod = new HeadMethod(url.getPath()); |
| 57 | 0 | break; |
| 58 | default: | |
| 59 | 0 | throw new IllegalArgumentException("Unsupported HTTP Method"); |
| 60 | } | |
| 61 | 0 | return httpMethod; |
| 62 | } | |
| 63 | } | |
| 64 |