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.engine.naming;
18:
19: import org.compass.core.config.CompassConfigurable;
20: import org.compass.core.config.CompassEnvironment;
21: import org.compass.core.config.CompassSettings;
22: import org.compass.core.engine.SearchEngineException;
23: import org.compass.core.util.ClassUtils;
24:
25: /**
26: * A default implementation of the property naming strategy factory. Can be used
27: * to create naming strategies that has default constructor, and no
28: * initialization requirements.
29: * <p/>
30: * Uses the {@link org.compass.core.config.CompassEnvironment.NamingStrategy#TYPE}
31: * setting for the fully qualified class name of the property naming strategy.
32: * If non is set, defaults to the
33: * {@link DefaultPropertyNamingStrategy}
34: * <p/>
35: * The {@link org.compass.core.config.CompassConfiguration} creates the factory,
36: * which can be set using the
37: * {@link org.compass.core.config.CompassEnvironment.NamingStrategy#FACTORY_TYPE}
38: * setting, and defaults to this class as the factory.
39: *
40: * @author kimchy
41: */
42: public class DefaultPropertyNamingStrategyFactory implements
43: PropertyNamingStrategyFactory {
44:
45: public PropertyNamingStrategy createNamingStrategy(
46: CompassSettings settings) {
47: PropertyNamingStrategy namingStrategy;
48: String namingStrategySetting = settings.getSetting(
49: CompassEnvironment.NamingStrategy.TYPE,
50: DefaultPropertyNamingStrategy.class.getName());
51: try {
52: namingStrategy = (PropertyNamingStrategy) ClassUtils
53: .forName(namingStrategySetting,
54: settings.getClassLoader()).newInstance();
55: } catch (Exception e) {
56: throw new SearchEngineException(
57: "Cannot create naming Strategy ["
58: + namingStrategySetting
59: + "]. Please verify the naming setting at ["
60: + CompassEnvironment.NamingStrategy.TYPE
61: + "]", e);
62: }
63: if (namingStrategy instanceof CompassConfigurable) {
64: ((CompassConfigurable) namingStrategy).configure(settings);
65: }
66: return namingStrategy;
67: }
68:
69: }
|