01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.databinding.types;
20:
21: import org.apache.axis2.util.XMLChar;
22:
23: /**
24: * Custom class for supporting XSD data type NMToken
25: * <p/>
26: * NMTOKEN represents the NMTOKEN attribute type from [XML 1.0(Second Edition)]. The value space of
27: * NMTOKEN is the set of tokens that match the Nmtoken production in [XML 1.0 (Second Edition)]. The
28: * base type of NMTOKEN is token.
29: *
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: private static final long serialVersionUID = -1319741002733174329L;
35:
36: public NMToken() {
37: super ();
38: }
39:
40: /**
41: * ctor for NMToken
42: *
43: * @throws IllegalArgumentException will be thrown if validation fails
44: */
45: public NMToken(String stValue) throws IllegalArgumentException {
46: try {
47: setValue(stValue);
48: } catch (IllegalArgumentException e) {
49: // recast normalizedString exception as token exception
50: throw new IllegalArgumentException(
51: // Messages.getMessage("badNmtoken00") + "data=[" +
52: stValue + "]");
53: }
54: }
55:
56: /**
57: * validate the value against the xsd definition Nmtoken ::= (NameChar)+ NameChar ::=
58: * Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender
59: */
60: public static boolean isValid(String stValue) {
61: int scan;
62:
63: for (scan = 0; scan < stValue.length(); scan++) {
64: if (!XMLChar.isName(stValue.charAt(scan)))
65: return false;
66: }
67:
68: return true;
69: }
70: }
|