View Javadoc

1   package net.sourceforge.blogentis.plugins.impl;
2   
3   //-----------------------------------------------------------------------
4   //Blogentis - a blog publishing platform.
5   //Copyright (C) 2004 Tassos Bassoukos <abassouk@gmail.com>
6   //
7   //This library is free software; you can redistribute it and/or
8   //modify it under the terms of the GNU Lesser General Public
9   //License as published by the Free Software Foundation; either
10  //version 2.1 of the License, or (at your option) any later version.
11  //
12  //This library is distributed in the hope that it will be useful,
13  //but WITHOUT ANY WARRANTY; without even the implied warranty of
14  //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  //Lesser General Public License for more details.
16  //
17  //You should have received a copy of the GNU Lesser General Public
18  //License along with this library; if not, write to the Free Software
19  //Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20  //-----------------------------------------------------------------------
21  //
22  //$Id: ExtensionPointList.java,v 1.1 2004/10/22 17:34:14 tassos Exp $
23  //
24  
25  import java.util.ArrayList;
26  import java.util.Iterator;
27  import java.util.List;
28  
29  import net.sourceforge.blogentis.plugins.BlogPluginService;
30  import net.sourceforge.blogentis.plugins.IExtensionPoint;
31  
32  import org.apache.commons.logging.Log;
33  import org.apache.commons.logging.LogFactory;
34  
35  /***
36   * An ArrayList that handles extension point management.
37   * 
38   * @author abas
39   */
40  class ExtensionPointList {
41      private static final Log log = LogFactory.getLog(BlogPluginService.class);
42  
43      private List list = new ArrayList();
44  
45      public synchronized void registerExtensionPoint(IExtensionPoint point) {
46          if (list.contains(point)) {
47              log.warn("Extension point '" + point.getName()
48                       + "' already exists for addition");
49              return;
50          }
51          list.add(point);
52      }
53  
54      public synchronized void deregisterExtensionPoint(IExtensionPoint point) {
55          if (list.contains(point)) {
56              log.warn("Extension point '" + point.getName()
57                       + "' does not exits for removal");
58              return;
59          }
60          list.remove(point);
61      }
62  
63      public synchronized IExtensionPoint locateExtensionPoint(Class name) {
64          for(Iterator i = list.iterator(); i.hasNext();) {
65              Object o = i.next();
66              if (name.isInstance(o))
67                  return (IExtensionPoint)o;
68          }
69          return null;
70      }
71      
72      public Iterator iterator(){
73          return list.iterator();
74      }
75  }