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 * BeanIO data format 031 * 032 * @version 033 */ 034@Metadata(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 052 private String beanReaderErrorHandlerType; 053 054 public BeanioDataFormat() { 055 super("beanio"); 056 } 057 058 @Override 059 protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) { 060 setProperty(camelContext, dataFormat, "mapping", mapping); 061 setProperty(camelContext, dataFormat, "streamName", streamName); 062 if (ignoreUnidentifiedRecords != null) { 063 setProperty(camelContext, dataFormat, "ignoreUnidentifiedRecords", ignoreUnidentifiedRecords); 064 } 065 if (ignoreUnexpectedRecords != null) { 066 setProperty(camelContext, dataFormat, "ignoreUnexpectedRecords", ignoreUnexpectedRecords); 067 } 068 if (ignoreInvalidRecords != null) { 069 setProperty(camelContext, dataFormat, "ignoreInvalidRecords", ignoreInvalidRecords); 070 } 071 if (encoding != null) { 072 setProperty(camelContext, dataFormat, "encoding", encoding); 073 } 074 if (beanReaderErrorHandlerType != null) { 075 setProperty(camelContext, dataFormat, "beanReaderErrorHandlerType", beanReaderErrorHandlerType); 076 } 077 } 078 079 public String getMapping() { 080 return mapping; 081 } 082 083 /** 084 * The BeanIO mapping file. 085 * Is by default loaded from the classpath. You can prefix with file:, http:, or classpath: to denote from where to load the mapping file. 086 */ 087 public void setMapping(String mapping) { 088 this.mapping = mapping; 089 } 090 091 public String getStreamName() { 092 return streamName; 093 } 094 095 /** 096 * The name of the stream to use. 097 */ 098 public void setStreamName(String streamName) { 099 this.streamName = streamName; 100 } 101 102 public Boolean getIgnoreUnidentifiedRecords() { 103 return ignoreUnidentifiedRecords; 104 } 105 106 /** 107 * Whether to ignore unidentified records. 108 */ 109 public void setIgnoreUnidentifiedRecords(Boolean ignoreUnidentifiedRecords) { 110 this.ignoreUnidentifiedRecords = ignoreUnidentifiedRecords; 111 } 112 113 public Boolean getIgnoreUnexpectedRecords() { 114 return ignoreUnexpectedRecords; 115 } 116 117 /** 118 * Whether to ignore unexpected records. 119 */ 120 public void setIgnoreUnexpectedRecords(Boolean ignoreUnexpectedRecords) { 121 this.ignoreUnexpectedRecords = ignoreUnexpectedRecords; 122 } 123 124 public Boolean getIgnoreInvalidRecords() { 125 return ignoreInvalidRecords; 126 } 127 128 /** 129 * Whether to ignore invalid records. 130 */ 131 public void setIgnoreInvalidRecords(Boolean ignoreInvalidRecords) { 132 this.ignoreInvalidRecords = ignoreInvalidRecords; 133 } 134 135 public String getEncoding() { 136 return encoding; 137 } 138 139 /** 140 * The charset to use. 141 * <p/> 142 * Is by default the JVM platform default charset. 143 */ 144 public void setEncoding(String encoding) { 145 this.encoding = encoding; 146 } 147 148 public String getBeanReaderErrorHandlerType() { 149 return beanReaderErrorHandlerType; 150 } 151 152 /** 153 * To use a custom org.apache.camel.dataformat.beanio.BeanIOErrorHandler as error handler 154 * while parsing. Configure the fully qualified class name of the error handler. 155 * Notice the options ignoreUnidentifiedRecords, ignoreUnexpectedRecords, and ignoreInvalidRecords 156 * may not be in use when you use a custom error handler. 157 */ 158 public void setBeanReaderErrorHandlerType(String beanReaderErrorHandlerType) { 159 this.beanReaderErrorHandlerType = beanReaderErrorHandlerType; 160 } 161}