1 18 package org.apache.tools.ant.taskdefs.optional.ejb; 19 20 import java.io.File ; 21 import java.io.FileInputStream ; 22 import java.io.ObjectInputStream ; 23 import javax.ejb.deployment.DeploymentDescriptor; 24 25 32 public final class DDCreatorHelper { 33 36 private File descriptorDirectory; 37 38 41 private File generatedFilesDirectory; 42 43 47 String [] descriptors; 48 50 58 public static void main(String [] args) throws Exception { 59 DDCreatorHelper helper = new DDCreatorHelper(args); 60 helper.process(); 61 } 62 63 67 private DDCreatorHelper(String [] args) { 68 int index = 0; 69 descriptorDirectory = new File (args[index++]); 70 generatedFilesDirectory = new File (args[index++]); 71 72 descriptors = new String [args.length - index]; 73 for (int i = 0; index < args.length; ++i) { 74 descriptors[i] = args[index++]; 75 } 76 } 77 78 85 private void process() throws Exception { 86 for (int i = 0; i < descriptors.length; ++i) { 87 String descriptorName = descriptors[i]; 88 File descriptorFile = new File (descriptorDirectory, descriptorName); 89 90 int extIndex = descriptorName.lastIndexOf("."); 91 String serName = null; 92 if (extIndex != -1) { 93 serName = descriptorName.substring(0, extIndex) + ".ser"; 94 } else { 95 serName = descriptorName + ".ser"; 96 } 97 File serFile = new File (generatedFilesDirectory, serName); 98 99 if (!serFile.exists() || serFile.lastModified() < descriptorFile.lastModified() 101 || regenerateSerializedFile(serFile)) { 102 103 String [] args = {"-noexit", 104 "-d", serFile.getParent(), 105 "-outputfile", serFile.getName(), 106 descriptorFile.getPath()}; 107 try { 108 weblogic.ejb.utils.DDCreator.main(args); 109 } catch (Exception e) { 110 String [] newArgs = {"-d", generatedFilesDirectory.getPath(), 112 "-outputfile", serFile.getName(), 113 descriptorFile.getPath()}; 114 weblogic.ejb.utils.DDCreator.main(newArgs); 115 } 116 } 117 } 118 } 119 120 126 private boolean regenerateSerializedFile(File serFile) { 127 try { 128 129 FileInputStream fis = new FileInputStream (serFile); 130 ObjectInputStream ois = new ObjectInputStream (fis); 131 DeploymentDescriptor dd = (DeploymentDescriptor) ois.readObject(); 132 fis.close(); 133 134 return false; 136 137 } catch (Exception e) { 138 139 return true; 142 143 } 144 } 145 } 146 | Popular Tags |