01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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:
18: /*
19: * ChainBuilder ESB
20: * Visual Enterprise Integration
21: *
22: * Copyright (C) 2006 Bostech Corporation
23: *
24: * This program is free software; you can redistribute it and/or modify it
25: * under the terms of the GNU General Public License as published by the
26: * Free Software Foundation; either version 2 of the License, or (at your option)
27: * any later version.
28: *
29: * This program is distributed in the hope that it will be useful,
30: * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
31: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
32: * for more details.
33: *
34: * You should have received a copy of the GNU General Public License along with
35: * this program; if not, write to the Free Software Foundation, Inc.,
36: * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
37: *
38: * $Id: ComponentRegistry.java 6866 2007-04-17 19:50:23Z tvolle $
39: */
40: package com.bostechcorp.cbesb.runtime.ccsl.jbi.messaging;
41:
42: import java.util.Collection;
43: import java.util.HashMap;
44: import java.util.Iterator;
45: import java.util.Map;
46:
47: public class ComponentRegistry {
48:
49: protected CbComponent component;
50: protected Map<String, CbEndpoint> endpoints;
51: protected Map<String, CbServiceUnit> serviceUnits;
52:
53: public ComponentRegistry(CbComponent component) {
54: this .component = component;
55: this .endpoints = new HashMap<String, CbEndpoint>();
56: this .serviceUnits = new HashMap<String, CbServiceUnit>();
57: }
58:
59: public CbEndpoint getEndpoint(String key) {
60: return this .endpoints.get(key);
61: }
62:
63: public CbServiceUnit getServiceUnit(String name) {
64: return this .serviceUnits.get(name);
65: }
66:
67: public void registerEndpoint(CbEndpoint ep) {
68: String key = EndpointKeyUtil.getKey(ep);
69: if (this .endpoints.put(key, ep) != null) {
70: throw new IllegalStateException(
71: "An endpoint is already registered for key: " + key);
72: }
73: }
74:
75: public void unregisterEndpoint(CbEndpoint ep) {
76: this .endpoints.remove(EndpointKeyUtil.getKey(ep));
77: }
78:
79: public void registerServiceUnit(CbServiceUnit su) {
80: this .serviceUnits.put(su.getName(), su);
81: Collection endpoints = (Collection) su.getEndpoints();
82: for (Iterator iter = endpoints.iterator(); iter.hasNext();) {
83: CbEndpoint ep = (CbEndpoint) iter.next();
84: registerEndpoint(ep);
85: }
86: }
87:
88: public void unregisterServiceUnit(CbServiceUnit su) {
89: this .serviceUnits.remove(su.getName());
90: Collection endpoints = (Collection) su.getEndpoints();
91: for (Iterator iter = endpoints.iterator(); iter.hasNext();) {
92: CbEndpoint ep = (CbEndpoint) iter.next();
93: unregisterEndpoint(ep);
94: }
95: }
96:
97: }
|