01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.binding;
19:
20: import java.util.Map;
21: import java.util.ResourceBundle;
22: import java.util.concurrent.ConcurrentHashMap;
23:
24: import javax.annotation.PostConstruct;
25: import javax.annotation.Resource;
26:
27: import org.apache.cxf.Bus;
28: import org.apache.cxf.BusException;
29: import org.apache.cxf.common.i18n.BundleUtils;
30: import org.apache.cxf.common.i18n.Message;
31:
32: public final class BindingFactoryManagerImpl implements
33: BindingFactoryManager {
34:
35: private static final ResourceBundle BUNDLE = BundleUtils
36: .getBundle(BindingFactoryManagerImpl.class);
37:
38: final Map<String, BindingFactory> bindingFactories;
39: Bus bus;
40:
41: public BindingFactoryManagerImpl() throws BusException {
42: bindingFactories = new ConcurrentHashMap<String, BindingFactory>();
43: }
44:
45: public BindingFactoryManagerImpl(
46: Map<String, BindingFactory> bindingFactories) {
47: super ();
48: if (!(bindingFactories instanceof ConcurrentHashMap)) {
49: bindingFactories = new ConcurrentHashMap<String, BindingFactory>(
50: bindingFactories);
51: }
52: this .bindingFactories = bindingFactories;
53: }
54:
55: @Resource
56: public void setBus(Bus b) {
57: bus = b;
58: }
59:
60: @PostConstruct
61: public void register() {
62: if (null != bus) {
63: bus.setExtension(this , BindingFactoryManager.class);
64: }
65: }
66:
67: public void registerBindingFactory(String name,
68: BindingFactory factory) {
69: bindingFactories.put(name, factory);
70: }
71:
72: public void unregisterBindingFactory(String name) {
73: bindingFactories.remove(name);
74: }
75:
76: public BindingFactory getBindingFactory(String namespace)
77: throws BusException {
78: BindingFactory factory = bindingFactories.get(namespace);
79: if (null == factory) {
80: throw new BusException(new Message(
81: "NO_BINDING_FACTORY_EXC", BUNDLE, namespace));
82: }
83: return factory;
84: }
85:
86: }
|