1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.reactive.beans.factory.config;
18
19 import org.apache.commons.logging.Log;
20 import org.apache.commons.logging.LogFactory;
21 import org.springframework.util.ClassUtils;
22
23 import java.util.List;
24 import java.util.Set;
25 import java.util.Map;
26 import java.util.Properties;
27
28 /***
29 * The default implementation of a placeholder.
30 *
31 * @author Dan Washusen
32 * @version $Id: DefaultPlaceholder.java,v 1.3 2005/06/16 07:02:06 dan_washusen Exp $
33 * @since 16.12.2004
34 */
35 public class DefaultPlaceholder
36 extends AbstractPlaceholder {
37 private static Log log = LogFactory.getLog(DefaultPlaceholder.class);
38
39 /*** The default string used to seperate the type from the key. */
40 public static final String DEFAULT_TYPE_SEPERATOR = "|";
41
42 /*** a string defined to signify the String class. */
43 public static final String TYPE_STRING = "String";
44 /*** a string defined to signify the String class. */
45 public static final String TYPE_ARRAY = "String[]";
46 /*** a string defined to signify the List class. */
47 public static final String TYPE_LIST = "List";
48 /*** a string defined to signify the Set class. */
49 public static final String TYPE_SET = "Set";
50 /*** a string defined to signify the Map class. */
51 public static final String TYPE_MAP = "Map";
52 /*** a string defined to signify the Properties class. */
53 public static final String TYPE_PROPS = "Props";
54
55 protected String typeSeperator;
56
57 public DefaultPlaceholder(String value) {
58 super(value);
59 }
60
61 /***
62 * Returns the value used to seperate type from the key.
63 * @return the value used to seperate type from the key
64 */
65 public String getTypeSeperator() {
66 if (typeSeperator == null)
67 return DEFAULT_TYPE_SEPERATOR;
68
69 return typeSeperator;
70 }
71
72 /***
73 * Sets the value used to seperate type from the key.
74 * @param typeSeperator the value used to seperate type from the key
75 */
76 public void setTypeSeperator(String typeSeperator) {
77 this.typeSeperator = typeSeperator;
78 }
79
80 protected Class determineType(String value) {
81 int typeSeperatorIndex = value.indexOf(getTypeSeperator());
82
83
84 if (typeSeperatorIndex == -1)
85 return String.class;
86
87 String typeName = value.substring(0, typeSeperatorIndex);
88
89
90 Class clazz = null;
91 try {
92 clazz = ClassUtils.forName(typeName);
93 }
94 catch (ClassNotFoundException e) {
95 log.error("Could not determine type for placeholder '" + value + "'; falling back to " + String.class);
96 clazz = String.class;
97 }
98
99 return clazz;
100 }
101
102 protected String determineKey(String value) {
103 int typeSeperatorIndex = value.indexOf(getTypeSeperator());
104
105
106 if (typeSeperatorIndex == -1)
107 return value;
108 else {
109
110 return value.substring(typeSeperatorIndex + 1, value.length());
111 }
112 }
113 }