KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > tests > j2eeserver > plugin > jsr88 > DepManager


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.tests.j2eeserver.plugin.jsr88;
21
22 import java.io.*;
23 import java.util.*;
24 import javax.enterprise.deploy.model.DeployableObject JavaDoc;
25 import javax.enterprise.deploy.shared.*;
26 import javax.enterprise.deploy.spi.*;
27 import javax.enterprise.deploy.spi.exceptions.*;
28 import javax.enterprise.deploy.spi.status.ProgressObject JavaDoc;
29 import org.netbeans.modules.j2ee.deployment.plugins.api.*;
30
31 /**
32  *
33  * @author gfink
34  * @author nn136682
35  */

36 public class DepManager implements DeploymentManager {
37     String JavaDoc name;
38
39     /** Creates a new instance of DepFactory */
40     public DepManager(String JavaDoc url, String JavaDoc user, String JavaDoc password) {
41         name = url;
42     }
43     public String JavaDoc getName() { return name ; }
44     
45     public DeploymentConfiguration createConfiguration(DeployableObject JavaDoc deployableObject) throws InvalidModuleException {
46         return new DepConfig(deployableObject,this);
47     }
48
49     public ProgressObject JavaDoc distribute(Target[] targets, final File file, File file2) throws java.lang.IllegalStateException JavaDoc {
50         java.util.logging.Logger.getLogger(DepManager.class.getName()).log(java.util.logging.Level.FINEST,"Deploying " + file + " with " + file2);
51
52         final ProgObject po = new ProgObject(this, targets, file, file2);
53         Runnable JavaDoc r = new Runnable JavaDoc() {
54             public void run() {
55                 try { Thread.sleep(200); //some latency
56
} catch (Exception JavaDoc e) {}
57                 po.setStatusDistributeRunning("TestPluginDM: distributing "+ file);
58                 try { Thread.sleep(500); //super server starting time
59
} catch (Exception JavaDoc e) {}
60                 if (getTestBehavior() == DISTRIBUTE_FAILED) {
61                     po.setStatusStartFailed("TestPluginDM distribute failed");
62                 } else {
63                     po.setStatusStartCompleted("TestPluginDM distribute finish");
64                 }
65             }
66         };
67         
68         (new Thread JavaDoc(r)).start();
69         return po;
70     }
71
72     public ProgObject incrementalDeploy(final TargetModuleID target, AppChangeDescriptor desc) throws java.lang.IllegalStateException JavaDoc {
73         System.out.println(desc);
74         final ProgObject po = new ProgObject(this, new TargetModuleID[] { target });
75         Runnable JavaDoc r = new Runnable JavaDoc() {
76             public void run() {
77                 try { Thread.sleep(50); //some latency
78
} catch (Exception JavaDoc e) {}
79                 po.setStatusDistributeRunning("TestPluginDM: incrementally deploying "+ target);
80                 try { Thread.sleep(500); //super server starting time
81
} catch (Exception JavaDoc e) {}
82                 if (getTestBehavior() == DISTRIBUTE_FAILED) {
83                     po.setStatusStartFailed("TestPluginDM incremental deploy failed");
84                 } else {
85                     po.setStatusStartCompleted("TestPluginDM incremental deploy finish");
86                 }
87             }
88         };
89         
90         (new Thread JavaDoc(r)).start();
91         return po;
92     }
93     
94     public boolean hasDistributed(String JavaDoc id) {
95         for (int i=0; i<getTargets().length; i++) {
96             Targ t = (Targ) getTargets()[i];
97             if (t.getTargetModuleID(id) != null)
98                 return true;
99         }
100         return false;
101     }
102     
103     public ProgressObject JavaDoc distribute(Target[] target, InputStream inputStream, InputStream inputStream2) throws java.lang.IllegalStateException JavaDoc {
104         return new ProgObject(this, target,inputStream,inputStream2);
105     }
106     
107     public ProgressObject JavaDoc distribute(Target[] target, ModuleType moduleType, InputStream inputStream, InputStream inputStream0) throws IllegalStateException JavaDoc {
108         return distribute(target, inputStream, inputStream0);
109     }
110     
111     public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] target) throws TargetException, java.lang.IllegalStateException JavaDoc {
112         List l = new ArrayList();
113         Targ[] mytargets = (Targ[]) getTargets();
114         HashSet yours = new HashSet(Arrays.asList(target));
115         for (int i=0; i<mytargets.length; i++) {
116             if (yours.contains(mytargets[i]))
117                 l.addAll(Arrays.asList((mytargets[i]).getTargetModuleIDs()));
118         }
119         return (TargetModuleID[]) l.toArray(new TargetModuleID[0]);
120     }
121     
122     public Locale getCurrentLocale() {
123         return Locale.getDefault();
124     }
125     
126     public DConfigBeanVersionType getDConfigBeanVersion() {
127         return DConfigBeanVersionType.V1_3;
128     }
129     
130     public Locale getDefaultLocale() {
131         return Locale.getDefault();
132     }
133     
134     public TargetModuleID[] getNonRunningModules(ModuleType moduleType, Target[] target) throws TargetException, java.lang.IllegalStateException JavaDoc {
135         return new TargetModuleID[0]; // PENDING see above.
136
}
137     
138     public TargetModuleID[] getRunningModules(ModuleType moduleType, Target[] target) throws TargetException, java.lang.IllegalStateException JavaDoc {
139         return new TargetModuleID[0]; // PENDING see above.
140
}
141     
142     public Locale[] getSupportedLocales() {
143         return new Locale[] { Locale.getDefault() };
144     }
145     
146     Targ[] targets;
147     public Target[] getTargets() throws java.lang.IllegalStateException JavaDoc {
148         if (targets == null) {
149             targets = new Targ[] {
150             new Targ("Target 1"),
151             new Targ("Target 2")
152         };
153         }
154         return targets;
155     }
156     
157     public boolean isDConfigBeanVersionSupported(DConfigBeanVersionType dConfigBeanVersionType) {
158         return true;
159     }
160     
161     public boolean isLocaleSupported(Locale locale) {
162         return Locale.getDefault().equals(locale);
163     }
164     
165     public boolean isRedeploySupported() {
166         return true; // PENDING use jsr88 redeploy?
167
}
168     
169     public ProgressObject JavaDoc redeploy(TargetModuleID[] targetModuleID, InputStream inputStream, InputStream inputStream2) throws java.lang.UnsupportedOperationException JavaDoc, java.lang.IllegalStateException JavaDoc {
170         throw new UnsupportedOperationException JavaDoc();
171     }
172     
173     Set redeployed;
174     public ProgressObject JavaDoc redeploy(TargetModuleID[] targetModuleID, File file, File file2) throws java.lang.UnsupportedOperationException JavaDoc, java.lang.IllegalStateException JavaDoc {
175         final ProgObject po = new ProgObject(this, targetModuleID);
176         final java.util.List JavaDoc targetModules = java.util.Arrays.asList(targetModuleID);
177         Runnable JavaDoc r = new Runnable JavaDoc() {
178             public void run() {
179                 try { Thread.sleep(200); //some latency
180
} catch (Exception JavaDoc e) {}
181                 po.setStatusRedeployRunning("TestPluginDM: redeploy "+ targetModules);
182                 redeployed = new HashSet();
183                 try { Thread.sleep(500); //super server starting time
184
} catch (Exception JavaDoc e) {}
185                 if (getTestBehavior() == REDEPLOY_FAILED) {
186                     po.setStatusRedeployFailed("TestPluginDM: failed to redeploy "+targetModules);
187                 } else {
188                     po.setStatusRedeployCompleted("TestPluginDM: done redeploy "+targetModules);
189                     TargetModuleID[] result = po.getResultTargetModuleIDs();
190                     for (int i=0; i<result.length; i++)
191                         redeployed.add(result[i].toString());
192                 }
193             }
194         };
195         
196         (new Thread JavaDoc(r)).start();
197         return po;
198     }
199     public boolean hasRedeployed(String JavaDoc id) {
200         return redeployed != null && redeployed.contains(id);
201     }
202     
203     public void release() {
204     }
205     
206     public void setDConfigBeanVersion(DConfigBeanVersionType dConfigBeanVersionType) throws DConfigBeanVersionUnsupportedException {
207     }
208     
209     public void setLocale(Locale locale) throws java.lang.UnsupportedOperationException JavaDoc {
210     }
211     
212     public ProgressObject JavaDoc start(TargetModuleID[] targetModuleID) throws java.lang.IllegalStateException JavaDoc {
213         final ProgObject po = new ProgObject(this, targetModuleID);
214         final java.util.List JavaDoc targetModules = java.util.Arrays.asList(targetModuleID);
215         Runnable JavaDoc r = new Runnable JavaDoc() {
216             public void run() {
217                 try { Thread.sleep(200); //some latency
218
} catch (Exception JavaDoc e) {}
219                 po.setStatusStartRunning("TestPluginDM: starting "+ targetModules);
220                 try { Thread.sleep(500); //super server starting time
221
} catch (Exception JavaDoc e) {}
222                 if (getTestBehavior() == START_MODULES_FAILED) {
223                     po.setStatusStartFailed("TestPluginDM: failed to start "+targetModules);
224                 } else {
225                     po.setStatusStartCompleted("TestPluginDM: done starting "+targetModules);
226                 }
227             }
228         };
229         
230         (new Thread JavaDoc(r)).start();
231         return po;
232     }
233     
234     public ProgressObject JavaDoc stop(TargetModuleID[] targetModuleID) throws java.lang.IllegalStateException JavaDoc {
235         final ProgObject po = new ProgObject(this, targetModuleID);
236         final java.util.List JavaDoc targetModules = java.util.Arrays.asList(targetModuleID);
237         Runnable JavaDoc r = new Runnable JavaDoc() {
238             public void run() {
239                 try { Thread.sleep(200); //some latency
240
} catch (Exception JavaDoc e) {}
241                 po.setStatusStopRunning("TestPluginDM: stopping "+ targetModules);
242                 try { Thread.sleep(500); //super server starting time
243
} catch (Exception JavaDoc e) {}
244                 if (getTestBehavior() == STOP_MODULES_FAILED) {
245                     po.setStatusStopFailed("TestPluginDM: failed to stop "+targetModules);
246                 } else {
247                     po.setStatusStopCompleted("TestPluginDM: done stopping "+targetModules);
248                 }
249             }
250         };
251         
252         (new Thread JavaDoc(r)).start();
253         return po;
254     }
255     
256     public ProgressObject JavaDoc undeploy(TargetModuleID[] targetModuleID) throws java.lang.IllegalStateException JavaDoc {
257         return new ProgObject(this, targetModuleID);
258     }
259     
260     public static final int NORMAL = 0;
261     public static final int START_FAILED = 1;
262     public static final int STOP_FAILED = 2;
263     public static final int START_MODULES_FAILED = 3;
264     public static final int STOP_MODULES_FAILED = 4;
265     public static final int DISTRIBUTE_FAILED = 5;
266     public static final int REDEPLOY_FAILED = 6;
267     
268     private int testBehavior = NORMAL;
269     public void setTestBehavior(int behavior) {
270         testBehavior = behavior;
271     }
272     public int getTestBehavior() {
273         return testBehavior;
274     }
275     public ServerProgress createServerProgress() {
276         return new DepManager.TestServerProgress();
277     }
278     public static final int STOPPED = 0;
279     public static final int STARTING = 1;
280     public static final int RUNNING = 2;
281     public static final int STOPPING = 3;
282     public static final int FAILED = 4;
283     private int state = STOPPED;
284     public int getState() {
285         return state;
286     }
287     public void setState(int state) {
288         this.state = state;
289     }
290     private class TestServerProgress extends ServerProgress {
291         public TestServerProgress() {
292             super(DepManager.this);
293         }
294     }
295 }
296
Popular Tags