01: /*
02: * XML 2 Java Binding (X2JB) - the excellent Java tool.
03: * Copyright 2007, by Richard Opalka.
04: *
05: * This is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU Lesser General Public License as
07: * published by the Free Software Foundation; either version 2.1 of
08: * the License, or (at your option) any later version.
09: *
10: * This software is distributed in the hope that it will be useful,
11: * but WITHOUT ANY WARRANTY; without even the implied warranty of
12: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13: * Lesser General Public License for more details.
14: *
15: * You should have received a copy of the GNU Lesser General Public
16: * License along with this software; if not see the FSF site:
17: * http://www.fsf.org/ and search for the LGPL License document there.
18: */
19: package com.x2jb.bind.handler;
20:
21: import org.x2jb.bind.BindingException;
22:
23: /**
24: * Boolean wrapper handler
25: *
26: * @author <a href="mailto:richard_opalka@yahoo.com">Richard Opalka</a>
27: * @version 1.0
28: */
29: public class BooleanHandler extends TemplateHandler {
30:
31: private static final String TRUE = "true";
32: private static final String FALSE = "false";
33: private static final String YES = "yes";
34: private static final String NO = "no";
35: private static final String INT_TRUE = "1";
36: private static final String INT_FALSE = "0";
37:
38: protected Object create(String value) throws BindingException {
39: String v = value.toLowerCase();
40: if (v.equals(TRUE) || v.equals(YES) || v.equals(INT_TRUE))
41: return Boolean.TRUE;
42: if (v.equals(FALSE) || v.equals(NO) || v.equals(INT_FALSE))
43: return Boolean.FALSE;
44: throw new BindingException("Incorrect value '" + value + "'");
45: }
46:
47: }
|