Source code: org/apache/axis/types/UnsignedShort.java
1 /*
2 * Copyright 2001-2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package org.apache.axis.types;
17
18 import org.apache.axis.utils.Messages;
19
20 /**
21 * Custom class for supporting primitive XSD data type UnsignedShort
22 *
23 * @author Chris Haddad <chaddad@cobia.net>
24 * @see <a href="http://www.w3.org/TR/xmlschema-2/#unsignedShort">XML Schema 3.3.23</a>
25 */
26 public class UnsignedShort extends UnsignedInt {
27
28 public UnsignedShort() {
29
30 }
31
32 /**
33 * ctor for UnsignedShort
34 * @exception NumberFormatException will be thrown if validation fails
35 */
36 public UnsignedShort(long sValue) throws NumberFormatException {
37 setValue(sValue);
38 }
39
40 public UnsignedShort(String sValue) throws NumberFormatException {
41 setValue(Long.parseLong(sValue));
42 }
43
44 /**
45 *
46 * validates the data and sets the value for the object.
47 *
48 * @param sValue value
49 */
50 public void setValue(long sValue) throws NumberFormatException {
51 if (UnsignedShort.isValid(sValue) == false)
52 throw new NumberFormatException(
53 Messages.getMessage("badUnsignedShort00") +
54 String.valueOf(sValue) + "]");
55 lValue = new Long(sValue);
56 }
57
58 /**
59 *
60 * validate the value against the xsd definition
61 *
62 */
63 public static boolean isValid(long sValue) {
64 if ( (sValue < 0L ) || (sValue > 65535L) )
65 return false;
66 else
67 return true;
68 }
69
70 }