1
2
3
4
5
6
7
8
9
10 package org.mule.config.converters;
11
12 import org.mule.api.MuleContext;
13 import org.mule.api.expression.PropertyConverter;
14 import org.mule.util.StringUtils;
15
16 import java.util.Properties;
17 import java.util.StringTokenizer;
18
19
20
21
22
23
24
25 public class PropertiesConverter implements PropertyConverter
26 {
27 public static final String DELIM = ",";
28
29 public Object convert(String properties, MuleContext context)
30 {
31 if (StringUtils.isNotBlank(properties))
32 {
33 Properties props = new Properties();
34
35 StringTokenizer st = new StringTokenizer(properties, DELIM);
36 while (st.hasMoreTokens())
37 {
38 String key = st.nextToken().trim();
39 int i = key.indexOf("=");
40 if(i < 1) {
41 throw new IllegalArgumentException("Property string is malformed: " + properties);
42 }
43 String value = key.substring(i+1);
44 key = key.substring(0, i);
45 props.setProperty(key, value);
46 }
47 return props;
48 }
49 return null;
50 }
51
52 public Class getType()
53 {
54 return Properties.class;
55 }
56 }