KickJava   Java API By Example, From Geeks To Geeks.

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


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.StorageHomeFactoryDecl;
32 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl;
33 import org.objectweb.openccm.ast.api.StorageTypeDecl;
34 import org.objectweb.openccm.ast.api.StorageTypeStateMemberDecl;
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
43 /**
44  * This class generates the mapping for a PSDL factory.
45  *
46  * @author <a HREF="mailto:Christophe.Demarey@lifl.fr">Christophe Demarey</a>
47  *
48  * @version 0.1
49  */

50 public class PSDLFactoryMapping
51   implements org.objectweb.openccm.pss.generator.common.api.PSDLFactoryMapping
52 {
53
54     // ==================================================================
55
//
56
// Internal state.
57
//
58
// ==================================================================
59

60     /** The PSDL factory Declaration. */
61     private StorageHomeFactoryDecl factory_;
62
63     // ===========================================================
64
//
65
// Constructors.
66
//
67
// ===========================================================
68

69     /**
70      * The default constructor.
71      */

72
73     public PSDLFactoryMapping()
74     {
75         // Init internal state
76
factory_ = null;
77     }
78
79     // ==================================================================
80
//
81
// Internal methods.
82
//
83
// ==================================================================
84

85     // ==================================================================
86
//
87
// Public methods.
88
//
89
// ==================================================================
90

91     /**
92      * Set the PSDL StorageHome Factory Declaration to map.
93      *
94      * @param factory - The factory to map.
95      */

96      public void
97      setFactory(StorageHomeFactoryDecl factory)
98      {
99          factory_ = factory;
100      }
101
102     /**
103      * Map a factory definition into Java methods.
104      *
105      * @param generator - The PSDL to Java generator.
106      * @param obj - The StorageHome mapping object.
107      * @param ast - The abstract storage type defining this factory.
108      * @param st - The storage type managed by the storage home.
109      */

110     public void
111     toJava(PSDL2JavaGenerator generator,
112            InterfaceObject obj,
113            AbstractStorageTypeDecl ast,
114            StorageTypeDecl st)
115     throws GenerationException
116     {
117         MethodObject method = null;
118         String JavaDoc[] states = null;
119
120         method = new MethodObjectImpl();
121         method.addComment("The " + factory_.getName() + " factory.");
122         method.setName(factory_.getName());
123         method.setReturnType( generator.getTranslator().getAbsoluteName(ast) );
124         states = factory_.getMemberList().getStrings();
125         StateMemberMapping.mapStateListToParameters
126             ( generator,
127               states,
128               method,
129               ast );
130         obj.addMethod(method);
131
132         if (st != null)
133         {
134             StorageTypeStateMemberDecl state = null;
135             java.util.List JavaDoc states_list = new java.util.ArrayList JavaDoc();
136             for (int i=0; i<states.length; i++)
137             {
138                 // Find the state in the current storageType
139
state = (StorageTypeStateMemberDecl)generator.getDeclaration(ast, states[i]);
140
141                 if (state == null)
142                 {
143                     AbstractStorageTypeDecl[] implemented = null;
144
145                     // Find in the implemented classes
146
implemented = ast.getAllImplementedAbstractStorageTypes().getAbstractStorageTypes();
147                     if(implemented.length > 0)
148                     {
149                         int j = 0;
150                         while( (j<implemented.length) && (state == null) )
151                         {
152                             state = (StorageTypeStateMemberDecl)generator.getDeclaration(implemented[j], states[i]);
153                             j++;
154                         }
155                     }
156                     if (state == null)
157                     {
158                         String JavaDoc msg = "State Member '"+states[i]+"' not found!";
159                         throw new GenerationException(msg);
160                     }
161                 }
162                 states_list.add(state);
163             }
164             method.getImpl().setMacro("SH_CREATE1_METHOD");
165             method.getImpl().addContextValue("states", states_list);
166             method.getImpl().addContextValue("st_type", generator.getTranslator().getAbsoluteName(st));
167         }
168     }
169 }
170
Popular Tags