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.engine;
018:
019: import org.compass.core.Property;
020: import org.compass.core.config.CompassEnvironment;
021: import org.compass.core.engine.naming.PropertyPath;
022: import org.compass.core.engine.subindex.ConstantSubIndexHash;
023: import org.compass.core.engine.subindex.SubIndexHash;
024: import org.compass.core.mapping.AbstractMultipleMapping;
025: import org.compass.core.mapping.AliasMapping;
026: import org.compass.core.mapping.AllMapping;
027: import org.compass.core.mapping.BoostPropertyMapping;
028: import org.compass.core.mapping.CascadeMapping;
029: import org.compass.core.mapping.Mapping;
030: import org.compass.core.mapping.ResourceAnalyzerController;
031: import org.compass.core.mapping.ResourceIdMappingProvider;
032: import org.compass.core.mapping.ResourcePropertyMapping;
033: import org.compass.core.mapping.SpellCheckType;
034: import org.compass.core.mapping.internal.DefaultAllMapping;
035: import org.compass.core.mapping.internal.InternalAllMapping;
036: import org.compass.core.mapping.internal.InternalResourceMapping;
037: import org.compass.core.util.config.ConfigurationHelper;
038:
039: /**
040: * @author kimchy
041: */
042: public class MockResourceMapping extends AbstractMultipleMapping
043: implements InternalResourceMapping, AliasMapping {
044:
045: public String[] getExtendingAliases() {
046: return extendingAliases;
047: }
048:
049: public void setExtendingAliases(String[] extendingAliases) {
050: this .extendingAliases = extendingAliases;
051: }
052:
053: private class MockResourceIdMapping implements
054: ResourceIdMappingProvider {
055: private ResourcePropertyMapping[] ids = new ResourcePropertyMapping[0];
056:
057: public void addId(ResourcePropertyMapping id) {
058: ResourcePropertyMapping[] result = new ResourcePropertyMapping[ids.length + 1];
059: int i = 0;
060: for (i = 0; i < ids.length; i++)
061: result[i] = ids[i];
062: result[i] = id;
063: ids = result;
064: }
065:
066: public Mapping[] getIdMappings() {
067: return ids;
068: }
069:
070: public ResourcePropertyMapping[] getResourceIdMappings() {
071: return ids;
072: }
073: }
074:
075: private String alias;
076:
077: private String[] extendedAliases = new String[0];
078:
079: private String[] extendingAliases = new String[0];
080:
081: private float boost = 1.0f;
082:
083: private SubIndexHash subIndexHash;
084:
085: private AllMapping allMapping = new DefaultAllMapping();
086:
087: private MockResourceIdMapping idMapping = new MockResourceIdMapping();
088:
089: public MockResourceMapping(String alias) {
090: this .alias = alias;
091: ((InternalAllMapping) allMapping).setExcludeAlias(false);
092: ((InternalAllMapping) allMapping).setOmitNorms(false);
093: ((InternalAllMapping) allMapping).setSupported(true);
094: ((InternalAllMapping) allMapping)
095: .setProperty(CompassEnvironment.All.DEFAULT_NAME);
096: ((InternalAllMapping) allMapping)
097: .setTermVector(Property.TermVector.NO);
098: }
099:
100: public AliasMapping shallowCopy() {
101: return new MockResourceMapping(alias);
102: }
103:
104: public void addId(ResourcePropertyMapping id) {
105: idMapping.addId(id);
106: }
107:
108: public Mapping[] getIdMappings() {
109: return idMapping.getIdMappings();
110: }
111:
112: public ResourcePropertyMapping[] getResourceIdMappings() {
113: return idMapping.getResourceIdMappings();
114: }
115:
116: public SubIndexHash getSubIndexHash() {
117: if (this .subIndexHash != null) {
118: return this .subIndexHash;
119: }
120: return new ConstantSubIndexHash(getAlias());
121: }
122:
123: public boolean isIncludePropertiesWithNoMappingsInAll() {
124: return true;
125: }
126:
127: public String getAlias() {
128: return alias;
129: }
130:
131: public void setAlias(String alias) {
132: this .alias = alias;
133: }
134:
135: public float getBoost() {
136: return boost;
137: }
138:
139: public void setBoost(float boost) {
140: this .boost = boost;
141: }
142:
143: public Mapping copy() {
144: return null;
145: }
146:
147: public boolean isRoot() {
148: return true;
149: }
150:
151: public String getAllProperty() {
152: return null;
153: }
154:
155: public Boolean isAllSupported() {
156: return true;
157: }
158:
159: public String[] getExtendedAliases() {
160: return extendedAliases;
161: }
162:
163: public void setExtendedAliases(String[] extendedMappings) {
164: this .extendedAliases = extendedMappings;
165: }
166:
167: public void setSubIndexHash(SubIndexHash subIndexHash) {
168: this .subIndexHash = subIndexHash;
169: }
170:
171: public Property.TermVector getAllTermVector() {
172: return Property.TermVector.NO;
173: }
174:
175: public ConfigurationHelper getConfiguration() {
176: return null;
177: }
178:
179: public ResourcePropertyMapping[] getResourcePropertyMappings() {
180: return new ResourcePropertyMapping[0];
181: }
182:
183: public String getAnalyzer() {
184: return null;
185: }
186:
187: public boolean hasSpecificAnalyzerPerResourceProperty() {
188: return false;
189: }
190:
191: public ResourcePropertyMapping getResourcePropertyMapping(
192: String propertyName) {
193: return null;
194: }
195:
196: public ResourcePropertyMapping getResourcePropertyMappingByPath(
197: PropertyPath path) {
198: return null;
199: }
200:
201: public ResourcePropertyMapping[] getResourcePropertyMappings(
202: String propertyName) {
203: return new ResourcePropertyMapping[0];
204: }
205:
206: public String getAllAnalyzer() {
207: return null;
208: }
209:
210: public ResourceAnalyzerController getAnalyzerController() {
211: return null;
212: }
213:
214: public BoostPropertyMapping getBoostPropertyMapping() {
215: return null;
216: }
217:
218: public String[] getResourcePropertyNames() {
219: return new String[0];
220: }
221:
222: public ResourcePropertyMapping getResourcePropertyMappingByDotPath(
223: String path) {
224: return null;
225: }
226:
227: public CascadeMapping[] getCascadeMappings() {
228: return null;
229: }
230:
231: public boolean operationAllowed(CascadeMapping.Cascade cascade) {
232: return isRoot();
233: }
234:
235: public boolean isAllOmitNorms() {
236: return false;
237: }
238:
239: public boolean isExcludeAliasFromAll() {
240: return true;
241: }
242:
243: public void setUIDPath(String uid) {
244: throw new IllegalStateException(
245: "Should not be called, just for testing");
246: }
247:
248: public String getUIDPath() {
249: return "$uid";
250: }
251:
252: public void setAnalyzer(String analyzer) {
253: }
254:
255: public AllMapping getAllMapping() {
256: return allMapping;
257: }
258:
259: public void setAllMapping(AllMapping allMapping) {
260: this .allMapping = allMapping;
261: }
262:
263: public void setSpellCheck(SpellCheckType spellCheck) {
264: }
265:
266: public SpellCheckType getSpellCheck() {
267: return SpellCheckType.NA;
268: }
269: }
|