KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > types > UnsignedByte


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
19 import org.apache.axis.utils.Messages;
20
21 /**
22  * Custom class for supporting primitive XSD data type UnsignedByte
23  *
24  * @author Chris Haddad <chaddad@cobia.net>
25  * @see <a HREF="http://www.w3.org/TR/xmlschema-2/#unsignedByte">XML Schema 3.3.24</a>
26  */

27 public class UnsignedByte extends UnsignedShort {
28
29
30     public UnsignedByte() {
31
32     }
33
34     /**
35      * ctor for UnsignedByte
36      * @exception Exception will be thrown if validation fails
37      */

38     public UnsignedByte(long sValue) throws NumberFormatException JavaDoc {
39       setValue(sValue);
40     }
41
42     public UnsignedByte(String JavaDoc sValue) throws NumberFormatException JavaDoc {
43       setValue(Long.parseLong(sValue));
44     }
45
46     /**
47      *
48      * validates the data and sets the value for the object.
49      *
50      * @param sValue the number to set
51      */

52     public void setValue(long sValue) throws NumberFormatException JavaDoc {
53         if (UnsignedByte.isValid(sValue) == false)
54             throw new NumberFormatException JavaDoc(
55                     Messages.getMessage("badUnsignedByte00") +
56                     String.valueOf(sValue) + "]");
57         lValue = new Long JavaDoc(sValue);
58     }
59
60     /**
61      *
62      * validate the value against the xsd value space definition
63      * @param sValue number to check against range
64      */

65     public static boolean isValid(long sValue) {
66       if ( (sValue < 0L ) || (sValue > 255L) )
67         return false;
68       else
69         return true;
70     }
71
72 }
73
Popular Tags