1 26 27 package org.objectweb.corba.generator.dependencies.lib; 28 29 import org.objectweb.openccm.ast.api.DeclarationKind; 31 import org.objectweb.openccm.ast.api.CompositionDecl; 32 import org.objectweb.openccm.ast.api.HomeExecutorDecl; 33 import org.objectweb.openccm.ast.api.ExecutorDecl; 34 import org.objectweb.openccm.ast.api.Scope; 35 import org.objectweb.openccm.generator.common.lib.GenerationException; 36 import java.util.Set ; 37 import java.util.TreeSet ; 38 import java.util.Iterator ; 39 import java.io.File ; 40 import java.io.FileWriter ; 41 42 50 51 public class CIDLFileDependenciesResolver 52 extends org.objectweb.openccm.generator.common.lib.GeneratorBase 53 implements org.objectweb.corba.generator.dependencies.api.CIDLFileDependenciesResolver 54 { 55 61 62 private static final String delimiter = 63 "==================================================================\n"; 64 65 66 org.objectweb.corba.generator.dependencies.api.CIDLDeclarationDependencies _resolver; 67 68 70 String [] _filters; 71 72 78 83 public 84 CIDLFileDependenciesResolver(org.objectweb.openccm.ast.api.AST ast) 85 { 86 super(ast); 87 88 _resolver = new org.objectweb.corba.generator.dependencies.lib.CIDLDeclarationDependencies(); 90 _filters = null; 91 } 92 93 99 107 private String 108 applyFilers(String input) 109 { 110 if (_filters == null) 111 return input; 112 113 for (int i=0; i<_filters.length; i++) 114 { 115 if ( input.startsWith(_filters[i]) ) 116 return ""; 117 } 118 119 return input; 120 } 121 122 130 private void 131 addExecutorDependencies( FileWriter output, 132 ExecutorDecl exec ) 133 throws java.io.IOException 134 { 135 Set files = null; 136 Iterator it = null; 137 138 files = _resolver.getExecutorDependencies(exec); 139 it = (new TreeSet (files)).iterator(); 140 141 output.write("# " + delimiter); 142 output.write("# Component " + exec.getAbsoluteName() + "\n"); 143 output.write("# " + delimiter); 144 145 while ( it.hasNext() ) 146 { 147 output.write( applyFilers(it.next() + "\n") ); 148 } 149 output.write("\n"); 150 } 151 152 160 private void 161 addHomeExecutorDependencies( FileWriter output, 162 HomeExecutorDecl home_exec ) 163 throws java.io.IOException 164 { 165 Set files = null; 166 Iterator it = null; 167 168 files = _resolver.getHomeExecutorDependencies(home_exec); 169 it = (new TreeSet (files)).iterator(); 170 171 output.write("# " + delimiter); 172 output.write("# Home " + home_exec.getAbsoluteName() + "\n"); 173 output.write("# " + delimiter); 174 175 while ( it.hasNext() ) 176 { 177 output.write( applyFilers(it.next() + "\n") ); 178 } 179 output.write("\n"); 180 } 181 182 190 private void 191 addCompositionDependencies(FileWriter output, 192 CompositionDecl composition) 193 throws java.io.IOException 194 { 195 org.objectweb.openccm.ast.utils.api.CompositionInfo comp = null; 196 197 comp = new org.objectweb.openccm.ast.utils.lib.CompositionInfo(composition); 198 199 output.write("# " + delimiter); 200 output.write("# Package for Composition :\n"); 201 output.write("# " + composition.getAbsoluteName() + "\n"); 202 output.write("# " + delimiter); 203 output.write("\n"); 204 205 addExecutorDependencies(output, comp.getComponentExecutor()); 207 208 addHomeExecutorDependencies(output, comp.getHomeExecutor()); 210 } 211 212 218 223 public void 224 set_filters(String [] filters) 225 { 226 _filters = filters; 227 } 228 229 237 public void 238 generate_composition_dependencies(CompositionDecl composition, 239 String file) 240 { 241 java.util.Iterator it = null; 242 File output_file = null; 243 FileWriter output = null; 244 int i = 0; 245 246 try 247 { 248 output_file = new File (file); 250 while ( output_file.exists() ) 251 { 252 output_file = new File ( file + String.valueOf(i) ); 253 i++; 254 } 255 int index = output_file.getPath().lastIndexOf( System.getProperty("file.separator") ); 257 if (index != -1) 258 { 259 File dir = new File ( output_file.getPath().substring(0, index+1) ); 260 dir.mkdirs(); 261 } 262 output_file.createNewFile(); 263 264 output = new FileWriter (output_file); 266 addCompositionDependencies(output, composition); 267 output.close(); 268 System.out.println("File '" + output_file.getAbsolutePath() + "' has been generated"); 269 }catch(java.io.IOException ex){ 270 ex.printStackTrace(); 271 } 272 } 273 274 282 public void 283 generate_composition_dependencies(String name, String file) 284 throws GenerationException 285 { 286 CompositionDecl composition = null; 287 288 composition = (CompositionDecl) getDeclaration(name); 290 generate_composition_dependencies(composition, file); 291 } 292 293 302 public void 303 generate_dependencies(Scope scope, 304 String base_dir) 305 throws GenerationException 306 { 307 java.util.List vect = null; 308 CompositionDecl[] compositions = null; 309 String filename = null; 310 311 vect = getAllDeclarations(scope, DeclarationKind.dk_composition); 312 compositions = (CompositionDecl[])vect.toArray(new CompositionDecl[0]); 313 for (int i=0; i<compositions.length; i++) 314 { 315 filename = base_dir + "/" + compositions[i].getName() + ".dep"; 316 generate_composition_dependencies(compositions[i], filename); 317 } 318 } 319 320 326 } 327 | Popular Tags |