Source Code Cross Referenced for Controller.java in  » Web-Services-AXIS2 » tools » org » apache » axis2 » tool » service » control » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Services AXIS2 » tools » org.apache.axis2.tool.service.control 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one
003:         * or more contributor license agreements. See the NOTICE file
004:         * distributed with this work for additional information
005:         * regarding copyright ownership. The ASF licenses this file
006:         * to you under the Apache License, Version 2.0 (the
007:         * "License"); you may not use this file except in compliance
008:         * with the License. You may obtain a copy of the License at
009:         *
010:         * http://www.apache.org/licenses/LICENSE-2.0
011:         *
012:         * Unless required by applicable law or agreed to in writing,
013:         * software distributed under the License is distributed on an
014:         * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015:         * KIND, either express or implied. See the License for the
016:         * specific language governing permissions and limitations
017:         * under the License.
018:         */
019:        package org.apache.axis2.tool.service.control;
020:
021:        import org.apache.axis2.tool.core.ClassFileHandler;
022:        import org.apache.axis2.tool.core.FileCopier;
023:        import org.apache.axis2.tool.core.JarFileWriter;
024:        import org.apache.axis2.tool.core.ServiceFileCreator;
025:        import org.apache.axis2.tool.core.ServiceXMLCreater;
026:        import org.apache.axis2.tool.service.bean.ClassFileSelectionBean;
027:        import org.apache.axis2.tool.service.bean.LibrarySelectionBean;
028:        import org.apache.axis2.tool.service.bean.Page2Bean;
029:        import org.apache.axis2.tool.service.bean.Page3Bean;
030:        import org.apache.axis2.tool.service.bean.WSDLFileLocationBean;
031:        import org.apache.axis2.tool.service.bean.WizardBean;
032:
033:        import java.io.BufferedWriter;
034:        import java.io.File;
035:        import java.io.FileWriter;
036:        import java.io.IOException;
037:        import java.util.ArrayList;
038:        import java.util.List;
039:
040:        public class Controller {
041:
042:            public ArrayList getMethodList(WizardBean bean)
043:                    throws ProcessException {
044:                ArrayList returnList = null;
045:                try {
046:                    returnList = new ClassFileHandler()
047:                            .getMethodNamesFromClass(bean.getPage2bean()
048:                                    .getAutomaticClassName(), bean
049:                                    .getPage1bean().getFileLocation());
050:                } catch (IOException e) {
051:                    throw new ProcessException(
052:                            "IO Error, The class file location may be faulty!",
053:                            e);
054:                } catch (ClassNotFoundException e) {
055:                    throw new ProcessException(
056:                            " The specified class does not exist!!!");
057:                } catch (Exception e) {
058:                    throw new ProcessException(
059:                            "Unknown Error! See whether all parameters are available");
060:                }
061:                return returnList;
062:            }
063:
064:            public void process(WizardBean bean) throws ProcessException,
065:                    Exception {
066:
067:                ClassFileSelectionBean page1Bean = bean.getPage1bean();
068:                WSDLFileLocationBean wsdlBean = bean.getWsdlBean();
069:                LibrarySelectionBean libBean = bean.getLibraryBean();
070:                Page2Bean page2Bean = bean.getPage2bean();
071:                Page3Bean page3Bean = bean.getPage3bean();
072:
073:                File serviceFile = null;
074:                File wsdlFile = null;
075:                File classFileFolder = null;
076:                File outputFolder = null;
077:                String outputFileName = null;
078:                boolean isServiceCreated = false;
079:                boolean isWSDLAvailable = false;
080:
081:                //see if the class file location is valid
082:                classFileFolder = new File(page1Bean.getFileLocation());
083:                if (!classFileFolder.exists()) {
084:                    throw new ProcessException(
085:                            "Specified Class file location is empty!!");
086:                }
087:                if (!classFileFolder.isDirectory()) {
088:                    throw new ProcessException(
089:                            "The class file location must be a folder!");
090:                }
091:
092:                //see if the  service.xml file is valid
093:                if (page2Bean.isManual()) {
094:                    serviceFile = new File(page2Bean.getManualFileName());
095:                    if (!serviceFile.exists()) {
096:                        throw new ProcessException(
097:                                "Specified Service XML file is missing!");
098:                    }
099:                } else {
100:                    ArrayList methodList = page2Bean.getSelectedMethodNames();
101:                    if (methodList.isEmpty()) {
102:                        throw new ProcessException(
103:                                "There are no methods selected to generate the service!!");
104:                    }
105:                    String currentUserDir = System.getProperty("user.dir");
106:                    String fileName = "services.xml";
107:                    ServiceXMLCreater serviceXMLCreater = new ServiceXMLCreater(
108:                            page2Bean.getServiceName(), page2Bean
109:                                    .getAutomaticClassName(), page2Bean
110:                                    .getSelectedMethodNames());
111:                    String serviceFileString = serviceXMLCreater.toString();
112:                    serviceFile = new File(currentUserDir + File.separator
113:                            + fileName);
114:                    if (serviceFile.exists()) {
115:                        serviceFile.delete();
116:                    }
117:                    FileWriter serviceXMLFileWriter = new FileWriter(
118:                            serviceFile, true);
119:                    BufferedWriter writer = new BufferedWriter(
120:                            serviceXMLFileWriter);
121:                    writer.write(serviceFileString);
122:                    writer.close();
123:
124:                    //                    new ServiceFileCreator().createServiceFile(
125:                    //                            page2Bean.getServiceName(),
126:                    //                            page2Bean.getAutomaticClassName(),
127:                    //                            page2Bean.getSelectedMethodNames());//create the file here
128:
129:                    isServiceCreated = true;
130:                }
131:
132:                //see if the WSDL file is available
133:                if (!wsdlBean.isSkip()) {
134:                    wsdlFile = new File(wsdlBean.getWSDLFileName());
135:                    if (!wsdlFile.exists()) {
136:                        throw new ProcessException(
137:                                "Specified WSDL file is missing!");
138:                    } else {
139:                        isWSDLAvailable = true;
140:                    }
141:                }
142:
143:                List fileList = new ArrayList();
144:                //check the libs
145:                if (libBean != null) {
146:                    String[] files = libBean.getFileList();
147:                    File tempFile = null;
148:                    if (files != null) {
149:                        for (int i = 0; i < files.length; i++) {
150:                            tempFile = new File(files[i]);
151:                            if (!tempFile.exists() || tempFile.isDirectory()) {
152:                                throw new ProcessException("Invalid libraries");
153:                            } else {
154:                                fileList.add(tempFile);
155:                            }
156:                        }
157:                    }
158:                }
159:
160:                outputFolder = new File(page3Bean.getOutputFolderName());
161:                outputFileName = page3Bean.getOutputFileName();
162:                if (!outputFileName.toLowerCase().endsWith(".jar")
163:                        && !outputFileName.toLowerCase().endsWith(".aar")) {
164:                    outputFileName = outputFileName + ".aar";
165:                }
166:
167:                File tempFileFolder = null;
168:                String xmlFilter = ".xml";
169:                String wsdlFilter = ".wsdl";
170:
171:                try {
172:                    //create a temporary directory and copy the files
173:                    tempFileFolder = new File("Service-copy");
174:                    if (tempFileFolder.exists()) {
175:                        deleteDir(tempFileFolder);
176:                    }
177:                    tempFileFolder.mkdir();
178:
179:                    File metaInfFolder = new File(tempFileFolder, "META-INF");
180:                    metaInfFolder.mkdir();
181:
182:                    File libFolder = new File(tempFileFolder, "lib");
183:                    libFolder.mkdir();
184:
185:                    FileCopier classFilecopier = new FileCopier();
186:                    //copy the classes
187:                    classFilecopier.copyFiles(classFileFolder, tempFileFolder,
188:                            page1Bean.getFilter());
189:
190:                    //copy the service.xml
191:                    FileCopier serviceXMLcopier = new FileCopier();
192:                    serviceXMLcopier.copyFiles(serviceFile, metaInfFolder,
193:                            xmlFilter);
194:
195:                    //copy the libs
196:                    FileCopier libCopier = new FileCopier();
197:                    for (int i = 0; i < fileList.size(); i++) {
198:                        libCopier.copyFiles((File) fileList.get(i), libFolder,
199:                                null);
200:                    }
201:
202:                    if (isWSDLAvailable) {
203:                        new FileCopier().copyFiles(wsdlFile, metaInfFolder,
204:                                wsdlFilter);
205:                    }
206:                    //jar the temp directory. the output folder will be created if missing
207:                    new JarFileWriter().writeJarFile(outputFolder,
208:                            outputFileName, tempFileFolder);
209:                } catch (Exception e) {
210:                    throw new ProcessException(e);
211:                } finally {
212:                    deleteDir(tempFileFolder);
213:                    if (isServiceCreated)
214:                        serviceFile.delete();
215:
216:                }
217:
218:            }
219:
220:            private boolean deleteDir(File dir) {
221:                if (dir.isDirectory()) {
222:                    String[] children = dir.list();
223:                    for (int i = 0; i < children.length; i++) {
224:                        boolean success = deleteDir(new File(dir, children[i]));
225:                        if (!success) {
226:                            return false;
227:                        }
228:                    }
229:                }
230:
231:                // The directory is now empty so delete it
232:                return dir.delete();
233:            }
234:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.