1 7 package org.ejtools.graph.service; 8 9 import java.beans.beancontext.BeanContext ; 10 import java.beans.beancontext.BeanContextServices ; 11 import java.util.Iterator ; 12 import java.util.Vector ; 13 14 import org.apache.log4j.Logger; 15 import org.ejtools.beans.Sort; 16 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider; 17 18 22 public class GraphServiceProvider extends CustomBeanContextServiceProvider implements GraphService 23 { 24 25 protected GraphService service = null; 26 27 private static Logger logger = Logger.getLogger(GraphServiceProvider.class); 28 29 30 31 public GraphServiceProvider() 32 { 33 this.service = this; 34 } 35 36 37 40 public void addGraphConsumer(GraphConsumer consumer) 41 { 42 BeanContext parent = this.getBeanContext(); 43 if (parent != null) 44 { 45 parent.add(consumer); 46 logger.debug("GraphConsumer added"); 47 } 48 } 49 50 51 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 71 public boolean containsGraphConsumer(GraphConsumer consumer) 72 { 73 BeanContext parent = this.getBeanContext(); 74 if (parent != null) 75 { 76 return parent.contains(consumer); 77 } 78 return false; 79 } 80 81 82 87 public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass) 88 { 89 return (new Vector ()).iterator(); 90 } 91 92 93 96 public GraphConsumer[] getGraphConsumers() 97 { 98 Vector result = new Vector (); 99 BeanContext parent = this.getBeanContext(); 100 if (parent != null) 101 { 102 for (Iterator 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 119 public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector) 120 { 121 return this.service; 122 } 123 124 125 130 public void releaseService(BeanContextServices bcs, Object requestor, Object service) { } 131 132 133 136 public void removeGraphConsumer(GraphConsumer consumer) 137 { 138 BeanContext parent = this.getBeanContext(); 139 if (parent != null) 140 { 141 parent.remove(consumer); 142 logger.debug("GraphConsumer removed"); 143 } 144 } 145 146 147 150 public void removeGraphProducer(GraphProducer producer) 151 { 152 BeanContext parent = this.getBeanContext(); 153 if (parent != null) 154 { 155 for (Iterator 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 167 protected Class [] getServiceClass() 168 { 169 return new Class []{GraphService.class}; 170 } 171 } 172 | Popular Tags |