KickJava   Java API By Example, From Geeks To Geeks.

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


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 XSD data type NormalizedString.
22  * normalizedString represents white space normalized strings.
23  * The base type of normalizedString is string.
24  *
25  * @author Chris Haddad <chaddad@cobia.net>
26  * @see <a HREF="http://www.w3.org/TR/xmlschema-2/#normalizedString">XML Schema Part 2: Datatypes 3.3.1</a>
27  */

28 public class NormalizedString extends Object JavaDoc implements java.io.Serializable JavaDoc {
29
30     String JavaDoc m_value = null; // JAX-RPC maps xsd:string to java.lang.String
31

32     public NormalizedString() {
33         super();
34     }
35
36     /**
37      *
38      * ctor for NormalizedString
39      * @param stValue is the String value
40      * @throws IllegalArgumentException if invalid format
41      */

42     public NormalizedString(String JavaDoc stValue) throws IllegalArgumentException JavaDoc {
43         setValue(stValue);
44     }
45
46     /**
47      *
48      * validates the data and sets the value for the object.
49      * @param stValue String value
50      * @throws IllegalArgumentException if invalid format
51      */

52     public void setValue(String JavaDoc stValue) throws IllegalArgumentException JavaDoc {
53         if (NormalizedString.isValid(stValue) == false)
54             throw new IllegalArgumentException JavaDoc(
55                Messages.getMessage("badNormalizedString00") +
56                " data=[" + stValue + "]");
57         m_value = stValue;
58     }
59
60     public String JavaDoc toString(){
61         return m_value;
62     }
63
64     public int hashCode(){
65         return m_value.hashCode();
66     }
67
68     /**
69      *
70      * validate the value against the xsd definition for the object
71      *
72      * The value space of normalizedString is the set of strings that
73      * do not contain the carriage return (#xD), line feed (#xA) nor
74      * tab (#x9) characters. The lexical space of normalizedString is
75      * the set of strings that do not contain the carriage return (#xD)
76      * nor tab (#x9) characters.
77      *
78      * @param stValue the String to test
79      * @returns true if valid normalizedString
80      */

81     public static boolean isValid(String JavaDoc stValue) {
82         int scan;
83
84         for (scan = 0; scan < stValue.length(); scan++) {
85             char cDigit = stValue.charAt(scan);
86             switch (cDigit) {
87                 case 0x09:
88                 case 0x0A:
89                 case 0x0D:
90                     return false;
91                 default:
92                     break;
93             }
94         }
95         return true;
96     }
97
98     public boolean equals(Object JavaDoc object) {
99         String JavaDoc s1 = object.toString();
100         return s1.equals(m_value);
101     }
102 }
103
Popular Tags