Source Code Cross Referenced for BootstrapServiceUnitManager.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » runtime » component » bootstrap » 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.runtime.component.bootstrap 
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:        package com.bostechcorp.cbesb.runtime.component.bootstrap;
025:
026:        import java.io.File;
027:        import java.io.IOException;
028:        import java.util.Collection;
029:        import java.util.Enumeration;
030:        import java.util.Iterator;
031:        import java.util.zip.ZipEntry;
032:        import java.util.zip.ZipFile;
033:
034:        import javax.jbi.management.DeploymentException;
035:
036:        import com.bostechcorp.cbesb.common.util.ErrorUtil;
037:        import com.bostechcorp.cbesb.common.util.EsbPathHelper;
038:        import com.bostechcorp.cbesb.common.util.FileUtil;
039:        import com.bostechcorp.cbesb.common.util.RuntimeClassLoader;
040:        import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.CbComponent;
041:        import com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging.CbServiceUnitManager;
042:
043:        /**
044:         * The installer service unit manager copies support files into the project workspace directory 
045:         * tree and adds entries into the runtime class path for the project.
046:         * 
047:         * The installer does not handle any messages, everything happens in deploy/undeploy. 
048:         */
049:        public class BootstrapServiceUnitManager extends CbServiceUnitManager {
050:
051:            public BootstrapServiceUnitManager(CbComponent component) {
052:                super (component, null, false);
053:            }
054:
055:            /* (non-Javadoc)
056:             * @see javax.jbi.component.ServiceUnitManager#deploy(java.lang.String, java.lang.String)
057:             */
058:            public synchronized String deploy(String serviceUnitName,
059:                    String serviceUnitRootPath) throws DeploymentException {
060:                try {
061:                    if (logger.isDebugEnabled()) {
062:                        logger.debug("Deploying service unit");
063:                    }
064:                    if (serviceUnitName == null
065:                            || serviceUnitName.length() == 0) {
066:                        throw new IllegalArgumentException(
067:                                "serviceUnitName should be non null and non empty");
068:                    }
069:                    if (getServiceUnit(serviceUnitName) != null) {
070:                        throw failure("deploy", "Service Unit '"
071:                                + serviceUnitName + "' is already deployed",
072:                                null);
073:                    }
074:                    // Expand zip files into the workspace directory tree
075:                    String ws = EsbPathHelper.getCbesbUiWorkSpace();
076:                    File targetDir = new File(ws);
077:                    File file = new File(serviceUnitRootPath);
078:                    if (file.exists() && file.isDirectory()) {
079:                        Collection<File> fileList = FileUtil.listFiles(file,
080:                                null, false);
081:                        for (Iterator it = fileList.iterator(); it.hasNext();) {
082:                            File f = (File) it.next();
083:                            if (f.getName().startsWith("ProjDef_")
084:                                    && f.getName().endsWith(".zip")) {
085:                                FileUtil.unpackArchiveCheckOverwrite(f,
086:                                        targetDir);
087:                            }
088:                        }
089:                    }
090:                    if (logger.isDebugEnabled()) {
091:                        logger.debug("Service unit deployed");
092:                    }
093:                    return createSuccessMessage("deploy");
094:                } catch (DeploymentException e) {
095:
096:                    ErrorUtil.printError("Exception in deploy(): ", e);
097:                    throw e;
098:                } catch (Exception e) {
099:
100:                    ErrorUtil.printError("Exception in deploy(): ", e);
101:                    throw failure("deploy", "Unable to deploy service unit", e);
102:                }
103:            }
104:
105:            /* (non-Javadoc)
106:             * @see javax.jbi.component.ServiceUnitManager#init(java.lang.String, java.lang.String)
107:             */
108:            public synchronized void init(String serviceUnitName,
109:                    String serviceUnitRootPath) throws DeploymentException {
110:                if (logger.isDebugEnabled())
111:                    logger.debug("Initializing service unit");
112:                // Add to runtime class path
113:                try {
114:                    addClasspaths(serviceUnitName, serviceUnitRootPath);
115:
116:                } catch (Exception ioe) {
117:                    throw new DeploymentException(ioe);
118:                }
119:            }
120:
121:            /* (non-Javadoc)
122:             * @see javax.jbi.component.ServiceUnitManager#start(java.lang.String)
123:             */
124:            public synchronized void start(String serviceUnitName)
125:                    throws DeploymentException {
126:                if (logger.isDebugEnabled())
127:                    logger.debug("Starting service unit");
128:
129:            }
130:
131:            /* (non-Javadoc)
132:             * @see javax.jbi.component.ServiceUnitManager#stop(java.lang.String)
133:             */
134:            public synchronized void stop(String serviceUnitName)
135:                    throws DeploymentException {
136:                if (logger.isDebugEnabled()) {
137:                    logger.debug("Stopping service unit");
138:                }
139:            }
140:
141:            /* (non-Javadoc)
142:             * @see javax.jbi.component.ServiceUnitManager#shutDown(java.lang.String)
143:             */
144:            public synchronized void shutDown(String serviceUnitName)
145:                    throws DeploymentException {
146:                if (logger.isDebugEnabled()) {
147:                    logger.debug("Shutting down service unit");
148:                }
149:
150:            }
151:
152:            /* (non-Javadoc)
153:             * Extract the SA name from the SU name using naming convention
154:             * the SA name is everything up to the first underscore
155:             */
156:            private String getSaNameFromSuName(String suName) {
157:                String saName = null;
158:                int underscorePosition = suName.indexOf("_");
159:                if (underscorePosition > 1)
160:                    saName = suName.substring(0, underscorePosition);
161:                return saName;
162:            }
163:
164:            /* (non-Javadoc)
165:             * @see javax.jbi.component.ServiceUnitManager#undeploy(java.lang.String, java.lang.String)
166:             */
167:            public synchronized String undeploy(String serviceUnitName,
168:                    String serviceUnitRootPath) throws DeploymentException {
169:                try {
170:                    if (logger.isDebugEnabled()) {
171:                        logger.debug("Undeploying service unit");
172:                    }
173:                    if (serviceUnitName == null
174:                            || serviceUnitName.length() == 0) {
175:                        throw new IllegalArgumentException(
176:                                "serviceUnitName should be non null and non empty");
177:                    }
178:                    // remove SA specific class path entries
179:                    String saName = getSaNameFromSuName(serviceUnitName);
180:                    if (saName != null)
181:                        RuntimeClassLoader.clearSaPath(saName);
182:                    return createSuccessMessage("undeploy");
183:                } catch (Exception e) {
184:                    ErrorUtil
185:                            .printError("Unable to undeploy service unit: ", e);
186:                    throw failure("undeploy",
187:                            "Unable to undeploy service unit", e);
188:                }
189:            }
190:
191:            /* (non-Javadoc)
192:             * Add runtime class path entries
193:             */
194:            private void addClasspaths(String serviceUnitName,
195:                    String serviceUnitRootPath) throws IOException {
196:                logger.debug("addClassPaths(" + serviceUnitName + ", "
197:                        + serviceUnitRootPath + ")");
198:
199:                if (serviceUnitName != null && serviceUnitName.length() > 0
200:                        && serviceUnitRootPath != null
201:                        && serviceUnitRootPath.length() > 0) {
202:
203:                    String saName = getSaNameFromSuName(serviceUnitName);
204:                    if (saName != null) {
205:                        String ws = EsbPathHelper.getCbesbUiWorkSpace();
206:                        File baseDir = new File(ws);
207:                        File file = new File(serviceUnitRootPath);
208:                        if (file.exists() && file.isDirectory()) {
209:                            File sazip = null;
210:                            File esbzip = null;
211:                            Collection<File> fileList = FileUtil.listFiles(
212:                                    file, null, false);
213:                            for (Iterator it = fileList.iterator(); it
214:                                    .hasNext();) {
215:                                File f = (File) it.next();
216:                                if (f.getName().equals("ProjDef_SA.zip")) {
217:                                    sazip = f;
218:                                } else if (f.getName().startsWith("ProjDef_")
219:                                        && f.getName().endsWith(".zip")) {
220:                                    esbzip = f;
221:                                }
222:                            }
223:                            if (sazip != null)
224:                                addToPath(sazip, baseDir, saName);
225:                            if (esbzip != null)
226:                                addToPath(esbzip, baseDir, saName);
227:                        }
228:
229:                    }
230:                }
231:            }
232:
233:            private void addToPath(File f, File baseDir, String saName)
234:                    throws IOException {
235:                ZipFile zipFile = new ZipFile(f);
236:                for (Enumeration entries = zipFile.entries(); entries
237:                        .hasMoreElements();) {
238:                    ZipEntry entry = (ZipEntry) entries.nextElement();
239:                    if (entry.getName().endsWith(".jar")) {
240:                        String newPathEntry = baseDir.getAbsolutePath()
241:                                + File.separator + entry.getName();
242:                        RuntimeClassLoader.addToPath(saName, newPathEntry);
243:                    }
244:                }
245:
246:            }
247:
248:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.