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.model.DataFormatDefinition; 025import org.apache.camel.spi.Metadata; 026 027/** 028 * JAXB data format uses the JAXB2 XML marshalling standard to unmarshal an XML 029 * payload into Java objects or to marshal Java objects into an XML payload. 030 */ 031@Metadata(firstVersion = "1.0.0", label = "dataformat,transformation,xml", title = "JAXB") 032@XmlRootElement(name = "jaxb") 033@XmlAccessorType(XmlAccessType.FIELD) 034public class JaxbDataFormat extends DataFormatDefinition { 035 @XmlAttribute(required = true) 036 private String contextPath; 037 @XmlAttribute 038 private String schema; 039 @XmlAttribute 040 @Metadata(enums = "0,1,2", defaultValue = "0") 041 private Integer schemaSeverityLevel; 042 @XmlAttribute 043 private Boolean prettyPrint; 044 @XmlAttribute 045 private Boolean objectFactory; 046 @XmlAttribute 047 private Boolean ignoreJAXBElement; 048 @XmlAttribute 049 private Boolean mustBeJAXBElement; 050 @XmlAttribute 051 private Boolean filterNonXmlChars; 052 @XmlAttribute 053 private String encoding; 054 @XmlAttribute 055 private Boolean fragment; 056 // Partial encoding 057 @XmlAttribute 058 private String partClass; 059 @XmlAttribute 060 private String partNamespace; 061 @XmlAttribute 062 private String namespacePrefixRef; 063 @XmlAttribute 064 @Metadata(label = "advanced") 065 private String xmlStreamWriterWrapper; 066 @XmlAttribute 067 private String schemaLocation; 068 @XmlAttribute 069 private String noNamespaceSchemaLocation; 070 @XmlAttribute 071 @Metadata(label = "advanced") 072 private String jaxbProviderProperties; 073 074 public JaxbDataFormat() { 075 super("jaxb"); 076 } 077 078 public JaxbDataFormat(boolean prettyPrint) { 079 this(); 080 setPrettyPrint(prettyPrint); 081 } 082 083 public String getContextPath() { 084 return contextPath; 085 } 086 087 /** 088 * Package name where your JAXB classes are located. 089 */ 090 public void setContextPath(String contextPath) { 091 this.contextPath = contextPath; 092 } 093 094 public String getSchema() { 095 return schema; 096 } 097 098 /** 099 * To validate against an existing schema. Your can use the prefix 100 * classpath:, file:* or *http: to specify how the resource should by 101 * resolved. You can separate multiple schema files by using the ',' 102 * character. 103 */ 104 public void setSchema(String schema) { 105 this.schema = schema; 106 } 107 108 public Integer getSchemaSeverityLevel() { 109 return schemaSeverityLevel; 110 } 111 112 /** 113 * Sets the schema severity level to use when validating against a schema. 114 * This level determines the minimum severity error that triggers JAXB to 115 * stop continue parsing. The default value of 0 (warning) means that any 116 * error (warning, error or fatal error) will trigger JAXB to stop. There 117 * are the following three levels: 0=warning, 1=error, 2=fatal error. 118 */ 119 public void setSchemaSeverityLevel(Integer schemaSeverityLevel) { 120 this.schemaSeverityLevel = schemaSeverityLevel; 121 } 122 123 public Boolean getPrettyPrint() { 124 return prettyPrint; 125 } 126 127 /** 128 * To enable pretty printing output nicely formatted. 129 * <p/> 130 * Is by default false. 131 */ 132 public void setPrettyPrint(Boolean prettyPrint) { 133 this.prettyPrint = prettyPrint; 134 } 135 136 public Boolean getObjectFactory() { 137 return objectFactory; 138 } 139 140 /** 141 * Whether to allow using ObjectFactory classes to create the POJO classes 142 * during marshalling. This only applies to POJO classes that has not been 143 * annotated with JAXB and providing jaxb.index descriptor files. 144 */ 145 public void setObjectFactory(Boolean objectFactory) { 146 this.objectFactory = objectFactory; 147 } 148 149 public Boolean getIgnoreJAXBElement() { 150 return ignoreJAXBElement; 151 } 152 153 /** 154 * Whether to ignore JAXBElement elements - only needed to be set to false 155 * in very special use-cases. 156 */ 157 public void setIgnoreJAXBElement(Boolean ignoreJAXBElement) { 158 this.ignoreJAXBElement = ignoreJAXBElement; 159 } 160 161 public Boolean getMustBeJAXBElement() { 162 return mustBeJAXBElement; 163 } 164 165 /** 166 * Whether marhsalling must be java objects with JAXB annotations. And if 167 * not then it fails. This option can be set to false to relax that, such as 168 * when the data is already in XML format. 169 */ 170 public void setMustBeJAXBElement(Boolean mustBeJAXBElement) { 171 this.mustBeJAXBElement = mustBeJAXBElement; 172 } 173 174 /** 175 * To turn on marshalling XML fragment trees. By default JAXB looks 176 * for @XmlRootElement annotation on given class to operate on whole XML 177 * tree. This is useful but not always - sometimes generated code does not 178 * have @XmlRootElement annotation, sometimes you need unmarshall only part 179 * of tree. In that case you can use partial unmarshalling. To enable this 180 * behaviours you need set property partClass. Camel will pass this class to 181 * JAXB's unmarshaler. 182 */ 183 public void setFragment(Boolean fragment) { 184 this.fragment = fragment; 185 } 186 187 public Boolean getFragment() { 188 return fragment; 189 } 190 191 public Boolean getFilterNonXmlChars() { 192 return filterNonXmlChars; 193 } 194 195 /** 196 * To ignore non xml characheters and replace them with an empty space. 197 */ 198 public void setFilterNonXmlChars(Boolean filterNonXmlChars) { 199 this.filterNonXmlChars = filterNonXmlChars; 200 } 201 202 public String getEncoding() { 203 return encoding; 204 } 205 206 /** 207 * To overrule and use a specific encoding 208 */ 209 public void setEncoding(String encoding) { 210 this.encoding = encoding; 211 } 212 213 public String getPartClass() { 214 return partClass; 215 } 216 217 /** 218 * Name of class used for fragment parsing. 219 * <p/> 220 * See more details at the fragment option. 221 */ 222 public void setPartClass(String partClass) { 223 this.partClass = partClass; 224 } 225 226 public String getPartNamespace() { 227 return partNamespace; 228 } 229 230 /** 231 * XML namespace to use for fragment parsing. 232 * <p/> 233 * See more details at the fragment option. 234 */ 235 public void setPartNamespace(String partNamespace) { 236 this.partNamespace = partNamespace; 237 } 238 239 public String getNamespacePrefixRef() { 240 return namespacePrefixRef; 241 } 242 243 /** 244 * When marshalling using JAXB or SOAP then the JAXB implementation will 245 * automatic assign namespace prefixes, such as ns2, ns3, ns4 etc. To 246 * control this mapping, Camel allows you to refer to a map which contains 247 * the desired mapping. 248 */ 249 public void setNamespacePrefixRef(String namespacePrefixRef) { 250 this.namespacePrefixRef = namespacePrefixRef; 251 } 252 253 public String getXmlStreamWriterWrapper() { 254 return xmlStreamWriterWrapper; 255 } 256 257 /** 258 * To use a custom xml stream writer. 259 */ 260 public void setXmlStreamWriterWrapper(String xmlStreamWriterWrapperRef) { 261 this.xmlStreamWriterWrapper = xmlStreamWriterWrapperRef; 262 } 263 264 public String getSchemaLocation() { 265 return schemaLocation; 266 } 267 268 /** 269 * To define the location of the schema 270 */ 271 public void setSchemaLocation(String schemaLocation) { 272 this.schemaLocation = schemaLocation; 273 } 274 275 public String getNoNamespaceSchemaLocation() { 276 return noNamespaceSchemaLocation; 277 } 278 279 /** 280 * To define the location of the namespaceless schema 281 */ 282 public void setNoNamespaceSchemaLocation(String schemaLocation) { 283 this.noNamespaceSchemaLocation = schemaLocation; 284 } 285 286 public String getJaxbProviderProperties() { 287 return jaxbProviderProperties; 288 } 289 290 /** 291 * Refers to a custom java.util.Map to lookup in the registry containing 292 * custom JAXB provider properties to be used with the JAXB marshaller. 293 */ 294 public void setJaxbProviderProperties(String jaxbProviderProperties) { 295 this.jaxbProviderProperties = jaxbProviderProperties; 296 } 297 298}