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
037        /**
038         * Returns an attribute associated with this meta data by name.
039         *
040         * @param name the attribute name
041         * @return the attribute
042         */
043        Object getAttribute(String name);
044
045        /**
046         * @return a read-only list of attributes.
047         */
048        Map<String, Object> getAttributes();
049
050        /**
051         *
052         * Returns an attribute associated with this meta data by name and
053         * specifying the type required.
054         *
055         * @param name the attribute name
056         * @param type the type of the attribute
057         * @return the value of the given attribute or <tt>null</tt> if there is no attribute for the given name
058         * @throws TypeConversionException is thrown if error during type conversion
059         */
060        <T> T getAttribute(String name, Class<T> type);
061
062        /**
063         * Returns the payload of the meta data as a POJO.
064         *
065         * @return the body, can be <tt>null</tt>
066         */
067        Object getPayload();
068
069        /**
070         * Returns the payload of the meta data as specified type.
071         *
072         * @param type the type that the payload should be converted yo.
073         * @return the payload of the meta data as the specified type.
074         * @throws TypeConversionException is thrown if error during type conversion
075         */
076        <T> T getPayload(Class<T> type);
077    }
078}