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.metadata; 018 019import java.util.Collections; 020import java.util.HashMap; 021import java.util.Map; 022 023import org.apache.camel.CamelContext; 024import org.apache.camel.component.extension.MetaDataExtension; 025 026public final class MetaDataBuilder { 027 private final CamelContext camelContext; 028 private Object payload; 029 private Map<String, Object> attributes; 030 031 private MetaDataBuilder(CamelContext camelContext) { 032 this.camelContext = camelContext; 033 } 034 035 public MetaDataBuilder withPayload(Object payload) { 036 this.payload = payload; 037 return this; 038 } 039 040 public MetaDataBuilder withAttribute(String name, Object value) { 041 if (this.attributes == null) { 042 this.attributes = new HashMap<>(); 043 } 044 045 this.attributes.put(name, value); 046 return this; 047 } 048 049 public MetaDataExtension.MetaData build() { 050 return new DefaultMetaData( 051 camelContext, 052 attributes == null ? Collections.emptyMap() : attributes, 053 payload 054 ); 055 } 056 057 // ***************************** 058 // 059 // ***************************** 060 061 public static MetaDataBuilder on(CamelContext camelContext) { 062 return new MetaDataBuilder(camelContext); 063 } 064}