KickJava   Java API By Example, From Geeks To Geeks.

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


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
20 /**
21  * Custom class for supporting XSD data type ID
22  * The base type of Id is NCName.
23  *
24  * @author Eddie Pick <eddie@pick.eu.org>
25  * @see <a HREF="http://www.w3.org/TR/xmlschema-2/#ID">XML Schema 3.3.8</a>
26  */

27 public class Id extends NCName {
28
29     public Id() {
30         super();
31     }
32
33     /**
34      * ctor for Id
35      * @exception IllegalArgumentException will be thrown if validation fails
36      */

37     public Id(String JavaDoc stValue) throws IllegalArgumentException JavaDoc {
38         try {
39             setValue(stValue);
40         }
41         catch (IllegalArgumentException JavaDoc e) {
42             // recast normalizedString exception as token exception
43
throw new IllegalArgumentException JavaDoc(
44                     Messages.getMessage("badIdType00") + "data=[" +
45                     stValue + "]");
46         }
47     }
48
49     /**
50      *
51      * validates the data and sets the value for the object.
52      * @param Token String value
53      * @throws IllegalArgumentException if invalid format
54      */

55     public void setValue(String JavaDoc stValue) throws IllegalArgumentException JavaDoc {
56         if (Id.isValid(stValue) == false)
57             throw new IllegalArgumentException JavaDoc(
58                Messages.getMessage("badIdType00") +
59                " data=[" + stValue + "]");
60         m_value = stValue;
61     }
62
63     /**
64      *
65      * validate the value against the xsd definition
66      *
67      * Same validation as NCName for the time being
68      */

69     public static boolean isValid(String JavaDoc stValue) {
70       return NCName.isValid(stValue);
71     }
72 }
73
Popular Tags