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.reifier.dataformat;
018
019import java.util.Map;
020import javax.xml.namespace.QName;
021
022import org.apache.camel.CamelContext;
023import org.apache.camel.model.DataFormatDefinition;
024import org.apache.camel.model.dataformat.JaxbDataFormat;
025import org.apache.camel.spi.DataFormat;
026import org.apache.camel.support.CamelContextHelper;
027import org.apache.camel.util.ObjectHelper;
028
029public class JaxbDataFormatReifier extends DataFormatReifier<JaxbDataFormat> {
030
031    public JaxbDataFormatReifier(DataFormatDefinition definition) {
032        super((JaxbDataFormat)definition);
033    }
034
035    @Override
036    protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
037        Boolean answer = ObjectHelper.toBoolean(definition.getPrettyPrint());
038        if (answer != null && !answer) {
039            setProperty(camelContext, dataFormat, "prettyPrint", Boolean.FALSE);
040        } else { // the default value is true
041            setProperty(camelContext, dataFormat, "prettyPrint", Boolean.TRUE);
042        }
043        answer = ObjectHelper.toBoolean(definition.getObjectFactory());
044        if (answer != null && !answer) {
045            setProperty(camelContext, dataFormat, "objectFactory", Boolean.FALSE);
046        } else { // the default value is true
047            setProperty(camelContext, dataFormat, "objectFactory", Boolean.TRUE);
048        }
049        answer = ObjectHelper.toBoolean(definition.getIgnoreJAXBElement());
050        if (answer != null && !answer) {
051            setProperty(camelContext, dataFormat, "ignoreJAXBElement", Boolean.FALSE);
052        } else { // the default value is true
053            setProperty(camelContext, dataFormat, "ignoreJAXBElement", Boolean.TRUE);
054        }
055        answer = ObjectHelper.toBoolean(definition.getMustBeJAXBElement());
056        if (answer != null && answer) {
057            setProperty(camelContext, dataFormat, "mustBeJAXBElement", Boolean.TRUE);
058        } else { // the default value is false
059            setProperty(camelContext, dataFormat, "mustBeJAXBElement", Boolean.FALSE);
060        }
061        answer = ObjectHelper.toBoolean(definition.getFilterNonXmlChars());
062        if (answer != null && answer) {
063            setProperty(camelContext, dataFormat, "filterNonXmlChars", Boolean.TRUE);
064        } else { // the default value is false
065            setProperty(camelContext, dataFormat, "filterNonXmlChars", Boolean.FALSE);
066        }
067        answer = ObjectHelper.toBoolean(definition.getFragment());
068        if (answer != null && answer) {
069            setProperty(camelContext, dataFormat, "fragment", Boolean.TRUE);
070        } else { // the default value is false
071            setProperty(camelContext, dataFormat, "fragment", Boolean.FALSE);
072        }
073
074        setProperty(camelContext, dataFormat, "contextPath", definition.getContextPath());
075        if (definition.getPartClass() != null) {
076            setProperty(camelContext, dataFormat, "partClass", definition.getPartClass());
077        }
078        if (definition.getPartNamespace() != null) {
079            setProperty(camelContext, dataFormat, "partNamespace", QName.valueOf(definition.getPartNamespace()));
080        }
081        if (definition.getEncoding() != null) {
082            setProperty(camelContext, dataFormat, "encoding", definition.getEncoding());
083        }
084        if (definition.getNamespacePrefixRef() != null) {
085            setProperty(camelContext, dataFormat, "namespacePrefixRef", definition.getNamespacePrefixRef());
086        }
087        if (definition.getSchema() != null) {
088            setProperty(camelContext, dataFormat, "schema", definition.getSchema());
089        }
090        if (definition.getSchemaSeverityLevel() != null) {
091            setProperty(camelContext, dataFormat, "schemaSeverityLevel", definition.getSchemaSeverityLevel());
092        }
093        if (definition.getXmlStreamWriterWrapper() != null) {
094            setProperty(camelContext, dataFormat, "xmlStreamWriterWrapper", definition.getXmlStreamWriterWrapper());
095        }
096        if (definition.getSchemaLocation() != null) {
097            setProperty(camelContext, dataFormat, "schemaLocation", definition.getSchemaLocation());
098        }
099        if (definition.getNoNamespaceSchemaLocation() != null) {
100            setProperty(camelContext, dataFormat, "noNamespaceSchemaLocation", definition.getNoNamespaceSchemaLocation());
101        }
102        if (definition.getJaxbProviderProperties() != null) {
103            Map map = CamelContextHelper.mandatoryLookup(camelContext, definition.getJaxbProviderProperties(), Map.class);
104            setProperty(camelContext, dataFormat, "jaxbProviderProperties", map);
105        }
106    }
107
108}