1 26 27 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base; 28 29 import java.io.StringWriter ; 31 import java.lang.reflect.InvocationTargetException ; 32 import java.lang.reflect.Method ; 33 import org.objectweb.apollon.framework.Bean; 34 35 43 public abstract class DeployerContext 44 implements Deployer 45 { 46 47 private LifeCycleManager lifeCycleManager; 54 private DeployerScheduler deployerScheduler; 56 private ErrorManager errorManager; 58 private Bean deployerDescription; 60 private String stringifiedDescription = null; 62 63 69 75 86 public abstract RootDeployerContext getRootDeployerContext(); 87 88 101 public void visit(Deployer depl) throws FatalDeploymentException { 102 try { 103 Method m = 104 this.getClass().getDeclaredMethod( 105 "visit", 106 new Class [] { 107 depl.getClass(), 108 this.getStatus().getClass()}); 109 m.invoke(this, new Object [] { depl, this.getStatus()}); 110 111 } catch (NoSuchMethodException e) { 112 throw new FatalDeploymentException 114 (e,"Deployment architecture corrupted check the deployer "+ 115 "implementation it segurely miss a visit method in right state"); 116 } catch (IllegalAccessException e1) { 117 throw new FatalDeploymentException 118 (e1,"Deployment architecture corrupted"); 119 } catch (InvocationTargetException e2) { 120 if(e2.getTargetException() instanceof FatalDeploymentException) 121 throw (FatalDeploymentException)e2.getTargetException(); 122 throw new FatalDeploymentException 123 ((Exception ) e2.getTargetException(), 124 "Deployment architecture throw an unexpected exception"); 125 } 126 } 127 128 139 public void 140 traverse(Deployer deployer, Deployer[] deployers) 141 throws FatalDeploymentException 142 { 143 deployerScheduler.traverse(deployer, deployers); 144 } 145 146 153 public void 154 connectLifeCycleManager(LifeCycleManager lifeCycleManager) 155 { 156 this.lifeCycleManager = lifeCycleManager; 157 } 158 159 163 public LifeCycleManager 164 getLifeCycleManager() 165 { 166 return this.lifeCycleManager; 167 } 168 169 170 176 public void 177 connectErrorManager(ErrorManager manager) 178 { 179 errorManager = manager; 180 } 181 182 187 public ErrorManager 188 getErrorManager() 189 { 190 return errorManager; 191 } 192 193 199 public void 200 connectDeployerScheduler(DeployerScheduler deployerScheduler) 201 { 202 this.deployerScheduler = deployerScheduler; 203 } 204 205 210 public void 211 connectDeployerDescription(Bean deployerDescription) 212 { 213 this.deployerDescription = deployerDescription; 214 } 215 216 224 public DeployerState 225 getStatus() 226 { 227 return lifeCycleManager.getStatus(); 228 } 229 230 231 240 public String 241 getStringifiedDeployerDescription() 242 throws InitializationError 243 { 244 try { 245 if (stringifiedDescription == null) { 246 StringWriter w = new StringWriter (); 247 deployerDescription.marshal(w); 248 stringifiedDescription = w.toString(); 249 } 250 return stringifiedDescription; 251 } catch (Exception e) { 252 e.printStackTrace(); 253 throw new InitializationError 254 (this, 255 "The deployer description retrieval failed due to:\n" 256 + e.getMessage()); 257 } 258 } 259 266 public String 267 getStringifiedDeployerDescriptionNoError() 268 { 269 try { 270 if (stringifiedDescription == null) { 271 StringWriter w = new StringWriter (); 272 deployerDescription.marshal(w); 273 stringifiedDescription = w.toString(); 274 } 275 return stringifiedDescription; 276 } catch (Exception e) { 277 return "Description not available"; 278 } 279 } 280 285 public String 286 getIdentifier() 287 { 288 String name = this.getClass().getName(); 289 return name.substring(name.lastIndexOf(".") + 1); 290 } 291 292 303 public abstract void 304 initialize() 305 throws InitializationError; 306 307 308 } 309 | Popular Tags |