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 getLabel() {
065        return "removeProperties[" + getPattern() + "]";
066    }
067
068    @Override
069    public Processor createProcessor(RouteContext routeContext) throws Exception {
070        ObjectHelper.notNull(getPattern(), "patterns", this);
071        if (getExcludePatterns() != null) {
072            return new RemovePropertiesProcessor(getPattern(), getExcludePatterns());
073        } else if (getExcludePattern() != null) {
074            return new RemovePropertiesProcessor(getPattern(), new String[]{getExcludePattern()});
075        } else {
076            return new RemovePropertiesProcessor(getPattern(), null);
077        }
078    }
079
080    /**
081     * Name or pattern of properties to remove
082     */
083    public void setPattern(String pattern) {
084        this.pattern = pattern;
085    }
086
087    public String getPattern() {
088        return pattern;
089    }
090
091    public String[] getExcludePatterns() {
092        return excludePatterns;
093    }
094
095    /**
096     * Name or pattern of properties to not remove
097     */
098    public void setExcludePatterns(String[] excludePatterns) {
099        this.excludePatterns = excludePatterns;
100    }
101
102    public String getExcludePattern() {
103        return excludePattern;
104    }
105
106    /**
107     * Name or pattern of properties to not remove
108     */
109    public void setExcludePattern(String excludePattern) {
110        this.excludePattern = excludePattern;
111    }
112}