KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > ejtools > deploy > factories > FactoryManagerServiceProvider


1 package net.sourceforge.ejtools.deploy.factories;
2
3 import java.beans.beancontext.BeanContextServiceProvider JavaDoc;
4 import java.beans.beancontext.BeanContextServices JavaDoc;
5 import java.beans.beancontext.BeanContextServicesSupport JavaDoc;
6 import java.net.JarURLConnection JavaDoc;
7 import java.net.URL JavaDoc;
8 import java.net.URLClassLoader JavaDoc;
9 import java.util.Iterator JavaDoc;
10 import java.util.Vector JavaDoc;
11 import java.util.jar.Attributes JavaDoc;
12
13 /**
14  * Description of the Class
15  *
16  * @author letiembl
17  * @created 13 décembre 2001
18  */

19 public class FactoryManagerServiceProvider extends BeanContextServicesSupport JavaDoc implements BeanContextServiceProvider JavaDoc, FactoryManagerService
20 {
21    /** Description of the Field */
22    protected final static String JavaDoc TAG = "J2EE-DeploymentFactoryManager-Implementation-Class";
23
24
25    /**
26     * Getter for the currentServiceSelectors attribute
27     *
28     * @param bcs Description of Parameter
29     * @param serviceClass Description of Parameter
30     * @return The value
31     */

32    public Iterator JavaDoc getCurrentServiceSelectors(BeanContextServices JavaDoc bcs, java.lang.Class JavaDoc serviceClass)
33    {
34       return (new Vector JavaDoc()).iterator();
35    }
36
37
38    /**
39     * Getter for the service attribute
40     *
41     * @param bcs Description of Parameter
42     * @param requestor Description of Parameter
43     * @param serviceClass Description of Parameter
44     * @param serviceSelector Description of Parameter
45     * @return The value
46     */

47    public Object JavaDoc getService(BeanContextServices JavaDoc bcs, java.lang.Object JavaDoc requestor, java.lang.Class JavaDoc serviceClass, java.lang.Object JavaDoc serviceSelector)
48    {
49       return this;
50    }
51
52
53    /**
54     * Description of the Method
55     *
56     * @return Description of the Return Value
57     */

58    public Iterator JavaDoc listFactories()
59    {
60       return iterator();
61    }
62
63
64    /** Description of the Method */
65    public void loadFactories()
66    {
67       try
68       {
69          // Find list of managers
70
URL JavaDoc[] urls = ((URLClassLoader JavaDoc) 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 JavaDoc attr = ((JarURLConnection JavaDoc) new URL JavaDoc("jar:" + urls[i] + "!/").openConnection()).getMainAttributes();
77                String JavaDoc factoryClass = attr.getValue(FactoryManagerServiceProvider.TAG);
78                System.out.println("URL " + urls[i] + " " + factoryClass);
79                if (factoryClass != null)
80                {
81                   try
82                   {
83 // DeploymentFactoryManager manager = (DeploymentFactoryManager) Class.forName(factoryClass).newInstance();
84
// System.out.println("manager " + manager);
85
// add(manager);
86

87 // DeploymentFactoryManagerProxy proxy = new DeploymentFactoryManagerProxy(manager);
88
// add(proxy);
89
}
90                   catch (Exception JavaDoc e)
91                   {
92                      e.printStackTrace();
93                   }
94                }
95             }
96          }
97
98       }
99       catch (Exception JavaDoc e)
100       {
101          e.printStackTrace();
102       }
103
104    }
105
106
107    /**
108     * Description of the Method
109     *
110     * @param bcs Description of Parameter
111     * @param requestor Description of Parameter
112     * @param service Description of Parameter
113     */

114    public void releaseService(BeanContextServices JavaDoc bcs, java.lang.Object JavaDoc requestor, java.lang.Object JavaDoc service) { }
115
116
117    /** Description of the Method */
118    protected void initializeBeanContextResources()
119    {
120       ((BeanContextServices JavaDoc) getBeanContext()).addService(FactoryManagerService.class, this);
121    }
122
123
124    /** Description of the Method */
125    protected void releaseBeanContextResources()
126    {
127       ((BeanContextServices JavaDoc) getBeanContext()).revokeService(FactoryManagerService.class, this, true);
128    }
129 }
130
131
Popular Tags