KickJava   Java API By Example, From Geeks To Geeks.

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


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.ast.api.TypeKind;
31 import org.objectweb.openccm.ast.api.DeclarationKind;
32 import org.objectweb.openccm.ast.api.Declaration;
33 import org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl;
34 import org.objectweb.openccm.ast.api.StorageTypeStoreDirectiveDecl;
35 import org.objectweb.openccm.ast.api.TypeRef;
36 import org.objectweb.openccm.ast.api.StorageTypeDecl;
37
38 /**
39  * This class implements useful methods dor PSDL Mapping.
40  *
41  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</A>
42  */

43
44 public class PSDLMappingTools
45      extends PSDLTools
46 {
47
48     // ==================================================================
49
//
50
// Internal state.
51
//
52
// ==================================================================
53

54     // ==================================================================
55
//
56
// Constructors.
57
//
58
// ==================================================================
59

60     /**
61      * The default constructor.
62      */

63
64     public PSDLMappingTools()
65     {
66     }
67
68     // ==================================================================
69
//
70
// Internal methods.
71
//
72
// ==================================================================
73

74     // ==================================================================
75
//
76
// Public methods.
77
//
78
// ==================================================================
79

80     /**
81      * Get the mapping type to marshal a typeref.
82      *
83      * @param typeref - A typeref to marshall.
84      *
85      * @return The marshalled type.
86      */

87     public static String JavaDoc
88     getMarshalledType(TypeRef typeref)
89     {
90         TypeKind tk = typeref.getTypeKind();
91
92         if (tk == TypeKind.tk_alias)
93         {
94             // Get the "native" type
95
org.objectweb.openccm.ast.api.AliasDecl alias;
96
97             alias = (org.objectweb.openccm.ast.api.AliasDecl)typeref;
98             return getMarshalledType( alias.getType() );
99         }
100
101         if ( (tk == TypeKind.tk_sequence)
102              || (tk == TypeKind.tk_array) )
103         {
104             org.objectweb.openccm.ast.api.TypeRefWithContent content = null;
105             java.lang.String JavaDoc str = null;
106
107             content = (org.objectweb.openccm.ast.api.TypeRefWithContent)typeref;
108             str = getMarshalledType( content.getContentType() );
109             return str + "[]";
110         }
111
112         if ( (tk == TypeKind.tk_struct)
113              || ( tk == TypeKind.tk_union)
114              || ( tk == TypeKind.tk_value_box)
115              || ( tk == TypeKind.tk_any)
116              || ( tk == TypeKind.tk_value) )
117         {
118             return "byte[]"; // A BLOB
119
}
120         else if ( tk == TypeKind.tk_interface)
121         {
122             return "java.lang.String"; // The IOR
123
}
124
125         return null;
126     }
127
128     /**
129      * Get the mapping type to marshal a psdl state member.
130      *
131      * @param st - The StorageType declaration.
132      * @param state - The state member to marshall.
133      *
134      * @return The marshalled type.
135      */

136     public static String JavaDoc
137     getMarshalledType(StorageTypeDecl st,
138                       StorageTypeStateMemberDecl state)
139     {
140         org.objectweb.openccm.ast.api.PsdlTypeRef psdltyperef = null;
141         org.objectweb.openccm.ast.api.TypeRef idl_type = null;
142
143         psdltyperef = state.getType();
144         idl_type = psdltyperef.getTypeRef();
145
146         if (idl_type != null)
147         {
148             return getMarshalledType(idl_type);
149         }
150         else
151         {
152             // type is an abstract storagetype
153
if (!psdltyperef.isRef())
154             {
155                 org.objectweb.openccm.generator.translator.idl2java.api.PSDL_JavaTranslator translator = null;
156                 Declaration[] decls = null;
157                 String JavaDoc sd_name = null;
158
159                 // Find a store directive for this state
160
decls = st.getContents(true, DeclarationKind.dk_storage_type_store_directive);
161                 sd_name = state.getName() + "_store_directive";
162                 for (int i=0;i<decls.length;i++)
163                 {
164                     if (sd_name.compareTo(decls[i].getName()) == 0)
165                     {
166                         StorageTypeStoreDirectiveDecl sd = (StorageTypeStoreDirectiveDecl)decls[i];
167                         translator = new org.objectweb.openccm.generator.translator.idl2java.lib.PSDL_JavaTranslator();
168                         return translator.toJava(sd.getType());
169                     }
170                 }
171             }
172             return null;
173         }
174     }
175 }
176
Popular Tags