KickJava   Java API By Example, From Geeks To Geeks.

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


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.JavaQName;
24 import org.apache.ws.jaxme.js.JavaQNameImpl;
25 import org.apache.ws.jaxme.js.TypedValue;
26 import org.apache.ws.jaxme.js.impl.TypedValueImpl;
27 import org.apache.ws.jaxme.xs.XSType;
28 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
29 import org.xml.sax.Locator JavaDoc;
30 import org.xml.sax.SAXException JavaDoc;
31
32
33 /**
34  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
35  */

36 public class IntSG extends PrimitiveTypeSG {
37   public static final JavaQName INT_TYPE = JavaQNameImpl.getInstance(int.class);
38   public static final JavaQName INT_OBJECT_TYPE = JavaQNameImpl.getInstance(Integer JavaDoc.class);
39
40   /** <p>Creates a new instance of LongSG.</p>
41    */

42   public IntSG(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException {
43     super(pFactory, pSchema, pType);
44   }
45
46   public JavaQName getPrimitiveRuntimeType(SimpleTypeSG pController) { return INT_TYPE; }
47   protected JavaQName getObjectRuntimeType(SimpleTypeSG pController) { return INT_OBJECT_TYPE; }
48   protected String JavaDoc getDatatypeName() { return "Int"; }
49   protected JavaQName getDatatypeType() { return INT_TYPE; }
50
51   public TypedValue getCastFromString(SimpleTypeSG pController, String JavaDoc pValue) throws SAXException {
52     try {
53       return new TypedValueImpl(new Integer JavaDoc(new DatatypeConverterImpl().parseInt(pValue)), INT_TYPE);
54     } catch (NumberFormatException JavaDoc e) {
55       Locator JavaDoc locator;
56       try {
57         locator = getLocator();
58       } catch (Exception JavaDoc f) {
59         throw new SAXException("Failed to convert string value to integer: " + pValue);
60       }
61       throw new LocSAXException("Failed to convert string value to integer: " + pValue, locator);
62     }
63   }
64 }
65
Popular Tags