Clover Coverage Report - ARESTC 0.1.7-SNAPSHOT
Coverage timestamp: Fri Aug 27 2010 19:12:04 CEST
../../../../img/srcFileCovDistChart9.png 41% of files have more coverage
47   370   30   1.74
6   147   0.64   27
27     1.11  
1    
 
  StandardConnectorRequest       Line # 38 47 0% 30 8 90% 0.9
 
  (18)
 
1    /*
2    *
3    * (C)opyright 2010, Nikolaos Georgosopoulos
4    *
5    * This file is part of ARESTC.
6    *
7    * ARESTC is free software: you can redistribute it and/or modify it under the
8    * terms of the Lesser General Public License as published by the Free Software
9    * Foundation, either version 3 of the License, or (at your option) any later
10    * version.
11    *
12    * ARESTC is distributed in the hope that it will be useful, but WITHOUT ANY
13    * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
14    * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
15    *
16    * You should have received a copy of the Lesser General Public License along
17    * with ARESTC. If not, see <http://www.gnu.org/licenses/>.
18    */
19    package net.sf.arestc.core;
20   
21    import java.util.Collection;
22    import java.util.HashMap;
23    import java.util.Map;
24   
25    import net.sf.arestc.core.bodytransformations.ReturnTransformationTypes;
26    import net.sf.arestc.core.bodytransformations.ReturnTransformer;
27   
28    import org.apache.commons.collections.CollectionUtils;
29    import org.apache.commons.httpclient.Credentials;
30    import org.apache.commons.httpclient.methods.RequestEntity;
31    import org.apache.commons.lang.builder.EqualsBuilder;
32    import org.apache.commons.lang.builder.HashCodeBuilder;
33   
34    // TODO: Auto-generated Javadoc
35    /**
36    * The Class StandardConnectorRequest.
37    */
 
