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; 018 019import java.net.URISyntaxException; 020import java.util.List; 021import java.util.Map; 022import java.util.SortedMap; 023 024import org.apache.camel.impl.ParameterConfiguration; 025 026/** 027 * Represents a set of configuration values for an endpoint URI which can be created from a URI string 028 * or a base URI string and a set of parameter names and values. 029 * 030 * The configuration values can then be introspected, modified and converted back into a URI string 031 * or Endpoint. 032 * 033 * For @{link UriEndpointComponent} implementations created for Endpoints annotated with {@link org.apache.camel.spi.UriEndpoint} and the 034 * associated annotations then all the parameter values can be introspected and the parameter values are converted to their 035 * correct type. 036 * 037 * Other implementations keep all the types as String and there is no validation until you try to create 038 * an Endpoint from the values. 039 */ 040public interface ComponentConfiguration { 041 042 /** 043 * Returns the base URI without any query parameters added 044 */ 045 String getBaseUri(); 046 047 /** 048 * Sets the base URI without any query parameters added 049 */ 050 void setBaseUri(String baseUri); 051 052 /** 053 * Returns the current parameters of the configuration (usually encoded as <tt>?foo=bar&whatnot=something</tt> URI query parameters) 054 */ 055 Map<String, Object> getParameters(); 056 057 /** 058 * Sets the parameter values of this configuration 059 */ 060 void setParameters(Map<String, Object> propertyValues); 061 062 /** 063 * Returns the parameter value for the given name 064 * 065 * @param name the name of the URI query parameter to get 066 * @return the value of the parameter 067 */ 068 Object getParameter(String name); 069 070 /** 071 * Sets the parameter value of the given name 072 * 073 * @param name the name of the URI query parameter 074 * @param value the new value of the parameter 075 */ 076 void setParameter(String name, Object value); 077 078 /** 079 * Returns the URI string (without schema) with query parameters for the current 080 * configuration which can then be used to create an {@link org.apache.camel.Endpoint} 081 */ 082 String getUriString(); 083 084 /** 085 * Sets the URI string (without schema but with optional query parameters) 086 * which will update the {@link #getBaseUri()} and the {@link #getParameters()} values 087 * 088 * @param newValue the new URI string with query arguments 089 */ 090 void setUriString(String newValue) throws URISyntaxException; 091 092 /** 093 * Returns the URI query parameter configuration for the given parameter name or null if it does not exist 094 */ 095 ParameterConfiguration getParameterConfiguration(String name); 096 097 /** 098 * Returns the sorted map of all the parameter names to their {@link ParameterConfiguration} objects 099 */ 100 SortedMap<String, ParameterConfiguration> getParameterConfigurationMap(); 101 102 /** 103 * Converts the configuration into a URI and then looks up the endpoint in the {@link CamelContext} 104 * which typically results in a new {@link Endpoint} instance being created. 105 */ 106 Endpoint createEndpoint() throws Exception; 107 108 /** 109 * Applies the current set of parameters to the given endpoint instance. 110 * <p/> 111 * Note that typically parts of the URI are not injected into the Endpoint; this method purely 112 * 113 * @param endpoint the endpoint instance 114 */ 115 void configureEndpoint(Endpoint endpoint); 116 117 /** 118 * Gets the named URI parameter value on the given endpoint 119 * 120 * @param endpoint the endpoint instance 121 * @param name the name of the URI query parameter 122 * @return the value of the parameter 123 * @throws RuntimeCamelException if the parameter name does not exist on the endpoint 124 */ 125 Object getEndpointParameter(Endpoint endpoint, String name) throws RuntimeCamelException; 126 127 /** 128 * Sets the named URI query parameter value on the given endpoint 129 * 130 * @param endpoint the endpoint instance 131 * @param name the name of the URI query parameter 132 * @param value the new value of the URI query parameter 133 * @throws RuntimeCamelException 134 */ 135 void setEndpointParameter(Endpoint endpoint, String name, Object value) throws RuntimeCamelException; 136 137 /** 138 * A helper method for tools such as CLIs, IDEs or web tools that provides a completion list for Endpoint Paths 139 * rather like bash tab completion or Karaf attribute or option completion handlers. 140 * 141 * So given the current configuration data, return a list of completions given the specified text. 142 * e.g. return the files in a directory, the matching queues in a message broker, the database tables in a database component etc 143 * 144 * @param completionText the prefix text used to complete on (usually a matching bit of text) 145 * @return a list of matches 146 */ 147 List<String> completeEndpointPath(String completionText); 148 149 /** 150 * Creates a <a href="http://json-schema.org/">JSON schema</a> representation of the 151 * configuration parameters for this endpoint and the types and validation rules. 152 * 153 * @return a JSON string which represents the JSON schema for this endpoints configuration parameters. 154 */ 155 String createParameterJsonSchema(); 156} 157