KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > picocontainer > testmodel > CoupleBeanEditor


1 package org.picocontainer.testmodel;
2
3 import java.beans.PropertyEditorSupport JavaDoc;
4
5 /**
6  *
7  * @author greg
8  * @author $Author: $ (last edit)
9  * @version $Revision: $
10  */

11 public class CoupleBeanEditor extends PropertyEditorSupport JavaDoc {
12     private static final String JavaDoc PREFIX_A = "a's name:";
13     private static final String JavaDoc PREFIX_B = "b's name:";
14     private static final String JavaDoc SEPARATOR = ";";
15
16     public CoupleBeanEditor() {
17         super();
18     }
19
20     public void setAsText(String JavaDoc s) throws IllegalArgumentException JavaDoc {
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 JavaDoc("Can't parse " + s + " into a CoupleBean");
27         }
28         String JavaDoc nameA = s.substring(startA + PREFIX_A.length(), stopA);
29         String JavaDoc 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