KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > common > Registry


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix.common;
18
19 import java.util.Collection JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23
24 public class Registry {
25
26     protected BaseComponent component;
27     protected Map JavaDoc endpoints;
28     protected Map JavaDoc serviceUnits;
29     
30     public Registry(BaseComponent component) {
31         this.component = component;
32         this.endpoints = new HashMap JavaDoc();
33         this.serviceUnits = new HashMap JavaDoc();
34     }
35
36     public Endpoint getEndpoint(String JavaDoc key) {
37         return (Endpoint) this.endpoints.get(key);
38     }
39     
40     public ServiceUnit getServiceUnit(String JavaDoc name) {
41         return (ServiceUnit) this.serviceUnits.get(name);
42     }
43     
44     public void registerEndpoint(Endpoint ep) {
45         String JavaDoc key = EndpointSupport.getKey(ep);
46         if (this.endpoints.put(key, ep) != null) {
47             throw new IllegalStateException JavaDoc("An endpoint is already registered for key: " + key);
48         }
49     }
50     
51     public void unregisterEndpoint(Endpoint ep) {
52         this.endpoints.remove(EndpointSupport.getKey(ep));
53     }
54     
55     public void registerServiceUnit(ServiceUnit su) {
56         this.serviceUnits.put(su.getName(), su);
57         Collection JavaDoc endpoints = (Collection JavaDoc) su.getEndpoints();
58         for (Iterator JavaDoc iter = endpoints.iterator(); iter.hasNext();) {
59             Endpoint ep = (Endpoint) iter.next();
60             registerEndpoint(ep);
61         }
62     }
63     
64     public void unregisterServiceUnit(ServiceUnit su) {
65         this.serviceUnits.remove(su.getName());
66         Collection JavaDoc endpoints = (Collection JavaDoc) su.getEndpoints();
67         for (Iterator JavaDoc iter = endpoints.iterator(); iter.hasNext();) {
68             Endpoint ep = (Endpoint) iter.next();
69             unregisterEndpoint(ep);
70         }
71     }
72     
73 }
74
Popular Tags