KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

42     public NMToken(String JavaDoc stValue) throws IllegalArgumentException JavaDoc {
43         try {
44             setValue(stValue);
45         }
46         catch (IllegalArgumentException JavaDoc e) {
47             // recast normalizedString exception as token exception
48
throw new IllegalArgumentException JavaDoc(
49                 Messages.getMessage("badNmtoken00") + "data=[" +
50                 stValue + "]");
51         }
52     }
53
54     /**
55      *
56      * validate the value against the xsd definition
57      * Nmtoken ::= (NameChar)+
58      * NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender
59      */

60     public static boolean isValid(String JavaDoc stValue) {
61         int scan;
62
63         for (scan=0; scan < stValue.length(); scan++) {
64           if (XMLChar.isName(stValue.charAt(scan)) == false)
65             return false;
66         }
67
68         return true;
69     }
70 }
71
Popular Tags