1 18 package org.apache.geronimo.interop.util; 19 20 import java.util.Iterator ; 21 import java.util.LinkedList ; 22 import java.util.List ; 23 24 import org.apache.geronimo.interop.properties.PropertyMap; 25 26 27 public class NamedValueList extends LinkedList { 28 public NamedValueList() { 29 } 30 31 public NamedValueList(String namedValueList) { 32 List csvList = ListUtil.getCommaSeparatedList(namedValueList); 33 for (Iterator i = csvList.iterator(); i.hasNext();) { 34 String item = (String ) i.next(); 35 int eqPos = item.indexOf("="); 36 if (eqPos == -1) { 37 badList(namedValueList); 38 } 39 String name = item.substring(0, eqPos).trim(); 40 if (name.length() == 0) { 41 badList(namedValueList); 42 } 43 String value = item.substring(eqPos + 1).trim(); 44 add(new NamedValue(name, value)); 45 } 46 } 47 48 50 public PropertyMap getProperties() { 51 PropertyMap props = new PropertyMap(); 52 for (Iterator i = this.iterator(); i.hasNext();) { 53 NamedValue nv = (NamedValue) i.next(); 54 props.put(nv.name, nv.value); 55 } 56 return props; 57 } 58 59 public String getValue(String name) { 60 return getValue(name, null); 61 } 62 63 public String getValue(String name, String defaultValue) { 64 return (String ) getProperties().getProperty(name, defaultValue); 65 } 66 67 public String toString() { 68 return ListUtil.formatCommaSeparatedList(this); 69 } 70 71 73 protected void badList(String namedValueList) { 74 throw new IllegalArgumentException ("namedValueList = " + namedValueList); 75 } 76 } 77 | Popular Tags |