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.builder;
018
019import java.nio.charset.Charset;
020import java.util.Map;
021import java.util.zip.Deflater;
022
023import org.w3c.dom.Node;
024
025import org.apache.camel.model.DataFormatDefinition;
026import org.apache.camel.model.ProcessorDefinition;
027import org.apache.camel.model.dataformat.ASN1DataFormat;
028import org.apache.camel.model.dataformat.AvroDataFormat;
029import org.apache.camel.model.dataformat.Base64DataFormat;
030import org.apache.camel.model.dataformat.BeanioDataFormat;
031import org.apache.camel.model.dataformat.BindyDataFormat;
032import org.apache.camel.model.dataformat.BindyType;
033import org.apache.camel.model.dataformat.BoonDataFormat;
034import org.apache.camel.model.dataformat.CastorDataFormat;
035import org.apache.camel.model.dataformat.CsvDataFormat;
036import org.apache.camel.model.dataformat.CustomDataFormat;
037import org.apache.camel.model.dataformat.FhirJsonDataFormat;
038import org.apache.camel.model.dataformat.FhirXmlDataFormat;
039import org.apache.camel.model.dataformat.GzipDataFormat;
040import org.apache.camel.model.dataformat.HL7DataFormat;
041import org.apache.camel.model.dataformat.HessianDataFormat;
042import org.apache.camel.model.dataformat.IcalDataFormat;
043import org.apache.camel.model.dataformat.JacksonXMLDataFormat;
044import org.apache.camel.model.dataformat.JaxbDataFormat;
045import org.apache.camel.model.dataformat.JibxDataFormat;
046import org.apache.camel.model.dataformat.JsonDataFormat;
047import org.apache.camel.model.dataformat.JsonLibrary;
048import org.apache.camel.model.dataformat.LZFDataFormat;
049import org.apache.camel.model.dataformat.MimeMultipartDataFormat;
050import org.apache.camel.model.dataformat.PGPDataFormat;
051import org.apache.camel.model.dataformat.ProtobufDataFormat;
052import org.apache.camel.model.dataformat.RssDataFormat;
053import org.apache.camel.model.dataformat.SerializationDataFormat;
054import org.apache.camel.model.dataformat.SoapJaxbDataFormat;
055import org.apache.camel.model.dataformat.StringDataFormat;
056import org.apache.camel.model.dataformat.SyslogDataFormat;
057import org.apache.camel.model.dataformat.TarFileDataFormat;
058import org.apache.camel.model.dataformat.ThriftDataFormat;
059import org.apache.camel.model.dataformat.TidyMarkupDataFormat;
060import org.apache.camel.model.dataformat.XMLBeansDataFormat;
061import org.apache.camel.model.dataformat.XMLSecurityDataFormat;
062import org.apache.camel.model.dataformat.XStreamDataFormat;
063import org.apache.camel.model.dataformat.XmlJsonDataFormat;
064import org.apache.camel.model.dataformat.YAMLDataFormat;
065import org.apache.camel.model.dataformat.YAMLLibrary;
066import org.apache.camel.model.dataformat.ZipDataFormat;
067import org.apache.camel.model.dataformat.ZipFileDataFormat;
068import org.apache.camel.util.CollectionStringBuffer;
069import org.apache.camel.util.jsse.KeyStoreParameters;
070
071/**
072 * An expression for constructing the different possible {@link org.apache.camel.spi.DataFormat}
073 * options.
074 *
075 * @version 
076 */
077public class DataFormatClause<T extends ProcessorDefinition<?>> {
078    private final T processorType;
079    private final Operation operation;
080
081    /**
082     * {@link org.apache.camel.spi.DataFormat} operations.
083     */
084    public enum Operation {
085        Marshal, Unmarshal
086    }
087
088    public DataFormatClause(T processorType, Operation operation) {
089        this.processorType = processorType;
090        this.operation = operation;
091    }
092
093    /**
094     * Uses the Avro data format
095     */
096    public T avro() {
097        return dataFormat(new AvroDataFormat());
098    }
099
100    public T avro(Object schema) {
101        AvroDataFormat dataFormat = new AvroDataFormat();
102        dataFormat.setSchema(schema);
103        return dataFormat(dataFormat);
104    }
105
106    public T avro(String instanceClassName) {
107        return dataFormat(new AvroDataFormat(instanceClassName));
108    }
109
110    /**
111     * Uses the base64 data format
112     */
113    public T base64() {
114        Base64DataFormat dataFormat = new Base64DataFormat();
115        return dataFormat(dataFormat);
116    }
117
118    /**
119     * Uses the base64 data format
120     */
121    public T base64(int lineLength, String lineSeparator, boolean urlSafe) {
122        Base64DataFormat dataFormat = new Base64DataFormat();
123        dataFormat.setLineLength(lineLength);
124        dataFormat.setLineSeparator(lineSeparator);
125        dataFormat.setUrlSafe(urlSafe);
126        return dataFormat(dataFormat);
127    }
128
129    /**
130     * Uses the beanio data format
131     */
132    public T beanio(String mapping, String streamName) {
133        BeanioDataFormat dataFormat = new BeanioDataFormat();
134        dataFormat.setMapping(mapping);
135        dataFormat.setStreamName(streamName);
136        return dataFormat(dataFormat);
137    }
138
139    /**
140     * Uses the beanio data format
141     */
142    public T beanio(String mapping, String streamName, String encoding) {
143        BeanioDataFormat dataFormat = new BeanioDataFormat();
144        dataFormat.setMapping(mapping);
145        dataFormat.setStreamName(streamName);
146        dataFormat.setEncoding(encoding);
147        return dataFormat(dataFormat);
148    }
149
150    /**
151     * Uses the beanio data format
152     */
153    public T beanio(String mapping, String streamName, String encoding,
154                    boolean ignoreUnidentifiedRecords, boolean ignoreUnexpectedRecords, boolean ignoreInvalidRecords) {
155        BeanioDataFormat dataFormat = new BeanioDataFormat();
156        dataFormat.setMapping(mapping);
157        dataFormat.setStreamName(streamName);
158        dataFormat.setEncoding(encoding);
159        dataFormat.setIgnoreUnidentifiedRecords(ignoreUnidentifiedRecords);
160        dataFormat.setIgnoreUnexpectedRecords(ignoreUnexpectedRecords);
161        dataFormat.setIgnoreInvalidRecords(ignoreInvalidRecords);
162        return dataFormat(dataFormat);
163    }
164    
165    /**
166     * Uses the beanio data format
167     */
168    public T beanio(String mapping, String streamName, String encoding, String beanReaderErrorHandlerType) {
169        BeanioDataFormat dataFormat = new BeanioDataFormat();
170        dataFormat.setMapping(mapping);
171        dataFormat.setStreamName(streamName);
172        dataFormat.setEncoding(encoding);
173        dataFormat.setBeanReaderErrorHandlerType(beanReaderErrorHandlerType);
174        return dataFormat(dataFormat);
175    }
176
177    /**
178     * Uses the Bindy data format
179     *
180     * @param type      the type of bindy data format to use
181     * @param classType the POJO class type
182     */
183    public T bindy(BindyType type, Class<?> classType) {
184        BindyDataFormat bindy = new BindyDataFormat();
185        bindy.setType(type);
186        bindy.setClassType(classType);
187        return dataFormat(bindy);
188    }
189
190    /**
191     * Uses the Bindy data format
192     *
193     * @param type      the type of bindy data format to use
194     * @param classType the POJO class type
195     * @param unwrapSingleInstance whether unmarshal should unwrap if there is a single instance in the result
196     */
197    public T bindy(BindyType type, Class<?> classType, boolean unwrapSingleInstance) {
198        BindyDataFormat bindy = new BindyDataFormat();
199        bindy.setType(type);
200        bindy.setClassType(classType);
201        bindy.setUnwrapSingleInstance(unwrapSingleInstance);
202        return dataFormat(bindy);
203    }
204
205    /**
206     * Uses the Boon data format
207     *
208     * @param classType the POJO class type
209     * @deprecated Not functional in Java 9+ and will be removed in Apache Camel 3.0.0
210     */
211    @Deprecated
212    public T boon(Class<?> classType) {
213        BoonDataFormat boon = new BoonDataFormat();
214        boon.setUnmarshalType(classType);
215        return dataFormat(boon);
216    }
217
218    /**
219     * Uses the CSV data format
220     */
221    public T csv() {
222        return dataFormat(new CsvDataFormat());
223    }
224
225    /**
226     * Uses the CSV data format for a huge file.
227     * Sequential access through an iterator.
228     */
229    public T csvLazyLoad() {
230        return dataFormat(new CsvDataFormat(true));
231    }
232
233    /**
234     * Uses the custom data format
235     */
236    public T custom(String ref) {
237        return dataFormat(new CustomDataFormat(ref));
238    }
239
240    /**
241     * Uses the Castor data format
242     */
243    public T castor() {
244        return dataFormat(new CastorDataFormat());
245    }
246
247    /**
248     * Uses the Castor data format
249     *
250     * @param mappingFile name of mapping file to locate in classpath
251     */
252    public T castor(String mappingFile) {
253        CastorDataFormat castor = new CastorDataFormat();
254        castor.setMappingFile(mappingFile);
255        return dataFormat(castor);
256    }
257
258    /**
259     * Uses the Castor data format
260     *
261     * @param mappingFile name of mapping file to locate in classpath
262     * @param validation  whether validation is enabled or not
263     */
264    public T castor(String mappingFile, boolean validation) {
265        CastorDataFormat castor = new CastorDataFormat();
266        castor.setMappingFile(mappingFile);
267        castor.setValidation(validation);
268        return dataFormat(castor);
269    }
270
271    /**
272     * Uses the GZIP deflater data format
273     */
274    public T gzip() {
275        GzipDataFormat gzdf = new GzipDataFormat();
276        return dataFormat(gzdf);
277    }
278
279    /**
280     * Uses the Hessian data format
281     */
282    public T hessian() {
283        return dataFormat(new HessianDataFormat());
284    }
285
286    /**
287     * Uses the HL7 data format
288     */
289    public T hl7() {
290        return dataFormat(new HL7DataFormat());
291    }
292
293    /**
294     * Uses the HL7 data format
295     */
296    public T hl7(boolean validate) {
297        HL7DataFormat hl7 = new HL7DataFormat();
298        hl7.setValidate(validate);
299        return dataFormat(hl7);
300    }
301    
302    /**
303     * Uses the HL7 data format
304     */
305    public T hl7(Object parser) {
306        HL7DataFormat hl7 = new HL7DataFormat();
307        hl7.setParser(parser);
308        return dataFormat(hl7);
309    }
310
311    /**
312     * Uses the iCal data format
313     */
314    public T ical(boolean validating) {
315        IcalDataFormat ical = new IcalDataFormat();
316        ical.setValidating(validating);
317        return dataFormat(ical);
318    }
319
320    /**
321     * Uses the LZF deflater data format
322     */
323    public T lzf() {
324        LZFDataFormat lzfdf = new LZFDataFormat();
325        return dataFormat(lzfdf);
326    }
327
328    /**
329     * Uses the MIME Multipart data format
330     */
331    public T mimeMultipart() {
332        MimeMultipartDataFormat mm = new MimeMultipartDataFormat();
333        return dataFormat(mm);
334    }
335
336    /**
337     * Uses the MIME Multipart data format
338     *
339     * @param multipartSubType Specifies the subtype of the MIME Multipart
340     */
341    public T mimeMultipart(String multipartSubType) {
342        MimeMultipartDataFormat mm = new MimeMultipartDataFormat();
343        mm.setMultipartSubType(multipartSubType);
344        return dataFormat(mm);
345    }
346
347    /**
348     * Uses the MIME Multipart data format
349     *
350     * @param multipartSubType           the subtype of the MIME Multipart
351     * @param multipartWithoutAttachment defines whether a message without attachment is also marshaled
352     *                                   into a MIME Multipart (with only one body part).
353     * @param headersInline              define the MIME Multipart headers as part of the message body
354     *                                   or as Camel headers
355     * @param binaryContent              have binary encoding for binary content (true) or use Base-64
356     *                                   encoding for binary content (false)
357     */
358    public T mimeMultipart(String multipartSubType, boolean multipartWithoutAttachment, boolean headersInline,
359                           boolean binaryContent) {
360        MimeMultipartDataFormat mm = new MimeMultipartDataFormat();
361        mm.setMultipartSubType(multipartSubType);
362        mm.setMultipartWithoutAttachment(multipartWithoutAttachment);
363        mm.setHeadersInline(headersInline);
364        mm.setBinaryContent(binaryContent);
365        return dataFormat(mm);
366    }
367
368    /**
369     * Uses the MIME Multipart data format
370     *
371     * @param multipartSubType           the subtype of the MIME Multipart
372     * @param multipartWithoutAttachment defines whether a message without attachment is also marshaled
373     *                                   into a MIME Multipart (with only one body part).
374     * @param headersInline              define the MIME Multipart headers as part of the message body
375     *                                   or as Camel headers
376     * @param includeHeaders            if headersInline is set to true all camel headers matching this
377     *                                   regex are also stored as MIME headers on the Multipart
378     * @param binaryContent              have binary encoding for binary content (true) or use Base-64
379     *                                   encoding for binary content (false)
380     */
381    public T mimeMultipart(String multipartSubType, boolean multipartWithoutAttachment, boolean headersInline,
382                           String includeHeaders, boolean binaryContent) {
383        MimeMultipartDataFormat mm = new MimeMultipartDataFormat();
384        mm.setMultipartSubType(multipartSubType);
385        mm.setMultipartWithoutAttachment(multipartWithoutAttachment);
386        mm.setHeadersInline(headersInline);
387        mm.setIncludeHeaders(includeHeaders);
388        mm.setBinaryContent(binaryContent);
389        return dataFormat(mm);
390    }
391
392    /**
393     * Uses the MIME Multipart data format
394     *
395     * @param multipartWithoutAttachment defines whether a message without attachment is also marshaled
396     *                                   into a MIME Multipart (with only one body part).
397     * @param headersInline              define the MIME Multipart headers as part of the message body
398     *                                   or as Camel headers
399     * @param binaryContent              have binary encoding for binary content (true) or use Base-64
400     *                                   encoding for binary content (false)
401     */
402    public T mimeMultipart(boolean multipartWithoutAttachment, boolean headersInline,
403                           boolean binaryContent) {
404        MimeMultipartDataFormat mm = new MimeMultipartDataFormat();
405        mm.setMultipartWithoutAttachment(multipartWithoutAttachment);
406        mm.setHeadersInline(headersInline);
407        mm.setBinaryContent(binaryContent);
408        return dataFormat(mm);
409    }
410
411    /**
412     * Uses the PGP data format
413     */
414    public T pgp(String keyFileName, String keyUserid) {
415        PGPDataFormat pgp = new PGPDataFormat();
416        pgp.setKeyFileName(keyFileName);
417        pgp.setKeyUserid(keyUserid);
418        return dataFormat(pgp);
419    }
420
421    /**
422     * Uses the PGP data format
423     */
424    public T pgp(String keyFileName, String keyUserid, String password) {
425        PGPDataFormat pgp = new PGPDataFormat();
426        pgp.setKeyFileName(keyFileName);
427        pgp.setKeyUserid(keyUserid);
428        pgp.setPassword(password);
429        return dataFormat(pgp);
430    }
431
432    /**
433     * Uses the PGP data format
434     */
435    public T pgp(String keyFileName, String keyUserid, String password, boolean armored, boolean integrity) {
436        PGPDataFormat pgp = new PGPDataFormat();
437        pgp.setKeyFileName(keyFileName);
438        pgp.setKeyUserid(keyUserid);
439        pgp.setPassword(password);
440        pgp.setArmored(armored);
441        pgp.setIntegrity(integrity);
442        return dataFormat(pgp);
443    }
444    
445    /**
446     * Uses the Jackson XML data format
447     */
448    public T jacksonxml() {
449        return dataFormat(new JacksonXMLDataFormat());
450    }
451
452    /**
453     * Uses the Jackson XML data format
454     *
455     * @param unmarshalType
456     *            unmarshal type for xml jackson type
457     */
458    public T jacksonxml(Class<?> unmarshalType) {
459        JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat();
460        jacksonXMLDataFormat.setUnmarshalType(unmarshalType);
461        return dataFormat(jacksonXMLDataFormat);
462    }
463
464    /**
465     * Uses the Jackson XML data format
466     *
467     * @param unmarshalType
468     *            unmarshal type for xml jackson type
469     * @param jsonView
470     *            the view type for xml jackson type
471     */
472    public T jacksonxml(Class<?> unmarshalType, Class<?> jsonView) {
473        JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat();
474        jacksonXMLDataFormat.setUnmarshalType(unmarshalType);
475        jacksonXMLDataFormat.setJsonView(jsonView);
476        return dataFormat(jacksonXMLDataFormat);
477    }
478
479    /**
480     * Uses the Jackson XML data format using the Jackson library turning pretty
481     * printing on or off
482     * 
483     * @param prettyPrint
484     *            turn pretty printing on or off
485     */
486    public T jacksonxml(boolean prettyPrint) {
487        JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat();
488        jacksonXMLDataFormat.setPrettyPrint(prettyPrint);
489        return dataFormat(jacksonXMLDataFormat);
490    }
491
492    /**
493     * Uses the Jackson XML data format
494     *
495     * @param unmarshalType
496     *            unmarshal type for xml jackson type
497     * @param prettyPrint
498     *            turn pretty printing on or off
499     */
500    public T jacksonxml(Class<?> unmarshalType, boolean prettyPrint) {
501        JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat();
502        jacksonXMLDataFormat.setUnmarshalType(unmarshalType);
503        jacksonXMLDataFormat.setPrettyPrint(prettyPrint);
504        return dataFormat(jacksonXMLDataFormat);
505    }
506
507    /**
508     * Uses the Jackson XML data format
509     *
510     * @param unmarshalType
511     *            unmarshal type for xml jackson type
512     * @param jsonView
513     *            the view type for xml jackson type
514     * @param prettyPrint
515     *            turn pretty printing on or off
516     */
517    public T jacksonxml(Class<?> unmarshalType, Class<?> jsonView, boolean prettyPrint) {
518        JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat();
519        jacksonXMLDataFormat.setUnmarshalType(unmarshalType);
520        jacksonXMLDataFormat.setJsonView(jsonView);
521        jacksonXMLDataFormat.setPrettyPrint(prettyPrint);
522        return dataFormat(jacksonXMLDataFormat);
523    }
524
525    /**
526     * Uses the Jackson XML data format
527     *
528     * @param unmarshalType
529     *            unmarshal type for xml jackson type
530     * @param jsonView
531     *            the view type for xml jackson type
532     * @param include
533     *            include such as <tt>ALWAYS</tt>, <tt>NON_NULL</tt>, etc.
534     */
535    public T jacksonxml(Class<?> unmarshalType, Class<?> jsonView, String include) {
536        JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat();
537        jacksonXMLDataFormat.setUnmarshalType(unmarshalType);
538        jacksonXMLDataFormat.setJsonView(jsonView);
539        jacksonXMLDataFormat.setInclude(include);
540        return dataFormat(jacksonXMLDataFormat);
541    }
542
543    /**
544     * Uses the Jackson XML data format
545     *
546     * @param unmarshalType
547     *            unmarshal type for xml jackson type
548     * @param jsonView
549     *            the view type for xml jackson type
550     * @param include
551     *            include such as <tt>ALWAYS</tt>, <tt>NON_NULL</tt>, etc.
552     * @param prettyPrint
553     *            turn pretty printing on or off
554     */
555    public T jacksonxml(Class<?> unmarshalType, Class<?> jsonView, String include, boolean prettyPrint) {
556        JacksonXMLDataFormat jacksonXMLDataFormat = new JacksonXMLDataFormat();
557        jacksonXMLDataFormat.setUnmarshalType(unmarshalType);
558        jacksonXMLDataFormat.setJsonView(jsonView);
559        jacksonXMLDataFormat.setInclude(include);
560        jacksonXMLDataFormat.setPrettyPrint(prettyPrint);
561        return dataFormat(jacksonXMLDataFormat);
562    }
563
564    /**
565     * Uses the JAXB data format
566     */
567    public T jaxb() {
568        return dataFormat(new JaxbDataFormat());
569    }
570
571    /**
572     * Uses the JAXB data format with context path
573     */
574    public T jaxb(String contextPath) {
575        JaxbDataFormat dataFormat = new JaxbDataFormat();
576        dataFormat.setContextPath(contextPath);
577        return dataFormat(dataFormat);
578    }
579
580    /**
581     * Uses the JAXB data format turning pretty printing on or off
582     */
583    public T jaxb(boolean prettyPrint) {
584        return dataFormat(new JaxbDataFormat(prettyPrint));
585    }
586
587    /**
588     * Uses the JiBX data format.
589     */
590    public T jibx() {
591        return dataFormat(new JibxDataFormat());
592    }
593
594    /**
595     * Uses the JiBX data format with unmarshall class.
596     */
597    public T jibx(Class<?> unmarshallClass) {
598        return dataFormat(new JibxDataFormat(unmarshallClass));
599    }
600
601    /**
602     * Uses the JSON data format using the XStream json library
603     */
604    public T json() {
605        return dataFormat(new JsonDataFormat());
606    }
607
608    /**
609     * Uses the JSON data format using the XStream json library turning pretty printing on or off
610     * 
611     * @param prettyPrint turn pretty printing on or off
612     */
613    public T json(boolean prettyPrint) {
614        JsonDataFormat json = new JsonDataFormat();
615        json.setPrettyPrint(prettyPrint);
616        return dataFormat(json);
617    }
618
619    /**
620     * Uses the JSON data format
621     *
622     * @param library the json library to use
623     */
624    public T json(JsonLibrary library) {
625        return dataFormat(new JsonDataFormat(library));
626    }
627
628    /**
629     * Uses the JSON data format
630     *
631     * @param library     the json library to use
632     * @param prettyPrint turn pretty printing on or off
633     */
634    public T json(JsonLibrary library, boolean prettyPrint) {
635        JsonDataFormat json = new JsonDataFormat(library);
636        json.setPrettyPrint(prettyPrint);
637        return dataFormat(json);
638    }
639
640    /**
641     * Uses the JSON data format
642     *
643     * @param type          the json type to use
644     * @param unmarshalType unmarshal type for json jackson type
645     */
646    public T json(JsonLibrary type, Class<?> unmarshalType) {
647        JsonDataFormat json = new JsonDataFormat(type);
648        json.setUnmarshalType(unmarshalType);
649        return dataFormat(json);
650    }
651
652    /**
653     * Uses the JSON data format
654     *
655     * @param type          the json type to use
656     * @param unmarshalType unmarshal type for json jackson type
657     * @param prettyPrint   turn pretty printing on or off
658     */
659    public T json(JsonLibrary type, Class<?> unmarshalType, boolean prettyPrint) {
660        JsonDataFormat json = new JsonDataFormat(type);
661        json.setUnmarshalType(unmarshalType);
662        json.setPrettyPrint(prettyPrint);
663        return dataFormat(json);
664    }
665
666    /**
667     * Uses the Jackson JSON data format
668     *
669     * @param unmarshalType unmarshal type for json jackson type
670     * @param jsonView      the view type for json jackson type
671     */
672    public T json(Class<?> unmarshalType, Class<?> jsonView) {
673        JsonDataFormat json = new JsonDataFormat(JsonLibrary.Jackson);
674        json.setUnmarshalType(unmarshalType);
675        json.setJsonView(jsonView);
676        return dataFormat(json);
677    }
678
679    /**
680     * Uses the Jackson JSON data format
681     *
682     * @param unmarshalType unmarshal type for json jackson type
683     * @param jsonView      the view type for json jackson type
684     * @param prettyPrint   turn pretty printing on or off
685     */
686    public T json(Class<?> unmarshalType, Class<?> jsonView, boolean prettyPrint) {
687        JsonDataFormat json = new JsonDataFormat(JsonLibrary.Jackson);
688        json.setUnmarshalType(unmarshalType);
689        json.setJsonView(jsonView);
690        json.setPrettyPrint(prettyPrint);
691        return dataFormat(json);
692    }
693
694    /**
695     * Uses the Jackson JSON data format
696     *
697     * @param unmarshalType unmarshal type for json jackson type
698     * @param jsonView      the view type for json jackson type
699     * @param include       include such as <tt>ALWAYS</tt>, <tt>NON_NULL</tt>, etc.
700     */
701    public T json(Class<?> unmarshalType, Class<?> jsonView, String include) {
702        JsonDataFormat json = new JsonDataFormat(JsonLibrary.Jackson);
703        json.setUnmarshalType(unmarshalType);
704        json.setJsonView(jsonView);
705        json.setInclude(include);
706        return dataFormat(json);
707    }
708
709    /**
710     * Uses the Jackson JSON data format
711     *
712     * @param unmarshalType unmarshal type for json jackson type
713     * @param jsonView      the view type for json jackson type
714     * @param include       include such as <tt>ALWAYS</tt>, <tt>NON_NULL</tt>, etc.
715      * @param prettyPrint  turn pretty printing on or off
716     */
717    public T json(Class<?> unmarshalType, Class<?> jsonView, String include, boolean prettyPrint) {
718        JsonDataFormat json = new JsonDataFormat(JsonLibrary.Jackson);
719        json.setUnmarshalType(unmarshalType);
720        json.setJsonView(jsonView);
721        json.setInclude(include);
722        json.setPrettyPrint(prettyPrint);
723        return dataFormat(json);
724    }
725
726    /**
727     * Uses the protobuf data format
728     */
729    public T protobuf() {
730        return dataFormat(new ProtobufDataFormat());
731    }
732
733    public T protobuf(Object defaultInstance) {
734        ProtobufDataFormat dataFormat = new ProtobufDataFormat();
735        dataFormat.setDefaultInstance(defaultInstance);
736        return dataFormat(dataFormat);
737    }
738    
739    public T protobuf(Object defaultInstance, String contentTypeFormat) {
740        ProtobufDataFormat dataFormat = new ProtobufDataFormat();
741        dataFormat.setDefaultInstance(defaultInstance);
742        dataFormat.setContentTypeFormat(contentTypeFormat);
743        return dataFormat(dataFormat);
744    }
745
746    public T protobuf(String instanceClassName) {
747        return dataFormat(new ProtobufDataFormat(instanceClassName));
748    }
749    
750    public T protobuf(String instanceClassName, String contentTypeFormat) {
751        return dataFormat(new ProtobufDataFormat(instanceClassName, contentTypeFormat));
752    }
753
754    /**
755     * Uses the RSS data format
756     */
757    public T rss() {
758        return dataFormat(new RssDataFormat());
759    }
760
761    /**
762     * Uses the Java Serialization data format
763     */
764    @Deprecated
765    public T serialization() {
766        return dataFormat(new SerializationDataFormat());
767    }
768
769    /**
770     * Uses the Soap 1.1 JAXB data format
771     */
772    public T soapjaxb() {
773        return dataFormat(new SoapJaxbDataFormat());
774    }
775
776    /**
777     * Uses the Soap 1.1 JAXB data format
778     */
779    public T soapjaxb(String contextPath) {
780        return dataFormat(new SoapJaxbDataFormat(contextPath));
781    }
782
783    /**
784     * Uses the Soap 1.1 JAXB data format
785     */
786    public T soapjaxb(String contextPath, String elementNameStrategyRef) {
787        return dataFormat(new SoapJaxbDataFormat(contextPath, elementNameStrategyRef));
788    }
789
790    /**
791     * Uses the Soap 1.1 JAXB data format
792     */
793    public T soapjaxb(String contextPath, Object elementNameStrategy) {
794        return dataFormat(new SoapJaxbDataFormat(contextPath, elementNameStrategy));
795    }
796
797    /**
798     * Uses the Soap 1.2 JAXB data format
799     */
800    public T soapjaxb12() {
801        SoapJaxbDataFormat soap = new SoapJaxbDataFormat();
802        soap.setVersion("1.2");
803        return dataFormat(soap);
804    }
805
806    /**
807     * Uses the Soap 1.2 JAXB data format
808     */
809    public T soapjaxb12(String contextPath) {
810        SoapJaxbDataFormat soap = new SoapJaxbDataFormat(contextPath);
811        soap.setVersion("1.2");
812        return dataFormat(soap);
813    }
814
815    /**
816     * Uses the Soap 1.2 JAXB data format
817     */
818    public T soapjaxb12(String contextPath, String elementNameStrategyRef) {
819        SoapJaxbDataFormat soap = new SoapJaxbDataFormat(contextPath, elementNameStrategyRef);
820        soap.setVersion("1.2");
821        return dataFormat(soap);
822    }
823
824    /**
825     * Uses the Soap JAXB data format
826     */
827    public T soapjaxb12(String contextPath, Object elementNameStrategy) {
828        SoapJaxbDataFormat soap = new SoapJaxbDataFormat(contextPath, elementNameStrategy);
829        soap.setVersion("1.2");
830        return dataFormat(soap);
831    }
832
833    /**
834     * Uses the String data format
835     */
836    @Deprecated
837    public T string() {
838        return string(null);
839    }
840
841    /**
842     * Uses the String data format supporting encoding using given charset
843     */
844    @Deprecated
845    public T string(String charset) {
846        StringDataFormat sdf = new StringDataFormat();
847        sdf.setCharset(charset);
848        return dataFormat(sdf);
849    }
850
851    /**
852     * Uses the Syslog data format
853     */
854    public T syslog() {
855        return dataFormat(new SyslogDataFormat());
856    }
857    
858    /**
859     * Uses the Thrift data format
860     */
861    public T thrift() {
862        return dataFormat(new ThriftDataFormat());
863    }
864
865    public T thrift(Object defaultInstance) {
866        ThriftDataFormat dataFormat = new ThriftDataFormat();
867        dataFormat.setDefaultInstance(defaultInstance);
868        return dataFormat(dataFormat);
869    }
870    
871    public T thrift(Object defaultInstance, String contentTypeFormat) {
872        ThriftDataFormat dataFormat = new ThriftDataFormat();
873        dataFormat.setDefaultInstance(defaultInstance);
874        dataFormat.setContentTypeFormat(contentTypeFormat);
875        return dataFormat(dataFormat);
876    }
877
878    public T thrift(String instanceClassName) {
879        return dataFormat(new ThriftDataFormat(instanceClassName));
880    }
881    
882    public T thrift(String instanceClassName, String contentTypeFormat) {
883        return dataFormat(new ThriftDataFormat(instanceClassName, contentTypeFormat));
884    }
885
886    /**
887     * Return WellFormed HTML (an XML Document) either
888     * {@link java.lang.String} or {@link org.w3c.dom.Node}
889     */
890    public T tidyMarkup(Class<?> dataObjectType) {
891        return dataFormat(new TidyMarkupDataFormat(dataObjectType));
892    }
893
894    /**
895     * Return TidyMarkup in the default format
896     * as {@link org.w3c.dom.Node}
897     */
898    public T tidyMarkup() {
899        return dataFormat(new TidyMarkupDataFormat(Node.class));
900    }
901
902    /**
903     * Uses the XStream data format.
904     * <p/>
905     * Favor using {@link #xstream(String)} to pass in a permission
906     */
907    public T xstream() {
908        return dataFormat(new XStreamDataFormat());
909    }
910
911    /**
912     * Uses the xstream by setting the encoding or permission
913     *
914     * @param encodingOrPermission is either an encoding or permission syntax
915     */
916    public T xstream(String encodingOrPermission) {
917        // is it an encoding? if not we assume its a permission
918        if (Charset.isSupported(encodingOrPermission)) {
919            return xstream(encodingOrPermission, (String) null);
920        } else {
921            return xstream(null, encodingOrPermission);
922        }
923    }
924
925    /**
926     * Uses the xstream by setting the encoding
927     */
928    public T xstream(String encoding, String permission) {
929        XStreamDataFormat xdf = new XStreamDataFormat();
930        xdf.setPermissions(permission);
931        xdf.setEncoding(encoding);
932        return dataFormat(xdf);
933    }
934
935    /**
936     * Uses the xstream by permitting the java type
937     *
938     * @param type the pojo xstream should use as allowed permission
939     */
940    public T xstream(Class<?> type) {
941        return xstream(null, type);
942    }
943
944    /**
945     * Uses the xstream by permitting the java type
946     *
947     * @param encoding encoding to use
948     * @param type the pojo class(es) xstream should use as allowed permission
949     */
950    public T xstream(String encoding, Class<?>... type) {
951        CollectionStringBuffer csb = new CollectionStringBuffer(",");
952        for (Class<?> clazz : type) {
953            csb.append("+");
954            csb.append(clazz.getName());
955        }
956        return xstream(encoding, csb.toString());
957    }
958
959    /**
960     * Uses the YAML data format
961     *
962     * @param library the yaml library to use
963     */
964    public T yaml(YAMLLibrary library) {
965        return dataFormat(new YAMLDataFormat(library));
966    }
967
968    /**
969     * Uses the YAML data format
970     *
971     * @param library the yaml type to use
972     * @param type the type for json snakeyaml type
973     */
974    public T yaml(YAMLLibrary library, Class<?> type) {
975        return dataFormat(new YAMLDataFormat(library, type));
976    }
977
978    /**
979     * Uses the XML Security data format
980     */
981    public T secureXML() {
982        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat();
983        return dataFormat(xsdf);
984    }
985
986    /**
987     * Uses the XML Security data format
988     */
989    public T secureXML(String secureTag, boolean secureTagContents) {
990        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents);
991        return dataFormat(xsdf);
992    }
993    
994    /**
995     * Uses the XML Security data format
996     */
997    public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents) {
998        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents);
999        return dataFormat(xsdf);
1000    }
1001
1002    /**
1003     * Uses the XML Security data format
1004     */
1005    public T secureXML(String secureTag, boolean secureTagContents, String passPhrase) {
1006        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, passPhrase);
1007        return dataFormat(xsdf);
1008    }
1009    
1010    /**
1011     * Uses the XML Security data format
1012     */
1013    public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String passPhrase) {
1014        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, passPhrase);
1015        return dataFormat(xsdf);
1016    }
1017    
1018    /**
1019     * Uses the XML Security data format
1020     */
1021    public T secureXML(String secureTag, boolean secureTagContents, String passPhrase, String xmlCipherAlgorithm) {
1022        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, passPhrase, xmlCipherAlgorithm);
1023        return dataFormat(xsdf);
1024    }
1025    
1026    
1027    /**
1028     * Uses the XML Security data format
1029     */
1030    public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String passPhrase, String xmlCipherAlgorithm) {
1031        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, passPhrase, xmlCipherAlgorithm);
1032        return dataFormat(xsdf);
1033    }
1034    
1035    
1036    /**
1037     * Uses the XML Security data format
1038     */
1039    public T secureXML(String secureTag, boolean secureTagContents, byte[] passPhraseByte) {
1040        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat();
1041        xsdf.setSecureTag(secureTag);
1042        xsdf.setSecureTagContents(secureTagContents);
1043        xsdf.setPassPhraseByte(passPhraseByte);
1044        return dataFormat(xsdf);
1045    }
1046    
1047    /**
1048     * Uses the XML Security data format
1049     */
1050    public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, byte[] passPhraseByte) {
1051        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat();
1052        xsdf.setSecureTag(secureTag);
1053        xsdf.setNamespaces(namespaces);
1054        xsdf.setSecureTagContents(secureTagContents);
1055        xsdf.setPassPhraseByte(passPhraseByte);
1056        return dataFormat(xsdf);
1057    }
1058    
1059    /**
1060     * Uses the XML Security data format
1061     */
1062    public T secureXML(String secureTag, boolean secureTagContents, byte[] passPhraseByte, String xmlCipherAlgorithm) {
1063        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat();
1064        xsdf.setSecureTag(secureTag);
1065        xsdf.setSecureTagContents(secureTagContents);
1066        xsdf.setPassPhraseByte(passPhraseByte);
1067        xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm);
1068        return dataFormat(xsdf);
1069    }
1070    
1071    
1072    /**
1073     * Uses the XML Security data format
1074     */
1075    public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, byte[] passPhraseByte, String xmlCipherAlgorithm) {
1076        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat();
1077        xsdf.setSecureTag(secureTag);
1078        xsdf.setNamespaces(namespaces);
1079        xsdf.setSecureTagContents(secureTagContents);
1080        xsdf.setPassPhraseByte(passPhraseByte);
1081        xsdf.setXmlCipherAlgorithm(xmlCipherAlgorithm);
1082        return dataFormat(xsdf);
1083    }
1084    
1085    /**
1086     * @deprecated Use {@link #secureXML(String, Map, boolean, String, String, String, String)} instead.
1087     * Uses the XML Security data format
1088     */
1089    @Deprecated
1090    public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, 
1091            String keyCipherAlgorithm) {
1092        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, keyCipherAlgorithm);
1093        return dataFormat(xsdf);
1094    }
1095    
1096    /**
1097     * Uses the XML Security data format
1098     */
1099    public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, 
1100            String keyCipherAlgorithm, String keyOrTrustStoreParametersId) {
1101        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 
1102            keyCipherAlgorithm, keyOrTrustStoreParametersId);
1103        return dataFormat(xsdf);
1104    }
1105    
1106    /**
1107     * Uses the XML Security data format
1108     */
1109    public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, 
1110            String keyCipherAlgorithm, String keyOrTrustStoreParametersId, String keyPassword) {
1111        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 
1112            keyCipherAlgorithm, keyOrTrustStoreParametersId, keyPassword);
1113        return dataFormat(xsdf);
1114    }    
1115    
1116    /**
1117     * Uses the XML Security data format
1118     */
1119    public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, 
1120            String keyCipherAlgorithm, KeyStoreParameters keyOrTrustStoreParameters) {
1121        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 
1122            keyCipherAlgorithm, keyOrTrustStoreParameters);
1123        return dataFormat(xsdf);
1124    }
1125    
1126    /**
1127     * Uses the XML Security data format
1128     */
1129    public T secureXML(String secureTag, boolean secureTagContents, String recipientKeyAlias, String xmlCipherAlgorithm, 
1130            String keyCipherAlgorithm, KeyStoreParameters keyOrTrustStoreParameters, String keyPassword) {
1131        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 
1132            keyCipherAlgorithm, keyOrTrustStoreParameters, keyPassword);
1133        return dataFormat(xsdf);
1134    }    
1135    
1136    /**
1137     * Uses the XML Security data format
1138     */
1139    public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, 
1140            String xmlCipherAlgorithm, String keyCipherAlgorithm, String keyOrTrustStoreParametersId) {
1141        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 
1142                keyCipherAlgorithm, keyOrTrustStoreParametersId);
1143        return dataFormat(xsdf);
1144    }
1145    
1146    /**
1147     * Uses the XML Security data format
1148     */
1149    public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, 
1150            String xmlCipherAlgorithm, String keyCipherAlgorithm, String keyOrTrustStoreParametersId, String keyPassword) {
1151        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 
1152                keyCipherAlgorithm, keyOrTrustStoreParametersId, keyPassword);
1153        return dataFormat(xsdf);
1154    }    
1155    
1156    /**
1157     * Uses the XML Security data format
1158     */
1159    public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, 
1160            String xmlCipherAlgorithm, String keyCipherAlgorithm, KeyStoreParameters keyOrTrustStoreParameters) {
1161        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 
1162                keyCipherAlgorithm, keyOrTrustStoreParameters);
1163        return dataFormat(xsdf);
1164    }
1165    
1166    /**
1167     * Uses the XML Security data format
1168     */
1169    public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, 
1170            String xmlCipherAlgorithm, String keyCipherAlgorithm, KeyStoreParameters keyOrTrustStoreParameters, String keyPassword) {
1171        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 
1172                keyCipherAlgorithm, keyOrTrustStoreParameters, keyPassword);
1173        return dataFormat(xsdf);
1174    }   
1175    
1176    /**
1177     * Uses the XML Security data format
1178     */
1179    public T secureXML(String secureTag, Map<String, String> namespaces, boolean secureTagContents, String recipientKeyAlias, 
1180            String xmlCipherAlgorithm, String keyCipherAlgorithm, KeyStoreParameters keyOrTrustStoreParameters, String keyPassword,
1181            String digestAlgorithm) {
1182        XMLSecurityDataFormat xsdf = new XMLSecurityDataFormat(secureTag, namespaces, secureTagContents, recipientKeyAlias, xmlCipherAlgorithm, 
1183                keyCipherAlgorithm, keyOrTrustStoreParameters, keyPassword, digestAlgorithm);
1184        return dataFormat(xsdf);
1185    }
1186
1187    /**
1188     * Uses the Tar file data format
1189     */
1190    public T tarFile() {
1191        TarFileDataFormat tfdf = new TarFileDataFormat();
1192        return dataFormat(tfdf);
1193    }
1194
1195    /**
1196     * Uses the xmlBeans data format
1197     */
1198    public T xmlBeans() {
1199        return dataFormat(new XMLBeansDataFormat());
1200    }
1201
1202    /**
1203     * Uses the xmljson dataformat, based on json-lib
1204     */
1205    @Deprecated
1206    public T xmljson() {
1207        return dataFormat(new XmlJsonDataFormat());
1208    }
1209    
1210    /**
1211     * Uses the xmljson dataformat, based on json-lib, initializing custom options with a Map
1212     */
1213    @Deprecated
1214    public T xmljson(Map<String, String> options) {
1215        return dataFormat(new XmlJsonDataFormat(options));
1216    }
1217    
1218    /**
1219     * Uses the ZIP deflater data format
1220     */
1221    public T zip() {
1222        ZipDataFormat zdf = new ZipDataFormat(Deflater.DEFAULT_COMPRESSION);
1223        return dataFormat(zdf);
1224    }
1225
1226    /**
1227     * Uses the ZIP deflater data format
1228     */
1229    public T zip(int compressionLevel) {
1230        ZipDataFormat zdf = new ZipDataFormat(compressionLevel);
1231        return dataFormat(zdf);
1232    }
1233
1234    /**
1235     * Uses the ZIP file data format
1236     */
1237    public T zipFile() {
1238        ZipFileDataFormat zfdf = new ZipFileDataFormat();
1239        return dataFormat(zfdf);
1240    }
1241    
1242    /**
1243     * Uses the ASN.1 file data format
1244     */
1245    public T asn1() {
1246        ASN1DataFormat asn1Df = new ASN1DataFormat();
1247        return dataFormat(asn1Df);
1248    }
1249    
1250    public T asn1(String clazzName) {
1251        return dataFormat(new ASN1DataFormat(clazzName));
1252    }
1253    
1254    public T asn1(Boolean usingIterator) {
1255        return dataFormat(new ASN1DataFormat(usingIterator));
1256    }
1257
1258    /**
1259     * Uses the FHIR JSON data format
1260     */
1261    public T fhirJson() {
1262        FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat();
1263        return dataFormat(jsonDataFormat);
1264    }
1265
1266    public T fhirJson(String version) {
1267        FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat();
1268        jsonDataFormat.setFhirVersion(version);
1269        return dataFormat(jsonDataFormat);
1270    }
1271
1272    public T fhirJson(boolean prettyPrint) {
1273        FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat();
1274        jsonDataFormat.setPrettyPrint(prettyPrint);
1275        return dataFormat(jsonDataFormat);
1276    }
1277
1278    public T fhirJson(String version, boolean prettyPrint) {
1279        FhirJsonDataFormat jsonDataFormat = new FhirJsonDataFormat();
1280        jsonDataFormat.setPrettyPrint(prettyPrint);
1281        jsonDataFormat.setFhirVersion(version);
1282        return dataFormat(jsonDataFormat);
1283    }
1284
1285    /**
1286     * Uses the FHIR XML data format
1287     */
1288    public T fhirXml() {
1289        FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat();
1290        return dataFormat(fhirXmlDataFormat);
1291    }
1292
1293    public T fhirXml(String version) {
1294        FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat();
1295        fhirXmlDataFormat.setFhirVersion(version);
1296        return dataFormat(fhirXmlDataFormat);
1297    }
1298
1299    public T fhirXml(boolean prettyPrint) {
1300        FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat();
1301        fhirXmlDataFormat.setPrettyPrint(prettyPrint);
1302        return dataFormat(fhirXmlDataFormat);
1303    }
1304
1305    public T fhirXml(String version, boolean prettyPrint) {
1306        FhirXmlDataFormat fhirXmlDataFormat = new FhirXmlDataFormat();
1307        fhirXmlDataFormat.setFhirVersion(version);
1308        fhirXmlDataFormat.setPrettyPrint(prettyPrint);
1309        return dataFormat(fhirXmlDataFormat);
1310    }
1311
1312    @SuppressWarnings("unchecked")
1313    private T dataFormat(DataFormatDefinition dataFormatType) {
1314        switch (operation) {
1315        case Unmarshal:
1316            return (T) processorType.unmarshal(dataFormatType);
1317        case Marshal:
1318            return (T) processorType.marshal(dataFormatType);
1319        default:
1320            throw new IllegalArgumentException("Unknown DataFormat operation: " + operation);
1321        }
1322    }
1323}