1 package org.picocontainer.testmodel; 2 3 import java.beans.PropertyEditorSupport ; 4 5 11 public class CoupleBeanEditor extends PropertyEditorSupport { 12 private static final String PREFIX_A = "a's name:"; 13 private static final String PREFIX_B = "b's name:"; 14 private static final String SEPARATOR = ";"; 15 16 public CoupleBeanEditor() { 17 super(); 18 } 19 20 public void setAsText(String s) throws IllegalArgumentException { 21 int startA = s.indexOf(PREFIX_A); 22 int stopA = s.indexOf(SEPARATOR, startA+PREFIX_A.length()); 23 int startB = s.indexOf(PREFIX_B, stopA + SEPARATOR.length()); 24 int stopB = s.indexOf(SEPARATOR, startB+ PREFIX_B.length()); 25 if (startA < 0 || stopA < 0 || startB < 0 || stopB < 0) { 26 throw new IllegalArgumentException ("Can't parse " + s + " into a CoupleBean"); 27 } 28 String nameA = s.substring(startA + PREFIX_A.length(), stopA); 29 String nameB = s.substring(startB + PREFIX_B.length(), stopB); 30 31 PersonBean a = new PersonBean(); 32 a.setName(nameA); 33 PersonBean b = new PersonBean(); 34 b.setName(nameB); 35 setValue(new CoupleBean(a, b)); 36 } 37 } 38 | Popular Tags |