KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > axis > tool > service > control > Controller


1 package org.apache.axis.tool.service.control;
2
3 import java.io.File JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.util.ArrayList JavaDoc;
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 /*
17  * Copyright 2004,2005 The Apache Software Foundation.
18  *
19  * Licensed under the Apache License, Version 2.0 (the "License");
20  * you may not use this file except in compliance with the License.
21  * You may obtain a copy of the License at
22  *
23  * http://www.apache.org/licenses/LICENSE-2.0
24  *
25  * Unless required by applicable law or agreed to in writing, software
26  * distributed under the License is distributed on an "AS IS" BASIS,
27  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28  * See the License for the specific language governing permissions and
29  * limitations under the License.
30  */

31 public class Controller {
32
33     public ArrayList JavaDoc getMethodList(WizardBean bean) throws ProcessException{
34         ArrayList JavaDoc returnList = null;
35         try {
36             returnList = new ClassFileHandler().getMethodNamesFromClass(bean.getPage2bean().getAutomaticClassName(),
37                                                            bean.getPage1bean().getFileLocation());
38         } catch (IOException JavaDoc e) {
39             throw new ProcessException("IO Error, The class file location may be faulty!",e);
40         } catch (ClassNotFoundException JavaDoc e) {
41            throw new ProcessException(" The specified class does not exist!!!");
42         } catch (Exception JavaDoc 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 JavaDoc{
50
51         Page1Bean page1Bean = bean.getPage1bean();
52         Page2Bean page2Bean = bean.getPage2bean();
53         Page3Bean page3Bean = bean.getPage3bean();
54
55         File JavaDoc serviceFile = null;
56         File JavaDoc classFileFolder = null;
57         File JavaDoc outputFolder =null;
58         String JavaDoc outputFileName = null;
59         boolean isServiceCreated = false;
60
61         //see if the class file location is valid
62
classFileFolder = new File JavaDoc(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          //see if the service.xml file is valid
71
if (page2Bean.isManual()){
72             serviceFile = new File JavaDoc(page2Bean.getManualFileName());
73             if (!serviceFile.exists()){
74                 throw new ProcessException("Specified Service XML file is missing!");
75             }
76         }else{
77             ArrayList JavaDoc 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());//create the file here
84
isServiceCreated = true;
85         }
86
87         outputFolder = new File JavaDoc(page3Bean.getOutputFolderName());
88         outputFileName = page3Bean.getOutputFileName();
89         if (!outputFileName.toLowerCase().endsWith(".jar")){
90             outputFileName = outputFileName + ".jar";
91         }
92
93         File JavaDoc tempFileFolder =null;
94
95         try {
96             //create a temporary directory and copy the files
97
tempFileFolder = new File JavaDoc("Service-copy");
98             tempFileFolder.mkdir();
99             File JavaDoc metaInfFolder = new File JavaDoc(tempFileFolder,"META-INF");
100             metaInfFolder.mkdir();
101
102             new FileCopier().copyFiles(classFileFolder,tempFileFolder);
103             new FileCopier().copyFiles(serviceFile,metaInfFolder);
104
105             //jar the temp directory. the output folder will be created if missing
106
new JarFileWriter().writeJarFile(outputFolder,outputFileName,tempFileFolder);
107         } catch (Exception JavaDoc 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