1. 程式人生 > >java程式碼生成器--紫楓凝瀟煙自主開發的程式碼生成器

java程式碼生成器--紫楓凝瀟煙自主開發的程式碼生成器

{
                    
if(threadStatus.equals(ThreadStatus.Stop))
                        
break;
                    
while(threadStatus.equals(ThreadStatus.Pause)){
                        Thread.sleep(
100);
                    }

                    String beanFileName 
= list.get(i);
                    VelocityContext context 
=new VelocityContext();
                    context.put(
"name", beanFileName);
                    context.put(
"packageName", taskList.get(k)[1]);
                    
                    
                    
//create Bean
if(k==0){
                        List
<FieldInfo> beanFieldList = beanUtil.getBeanInfo(beanFileName);
                        context.put(
"beanFieldList",beanFieldList);
                    }
else{
                        String lowerCaseFileName 
= beanFileName.substring(01)
                                .toLowerCase()
                                
+ beanFileName.substring(1);
                        context.put(
"parameter", lowerCaseFileName);
                        context.put(
"modeName", modeName);
                        context.put(
"pack", bean);
                    }

                    Template template 
=null;
                    template 
= Velocity.getTemplate(taskList.get(k)[0]);
                    fileName 
= directoryName + File.separator + beanFileName + taskList.get(k)[2]
                            
+".java";
                    File directoryFile 
=new File(directoryName);
                    
this.out(outPanel, "建立檔案:......"+ fileName
                            
+"");
                    bar.setValue(
1000*(k*listSize+(i+1))/totalFileCount);
                    
if (!directoryFile.exists()) {
                        
this.out(outPanel, "建立目錄:......"+ directoryFile
                                
+"");
                        directoryFile.mkdirs();
                    }

                    BufferedWriter writer 
=new BufferedWriter(
                            
new FileWriter(fileName));

                    
if (template !=null)
                        template.merge(context, writer);

                    writer.flush();
                    writer.close();

                }