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