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.runtimecatalog;
018
019import java.net.URISyntaxException;
020import java.util.Map;
021
022import org.apache.camel.StaticService;
023
024/**
025 * Runtime based CamelCatalog which are included in camel-core that can provided limit CamelCatalog capabilities
026 */
027public interface RuntimeCamelCatalog extends StaticService {
028
029    // configuration
030
031    /**
032     * Gets the {@link JSonSchemaResolver}.
033     */
034    JSonSchemaResolver getJSonSchemaResolver();
035
036    /**
037     * To use a custom {@link JSonSchemaResolver}
038     */
039    void setJSonSchemaResolver(JSonSchemaResolver resolver);
040
041    // functions
042
043    /**
044     * Returns the component information as JSon format.
045     *
046     * @param name the component name
047     * @return component details in JSon
048     */
049    String componentJSonSchema(String name);
050
051    /**
052     * Returns the data format information as JSon format.
053     *
054     * @param name the data format name
055     * @return data format details in JSon
056     */
057    String dataFormatJSonSchema(String name);
058
059    /**
060     * Returns the language information as JSon format.
061     *
062     * @param name the language name
063     * @return language details in JSon
064     */
065    String languageJSonSchema(String name);
066
067    /**
068     * Returns the model information as JSon format.
069     *
070     * @param name the model name
071     * @return model details in JSon
072     */
073    String modelJSonSchema(String name);
074
075    /**
076     * Parses the endpoint uri and constructs a key/value properties of each option
077     *
078     * @param uri  the endpoint uri
079     * @return properties as key value pairs of each endpoint option
080     */
081    Map<String, String> endpointProperties(String uri) throws URISyntaxException;
082
083    /**
084     * Parses the endpoint uri and constructs a key/value properties of only the lenient properties (eg custom options)
085     * <p/>
086     * For example using the HTTP components to provide query parameters in the endpoint uri.
087     *
088     * @param uri  the endpoint uri
089     * @return properties as key value pairs of each lenient properties
090     */
091    Map<String, String> endpointLenientProperties(String uri) throws URISyntaxException;
092
093    /**
094     * Validates the pattern whether its a valid time pattern.
095     *
096     * @param pattern  the pattern such as 5000, 5s, 5sec, 4min, 4m30s, 1h, etc.
097     * @return <tt>true</tt> if valid, <tt>false</tt> if invalid
098     */
099    boolean validateTimePattern(String pattern);
100
101    /**
102     * Validates the properties for the given scheme against component and endpoint
103     *
104     * @param scheme  the endpoint scheme
105     * @param properties  the endpoint properties
106     * @return validation result
107     */
108    EndpointValidationResult validateProperties(String scheme, Map<String, String> properties);
109
110    /**
111     * Parses and validates the endpoint uri and constructs a key/value properties of each option.
112     *
113     * @param uri  the endpoint uri
114     * @return validation result
115     */
116    EndpointValidationResult validateEndpointProperties(String uri);
117
118    /**
119     * Parses and validates the endpoint uri and constructs a key/value properties of each option.
120     * <p/>
121     * The option ignoreLenientProperties can be used to ignore components that uses lenient properties.
122     * When this is true, then the uri validation is stricter but would fail on properties that are not part of the component
123     * but in the uri because of using lenient properties.
124     * For example using the HTTP components to provide query parameters in the endpoint uri.
125     *
126     * @param uri  the endpoint uri
127     * @param ignoreLenientProperties  whether to ignore components that uses lenient properties.
128     * @return validation result
129     */
130    EndpointValidationResult validateEndpointProperties(String uri, boolean ignoreLenientProperties);
131
132    /**
133     * Parses and validates the endpoint uri and constructs a key/value properties of each option.
134     * <p/>
135     * The option ignoreLenientProperties can be used to ignore components that uses lenient properties.
136     * When this is true, then the uri validation is stricter but would fail on properties that are not part of the component
137     * but in the uri because of using lenient properties.
138     * For example using the HTTP components to provide query parameters in the endpoint uri.
139     *
140     * @param uri  the endpoint uri
141     * @param ignoreLenientProperties  whether to ignore components that uses lenient properties.
142     * @param consumerOnly whether the endpoint is only used as a consumer
143     * @param producerOnly whether the endpoint is only used as a producer
144     * @return validation result
145     */
146    EndpointValidationResult validateEndpointProperties(String uri, boolean ignoreLenientProperties, boolean consumerOnly, boolean producerOnly);
147
148    /**
149     * Parses and validates the language as a predicate
150     * <p/>
151     * <b>Important:</b> This requires having <tt>camel-core</tt> and the language dependencies on the classpath
152     *
153     * @param classLoader a custom classloader to use for loading the language from the classpath, or <tt>null</tt> for using default classloader
154     * @param language the name of the language
155     * @param text  the predicate text
156     * @return validation result
157     */
158    LanguageValidationResult validateLanguagePredicate(ClassLoader classLoader, String language, String text);
159
160    /**
161     * Parses and validates the language as an expression
162     * <p/>
163     * <b>Important:</b> This requires having <tt>camel-core</tt> and the language dependencies on the classpath
164     *
165     * @param classLoader a custom classloader to use for loading the language from the classpath, or <tt>null</tt> for using default classloader
166     * @param language the name of the language
167     * @param text  the expression text
168     * @return validation result
169     */
170    LanguageValidationResult validateLanguageExpression(ClassLoader classLoader, String language, String text);
171
172    /**
173     * Returns the component name from the given endpoint uri
174     *
175     * @param uri  the endpoint uri
176     * @return the component name (aka scheme), or <tt>null</tt> if not possible to determine
177     */
178    String endpointComponentName(String uri);
179
180    /**
181     * Creates an endpoint uri in Java style from the information from the properties
182     *
183     * @param scheme the endpoint schema
184     * @param properties the properties as key value pairs
185     * @param encode whether to URL encode the returned uri or not
186     * @return the constructed endpoint uri
187     * @throws java.net.URISyntaxException is thrown if there is encoding error
188     */
189    String asEndpointUri(String scheme, Map<String, String> properties, boolean encode) throws URISyntaxException;
190
191    /**
192     * Creates an endpoint uri in XML style (eg escape & as &ampl;) from the information from the properties
193     *
194     * @param scheme the endpoint schema
195     * @param properties the properties as key value pairs
196     * @param encode whether to URL encode the returned uri or not
197     * @return the constructed endpoint uri
198     * @throws java.net.URISyntaxException is thrown if there is encoding error
199     */
200    String asEndpointUriXml(String scheme, Map<String, String> properties, boolean encode) throws URISyntaxException;
201
202}