001 /**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017
018 package org.apache.camel.component.cxf.feature;
019
020 import java.util.Collection;
021 import java.util.List;
022 import java.util.logging.Logger;
023
024 import org.apache.cxf.feature.AbstractFeature;
025 import org.apache.cxf.interceptor.Interceptor;
026 import org.apache.cxf.phase.PhaseInterceptor;
027
028 /**
029 * The abstract class for the data format feature
030 */
031 public abstract class AbstractDataFormatFeature extends AbstractFeature {
032
033 protected abstract Logger getLogger();
034
035 protected void removeInterceptorWhichIsInThePhases(List<Interceptor> interceptors, String[] phaseNames) {
036 for (Interceptor i : interceptors) {
037 if (i instanceof PhaseInterceptor) {
038 PhaseInterceptor p = (PhaseInterceptor)i;
039 for (String phaseName : phaseNames) {
040 if (p.getPhase().equals(phaseName)) {
041 getLogger().info("removing the interceptor " + p);
042 interceptors.remove(p);
043 break;
044 }
045 }
046 }
047 }
048 }
049
050 protected void removeInterceptorWhichIsOutThePhases(List<Interceptor> interceptors, String[] phaseNames) {
051 for (Interceptor i : interceptors) {
052 boolean outside = false;
053 if (i instanceof PhaseInterceptor) {
054 PhaseInterceptor p = (PhaseInterceptor)i;
055 for (String phaseName : phaseNames) {
056 if (p.getPhase().equals(phaseName)) {
057 outside = true;
058 break;
059 }
060 }
061 if (!outside) {
062 getLogger().info("removing the interceptor " + p);
063 interceptors.remove(p);
064 }
065 }
066 }
067 }
068
069
070 protected void removeInterceptors(List<Interceptor> interceptors,
071 Collection<Class> toBeRemovedInterceptors) {
072 for (Interceptor interceptor : interceptors) {
073 if (toBeRemovedInterceptors.contains(interceptor.getClass())) {
074 getLogger().info("removing the interceptor " + interceptor);
075 interceptors.remove(interceptor);
076 }
077 }
078 }
079
080 }