Source Code Cross Referenced for DeployAction.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » ui » componentflow » componentFlowEditor » diagram » actions » 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 » ESB » cbesb 1.2 » com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.actions 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ChainBuilder ESB
003:         *          Visual Enterprise Integration
004:         *  
005:         * Copyright (C) 2006 Bostech Corporation
006:         * 
007:         * This program is free software; you can redistribute it and/or modify it 
008:         * under the terms of the GNU General Public License as published by the 
009:         * Free Software Foundation; either version 2 of the License, or (at your option) 
010:         * any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful, 
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
014:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
015:         * for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License along with 
018:         * this program; if not, write to the Free Software Foundation, Inc., 
019:         * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020:         *
021:         *
022:         * $Id$
023:         */
024:
025:        package com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.actions;
026:
027:        import java.io.File;
028:        import java.io.FileFilter;
029:        import java.io.FileNotFoundException;
030:        import java.io.IOException;
031:        import java.util.ArrayList;
032:        import java.util.List;
033:
034:        import org.eclipse.core.resources.IFile;
035:        import org.eclipse.core.resources.IProject;
036:        import org.eclipse.core.resources.IResource;
037:        import org.eclipse.core.runtime.Path;
038:        import org.eclipse.jface.action.IAction;
039:        import org.eclipse.jface.viewers.ISelection;
040:        import org.eclipse.jface.viewers.StructuredSelection;
041:        import org.eclipse.swt.SWT;
042:        import org.eclipse.swt.widgets.MessageBox;
043:        import org.eclipse.ui.IActionDelegate;
044:        import org.eclipse.ui.IEditorActionDelegate;
045:        import org.eclipse.ui.IEditorPart;
046:        import org.eclipse.ui.IObjectActionDelegate;
047:        import org.eclipse.ui.IViewActionDelegate;
048:        import org.eclipse.ui.IViewPart;
049:        import org.eclipse.ui.IWorkbenchPart;
050:        import org.eclipse.ui.PlatformUI;
051:        import org.jdom.JDOMException;
052:
053:        import com.bostechcorp.cbesb.common.i18n.I18N;
054:        import com.bostechcorp.cbesb.common.i18n.Messages;
055:        import com.bostechcorp.cbesb.common.sa.service.ServiceAssembly;
056:        import com.bostechcorp.cbesb.common.util.EsbPathHelper;
057:        import com.bostechcorp.cbesb.common.util.FileUtil;
058:        import com.bostechcorp.cbesb.common.util.generators.wsdl.generators.HTTPPublicWsdlUpdater;
059:        import com.bostechcorp.cbesb.common.util.macro.MacroUtil;
060:        import com.bostechcorp.cbesb.common.util.project.ProjectUtil;
061:        import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.BaseElement;
062:        import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.HTTP;
063:        import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.HttpProvider;
064:        import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.RoleType;
065:        import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorDiagramEditor;
066:        import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.part.ComponentFlowEditorResourceGenerator;
067:        import com.bostechcorp.cbesb.ui.componentflow.componentFlowEditor.diagram.wizards.httpExtra.io.WsdlPorting;
068:        import com.bostechcorp.cbesb.ui.util.MsgUtil;
069:        import com.bostechcorp.cbesb.ui.util.ViewUtil;
070:        import com.bostechcorp.cbesb.ui.util.log.ESBLog;
071:
072:        public class DeployAction implements  IObjectActionDelegate {
073:            /**
074:             * The currently selected object in the active view
075:             */
076:            private ISelection selection;
077:
078:            private IWorkbenchPart targetPart;
079:
080:            /**
081:             * Sets the active part for the delegate. This method will be called every
082:             * time the action appears in a context menu. The targetPart may change with
083:             * each invocation.
084:             */
085:            public void setActivePart(IAction action, IWorkbenchPart part) {
086:                this .targetPart = part;
087:            }
088:
089:            /**
090:             * Initializes this action delegate with the view it will work in.
091:             * 
092:             * @param view
093:             *            the view that provides the context for this delegate
094:             * @see IViewActionDelegate#init(IViewPart)
095:             */
096:            public void init(IViewPart view) {
097:                // this.view = view;
098:            }
099:
100:            /**
101:             * Sets the active editor for the delegate. Implementors should disconnect
102:             * from the old editor, connect to the new editor, and update the action to
103:             * reflect the new editor.
104:             * 
105:             * @param action
106:             *            the action proxy that handles presentation portion of the
107:             *            action
108:             * @param editor
109:             *            the new editor target
110:             * @see IEditorActionDelegate #setActiveEditor(IAction, IEditorPart)
111:             */
112:            public void setActiveEditor(IAction action, IEditorPart editor) {
113:
114:            }
115:
116:            /**
117:             * Notifies this action delegate that the selection in the workbench has
118:             * changed.
119:             * 
120:             * @param action
121:             *            the action proxy that handles presentation portion of the
122:             *            action
123:             * @param selection
124:             *            the current selection, or <code>null</code> if there is no
125:             *            selection.
126:             * @see IActionDelegate#selectionChanged(IAction, ISelection)
127:             */
128:            public void selectionChanged(IAction action, ISelection selection) {
129:                this .selection = selection;
130:                action.setEnabled(!selection.isEmpty());
131:            }
132:
133:            /**
134:             * Called when the user has selected this action to be executed.
135:             */
136:            public void run(IAction action) {
137:                if (!(this .targetPart instanceof  ComponentFlowEditorDiagramEditor)) {
138:                    MsgUtil.warningMsg(I18N.getString(Messages.DEPLOY_TIP));
139:                    return;
140:                }
141:                // first, asking to save
142:                MessageBox mbQuestion = new MessageBox(PlatformUI
143:                        .getWorkbench().getActiveWorkbenchWindow().getShell(),
144:                        SWT.ICON_QUESTION | SWT.YES | SWT.NO | SWT.CANCEL);
145:
146:                mbQuestion.setText("Resource save");
147:                if (PlatformUI.getWorkbench().getActiveWorkbenchWindow()
148:                        .getActivePage().getActiveEditor()
149:                        .isSaveOnCloseNeeded()) {
150:                    mbQuestion.setMessage("\'"
151:                            + PlatformUI.getWorkbench()
152:                                    .getActiveWorkbenchWindow().getActivePage()
153:                                    .getActiveEditor().getTitle()
154:                            + "\' have been modified. Save changes?");
155:                    int mqResult = mbQuestion.open();
156:                    if (mqResult == SWT.YES) {
157:                        PlatformUI.getWorkbench().getActiveWorkbenchWindow()
158:                                .getActivePage().getActiveEditor().doSave(null);
159:                    } else if (mqResult == SWT.CANCEL) {
160:                        return;
161:                    }
162:                }
163:                // doing the rest of the job
164:                ViewUtil.displayConsoleView(ESBLog.ID);
165:                ComponentFlowEditorDiagramEditor editor = (ComponentFlowEditorDiagramEditor) this .targetPart;
166:
167:                StructuredSelection sele = (StructuredSelection) selection;
168:                String saPath = "";
169:                String suPath = "";
170:                IProject project = null;
171:                if (sele.getFirstElement() instanceof  IProject) {
172:                    project = (IProject) sele.getFirstElement();
173:
174:                } else if (sele.getFirstElement() instanceof  IFile) {
175:                    IFile f = (IFile) sele.getFirstElement();
176:                    project = f.getProject();
177:                }
178:                if (project != null) {
179:                    String projLocation = project.getLocation().toOSString();
180:                    String projName = project.getName();
181:                    // refreshing the project
182:                    com.bostechcorp.cbesb.ui.util.ProjectUtil
183:                            .refreshProject(projName);
184:                    //
185:
186:                    saPath = new File(projLocation + File.separator + "src"
187:                            + File.separator + "sa").toString();
188:                    suPath = (new File(saPath)).getParent() + File.separator
189:                            + "SUs";
190:
191:                    try {
192:                        clearSUDirectory(suPath);
193:                        ComponentFlowEditorResourceGenerator rg = new ComponentFlowEditorResourceGenerator(
194:                                null, editor.getDiagramRoot(), editor
195:                                        .getEditorInput());
196:                        ServiceAssembly assembly = rg.loadServiceAssembly();
197:                        if (assembly == null)
198:                            return;
199:                        assembly.deploy(saPath, suPath);
200:
201:                        ArrayList<HTTP> clientList = getAllHttpClientWithSoap();
202:                        ArrayList<HTTP> list = getAllHttpServerWithSoap();
203:                        // Dialog was shown to export the Public WSDL
204:                        // Copy public wsdl & afferent files (XSD's) automatically
205:                        exportWSDLDefinitions(list, projLocation);
206:                        handleClientsWSDLDefinitions(clientList, projLocation,
207:                                project);
208:
209:                        cbesb_deploy(projName, projLocation);
210:                        project.refreshLocal(IResource.DEPTH_INFINITE, null);
211:
212:                    } catch (Exception ex) {
213:                        ex.printStackTrace();
214:                        MsgUtil.warningMsg(ex.toString());
215:                        return;
216:                    }
217:                    MsgUtil.confirmMsg(PlatformUI.getWorkbench()
218:                            .getActiveWorkbenchWindow().getShell(), I18N
219:                            .getString(Messages.DEPLOY_SUCCESS));
220:                }
221:            }
222:
223:            private ArrayList<HTTP> getAllHttpClientWithSoap() {
224:                ArrayList<HTTP> list = new ArrayList<HTTP>();
225:                ComponentFlowEditorDiagramEditor editor = (ComponentFlowEditorDiagramEditor) PlatformUI
226:                        .getWorkbench().getActiveWorkbenchWindow()
227:                        .getActivePage().getActiveEditor();
228:                List list_ele = editor.getDiagramRoot()
229:                        .getComponentFlowEditorElements();
230:                // List list_dec = editor.getDiagramRoot().getDecorativeModelElements();
231:                for (int i = 0; i < list_ele.size(); i++) {
232:                    BaseElement object = (BaseElement) list_ele.get(i);
233:                    if (object instanceof  HTTP) {
234:                        HTTP httpModel = (HTTP) object;
235:                        if (httpModel.getRole() == RoleType
236:                                .get(RoleType.PROVIDER)
237:                                || httpModel.getRole() == RoleType
238:                                        .get(RoleType.BOTH)) {
239:                            if (httpModel.getHttpProvider().isSoapEnabled()) {
240:                                list.add(httpModel);
241:                            }
242:                        }
243:                    }
244:                }
245:                return list;
246:            }
247:
248:            /**
249:             * Copy the WSDL from src/wsdl/{SU_NAME} into src/SUs/{SU_NAME}/wsdlPublic
250:             * for each HTTP server component Service Unit. <br/> Actually this method
251:             * will copy all files from source folder, excluding .customWSDL <br/>
252:             * According to Review 9-11-07 it will also update the address Tag <br/> Ex:
253:             * from "http://localhost:8899/test/" to "http://localhost:8899/test/<b>service/HTTP_Service</b>"
254:             * 
255:             * @param list
256:             * @param projLocation
257:             * @throws IOException
258:             * @throws FileNotFoundException
259:             */
260:            private void exportWSDLDefinitions(ArrayList<HTTP> list,
261:                    String projLocation) throws FileNotFoundException,
262:                    IOException {
263:                FileFilter filter = new FileFilter() {
264:                    public boolean accept(File pathname) {
265:                        return !pathname.getName().endsWith(".customWsdl");
266:                    }
267:                };
268:                String saName = new Path(projLocation).lastSegment();
269:
270:                for (HTTP http : list) {
271:                    String dirname = projLocation;
272:                    if (!dirname.endsWith(File.separator))
273:                        dirname += File.separator;
274:                    File dir = new File(dirname + "src" + File.separator
275:                            + "wsdl" + File.separator + http.getName());
276:                    FileUtil.buildDirectory(dir);
277:                    // dir.mkdirs();
278:                    // take all the dirs in wsdl
279:
280:                    String newPatString = dirname + "src" + File.separator
281:                            + "SUs" + File.separator + saName + "_"
282:                            + http.getName() + File.separator + "wsdlPublic"
283:                            + File.separator;
284:                    FileUtil.copyFilesRecursively(dir.getAbsolutePath(),
285:                            newPatString, filter);
286:                }
287:            }
288:
289:            /**
290:             * 
291:             * Copy the WSDL from src/wsdl/{SU_NAME} into src/SUs/{SU_NAME}/wsdlPublic
292:             * for each HTTP server component Service Unit. <br/> Actually this method
293:             * will copy all files from source folder, excluding .customWSDL <br/>
294:             * According to Review 9-11-07 it will also update the address Tag <br/> Ex:
295:             * from "http://localhost:8899/test/" to "http://localhost:8899/test/<b>service/HTTP_Service</b>"
296:             * <br/>
297:             * <i>Note:</i> According to recursive check implementation, files are copyed after
298:             * the dependency check. So all xsd mentioned in wsdl file are copyed and all their 
299:             * dependent xsd  files.
300:             * @param list
301:             * @param projLocation
302:             * @throws Exception
303:             */
304:            @SuppressWarnings("unused")
305:            private void handleClientsWSDLDefinitions(ArrayList<HTTP> list,
306:                    String projLocation, IProject project) throws Exception {
307:                FileFilter filter = new FileFilter() {
308:                    public boolean accept(File pathname) {
309:                        return !pathname.getName().endsWith(".customWsdl");
310:                    }
311:                };
312:
313:                String saName = new Path(projLocation).lastSegment();
314:
315:                for (HTTP http : list) {
316:                    String wsdlFileName;
317:                    String dirname = projLocation;
318:                    if (!dirname.endsWith(File.separator))
319:                        dirname += File.separator;
320:                    File dir = null;
321:                    if (http.getProvider() != null) {
322:                        if (http.getProvider() instanceof  HttpProvider) {
323:                            wsdlFileName = EsbPathHelper
324:                                    .getFullPathForDef(MacroUtil
325:                                            .resolveBuiltinMacro(
326:                                                    ((HttpProvider) http
327:                                                            .getProvider())
328:                                                            .getImportedWSDL(),
329:                                                    saName));
330:                            dir = new File(new Path(wsdlFileName)
331:                                    .removeLastSegments(1).toString());
332:                        } else {
333:                            throw new Exception(
334:                                    "Http provider(Client) side is not Instance of HttpProvider, it is instabce of "
335:                                            + http.getProvider().getClass()
336:                                                    .getName()
337:                                            + "It is imposible to get to this situation!");
338:                        }
339:                    } else {
340:                        throw new Exception(
341:                                "Http provider(Client) side is Null, (It is imposible to get in this situation!)");
342:                    }
343:
344:                    String newPatString = dirname + "src" + File.separator
345:                            + "SUs" + File.separator + saName + "_"
346:                            + http.getName() + File.separator + "wsdlPublic";
347:                    //Copying files recursively is the best solution for 99.99% of cases 
348:                    //because we will have all the time only one wsdl in src/wsdl/{su_Name}
349:                    //FileUtil.copyFilesRecursively(dir.getAbsolutePath(), newPatString,filter);
350:
351:                    // now we will copy recursively files dependent to the wsdl
352:                    WsdlPorting.doCopyWsdl(wsdlFileName, newPatString);
353:                }
354:            }
355:
356:            @SuppressWarnings("unused")
357:            private void updateAddress(String wsdlFileName) {
358:                try {
359:                    HTTPPublicWsdlUpdater.updateAllAdressTags(wsdlFileName);
360:                } catch (JDOMException e) {
361:                    e.printStackTrace();
362:                    MsgUtil.warningMsg(e.toString());
363:                } catch (IOException e) {
364:                    e.printStackTrace();
365:                    MsgUtil.warningMsg(e.toString());
366:                } catch (Exception e) {
367:                    e.printStackTrace();
368:                    MsgUtil.warningMsg(e.toString());
369:                }
370:            }
371:
372:            private void clearSUDirectory(String suPath) throws Exception {
373:                File suFile = new File(suPath);
374:                boolean userFiles = false;
375:                if (suFile != null && suFile.exists()) {
376:                    if (suFile.isDirectory()) {
377:                        File[] files = suFile.listFiles();
378:                        if (files != null) {
379:                            for (int i = 0; i < files.length; i++) {
380:                                if (files[i].getName().equals("User-Files")) {
381:                                    userFiles = true;
382:                                    continue;
383:                                }
384:                                FileUtil.deleteFile(files[i]);
385:                            }
386:                        }
387:                    }
388:                    if (!userFiles) {
389:                        File userFile = new File(suPath + File.separator
390:                                + "User-Files");
391:                        FileUtil.buildDirectory(userFile);
392:                    }
393:                } else {
394:                    FileUtil.buildDirectory(suFile);
395:                    File userFile = new File(suPath + File.separator
396:                            + "User-Files");
397:                    FileUtil.buildDirectory(userFile);
398:                }
399:            }
400:
401:            private ArrayList<HTTP> getAllHttpServerWithSoap() {
402:                // TODO : WARINING this function contains more http components than is
403:                // required. to be tested
404:
405:                ArrayList<HTTP> list = new ArrayList<HTTP>();
406:                ComponentFlowEditorDiagramEditor editor = (ComponentFlowEditorDiagramEditor) PlatformUI
407:                        .getWorkbench().getActiveWorkbenchWindow()
408:                        .getActivePage().getActiveEditor();
409:                List list_ele = editor.getDiagramRoot()
410:                        .getComponentFlowEditorElements();
411:                // List list_dec = editor.getDiagramRoot().getDecorativeModelElements();
412:                for (int i = 0; i < list_ele.size(); i++) {
413:                    BaseElement object = (BaseElement) list_ele.get(i);
414:                    if (object instanceof  HTTP) {
415:                        HTTP httpModel = (HTTP) object;
416:                        if (httpModel.getRole() == RoleType
417:                                .get(RoleType.CONSUMER)
418:                                || httpModel.getRole() == RoleType
419:                                        .get(RoleType.BOTH)) {
420:                            if (httpModel.getHttpConsumer().isSoapEnabled()) {
421:                                list.add(httpModel);
422:                            }
423:                        }
424:                    }
425:                }
426:                return list;
427:            }
428:
429:            private void cbesb_deploy(String projName, String projLocation)
430:                    throws Exception {
431:                ProjectUtil.buildProject(projLocation);
432:                ProjectUtil.buildProjectDefGen(projName);
433:                ProjectUtil.buildSa(projLocation);
434:                ProjectUtil.buildDeploy(projName);
435:
436:            }
437:        }
w__w___w___.___j__a___va_2___s__.__c_om_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.