01: package org.emforge.jbpm.web.converter;
02:
03: import javax.faces.component.UIComponent;
04: import javax.faces.context.FacesContext;
05: import javax.faces.convert.Converter;
06: import javax.faces.convert.ConverterException;
07:
08: import org.apache.commons.lang.StringUtils;
09:
10: import org.emforge.xfer.TransitionTO;
11:
12: /** Converts Transition to string by Name
13: *
14: */
15: public class TransitionConverter implements Converter {
16:
17: private static final String EMPTY_NAME = "_";
18:
19: public Object getAsObject(FacesContext i_context,
20: UIComponent i_component, String i_value)
21: throws ConverterException {
22: if (StringUtils.isEmpty(i_value)) {
23: return null;
24: }
25:
26: if (i_value.equals(EMPTY_NAME)) {
27: return new TransitionTO("", null);
28: } else {
29: return new TransitionTO(i_value, null);
30: }
31: }
32:
33: public String getAsString(FacesContext context,
34: UIComponent component, Object value)
35: throws ConverterException {
36: if (value == null) {
37: return "";
38: }
39:
40: if (value instanceof String) {
41: return (String) value;
42: }
43:
44: TransitionTO transition = (TransitionTO) value;
45: String name = transition.getName();
46:
47: // special processing for emtpry string - to serapate later null value from value with empty name
48: if (StringUtils.isEmpty(name)) {
49: return EMPTY_NAME;
50: }
51: return name;
52: }
53: }
|