01: /*
02: * Copyright 2004-2006 the original author or authors.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.compass.core.mapping.rsem;
18:
19: import java.util.Iterator;
20:
21: import org.compass.core.mapping.AbstractResourceMapping;
22: import org.compass.core.mapping.AliasMapping;
23: import org.compass.core.mapping.InvalidMappingException;
24: import org.compass.core.mapping.Mapping;
25: import org.compass.core.mapping.MappingException;
26: import org.compass.core.mapping.OverrideByNameMapping;
27: import org.compass.core.mapping.PostProcessingMapping;
28: import org.compass.core.mapping.ResourcePropertyMapping;
29:
30: /**
31: * @author kimchy
32: */
33: public class RawResourceMapping extends AbstractResourceMapping
34: implements PostProcessingMapping {
35:
36: private ResourcePropertyMapping[] resourcePropertyMappings;
37:
38: public Mapping copy() {
39: RawResourceMapping copy = new RawResourceMapping();
40: copy(copy);
41: return copy;
42: }
43:
44: public AliasMapping shallowCopy() {
45: RawResourceMapping copy = new RawResourceMapping();
46: shallowCopy(copy);
47: return copy;
48: }
49:
50: public int addMapping(Mapping mapping) {
51: // no duplicate mapping names are allowed
52: if (mapping instanceof ResourcePropertyMapping) {
53: ResourcePropertyMapping resourcePropertyMapping = (ResourcePropertyMapping) mapping;
54: if (mappingsByNameMap
55: .get(resourcePropertyMapping.getName()) != null) {
56: if (!(resourcePropertyMapping instanceof OverrideByNameMapping)
57: || !((OverrideByNameMapping) resourcePropertyMapping)
58: .isOverrideByName()) {
59: throw new InvalidMappingException(
60: "Two resource property mappings are mapped to property path ["
61: + resourcePropertyMapping.getPath()
62: .getPath()
63: + "], it is not allowed");
64: }
65: }
66: }
67: return super .addMapping(mapping);
68: }
69:
70: protected void doPostProcess() throws MappingException {
71: resourcePropertyMappings = new ResourcePropertyMapping[mappingsSize()];
72: int i = 0;
73: for (Iterator it = mappingsIt(); it.hasNext();) {
74: resourcePropertyMappings[i++] = (ResourcePropertyMapping) it
75: .next();
76: }
77: }
78:
79: public ResourcePropertyMapping getResourcePropertyMappingByDotPath(
80: String path) {
81: return (ResourcePropertyMapping) mappingsByNameMap.get(path);
82: }
83:
84: public ResourcePropertyMapping[] getResourcePropertyMappings() {
85: return resourcePropertyMappings;
86: }
87: }
|