001    package org.picocontainer.testmodel;
002    
003    import java.beans.PropertyEditorSupport;
004    
005    /**
006     *
007     * @author greg
008     * @author $Author: $ (last edit)
009     * @version $Revision: $
010     */
011    public class CoupleBeanEditor extends PropertyEditorSupport {
012        private static final String PREFIX_A = "a's name:";
013        private static final String PREFIX_B = "b's name:";
014        private static final String SEPARATOR = ";";
015    
016        public CoupleBeanEditor() {
017            super();
018        }
019    
020        public void setAsText(String s) throws IllegalArgumentException {
021            int startA = s.indexOf(PREFIX_A);
022            int stopA = s.indexOf(SEPARATOR, startA+PREFIX_A.length());
023            int startB = s.indexOf(PREFIX_B, stopA + SEPARATOR.length());
024            int stopB = s.indexOf(SEPARATOR, startB+ PREFIX_B.length());
025            if (startA < 0 || stopA < 0 || startB < 0 || stopB < 0) {
026                throw new IllegalArgumentException("Can't parse " + s + " into a CoupleBean");
027            }
028            String nameA = s.substring(startA + PREFIX_A.length(), stopA);
029            String nameB = s.substring(startB + PREFIX_B.length(), stopB);
030    
031            PersonBean a = new PersonBean();
032            a.setName(nameA);
033            PersonBean b = new PersonBean();
034            b.setName(nameB);
035            setValue(new CoupleBean(a, b));
036        }
037    }