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.impl; 018 019import java.util.Map; 020import java.util.Set; 021import java.util.SortedMap; 022import java.util.TreeMap; 023 024import org.apache.camel.Component; 025import org.apache.camel.Endpoint; 026import org.apache.camel.InvalidPropertyException; 027import org.apache.camel.RuntimeCamelException; 028import org.apache.camel.util.IntrospectionSupport; 029 030/** 031 * Default implementation for components which do not inherit from {@link UriEndpointComponent} and 032 * do not have Endpoint classes annotated with {@link org.apache.camel.spi.UriEndpoint} 033 */ 034@Deprecated 035public class DefaultComponentConfiguration extends ComponentConfigurationSupport { 036 037 public DefaultComponentConfiguration(Component component) { 038 super(component); 039 } 040 041 @Override 042 public Object getEndpointParameter(Endpoint endpoint, String name) throws RuntimeCamelException { 043 try { 044 return IntrospectionSupport.getProperty(endpoint, name); 045 } catch (Exception e) { 046 throw new RuntimeCamelException("Failed to get property " + name + " on endpoint " + endpoint + " due to " + e.getMessage(), e); 047 } 048 } 049 050 @Override 051 public void setEndpointParameter(Endpoint endpoint, String name, Object value) throws RuntimeCamelException { 052 boolean answer; 053 try { 054 answer = IntrospectionSupport.setProperty(endpoint, name, value); 055 } catch (Exception e) { 056 throw new RuntimeCamelException( 057 "Failed to set property " + name + " with value " + value + " on endpoint " + endpoint + " due to " + e.getMessage(), e); 058 } 059 if (!answer) { 060 throw new InvalidPropertyException(endpoint, name); 061 } 062 } 063 064 /** 065 * Since we have no parameter metadata lets just return parameter configurations for each parameter we 066 * have right now. 067 * 068 * @return configurations for each current property value 069 */ 070 @Override 071 public SortedMap<String, ParameterConfiguration> getParameterConfigurationMap() { 072 SortedMap<String, ParameterConfiguration> answer = new TreeMap<>(); 073 Set<Map.Entry<String, Object>> entries = getParameters().entrySet(); 074 for (Map.Entry<String, Object> entry : entries) { 075 String name = entry.getKey(); 076 Object value = entry.getValue(); 077 Class<?> type = (value != null) ? value.getClass() : String.class; 078 answer.put(name, new ParameterConfiguration(name, type)); 079 } 080 return answer; 081 } 082 083}