KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > autodeploy > AutoDirReDeployer


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 /*
25  * AutoDirReDeployer.java
26  *
27  * @author bnevins
28  * Simple derived class of AutoDeployer for auto-redeploy via "touch .reload"
29  */

30
31 package com.sun.enterprise.deployment.autodeploy;
32
33 import java.io.File JavaDoc;
34 import java.util.Properties JavaDoc;
35 import com.sun.enterprise.deployment.backend.DeploymentRequest;
36 import com.sun.enterprise.deployment.util.DeploymentProperties;
37 import com.sun.enterprise.util.io.FileSource;
38 import com.sun.enterprise.util.io.FileUtils;
39 import com.sun.enterprise.util.StringUtils;
40 import com.sun.enterprise.deployment.backend.IASDeploymentException;
41 import com.sun.enterprise.util.i18n.StringManager;
42
43 public class AutoDirReDeployer extends AutoDeployer
44 {
45     public AutoDirReDeployer(DeploymentRequest req)
46     {
47         if(req == null)
48             throw new IllegalArgumentException JavaDoc("nullarg");
49         
50         this.req = req;
51     }
52     
53     public boolean redeploy() throws AutoDeploymentException
54     {
55                 boolean status = false;
56                 int deployResult = DEPLOY_FAILURE;
57         try
58         {
59             init();
60             verify();
61             File JavaDoc source = req.getFileSource().getFile();
62             String JavaDoc name = req.getName();
63
64                 deployResult = deploy(source, name);
65         }
66         catch(AutoDeploymentException ade)
67         {
68             throw ade;
69         }
70         catch(Exception JavaDoc e)
71         {
72             throw new AutoDeploymentException("Error in AutoDirReDeployer.redeploy", e);
73         }
74                 status = (deployResult == DEPLOY_SUCCESS);
75                 return status;
76     }
77
78     /**
79      * I had to override this method because of a bunch of AutoDeployer-specific
80      * error handling that isn't appropriate here
81      */

82     
83     boolean invokeDeploymentService(File JavaDoc deployablefile, String JavaDoc action, Object JavaDoc[] params, String JavaDoc[] signature)
84             throws AutoDeploymentException
85     {
86                 boolean status = false;
87         try
88         {
89             Object JavaDoc result = getMBeanServer().invoke(getMBeanName(), action, params, signature);
90                         status = parseResult(result);
91         }
92         catch(AutoDeploymentException de)
93         {
94             throw de;
95         }
96         catch(Exception JavaDoc e)
97         {
98             String JavaDoc msg = "Error in AutoReDeployer.invokeDeploymentService";
99             throw new AutoDeploymentException(msg, e);
100         }
101         return status;
102     }
103
104     protected Properties JavaDoc getUndeployActionProperties(String JavaDoc name){
105         DeploymentProperties dProps =
106             (DeploymentProperties)super.getUndeployActionProperties(name);
107         dProps.setReload(true);
108         return (Properties JavaDoc)dProps;
109     }
110
111     ///////////////////////////////////////////////////////////////////////////
112

113     private void verify() throws AutoDeploymentException
114     {
115         // make sure we have valid info.
116

117         // first -- only ejb modules and J2EE Apps are supported
118
if(!req.isApplication() && !req.isEjbModule() && !req.isWebModule())
119             throw new AutoDeploymentException(getString("wrongType"));
120
121         // make sure it is a directory. Don't worry about NPE here!
122
if(!FileUtils.safeIsDirectory(req.getFileSource().getFile()))
123             throw new AutoDeploymentException(getString("notDir") + req.getFileSource().getFile().getAbsolutePath());
124             
125         // check that there is a valid name.
126
if(!StringUtils.ok(req.getName()))
127             throw new AutoDeploymentException(getString("noName"));
128     }
129     
130     ///////////////////////////////////////////////////////////////////////////
131

132     private String JavaDoc getString(String JavaDoc s)
133     {
134         return localStrings.getString("enterprise.deployment.AutoDirRedeploy." + s);
135     }
136     
137     ///////////////////////////////////////////////////////////////////////////
138

139     
140     private DeploymentRequest req;
141     private static StringManager localStrings = StringManager.getManager(AutoDirReDeployer.class);
142 }
143
144
Popular Tags