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.component.extension; 018 019import java.util.Map; 020import java.util.Optional; 021 022import org.apache.camel.Exchange; 023import org.apache.camel.TypeConversionException; 024 025public interface MetaDataExtension extends ComponentExtension { 026 /** 027 * @param parameters 028 * @return the {@link MetaData} 029 */ 030 Optional<MetaData> meta(Map<String, Object> parameters); 031 032 interface MetaData { 033 // Common meta-data attributes 034 String CONTENT_TYPE = Exchange.CONTENT_TYPE; 035 String JAVA_TYPE = "Java-Type"; 036 String CONTEXT = "Meta-Context"; 037 038 /** 039 * Returns an attribute associated with this meta data by name. 040 * 041 * @param name the attribute name 042 * @return the attribute 043 */ 044 Object getAttribute(String name); 045 046 /** 047 * @return a read-only list of attributes. 048 */ 049 Map<String, Object> getAttributes(); 050 051 /** 052 * 053 * Returns an attribute associated with this meta data by name and 054 * specifying the type required. 055 * 056 * @param name the attribute name 057 * @param type the type of the attribute 058 * @return the value of the given attribute or <tt>null</tt> if there is no attribute for the given name 059 * @throws TypeConversionException is thrown if error during type conversion 060 */ 061 <T> T getAttribute(String name, Class<T> type); 062 063 /** 064 * Returns the payload of the meta data as a POJO. 065 * 066 * @return the body, can be <tt>null</tt> 067 */ 068 Object getPayload(); 069 070 /** 071 * Returns the payload of the meta data as specified type. 072 * 073 * @param type the type that the payload should be converted yo. 074 * @return the payload of the meta data as the specified type. 075 * @throws TypeConversionException is thrown if error during type conversion 076 */ 077 <T> T getPayload(Class<T> type); 078 } 079}