1 26 27 package org.objectweb.openccm.Deployment; 28 29 30 31 import org.objectweb.openccm.Containers.MetaInformation.HomeInstance; 32 import org.objectweb.openccm.Containers.MetaInformation.HomeType; 33 44 45 public class DeploymentComponentFactory { 46 47 private static SystemHomeManagerImpl home_manager_ = 53 new SystemHomeManagerImpl(); 54 55 private static org.objectweb.openccm.Containers.PCA rootPCA_ = 56 new org.objectweb.openccm.Containers.RootPCAImpl(home_manager_); 57 58 protected HomeType home_type_; 61 62 66 static private org.objectweb.ccm.visitorIDL3.java.JavaTranslator 67 javaTranslator = new org.objectweb.ccm.visitorIDL3.java.JavaTranslator(); 68 69 75 77 78 86 protected static void 87 trace_error(String method, 88 String msg, 89 Throwable exc) 90 { 91 System.err.println("DeploymentComponentFactory::" + method + ": " + msg); 92 if(exc != null) 93 exc.printStackTrace(); 94 } 95 96 97 105 protected static String 106 computeFullHomeServantClassName(Class homeExecutorClass) 107 { 108 if(homeExecutorClass == null) 110 return null; 111 112 String fullClassName = homeExecutorClass.getName(); 114 115 int idx = fullClassName.lastIndexOf(".") + 1; 117 String shortClassName = fullClassName.substring(idx); 118 119 if(shortClassName.startsWith("CCM_")) 122 return fullClassName.substring(0, idx) 123 + javaTranslator.checkKeywords(shortClassName.substring(4)) 124 + "CCM"; 125 126 Class [] itfs = homeExecutorClass.getInterfaces(); 129 130 for(int i=itfs.length-1; i>=0; i--) 134 { 135 String className = computeFullHomeServantClassName(itfs[i]); 136 if(className != null) 137 return className; 138 } 139 140 String className = computeFullHomeServantClassName(homeExecutorClass.getSuperclass()); 142 if(className != null) 143 return className; 144 145 return null; 147 } 148 149 150 160 protected static org.omg.Components.HomeExecutorBase 161 create_home_executor(java.lang.String entrypt) 162 throws org.omg.Components.Deployment.ImplEntryPointNotFound, 163 org.omg.Components.Deployment.InstallationFailure 164 { 165 try 166 { 167 java.lang.Object object = 169 TheURLClassLoader.getURLClassLoader() 170 .callStaticClassMethod(entrypt, new Object [0]); 171 172 return (org.omg.Components.HomeExecutorBase)object; 174 } 175 catch(java.lang.ClassNotFoundException exc) 176 { 177 trace_error("install_home", 178 "Class '" + exc.getMessage() + "' not found for home executor entry point '" 179 + entrypt + "'!!!", 180 null); 181 throw new org.omg.Components.Deployment.ImplEntryPointNotFound(); 182 } 183 catch(java.lang.NoSuchMethodException exc) 184 { 185 trace_error("install_home", 186 "Home executor entry point 'public static org.omg.Components.HomeExecutorBase " 187 + entrypt + "();' not found, check the home executor entry point signature!!!", 188 null); 189 throw new org.omg.Components.Deployment.ImplEntryPointNotFound(); 190 } 191 catch(java.lang.reflect.InvocationTargetException exc) 192 { 193 trace_error("install_home", 194 "Exception thrown by home executor entry point '" + entrypt + "'!!!", 195 exc.getTargetException()); 196 throw new org.omg.Components.Deployment.InstallationFailure( 197 org.objectweb.openccm.Deployment.ExceptionThrownByHomeExecutorEntryPoint.value 198 ); 199 } 200 catch(java.lang.IllegalAccessException exc) 201 { 202 trace_error("install_home", 203 "Illegal access by home executor entry point '" + entrypt + "'!!!", 204 exc); 205 throw new org.omg.Components.Deployment.InstallationFailure( 206 org.objectweb.openccm.Deployment.IllegalAccessByHomeExecutorEntryPoint.value 207 ); 208 } 209 catch(java.lang.ClassCastException exc) 210 { 211 trace_error("install_home", 212 "Home executor entry point '" + entrypt + 213 "' does not return org.omg.Components.HomeExecutorBase," + 214 " check the home executor entry point signature!!!", 215 null); 216 throw new org.omg.Components.Deployment.ImplEntryPointNotFound(); 217 } 218 } 219 220 221 protected String retrieve_MI_name(String className) 222 { 223 try 224 { 225 String tmpName = className.substring(0, className.lastIndexOf("Impl.")); 227 String IDLName = tmpName.substring(tmpName.lastIndexOf(".") + 1); 229 String prefix = tmpName.substring(0,tmpName.lastIndexOf(".")); 231 prefix = tmpName.substring(0,prefix.lastIndexOf(".") + 1); 232 if (IDLName != null) 234 { 235 return prefix + IDLName; 237 } 238 } 239 catch(Exception e) 241 { 242 } 245 return null; 246 } 247 248 254 public org.omg.Components.CCMHome 255 install_home(String entrypt) 256 { 257 try { 258 org.omg.Components.HomeExecutorBase home = 260 create_home_executor(entrypt); 261 262 String clazz_name = computeFullHomeServantClassName(home.getClass()); 263 if (clazz_name == null) 264 { 265 trace_error("install_home", 266 "Home servant class for " + home.getClass().getName() + " not found!!!", 267 null); 268 throw new org.omg.Components.Deployment. 269 InstallationFailure(org.objectweb.openccm.Deployment.HomeServantClassNotFound.value); 270 } 271 272 org.objectweb.openccm.Containers.HomeExecutorBase home_exec = 274 (org.objectweb.openccm.Containers.HomeExecutorBase) 275 create_home_executor(clazz_name + "._create_home_executor"); 276 277 home_exec._delegate(home); 278 279 org.objectweb.openccm.Containers.HomeServantImpl servant = 281 new org.objectweb.openccm.Containers.HomeServantImpl(); 282 283 home_exec._home_servant(servant); 286 287 servant.the_home_executor(home_exec); 288 289 291 servant.the_home_finder(home_manager_); 293 294 org.omg.Components.CCMHome ref = rootPCA_.activate_home(servant); 296 297 String IDL_name = retrieve_MI_name(entrypt); 303 304 if (IDL_name != null) 305 { 306 String methodName = IDL_name + "_homeMI.create_type_MI"; 308 try 310 { 311 home_type_ = (HomeType) TheURLClassLoader.getURLClassLoader() 312 .callStaticClassMethod(methodName,new Object [0]); 313 } 314 catch(Exception e) 315 { 316 home_type_ = null; 318 } 319 } 320 321 323 HomeInstance _tmp_hi = null; 324 325 if (home_type_ != null){ 326 _tmp_hi = home_type_.create_home_instance(); 327 if (_tmp_hi == null){ 328 trace_error("install_home", "home instance is null ", null); 329 } 330 servant.the_home_instance(_tmp_hi); 331 } 332 else { 333 trace_error("retrieve_MI_name", 334 "Instance MetaInformation for DCI not supported ", null); 335 } 336 servant.the_home_instance(_tmp_hi); 337 339 342 343 return ref; 344 } 345 catch(Exception e){ 346 e.printStackTrace(); 347 System.err.println(e.getMessage()); 348 } 349 350 return null; 351 352 } 353 354 355 356 357 358 } 359 | Popular Tags |