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.databinding.stax;
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.feature.AbstractFeature;
26: import org.apache.cxf.interceptor.BareInInterceptor;
27: import org.apache.cxf.interceptor.DocLiteralInInterceptor;
28: import org.apache.cxf.interceptor.Interceptor;
29: import org.apache.cxf.interceptor.WrappedInInterceptor;
30: import org.apache.cxf.phase.PhaseInterceptor;
31:
32: public class StaxDataBindingFeature extends AbstractFeature {
33:
34: @Override
35: public void initialize(Client client, Bus bus) {
36: removeDatabindingInterceptor(client.getEndpoint().getBinding()
37: .getInInterceptors());
38: }
39:
40: @Override
41: public void initialize(Server server, Bus bus) {
42: removeDatabindingInterceptor(server.getEndpoint().getBinding()
43: .getInInterceptors());
44: }
45:
46: private void removeDatabindingInterceptor(
47: List<Interceptor> inInterceptors) {
48: removeInterceptor(inInterceptors, DocLiteralInInterceptor.class
49: .getName());
50: removeInterceptor(inInterceptors, BareInInterceptor.class
51: .getName());
52: removeInterceptor(inInterceptors, WrappedInInterceptor.class
53: .getName());
54:
55: inInterceptors.add(new StaxDataBindingInterceptor());
56: }
57:
58: private void removeInterceptor(List<Interceptor> inInterceptors,
59: String name) {
60:
61: for (Interceptor i : inInterceptors) {
62: if (i instanceof PhaseInterceptor) {
63: PhaseInterceptor p = (PhaseInterceptor) i;
64:
65: if (p.getId().equals(name)) {
66: inInterceptors.remove(p);
67: return;
68: }
69: }
70: }
71: }
72:
73: }
|