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 java.util.Collection;
020: import java.util.HashMap;
021: import java.util.Map;
022: import java.util.Set;
023:
024: import org.compass.core.CompassException;
025: import org.compass.core.spi.InternalCompassHighlightedText;
026:
027: /**
028: * @author kimchy
029: */
030: public class DefaultCompassHighlightedText implements
031: InternalCompassHighlightedText, Map {
032:
033: private HashMap highlightedText = new HashMap();
034:
035: public void setHighlightedText(String propertyName,
036: String highlightedText) {
037: this .highlightedText.put(propertyName, highlightedText);
038: }
039:
040: public String getHighlightedText() throws CompassException {
041: if (highlightedText.size() == 0) {
042: return null;
043: }
044: return (String) highlightedText.values().iterator().next();
045: }
046:
047: public String getHighlightedText(String propertyName)
048: throws CompassException {
049: return (String) highlightedText.get(propertyName);
050: }
051:
052: // methods from the Map interface
053: // ------------------------------
054:
055: public void clear() {
056: throw new UnsupportedOperationException(
057: "Map operations are supported for read operations only");
058: }
059:
060: public boolean containsValue(Object value) {
061: throw new UnsupportedOperationException(
062: "Map operations are supported for read operations only");
063: }
064:
065: public Set entrySet() {
066: return highlightedText.entrySet();
067: }
068:
069: public void putAll(Map t) {
070: throw new UnsupportedOperationException(
071: "Map operations are supported for read operations only");
072: }
073:
074: public Set keySet() {
075: return highlightedText.keySet();
076: }
077:
078: public Object remove(Object key) {
079: throw new UnsupportedOperationException(
080: "Map operations are supported for read operations only");
081: }
082:
083: public Object put(Object key, Object value) {
084: throw new UnsupportedOperationException(
085: "Map operations are supported for read operations only");
086: }
087:
088: public boolean containsKey(Object key) {
089: return highlightedText.containsKey(key);
090: }
091:
092: public int size() {
093: return highlightedText.size();
094: }
095:
096: public boolean isEmpty() {
097: return highlightedText.isEmpty();
098: }
099:
100: public Collection values() {
101: return highlightedText.values();
102: }
103:
104: public Object get(Object key) {
105: return highlightedText.get(key);
106: }
107:
108: }
|