1 26 27 package org.objectweb.openccm.pss.generator.common.lib; 28 29 31 import org.objectweb.openccm.ast.api.AbstractStorageTypeDecl; 32 import org.objectweb.openccm.ast.api.StorageTypeDecl; 33 import org.objectweb.openccm.ast.api.AbstractStorageHomeDecl; 34 import org.objectweb.openccm.ast.api.StorageHomeDecl; 35 import org.objectweb.openccm.ast.api.DeclarationKind; 36 import org.objectweb.openccm.ast.api.Scope; 37 import org.objectweb.openccm.ast.api.AST; 38 39 import org.objectweb.openccm.generator.java.core.lib.*; 40 import org.objectweb.openccm.generator.java.ast.api.*; 41 import org.objectweb.openccm.generator.java.ast.lib.*; 42 43 import org.objectweb.openccm.generator.common.lib.GenerationException; 44 import org.objectweb.openccm.generator.translator.idl2java.api.PSDL_JavaTranslator; 45 import org.objectweb.openccm.pss.generator.hibernate.api.HibernateXmlGenerator; 46 import org.objectweb.openccm.pss.generator.jdo.api.JdoXmlGenerator; 47 48 import java.util.List ; 49 50 51 58 59 public class PSDL2JavaGenerator 60 extends org.objectweb.openccm.generator.common.lib.GeneratorBase 61 implements org.objectweb.openccm.pss.generator.common.api.PSDL2JavaGenerator 62 { 63 64 70 71 private static final int JDO_BACKEND = 0; 72 73 74 private static final int HIBERNATE_BACKEND = 1; 75 76 82 83 private Repository repository_; 84 85 86 private int backend_; 87 88 89 public PSDL_JavaTranslator translator_; 90 91 97 102 103 public PSDL2JavaGenerator(AST ast) 104 { 105 super(ast); 106 repository_ = null; 108 translator_ = new org.objectweb.openccm.generator.translator.idl2java.lib.PSDL_JavaTranslator(); 109 backend_ = JDO_BACKEND; 110 } 111 112 118 124 130 131 137 142 public PSDL_JavaTranslator 143 getTranslator() 144 { 145 return translator_; 146 } 147 148 153 public Repository 154 getJavaRepository() 155 { 156 return repository_; 157 } 158 159 160 168 public void 169 psdl_to_java(String base_dir, 170 Scope scope, 171 String user_properties_file, 172 String backend) 173 throws GenerationException 174 { 175 java.io.File out_dir = null; 176 repository_ = new RepositoryImpl(); 177 List vect = null; 178 AbstractStorageTypeDecl[] ast_array = null; 179 StorageTypeDecl[] st_array = null; 180 AbstractStorageHomeDecl[] ash_array = null; 181 StorageHomeDecl[] sh_array = null; 182 183 try{ 185 out_dir = org.objectweb.openccm.generator.common.lib.FileManager.mkdir(base_dir); 186 }catch(GenerationException ex){ 187 System.err.println(ex.getMessage()); 188 return; 189 } 190 191 System.getProperties().put("openccm.pss.pf", backend); 193 if (backend.compareTo("jdo") == 0) 194 { 195 backend_ = JDO_BACKEND; 196 } 197 else if (backend.compareTo("hibernate") == 0) 198 { 199 backend_ = HIBERNATE_BACKEND; 200 } 201 202 203 204 vect = getAllDeclarations(scope, DeclarationKind.dk_abstract_storage_type); 205 ast_array = (AbstractStorageTypeDecl[])vect.toArray(new AbstractStorageTypeDecl[0]); 206 for (int i=0; i<ast_array.length; i++) 207 { 208 org.objectweb.openccm.pss.generator.common.api.AbstractStorageTypeMapping ast = null; 209 210 ast = (org.objectweb.openccm.pss.generator.common.api.AbstractStorageTypeMapping) 211 MappingObjectFactory.getClass("AbstractStorageTypeMapping"); 212 ast.setAbstractStorageType(ast_array[i]); 213 ast.toJava(this); 214 } 215 216 217 vect = getAllDeclarations(scope, DeclarationKind.dk_abstract_storage_home); 218 ash_array = (AbstractStorageHomeDecl[])vect.toArray(new AbstractStorageHomeDecl[0]); 219 for (int i=0; i<ash_array.length; i++) 220 { 221 org.objectweb.openccm.pss.generator.common.api.AbstractStorageHomeMapping ash = null; 222 223 ash = (org.objectweb.openccm.pss.generator.common.api.AbstractStorageHomeMapping) 224 MappingObjectFactory.getClass("AbstractStorageHomeMapping"); 225 ash.setAbstractStorageHome(ash_array[i]); 226 ash.toJava(this); 227 } 228 229 230 vect = getAllDeclarations(scope, DeclarationKind.dk_storage_type); 231 st_array = (StorageTypeDecl[])vect.toArray(new StorageTypeDecl[0]); 232 for (int i=0; i<st_array.length; i++) 233 { 234 org.objectweb.openccm.pss.generator.common.api.StorageTypeMapping st = null; 235 236 st = (org.objectweb.openccm.pss.generator.common.api.StorageTypeMapping) 237 MappingObjectFactory.getClass("StorageTypeMapping"); 238 st.setStorageType(st_array[i]); 239 st.toJava(true, this); 240 } 241 if (backend_ == JDO_BACKEND) 243 { 244 JdoXmlGenerator jdo_xml_gen = null; 245 246 jdo_xml_gen = new org.objectweb.openccm.pss.generator.jdo.lib.JdoXmlGenerator(this); 247 jdo_xml_gen.initialize("psdl_java"); 248 jdo_xml_gen.to_jdo_xml(base_dir, vect, user_properties_file); 249 } 250 else 251 { 252 HibernateXmlGenerator hibernate_xml_gen = null; 253 254 hibernate_xml_gen = new org.objectweb.openccm.pss.generator.hibernate.lib.HibernateXmlGenerator(this); 255 hibernate_xml_gen.initialize("psdl_java"); 256 hibernate_xml_gen.to_hibernate_xml(base_dir, vect, user_properties_file); 257 } 258 259 260 vect = getAllDeclarations(scope, DeclarationKind.dk_storage_home); 261 sh_array = (StorageHomeDecl[])vect.toArray(new StorageHomeDecl[0]); 262 for (int i=0; i<sh_array.length; i++) 263 { 264 org.objectweb.openccm.pss.generator.common.api.StorageHomeMapping sh = null; 265 266 sh = (org.objectweb.openccm.pss.generator.common.api.StorageHomeMapping) 267 MappingObjectFactory.getClass("StorageHomeMapping"); 268 sh.setStorageHome(sh_array[i]); 269 sh.toJava(this); 270 } 271 272 org.objectweb.openccm.generator.java.core.lib.JavaGenerator java_gen = new JavaGenerator(); 274 java.util.List v = new java.util.ArrayList (); 275 v.add("org/objectweb/openccm/pss/generator/common/psdl2java_common.vm"); 276 if (backend_ == JDO_BACKEND) 277 { 278 v.add("org/objectweb/openccm/pss/generator/jdo/psdl2java_jdo.vm"); 279 } 280 else 281 { 282 v.add("org/objectweb/openccm/pss/generator/hibernate/psdl2java_hibernate.vm"); 283 } 284 java_gen.initialize("PSDL2JAVA", v); 285 java_gen.generate(repository_, base_dir); 286 } 287 } 288 | Popular Tags |