KickJava   Java API By Example, From Geeks To Geeks.

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


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  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
33  */

34 public class BooleanSG extends PrimitiveTypeSG {
35     /** The primitive boolean type.
36      */

37     public static final JavaQName BOOLEAN_TYPE = JavaQNameImpl.getInstance(boolean.class);
38     /** The object boolean type.
39      */

40     public static final JavaQName BOOLEAN_OBJECT_TYPE = JavaQNameImpl.getInstance(Boolean JavaDoc.class);
41
42   /** <p>Creates a new instance of BooleanSG.java.</p>
43    */

44   public BooleanSG(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException {
45     super(pFactory, pSchema, pType);
46   }
47
48   protected String JavaDoc getDatatypeName() { return "Boolean"; }
49   protected JavaQName getDatatypeType() { return BOOLEAN_TYPE; }
50   public JavaQName getPrimitiveRuntimeType(SimpleTypeSG pController) { return BOOLEAN_TYPE; }
51   protected JavaQName getObjectRuntimeType(SimpleTypeSG pController) { return BOOLEAN_OBJECT_TYPE; }
52
53   public TypedValue getCastFromString(SimpleTypeSG pController, String JavaDoc pValue) throws SAXException {
54     try {
55       return new TypedValueImpl(new DatatypeConverterImpl().parseBoolean(pValue) ? Boolean.TRUE : Boolean.FALSE,
56                                 BOOLEAN_OBJECT_TYPE);
57     } catch (RuntimeException JavaDoc e) {
58         try {
59             throw new LocSAXException("Failed to convert string value to "
60                     + getDatatypeName() + " instance: " + pValue, getLocator());
61         } catch (Exception JavaDoc e1) {
62             throw new SAXException("Failed to convert string value to "
63                     + getDatatypeName() + " instance: " + pValue);
64         }
65     }
66   }
67
68     public boolean isCausingParseConversionEvent(SimpleTypeSG pController) {
69         return false;
70     }
71 }
72
Popular Tags