KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > tomcat5 > ide > TomcatIncrementalDeployment


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.tomcat5.ide;
21
22 import java.io.File JavaDoc;
23
24 import org.netbeans.modules.j2ee.deployment.plugins.api.IncrementalDeployment;
25 import javax.enterprise.deploy.spi.*;
26 import javax.enterprise.deploy.model.*;
27 import javax.enterprise.deploy.shared.*;
28 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
29 import javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException JavaDoc;
30 import org.openide.util.RequestProcessor;
31 import org.netbeans.modules.tomcat5.progress.ProgressEventSupport;
32 import org.netbeans.modules.tomcat5.progress.Status;
33
34 import org.netbeans.modules.tomcat5.*;
35
36 /**
37  *
38  * @author Pavel Buzek
39  */

40 public class TomcatIncrementalDeployment extends IncrementalDeployment {
41     
42     private TomcatManager tm;
43     
44     /** Creates a new instance of TomcatIncrementaDeployment */
45     public TomcatIncrementalDeployment (DeploymentManager dm) {
46         this.tm = (TomcatManager) dm;
47     }
48     
49     public boolean canFileDeploy (Target target, DeployableObject deployable) {
50         return deployable.getType ().equals (javax.enterprise.deploy.shared.ModuleType.WAR);
51         
52     }
53     
54     public File JavaDoc getDirectoryForModule (TargetModuleID module) {
55         return null;
56         /*TomcatModule tModule = (TomcatModule) module;
57         String moduleFolder = tm.getCatalinaBaseDir ().getAbsolutePath ()
58         + System.getProperty("file.separator") + "webapps" //NOI18N
59         + System.getProperty("file.separator") + tModule.getPath ().substring (1); //NOI18N
60         File f = new File (moduleFolder);
61         return f;*/

62     }
63     
64     public File JavaDoc getDirectoryForNewApplication (Target target, DeployableObject module, DeploymentConfiguration configuration) {
65         if (module.getType ().equals (ModuleType.WAR)) {
66             return null;
67             /*if (configuration instanceof WebappConfiguration) {
68                 String moduleFolder = tm.getCatalinaBaseDir ().getAbsolutePath ()
69                 + System.getProperty("file.separator") + "webapps" //NOI18N
70                 + System.getProperty("file.separator") + ((WebappConfiguration)configuration).getPath ().substring (1); //NOI18N
71                 File f = new File (moduleFolder);
72                 return f;
73             }*/

74         }
75         throw new IllegalArgumentException JavaDoc ("ModuleType:" + module == null ? null : module.getType () + " Configuration:"+configuration); //NOI18N
76
}
77     
78     public java.io.File JavaDoc getDirectoryForNewModule (java.io.File JavaDoc appDir, String JavaDoc uri, javax.enterprise.deploy.model.DeployableObject JavaDoc module, javax.enterprise.deploy.spi.DeploymentConfiguration JavaDoc configuration) {
79         throw new UnsupportedOperationException JavaDoc ();
80     }
81     
82     public ProgressObject JavaDoc incrementalDeploy (final TargetModuleID module, org.netbeans.modules.j2ee.deployment.plugins.api.AppChangeDescriptor changes) {
83         if (changes.descriptorChanged () || changes.serverDescriptorChanged () || changes.classesChanged ()) {
84             TomcatManagerImpl tmi = new TomcatManagerImpl (tm);
85             if (changes.serverDescriptorChanged ()) {
86                 new TomcatManagerImpl (tm).remove ((TomcatModule) module);
87                 tmi.incrementalRedeploy ((TomcatModule) module);
88             } else if (changes.descriptorChanged()) {
89                 new TomcatManagerImpl (tm).stop((TomcatModule) module);
90                 tmi.start ((TomcatModule) module);
91             } else {
92                 tmi.reload ((TomcatModule)module);
93             }
94             return tmi;
95         } else {
96             final P p = new P (module);
97             p.supp.fireHandleProgressEvent (module, new Status (ActionType.EXECUTE, CommandType.DISTRIBUTE, "", StateType.COMPLETED));
98             RequestProcessor.getDefault().post(new Runnable JavaDoc() {
99                 public void run() {
100                     try {
101                         p.supp.fireHandleProgressEvent (module, new Status (ActionType.EXECUTE, CommandType.DISTRIBUTE, "", StateType.COMPLETED));
102                         
103                     } catch (Throwable JavaDoc e) {
104                         e.printStackTrace();
105                     }
106                 }
107             });
108             return p;
109         }
110     }
111     
112     public ProgressObject JavaDoc initialDeploy (Target target, javax.enterprise.deploy.model.DeployableObject JavaDoc app, DeploymentConfiguration configuration, File JavaDoc dir) {
113         TomcatManagerImpl tmi = new TomcatManagerImpl (tm);
114         File JavaDoc contextXml = new File JavaDoc (dir.getAbsolutePath () + "/META-INF/context.xml"); //NOI18N
115
tmi.initialDeploy (target, contextXml, dir);
116         return tmi;
117     }
118     
119     public void notifyDeployment(TargetModuleID module) {
120         if (tm.isTomcat50() && tm.getTomcatProperties().getOpenContextLogOnRun()) {
121             tm.openLog(module);
122         }
123     }
124     
125     private static class P implements ProgressObject JavaDoc {
126         
127         ProgressEventSupport supp = new ProgressEventSupport (this);
128         TargetModuleID tmid;
129         
130         P (TargetModuleID tmid) {
131             this.tmid = tmid;
132         }
133         
134         public void addProgressListener (javax.enterprise.deploy.spi.status.ProgressListener JavaDoc progressListener) {
135             supp.addProgressListener (progressListener);
136         }
137         
138         public void removeProgressListener (javax.enterprise.deploy.spi.status.ProgressListener JavaDoc progressListener) {
139             supp.removeProgressListener (progressListener);
140         }
141         
142         public javax.enterprise.deploy.spi.status.ClientConfiguration JavaDoc getClientConfiguration (javax.enterprise.deploy.spi.TargetModuleID JavaDoc targetModuleID) {
143             return null;
144         }
145         
146         public javax.enterprise.deploy.spi.status.DeploymentStatus JavaDoc getDeploymentStatus () {
147             return supp.getDeploymentStatus ();
148         }
149         
150         public javax.enterprise.deploy.spi.TargetModuleID JavaDoc[] getResultTargetModuleIDs () {
151             return new TargetModuleID [] {tmid};
152         }
153         
154         public boolean isCancelSupported () {
155             return false;
156         }
157         
158         public boolean isStopSupported () {
159             return false;
160         }
161         
162         public void cancel () throws javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException JavaDoc {
163             throw new OperationUnsupportedException JavaDoc ("");
164         }
165         
166         public void stop () throws javax.enterprise.deploy.spi.exceptions.OperationUnsupportedException JavaDoc {
167             throw new OperationUnsupportedException JavaDoc ("");
168         }
169         
170     }
171 }
172
Popular Tags