1 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 ; 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 ; 29 import org.netbeans.modules.j2ee.deployment.plugins.api.*; 30 31 36 public class DepManager implements DeploymentManager { 37 String name; 38 39 40 public DepManager(String url, String user, String password) { 41 name = url; 42 } 43 public String getName() { return name ; } 44 45 public DeploymentConfiguration createConfiguration(DeployableObject deployableObject) throws InvalidModuleException { 46 return new DepConfig(deployableObject,this); 47 } 48 49 public ProgressObject distribute(Target[] targets, final File file, File file2) throws java.lang.IllegalStateException { 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 r = new Runnable () { 54 public void run() { 55 try { Thread.sleep(200); } catch (Exception e) {} 57 po.setStatusDistributeRunning("TestPluginDM: distributing "+ file); 58 try { Thread.sleep(500); } catch (Exception 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 (r)).start(); 69 return po; 70 } 71 72 public ProgObject incrementalDeploy(final TargetModuleID target, AppChangeDescriptor desc) throws java.lang.IllegalStateException { 73 System.out.println(desc); 74 final ProgObject po = new ProgObject(this, new TargetModuleID[] { target }); 75 Runnable r = new Runnable () { 76 public void run() { 77 try { Thread.sleep(50); } catch (Exception e) {} 79 po.setStatusDistributeRunning("TestPluginDM: incrementally deploying "+ target); 80 try { Thread.sleep(500); } catch (Exception 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 (r)).start(); 91 return po; 92 } 93 94 public boolean hasDistributed(String 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 distribute(Target[] target, InputStream inputStream, InputStream inputStream2) throws java.lang.IllegalStateException { 104 return new ProgObject(this, target,inputStream,inputStream2); 105 } 106 107 public ProgressObject distribute(Target[] target, ModuleType moduleType, InputStream inputStream, InputStream inputStream0) throws IllegalStateException { 108 return distribute(target, inputStream, inputStream0); 109 } 110 111 public TargetModuleID[] getAvailableModules(ModuleType moduleType, Target[] target) throws TargetException, java.lang.IllegalStateException { 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 { 135 return new TargetModuleID[0]; } 137 138 public TargetModuleID[] getRunningModules(ModuleType moduleType, Target[] target) throws TargetException, java.lang.IllegalStateException { 139 return new TargetModuleID[0]; } 141 142 public Locale[] getSupportedLocales() { 143 return new Locale[] { Locale.getDefault() }; 144 } 145 146 Targ[] targets; 147 public Target[] getTargets() throws java.lang.IllegalStateException { 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; } 168 169 public ProgressObject redeploy(TargetModuleID[] targetModuleID, InputStream inputStream, InputStream inputStream2) throws java.lang.UnsupportedOperationException , java.lang.IllegalStateException { 170 throw new UnsupportedOperationException (); 171 } 172 173 Set redeployed; 174 public ProgressObject redeploy(TargetModuleID[] targetModuleID, File file, File file2) throws java.lang.UnsupportedOperationException , java.lang.IllegalStateException { 175 final ProgObject po = new ProgObject(this, targetModuleID); 176 final java.util.List targetModules = java.util.Arrays.asList(targetModuleID); 177 Runnable r = new Runnable () { 178 public void run() { 179 try { Thread.sleep(200); } catch (Exception e) {} 181 po.setStatusRedeployRunning("TestPluginDM: redeploy "+ targetModules); 182 redeployed = new HashSet(); 183 try { Thread.sleep(500); } catch (Exception 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 (r)).start(); 197 return po; 198 } 199 public boolean hasRedeployed(String 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 { 210 } 211 212 public ProgressObject start(TargetModuleID[] targetModuleID) throws java.lang.IllegalStateException { 213 final ProgObject po = new ProgObject(this, targetModuleID); 214 final java.util.List targetModules = java.util.Arrays.asList(targetModuleID); 215 Runnable r = new Runnable () { 216 public void run() { 217 try { Thread.sleep(200); } catch (Exception e) {} 219 po.setStatusStartRunning("TestPluginDM: starting "+ targetModules); 220 try { Thread.sleep(500); } catch (Exception 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 (r)).start(); 231 return po; 232 } 233 234 public ProgressObject stop(TargetModuleID[] targetModuleID) throws java.lang.IllegalStateException { 235 final ProgObject po = new ProgObject(this, targetModuleID); 236 final java.util.List targetModules = java.util.Arrays.asList(targetModuleID); 237 Runnable r = new Runnable () { 238 public void run() { 239 try { Thread.sleep(200); } catch (Exception e) {} 241 po.setStatusStopRunning("TestPluginDM: stopping "+ targetModules); 242 try { Thread.sleep(500); } catch (Exception 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 (r)).start(); 253 return po; 254 } 255 256 public ProgressObject undeploy(TargetModuleID[] targetModuleID) throws java.lang.IllegalStateException { 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 |