KickJava   Java API By Example, From Geeks To Geeks.

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


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.AtomicTypeSG;
20 import org.apache.ws.jaxme.generator.sg.Facet;
21 import org.apache.ws.jaxme.generator.sg.ListTypeSG;
22 import org.apache.ws.jaxme.generator.sg.SGFactory;
23 import org.apache.ws.jaxme.generator.sg.SchemaSG;
24 import org.apache.ws.jaxme.generator.sg.SimpleTypeSG;
25 import org.apache.ws.jaxme.generator.sg.SimpleTypeSGChain;
26 import org.apache.ws.jaxme.generator.sg.UnionTypeSG;
27 import org.apache.ws.jaxme.generator.sg.impl.JAXBSGItem;
28 import org.apache.ws.jaxme.js.DirectAccessible;
29 import org.apache.ws.jaxme.js.JavaMethod;
30 import org.apache.ws.jaxme.js.JavaQNameImpl;
31 import org.apache.ws.jaxme.js.JavaSource;
32 import org.apache.ws.jaxme.xs.XSType;
33 import org.xml.sax.Locator JavaDoc;
34 import org.xml.sax.SAXException JavaDoc;
35
36
37 /**
38  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
39  */

40 public abstract class SimpleTypeSGImpl extends JAXBSGItem implements SimpleTypeSGChain {
41   private boolean isNullable;
42
43   /** <p>Creates a new instance of SimpleTypeSGImpl.</p>
44    */

45   protected SimpleTypeSGImpl(SGFactory pFactory, SchemaSG pSchema, XSType pType) throws SAXException JavaDoc {
46     super(pFactory, pSchema, pType);
47     if (!pType.isSimple()) {
48       throw new IllegalStateException JavaDoc("The given type is complex.");
49     }
50   }
51
52   protected XSType getXSType() { return (XSType) super.getXSObject(); }
53   public SGFactory getFactory(SimpleTypeSG pController) { return getFactory(); }
54   public SchemaSG getSchema(SimpleTypeSG pController) { return getSchema(); }
55   public Locator JavaDoc getLocator(SimpleTypeSG pController) { return getLocator(); }
56   public boolean isAtomic(SimpleTypeSG pController) { return false; }
57   public boolean isList(SimpleTypeSG pController) { return false; }
58   public boolean isUnion(SimpleTypeSG pController) { return false; }
59   public boolean hasSetMethod(SimpleTypeSG pController) { return true; }
60   public void setNullable(SimpleTypeSG pController, boolean pNullable) {
61     setNullable(pNullable);
62   }
63   /** Sets whether the data type is nullable.
64    */

65   public void setNullable(boolean pNullable) { isNullable = pNullable; }
66   public boolean isNullable(SimpleTypeSG pController) { return isNullable; }
67
68   public void init(SimpleTypeSG pController) throws SAXException JavaDoc {
69   }
70
71   public String JavaDoc getCollectionType(SimpleTypeSG pController) {
72     return getSchema().getCollectionType();
73   }
74
75   public UnionTypeSG getUnionType(SimpleTypeSG pController) {
76     throw new IllegalStateException JavaDoc("This type is no union.");
77   }
78
79   public ListTypeSG getListType(SimpleTypeSG pController) {
80     throw new IllegalStateException JavaDoc("This type is no list.");
81   }
82
83   public AtomicTypeSG getAtomicType(SimpleTypeSG pController) {
84     throw new IllegalStateException JavaDoc("This type is not atomic.");
85   }
86
87   public Facet[] getFacets(SimpleTypeSG pController) {
88     return new Facet[0];
89   }
90
91   public Facet getFacet(SimpleTypeSG pController, Facet.Type pType) {
92     Facet[] facets = pController.getFacets();
93     for (int i = 0; i < facets.length; i++) {
94       Facet f = facets[i];
95       if (f.getType().equals(pType)) {
96         return f;
97       }
98     }
99     return null;
100   }
101
102   public void generate(SimpleTypeSG pController) {
103   }
104
105   public void generate(SimpleTypeSG pController, JavaSource pSource) {
106   }
107
108   public Object JavaDoc getInitialValue(SimpleTypeSG pController, JavaSource pSource) throws SAXException JavaDoc {
109     return null;
110   }
111
112   public JavaMethod getXMLSetMethod(SimpleTypeSG pController, JavaSource pSource,
113                                     String JavaDoc pFieldName, String JavaDoc pParamName, String JavaDoc pMethodName) throws SAXException JavaDoc {
114     if (pController.hasSetMethod()) {
115       JavaMethod jm = pSource.newJavaMethod(pMethodName, JavaQNameImpl.VOID, JavaSource.PUBLIC);
116       DirectAccessible param = jm.addParam(pController.getRuntimeType(), pParamName);
117       if (!pSource.isInterface()) {
118         pController.addValidation(jm, param);
119         jm.addLine(pFieldName, " = ", param, ";");
120       }
121       return jm;
122     } else {
123       return null;
124     }
125   }
126
127   public void addValidation(SimpleTypeSG pController, JavaMethod pMethod, DirectAccessible pValue) throws SAXException JavaDoc {
128   }
129 }
130
Popular Tags