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.dataformat;
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;
023
024import org.apache.camel.CamelContext;
025import org.apache.camel.model.DataFormatDefinition;
026import org.apache.camel.spi.DataFormat;
027import org.apache.camel.spi.Metadata;
028
029/**
030 * The BeanIO data format is used for working with flat payloads (such as CSV, delimited, or fixed length formats).
031 *
032 * @version 
033 */
034@Metadata(firstVersion = "2.10.0", label = "dataformat,transformation,csv", title = "BeanIO")
035@XmlRootElement(name = "beanio")
036@XmlAccessorType(XmlAccessType.FIELD)
037public class BeanioDataFormat extends DataFormatDefinition {
038
039    @XmlAttribute(required = true)
040    private String mapping;
041    @XmlAttribute(required = true)
042    private String streamName;
043    @XmlAttribute
044    private Boolean ignoreUnidentifiedRecords;
045    @XmlAttribute
046    private Boolean ignoreUnexpectedRecords;
047    @XmlAttribute
048    private Boolean ignoreInvalidRecords;
049    @XmlAttribute
050    private String encoding;
051    @XmlAttribute @Metadata(label = "advanced")
052    private String beanReaderErrorHandlerType;
053    @XmlAttribute @Metadata(label = "advanced")
054    private Boolean unmarshalSingleObject;
055
056    public BeanioDataFormat() {
057        super("beanio");
058    }
059
060    @Override
061    protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
062        setProperty(camelContext, dataFormat, "mapping", mapping);
063        setProperty(camelContext, dataFormat, "streamName", streamName);
064        if (ignoreUnidentifiedRecords != null) {
065            setProperty(camelContext, dataFormat, "ignoreUnidentifiedRecords", ignoreUnidentifiedRecords);
066        }
067        if (ignoreUnexpectedRecords != null) {
068            setProperty(camelContext, dataFormat, "ignoreUnexpectedRecords", ignoreUnexpectedRecords);
069        }
070        if (ignoreInvalidRecords != null) {
071            setProperty(camelContext, dataFormat, "ignoreInvalidRecords", ignoreInvalidRecords);
072        }
073        if (encoding != null) {
074            setProperty(camelContext, dataFormat, "encoding", encoding);
075        }
076        if (beanReaderErrorHandlerType != null) {
077            setProperty(camelContext, dataFormat, "beanReaderErrorHandlerType", beanReaderErrorHandlerType);
078        }
079        if (unmarshalSingleObject != null) {
080            setProperty(camelContext, dataFormat, "unmarshalSingleObject", unmarshalSingleObject);
081        }
082    }
083
084    public String getMapping() {
085        return mapping;
086    }
087
088    /**
089     * The BeanIO mapping file.
090     * Is by default loaded from the classpath. You can prefix with file:, http:, or classpath: to denote from where to load the mapping file.
091     */
092    public void setMapping(String mapping) {
093        this.mapping = mapping;
094    }
095
096    public String getStreamName() {
097        return streamName;
098    }
099
100    /**
101     * The name of the stream to use.
102     */
103    public void setStreamName(String streamName) {
104        this.streamName = streamName;
105    }
106
107    public Boolean getIgnoreUnidentifiedRecords() {
108        return ignoreUnidentifiedRecords;
109    }
110
111    /**
112     * Whether to ignore unidentified records.
113     */
114    public void setIgnoreUnidentifiedRecords(Boolean ignoreUnidentifiedRecords) {
115        this.ignoreUnidentifiedRecords = ignoreUnidentifiedRecords;
116    }
117
118    public Boolean getIgnoreUnexpectedRecords() {
119        return ignoreUnexpectedRecords;
120    }
121
122    /**
123     * Whether to ignore unexpected records.
124     */
125    public void setIgnoreUnexpectedRecords(Boolean ignoreUnexpectedRecords) {
126        this.ignoreUnexpectedRecords = ignoreUnexpectedRecords;
127    }
128
129    public Boolean getIgnoreInvalidRecords() {
130        return ignoreInvalidRecords;
131    }
132
133    /**
134     * Whether to ignore invalid records.
135     */
136    public void setIgnoreInvalidRecords(Boolean ignoreInvalidRecords) {
137        this.ignoreInvalidRecords = ignoreInvalidRecords;
138    }
139
140    public String getEncoding() {
141        return encoding;
142    }
143
144    /**
145     * The charset to use.
146     * <p/>
147     * Is by default the JVM platform default charset.
148     */
149    public void setEncoding(String encoding) {
150        this.encoding = encoding;
151    }
152
153    public String getBeanReaderErrorHandlerType() {
154        return beanReaderErrorHandlerType;
155    }
156
157    /**
158     * To use a custom org.apache.camel.dataformat.beanio.BeanIOErrorHandler as error handler
159     * while parsing. Configure the fully qualified class name of the error handler.
160     * Notice the options ignoreUnidentifiedRecords, ignoreUnexpectedRecords, and ignoreInvalidRecords
161     * may not be in use when you use a custom error handler.
162     */
163    public void setBeanReaderErrorHandlerType(String beanReaderErrorHandlerType) {
164        this.beanReaderErrorHandlerType = beanReaderErrorHandlerType;
165    }
166
167    public Boolean getUnmarshalSingleObject() {
168        return unmarshalSingleObject;
169    }
170
171    /**
172     * This options controls whether to unmarshal as a list of objects or as a single object only. The former is the default mode, and the latter
173     * is only intended in special use-cases where beanio maps the Camel message to a single POJO bean.
174     */
175    public void setUnmarshalSingleObject(Boolean unmarshalSingleObject) {
176        this.unmarshalSingleObject = unmarshalSingleObject;
177    }
178}