Clover Coverage Report - ARESTC 0.1.7-SNAPSHOT
Coverage timestamp: Fri Aug 27 2010 19:12:04 CEST
../../../../img/srcFileCovDistChart7.png 67% of files have more coverage
22   139   11   3.14
2   65   0.5   7
7     1.57  
1    
 
  ARESTConnector       Line # 38 22 0% 11 9 71% 0.7096774
 
  (10)
 
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
8    it under the terms of the Lesser General Public License as published by
9    the Free Software Foundation, either version 3 of the License, or
10    (at your option) any later version.
11   
12    ARESTC is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15    GNU General Public License for more details.
16   
17    You should have received a copy of the Lesser General Public License
18    along with ARESTC. If not, see <http://www.gnu.org/licenses/>.
19   
20    */
21    package net.sf.arestc.core;
22   
23    import java.util.Map;
24   
25    import net.sf.arestc.configuration.CommunicationBuilder;
26    import net.sf.arestc.configuration.ServicesConfigurationFactory;
27    import net.sf.arestc.core.services.RESTService;
28   
29    import org.apache.commons.configuration.ConfigurationException;
30    import org.apache.commons.httpclient.HttpClient;
31    import org.apache.log4j.Logger;
32   
33    /**
34    * The Class ARESTConnector.
35    *
36    * @author georgni
37    */
 
38    public class ARESTConnector {
39   
40    /** The client. */
41    private HttpClient client;
42   
43    /** The type. */
44    private ConnectorTypes type;
45   
46    /** The services. */
47    private Map<String, RESTService> services;
48   
49    /** The Constant LOGGER. */
50    private static final Logger LOGGER = Logger.getLogger(ARESTConnector.class
51    .getName());
52   
53    /**
54    * Instantiates a new aREST connector.
55    *
56    * @param type
57    * the type
58    * @throws ConfigurationException
59    * the configuration exception
60    */
 
61  12 toggle public ARESTConnector(final ConnectorTypes type)
62    throws ConfigurationException {
63  12 try {
64  12 this.type = type;
65  12 services = ServicesConfigurationFactory._instance.configure();
66   
67  12 client = new CommunicationBuilder().getMultithreadedClient();
68    } catch (final ConfigurationException e) {
69  0 LOGGER.error(e);
70  0 throw e;
71    }
72    }
73   
 
74  0 toggle public ARESTConnector(final ConnectorTypes type, final String servicesFile,
75    final String communicationFileName) throws ConfigurationException {
76  0 try {
77  0 this.type = type;
78  0 services = ServicesConfigurationFactory._instance
79    .configure(servicesFile);
80   
81  0 client = new CommunicationBuilder()
82    .getMultithreadedClient(communicationFileName);
83    } catch (final ConfigurationException e) {
84  0 LOGGER.error(e);
85  0 throw e;
86    }
87    }
88   
 
89  1 toggle public HttpClient getClient() {
90  1 return client;
91    }
92   
 
93  1 toggle public Map<String, RESTService> getServices() {
94  1 return services;
95    }
96   
97    /**
98    * Serve.
99    *
100    * @param request
101    * the request
102    * @return the connector response
103    * @throws CommandException
104    * the command exception
105    */
 
106  12 toggle public ConnectorResponse serve(final ConnectorRequest request)
107    throws CommandException {
108  12 if (!services.containsKey(request.getServiceName())
109    && !ConnectorTypes.DUMMY.equals(type)) {
110  1 throw new CommandException("Service does not exist.",
111    new IllegalStateException());
112    }
113  11 final ConnectorContext context = new ConnectorContext(client,
114    services.get(request.getServiceName()));
115  11 final ConnectorCommand firstLink = type.chain(context,
116    request.getStartTransformer(), request.getEndTransformer());
117   
118  11 firstLink.process(request, context);
119   
120  11 return new StandardConnectorResponse(context);
121    }
122   
123    /**
124    * Sets the client.
125    *
126    * @param client
127    * the client to set
128    */
 
129  1 toggle public void setClient(final HttpClient client) {
130  1 this.client = client;
131    }
132   
133    /**
134    * Shutdown.
135    */
 
136  1 toggle public void shutdown() {
137  1 new CommunicationBuilder().shutdownCommunication();
138    }
139    }