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.engine.naming.PropertyPath;
020: import org.compass.core.mapping.Mapping;
021: import org.compass.core.mapping.OverrideByNameMapping;
022: import org.compass.core.util.Parameter;
023:
024: /**
025: * @author kimchy
026: */
027: public abstract class AbstractCollectionMapping extends
028: AbstractAccessorMapping implements OverrideByNameMapping {
029:
030: public static final class CollectionType extends Parameter {
031:
032: private static final long serialVersionUID = 5419036751959715652L;
033:
034: private CollectionType(String name) {
035: super (name);
036: }
037:
038: public static final CollectionType NOT_REQUIRED = new CollectionType(
039: "NOT_REQUIRED");
040:
041: public static final CollectionType UNKNOWN = new CollectionType(
042: "UNKNOWN");
043:
044: public static final CollectionType SET = new CollectionType(
045: "SET");
046:
047: public static final CollectionType LIST = new CollectionType(
048: "LIST");
049:
050: public static final CollectionType SORTED_SET = new CollectionType(
051: "SORTED_SET");
052:
053: public static String toString(CollectionType collectionType) {
054: if (collectionType == CollectionType.NOT_REQUIRED) {
055: return "na";
056: } else if (collectionType == CollectionType.UNKNOWN) {
057: return "unknown";
058: } else if (collectionType == CollectionType.SET) {
059: return "set";
060: } else if (collectionType == CollectionType.LIST) {
061: return "list";
062: } else if (collectionType == CollectionType.SORTED_SET) {
063: return "sortset";
064: }
065: throw new IllegalArgumentException(
066: "Can't find collection type for [" + collectionType
067: + "]");
068: }
069:
070: public static CollectionType fromString(String collectionType) {
071: if ("na".equalsIgnoreCase(collectionType)) {
072: return CollectionType.NOT_REQUIRED;
073: } else if ("unknown".equalsIgnoreCase(collectionType)) {
074: return CollectionType.UNKNOWN;
075: } else if ("set".equalsIgnoreCase(collectionType)) {
076: return CollectionType.SET;
077: } else if ("list".equalsIgnoreCase(collectionType)) {
078: return CollectionType.LIST;
079: } else if ("sortset".equalsIgnoreCase(collectionType)) {
080: return CollectionType.SORTED_SET;
081: }
082: throw new IllegalArgumentException(
083: "Can't find collection type for [" + collectionType
084: + "]");
085: }
086: }
087:
088: private PropertyPath collectionTypePath;
089:
090: private PropertyPath colSizePath;
091:
092: private Mapping elementMapping;
093:
094: private boolean overrideByName;
095:
096: private CollectionType collectionType;
097:
098: public void copy(AbstractCollectionMapping copy) {
099: super .copy(copy);
100: copy.setElementMapping(getElementMapping());
101: copy.setCollectionTypePath(getCollectionTypePath());
102: copy.setColSizePath(getColSizePath());
103: copy.setOverrideByName(isOverrideByName());
104: copy.setCollectionType(getCollectionType());
105: }
106:
107: public boolean canBeCollectionWrapped() {
108: return false;
109: }
110:
111: public Mapping getElementMapping() {
112: return elementMapping;
113: }
114:
115: public void setElementMapping(Mapping elementMapping) {
116: this .elementMapping = elementMapping;
117: }
118:
119: public PropertyPath getCollectionTypePath() {
120: return collectionTypePath;
121: }
122:
123: public void setCollectionTypePath(PropertyPath collectionTypePath) {
124: this .collectionTypePath = collectionTypePath;
125: }
126:
127: public PropertyPath getColSizePath() {
128: return colSizePath;
129: }
130:
131: public void setColSizePath(PropertyPath colSizePath) {
132: this .colSizePath = colSizePath;
133: }
134:
135: public boolean isOverrideByName() {
136: return overrideByName;
137: }
138:
139: public void setOverrideByName(boolean overrideByName) {
140: this .overrideByName = overrideByName;
141: }
142:
143: public CollectionType getCollectionType() {
144: return collectionType;
145: }
146:
147: public void setCollectionType(CollectionType collectionType) {
148: this.collectionType = collectionType;
149: }
150: }
|