1 22 23 package org.objectweb.petals.engine.pojo; 24 25 import static org.objectweb.petals.component.common.util.ClassLoaderUtil.createClassLoader; 26 27 import java.util.List ; 28 import java.util.Map ; 29 30 import org.objectweb.petals.component.common.PEtALSComponentSDKException; 31 import org.objectweb.petals.component.common.su.ServiceUnitListener; 32 import org.objectweb.petals.component.common.util.PetalsExtensionsUtil; 33 import org.objectweb.petals.tools.jbicommon.descriptor.Extensions; 34 import org.objectweb.petals.tools.jbicommon.descriptor.JBIDescriptor; 35 import org.objectweb.petals.tools.jbicommon.descriptor.Provides; 36 37 public class PojoServiceUnitListener implements ServiceUnitListener { 38 39 private Map <String , Pojo> pojos; 40 41 private PojoSE pojoSE; 42 43 44 public PojoServiceUnitListener(PojoSE pojoSE, Map <String , Pojo> pojos){ 45 this.pojos = pojos; 46 this.pojoSE = pojoSE; 47 } 48 49 public void onSUDeployed(String serviceUnitName, String suRootPath, 50 JBIDescriptor descriptor) throws PEtALSComponentSDKException { 51 52 List <Provides> providesList = descriptor.getServices().getProvides(); 54 if(providesList.size() != 1){ 55 throw new PEtALSComponentSDKException( 56 "One, and only one, 'provides' section is required un the JBI.XML descriptor."); 57 } 58 Extensions extensions = providesList.get(0).getExtensions(); 59 60 String className =null; 62 className = PetalsExtensionsUtil.extractValueFromKeyValueExtension( 63 extensions, "class-name"); 64 if(className == null){ 65 throw new PEtALSComponentSDKException( 66 "'class-name' property not found in the JBI.XML descriptor"); 67 } 68 69 ClassLoader classLoader = createClassLoader(suRootPath, this.getClass().getClassLoader()); 71 72 Class clazz =null; 74 try { 75 clazz = classLoader.loadClass(className); 76 } catch (ClassNotFoundException e) { 77 throw new PEtALSComponentSDKException( 78 className+ " class not found in the service-unit libraries.",e); 79 } 80 81 Pojo pojo=null; 83 try { 84 pojo = new Pojo(clazz.newInstance(), pojoSE); 85 } catch (Exception e) { 86 throw new PEtALSComponentSDKException( 87 className+ " found, but can not create an instance.",e); 88 } 89 90 pojo.init(); 92 pojos.put(serviceUnitName,pojo); 93 } 94 95 public void onSUStarted(String serviceUnitName) 96 throws PEtALSComponentSDKException { 97 pojos.get(serviceUnitName).start(); 98 } 99 100 public void onSUStopped(String serviceUnitName) 101 throws PEtALSComponentSDKException { 102 pojos.get(serviceUnitName).stop(); 103 } 104 105 public void onSUUndeployed(String serviceUnitName, String suRootPath, 106 JBIDescriptor descriptor) throws PEtALSComponentSDKException { 107 pojos.remove(serviceUnitName); 108 } 109 110 } 111 | Popular Tags |