01: /*
02: * Copyright 2000-2001,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
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
30: ProducerRegistry {
31:
32: private Hashtable producers = null;
33:
34: public GenericProducerRegistryImpl() {
35: producers = new Hashtable();
36: }
37:
38: /**
39: * Add a producer to the registry
40: *
41: * @param producer The producer to add
42: */
43: public void addProducer(Producer producer) {
44: if (producer != null) {
45: producers.put(producer.getID(), producer);
46: }
47: }
48:
49: /**
50: * Get the producer for the given URL
51: *
52: * @param id The ID of the producer
53: *
54: * @return The producer with the given ID
55: **/
56: public Producer getProducer(String id) {
57:
58: return (Producer) producers.get(id);
59: }
60:
61: /**
62: * Get all producer in the registry
63: *
64: * @return Iterator with all producers
65: **/
66: public Iterator getAllProducers() {
67: return producers.values().iterator();
68: }
69:
70: /**
71: * Remove the producer with the given ID from the registry
72: *
73: * @param id The ID of the producer
74: *
75: * @return The producer which had been mapped to this id or
76: * null if no producer was found with this id
77: **/
78: public Producer removeProducer(String id) {
79: return (Producer) producers.remove(id);
80: }
81:
82: /**
83: * Remove all producer objects from the registry
84: **/
85: public void removeAllProducers() {
86: producers.clear();
87: }
88:
89: /**
90: * Check if a producer with the given ID exists in the registry.
91: *
92: * @param id The ID of the producer
93: *
94: * @return True if producer exists with this ID
95: **/
96: public boolean existsProducer(String id) {
97: return producers.containsKey(id);
98: }
99: }
|