1 /* 2 * JBoss, Home of Professional Open Source 3 * Copyright 2005, JBoss Inc., and individual contributors as indicated 4 * by the @authors tag. See the copyright.txt in the distribution for a 5 * full listing of individual contributors. 6 * 7 * This is free software; you can redistribute it and/or modify it 8 * under the terms of the GNU Lesser General Public License as 9 * published by the Free Software Foundation; either version 2.1 of 10 * the License, or (at your option) any later version. 11 * 12 * This software 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 software; if not, write to the Free 19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org. 21 */ 22 package org.jboss.kernel.plugins.registry; 23 24 import java.util.Iterator; 25 import java.util.List; 26 import java.util.ListIterator; 27 28 import org.jboss.kernel.plugins.AbstractKernelObject; 29 import org.jboss.kernel.spi.registry.KernelRegistry; 30 import org.jboss.kernel.spi.registry.KernelRegistryEntry; 31 import org.jboss.kernel.spi.registry.KernelRegistryEntryNotFoundException; 32 import org.jboss.kernel.spi.registry.KernelRegistryPlugin; 33 import org.jboss.util.collection.CollectionsFactory; 34 35 /** 36 * Abstract Kernel registry. 37 * 38 * @author <a HREF="adrian@jboss.com">Adrian Brock</a> 39 * @author <a HREF="mailto:les.hazlewood@jboss.org">Les A. Hazlewood</a> 40 * @version $Revision: 45764 $ 41 */ 42 public abstract class AbstractKernelRegistry extends AbstractKernelObject implements KernelRegistry 43 { 44 /** The registry factories */ 45 protected List<KernelRegistryPlugin> factories = CollectionsFactory.createCopyOnWriteList(); 46 47 /** 48 * Create an abstract kernel registry 49 * 50 * @throws Exception for any error 51 */ 52 public AbstractKernelRegistry() throws Exception 53 { 54 } 55 56 /** 57 * Add a kernel registry factory 58 * 59 * @param factory the factory to add 60 */ 61 public void addKernelRegistryFactory(KernelRegistryPlugin factory) 62 { 63 factories.add(factory); 64 if (log.isTraceEnabled()) 65 log.trace("Registry " + this + " added registry factory " + factory); 66 } 67 68 /** 69 * Remove a kernel registry factory 70 * 71 * @param factory the factory to remove 72 */ 73 public void removeKernelRegistryFactory(KernelRegistryPlugin factory) 74 { 75 factories.remove(factory); 76 if (log.isTraceEnabled()) 77 log.trace("Registry " + this + " removed registry factory " + factory); 78 } 79 80 public KernelRegistryEntry getEntry(Object name) 81 { 82 for (ListIterator i = factories.listIterator(); i.hasNext();) 83 { 84 KernelRegistryPlugin factory = (KernelRegistryPlugin) i.next(); 85 KernelRegistryEntry entry = factory.getEntry(name); 86 if (entry != null) 87 return entry; 88 } 89 throw new KernelRegistryEntryNotFoundException("Entry not found with name: " + name); 90 } 91 92 public boolean containsEntry(Object name) 93 { 94 Iterator i = factories.iterator(); 95 while (i.hasNext()) 96 { 97 KernelRegistryPlugin factory = (KernelRegistryPlugin) i.next(); 98 KernelRegistryEntry entry = factory.getEntry(name); 99 if (entry != null) 100 return true; 101 } 102 return false; 103 } 104 } 105