38    public class StandardConnectorRequest implements ConnectorRequest {
39   
40    /** The parameters. */
41    private final Map<String, Object> parameters;
42   
43    /** The service name. */
44    private final String serviceName;
45   
46    /** The start link. */
47    private ConnectorCommand startLink;
48   
49    /** The end link. */
50    private ConnectorCommand endLink;
51   
52    /** The credentials. */
53    private Credentials credentials;
54   
55    /** The return type. */
56    private ReturnTransformationTypes returnType;
57   
58    /** The body. */
59    private RequestEntity body;
60    private final String charset;
61   
62    /**
63    * Instantiates a new standard connector request.
64    *
65    * @param newService
66    * the new service
67    * @param newParameters
68    * the new parameters
69    */
 
70  25 toggle public StandardConnectorRequest(final String newService,
71    final Map<String, Object> newParameters) {
72  25 this(newService, newParameters, ReturnTransformationTypes.NONE, "UTF-8");
73    }
74   
 
75  3 toggle public StandardConnectorRequest(final String newService,
76    final Map<String, Object> newParameters,
77    final ReturnTransformationTypes type) {
78  3 this(newService, newParameters, type, "UTF-8");
79    }
80   
81    /**
82    * Instantiates a new standard connector request.
83    *
84    * @param newService
85    * the new service
86    * @param newParameters
87    * the new parameters
88    * @param type
89    * the type
90    */
 
91  29 toggle public StandardConnectorRequest(final String newService,
92    final Map<String, Object> newParameters,
93    final ReturnTransformationTypes type, final String newCharset) {
94  29 serviceName = newService;
95  29 parameters = newParameters;
96  29 returnType = type;
97  29 charset = newCharset;
98    }
99   
100    /*
101    * (non-Javadoc)
102    *
103    * @see java.lang.Object#equals(java.lang.Object)
104    */
 
105  8 toggle @Override
106    public boolean equals(final Object obj) {
107  8 if (this == obj) {
108  1 return true;
109    }
110  7 if (obj == null) {
111  1 return false;
112    }
113  6 if (getClass() != obj.getClass()) {
114  1 return false;
115    }
116  5 final StandardConnectorRequest other = (StandardConnectorRequest) obj;
117  5 return new EqualsBuilder().append(startLink, other.getStartLink())
118    .append(parameters, other.getParameters())
119    .append(serviceName, other.getServiceName())
120    .append(endLink, other.getEndLink())
121    .append(credentials, other.getCredentials())
122    .append(returnType, other.getReturnType())
123    .append(body, other.getBody()).isEquals();
124    }
125   
126    /*
127    * (non-Javadoc)
128    *
129    * @see net.sf.arestc.core.ConnectorRequest#getBody()
130    */
 
131  9 toggle public RequestEntity getBody() {
132  9 return body;
133    }
134   
135    /*
136    * (non-Javadoc)
137    *
138    * @see
139    * net.sf.arestc.core.ConnectorRequest#getBODYParameters(net.sf.arestc.core
140    * .ConnectorContext)
141    */
 
142  2 toggle public Map<String, Object> getBODYParameters(final ConnectorContext context) {
143  2 final Collection<String> urlParameters = context.getService()
144    .getURLParameters();
145  2 final Collection<String> names = CollectionUtils.disjunction(
146    parameters.keySet(), urlParameters);
147  2 final Map<String, Object> ret = new HashMap<String, Object>(
148    names.size());
149  2 for (final String name : names) {
150  4 ret.put(name, parameters.get(name));
151    }
152   
153  2 return ret;
154    }
155   
156    /**
157    * @return the charset
158    */
 
159  0 toggle public String getCharset() {
160  0 return charset;
161    }
162   
163    /*
164    * (non-Javadoc)
165    *
166    * @see net.sf.arestc.core.ConnectorRequest#getCredentials()
167    */
 
168  21 toggle public Credentials getCredentials() {
169  21 return credentials;
170    }
171   
172    /**
173    * Gets the end link.
174    *
175    * @return the end link
176    */
 
177  18 toggle public ConnectorCommand getEndLink() {
178  18 return endLink;
179    }
180   
181    /*
182    * (non-Javadoc)
183    *
184    * @see net.sf.arestc.core.ConnectorRequest#getEndTransformer()
185    */
 
186  12 toggle public ConnectorCommand getEndTransformer() {
187  12 return getEndLink();
188    }
189   
190    /*
191    * (non-Javadoc)
192    *
193    * @see net.sf.arestc.core.ConnectorRequest#getParameters()
194    */
 
195  33 toggle public Map<String, Object> getParameters() {
196  33 return parameters;
197    }
198   
199    /*
200    * (non-Javadoc)
201    *
202    * @see net.sf.arestc.core.ConnectorRequest#getReturnTransformationType()
203    */
 
204  0 toggle public ReturnTransformationTypes getReturnTransformationType() {
205  0 return getReturnType();
206    }
207   
208    /*
209    * (non-Javadoc)
210    *
211    * @see net.sf.arestc.core.ConnectorRequest#getReturnTransformer()
212    */
 
213  11 toggle public ReturnTransformer getReturnTransformer() {
214  11 return returnType.getReturnTransformer();
215    }
216   
217    /**
218    * Gets the return type.
219    *
220    * @return the return type
221    */
 
222  5 toggle public ReturnTransformationTypes getReturnType() {
223  5 return returnType;
224    }
225   
226    /*
227    * (non-Javadoc)
228    *
229    * @see net.sf.arestc.core.ConnectorRequest#getServiceName()
230    */
 
231  30 toggle public String getServiceName() {
232  30 return serviceName;
233    }
234   
235    /**
236    * Gets the start link.
237    *
238    * @return the start link
239    */
 
240  18 toggle public ConnectorCommand getStartLink() {
241  18 return startLink;
242    }
243   
244    /*
245    * (non-Javadoc)
246    *
247    * @see net.sf.arestc.core.ConnectorRequest#getStartTransformer()
248    */
 
249  12 toggle public ConnectorCommand getStartTransformer() {
250  12 return getStartLink();
251    }
252   
253    /*
254    * (non-Javadoc)
255    *
256    * @see
257    * net.sf.arestc.core.ConnectorRequest#getURLParameters(net.sf.arestc.core
258    * .ConnectorContext)
259    */
 
260  3 toggle public Map<String, Object> getURLParameters(final ConnectorContext context) {
261  3 final Collection<String> urlParameters = context.getService()
262    .getURLParameters();
263  3 final Collection<String> names = CollectionUtils.intersection(
264    urlParameters, parameters.keySet());
265  3 final Map<String, Object> ret = new HashMap<String, Object>(
266    names.size());
267  3 for (final String name : names) {
268  9 ret.put(name, parameters.get(name));
269    }
270  3 return ret;
271    }
272   
273    /*
274    * (non-Javadoc)
275    *
276    * @see java.lang.Object#hashCode()
277    */
 
278  10 toggle @Override
279    public int hashCode() {
280  10 return new HashCodeBuilder().append(startLink).append(parameters)
281    .append(serviceName).append(endLink).toHashCode();
282    }
283   
284    /*
285    * (non-Javadoc)
286    *
287    * @see
288    * net.sf.arestc.core.ConnectorRequest#setBody(org.apache.commons.httpclient
289    * .methods.RequestEntity)
290    */
 
291  3 toggle public void setBody(final RequestEntity body) {
292  3 this.body = body;
293    }
294   
295    /*
296    * (non-Javadoc)
297    *
298    * @see
299    * net.sf.arestc.core.ConnectorRequest#setCredentials(org.apache.commons
300    * .httpclient.Credentials)
301    */
 
302  6 toggle public void setCredentials(final Credentials credentials) {
303  6 this.credentials = credentials;
304    }
305   
306    /**
307    * Sets the end link.
308    *
309    * @param endLink
310    * the new end link
311    */
 
312  3 toggle public void setEndLink(final ConnectorCommand endLink) {
313  3 this.endLink = endLink;
314    }
315   
316    /*
317    * (non-Javadoc)
318    *
319    * @see
320    * net.sf.arestc.core.ConnectorRequest#setEndTransformer(net.sf.arestc.core
321    * .ConnectorCommand)
322    */
 
323  2 toggle public void setEndTransformer(final ConnectorCommand newLink) {
324  2 setEndLink(newLink);
325   
326    }
327   
328    /**
329    * Sets the return transformation type.
330    *
331    * @param type
332    * the new return transformation type
333    */
 
334  0 toggle public void setReturnTransformationType(final ReturnTransformationTypes type) {
335  0 returnType = type;
336    }
337   
338    /**
339    * Sets the return type.
340    *
341    * @param returnType
342    * the new return type
343    */
 
344  0 toggle public void setReturnType(final ReturnTransformationTypes returnType) {
345  0 this.returnType = returnType;
346    }
347   
348    /**
349    * Sets the start link.
350    *
351    * @param startLink
352    * the new start link
353    */
 
354  2 toggle public void setStartLink(final ConnectorCommand startLink) {
355  2 this.startLink = startLink;
356    }
357   
358    /*
359    * (non-Javadoc)
360    *
361    * @see
362    * net.sf.arestc.core.ConnectorRequest#setStartTransformer(net.sf.arestc
363    * .core.ConnectorCommand)
364    */
 
365  1 toggle public void setStartTransformer(final ConnectorCommand newLink) {
366  1 setStartLink(newLink);
367   
368    }
369   
370    }