KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > ws > jaxme > generator > sg > impl > SerializableSG


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.sg.impl;
18
19 import java.io.Serializable JavaDoc;
20
21 import org.apache.ws.jaxme.generator.SchemaReader;
22 import org.apache.ws.jaxme.generator.sg.SchemaSG;
23 import org.apache.ws.jaxme.js.JavaField;
24 import org.apache.ws.jaxme.js.JavaQName;
25 import org.apache.ws.jaxme.js.JavaQNameImpl;
26 import org.apache.ws.jaxme.js.JavaSource;
27
28 /**
29  * @author <a HREF="mailto:joe@ispsoft.de">Jochen Wiedmann</a>
30  */

31 public class SerializableSG {
32     private static final JavaQName SERIALIZABLE_TYPE = JavaQNameImpl.getInstance(Serializable JavaDoc.class);
33
34     /** Makes the class <code>pSource</code> implementing the
35      * {@link Serializable} interface.
36      */

37     public static void makeSerializable(SchemaSG pSchema, JavaSource pSource) {
38         SchemaReader sr = pSchema.getFactory().getGenerator().getSchemaReader();
39         if (sr instanceof JaxMeSchemaReader) {
40             JaxMeSchemaReader jsr = (JaxMeSchemaReader) sr;
41             XjcSerializable xjcSerializable = jsr.getXjcSerializable();
42             if (xjcSerializable != null) {
43                 if (!pSource.isImplementing(SERIALIZABLE_TYPE)) {
44                     pSource.addImplements(SERIALIZABLE_TYPE);
45                 }
46                 if (xjcSerializable.getUid() != null) {
47                     JavaField uid = pSource.newJavaField("serialVersionUID", JavaQNameImpl.LONG, JavaSource.PRIVATE);
48                     uid.setStatic(true);
49                     uid.setFinal(true);
50                     uid.addLine(xjcSerializable.getUid());
51                 }
52             }
53         }
54     }
55 }
56
Popular Tags