KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > generator > types > UnsignedIntSG


1 /*
2  * Copyright 2003, 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  */

17 package org.apache.ws.jaxme.generator.types;
18
19 import org.apache.ws.jaxme.generator.sg.SGFactory;
20 import org.apache.ws.jaxme.generator.sg.SchemaSG;
21 import org.apache.ws.jaxme.generator.sg.SimpleTypeSG;
22 import org.apache.ws.jaxme.impl.DatatypeConverterImpl;
23 import org.apache.ws.jaxme.js.TypedValue;
24 import org.apache.ws.jaxme.js.impl.TypedValueImpl;
25 import org.apache.ws.jaxme.xs.XSType;
26 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
27 import org.xml.sax.SAXException JavaDoc;
28
29 /**
30  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
31  */

32 public class UnsignedIntSG extends LongSG {
33   /** <p>Creates a new instance of UnsignedIntSG.</p>
34    */

35   public UnsignedIntSG(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException {
36     super(pFactory, pSchema, pType);
37   }
38
39   protected boolean isUnsigned() { return true; }
40   protected String JavaDoc getDatatypeName() { return "UnsignedInt"; }
41
42   public TypedValue getCastFromString(SimpleTypeSG pController, String JavaDoc pValue) throws SAXException {
43     try {
44       return new TypedValueImpl(new Long JavaDoc(new DatatypeConverterImpl().parseUnsignedInt(pValue)) + "l", LONG_TYPE);
45     } catch (NumberFormatException JavaDoc e) {
46       throw new LocSAXException("Failed to convert string value to unsigned integer: " + pValue, getLocator());
47     }
48   }
49 }
50
Popular Tags