01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.commons.discovery.tools;
18:
19: import java.util.Properties;
20:
21: import org.apache.commons.discovery.resource.ClassLoaders;
22:
23: /**
24: * Holder for a default class.
25: *
26: * Class may be specified by name (String) or class (Class).
27: * Using the holder complicates the users job, but minimized # of API's.
28: *
29: * @author Richard A. Sitze
30: */
31: public class PropertiesHolder {
32: private Properties properties;
33: private final String propertiesFileName;
34:
35: public PropertiesHolder(Properties properties) {
36: this .properties = properties;
37: this .propertiesFileName = null;
38: }
39:
40: public PropertiesHolder(String propertiesFileName) {
41: this .properties = null;
42: this .propertiesFileName = propertiesFileName;
43: }
44:
45: /**
46: * @param spi Optional SPI (may be null).
47: * If provided, an attempt is made to load the
48: * property file as-per Class.getResource().
49: *
50: * @param loaders Used only if properties need to be loaded.
51: *
52: * @return Properties. Load the properties if necessary.
53: */
54: public Properties getProperties(SPInterface spi,
55: ClassLoaders loaders) {
56: if (properties == null) {
57: properties = ResourceUtils.loadProperties(spi.getSPClass(),
58: getPropertiesFileName(), loaders);
59: }
60: return properties;
61: }
62:
63: public String getPropertiesFileName() {
64: return propertiesFileName;
65: }
66: }
|