KickJava   Java API By Example, From Geeks To Geeks.

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


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

36 public abstract class PrimitiveTypeSG extends AtomicTypeSGImpl {
37   /** <p>Creates a new instance of PrimitiveTypeSG.java.</p>
38    */

39   protected PrimitiveTypeSG(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException JavaDoc {
40     super(pFactory, pSchema, pType);
41   }
42
43   protected boolean isUnsigned() { return false; }
44   protected abstract JavaQName getObjectRuntimeType(SimpleTypeSG pController);
45   protected abstract JavaQName getPrimitiveRuntimeType(SimpleTypeSG pController);
46   public JavaQName getRuntimeType(SimpleTypeSG pController) {
47     return pController.isNullable() ? getObjectRuntimeType(pController) : getPrimitiveRuntimeType(pController);
48   }
49
50   public TypedValue getCastFromString(SimpleTypeSG pController, JavaMethod pMethod, Object JavaDoc pValue, Object JavaDoc pData) throws SAXException JavaDoc {
51     TypedValue v = super.getCastFromString(pController, pMethod, pValue, pData);
52     if (pController.isNullable()) {
53         JavaQName objectType = getObjectRuntimeType(pController);
54         v = new TypedValueImpl(new Object JavaDoc[]{"new ", objectType, "(", v, ")"},
55                                objectType);
56     }
57     return v;
58   }
59
60   public TypedValue getCastToString(SimpleTypeSG pController, Object JavaDoc pValue, DirectAccessible pData) {
61     if (pController.isNullable()) {
62       pValue = new Object JavaDoc[]{pValue, "." + getPrimitiveRuntimeType(pController).getClassName() +"Value()"};
63     }
64     return super.getCastToString(pController, pValue, pData);
65   }
66
67   public void forAllValues(SimpleTypeSG pController, JavaMethod pMethod, Object JavaDoc pValue, SGlet pSGlet) throws SAXException JavaDoc {
68     pSGlet.generate(pMethod, pValue);
69   }
70
71   public void forAllNonNullValues(SimpleTypeSG pController, JavaMethod pMethod, Object JavaDoc pValue, SGlet pSGlet) throws SAXException JavaDoc {
72     if (pController.isNullable()) {
73       LocalJavaField f = pMethod.newJavaField(getObjectRuntimeType(pController));
74       f.addLine(pValue);
75       pMethod.addIf(f, " != null");
76       pSGlet.generate(pMethod, pValue);
77       pMethod.addEndIf();
78     } else {
79       pSGlet.generate(pMethod, pValue);
80     }
81   }
82
83   public Object JavaDoc getEqualsCheck(SimpleTypeSG pController, JavaMethod pMethod, Object JavaDoc pValue1, Object JavaDoc pValue2) throws SAXException JavaDoc {
84     if (pController.isNullable()) {
85       return super.getEqualsCheck(pController, pMethod, pValue1, pValue2);
86     } else {
87       return new Object JavaDoc[]{pValue1, " == ", pValue2};
88     }
89   }
90 }
91
Popular Tags