1 31 32 package org.objectweb.openccm.Deployment; 33 34 import org.objectweb.openccm.Containers.MetaInformation.HomeType; 35 import org.objectweb.openccm.Containers.MetaInformation.HomeInstance; 36 37 50 51 public class ContainerBase 52 { 53 59 67 protected ComponentServerImpl the_component_server_; 68 70 73 protected org.omg.Components.ConfigValue[] configuration_; 74 75 78 protected org.objectweb.ccm.util.Vector homes_; 79 80 83 protected fr.lifl.cim.jidlscript.JOSInterpreter josh_; 84 85 88 protected org.objectweb.openccm.Containers.PCA rootPCA_; 89 90 93 protected org.objectweb.openccm.Containers.SystemConfiguration container_configuration_; 94 95 98 protected org.objectweb.openccm.Containers.SystemConfiguration home_configuration_; 99 100 101 protected org.omg.Components.Deployment.ComponentInstallation the_component_installation; 102 103 106 protected org.objectweb.openccm.Containers.SystemConfiguration component_configuration_; 107 108 111 protected SystemHomeManagerImpl home_manager_; 112 113 116 protected org.objectweb.openccm.Deployment.listener.ContainerListener listener_; 117 118 121 protected org.omg.Components.Deployment.Container the_container_ref_; 122 123 124 protected ContainerHomeInformation containerHomeInfo; 125 126 129 protected HomeType home_type_; 130 131 137 145 public 146 ContainerBase(org.omg.Components.ConfigValue[] config, 147 150 ComponentServerImpl component_server, 151 org.omg.Components.Deployment.ComponentInstallation the_component_installation) 152 153 throws org.omg.Components.CreateFailure, 154 org.omg.Components.Deployment.InvalidConfiguration 155 { 156 the_component_server_ = component_server; 157 this.the_component_installation=the_component_installation; 158 configuration_ = config; 159 homes_ = new org.objectweb.ccm.util.Vector(); 160 home_manager_ = new SystemHomeManagerImpl(); 161 listener_ = null; 162 the_container_ref_ = null; 163 164 home_type_ = null; 166 167 org.objectweb.openccm.Deployment.listener 168 .TheContainerConfigurator 169 .get_instance() 170 .configure_container(new ContainerLocalImpl(this)); 171 172 container_configuration_ = null; 173 home_configuration_ = null; 174 component_configuration_ = null; 175 fr.lifl.cim.jidlscript.lang.JISScope scope = null; 176 177 try 179 { 180 josh_ = new fr.lifl.cim.jidlscript.JOSInterpreter(); 182 183 rootPCA_ = new org.objectweb.openccm.Containers.RootPCAImpl(home_manager_); 185 scope = new fr.lifl.cim.jidlscript.lang.JISScope("CONTAINER"); 186 fr.lifl.cim.jidlscript.lang.JISRootScope.root().insertScoped(scope); 187 create_alias(scope, "org.objectweb.openccm.Deployment.ContainerBase", this, "container"); 188 } 192 catch(fr.lifl.cim.jidlscript.lang.JISError ex) 193 { 194 throw new org.omg.Components.CreateFailure(); 195 } 196 197 java.lang.String script = ""; 199 for (int i=0;i<config.length;i++) 200 { 201 if (config[i].name.equals("container_script")) 202 { 203 script = config[i].value.extract_string(); 204 break; 205 } 206 } 207 208 try 210 { 211 josh_.eval(script); 212 } 213 catch(fr.lifl.cim.jidlscript.lang.JISError ex) 214 { 215 throw new java.lang.Error ("### script failure : \n"+ex.exception.toString()); 220 } 221 } 222 223 229 232 protected void 233 trace_error(String method, 234 String msg, 235 Throwable exc) 236 { 237 System.err.println("Components::Deployment::Container::" + method + ": " + msg); 238 if(exc != null) 239 exc.printStackTrace(); 240 } 241 242 245 protected void 246 create_alias(fr.lifl.cim.jidlscript.lang.JISScope scope, 247 java.lang.String clazz, 248 java.lang.Object instance, 249 java.lang.String alias) 250 { 251 try 252 { 253 fr.lifl.cim.jidlscript.java.JISJavaClass jc = 254 fr.lifl.cim.jidlscript.java.JISJavaClass.importClass(new fr.lifl.cim.jidlscript.lang.JISString(clazz)); 255 fr.lifl.cim.jidlscript.java.JISJavaInstance ji = new fr.lifl.cim.jidlscript.java.JISJavaInstance(jc, instance); 256 scope.insertScoped(new fr.lifl.cim.jidlscript.lang.JISAlias(alias, ji)); 257 } 258 catch(fr.lifl.cim.jidlscript.lang.JISError ex) 259 { 260 } 264 } 265 266 276 protected org.omg.Components.HomeExecutorBase 277 create_home_executor(java.lang.String entrypt) 278 throws org.omg.Components.Deployment.ImplEntryPointNotFound, 279 org.omg.Components.Deployment.InstallationFailure 280 { 281 try 282 { 283 java.lang.Object object = 285 TheURLClassLoader.getURLClassLoader() 286 .callStaticClassMethod(entrypt, new Object [0]); 287 288 return (org.omg.Components.HomeExecutorBase)object; 290 } 291 catch(java.lang.ClassNotFoundException exc) 292 { 293 trace_error("install_home", 294 "Class '" + exc.getMessage() + "' not found for home executor entry point '" 295 + entrypt + "'!!!", 296 null); 297 throw new org.omg.Components.Deployment.ImplEntryPointNotFound(); 298 } 299 catch(java.lang.NoSuchMethodException exc) 300 { 301 trace_error("install_home", 302 "Home executor entry point 'public static org.omg.Components.HomeExecutorBase " 303 + entrypt + "();' not found, check the home executor entry point signature!!!", 304 null); 305 throw new org.omg.Components.Deployment.ImplEntryPointNotFound(); 306 } 307 catch(java.lang.reflect.InvocationTargetException exc) 308 { 309 trace_error("install_home", 310 "Exception thrown by home executor entry point '" + entrypt + "'!!!", 311 exc.getTargetException()); 312 throw new org.omg.Components.Deployment.InstallationFailure( 313 org.objectweb.openccm.Deployment.ExceptionThrownByHomeExecutorEntryPoint.value 314 ); 315 } 316 catch(java.lang.IllegalAccessException exc) 317 { 318 trace_error("install_home", 319 "Illegal access by home executor entry point '" + entrypt + "'!!!", 320 exc); 321 throw new org.omg.Components.Deployment.InstallationFailure( 322 org.objectweb.openccm.Deployment.IllegalAccessByHomeExecutorEntryPoint.value 323 ); 324 } 325 catch(java.lang.ClassCastException exc) 326 { 327 trace_error("install_home", 328 "Home executor entry point '" + entrypt + 329 "' does not return org.omg.Components.HomeExecutorBase," + 330 " check the home executor entry point signature!!!", 331 null); 332 throw new org.omg.Components.Deployment.ImplEntryPointNotFound(); 333 } 334 } 335 336 340 static private org.objectweb.openccm.generator.translator.idl2java.api.CommonTranslator 341 javaTranslator = new org.objectweb.openccm.generator.translator.idl2java.lib.CommonTranslator(); 342 343 351 protected static String 352 computeFullHomeServantClassName(Class homeExecutorClass) 353 { 354 if(homeExecutorClass == null) 356 return null; 357 358 String fullClassName = homeExecutorClass.getName(); 360 361 int idx = fullClassName.lastIndexOf(".") + 1; 363 String shortClassName = fullClassName.substring(idx); 364 365 if(shortClassName.startsWith("CCM_")) 368 return fullClassName.substring(0, idx) 369 + javaTranslator.checkKeywords(shortClassName.substring(4)) 370 + "CCM"; 371 372 Class [] itfs = homeExecutorClass.getInterfaces(); 375 376 for(int i=itfs.length-1; i>=0; i--) 380 { 381 String className = computeFullHomeServantClassName(itfs[i]); 382 if(className != null) 383 return className; 384 } 385 386 String className = computeFullHomeServantClassName(homeExecutorClass.getSuperclass()); 388 if(className != null) 389 return className; 390 391 return null; 393 } 394 395 408 protected void load_lib_dependency(String uuid) 409 throws org.omg.Components.Deployment.UnknownImplId, 410 org.omg.Components.Deployment.InstallationFailure 411 { 412 try{ 413 TheURLClassLoader.getURLClassLoader() 414 .addURL(new java.net.URL (the_component_installation 415 .get_implementation(uuid))); 416 417 } 418 catch(java.net.MalformedURLException ef) 419 { 420 trace_error("load_lib_dependency", 421 "Installation failuer for package related to " + 422 uuid + ".", null); 423 throw new org.omg.Components.Deployment.InstallationFailure(); 424 } 425 } 426 427 protected String retrieve_MI_name(String className) 428 { 429 430 try 431 { 432 String tmpName = className.substring(0, className.lastIndexOf("Impl.")); 434 String IDLName = tmpName.substring(tmpName.lastIndexOf(".") + 1); 436 String prefix = tmpName.substring(0,tmpName.lastIndexOf(".")); 438 prefix = tmpName.substring(0,prefix.lastIndexOf(".") + 1); 439 if (IDLName != null) 441 { 442 return prefix + IDLName; 443 } 444 } 445 catch(Exception e) 447 { 448 trace_error("retrieve_MI_name","error when computing IDL name for MetaInformation", null); 449 } 450 return null; 451 } 452 453 456 public void 457 unregister_home(org.omg.Components.CCMHome ref) 458 throws org.omg.Components.RemoveFailure 459 { 460 listener_.on_remove(ref); 461 for(java.util.Iterator it=homes_.iterator();it.hasNext(); ) 462 if(ref._is_equivalent(((org.omg.Components.CCMHome)it.next()))){ 463 it.remove(); 464 if(containerHomeInfo!=null) 465 get_container_home_info().unregister_home(ref); 466 return; 467 468 } 469 throw new org.omg.Components.RemoveFailure(); 471 } 472 473 479 484 public void 485 add_listener (org.objectweb.openccm.Deployment.listener.ContainerListener listener) 486 { 487 if (listener_ == null) 488 listener_ = listener; 489 else 490 listener_.set_delegate(listener); 491 } 492 493 496 public void 497 the_container_ref(org.omg.Components.Deployment.Container container) 498 { 499 the_container_ref_ = container; 500 } 501 502 505 public org.omg.Components.Deployment.Container 506 the_container_ref() 507 { 508 return the_container_ref_; 509 } 510 511 514 public org.objectweb.openccm.Containers.PCA 515 get_rootPCA() 516 { 517 return rootPCA_; 518 } 519 520 523 public org.objectweb.openccm.Containers.SystemHome 524 create_system_home(java.lang.String implUUID, 525 java.lang.String alias, 526 java.lang.String entrypt) 527 throws org.objectweb.openccm.Containers.CreationFailed 528 { 529 return home_manager_.create_system_home(implUUID, alias, entrypt); 530 } 531 532 535 public org.objectweb.openccm.Containers.SystemHome 536 find_system_home(java.lang.String alias) 537 throws org.objectweb.openccm.Containers.HomeNotFound 538 { 539 return home_manager_.find_system_home(alias); 540 } 541 542 545 public void 546 set_container_configuration(org.objectweb.openccm.Containers.SystemConfiguration config) 547 { 548 container_configuration_ = config; 549 } 550 551 554 public org.objectweb.openccm.Containers.SystemConfiguration 555 get_container_configuration() 556 { 557 return container_configuration_; 558 } 559 560 563 public void 564 set_home_configuration(org.objectweb.openccm.Containers.SystemConfiguration config) 565 { 566 home_configuration_ = config; 567 } 568 569 572 public org.objectweb.openccm.Containers.SystemConfiguration 573 get_home_configuration() 574 { 575 return home_configuration_; 576 } 577 578 581 public void 582 set_component_configuration(org.objectweb.openccm.Containers.SystemConfiguration config) 583 { 584 component_configuration_ = config; 585 } 586 587 590 public org.objectweb.openccm.Containers.SystemConfiguration 591 get_component_configuration() 592 { 593 return component_configuration_; 594 } 595 596 601 public void 602 add_home(org.omg.Components.CCMHome ref) 603 { 604 homes_.add(ref); 605 listener_.on_add(ref); 606 } 607 608 611 public void 612 set_container_home_info(ContainerHomeInformation containerHomeInfo) 613 { 614 this.containerHomeInfo=containerHomeInfo; 615 } 616 617 620 public ContainerHomeInformation 621 get_container_home_info() 622 { 623 return containerHomeInfo; 624 } 625 626 627 628 634 641 public org.omg.Components.ConfigValue[] 642 configuration() 643 { 644 return configuration_; 645 } 646 647 653 public org.omg.Components.Deployment.ComponentServer 654 get_component_server() 655 { 656 return the_component_server_.asComponentServer(); 657 } 658 659 677 public org.omg.Components.CCMHome 678 install_home(java.lang.String uuid, 679 java.lang.String entrypt, 680 org.omg.Components.ConfigValue[] config) 681 throws org.omg.Components.Deployment.UnknownImplId, 682 org.omg.Components.Deployment.ImplEntryPointNotFound, 683 org.omg.Components.Deployment.InstallationFailure, 684 org.omg.Components.Deployment.InvalidConfiguration 685 { 686 try { 687 688 load_lib_dependency(uuid); 692 693 for (int i=0; i<config.length; i++) 695 { 696 if (config[i].name.equals("load_lib_dependency")) 697 { 698 load_lib_dependency(config[i].value.extract_string()); 699 } 700 } 701 702 java.lang.String script = ""; 704 for (int i=0; i<config.length; i++) 705 { 706 if (config[i].name.equals("home_script")) 707 { 708 try 709 { 710 script = config[i].value.extract_string(); 711 } 712 catch(org.omg.CORBA.SystemException exc) 713 { 714 trace_error("install_home", 715 "Invalid type for the 'home_script' configuration value, a string is expected!!!", 716 null); 717 throw new org.omg.Components.Deployment.InvalidConfiguration( 718 org.omg.Components.Deployment.InvalidConfigValueType.value, 719 "home_script"); 720 } 721 break; 722 } 723 } 724 725 try 727 { 728 josh_.eval(script); 729 } 730 catch(fr.lifl.cim.jidlscript.lang.JISError exc) 731 { 732 trace_error("install_home", 733 "Invalid value for the 'home_script' configuration value!!!\n" 734 + script, 735 null); 736 throw new org.omg.Components.Deployment.InvalidConfiguration( 737 org.objectweb.openccm.Deployment.InvalidConfigValue.value, 738 "home_script"); 739 } 740 String IDL_name = retrieve_MI_name(entrypt); 746 if (IDL_name != null) 747 { 748 String methodName = IDL_name + "_homeMI.create_type_MI"; 750 try 752 { 753 home_type_ = 754 (HomeType) TheURLClassLoader 755 .getURLClassLoader() 756 .callStaticClassMethod( 757 methodName, 758 new Object [0]); 759 } 760 catch(Exception e) 761 { 762 home_type_ = null; 765 } 766 } 767 org.omg.Components.HomeExecutorBase home = 770 create_home_executor(entrypt); 771 772 String clazz_name = computeFullHomeServantClassName(home.getClass()); 773 if (clazz_name == null) 774 { 775 trace_error("install_home", 776 "Home servant class for " + home.getClass().getName() + " not found!!!", 777 null); 778 throw new org.omg.Components.Deployment.InstallationFailure( 779 org.objectweb.openccm.Deployment.HomeServantClassNotFound.value 780 ); 781 } 782 783 org.objectweb.openccm.Containers.HomeExecutorBase home_exec = 785 (org.objectweb.openccm.Containers.HomeExecutorBase) 786 create_home_executor(clazz_name + "._create_home_executor"); 787 788 home_exec._delegate(home); 789 790 org.objectweb.openccm.Containers.HomeServantImpl servant = 792 new org.objectweb.openccm.Containers.HomeServantImpl(); 793 servant.the_container_base(this); 794 home_exec._home_servant(servant); 795 servant.the_home_executor(home_exec); 796 servant.the_home_configuration(get_home_configuration()); 797 servant.the_component_configuration(get_component_configuration()); 798 servant.the_home_finder(home_manager_); 799 if (home_type_ != null) 801 { 802 HomeInstance _tmp_hi = home_type_.create_home_instance(); 803 if (_tmp_hi == null) 804 { 805 trace_error("install_home", "home instance is null ", null); 806 } 807 servant.the_home_instance(_tmp_hi); 808 809 } 810 else 811 { 812 trace_error( 813 "retrieve_MI_name", 814 "Instance MetaInformation for HomeFinder not supported ", 815 null); 816 } 817 org.omg.Components.CCMHome ref = rootPCA_.activate_home(servant); 819 820 821 int h_s=homes_.size(); 822 listener_.on_create(ref); 823 if(homes_.size()==h_s){ 824 homes_.add(ref); 825 } 826 return ref; 827 } 828 catch(org.omg.Components.Deployment.UnknownImplId exc) 829 { 830 trace_error("install_home", "Throw exception " + exc.getMessage(), null); 831 throw exc; 832 } 833 catch(org.omg.Components.Deployment.ImplEntryPointNotFound exc) 834 { 835 trace_error("install_home", "Throw exception " + exc.getMessage(), null); 836 throw exc; 837 } 838 catch(org.omg.Components.Deployment.InstallationFailure exc) 839 { 840 trace_error("install_home", "Throw exception " + exc.getMessage(), null); 841 throw exc; 842 } 843 catch(org.omg.Components.Deployment.InvalidConfiguration exc) 844 { 845 trace_error("install_home", "Throw exception " + exc.getMessage(), null); 846 throw exc; 847 } 848 catch(Throwable exc) 849 { 850 trace_error("install_home", "Unexpected Java exception!", exc); 851 trace_error("install_home", "Throw exception Components::Deployment::InstallationFailure", null); 852 throw new org.omg.Components.Deployment.InstallationFailure( 853 org.objectweb.openccm.Deployment.UnknownInstallationFailureReason.value 854 ); 855 } 856 } 857 858 864 public void 865 remove_home(org.omg.Components.CCMHome ref) 866 throws org.omg.Components.RemoveFailure 867 { 868 878 879 for(int i=0; i<homes_.size(); i++) 881 { 882 org.omg.Components.CCMHome h = 883 (org.omg.Components.CCMHome)homes_.get(i); 884 885 if(ref._is_equivalent(h)) 887 { 888 ref.remove_home(); 889 return; 890 } 891 } 892 893 throw new org.omg.Components.RemoveFailure(); 895 } 896 897 903 public org.omg.Components.CCMHome[] 904 get_homes() 905 { 906 org.omg.Components.CCMHome[] result = 907 new org.omg.Components.CCMHome[homes_.size()]; 908 909 for (int i=0;i<result.length;i++) 910 result[i] = (org.omg.Components.CCMHome)homes_.get(i); 911 912 return result; 913 } 914 915 921 public void 922 remove() 923 throws org.omg.Components.RemoveFailure 924 { 925 928 929 org.omg.Components.CCMHome[] homes = get_homes(); 931 for(int i=0; i<homes.length; i++) 932 { 933 homes[i].remove_home(); 934 } 935 if(listener_!=null) 936 listener_.on_destroy(); 937 938 if(the_component_server_!=null) 940 the_component_server_.unregister_container(the_container_ref()); 941 942 try { 943 org.objectweb.openccm.corba.TheRootPOA.getRootPOA().deactivate_object(org.objectweb.openccm.corba.TheRootPOA.getRootPOA().reference_to_id(the_container_ref())); 944 945 } catch (org.omg.PortableServer.POAPackage.WrongAdapter ex) { 946 throw new org.omg.Components.RemoveFailure(); 947 } catch (org.omg.PortableServer.POAPackage.WrongPolicy ex) { 948 throw new org.omg.Components.RemoveFailure(); 949 } catch (org.omg.PortableServer.POAPackage.ObjectNotActive ex) { 950 throw new org.omg.Components.RemoveFailure(); 951 } 952 } 953 } 954 | Popular Tags |