KickJava   Java API By Example, From Geeks To Geeks.

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


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.SAXException JavaDoc;
30
31
32 /**
33  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
34  */

35 public class LongSG extends PrimitiveTypeSG {
36   public static final JavaQName LONG_TYPE = JavaQNameImpl.getInstance(long.class);
37   public static final JavaQName LONG_OBJECT_TYPE = JavaQNameImpl.getInstance(Long JavaDoc.class);
38
39   /** <p>Creates a new instance of LongSG.</p>
40    */

41   public LongSG(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException {
42     super(pFactory, pSchema, pType);
43   }
44
45   public JavaQName getPrimitiveRuntimeType(SimpleTypeSG pController) { return LONG_TYPE; }
46   protected JavaQName getObjectRuntimeType(SimpleTypeSG pController) { return LONG_OBJECT_TYPE; }
47   protected String JavaDoc getDatatypeName() { return "Long"; }
48   protected JavaQName getDatatypeType() { return LONG_TYPE; }
49
50   public TypedValue getCastFromString(SimpleTypeSG pController, String JavaDoc pValue) throws SAXException {
51     try {
52       return new TypedValueImpl(new Long JavaDoc(new DatatypeConverterImpl().parseLong(pValue)) + "l", LONG_TYPE);
53     } catch (RuntimeException JavaDoc e) {
54         try {
55             throw new LocSAXException("Failed to convert string value to "
56                     + getDatatypeName() + " instance: " + pValue, getLocator());
57         } catch (Exception JavaDoc e1) {
58             throw new SAXException("Failed to convert string value to "
59                     + getDatatypeName() + " instance: " + pValue);
60         }
61     }
62   }
63 }
64
Popular Tags