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 org.apache.camel.CamelContext;
020import org.apache.camel.RuntimeCamelException;
021import org.apache.camel.model.DataFormatDefinition;
022import org.apache.camel.model.dataformat.CBORDataFormat;
023import org.apache.camel.spi.DataFormat;
024
025public class CBORDataFormatReifier extends DataFormatReifier<CBORDataFormat> {
026
027    public CBORDataFormatReifier(DataFormatDefinition definition) {
028        super((CBORDataFormat)definition);
029    }
030
031    @Override
032    protected DataFormat doCreateDataFormat(CamelContext camelContext) {
033        if (definition.getUnmarshalType() == null && definition.getUnmarshalTypeName() != null) {
034            try {
035                definition.setUnmarshalType(camelContext.getClassResolver().resolveMandatoryClass(definition.getUnmarshalTypeName()));
036            } catch (ClassNotFoundException e) {
037                throw RuntimeCamelException.wrapRuntimeCamelException(e);
038            }
039        }
040        if (definition.getCollectionType() == null && definition.getCollectionTypeName() != null) {
041            try {
042                definition.setCollectionType(camelContext.getClassResolver().resolveMandatoryClass(definition.getCollectionTypeName()));
043            } catch (ClassNotFoundException e) {
044                throw RuntimeCamelException.wrapRuntimeCamelException(e);
045            }
046        }
047
048        return super.doCreateDataFormat(camelContext);
049    }
050
051    @Override
052    protected void configureDataFormat(DataFormat dataFormat, CamelContext camelContext) {
053        if (definition.getObjectMapper() != null) {
054            // must be a reference value
055            String ref = definition.getObjectMapper().startsWith("#") ? definition.getObjectMapper() : "#" + definition.getObjectMapper();
056            setProperty(camelContext, dataFormat, "xmlMapper", ref);
057        }
058        if (definition.getUnmarshalType() != null) {
059            setProperty(camelContext, dataFormat, "unmarshalType", definition.getUnmarshalType());
060        }
061        if (definition.getCollectionTypeName() != null) {
062            setProperty(camelContext, dataFormat, "collectionType", definition.getCollectionTypeName());
063        }
064        if (definition.getUseList() != null) {
065            setProperty(camelContext, dataFormat, "useList", definition.getUseList());
066        }
067        if (definition.getAllowUnmarshallType() != null) {
068            setProperty(camelContext, dataFormat, "allowUnmarshallType", definition.getAllowUnmarshallType());
069        }
070        if (definition.getPrettyPrint() != null) {
071            setProperty(camelContext, dataFormat, "prettyPrint", definition.getPrettyPrint());
072        }
073        if (definition.getAllowJmsType() != null) {
074            setProperty(camelContext, dataFormat, "allowJmsType", definition.getAllowJmsType());
075        }
076        if (definition.getEnableFeatures() != null) {
077            setProperty(camelContext, dataFormat, "enableFeatures", definition.getEnableFeatures());
078        }
079        if (definition.getDisableFeatures() != null) {
080            setProperty(camelContext, dataFormat, "disableFeatures", definition.getDisableFeatures());
081        }
082    }
083
084}