View Javadoc

1   /*
2    * #%L
3    * bitrepository-access-client
4    * *
5    * $Id$
6    * $HeadURL$
7    * %%
8    * Copyright (C) 2010 - 2011 The State and University Library, The Royal Library and The State Archives, Denmark
9    * %%
10   * This program is free software: you can redistribute it and/or modify
11   * it under the terms of the GNU Lesser General Public License as 
12   * published by the Free Software Foundation, either version 2.1 of the 
13   * License, or (at your option) any later version.
14   * 
15   * This program is distributed in the hope that it will be useful,
16   * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18   * GNU General Lesser Public License for more details.
19   * 
20   * You should have received a copy of the GNU General Lesser Public 
21   * License along with this program.  If not, see
22   * <http://www.gnu.org/licenses/lgpl-2.1.html>.
23   * #L%
24   */
25  package org.bitrepository.pillar.checksumpillar.messagehandler;
26  
27  import org.bitrepository.bitrepositoryelements.ResponseCode;
28  import org.bitrepository.bitrepositoryelements.ResponseInfo;
29  import org.bitrepository.bitrepositorymessages.IdentifyPillarsForGetFileRequest;
30  import org.bitrepository.bitrepositorymessages.IdentifyPillarsForGetFileResponse;
31  import org.bitrepository.bitrepositorymessages.MessageResponse;
32  import org.bitrepository.pillar.cache.ChecksumStore;
33  import org.bitrepository.pillar.common.MessageHandlerContext;
34  import org.bitrepository.service.exception.InvalidMessageException;
35  import org.bitrepository.service.exception.RequestHandlerException;
36  
37  /**
38   * Class for handling the identification of this pillar for the purpose of performing the GetFile operation.
39   */
40  public class IdentifyPillarsForGetFileRequestHandler extends ChecksumPillarMessageHandler<IdentifyPillarsForGetFileRequest> {
41      /**
42       * Constructor.
43       * @param context The context of the message handler.
44       * @param refCache The cache for the checksum data.
45       */
46      public IdentifyPillarsForGetFileRequestHandler(MessageHandlerContext context, ChecksumStore refCache) {
47          super(context, refCache);
48      }
49      
50      @Override
51      public Class<IdentifyPillarsForGetFileRequest> getRequestClass() {
52          return IdentifyPillarsForGetFileRequest.class;
53      }
54  
55      @Override
56      public void processRequest(IdentifyPillarsForGetFileRequest message) throws RequestHandlerException {
57          ResponseInfo ri = new ResponseInfo();
58          ri.setResponseCode(ResponseCode.REQUEST_NOT_SUPPORTED);
59          ri.setResponseText("The ChecksumPillar '" 
60                  + getSettings().getReferenceSettings().getPillarSettings().getPillarID() + "' cannot handle a "
61                  + "request for the actual file, since it only contains the checksum of the file.");
62          
63          throw new InvalidMessageException(ri, message.getCollectionID());
64      }
65  
66      @Override
67      public MessageResponse generateFailedResponse(IdentifyPillarsForGetFileRequest message) {
68          return createFinalResponse(message);
69      }
70      
71      /**
72       * Creates a IdentifyPillarsForGetFileResponse based on a 
73       * IdentifyPillarsForGetFileRequest. The following fields are not inserted:
74       * <br/> - TimeToDeliver
75       * <br/> - AuditTrailInformation
76       * <br/> - IdentifyResponseInfo
77       * 
78       * @param request The IdentifyPillarsForGetFileRequest to base the response on.
79       * @return The response to the request.
80       */
81      private IdentifyPillarsForGetFileResponse createFinalResponse(IdentifyPillarsForGetFileRequest request) {
82          IdentifyPillarsForGetFileResponse res = new IdentifyPillarsForGetFileResponse();
83          res.setFileID(request.getFileID());
84          res.setPillarID(getSettings().getReferenceSettings().getPillarSettings().getPillarID());
85          
86          return res;
87      }
88  }