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.config;
018:
019: import java.io.File;
020: import java.io.InputStream;
021: import java.net.URL;
022: import java.util.ArrayList;
023: import java.util.List;
024:
025: import org.compass.core.config.binding.MappingBinding;
026: import org.compass.core.mapping.CompassMapping;
027: import org.compass.core.mapping.MappingException;
028: import org.compass.core.mapping.ResourceMapping;
029: import org.compass.core.metadata.CompassMetaData;
030:
031: /**
032: * Compass {@link org.compass.core.config.binding.MappingBinding} is a mapping binding that holds
033: * a list of {@link org.compass.core.config.binding.MappingBinding}s (ordered) and when trying to
034: * add mappings, it will iterate through them and try and add it to each one.
035: *
036: * @author kimchy
037: */
038: public class CompassMappingBinding implements MappingBinding {
039:
040: private List<MappingBinding> mappingBindings = new ArrayList<MappingBinding>();
041:
042: private CompassMapping mapping;
043:
044: public void addMappingBinding(MappingBinding mappingBinding) {
045: this .mappingBindings.add(mappingBinding);
046: }
047:
048: public void setUpBinding(CompassMapping mapping,
049: CompassMetaData metaData, CompassSettings settings) {
050: this .mapping = mapping;
051: for (MappingBinding mappingBinding : mappingBindings) {
052: (mappingBinding).setUpBinding(mapping, metaData, settings);
053: }
054: }
055:
056: public boolean addResoruceMapping(ResourceMapping resourceMapping)
057: throws ConfigurationException, MappingException {
058: mapping.addMapping(resourceMapping);
059: return true;
060: }
061:
062: public boolean addResource(String path)
063: throws ConfigurationException, MappingException {
064: boolean hasAddedResource = false;
065: for (MappingBinding mappingBinding : mappingBindings) {
066: boolean retVal = mappingBinding.addResource(path);
067: if (retVal) {
068: hasAddedResource = true;
069: }
070: }
071: return hasAddedResource;
072: }
073:
074: public boolean addResource(String path, ClassLoader classLoader)
075: throws ConfigurationException, MappingException {
076: boolean hasAddedResource = false;
077: for (MappingBinding mappingBinding : mappingBindings) {
078: boolean retVal = mappingBinding.addResource(path,
079: classLoader);
080: if (retVal) {
081: hasAddedResource = true;
082: }
083: }
084: return hasAddedResource;
085: }
086:
087: public boolean addURL(URL url) throws ConfigurationException,
088: MappingException {
089: boolean hasAddedResource = false;
090: for (MappingBinding mappingBinding : mappingBindings) {
091: boolean retVal = mappingBinding.addURL(url);
092: if (retVal) {
093: hasAddedResource = true;
094: }
095: }
096: return hasAddedResource;
097: }
098:
099: public boolean addDirectory(File dir)
100: throws ConfigurationException, MappingException {
101: boolean hasAddedResource = false;
102: for (MappingBinding mappingBinding : mappingBindings) {
103: boolean retVal = mappingBinding.addDirectory(dir);
104: if (retVal) {
105: hasAddedResource = true;
106: }
107: }
108: return hasAddedResource;
109: }
110:
111: public boolean addJar(File jar) throws ConfigurationException,
112: MappingException {
113: boolean hasAddedResource = false;
114: for (MappingBinding mappingBinding : mappingBindings) {
115: boolean retVal = mappingBinding.addJar(jar);
116: if (retVal) {
117: hasAddedResource = true;
118: }
119: }
120: return hasAddedResource;
121: }
122:
123: public boolean addFile(String filePath)
124: throws ConfigurationException, MappingException {
125: boolean hasAddedResource = false;
126: for (MappingBinding mappingBinding : mappingBindings) {
127: boolean retVal = mappingBinding.addFile(filePath);
128: if (retVal) {
129: hasAddedResource = true;
130: }
131: }
132: return hasAddedResource;
133: }
134:
135: public boolean addFile(File file) throws ConfigurationException,
136: MappingException {
137: boolean hasAddedResource = false;
138: for (MappingBinding mappingBinding : mappingBindings) {
139: boolean retVal = mappingBinding.addFile(file);
140: if (retVal) {
141: hasAddedResource = true;
142: }
143: }
144: return hasAddedResource;
145: }
146:
147: public boolean addPackage(String packageName)
148: throws ConfigurationException, MappingException {
149: boolean hasAddedResource = false;
150: for (MappingBinding mappingBinding : mappingBindings) {
151: boolean retVal = mappingBinding.addPackage(packageName);
152: if (retVal) {
153: hasAddedResource = true;
154: }
155: }
156: return hasAddedResource;
157: }
158:
159: public boolean addClass(Class clazz) throws ConfigurationException,
160: MappingException {
161: boolean hasAddedResource = false;
162: for (MappingBinding mappingBinding : mappingBindings) {
163: boolean retVal = mappingBinding.addClass(clazz);
164: if (retVal) {
165: hasAddedResource = true;
166: }
167: }
168: return hasAddedResource;
169: }
170:
171: public boolean addMappingResolver(
172: InputStreamMappingResolver mappingResolver)
173: throws ConfigurationException, MappingException {
174: boolean hasAddedResource = false;
175: for (MappingBinding mappingBinding : mappingBindings) {
176: boolean retVal = mappingBinding
177: .addMappingResolver(mappingResolver);
178: if (retVal) {
179: hasAddedResource = true;
180: }
181: }
182: return hasAddedResource;
183: }
184:
185: public boolean addInputStream(InputStream is, String resourceName)
186: throws ConfigurationException, MappingException {
187: boolean hasAddedResource = false;
188: for (MappingBinding mappingBinding : mappingBindings) {
189: boolean retVal = mappingBinding.addInputStream(is,
190: resourceName);
191: if (retVal) {
192: hasAddedResource = true;
193: }
194: }
195: return hasAddedResource;
196: }
197: }
|