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.feature;
19:
20: import java.util.List;
21:
22: import org.apache.cxf.Bus;
23: import org.apache.cxf.endpoint.Client;
24: import org.apache.cxf.endpoint.Server;
25: import org.apache.cxf.interceptor.InterceptorProvider;
26:
27: /**
28: * A Feature is something that is able to customize a Server, Client, or Bus, typically
29: * adding capabilities. For instance, there may be a LoggingFeature which configures
30: * one of the above to log each of their messages.
31: * <p>
32: * By default the initialize methods all delegate to initializeProvider(InterceptorProvider).
33: * If you're simply adding interceptors to a Server, Client, or Bus, this allows you to add
34: * them easily.
35: */
36: public abstract class AbstractFeature {
37: public void initialize(Server server, Bus bus) {
38: initializeProvider(server.getEndpoint(), bus);
39: }
40:
41: public void initialize(Client client, Bus bus) {
42: initializeProvider(client, bus);
43: }
44:
45: public void initialize(Bus bus) {
46: initializeProvider(bus, bus);
47: }
48:
49: protected void initializeProvider(InterceptorProvider provider,
50: Bus bus) {
51:
52: }
53:
54: /**
55: * Convenience method to extract a feature by type from an active list.
56: *
57: * @param features the given feature list
58: * @param type the feature type required
59: * @return the feature of the specified type if active
60: */
61: public static <T> T getActive(List<AbstractFeature> features,
62: Class<T> type) {
63: T active = null;
64: if (features != null) {
65: for (AbstractFeature feature : features) {
66: if (type.isInstance(feature)) {
67: active = type.cast(feature);
68: break;
69: }
70: }
71: }
72: return active;
73: }
74: }
|