KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jface > internal > databinding > provisional > conversion > ConvertString2Boolean


1 /*
2  * Copyright (C) 2005 db4objects Inc. http://www.db4o.com
3  *
4  * All rights reserved. This program and the accompanying materials
5  * are made available under the terms of the Eclipse Public License v1.0
6  * which accompanies this distribution, and is available at
7  * http://www.eclipse.org/legal/epl-v10.html
8  *
9  * Contributors:
10  * db4objects - Initial API and implementation
11  */

12 package org.eclipse.jface.internal.databinding.provisional.conversion;
13
14 import org.eclipse.jface.internal.databinding.internal.BindingMessages;
15
16
17
18 /**
19  * ConvertString2Boolean.
20  */

21 public class ConvertString2Boolean implements IConverter {
22
23     /* (non-Javadoc)
24      * @see org.eclipse.jface.binding.converter.IConverter#convert(java.lang.Object)
25      */

26     public Object JavaDoc convert(Object JavaDoc source) {
27         String JavaDoc s = (String JavaDoc) source;
28         if (s.equals(BindingMessages.getString("Yes")) || s.equals(BindingMessages.getString("yes")) || s.equals(BindingMessages.getString("true")) || s.equals(BindingMessages.getString("True"))) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
29
return Boolean.TRUE;
30         if (s.equals(BindingMessages.getString("No")) || s.equals(BindingMessages.getString("no")) || s.equals(BindingMessages.getString("false")) || s.equals(BindingMessages.getString("False"))) //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$
31
return Boolean.FALSE;
32         
33         throw new IllegalArgumentException JavaDoc(s + " is not a legal boolean value"); //$NON-NLS-1$
34
}
35
36     public Object JavaDoc getFromType() {
37         return String JavaDoc.class;
38     }
39
40     public Object JavaDoc getToType() {
41         return Boolean JavaDoc.class;
42     }
43
44 }
45
Popular Tags