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 */ 017 package org.apache.camel.model.dataformat; 018 019 import javax.xml.bind.annotation.XmlAccessType; 020 import javax.xml.bind.annotation.XmlAccessorType; 021 import javax.xml.bind.annotation.XmlAttribute; 022 import javax.xml.bind.annotation.XmlRootElement; 023 024 import org.apache.camel.model.DataFormatDefinition; 025 import org.apache.camel.spi.DataFormat; 026 027 /** 028 * Represents a <a href="http://camel.apache.org/castor.html">Castor</a> {@link org.apache.camel.spi.DataFormat}. 029 * 030 * @version 031 */ 032 @XmlRootElement(name = "castor") 033 @XmlAccessorType(XmlAccessType.FIELD) 034 public class CastorDataFormat extends DataFormatDefinition { 035 @XmlAttribute 036 private String mappingFile; 037 @XmlAttribute 038 private Boolean validation; 039 @XmlAttribute 040 private String encoding; 041 @XmlAttribute 042 private String[] packages; 043 @XmlAttribute 044 private String[] classes; 045 046 public CastorDataFormat() { 047 super("castor"); 048 } 049 050 public boolean isValidation() { 051 // defaults to true if not configured 052 return validation != null ? validation : true; 053 } 054 055 public Boolean getValidation() { 056 return validation; 057 } 058 059 public void setValidation(Boolean validation) { 060 this.validation = validation; 061 } 062 063 public String getMappingFile() { 064 return mappingFile; 065 } 066 067 public void setMappingFile(String mappingFile) { 068 this.mappingFile = mappingFile; 069 } 070 071 public String[] getPackages() { 072 return packages; 073 } 074 075 public void setPackages(String[] packages) { 076 this.packages = packages; 077 } 078 079 public String[] getClasses() { 080 return classes; 081 } 082 083 public void setClasses(String[] classes) { 084 this.classes = classes; 085 } 086 087 public String getEncoding() { 088 return encoding; 089 } 090 091 public void setEncoding(String encoding) { 092 this.encoding = encoding; 093 } 094 095 @Override 096 protected void configureDataFormat(DataFormat dataFormat) { 097 if (mappingFile != null) { 098 setProperty(dataFormat, "mappingFile", mappingFile); 099 } 100 setProperty(dataFormat, "validation", isValidation()); 101 102 if (encoding != null) { 103 setProperty(dataFormat, "encoding", encoding); 104 } 105 if (packages != null) { 106 setProperty(dataFormat, "packages", packages); 107 } 108 if (classes != null) { 109 setProperty(dataFormat, "classes", classes); 110 } 111 } 112 113 }