1 package org.apache.tools.ant.taskdefs.optional.jmx.converter; 2 3 52 53 54 55 import java.util.Properties ; 56 import java.util.StringTokenizer ; 57 58 64 public class PropertiesValueConverter implements ValueConverter { 65 66 private static String [] supportedTypes = {Properties .class.getName()}; 67 68 71 public PropertiesValueConverter() { 72 } 73 74 82 public Object valueOf(String value, String type) throws Exception { 83 84 try { 85 StringTokenizer tokenizer = new StringTokenizer (value," []{}\t\n\r\f"); 86 Properties result = new Properties (); 87 while (tokenizer.hasMoreTokens()) { 88 String property = tokenizer.nextToken(); 89 90 StringTokenizer valueTokenizer = new StringTokenizer (property,"="); 91 92 String propName = valueTokenizer.nextToken(); 93 String propValue = valueTokenizer.nextToken(); 94 95 result.setProperty(propName,propValue); 96 } 97 return result; 98 } catch (Exception x) { 99 throw new org.apache.tools.ant.BuildException("Invalid Properties value format. Expected format \"name1=value1 name2=value2\" etc. E.g. server=myserver user=barney password=secret"); 100 } 101 } 102 103 public String [] getSupportedTypes() { 104 return supportedTypes; 105 } 106 107 } 108 109 | Popular Tags |