KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > bridge > DirectoryDeployment


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.j2ee.sun.bridge;
21 import java.io.File JavaDoc;
22 import javax.enterprise.deploy.spi.status.DeploymentStatus JavaDoc;
23 import javax.enterprise.deploy.spi.status.ProgressEvent JavaDoc;
24 import javax.enterprise.deploy.spi.status.ProgressListener JavaDoc;
25
26 import org.netbeans.modules.j2ee.deployment.plugins.api.IncrementalDeployment;
27 import org.netbeans.modules.j2ee.deployment.plugins.api.AppChangeDescriptor;
28
29
30 import javax.enterprise.deploy.spi.Target JavaDoc;
31 import javax.enterprise.deploy.spi.TargetModuleID JavaDoc;
32 import javax.enterprise.deploy.spi.DeploymentManager JavaDoc;
33 import javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc;
34 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
35 import javax.enterprise.deploy.shared.ModuleType JavaDoc;
36 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
37 import org.netbeans.modules.j2ee.sun.api.SunDeploymentManagerInterface;
38 import org.netbeans.modules.j2ee.sun.api.SunDeploymentConfigurationInterface;
39
40 /**
41  *
42  * @author Ludo Champenois
43  * @author Vince Kraemer
44  */

45 public class DirectoryDeployment extends IncrementalDeployment {
46     
47     private SunDeploymentManagerInterface dm;
48
49
50     /** Creates a new instance of DirectoryDeployment */
51     public DirectoryDeployment() {
52     }
53
54    public DirectoryDeployment(DeploymentManager JavaDoc manager) {
55        setDeploymentManager( manager);
56     }
57
58
59   
60     
61     
62     
63     /** Return a bogus name to satisfy the API. A file may be created by the
64      * tool side. That file will be returned to this object in
65      * writeDeploymentPlanFiles. I will use it to find the directory for
66      * writing the deployment descriptors and then delete it from that
67      * directory.
68      *
69      * @param targetModuleID The module id
70      * @return a single, unique file name.
71      */

72     public String JavaDoc[] getDeploymentPlanFileNames(ModuleType JavaDoc type) {
73         String JavaDoc[] s;
74         if (type==null){
75             throw new IllegalArgumentException JavaDoc("invalid null argumment");
76         }
77         else if(type.equals(ModuleType.WAR)){
78             s = new String JavaDoc[] { "WEB-INF/sun-web.xml" };
79         }
80         else if(type.equals(ModuleType.EJB)){
81             s = new String JavaDoc[] { "META-INF/sun-ejb-jar.xml", "META-INF/sun-cmp-mappings.xml" };
82         }
83         else if(type.equals(ModuleType.EAR)){
84             s = new String JavaDoc[] { "META-INF/sun-application.xml" };
85         }
86         else if(type.equals(ModuleType.RAR)){
87             s = new String JavaDoc[] { "META-INF/sun-connector.xml" };
88         }
89         else if(type.equals(ModuleType.CAR)){
90             s = new String JavaDoc[] { "META-INF/sun-application-client.xml" };
91         }
92       
93         else{
94             s = new String JavaDoc[] { ".timestamp" };
95         }
96
97         return s;
98     }
99     
100     /** Determine where a module is going to be copied to.
101      * If the target is not a local instance, return null.
102      *
103      * If the bug 4946433 still exists, return null. This will disable
104      * in-place deployment for J2EE apps.
105      *
106      * @param module The module being deployed
107      * @return The name of a directory.
108      */

109     public File JavaDoc getDirectoryForModule(TargetModuleID JavaDoc module) {
110         if (null == dm){
111             throw new IllegalStateException JavaDoc("invalid dm value");
112         }
113 //Ludo move to netbeans 5.0: not used
114
// if (isWar(module)){ //use the same dir as the source web app.Even faster that copying binaries
115
// return null; ////new for NB3.6: In palce deployment
116
// }
117

118 // if (dm.isLocal()) {
119
// boolean isApp = isApp(module);
120
// if (!isApp || module.getChildTargetModuleID() != null) {
121
// appDir = new File(getApplicationsDir(), getModuleRelativePath(module));
122
// if (! appDir.exists())
123
// appDir.mkdirs();
124
// }
125
//
126
// }
127
// return appDir;
128
return null;
129     }
130     
131     
132     
133     /**
134      * @param manager
135      */

136     public void setDeploymentManager(DeploymentManager JavaDoc manager) {
137         if (null == manager){
138             throw new IllegalArgumentException JavaDoc("invalid null argumment");
139         }
140         if (manager instanceof SunDeploymentManagerInterface){
141             this.dm = (SunDeploymentManagerInterface) manager;
142         }
143         else{
144             throw new IllegalArgumentException JavaDoc("setDeploymentManager: Invalid manager type, expecting SunDeploymentManager and got "+manager.getClass().getName());
145         }
146     }
147     
148     
149     /**
150      * @param targetModuleID
151      * @param appChangeDescriptor
152      * @return a progress object representing the incrmental dpeloy action.
153      */

154     final public ProgressObject JavaDoc incrementalDeploy( final TargetModuleID JavaDoc tmid, AppChangeDescriptor aCD) {
155         ProgressObject JavaDoc retVal = null;
156         try {
157             
158             dm.grabInnerDM(false);
159             DirectoryDeploymentFacility ddf = new DirectoryDeploymentFacility(dm.getHost(),dm.getPort(),dm.getUserName(),dm.getPassword(),dm.isSecure());
160             retVal = ddf.incrementalDeploy(tmid);
161             if (null != retVal) {
162                 retVal.addProgressListener(new Releaser(dm));
163             }
164         } finally {
165             if (null == retVal) {
166                 dm.releaseInnerDM();
167             }
168         }
169         return retVal; //ddf. incrementalDeploy( tmid);
170

171     }
172     
173
174
175  
176     
177     /**
178      * Get the URI pointing to location of child module inside a application archive.
179      * For a root module, service provider does not need to override this method.
180      *
181      * @param module TargetModuleID of the child module
182      * @return its relative path within application archive, returns null by
183      * default (for standalone module)
184      */

185     public String JavaDoc getModuleUrl(TargetModuleID JavaDoc module){
186
187         return AppServerBridge.getModuleUrl (module);
188     }
189     
190     
191
192
193     
194     /**
195      * First time deployment file distribution.
196      * Before this method is called the files are copied into the target
197      * folder provided by plugin.
198      * @param target target of deployment
199      * @param app the app to deploy
200      * @param configuration server specific data for deployment
201      * @param dir the destination directory for the given deploy app
202      * @return the object for feedback on progress of deployment
203      */

204     public ProgressObject JavaDoc initialDeploy(Target JavaDoc target,
205                 DeployableObject JavaDoc deployableObject,
206                 DeploymentConfiguration JavaDoc deploymentConfiguration,
207                 File JavaDoc file) {
208         SunDeploymentConfigurationInterface s1dc =(SunDeploymentConfigurationInterface) deploymentConfiguration;
209         s1dc.getContextRoot();
210         String JavaDoc moduleID= getGoodDirNameFromContextRoot(s1dc.getDeploymentModuleName());
211         ProgressObject JavaDoc retVal = null;
212         try {
213             
214             dm.grabInnerDM(false);
215             DirectoryDeploymentFacility ddf = new DirectoryDeploymentFacility(dm.getHost(),dm.getPort(),dm.getUserName(),dm.getPassword(),dm.isSecure());
216             retVal = ddf.initialDeploy( target, file , moduleID);
217             if (null != retVal) {
218                 retVal.addProgressListener(new Releaser(dm));
219             }
220         } finally {
221             if (null == retVal) {
222                 dm.releaseInnerDM();
223             }
224         }
225         return retVal;
226     }
227
228
229     
230     
231     private String JavaDoc getGoodDirNameFromContextRoot(String JavaDoc contextRoot){
232         String JavaDoc moduleID;
233         if (contextRoot==null){
234             return "_default_"+this.hashCode() ;
235         }
236         if (contextRoot.equals("")){
237             return "_default_"+this.hashCode();
238         }
239         
240         moduleID = contextRoot.replace(' ','_');
241         
242         // This moduleID will be later used to construct file path,
243
// replace the illegal characters in file name
244
// \ / : * ? " < > | with _
245
moduleID = moduleID.replace('\\', '_').replace('/', '_');
246         moduleID = moduleID.replace(':', '_').replace('*', '_');
247         moduleID = moduleID.replace('?', '_').replace('"', '_');
248         moduleID = moduleID.replace('<', '_').replace('>', '_');
249         moduleID = moduleID.replace('|', '_');
250         
251         // This moduleID will also be used to construct an ObjectName
252
// to register the module, so replace additional special
253
// characters , = used in property parsing with -
254
moduleID = moduleID.replace(',', '_').replace('=', '_');
255         return moduleID;
256         
257     }
258     /**
259      * Whether the deployable object could be file deployed to the specified target
260      * @param target target in question
261      * @param deployable the deployable object in question
262      * @return true if it is possible to do file deployment
263      */

264     public boolean canFileDeploy(Target JavaDoc target, DeployableObject JavaDoc deployableObject) {
265         if (null == target){
266             return false;
267         }
268         if (null == deployableObject){
269             return false;
270         }
271         if (null == dm){
272             return false;
273         }
274         if (deployableObject.getType() == ModuleType.EAR ||
275                     deployableObject.getType() == ModuleType.EJB){
276             return false;
277         }
278         return dm.isLocal();
279     }
280     
281     /**
282      * Return absolute path which the IDE will write the specified app or
283      * stand-alone module contents to.
284      * @param target target server of the deployment
285      * @param app the app or stand-alone module to deploy
286      * @param configuration server specific data for deployment
287      * @return absolute path root directory for the specified app or
288      * null if server can accept the deployment from an arbitrary directory.
289      */

290     
291     public java.io.File JavaDoc getDirectoryForNewApplication(Target JavaDoc target, DeployableObject JavaDoc deployableObject, DeploymentConfiguration JavaDoc deploymentConfiguration) {
292 // if (deployableObject.getType().equals(ModuleType.WAR)) {
293
// return null;
294
// }
295
// if (deployableObject.getType().equals(ModuleType.EJB)) {
296
// return null;
297
// }
298
return null;
299     }
300
301      /**
302       * Return absolute path the IDE will write the app or stand-alone module content to.
303       * Note: to use deployment name, implementation nees to override this.
304       *
305       * @param deploymentName name to use in deployment
306       * @param target target server of the deployment
307       * @param configuration server specific data for deployment
308       * @return absolute path root directory for the specified app or null if
309       * server can accept the deployment from an arbitrary directory.
310       */

311     public File JavaDoc getDirectoryForNewApplication(String JavaDoc deploymentName, Target JavaDoc target, DeploymentConfiguration JavaDoc configuration){
312         
313     return null;
314         //return new File(getApplicationsDir().getAbsolutePath()+"/" +deploymentName);
315

316     }
317         /**
318      * Return absolute path which the IDE will write the specified module contents to.
319      * @param appDir the root directory of containing application
320      * @param uri the URI of child module within the app
321      * @param module the child module object to deploy
322      * @param configuration server specific data for deployment
323      * @return absolute path root directory for the specified module.
324      */

325     
326     public java.io.File JavaDoc getDirectoryForNewModule(File JavaDoc file, String JavaDoc str, DeployableObject JavaDoc deployableObject, DeploymentConfiguration JavaDoc deploymentConfiguration) {
327         System.out.println(" getDirectoryForNewModule" +file+str);
328         System.out.println(" getDirectoryForNewModule" +deploymentConfiguration);
329         System.out.println(" getDirectoryForNewModule" +deployableObject);
330         return new File JavaDoc("C:\\tmp\\ludo222");
331     }
332
333     private class Releaser implements ProgressListener JavaDoc {
334         SunDeploymentManagerInterface dm;
335         Releaser(SunDeploymentManagerInterface dm) {
336             this.dm = dm;
337         }
338         
339         public void handleProgressEvent(ProgressEvent JavaDoc progressEvent) {
340             DeploymentStatus JavaDoc dms = progressEvent.getDeploymentStatus();
341             if (!dms.isRunning()) {
342                 dm.releaseInnerDM();
343             }
344         }
345     }
346  
347 }
348
349
350
Popular Tags