1 package org.apache.axis.tool.service.control; 2 3 import java.io.File ; 4 import java.io.IOException ; 5 import java.util.ArrayList ; 6 7 8 import org.apache.axis.tool.service.bean.Page1Bean; 9 import org.apache.axis.tool.service.bean.Page2Bean; 10 import org.apache.axis.tool.service.bean.Page3Bean; 11 import org.apache.axis.tool.service.bean.WizardBean; 12 import org.apache.axis.tool.core.ClassFileHandler; 13 import org.apache.axis.tool.core.FileCopier; 14 import org.apache.axis.tool.core.JarFileWriter; 15 import org.apache.axis.tool.core.ServiceFileCreator; 16 31 public class Controller { 32 33 public ArrayList getMethodList(WizardBean bean) throws ProcessException{ 34 ArrayList returnList = null; 35 try { 36 returnList = new ClassFileHandler().getMethodNamesFromClass(bean.getPage2bean().getAutomaticClassName(), 37 bean.getPage1bean().getFileLocation()); 38 } catch (IOException e) { 39 throw new ProcessException("IO Error, The class file location may be faulty!",e); 40 } catch (ClassNotFoundException e) { 41 throw new ProcessException(" The specified class does not exist!!!"); 42 } catch (Exception e){ 43 throw new ProcessException("Unknown Error! See whether all parameters are available"); 44 } 45 return returnList; 46 } 47 48 49 public void process(WizardBean bean) throws ProcessException,Exception { 50 51 Page1Bean page1Bean = bean.getPage1bean(); 52 Page2Bean page2Bean = bean.getPage2bean(); 53 Page3Bean page3Bean = bean.getPage3bean(); 54 55 File serviceFile = null; 56 File classFileFolder = null; 57 File outputFolder =null; 58 String outputFileName = null; 59 boolean isServiceCreated = false; 60 61 classFileFolder = new File (page1Bean.getFileLocation()); 63 if (!classFileFolder.exists()){ 64 throw new ProcessException("Specified Class file location is empty!!"); 65 } 66 if (!classFileFolder.isDirectory()){ 67 throw new ProcessException("The class file location must be a folder!"); 68 } 69 70 if (page2Bean.isManual()){ 72 serviceFile = new File (page2Bean.getManualFileName()); 73 if (!serviceFile.exists()){ 74 throw new ProcessException("Specified Service XML file is missing!"); 75 } 76 }else{ 77 ArrayList methodList = page2Bean.getSelectedMethodNames(); 78 if (methodList.isEmpty()){ 79 throw new ProcessException("There are no methods selected to generate the service!!"); 80 } 81 serviceFile=new ServiceFileCreator().createServiceFile(page2Bean.getProviderClassName(), 82 page2Bean.getAutomaticClassName(), 83 page2Bean.getSelectedMethodNames()); isServiceCreated = true; 85 } 86 87 outputFolder = new File (page3Bean.getOutputFolderName()); 88 outputFileName = page3Bean.getOutputFileName(); 89 if (!outputFileName.toLowerCase().endsWith(".jar")){ 90 outputFileName = outputFileName + ".jar"; 91 } 92 93 File tempFileFolder =null; 94 95 try { 96 tempFileFolder = new File ("Service-copy"); 98 tempFileFolder.mkdir(); 99 File metaInfFolder = new File (tempFileFolder,"META-INF"); 100 metaInfFolder.mkdir(); 101 102 new FileCopier().copyFiles(classFileFolder,tempFileFolder); 103 new FileCopier().copyFiles(serviceFile,metaInfFolder); 104 105 new JarFileWriter().writeJarFile(outputFolder,outputFileName,tempFileFolder); 107 } catch (Exception e) { 108 throw new ProcessException(e); 109 } finally { 110 tempFileFolder.delete(); 111 if (isServiceCreated) 112 serviceFile.delete(); 113 114 115 } 116 117 } 118 } 119 | Popular Tags |