001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.bus.extension;
019:
020: import java.util.HashMap;
021: import java.util.Map;
022:
023: import org.apache.cxf.binding.BindingFactory;
024: import org.apache.cxf.binding.BindingFactoryManager;
025: import org.apache.cxf.binding.BindingFactoryManagerImpl;
026: import org.apache.cxf.bus.BusState;
027: import org.apache.cxf.bus.CXFBusImpl;
028: import org.apache.cxf.buslifecycle.BusLifeCycleManager;
029: import org.apache.cxf.configuration.Configurer;
030: import org.apache.cxf.configuration.NullConfigurer;
031: import org.apache.cxf.resource.DefaultResourceManager;
032: import org.apache.cxf.resource.ObjectTypeResolver;
033: import org.apache.cxf.resource.PropertiesResolver;
034: import org.apache.cxf.resource.ResourceManager;
035: import org.apache.cxf.resource.ResourceResolver;
036: import org.apache.cxf.resource.SinglePropertyResolver;
037: import org.apache.cxf.transport.ConduitInitiator;
038: import org.apache.cxf.transport.ConduitInitiatorManager;
039: import org.apache.cxf.transport.ConduitInitiatorManagerImpl;
040: import org.apache.cxf.transport.DestinationFactory;
041: import org.apache.cxf.transport.DestinationFactoryManager;
042: import org.apache.cxf.transport.DestinationFactoryManagerImpl;
043:
044: /**
045: * This bus uses CXF's built in extension manager to load components
046: * (as opposed to using the Spring bus implementation). While this is faster
047: * to load it doesn't allow extensive configuration and customization like
048: * the Spring bus does.
049: */
050: public class ExtensionManagerBus extends CXFBusImpl {
051:
052: public static final String BUS_PROPERTY_NAME = "bus";
053: private static final String BUS_ID_PROPERTY_NAME = "org.apache.cxf.bus.id";
054:
055: private static final String BUS_EXTENSION_RESOURCE = "META-INF/bus-extensions.xml";
056:
057: public ExtensionManagerBus(Map<Class, Object> e,
058: Map<String, Object> properties) {
059: super (e);
060:
061: if (null == properties) {
062: properties = new HashMap<String, Object>();
063: }
064:
065: Configurer configurer = (Configurer) extensions
066: .get(Configurer.class);
067: if (null == configurer) {
068: configurer = new NullConfigurer();
069: extensions.put(Configurer.class, configurer);
070: }
071:
072: setId(getBusId(properties));
073:
074: ResourceManager resourceManager = new DefaultResourceManager();
075:
076: properties.put(BUS_ID_PROPERTY_NAME, BUS_PROPERTY_NAME);
077: properties.put(BUS_PROPERTY_NAME, this );
078:
079: ResourceResolver propertiesResolver = new PropertiesResolver(
080: properties);
081: resourceManager.addResourceResolver(propertiesResolver);
082:
083: ResourceResolver busResolver = new SinglePropertyResolver(
084: BUS_PROPERTY_NAME, this );
085: resourceManager.addResourceResolver(busResolver);
086: resourceManager
087: .addResourceResolver(new ObjectTypeResolver(this ));
088:
089: extensions.put(ResourceManager.class, resourceManager);
090:
091: ExtensionManagerImpl em = new ExtensionManagerImpl(
092: BUS_EXTENSION_RESOURCE, Thread.currentThread()
093: .getContextClassLoader(), extensions,
094: resourceManager);
095:
096: setState(BusState.INITIAL);
097:
098: BusLifeCycleManager lifeCycleManager = this
099: .getExtension(BusLifeCycleManager.class);
100: if (null != lifeCycleManager) {
101: lifeCycleManager.initComplete();
102:
103: }
104:
105: DestinationFactoryManager dfm = this
106: .getExtension(DestinationFactoryManager.class);
107: if (null == dfm) {
108: dfm = new DestinationFactoryManagerImpl(
109: new DeferredMap<DestinationFactory>(em,
110: DestinationFactory.class));
111: extensions.put(DestinationFactoryManager.class, dfm);
112: }
113:
114: ConduitInitiatorManager cfm = this
115: .getExtension(ConduitInitiatorManager.class);
116: if (null == cfm) {
117: cfm = new ConduitInitiatorManagerImpl(
118: new DeferredMap<ConduitInitiator>(em,
119: ConduitInitiator.class));
120: extensions.put(ConduitInitiatorManager.class, cfm);
121: }
122:
123: BindingFactoryManager bfm = this
124: .getExtension(BindingFactoryManager.class);
125: if (null == bfm) {
126: bfm = new BindingFactoryManagerImpl(
127: new DeferredMap<BindingFactory>(em,
128: BindingFactory.class));
129: extensions.put(BindingFactoryManager.class, bfm);
130: }
131: }
132:
133: public ExtensionManagerBus() {
134: this (null, null);
135: }
136:
137: private String getBusId(Map<String, Object> properties) {
138:
139: String busId = null;
140:
141: // first check properties
142: if (null != properties) {
143: busId = (String) properties.get(BUS_ID_PROPERTY_NAME);
144: if (null != busId && !"".equals(busId)) {
145: return busId;
146: }
147: }
148:
149: // next check system properties
150: busId = System.getProperty(BUS_ID_PROPERTY_NAME);
151: if (null != busId && !"".equals(busId)) {
152: return busId;
153: }
154:
155: // otherwise use default
156: return DEFAULT_BUS_ID;
157: }
158: }
|