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 | 0 | public class PropertiesConverter implements PropertyConverter |
23 | |
{ |
24 | |
public static final String DELIM = ","; |
25 | |
|
26 | |
public Object convert(String properties, MuleContext context) |
27 | |
{ |
28 | 0 | if (StringUtils.isNotBlank(properties)) |
29 | |
{ |
30 | 0 | Properties props = new Properties(); |
31 | |
|
32 | 0 | StringTokenizer st = new StringTokenizer(properties, DELIM); |
33 | 0 | while (st.hasMoreTokens()) |
34 | |
{ |
35 | 0 | String key = st.nextToken().trim(); |
36 | 0 | int i = key.indexOf("="); |
37 | 0 | if(i < 1) { |
38 | 0 | throw new IllegalArgumentException("Property string is malformed: " + properties); |
39 | |
} |
40 | 0 | String value = key.substring(i+1); |
41 | 0 | key = key.substring(0, i); |
42 | 0 | props.setProperty(key, value); |
43 | 0 | } |
44 | 0 | return props; |
45 | |
} |
46 | 0 | return null; |
47 | |
} |
48 | |
|
49 | |
public Class getType() |
50 | |
{ |
51 | 0 | return Properties.class; |
52 | |
} |
53 | |
} |