KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.axis.utils.XMLChar;
21
22 /**
23  * Custom class for supporting XSD data type Name
24  * Name represents XML Names. The value space of Name is
25  * the set of all strings which match the Name production
26  * of [XML 1.0 (Second Edition)].
27  * The base type of Name is token.
28  * @author Chris Haddad <chaddad@cobia.net>
29  * @see <a HREF="http://www.w3.org/TR/xmlschema-2/#Name">XML Schema 3.3.6</a>
30  */

31 public class Name extends Token {
32
33     public Name() {
34         super();
35     }
36
37     /**
38      * ctor for Name
39      * @exception IllegalArgumentException will be thrown if validation fails
40      */

41     public Name(String JavaDoc stValue) throws IllegalArgumentException JavaDoc {
42         try {
43             setValue(stValue);
44         }
45         catch (IllegalArgumentException JavaDoc e) {
46             // recast normalizedString exception as token exception
47
throw new IllegalArgumentException JavaDoc(
48                  Messages.getMessage("badNameType00") + "data=[" +
49                  stValue + "]");
50         }
51     }
52
53     /**
54      *
55      * validates the data and sets the value for the object.
56      * @param stValue String value
57      * @throws IllegalArgumentException if invalid format
58      */

59     public void setValue(String JavaDoc stValue) throws IllegalArgumentException JavaDoc {
60         if (Name.isValid(stValue) == false)
61             throw new IllegalArgumentException JavaDoc(
62                Messages.getMessage("badNameType00") +
63                " data=[" + stValue + "]");
64         m_value = stValue;
65     }
66
67     /**
68      *
69      * validate the value against the xsd definition
70      * Name ::= (Letter | '_' | ':') ( NameChar)*
71      * NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender
72      */

73     public static boolean isValid(String JavaDoc stValue) {
74         int scan;
75         boolean bValid = true;
76
77         for (scan=0; scan < stValue.length(); scan++) {
78           if (scan == 0)
79              bValid = XMLChar.isNameStart(stValue.charAt(scan));
80           else
81              bValid = XMLChar.isName(stValue.charAt(scan));
82           if (bValid == false)
83               break;
84         }
85
86         return bValid;
87     }
88 }
89
Popular Tags