View Javadoc

1   /**
2    * Copyright (C) 2005-2009 Alfresco Software Limited.
3    *
4    * This file is part of the Spring Surf Extension project.
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  package org.springframework.extensions.webscripts.connector;
20  
21  import java.util.Collections;
22  import java.util.HashMap;
23  import java.util.Map;
24  
25  /**
26   * Describes invocation context that the connector should consider
27   * when creating the connection to the remote service.
28   * 
29   * Invocation context consists of HTTP request state such as
30   * fixed parameters and headers.
31   * 
32   * @author Uzquiano
33   */
34  public final class ConnectorContext
35  {
36      /** The parameters. */
37      private Map<String, String> parameters = Collections.<String, String>emptyMap();
38      
39      /** The headers. */
40      private Map<String, String> headers = Collections.<String, String>emptyMap();
41      
42      /** The content type. */
43      private String contentType;
44      
45      /** The method. */
46      private HttpMethod method = HttpMethod.GET;
47      
48      
49      /**
50       * Instantiates a new connector context.
51       */
52      public ConnectorContext()
53      {
54          this(null, null, null);
55      }
56      
57      /**
58       * Instantiates a new connector context.
59       * 
60       * @param parameters the parameters
61       * @param headers the headers
62       */
63      public ConnectorContext(Map<String, String> parameters, Map<String, String> headers)
64      {
65          this(null, parameters, headers);
66      }
67      
68      /**
69       * Instantiates a new connector context.
70       * 
71       * @param method the HTTP method
72       */
73      public ConnectorContext(HttpMethod method)
74      {
75          if (method != null)
76          {
77              this.method = method;
78          }
79      }
80  
81      /**
82       * Instantiates a new connector context.
83       * 
84       * @param method the HTTP method
85       * @param parameters the parameters
86       * @param headers the headers
87       */
88      public ConnectorContext(HttpMethod method, Map<String, String> parameters, Map<String, String> headers)
89      {
90          if (method != null)
91          {
92              this.method = method;
93          }
94          if (parameters != null)
95          {
96              this.parameters = new HashMap<String, String>(parameters.size());
97              this.parameters.putAll(parameters);
98          }
99          if (headers != null)
100         {
101             this.headers = new HashMap<String, String>(headers.size());
102             this.headers.putAll(headers);
103         }
104     }
105     
106     /**
107      * Gets the parameters.
108      * 
109      * @return the parameters
110      */
111     public Map<String, String> getParameters()
112     {
113         return this.parameters;
114     }
115     
116     /**
117      * Gets the headers.
118      * 
119      * @return the headers
120      */
121     public Map<String, String> getHeaders()
122     {
123         return this.headers;
124     }
125     
126     /**
127      * Gets the content type.
128      * 
129      * @return the content type
130      */
131     public String getContentType()
132     {
133         return this.contentType;
134     }
135     
136     /**
137      * Sets the content type.
138      * 
139      * @param contentType the new content type
140      */
141     public void setContentType(String contentType)
142     {
143         this.contentType = contentType;
144     }
145     
146     /**
147      * Gets the method.
148      * 
149      * @return the method
150      */
151     public HttpMethod getMethod()
152     {
153         return this.method;
154     }
155     
156     /**
157      * Sets the method.
158      * 
159      * @param method the new method
160      */
161     public void setMethod(HttpMethod method)
162     {
163         if (method != null)
164         {
165             this.method = method;
166         }
167     }
168 }