source: SRUAggregator/trunk/src/main/java/eu/clarin/sru/fcs/aggregator/sparam2/SearchResult2.java @ 2926

Last change on this file since 2926 was 2926, checked in by yana, 11 years ago

rebuilding the interface - initial version, still not functional!

File size: 2.5 KB
Line 
1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5package eu.clarin.sru.fcs.aggregator.sparam2;
6
7import eu.clarin.sru.client.SRUSearchRetrieveResponse;
8import eu.clarin.sru.client.fcs.DataViewKWIC;
9import java.util.ArrayList;
10import java.util.List;
11import java.util.concurrent.Future;
12import java.util.logging.Level;
13import java.util.logging.Logger;
14
15/**
16 * Represents the results of a SRU search-retrieve operation request. It
17 * contains the endpoint and corpus (if specified in the request) to which a
18 * request was sent, and the corresponding SRU search-retrieve response.
19 *
20 * @author Yana Panchenko
21 */
22public class SearchResult2 {
23
24    //private Endpoint endpoint;
25    private Corpus2 corpus;
26    private Future<SRUSearchRetrieveResponse> futureResponse;
27    private SRUSearchRetrieveResponse response;
28    private List<DataViewKWIC> dataKWIC = new ArrayList<DataViewKWIC>();
29   
30    private static final Logger logger = Logger.getLogger(SearchResult2.class.getName());
31
32    public List<DataViewKWIC> getDataKWIC() {
33        return dataKWIC;
34    }
35
36    public void addKWIC(DataViewKWIC kw) {
37        this.dataKWIC.add(kw);
38    }
39   
40
41    public SearchResult2(Corpus2 corpus) {
42        this.corpus = corpus;
43    }
44
45    public Corpus2 getCorpus() {
46        return corpus;
47    }
48
49    public void setFutureResponse(Future<SRUSearchRetrieveResponse> futureResponse) {
50        this.futureResponse = futureResponse;
51    }
52
53    public void setResponse(SRUSearchRetrieveResponse response) {
54        this.response = response;
55    }
56
57    public SRUSearchRetrieveResponse getResponse() {
58        return response;
59    }
60
61    public boolean hasCorpusHandler() {
62        if (corpus != null && corpus.getHandle() != null) {
63            return true;
64        }
65        return false;
66    }
67
68    public void cancelWaitingForResponse() {
69        futureResponse.cancel(true);
70    }
71
72    public boolean isWaitingForResponse() {
73        if (futureResponse == null) {
74            return false;
75        } else if (futureResponse.isDone()) {
76            return false;
77        } else {
78            return true;
79        }
80    }
81
82    public void consumeResponse() {
83
84        try {
85            if (futureResponse != null) {
86                response = futureResponse.get();
87            }
88        } catch (Exception ex) {
89            logger.log(Level.SEVERE, "Error consuming response from {0} {1} {2} {3}", 
90                    new Object[]{corpus.getEndpointUrl(), corpus, ex.getClass().getName(), ex.getMessage()});
91        }
92    }
93}
Note: See TracBrowser for help on using the repository browser.