001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.core.impl;
018:
019: import org.compass.core.CompassException;
020: import org.compass.core.CompassHighlightedText;
021: import org.compass.core.CompassHit;
022: import org.compass.core.CompassHitsOperations;
023: import org.compass.core.Resource;
024:
025: /**
026: * @author kimchy
027: */
028: public class DefaultCompassHit implements CompassHit {
029:
030: private static final long serialVersionUID = 3617578210385408048L;
031:
032: private Resource resource;
033:
034: private Object data;
035:
036: private float score;
037:
038: private boolean resolvedResource;
039:
040: private boolean resolvedData;
041:
042: private CompassHitsOperations compassHits;
043:
044: private int hitNumber;
045:
046: DefaultCompassHit(CompassHitsOperations compassHits, int hitNumber) {
047: this .compassHits = compassHits;
048: this .hitNumber = hitNumber;
049: }
050:
051: public Object getData() {
052: fetchTheData();
053: return data;
054: }
055:
056: public Object data() throws CompassException {
057: return getData();
058: }
059:
060: public Resource getResource() throws CompassException {
061: fetchTheResource();
062: return resource;
063: }
064:
065: public Resource resource() throws CompassException {
066: return getResource();
067: }
068:
069: public float getScore() throws CompassException {
070: fetchTheResource();
071: return score;
072: }
073:
074: public float score() throws CompassException {
075: return getScore();
076: }
077:
078: public CompassHighlightedText getHighlightedText()
079: throws CompassException {
080: return compassHits.highlightedText(hitNumber);
081: }
082:
083: public CompassHighlightedText highlightedText()
084: throws CompassException {
085: return getHighlightedText();
086: }
087:
088: public String getAlias() throws CompassException {
089: fetchTheResource();
090: return resource.getAlias();
091: }
092:
093: public String alias() throws CompassException {
094: return getAlias();
095: }
096:
097: private void fetchTheData() throws CompassException {
098: fetchTheResource();
099: if (!resolvedData) {
100: data = compassHits.data(hitNumber);
101: resolvedData = true;
102: }
103: }
104:
105: private void fetchTheResource() throws CompassException {
106: if (!resolvedResource) {
107: resource = compassHits.resource(hitNumber);
108: score = compassHits.score(hitNumber);
109: resolvedResource = true;
110: }
111: }
112:
113: }
|