1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.reactive.beans.factory.config.commons;
18
19 import org.reactive.beans.factory.config.PlaceholderEvaluator;
20 import org.reactive.beans.factory.config.Placeholder;
21 import org.reactive.beans.factory.config.AbstractPlaceholderEvaluator;
22 import org.apache.commons.configuration.Configuration;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25
26 import java.util.*;
27
28 /***
29 * Used to evaluate a placeholder using the Commons-Configuration configuration agent.
30 *
31 * @author Dan Washusen
32 * @version $Id: CommonsPlaceholderEvaluator.java,v 1.3 2004/12/30 07:35:28 dan_washusen Exp $
33 * @since 20/12/2004
34 */
35 public class CommonsPlaceholderEvaluator
36 extends AbstractPlaceholderEvaluator {
37 private static final Log log = LogFactory.getLog(CommonsPlaceholderEvaluator.class);
38
39 protected Configuration configuration;
40
41 public Configuration getConfiguration() {
42 return configuration;
43 }
44
45 public void setConfiguration(Configuration configuration) {
46 this.configuration = configuration;
47 }
48
49 protected String evaluateString(Placeholder placeholder) {
50 return getConfiguration().getString(placeholder.getKey());
51 }
52
53 protected String[] evaluateArray(Placeholder placeholder) {
54 return getConfiguration().getStringArray(placeholder.getKey());
55 }
56
57 protected List evaluateList(Placeholder placeholder) {
58 return getConfiguration().getList(placeholder.getKey());
59 }
60
61 protected Set evaluateSet(Placeholder placeholder) {
62
63 List list = getConfiguration().getList(placeholder.getKey());
64 Set set = new HashSet(list);
65
66
67 if (log.isDebugEnabled()) {
68 if (list.size() != set.size())
69 log.debug("The set with the key: '" + placeholder.getKey() + "' contained duplicates, they have removed.");
70 }
71
72 return set;
73 }
74
75 protected Map evaluateMap(Placeholder placeholder) {
76
77 return (Map) getConfiguration().getProperties(placeholder.getKey());
78 }
79
80 protected Properties evaluateProperties(Placeholder placeholder) {
81 return getConfiguration().getProperties(placeholder.getKey());
82 }
83
84 protected Object evaluateObject(Placeholder placeholder) {
85 return getConfiguration().getString(placeholder.getKey());
86 }
87 }