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