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 052 public BeanioDataFormat() { 053 super("beanio"); 054 } 055 056 @Override 057 protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) { 058 setProperty(camelContext, dataFormat, "mapping", mapping); 059 setProperty(camelContext, dataFormat, "streamName", streamName); 060 if (ignoreUnidentifiedRecords != null) { 061 setProperty(camelContext, dataFormat, "ignoreUnidentifiedRecords", ignoreUnidentifiedRecords); 062 } 063 if (ignoreUnexpectedRecords != null) { 064 setProperty(camelContext, dataFormat, "ignoreUnexpectedRecords", ignoreUnexpectedRecords); 065 } 066 if (ignoreInvalidRecords != null) { 067 setProperty(camelContext, dataFormat, "ignoreInvalidRecords", ignoreInvalidRecords); 068 } 069 if (encoding != null) { 070 setProperty(camelContext, dataFormat, "encoding", encoding); 071 } 072 } 073 074 public String getMapping() { 075 return mapping; 076 } 077 078 /** 079 * The BeanIO mapping file. 080 * Is by default loaded from the classpath. You can prefix with file:, http:, or classpath: to denote from where to load the mapping file. 081 */ 082 public void setMapping(String mapping) { 083 this.mapping = mapping; 084 } 085 086 public String getStreamName() { 087 return streamName; 088 } 089 090 /** 091 * The name of the stream to use. 092 */ 093 public void setStreamName(String streamName) { 094 this.streamName = streamName; 095 } 096 097 public Boolean getIgnoreUnidentifiedRecords() { 098 return ignoreUnidentifiedRecords; 099 } 100 101 /** 102 * Whether to ignore unidentified records. 103 */ 104 public void setIgnoreUnidentifiedRecords(Boolean ignoreUnidentifiedRecords) { 105 this.ignoreUnidentifiedRecords = ignoreUnidentifiedRecords; 106 } 107 108 public Boolean getIgnoreUnexpectedRecords() { 109 return ignoreUnexpectedRecords; 110 } 111 112 /** 113 * Whether to ignore unexpected records. 114 */ 115 public void setIgnoreUnexpectedRecords(Boolean ignoreUnexpectedRecords) { 116 this.ignoreUnexpectedRecords = ignoreUnexpectedRecords; 117 } 118 119 public Boolean getIgnoreInvalidRecords() { 120 return ignoreInvalidRecords; 121 } 122 123 /** 124 * Whether to ignore invalid records. 125 */ 126 public void setIgnoreInvalidRecords(Boolean ignoreInvalidRecords) { 127 this.ignoreInvalidRecords = ignoreInvalidRecords; 128 } 129 130 public String getEncoding() { 131 return encoding; 132 } 133 134 /** 135 * The charset to use. 136 * <p/> 137 * Is by default the JVM platform default charset. 138 */ 139 public void setEncoding(String encoding) { 140 this.encoding = encoding; 141 } 142 143}