View Javadoc

1   /*
2    * #%L
3    * Bitrepository Reference Pillar
4    * %%
5    * Copyright (C) 2010 - 2012 The State and University Library, The Royal Library and The State Archives, Denmark
6    * %%
7    * This program is free software: you can redistribute it and/or modify
8    * it under the terms of the GNU Lesser General Public License as 
9    * published by the Free Software Foundation, either version 2.1 of the 
10   * License, or (at your option) any later version.
11   * 
12   * This program 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 Lesser Public License for more details.
16   * 
17   * You should have received a copy of the GNU General Lesser Public 
18   * License along with this program.  If not, see
19   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
20   * #L%
21   */
22  package org.bitrepository.service.contributor.handler;
23  
24  import org.bitrepository.bitrepositoryelements.ResponseInfo;
25  import org.bitrepository.bitrepositorymessages.IdentifyContributorsForGetAuditTrailsRequest;
26  import org.bitrepository.bitrepositorymessages.IdentifyContributorsForGetAuditTrailsResponse;
27  import org.bitrepository.bitrepositorymessages.MessageResponse;
28  import org.bitrepository.common.ArgumentValidator;
29  import org.bitrepository.common.utils.ResponseInfoUtils;
30  import org.bitrepository.service.contributor.ContributorContext;
31  
32  /**
33   * Class for handling the identification of this pillar for the purpose of performing the GetStatus operation.
34   */
35  public class IdentifyContributorsForGetAuditTrailsRequestHandler 
36          extends AbstractRequestHandler<IdentifyContributorsForGetAuditTrailsRequest> {
37      /**
38       * Constructor.
39       * @param context The context of the message handler.
40       */
41      public IdentifyContributorsForGetAuditTrailsRequestHandler(ContributorContext context) {
42          super(context);
43      }
44  
45      @Override
46      public Class<IdentifyContributorsForGetAuditTrailsRequest> getRequestClass() {
47          return IdentifyContributorsForGetAuditTrailsRequest.class;
48      }
49  
50      @Override
51      public void processRequest(IdentifyContributorsForGetAuditTrailsRequest message) {
52          ArgumentValidator.checkNotNull(message, "IdentifyContributorsForGetAuditTrailsRequest message");
53  
54          respondSuccessfulIdentification(message);
55      }
56  
57      @Override
58      public MessageResponse generateFailedResponse(IdentifyContributorsForGetAuditTrailsRequest request) {
59          return createResponse();
60      }
61      
62      /**
63       * Makes a success response for the identification.
64       * @param request The request to base the response upon.
65       */
66      protected void respondSuccessfulIdentification(IdentifyContributorsForGetAuditTrailsRequest request) {
67          IdentifyContributorsForGetAuditTrailsResponse response = createResponse();
68          response.setResponseInfo(ResponseInfoUtils.getPositiveIdentification());
69          getContext().getResponseDispatcher().dispatchResponse(response, request);
70      }
71      
72      /**
73       * Sends a bad response with the given cause.
74       * @param request The identification request to respond to.
75       * @param responseInfo The cause of the bad identification (e.g. which file is missing).
76       */
77      protected void respondFailedIdentification(IdentifyContributorsForGetAuditTrailsRequest request,
78              ResponseInfo responseInfo) {
79          IdentifyContributorsForGetAuditTrailsResponse response = createResponse();
80          
81          response.setResponseInfo(responseInfo);
82          getContext().getResponseDispatcher().dispatchResponse(response, request);
83      }
84      
85      /**
86       * Creates a IdentifyContributorsForGetAuditTrailsResponse based on a
87       * IdentifyContributorsForGetAuditTrailsResponse. The following fields are not inserted:
88       * <br/> - ResponseInfo
89       *
90       * @return The response to the request.
91       */
92      protected IdentifyContributorsForGetAuditTrailsResponse createResponse() {
93          IdentifyContributorsForGetAuditTrailsResponse res = new IdentifyContributorsForGetAuditTrailsResponse();
94          return res;
95      }
96  }