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.mapping.osem;
018:
019: import org.compass.core.Property;
020: import org.compass.core.converter.Converter;
021: import org.compass.core.mapping.Mapping;
022: import org.compass.core.mapping.OverrideByNameMapping;
023: import org.compass.core.mapping.ResourcePropertyMapping;
024: import org.compass.core.util.Parameter;
025:
026: /**
027: * @author kimchy
028: */
029: public class ClassPropertyMapping extends
030: AbstractAccessorMultipleMapping implements
031: OverrideByNameMapping {
032:
033: private static final int ID_NOT_SET_VALUE = -1;
034:
035: public static final class ManagedId extends Parameter {
036:
037: private static final long serialVersionUID = -7849904473959816389L;
038:
039: private ManagedId(String name) {
040: super (name);
041: }
042:
043: /**
044: * The meta-data (resource-property) that will act as the id will be
045: * computed automatically.
046: */
047: public static final ManagedId AUTO = new ManagedId("AUTO");
048:
049: /**
050: * The class property will always have an internal managed id that will
051: * be created.
052: */
053: public static final ManagedId TRUE = new ManagedId("TRUE");
054:
055: /**
056: * The class property will not have an internal managed id, the
057: * meta-data that will be used as an id will be the first one.
058: */
059: public static final ManagedId FALSE = new ManagedId("FALSE");
060:
061: /**
062: * The class proeprty will not create an internal managed id if
063: * all its meta data mappings have store=no
064: */
065: public static final ManagedId NO_STORE = new ManagedId(
066: "NO_STORE");
067:
068: /**
069: * The class property will not have any internal meta-data id, causing
070: * it not to be unmarshalled at all.
071: */
072: public static final ManagedId NO = new ManagedId("NO");
073:
074: public static String toString(ManagedId managedId) {
075: if (managedId == ManagedId.AUTO) {
076: return "auto";
077: } else if (managedId == ManagedId.TRUE) {
078: return "true";
079: } else if (managedId == ManagedId.FALSE) {
080: return "false";
081: } else if (managedId == ManagedId.NO_STORE) {
082: return "no_store";
083: } else if (managedId == ManagedId.NO) {
084: return "no";
085: }
086: throw new IllegalArgumentException(
087: "Can't find managed-id for [" + managedId + "]");
088: }
089:
090: public static ManagedId fromString(String managedId) {
091: if ("auto".equalsIgnoreCase(managedId)) {
092: return ManagedId.AUTO;
093: } else if ("true".equalsIgnoreCase(managedId)) {
094: return ManagedId.TRUE;
095: } else if ("false".equalsIgnoreCase(managedId)) {
096: return ManagedId.FALSE;
097: } else if ("no_store".equalsIgnoreCase(managedId)) {
098: return ManagedId.NO_STORE;
099: } else if ("no".equalsIgnoreCase(managedId)) {
100: return ManagedId.NO;
101: }
102: throw new IllegalArgumentException(
103: "Can't find managed-id for [" + managedId + "]");
104: }
105:
106: }
107:
108: private String className;
109:
110: private float boost;
111:
112: private int idPropertyIndex = ID_NOT_SET_VALUE;
113:
114: private ManagedId managedId;
115:
116: private Converter managedIdConverter;
117:
118: private String managedIdConverterName;
119:
120: private ResourcePropertyMapping.ExcludeFromAllType excludeFromAll = ResourcePropertyMapping.ExcludeFromAllType.NO;
121:
122: private String analyzer;
123:
124: private boolean overrideByName = true;
125:
126: private Property.Index managedIdIndex;
127:
128: private String colClassName;
129:
130: private String accessor;
131:
132: private String propertyName;
133:
134: private String definedInAlias;
135:
136: protected void copy(ClassPropertyMapping mapping) {
137: super .copy(mapping);
138: mapping.setClassName(getClassName());
139: mapping.setBoost(getBoost());
140: mapping.setManagedId(getManagedId());
141: mapping.setIdPropertyIndex(getIdPropertyIndex());
142: mapping.setExcludeFromAll(getExcludeFromAll());
143: mapping.setAnalyzer(getAnalyzer());
144: mapping.setOverrideByName(isOverrideByName());
145: mapping.setManagedIdIndex(getManagedIdIndex());
146: mapping.setColClassName(getColClassName());
147: mapping.setAccessor(getAccessor());
148: mapping.setPropertyName(getPropertyName());
149: mapping.setManagedIdConverter(getManagedIdConverter());
150: mapping.setManagedIdConverterName(getManagedIdConverterName());
151: mapping.setDefinedInAlias(getDefinedInAlias());
152: }
153:
154: public Mapping copy() {
155: ClassPropertyMapping copy = new ClassPropertyMapping();
156: copy(copy);
157: return copy;
158: }
159:
160: public boolean canBeCollectionWrapped() {
161: return true;
162: }
163:
164: public ClassPropertyMetaDataMapping getIdMapping() {
165: if (!isIdPropertySet()) {
166: return null;
167: }
168: return (ClassPropertyMetaDataMapping) getMapping(idPropertyIndex);
169: }
170:
171: public float getBoost() {
172: return boost;
173: }
174:
175: public void setBoost(float boost) {
176: this .boost = boost;
177: }
178:
179: public ManagedId getManagedId() {
180: return managedId;
181: }
182:
183: public void setManagedId(ManagedId managedId) {
184: this .managedId = managedId;
185: }
186:
187: public String getClassName() {
188: return className;
189: }
190:
191: public void setClassName(String className) {
192: this .className = className;
193: }
194:
195: public int getIdPropertyIndex() {
196: return idPropertyIndex;
197: }
198:
199: public void setIdPropertyIndex(int idPropertyIndex) {
200: this .idPropertyIndex = idPropertyIndex;
201: }
202:
203: public boolean isIdPropertySet() {
204: return idPropertyIndex != ID_NOT_SET_VALUE;
205: }
206:
207: public ResourcePropertyMapping.ExcludeFromAllType getExcludeFromAll() {
208: return excludeFromAll;
209: }
210:
211: public void setExcludeFromAll(
212: ResourcePropertyMapping.ExcludeFromAllType excludeFromAll) {
213: this .excludeFromAll = excludeFromAll;
214: }
215:
216: public String getAnalyzer() {
217: return analyzer;
218: }
219:
220: public void setAnalyzer(String analyzer) {
221: this .analyzer = analyzer;
222: }
223:
224: public boolean isOverrideByName() {
225: return overrideByName;
226: }
227:
228: public void setOverrideByName(boolean overrideByName) {
229: this .overrideByName = overrideByName;
230: }
231:
232: public Property.Index getManagedIdIndex() {
233: return managedIdIndex;
234: }
235:
236: public void setManagedIdIndex(Property.Index managedIdIndex) {
237: this .managedIdIndex = managedIdIndex;
238: }
239:
240: public String getColClassName() {
241: return colClassName;
242: }
243:
244: public void setColClassName(String colClassName) {
245: this .colClassName = colClassName;
246: }
247:
248: public String getAccessor() {
249: return accessor;
250: }
251:
252: public void setAccessor(String accessor) {
253: this .accessor = accessor;
254: }
255:
256: public String getPropertyName() {
257: return propertyName;
258: }
259:
260: public void setPropertyName(String propertyName) {
261: this .propertyName = propertyName;
262: }
263:
264: public Converter getManagedIdConverter() {
265: return managedIdConverter;
266: }
267:
268: public void setManagedIdConverter(Converter managedIdConverter) {
269: this .managedIdConverter = managedIdConverter;
270: }
271:
272: public String getManagedIdConverterName() {
273: return managedIdConverterName;
274: }
275:
276: public void setManagedIdConverterName(String managedIdConverterName) {
277: this .managedIdConverterName = managedIdConverterName;
278: }
279:
280: public String getDefinedInAlias() {
281: return definedInAlias;
282: }
283:
284: public void setDefinedInAlias(String definedInAlias) {
285: this.definedInAlias = definedInAlias;
286: }
287: }
|