KickJava   Java API By Example, From Geeks To Geeks.

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


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
/** To access AST. */
31 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl;
32 import org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl;
33 import org.objectweb.openccm.ast.api.PsdlOperationDecl;
34 import org.objectweb.openccm.ast.api.DeclarationKind;
35 /** To access Java AST. */
36 import org.objectweb.openccm.generator.java.ast.api.*;
37 import org.objectweb.openccm.generator.java.ast.lib.*;
38 /** Others. */
39 import org.objectweb.openccm.generator.common.lib.GenerationException;
40 import org.objectweb.openccm.pss.generator.common.api.PSDL2JavaGenerator;
41
42 import java.util.List JavaDoc;
43
44
45 /**
46  * This class generates Abstract Storage Type Mapping.
47  *
48  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
49  *
50  * @version 0.1
51  */

52
53 public class AbstractStorageTypeMapping
54   implements org.objectweb.openccm.pss.generator.common.api.AbstractStorageTypeMapping
55 {
56
57     // ==================================================================
58
//
59
// Internal state.
60
//
61
// ==================================================================
62

63     /** The Abstract StorageType declaration. */
64     private AbstractStorageTypeDecl ast_;
65
66     // ===========================================================
67
//
68
// Constructors.
69
//
70
// ===========================================================
71

72     /**
73      * The default constructor.
74      */

75     public AbstractStorageTypeMapping()
76     {
77         // Init internal state
78
ast_ = null;
79     }
80
81     // ==================================================================
82
//
83
// Internal methods.
84
//
85
// ==================================================================
86

87     // ==================================================================
88
//
89
// Public methods.
90
//
91
// ==================================================================
92

93     /**
94      * Set the PSDL Abstract StorageType Declaration to map.
95      *
96      * @param ast - The Abstract Storage Type to map.
97      */

98      public void
99      setAbstractStorageType(AbstractStorageTypeDecl ast)
100      {
101          ast_ = ast;
102      }
103
104     /**
105      * Map an Abstract Storage Type definition into a java Interface.
106      *
107      * @param generator - The PSDL to Java generator.
108      */

109     public void
110     toJava(PSDL2JavaGenerator generator)
111     throws GenerationException
112     {
113         InterfaceObject itf = null;
114         MethodObject method = null;
115         AbstractStorageTypeDecl[] inherited = null;
116         List JavaDoc vect = null;
117         StorageTypeStateMemberDecl[] state_members = null;
118         PsdlOperationDecl[] operations = null;
119
120         itf = new InterfaceObjectImpl(ast_.getName());
121         itf.addComment(" Abstract Storage Type "+ast_.getName());
122         itf.addComment("");
123         itf.addComment(" @author OpenCCM PSDL Compiler");
124         itf.setModifier(ModifierKindImpl.mk_public);
125         itf.setPackage(generator.getTranslator().getPackage(ast_));
126
127         // Add Inherited Abstract Storage Type by ast
128
inherited = ast_.getAbstractStorageTypeList().getAbstractStorageTypes();
129         for (int i=0; i<inherited.length; i++)
130             itf.addInheritedObject(generator.getTranslator().getAbsoluteName(inherited[i]));
131
132         // inherits implicitly org.omg.CosPersistentState.StorageObject
133
if (inherited.length < 1)
134             itf.addInheritedObject("org.objectweb.openccm.pss.runtime.common.api.StorageObject");
135
136         generator.getJavaRepository().addObject(itf);
137         HolderMapping hm = new HolderMapping(ast_.getName(), generator.getTranslator().getPackage(ast_));
138         hm.toJava(generator.getJavaRepository());
139
140         // Map State Members
141
vect = generator.getDeclarations(ast_, DeclarationKind.dk_storage_type_state_member);
142         state_members = (StorageTypeStateMemberDecl[])vect.toArray(new StorageTypeStateMemberDecl[0]);
143         for (int i=0; i<state_members.length; i++)
144         {
145             org.objectweb.openccm.pss.generator.common.api.StateMemberMapping state = null;
146             
147             state = (org.objectweb.openccm.pss.generator.common.api.StateMemberMapping)
148                          MappingObjectFactory.getClass("StateMemberMapping");
149             state.setStateMember(state_members[i]);
150             state.toJavaAccessors(generator.getTranslator(), itf, false);
151         }
152
153         // Map Psdl Operations
154
vect = generator.getDeclarations(ast_, DeclarationKind.dk_psdl_operation);
155         operations = (PsdlOperationDecl[])vect.toArray(new PsdlOperationDecl[0]);
156         for (int i=0; i<operations.length; i++)
157         {
158             org.objectweb.openccm.pss.generator.common.api.PSDLOperationMapping op = null;
159             
160             op = (org.objectweb.openccm.pss.generator.common.api.PSDLOperationMapping)
161                         MappingObjectFactory.getClass("PSDLOperationMapping");
162             op.setOperation(operations[i]);
163             op.toJava(generator.getTranslator(), itf);
164         }
165     }
166 }
167
Popular Tags