001 /*****************************************************************************
002 * Copyright (C) PicoContainer Organization. All rights reserved. *
003 * ------------------------------------------------------------------------- *
004 * The software in this package is published under the terms of the BSD *
005 * style license a copy of which has been included with this distribution in *
006 * the LICENSE.txt file. *
007 * *
008 * Original code by *
009 *****************************************************************************/
010 package org.picocontainer.testmodel;
011
012 import java.beans.PropertyEditorSupport;
013
014 /**
015 *
016 * @author greg
017 * @author $Author: $ (last edit)
018 * @version $Revision: $
019 */
020 public class CoupleBeanEditor extends PropertyEditorSupport {
021 private static final String PREFIX_A = "a's name:";
022 private static final String PREFIX_B = "b's name:";
023 private static final String SEPARATOR = ";";
024
025 public CoupleBeanEditor() {
026 super();
027 }
028
029 public void setAsText(String s) throws IllegalArgumentException {
030 int startA = s.indexOf(PREFIX_A);
031 int stopA = s.indexOf(SEPARATOR, startA+PREFIX_A.length());
032 int startB = s.indexOf(PREFIX_B, stopA + SEPARATOR.length());
033 int stopB = s.indexOf(SEPARATOR, startB+ PREFIX_B.length());
034 if (startA < 0 || stopA < 0 || startB < 0 || stopB < 0) {
035 throw new IllegalArgumentException("Can't parse " + s + " into a CoupleBean");
036 }
037 String nameA = s.substring(startA + PREFIX_A.length(), stopA);
038 String nameB = s.substring(startB + PREFIX_B.length(), stopB);
039
040 PersonBean a = new PersonBean();
041 a.setName(nameA);
042 PersonBean b = new PersonBean();
043 b.setName(nameB);
044 setValue(new CoupleBean(a, b));
045 }
046 }