GenericProducerRegistryImpl.java |
1 /* 2 * Copyright 2000-2001,2004 The Apache Software Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 /* 18 19 */ 20 21 package org.apache.wsrp4j.consumer.driver; 22 23 import java.util.Hashtable; 24 import java.util.Iterator; 25 26 import org.apache.wsrp4j.consumer.Producer; 27 import org.apache.wsrp4j.consumer.ProducerRegistry; 28 29 public abstract class GenericProducerRegistryImpl implements ProducerRegistry { 30 31 private Hashtable producers = null; 32 33 public GenericProducerRegistryImpl() { 34 producers = new Hashtable(); 35 } 36 37 /** 38 * Add a producer to the registry 39 * 40 * @param producer The producer to add 41 */ 42 public void addProducer(Producer producer) { 43 if (producer != null) { 44 producers.put(producer.getID(), producer); 45 } 46 } 47 48 /** 49 * Get the producer for the given URL 50 * 51 * @param id The ID of the producer 52 * 53 * @return The producer with the given ID 54 **/ 55 public Producer getProducer(String id) { 56 57 return (Producer) producers.get(id); 58 } 59 60 /** 61 * Get all producer in the registry 62 * 63 * @return Iterator with all producers 64 **/ 65 public Iterator getAllProducers() { 66 return producers.values().iterator(); 67 } 68 69 /** 70 * Remove the producer with the given ID from the registry 71 * 72 * @param id The ID of the producer 73 * 74 * @return The producer which had been mapped to this id or 75 * null if no producer was found with this id 76 **/ 77 public Producer removeProducer(String id) { 78 return (Producer) producers.remove(id); 79 } 80 81 /** 82 * Remove all producer objects from the registry 83 **/ 84 public void removeAllProducers() { 85 producers.clear(); 86 } 87 88 /** 89 * Check if a producer with the given ID exists in the registry. 90 * 91 * @param id The ID of the producer 92 * 93 * @return True if producer exists with this ID 94 **/ 95 public boolean existsProducer(String id) { 96 return producers.containsKey(id); 97 } 98 }