1 package net.sourceforge.ejtools.deploy.factories; 2 3 import java.beans.beancontext.BeanContextServiceProvider ; 4 import java.beans.beancontext.BeanContextServices ; 5 import java.beans.beancontext.BeanContextServicesSupport ; 6 import java.net.JarURLConnection ; 7 import java.net.URL ; 8 import java.net.URLClassLoader ; 9 import java.util.Iterator ; 10 import java.util.Vector ; 11 import java.util.jar.Attributes ; 12 13 19 public class FactoryManagerServiceProvider extends BeanContextServicesSupport implements BeanContextServiceProvider , FactoryManagerService 20 { 21 22 protected final static String TAG = "J2EE-DeploymentFactoryManager-Implementation-Class"; 23 24 25 32 public Iterator getCurrentServiceSelectors(BeanContextServices bcs, java.lang.Class serviceClass) 33 { 34 return (new Vector ()).iterator(); 35 } 36 37 38 47 public Object getService(BeanContextServices bcs, java.lang.Object requestor, java.lang.Class serviceClass, java.lang.Object serviceSelector) 48 { 49 return this; 50 } 51 52 53 58 public Iterator listFactories() 59 { 60 return iterator(); 61 } 62 63 64 65 public void loadFactories() 66 { 67 try 68 { 69 URL [] urls = ((URLClassLoader ) Thread.currentThread().getContextClassLoader()).getURLs(); 71 72 for (int i = 0; i < urls.length; i++) 73 { 74 if (urls[i].getFile().endsWith(".jar")) 75 { 76 Attributes attr = ((JarURLConnection ) new URL ("jar:" + urls[i] + "!/").openConnection()).getMainAttributes(); 77 String factoryClass = attr.getValue(FactoryManagerServiceProvider.TAG); 78 System.out.println("URL " + urls[i] + " " + factoryClass); 79 if (factoryClass != null) 80 { 81 try 82 { 83 87 } 90 catch (Exception e) 91 { 92 e.printStackTrace(); 93 } 94 } 95 } 96 } 97 98 } 99 catch (Exception e) 100 { 101 e.printStackTrace(); 102 } 103 104 } 105 106 107 114 public void releaseService(BeanContextServices bcs, java.lang.Object requestor, java.lang.Object service) { } 115 116 117 118 protected void initializeBeanContextResources() 119 { 120 ((BeanContextServices ) getBeanContext()).addService(FactoryManagerService.class, this); 121 } 122 123 124 125 protected void releaseBeanContextResources() 126 { 127 ((BeanContextServices ) getBeanContext()).revokeService(FactoryManagerService.class, this, true); 128 } 129 } 130 131 | Popular Tags |