1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.reactive.beans.factory.config.properties;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.reactive.beans.factory.config.*;
22 import org.springframework.beans.factory.BeanInitializationException;
23 import org.springframework.beans.factory.InitializingBean;
24 import org.springframework.core.io.Resource;
25 import org.springframework.util.DefaultPropertiesPersister;
26 import org.springframework.util.PropertiesPersister;
27
28 import java.io.IOException;
29 import java.io.InputStream;
30 import java.io.InputStreamReader;
31 import java.util.Enumeration;
32 import java.util.Properties;
33
34 /***
35 * Used to evaluate a placeholder using the {@link java.util.Properties} class. Only placeholders of type String can
36 * be evaluated using this class.
37 *
38 * <p>
39 * Note: This class is basically equivelant to Spring's org.springframework.beans.factory.config.PropertyResourceConfigurer
40 * by Juergen Hoeller.
41 * </p>
42 *
43 * @author Dan Washusen
44 * @version $Id: PropertiesPlaceholderEvaluator.java,v 1.2 2004/12/30 23:28:28 dan_washusen Exp $
45 * @since 20/12/2004
46 * @see org.reactive.configuration.PropertiesConfigurationFactory
47 */
48 public class PropertiesPlaceholderEvaluator
49 implements PlaceholderEvaluator {
50 protected final Log logger = LogFactory.getLog(PropertiesPlaceholderEvaluator.class);
51
52 private Properties properties;
53
54 public Properties getProperties() {
55 return properties;
56 }
57
58 public void setProperties(Properties properties) {
59 this.properties = properties;
60 }
61
62 public Object evaluate(Placeholder placeholder) {
63 if (String.class.equals(placeholder.getType())) {
64 return getProperties().getProperty(placeholder.getKey());
65 }
66 else {
67 throw new InvalidPlaceholderException("Only placeholders of type " + DefaultPlaceholder.TYPE_STRING + " are allowed when using " + this.getClass().getName());
68 }
69 }
70 }