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; 023import javax.xml.namespace.QName; 024 025import org.apache.camel.CamelContext; 026import org.apache.camel.model.DataFormatDefinition; 027import org.apache.camel.spi.DataFormat; 028import org.apache.camel.util.ObjectHelper; 029 030/** 031 * Represents the JAXB2 XML {@link DataFormat} 032 * 033 * @version 034 */ 035@XmlRootElement(name = "jaxb") 036@XmlAccessorType(XmlAccessType.FIELD) 037public class JaxbDataFormat extends DataFormatDefinition { 038 @XmlAttribute(required = true) 039 private String contextPath; 040 @XmlAttribute 041 private String schema; 042 @XmlAttribute 043 private Boolean prettyPrint; 044 @XmlAttribute 045 private Boolean ignoreJAXBElement; 046 @XmlAttribute 047 private Boolean mustBeJAXBElement; 048 @XmlAttribute 049 private Boolean filterNonXmlChars; 050 @XmlAttribute 051 private String encoding; 052 @XmlAttribute 053 private Boolean fragment; 054 // Partial encoding 055 @XmlAttribute 056 private String partClass; 057 @XmlAttribute 058 private String partNamespace; 059 @XmlAttribute 060 private String namespacePrefixRef; 061 @XmlAttribute 062 private String xmlStreamWriterWrapper; 063 @XmlAttribute 064 private String schemaLocation; 065 066 public JaxbDataFormat() { 067 super("jaxb"); 068 } 069 070 public JaxbDataFormat(boolean prettyPrint) { 071 this(); 072 setPrettyPrint(prettyPrint); 073 } 074 075 public String getContextPath() { 076 return contextPath; 077 } 078 079 public void setContextPath(String contextPath) { 080 this.contextPath = contextPath; 081 } 082 083 public String getSchema() { 084 return schema; 085 } 086 087 public void setSchema(String schema) { 088 this.schema = schema; 089 } 090 091 public Boolean getPrettyPrint() { 092 return prettyPrint; 093 } 094 095 public void setPrettyPrint(Boolean prettyPrint) { 096 this.prettyPrint = prettyPrint; 097 } 098 099 public Boolean getIgnoreJAXBElement() { 100 return ignoreJAXBElement; 101 } 102 103 public void setIgnoreJAXBElement(Boolean ignoreJAXBElement) { 104 this.ignoreJAXBElement = ignoreJAXBElement; 105 } 106 107 public Boolean getMustBeJAXBElement() { 108 return mustBeJAXBElement; 109 } 110 111 public void setMustBeJAXBElement(Boolean mustBeJAXBElement) { 112 this.mustBeJAXBElement = mustBeJAXBElement; 113 } 114 115 public void setFragment(Boolean fragment) { 116 this.fragment = fragment; 117 } 118 119 public Boolean getFragment() { 120 return fragment; 121 } 122 123 public Boolean getFilterNonXmlChars() { 124 return filterNonXmlChars; 125 } 126 127 public void setFilterNonXmlChars(Boolean filterNonXmlChars) { 128 this.filterNonXmlChars = filterNonXmlChars; 129 } 130 131 public String getEncoding() { 132 return encoding; 133 } 134 135 public void setEncoding(String encoding) { 136 this.encoding = encoding; 137 } 138 139 public String getPartClass() { 140 return partClass; 141 } 142 143 public void setPartClass(String partClass) { 144 this.partClass = partClass; 145 } 146 147 public String getPartNamespace() { 148 return partNamespace; 149 } 150 151 public void setPartNamespace(String partNamespace) { 152 this.partNamespace = partNamespace; 153 } 154 155 public String getNamespacePrefixRef() { 156 return namespacePrefixRef; 157 } 158 159 public void setNamespacePrefixRef(String namespacePrefixRef) { 160 this.namespacePrefixRef = namespacePrefixRef; 161 } 162 163 public String getXmlStreamWriterWrapper() { 164 return xmlStreamWriterWrapper; 165 } 166 167 public void setXmlStreamWriterWrapper(String xmlStreamWriterWrapperRef) { 168 this.xmlStreamWriterWrapper = xmlStreamWriterWrapperRef; 169 } 170 171 public String getSchemaLocation() { 172 return schemaLocation; 173 } 174 175 public void setSchemaLocation(String schemaLocation) { 176 this.schemaLocation = schemaLocation; 177 } 178 179 @Override 180 protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) { 181 Boolean answer = ObjectHelper.toBoolean(getPrettyPrint()); 182 if (answer != null && !answer) { 183 setProperty(camelContext, dataFormat, "prettyPrint", Boolean.FALSE); 184 } else { // the default value is true 185 setProperty(camelContext, dataFormat, "prettyPrint", Boolean.TRUE); 186 } 187 answer = ObjectHelper.toBoolean(getIgnoreJAXBElement()); 188 if (answer != null && !answer) { 189 setProperty(camelContext, dataFormat, "ignoreJAXBElement", Boolean.FALSE); 190 } else { // the default value is true 191 setProperty(camelContext, dataFormat, "ignoreJAXBElement", Boolean.TRUE); 192 } 193 answer = ObjectHelper.toBoolean(getMustBeJAXBElement()); 194 if (answer != null && answer) { 195 setProperty(camelContext, dataFormat, "mustBeJAXBElement", Boolean.TRUE); 196 } else { // the default value is false 197 setProperty(camelContext, dataFormat, "mustBeJAXBElement", Boolean.FALSE); 198 } 199 answer = ObjectHelper.toBoolean(getFilterNonXmlChars()); 200 if (answer != null && answer) { 201 setProperty(camelContext, dataFormat, "filterNonXmlChars", Boolean.TRUE); 202 } else { // the default value is false 203 setProperty(camelContext, dataFormat, "filterNonXmlChars", Boolean.FALSE); 204 } 205 answer = ObjectHelper.toBoolean(getFragment()); 206 if (answer != null && answer) { 207 setProperty(camelContext, dataFormat, "fragment", Boolean.TRUE); 208 } else { // the default value is false 209 setProperty(camelContext, dataFormat, "fragment", Boolean.FALSE); 210 } 211 if (partClass != null) { 212 setProperty(camelContext, dataFormat, "partClass", partClass); 213 } 214 if (partNamespace != null) { 215 setProperty(camelContext, dataFormat, "partNamespace", QName.valueOf(partNamespace)); 216 } 217 if (encoding != null) { 218 setProperty(camelContext, dataFormat, "encoding", encoding); 219 } 220 if (namespacePrefixRef != null) { 221 setProperty(camelContext, dataFormat, "namespacePrefixRef", namespacePrefixRef); 222 } 223 setProperty(camelContext, dataFormat, "contextPath", contextPath); 224 if (schema != null) { 225 setProperty(camelContext, dataFormat, "schema", schema); 226 } 227 if (xmlStreamWriterWrapper != null) { 228 setProperty(camelContext, dataFormat, "xmlStreamWriterWrapper", xmlStreamWriterWrapper); 229 } 230 if (schemaLocation != null) { 231 setProperty(camelContext, dataFormat, "schemaLocation", schemaLocation); 232 } 233 } 234}