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 */
017package org.apache.camel.model;
018
019import javax.xml.bind.annotation.XmlAccessType;
020import javax.xml.bind.annotation.XmlAccessorType;
021import javax.xml.bind.annotation.XmlAttribute;
022import javax.xml.bind.annotation.XmlRootElement;
023import javax.xml.bind.annotation.XmlTransient;
024
025import org.apache.camel.Processor;
026import org.apache.camel.processor.RemovePropertiesProcessor;
027import org.apache.camel.spi.Metadata;
028import org.apache.camel.spi.RouteContext;
029import org.apache.camel.util.ObjectHelper;
030
031/**
032 * Removes message exchange properties whose name matches a specified pattern
033 */
034@Metadata(label = "eip,transformation")
035@XmlRootElement(name = "removeProperties")
036@XmlAccessorType(XmlAccessType.FIELD)
037public class RemovePropertiesDefinition extends NoOutputDefinition<RemovePropertiesDefinition> {
038    @XmlAttribute(required = true)
039    private String pattern;
040    @XmlAttribute
041    private String excludePattern;
042    // in XML we cannot use String[] for attributes, so we provide a single attribute instead
043    @XmlTransient
044    private String[] excludePatterns;
045
046    public RemovePropertiesDefinition() {
047    }
048
049    public RemovePropertiesDefinition(String pattern) {
050        setPattern(pattern);
051    }
052    
053    public RemovePropertiesDefinition(String pattern, String... excludePatterns) {
054        setPattern(pattern);
055        setExcludePatterns(excludePatterns);
056    }
057
058    @Override
059    public String toString() {
060        return "removeProperties[" + getPattern() + "]";
061    }
062
063    @Override
064    public String getShortName() {
065        return "removeProperties";
066    }
067
068    @Override
069    public String getLabel() {
070        return "removeProperties[" + getPattern() + "]";
071    }
072
073    @Override
074    public Processor createProcessor(RouteContext routeContext) throws Exception {
075        ObjectHelper.notNull(getPattern(), "patterns", this);
076        if (getExcludePatterns() != null) {
077            return new RemovePropertiesProcessor(getPattern(), getExcludePatterns());
078        } else if (getExcludePattern() != null) {
079            return new RemovePropertiesProcessor(getPattern(), new String[]{getExcludePattern()});
080        } else {
081            return new RemovePropertiesProcessor(getPattern(), null);
082        }
083    }
084
085    /**
086     * Name or pattern of properties to remove
087     */
088    public void setPattern(String pattern) {
089        this.pattern = pattern;
090    }
091
092    public String getPattern() {
093        return pattern;
094    }
095
096    public String[] getExcludePatterns() {
097        return excludePatterns;
098    }
099
100    /**
101     * Name or pattern of properties to not remove
102     */
103    public void setExcludePatterns(String[] excludePatterns) {
104        this.excludePatterns = excludePatterns;
105    }
106
107    public String getExcludePattern() {
108        return excludePattern;
109    }
110
111    /**
112     * Name or pattern of properties to not remove
113     */
114    public void setExcludePattern(String excludePattern) {
115        this.excludePattern = excludePattern;
116    }
117}