KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > openccm > pss > generator > common > lib > HolderMapping


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2004 INRIA & USTL - LIFL - GOAL
5 Contact: openccm@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Christophe Demarey.
23 Contributor(s): ________________________________________.
24
25 ====================================================================*/

26
27 package org.objectweb.openccm.pss.generator.common.lib;
28
29 // Package dependencies
30
import org.objectweb.openccm.generator.java.ast.api.*;
31 import org.objectweb.openccm.generator.java.ast.lib.*;
32
33
34 /**
35  * This class generates Holder Mapping.
36  *
37  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</A>
38  *
39  * @version 0.1
40  */

41
42 public class HolderMapping
43   implements org.objectweb.openccm.pss.generator.common.api.HolderMapping
44 {
45
46     // ==================================================================
47
//
48
// Internal state.
49
//
50
// ==================================================================
51

52     /** The type to hold. */
53     private String JavaDoc type_;
54
55     /** The Holder package. */
56     private String JavaDoc package_name_;
57
58     // ===========================================================
59
//
60
// Constructors.
61
//
62
// ===========================================================
63

64     /**
65      * The default constructor.
66      *
67      * @param ast - The Abstract Syntax Tree.
68      */

69
70     public HolderMapping(String JavaDoc type, String JavaDoc package_name)
71     {
72         // Init internal state
73
type_ = type;
74         package_name_ = package_name;
75     }
76
77     // ==================================================================
78
//
79
// Internal methods.
80
//
81
// ==================================================================
82

83     // ==================================================================
84
//
85
// Public methods.
86
//
87
// ==================================================================
88

89     /**
90      * Map a Holder for a type to a Java class.
91      *
92      * @param repository - The Java Abstract Syntax Tree.
93      */

94     public void
95     toJava(org.objectweb.openccm.generator.java.ast.api.Repository repository)
96     {
97         ClassObject clazz = null;
98         AttributeObject att = null;
99         ConstructorObject ct = null;
100         MethodObject method = null;
101         ParameterObject param = null;
102
103         clazz = new ClassObjectImpl(type_ + "Holder");
104         clazz.addComment("Holder class for : " + type_);
105         clazz.addComment("");
106         clazz.addComment(" @author OpenCCM PSDL Compiler");
107         clazz.setModifier(ModifierKindImpl.mk_public);
108         clazz.setPackage(package_name_);
109         clazz.addImplementedObject("org.omg.CORBA.portable.Streamable");
110
111         // Add the context attribute
112
att = new AttributeObjectImpl();
113         att.addComment("Internal " + type_ + " value");
114         att.setName("value_");
115         att.setType(package_name_ + "." + type_);
116         att.setModifier( ModifierKindImpl.mk_public );
117         clazz.addAttribute(att);
118
119         // Add the default constructor
120
ct = new ConstructorObjectImpl();
121         ct.addComment("The default constructor.");
122         clazz.addConstructor(ct);
123         // Add a constructor with initial value
124
ct = new ConstructorObjectImpl();
125         ct.addComment("Constructor with initial value.");
126         ct.addComment(" ");
127         ct.addComment("@param value - The initial value.");
128         param = new ParameterObjectImpl();
129         param.setName("value");
130         param.setType(package_name_ + "." + type_);
131         ct.addParameter(param);
132         ct.getImpl().setMacro("HOLDER_CONSTRUCTOR");
133         ct.getImpl().addContextValue("var", "value_");
134         clazz.addConstructor(ct);
135
136         // Add the _read method
137
method = new MethodObjectImpl();
138         method.addComment("Reads data from istream and initalizes the value "+
139                           "field of the Holder with the unmarshalled data.");
140         method.addComment(" ");
141         method.addComment("@param istream - the InputStream that represents the CDR data from the wire.");
142         method.setName("_read");
143         method.setReturnType("void");
144         param = new ParameterObjectImpl();
145         param.setName("istream");
146         param.setType("org.omg.CORBA.portable.InputStream");
147         method.addParameter(param);
148         method.getImpl().setMacro("CORBA_NO_IMPLEMENT");
149         clazz.addMethod(method);
150
151         // Add the _write method
152
method = new MethodObjectImpl();
153         method.addComment("Marshals to ostream the value in the value field of the Holder.");
154         method.addComment(" ");
155         method.addComment("@param ostream - the CDR OutputStream.");
156         method.setName("_write");
157         method.setReturnType("void");
158         param = new ParameterObjectImpl();
159         param.setName("ostream");
160         param.setType("org.omg.CORBA.portable.OutputStream");
161         method.addParameter(param);
162         method.getImpl().setMacro("CORBA_NO_IMPLEMENT");
163         clazz.addMethod(method);
164
165         // Add the _type method
166
method = new MethodObjectImpl();
167         method.addComment("Retrieves the TypeCode object corresponding to the value"+
168                           " in the value field of the Holder.");
169         method.addComment(" ");
170         method.addComment("@return The TypeCode object for the value held in the holder.");
171         method.setName("_type");
172         method.setReturnType("org.omg.CORBA.TypeCode");
173         method.getImpl().setMacro("CORBA_NO_IMPLEMENT");
174         clazz.addMethod(method);
175
176         repository.addObject(clazz);
177     }
178 }
179
Popular Tags