1 26 package org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.base; 27 28 import java.lang.reflect.InvocationTargetException ; 30 import java.lang.reflect.Method ; 31 import java.io.StringWriter ; 32 import org.objectweb.apollon.framework.Bean; 33 import org.objectweb.apollon.framework.Extension; 34 import org.objectweb.openccm.descriptor.componentassembly.ccm.deployer.managers.*; 35 36 43 public abstract class HandlerBase 44 extends Extension { 45 51 private RootDeployerContext rootContext; 53 private HandlerContext context; 55 56 62 68 74 78 public void 79 connectRootDeployerContext(RootDeployerContext rootContext) 80 { 81 this.rootContext = rootContext; 82 } 83 84 88 protected RootDeployerContext 89 getRootDeployerContext() 90 { 91 return rootContext; 92 } 93 94 102 public Deployer 103 getDeployer(Object obj) 104 throws InitializationError 105 { 106 Bean bean=null; 107 108 try { 109 bean = (Bean) obj; 110 HandlerBase tmp = 111 (HandlerBase) bean.getExtensionManager() 112 .getExtensionByName(resolveExtention(bean)); 113 tmp.connectRootDeployerContext(getRootDeployerContext()); 114 tmp.connectHandlerContext(getHandlerContext()); 115 Method m = 116 tmp.getClass() 117 .getDeclaredMethod("getInstance", 118 new Class [] { obj.getClass()}); 119 120 return (Deployer) m.invoke(tmp, new Object [] { obj }); 121 122 } catch (NoSuchMethodException nos) { 123 throw new InitializationError 124 (null,nos, 125 "NoSuchMethodException was thrown when looking for a deployer child " 126 +"The handler use to instantiate the deployer seem to be devoided " 127 +"of the [Deployer getInstance("+obj.getClass()+")] method "); 128 129 } catch (IllegalAccessException iae) { 130 throw new InitializationError 131 (null,iae, 132 "IllegalAccessException was thrown when looking for a deployer child"); 133 } catch (InvocationTargetException e) { 134 135 if (e.getTargetException() instanceof InitializationError) 136 throw (InitializationError) e.getTargetException(); 137 else{ 138 139 throw new InitializationError 140 (null,e, 141 "Unespected exception was thrown when looking for a deployer child on :\n " 142 +getStringifiedDescription(bean),1); 143 } 144 } 145 } 146 149 public String 150 getStringifiedDescription(Bean bean) 151 { 152 try{ 153 StringWriter w = new StringWriter (); 154 bean.marshal(w); 155 return w.toString(); 156 } 157 catch(Exception e){ 158 return "Description not available"; 159 } 160 161 } 162 167 public void 168 applyCommonConfig(ChildDeployerContext deploy) 169 { 170 LifeCycleManager dlcm = new DefaultLifeCycleManager(); 172 deploy.connectLifeCycleManager(dlcm); 174 dlcm.connectLogger(getRootDeployerContext().getDeploymentLogger()); 176 dlcm.connectManagedDeployer(deploy); 178 deploy.connectDeployerScheduler(new DefaultDeployerScheduler()); 180 deploy.connectRootDeployerContext(getRootDeployerContext()); 182 deploy.connectErrorManager(getRootDeployerContext().getErrorManager()); 184 } 185 186 191 public DeploymentLogger 192 getLogger() 193 { 194 return getRootDeployerContext().getDeploymentLogger(); 195 } 196 197 201 public void 202 connectHandlerContext(HandlerContext context) 203 { 204 this.context = context; 205 } 206 207 212 public HandlerContext 213 getHandlerContext() 214 { 215 return context; 216 } 217 218 224 public String 225 resolveExtention(Bean bean) 226 { 227 return getHandlerContext().getHandlerResolver().getExtension(bean); 228 } 229 230 233 public String 234 toString() 235 { 236 String className = getClass().getName(); 237 return className.substring( 238 className.lastIndexOf("ccm"), 239 className.lastIndexOf(".")) 240 + ".Deployer"; 241 } 242 243 } | Popular Tags |