01: package org.obe.worklist;
02:
03: import org.obe.client.api.base.WMParticipantImpl;
04: import org.wfmc.wapi.WMParticipant;
05:
06: import javax.faces.component.UIComponent;
07: import javax.faces.context.FacesContext;
08: import javax.faces.convert.Converter;
09: import java.io.Serializable;
10: import java.util.StringTokenizer;
11:
12: /**
13: * Converts WMParticipant arrays to/from strings.
14: *
15: * @author Adrian Price
16: */
17: public class WMParticipantArrayConverter implements Converter,
18: Serializable {
19: private static final long serialVersionUID = 5283650265320122653L;
20:
21: public WMParticipantArrayConverter() {
22: }
23:
24: public Object getAsObject(FacesContext context,
25: UIComponent component, String value) {
26:
27: WMParticipant[] wmParticipants;
28: if (value != null) {
29: StringTokenizer st = new StringTokenizer(value, ", ");
30: wmParticipants = new WMParticipant[st.countTokens()];
31: for (int i = 0; st.hasMoreTokens(); i++)
32: wmParticipants[i] = new WMParticipantImpl(st
33: .nextToken());
34: } else {
35: wmParticipants = null;
36: }
37:
38: return wmParticipants;
39: }
40:
41: public String getAsString(FacesContext context,
42: UIComponent component, Object value) {
43:
44: String s;
45: if (value instanceof WMParticipant[]) {
46: WMParticipant[] objects = (WMParticipant[]) value;
47: StringBuffer sb = new StringBuffer();
48: for (int i = 0; i < objects.length; i++) {
49: if (i > 0)
50: sb.append(',');
51: sb.append(objects[i]);
52: }
53: s = sb.toString();
54: } else {
55: s = " ";
56: }
57: return s;
58: }
59: }
|