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