KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.math.BigDecimal JavaDoc;
20
21 import org.apache.ws.jaxme.generator.sg.SGFactory;
22 import org.apache.ws.jaxme.generator.sg.SGlet;
23 import org.apache.ws.jaxme.generator.sg.SchemaSG;
24 import org.apache.ws.jaxme.generator.sg.SimpleTypeSG;
25 import org.apache.ws.jaxme.impl.DatatypeConverterImpl;
26 import org.apache.ws.jaxme.js.JavaMethod;
27 import org.apache.ws.jaxme.js.JavaQName;
28 import org.apache.ws.jaxme.js.JavaQNameImpl;
29 import org.apache.ws.jaxme.js.LocalJavaField;
30 import org.apache.ws.jaxme.js.TypedValue;
31 import org.apache.ws.jaxme.js.impl.TypedValueImpl;
32 import org.apache.ws.jaxme.xs.XSType;
33 import org.apache.ws.jaxme.xs.parser.impl.LocSAXException;
34 import org.xml.sax.SAXException JavaDoc;
35
36 /**
37  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
38  */

39 public class DecimalSG extends AtomicTypeSGImpl {
40   static public final JavaQName DECIMAL_TYPE = JavaQNameImpl.getInstance(BigDecimal JavaDoc.class);
41
42   /** <p>Creates a new instance of DecimalSG.</p>
43    */

44   public DecimalSG(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException {
45     super(pFactory, pSchema, pType);
46   }
47
48   public JavaQName getRuntimeType(SimpleTypeSG pController) { return DECIMAL_TYPE; }
49   protected String JavaDoc getDatatypeName() { return "Decimal"; }
50   protected JavaQName getDatatypeType() { return DECIMAL_TYPE; }
51
52   public TypedValue getCastFromString(SimpleTypeSG pController, String JavaDoc pValue) throws SAXException {
53     try {
54         return new TypedValueImpl("new java.math.BigDecimal(\"" + pValue + "\")", DECIMAL_TYPE);
55     } catch (RuntimeException JavaDoc e) {
56         try {
57             throw new LocSAXException("Failed to convert string value to "
58                     + getDatatypeName() + " instance: " + pValue, getLocator());
59         } catch (Exception JavaDoc e1) {
60             throw new SAXException("Failed to convert string value to "
61                     + getDatatypeName() + " instance: " + pValue);
62         }
63     }
64   }
65
66   public void forAllNonNullValues(SimpleTypeSG pController, JavaMethod pMethod, Object JavaDoc pValue, SGlet pSGlet) throws SAXException {
67     LocalJavaField f = pMethod.newJavaField(DECIMAL_TYPE);
68     f.addLine(pValue);
69     pMethod.addIf(f, " != null");
70     pSGlet.generate(pMethod, pValue);
71     pMethod.addEndIf();
72   }
73
74   public void forAllValues(SimpleTypeSG pController, JavaMethod pMethod, Object JavaDoc pValue, SGlet pSGlet) throws SAXException {
75     pSGlet.generate(pMethod, pValue);
76   }
77 }
78
Popular Tags