KickJava   Java API By Example, From Geeks To Geeks.

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


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 NCName
24  * NCName represents XML "non-colonized" Names
25  * The base type of NCName is Name.
26  *
27  * @author Chris Haddad <chaddad@cobia.net>
28  * @see <a HREF="http://www.w3.org/TR/xmlschema-2/#NCName">XML Schema 3.3.7</a>
29  * @see <A HREF="http://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-NCName">NCName Production</a>
30  */

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

41     public NCName(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("badNCNameType00") + "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 (NCName.isValid(stValue) == false)
61             throw new IllegalArgumentException JavaDoc(
62                Messages.getMessage("badNCNameType00") +
63                " data=[" + stValue + "]");
64         m_value = stValue;
65     }
66
67     /**
68      *
69      * validate the value against the xsd definition
70      *
71      * NCName ::= (Letter | '_') (NCNameChar)*
72      * NCNameChar ::= Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender
73      */

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