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 namespaces;
20:
21: import org.x2jb.bind.BindingException;
22:
23: /**
24: * Namespaces sample
25: * @author <a href="mailto:richard_opalka@yahoo.com">Richard Opalka</a>
26: * @version 1.0
27: */
28: public final class Direction {
29:
30: /** IN Direction type */
31: public static final Direction IN = new Direction("IN");
32: /** OUT Direction type */
33: public static final Direction OUT = new Direction("OUT");
34: /** IN OUT Direction type */
35: public static final Direction IN_OUT = new Direction("IN OUT");
36:
37: private final String type;
38:
39: /**
40: * Forbidden constructor
41: * @param type direction type
42: */
43: private Direction(String type) {
44: super ();
45: this .type = type;
46: }
47:
48: /**
49: * Factory method which converts passed <code>String</code> to <code>Direction</code> object
50: * @param s to be converted
51: * @return <code>Direction</code> instance
52: * @throws BindingException if passed string is incorrect
53: */
54: public static Direction valueOf(String s) throws BindingException {
55: if (s != null) {
56: String directionType = s.toUpperCase();
57: if ((directionType.indexOf(IN.toString()) != -1)
58: && (directionType.indexOf(OUT.toString()) != -1)) {
59: return IN_OUT;
60: }
61: if (directionType.indexOf(IN.toString()) != -1) {
62: return IN;
63: }
64: if (directionType.indexOf(OUT.toString()) != -1) {
65: return OUT;
66: }
67: }
68:
69: throw new BindingException("Value '" + s
70: + "' has incorrect direction value");
71: }
72:
73: public final String toString() {
74: return this.type;
75: }
76:
77: }
|