KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ejtools > graph > service > GraphServiceProvider


1 /*
2  * EJTools, the Enterprise Java Tools
3  *
4  * Distributable under LGPL license.
5  * See terms of license at www.gnu.org.
6  */

7 package org.ejtools.graph.service;
8
9 import java.beans.beancontext.BeanContext JavaDoc;
10 import java.beans.beancontext.BeanContextServices JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.Vector JavaDoc;
13
14 import org.apache.log4j.Logger;
15 import org.ejtools.beans.Sort;
16 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider;
17
18 /**
19  * @author Laurent Etiemble
20  * @version $Revision: 1.5 $
21  */

22 public class GraphServiceProvider extends CustomBeanContextServiceProvider implements GraphService
23 {
24    /** Description of the Field */
25    protected GraphService service = null;
26    /** Description of the Field */
27    private static Logger logger = Logger.getLogger(GraphServiceProvider.class);
28
29
30    /** Constructor for GraphServiceProvider. */
31    public GraphServiceProvider()
32    {
33       this.service = this;
34    }
35
36
37    /**
38     * @param consumer The feature to be added to the GraphConsumer attribute
39     */

40    public void addGraphConsumer(GraphConsumer consumer)
41    {
42       BeanContext JavaDoc parent = this.getBeanContext();
43       if (parent != null)
44       {
45          parent.add(consumer);
46          logger.debug("GraphConsumer added");
47       }
48    }
49
50
51    /**
52     * @param consumer The feature to be added to the GraphProducer attribute
53     * @param producer The feature to be added to the GraphProducer attribute
54     */

55    public void addGraphProducer(GraphConsumer consumer, GraphProducer producer)
56    {
57       if (!this.containsGraphConsumer(consumer))
58       {
59          this.addGraphConsumer(consumer);
60       }
61       consumer.addGraphProducer(producer);
62    }
63
64
65    /**
66     * Description of the Method
67     *
68     * @param consumer Description of the Parameter
69     * @return Description of the Return Value
70     */

71    public boolean containsGraphConsumer(GraphConsumer consumer)
72    {
73       BeanContext JavaDoc parent = this.getBeanContext();
74       if (parent != null)
75       {
76          return parent.contains(consumer);
77       }
78       return false;
79    }
80
81
82    /**
83     * @param bcs Description of the Parameter
84     * @param serviceClass Description of the Parameter
85     * @return The currentServiceSelectors value
86     */

87    public Iterator JavaDoc getCurrentServiceSelectors(BeanContextServices JavaDoc bcs, Class JavaDoc serviceClass)
88    {
89       return (new Vector JavaDoc()).iterator();
90    }
91
92
93    /**
94     * @return The graphConsumers value
95     */

96    public GraphConsumer[] getGraphConsumers()
97    {
98       Vector JavaDoc result = new Vector JavaDoc();
99       BeanContext JavaDoc parent = this.getBeanContext();
100       if (parent != null)
101       {
102          for (Iterator JavaDoc iterator = Sort.getChildrenByClass(parent.iterator(), GraphConsumer.class); iterator.hasNext(); )
103          {
104             GraphConsumer consumer = (GraphConsumer) iterator.next();
105             result.add(consumer);
106          }
107       }
108       return (GraphConsumer[]) result.toArray(new GraphConsumer[0]);
109    }
110
111
112    /**
113     * @param bcs Description of the Parameter
114     * @param requestor Description of the Parameter
115     * @param serviceClass Description of the Parameter
116     * @param serviceSelector Description of the Parameter
117     * @return The service value
118     */

119    public Object JavaDoc getService(BeanContextServices JavaDoc bcs, Object JavaDoc requestor, Class JavaDoc serviceClass, Object JavaDoc serviceSelector)
120    {
121       return this.service;
122    }
123
124
125    /**
126     * @param bcs Description of the Parameter
127     * @param requestor Description of the Parameter
128     * @param service Description of the Parameter
129     */

130    public void releaseService(BeanContextServices JavaDoc bcs, Object JavaDoc requestor, Object JavaDoc service) { }
131
132
133    /**
134     * @param consumer Description of the Parameter
135     */

136    public void removeGraphConsumer(GraphConsumer consumer)
137    {
138       BeanContext JavaDoc parent = this.getBeanContext();
139       if (parent != null)
140       {
141          parent.remove(consumer);
142          logger.debug("GraphConsumer removed");
143       }
144    }
145
146
147    /**
148     * @param producer Description of the Parameter
149     */

150    public void removeGraphProducer(GraphProducer producer)
151    {
152       BeanContext JavaDoc parent = this.getBeanContext();
153       if (parent != null)
154       {
155          for (Iterator JavaDoc iterator = Sort.getChildrenByClass(parent.iterator(), GraphConsumer.class); iterator.hasNext(); )
156          {
157             GraphConsumer consumer = (GraphConsumer) iterator.next();
158             consumer.removeGraphProducer(producer);
159          }
160       }
161    }
162
163
164    /**
165     * @return The serviceClass value
166     */

167    protected Class JavaDoc[] getServiceClass()
168    {
169       return new Class JavaDoc[]{GraphService.class};
170    }
171 }
172
Popular Tags