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.binding; 018 019import java.util.Map; 020 021import org.apache.camel.CamelContext; 022import org.apache.camel.Endpoint; 023import org.apache.camel.impl.DefaultComponent; 024import org.apache.camel.spi.Binding; 025import org.apache.camel.util.ObjectHelper; 026 027import static org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint; 028 029/** 030 * A composite {@link org.apache.camel.Component} which creates a {@link BindingEndpoint} from a 031 * configured {@link Binding} instance and using the optional {@link #setUriPrefix(String)} 032 * and {@link #setUriPostfix(String)} to create the underlying endpoint from the remaining URI 033 * 034 * @deprecated use {@link org.apache.camel.component.binding.BindingNameComponent} 035 */ 036@Deprecated 037public class BindingComponent extends DefaultComponent { 038 private Binding binding; 039 private String uriPrefix; 040 private String uriPostfix; 041 042 public BindingComponent() { 043 } 044 045 public BindingComponent(Binding binding) { 046 this.binding = binding; 047 } 048 049 public BindingComponent(Binding binding, String uriPrefix) { 050 this(binding); 051 this.uriPrefix = uriPrefix; 052 } 053 054 public BindingComponent(Binding binding, String uriPrefix, String uriPostfix) { 055 this(binding, uriPrefix); 056 this.uriPostfix = uriPostfix; 057 } 058 059 public Binding getBinding() { 060 return binding; 061 } 062 063 public void setBinding(Binding binding) { 064 this.binding = binding; 065 } 066 067 public String getUriPostfix() { 068 return uriPostfix; 069 } 070 071 public void setUriPostfix(String uriPostfix) { 072 this.uriPostfix = uriPostfix; 073 } 074 075 public String getUriPrefix() { 076 return uriPrefix; 077 } 078 079 public void setUriPrefix(String uriPrefix) { 080 this.uriPrefix = uriPrefix; 081 } 082 083 @Override 084 protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception { 085 Binding bindingValue = getBinding(); 086 ObjectHelper.notNull(bindingValue, "binding"); 087 088 CamelContext camelContext = getCamelContext(); 089 String delegateURI = createDelegateURI(remaining, parameters); 090 Endpoint delegate = getMandatoryEndpoint(camelContext, delegateURI); 091 return new BindingEndpoint(uri, this, bindingValue, delegate); 092 } 093 094 protected String createDelegateURI(String remaining, Map<String, Object> parameters) { 095 return getOrEmpty(uriPrefix) + remaining + getOrEmpty(uriPostfix); 096 } 097 098 protected static String getOrEmpty(String text) { 099 return text != null ? text : ""; 100 } 101}