KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

65     /** The Abstract Storage Home declaration. */
66     private AbstractStorageHomeDecl ash_;
67
68     // ===========================================================
69
//
70
// Constructors.
71
//
72
// ===========================================================
73

74     /**
75      * The default constructor.
76      */

77
78     public AbstractStorageHomeMapping()
79     {
80         // Init internal state
81
ash_ = null;
82     }
83
84     // ==================================================================
85
//
86
// Internal methods.
87
//
88
// ==================================================================
89

90     // ==================================================================
91
//
92
// Public methods.
93
//
94
// ==================================================================
95

96     /**
97      * Set the PSDL Abstract StorageHome Declaration to map.
98      *
99      * @param ash - The Abstract Storage Home to map.
100      */

101      public void
102      setAbstractStorageHome(AbstractStorageHomeDecl ash)
103      {
104          ash_ = ash;
105      }
106      
107     /**
108      * Map an Abstract Storage Home definition into a java Interface.
109      *
110      * @param generator - The PSDL to Java generator.
111      */

112     public void
113     toJava(PSDL2JavaGenerator generator)
114     throws GenerationException
115     {
116         InterfaceObject itf = null;
117         MethodObject method = null;
118         AbstractStorageHomeDecl[] inherited = null;
119         List JavaDoc vect = null;
120         PsdlOperationDecl[] operations = null;
121         AbstractStorageTypeDecl ast = null;
122         StorageHomeKeyDecl[] keys = null;
123         StorageHomeFactoryDecl[] factories = null;
124         Declaration decl = null;
125
126         itf = new InterfaceObjectImpl(ash_.getName());
127         itf.addComment(" Abstract Storage Home "+ash_.getName());
128         itf.addComment("");
129         itf.addComment(" @author OpenCCM PSDL Compiler");
130         itf.setModifier(ModifierKindImpl.mk_public);
131         itf.setPackage(generator.getTranslator().getPackage(ash_));
132
133         // Add Inherited Abstract Storage Home by ash
134
inherited = ash_.getAbstractStorageHomeList().getAbstractStorageHomes();
135         for (int i=0; i<inherited.length; i++)
136             itf.addInheritedObject(generator.getTranslator().getAbsoluteName(inherited[i]));
137
138         if (inherited.length < 1)
139             itf.addInheritedObject("org.omg.CosPersistentState.StorageHomeBase");
140
141         generator.getJavaRepository().addObject(itf);
142
143         // Get the managed Abstract Storage Type
144
ast = ash_.getAbstractStorageType();
145
146         // Map Factories
147
vect = generator.getDeclarations(ash_, DeclarationKind.dk_storage_home_factory);
148         factories = (StorageHomeFactoryDecl[])vect.toArray(new StorageHomeFactoryDecl[0]);
149         for (int i=0; i<factories.length; i++)
150         {
151             org.objectweb.openccm.pss.generator.common.api.PSDLFactoryMapping factory = null;
152             
153             factory = (org.objectweb.openccm.pss.generator.common.api.PSDLFactoryMapping)
154                             MappingObjectFactory.getClass("PSDLFactoryMapping");
155             factory.setFactory(factories[i]);
156             factory.toJava(generator, itf, ast, null);
157         }
158
159         // Map Keys
160
vect = generator.getDeclarations(ash_, DeclarationKind.dk_storage_home_key);
161         keys = (StorageHomeKeyDecl[])vect.toArray(new StorageHomeKeyDecl[0]);
162         for (int i=0; i<keys.length; i++)
163         {
164             org.objectweb.openccm.pss.generator.common.api.PSDLKeyMapping key = null;
165             
166             key = (org.objectweb.openccm.pss.generator.common.api.PSDLKeyMapping)
167                         MappingObjectFactory.getClass("PSDLKeyMapping");
168             key.setKey(keys[i]);
169             key.toJava(generator, itf, ast);
170         }
171
172          // Map Operations
173
vect = generator.getDeclarations(ash_, DeclarationKind.dk_psdl_operation);
174         operations = (PsdlOperationDecl[])vect.toArray(new PsdlOperationDecl[0]);
175         for (int i=0; i<operations.length; i++)
176         {
177             org.objectweb.openccm.pss.generator.common.api.PSDLOperationMapping op = null;
178             
179             op = (org.objectweb.openccm.pss.generator.common.api.PSDLOperationMapping)
180                         MappingObjectFactory.getClass("PSDLOperationMapping");
181             op.setOperation(operations[i]);
182             op.toJava(generator.getTranslator(), itf);
183         }
184    }
185
186 }
187
Popular Tags