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.JacksonXMLDataFormat; 023import org.apache.camel.spi.DataFormat; 024 025public class JacksonXMLDataFormatReifier extends DataFormatReifier<JacksonXMLDataFormat> { 026 027 public JacksonXMLDataFormatReifier(DataFormatDefinition definition) { 028 super((JacksonXMLDataFormat)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.getXmlMapper() != null) { 054 // must be a reference value 055 String ref = definition.getXmlMapper().startsWith("#") ? definition.getXmlMapper() : "#" + definition.getXmlMapper(); 056 setProperty(camelContext, dataFormat, "xmlMapper", ref); 057 } 058 if (definition.getUnmarshalType() != null) { 059 setProperty(camelContext, dataFormat, "unmarshalType", definition.getUnmarshalType()); 060 } 061 if (definition.getPrettyPrint() != null) { 062 setProperty(camelContext, dataFormat, "prettyPrint", definition.getPrettyPrint()); 063 } 064 if (definition.getJsonView() != null) { 065 setProperty(camelContext, dataFormat, "jsonView", definition.getJsonView()); 066 } 067 if (definition.getInclude() != null) { 068 setProperty(camelContext, dataFormat, "include", definition.getInclude()); 069 } 070 if (definition.getAllowJmsType() != null) { 071 setProperty(camelContext, dataFormat, "allowJmsType", definition.getAllowJmsType()); 072 } 073 if (definition.getCollectionTypeName() != null) { 074 setProperty(camelContext, dataFormat, "collectionType", definition.getCollectionTypeName()); 075 } 076 if (definition.getUseList() != null) { 077 setProperty(camelContext, dataFormat, "useList", definition.getUseList()); 078 } 079 if (definition.getEnableJaxbAnnotationModule() != null) { 080 setProperty(camelContext, dataFormat, "enableJaxbAnnotationModule", definition.getEnableJaxbAnnotationModule()); 081 } 082 if (definition.getModuleClassNames() != null) { 083 setProperty(camelContext, dataFormat, "modulesClassNames", definition.getModuleClassNames()); 084 } 085 if (definition.getModuleRefs() != null) { 086 setProperty(camelContext, dataFormat, "moduleRefs", definition.getModuleRefs()); 087 } 088 if (definition.getEnableFeatures() != null) { 089 setProperty(camelContext, dataFormat, "enableFeatures", definition.getEnableFeatures()); 090 } 091 if (definition.getDisableFeatures() != null) { 092 setProperty(camelContext, dataFormat, "disableFeatures", definition.getDisableFeatures()); 093 } 094 if (definition.getAllowUnmarshallType() != null) { 095 setProperty(camelContext, dataFormat, "allowUnmarshallType", definition.getAllowUnmarshallType()); 096 } 097 } 098 099}