Source Code Cross Referenced for RemoteDeployer.java in  » J2EE » ow2-easybeans » org » ow2 » easybeans » deployer » 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 » J2EE » ow2 easybeans » org.ow2.easybeans.deployer 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * EasyBeans
003:         * Copyright (C) 2006-2007 Bull S.A.S.
004:         * Contact: easybeans@ow2.org
005:         *
006:         * This library is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU Lesser General Public
008:         * License as published by the Free Software Foundation; either
009:         * version 2.1 of the License, or any later version.
010:         *
011:         * This library is distributed in the hope that it will be useful,
012:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:         * Lesser General Public License for more details.
015:         *
016:         * You should have received a copy of the GNU Lesser General Public
017:         * License along with this library; if not, write to the Free Software
018:         * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
019:         * USA
020:         *
021:         * --------------------------------------------------------------------------
022:         * $Id: RemoteDeployer.java 1970 2007-10-16 11:49:25Z benoitf $
023:         * --------------------------------------------------------------------------
024:         */package org.ow2.easybeans.deployer;
025:
026:        import java.io.File;
027:        import java.io.FileNotFoundException;
028:        import java.io.FileOutputStream;
029:        import java.io.IOException;
030:
031:        import org.ow2.easybeans.api.EZBServer;
032:        import org.ow2.easybeans.deployable.DeployerFactory;
033:        import org.ow2.util.ee.deploy.api.archive.IArchive;
034:        import org.ow2.util.ee.deploy.api.deployable.IDeployable;
035:        import org.ow2.util.ee.deploy.api.deployer.DeployerException;
036:        import org.ow2.util.ee.deploy.api.deployer.IDeployer;
037:        import org.ow2.util.ee.deploy.impl.archive.ArchiveManager;
038:        import org.ow2.util.ee.deploy.impl.helper.DeployableHelper;
039:        import org.ow2.util.ee.deploy.impl.helper.DeployableHelperException;
040:        import org.ow2.util.log.Log;
041:        import org.ow2.util.log.LogFactory;
042:
043:        /**
044:         * Deployer allowing deploy/undeploy functions on this container.
045:         * @author Florent Benoit
046:         */
047:        public final class RemoteDeployer implements  IRemoteDeployer {
048:
049:            /**
050:             * Folder to create in tmp folder.
051:             */
052:            private static final String DEFAULT_FOLDER = "EasyBeans-"
053:                    + RemoteDeployer.class.getSimpleName();
054:
055:            /**
056:             * Logger.
057:             */
058:            private static Log logger = LogFactory.getLog(RemoteDeployer.class);
059:
060:            /**
061:             * Link to a local deployer.
062:             */
063:            private IDeployer deployer = null;
064:
065:            /**
066:             * Build a Deployer for the given Embedded instance.
067:             * @param embedded the Server instance.
068:             * @throws DeployerException if the local deployer can't be accessed.
069:             */
070:            public RemoteDeployer(final EZBServer embedded)
071:                    throws DeployerException {
072:                // Get local deployer
073:                this .deployer = DeployerFactory.getDeployer(embedded);
074:            }
075:
076:            /**
077:             * Dump the given bytes to a local file and then return the path to this
078:             * file.
079:             * @param fileName the name of the file to deploy
080:             * @param fileContent the content of the given file
081:             * @return the path of the deployed file
082:             */
083:            public String dumpFile(final String fileName,
084:                    final byte[] fileContent) {
085:                logger
086:                        .info(
087:                                "Dump file to the local filesystem with the name = ''{0}''.",
088:                                fileName);
089:
090:                // Dump the file on a temporary file
091:                File rootFolder = new File(System.getProperty("java.io.tmpdir")
092:                        + File.separator + DEFAULT_FOLDER);
093:                rootFolder.mkdirs();
094:
095:                // Create file in this folder
096:                File file = new File(rootFolder, fileName);
097:
098:                // Dump the content on this file
099:                FileOutputStream out = null;
100:                try {
101:                    out = new FileOutputStream(file);
102:                } catch (FileNotFoundException e) {
103:                    throw new IllegalStateException(
104:                            "Cannot build an outputstream on file '" + file
105:                                    + "'.", e);
106:                }
107:
108:                // Write the array of bytes
109:                try {
110:                    out.write(fileContent);
111:                } catch (IOException e) {
112:                    throw new IllegalStateException(
113:                            "Cannot write byte in outputstream", e);
114:                }
115:
116:                // Close resource
117:                try {
118:                    out.close();
119:                } catch (IOException e) {
120:                    throw new IllegalStateException("Cannot close outpustream",
121:                            e);
122:                }
123:
124:                // return the local dump of the file
125:                return file.getPath();
126:            }
127:
128:            /**
129:             * Dump the given bytes to a local file and then deploy this file to a local deployer.
130:             * @param fileName the name of the file to deploy
131:             * @param fileContent the content of the given file
132:             */
133:            public void deployFile(final String fileName,
134:                    final byte[] fileContent) {
135:
136:                // Deploy this local file
137:                deploy(dumpFile(fileName, fileContent));
138:            }
139:
140:            /**
141:             * Deploy a file to a local deployer.
142:             * @param fileName the name of the file to deploy
143:             */
144:            public void deploy(final String fileName) {
145:
146:                logger.info("Deploying ''{0}''", fileName);
147:
148:                IDeployable deployable = getDeployable(fileName);
149:
150:                try {
151:                    deployer.deploy(deployable);
152:                } catch (DeployerException e) {
153:                    logger.error("Cannot deploy the deployable ''{0}''",
154:                            deployable, e);
155:                    throw new RuntimeException("Cannot deploy the deployable '"
156:                            + deployable + "' : " + e.getMessage());
157:                }
158:            }
159:
160:            /**
161:             * Gets a deployable for a given file.
162:             * @param fileName the name of the file
163:             * @return a deployable for the given filename
164:             */
165:            protected IDeployable getDeployable(final String fileName) {
166:                // Get File
167:                File file = new File(fileName);
168:
169:                // check file
170:                if (!file.exists()) {
171:                    throw new RuntimeException("The file '" + fileName
172:                            + "' is not present on the filesystem.");
173:                }
174:
175:                // Else, get the deployable
176:                IArchive archive = ArchiveManager.getInstance()
177:                        .getArchive(file);
178:                if (archive == null) {
179:                    logger.error(
180:                            "No archive found for the invalid file ''{0}''",
181:                            file);
182:                    throw new RuntimeException(
183:                            "No archive found for the invalid file '" + file
184:                                    + "'.");
185:                }
186:                IDeployable deployable;
187:                try {
188:                    deployable = DeployableHelper.getDeployable(archive);
189:                } catch (DeployableHelperException e) {
190:                    logger.error(
191:                            "Cannot get a deployable for the archive ''{0}''",
192:                            archive, e);
193:                    throw new RuntimeException(
194:                            "Cannot get a deployable for the archive '"
195:                                    + archive + "' : " + e.getMessage());
196:                }
197:
198:                return deployable;
199:            }
200:
201:            /**
202:             * Undeploy a file by using a local deployer.
203:             * @param fileName the name of the file to undeploy
204:             */
205:            public void undeploy(final String fileName) {
206:                logger.info("Undeploying ''{0}''", fileName);
207:
208:                IDeployable deployable = getDeployable(fileName);
209:
210:                try {
211:                    deployer.undeploy(deployable);
212:                } catch (DeployerException e) {
213:                    logger.error("Cannot undeploy the deployable ''{0}''",
214:                            deployable, e);
215:                    throw new RuntimeException(
216:                            "Cannot undeploy the deployable '" + deployable
217:                                    + "' : " + e.getMessage());
218:                }
219:            }
220:
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.