001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */
019: package org.apache.axis2.databinding.types;
020:
021: /**
022: * Custom class for supporting XSD data type NormalizedString. normalizedString represents white
023: * space normalized strings. The base type of normalizedString is string.
024: *
025: * @see <a href="http://www.w3.org/TR/xmlschema-2/#normalizedString">XML Schema Part 2: Datatypes
026: * 3.3.1</a>
027: */
028: public class NormalizedString implements java.io.Serializable {
029:
030: private static final long serialVersionUID = -290878151870399401L;
031:
032: String m_value; // JAX-RPC maps xsd:string to java.lang.String
033:
034: public NormalizedString() {
035: super ();
036: }
037:
038: /**
039: * ctor for NormalizedString
040: *
041: * @param stValue is the String value
042: * @throws IllegalArgumentException if invalid format
043: */
044: public NormalizedString(String stValue)
045: throws IllegalArgumentException {
046: setValue(stValue);
047: }
048:
049: /**
050: * validates the data and sets the value for the object.
051: *
052: * @param stValue String value
053: * @throws IllegalArgumentException if invalid format
054: */
055: public void setValue(String stValue)
056: throws IllegalArgumentException {
057: if (!NormalizedString.isValid(stValue))
058: throw new IllegalArgumentException(
059: // Messages.getMessage("badNormalizedString00") +
060: " data=[" + stValue + "]");
061: m_value = stValue;
062: }
063:
064: public String toString() {
065: return m_value;
066: }
067:
068: public int hashCode() {
069: return m_value.hashCode();
070: }
071:
072: /**
073: * validate the value against the xsd definition for the object
074: * <p/>
075: * The value space of normalizedString is the set of strings that do not contain the carriage
076: * return (#xD), line feed (#xA) nor tab (#x9) characters. The lexical space of normalizedString
077: * is the set of strings that do not contain the carriage return (#xD) nor tab (#x9)
078: * characters.
079: *
080: * @param stValue the String to test
081: * @return Returns true if valid normalizedString.
082: */
083: public static boolean isValid(String stValue) {
084: int scan;
085:
086: for (scan = 0; scan < stValue.length(); scan++) {
087: char cDigit = stValue.charAt(scan);
088: switch (cDigit) {
089: case 0x09:
090: case 0x0A:
091: case 0x0D:
092: return false;
093: default:
094: break;
095: }
096: }
097: return true;
098: }
099:
100: public boolean equals(Object object) {
101: String s1 = object.toString();
102: return s1.equals(m_value);
103: }
104: }
|