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 Name Name represents XML Names. The value space of Name
25: * is the set of all strings which match the Name production of [XML 1.0 (Second Edition)]. The base
26: * type of Name is token.
27: *
28: * @see <a href="http://www.w3.org/TR/xmlschema-2/#Name">XML Schema 3.3.6</a>
29: */
30: public class Name extends Token {
31:
32: private static final long serialVersionUID = -8354594301737358441L;
33:
34: public Name() {
35: super ();
36: }
37:
38: /**
39: * ctor for Name
40: *
41: * @throws IllegalArgumentException will be thrown if validation fails
42: */
43: public Name(String stValue) throws IllegalArgumentException {
44: try {
45: setValue(stValue);
46: } catch (IllegalArgumentException e) {
47: // recast normalizedString exception as token exception
48: throw new IllegalArgumentException(
49: //Messages.getMessage("badNameType00") +
50: "data=[" + stValue + "]");
51: }
52: }
53:
54: /**
55: * validates the data and sets the value for the object.
56: *
57: * @param stValue String value
58: * @throws IllegalArgumentException if invalid format
59: */
60: public void setValue(String stValue)
61: throws IllegalArgumentException {
62: if (!Name.isValid(stValue))
63: throw new IllegalArgumentException(
64: //Messages.getMessage("badNameType00") +
65: " data=[" + stValue + "]");
66: m_value = stValue;
67: }
68:
69: /**
70: * validate the value against the xsd definition Name ::= (Letter | '_' | ':') (
71: * NameChar)* NameChar ::= Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar |
72: * Extender
73: */
74: //todo - Fix this
75: public static boolean isValid(String stValue) {
76: int scan;
77: boolean bValid = true;
78:
79: for (scan = 0; scan < stValue.length(); scan++) {
80: if (scan == 0) {
81: bValid = XMLChar.isNameStart(stValue.charAt(scan));
82: } else {
83: bValid = XMLChar.isName(stValue.charAt(scan));
84: }
85: if (!bValid)
86: break;
87: }
88:
89: return bValid;
90: }
91: }
|