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 simple expression.
150     * <p/>
151     * <b>Important:</b> This requires having <tt>camel-core</tt> on the classpath
152     *
153     * @param simple  the simple expression
154     * @return validation result
155     * @deprecated use {@link #validateSimpleExpression(ClassLoader, String)}
156     */
157    @Deprecated
158    SimpleValidationResult validateSimpleExpression(String simple);
159
160    /**
161     * Parses and validates the simple expression.
162     * <p/>
163     * <b>Important:</b> This requires having <tt>camel-core</tt> 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 simple  the simple expression
167     * @return validation result
168     */
169    SimpleValidationResult validateSimpleExpression(ClassLoader classLoader, String simple);
170
171    /**
172     * Parses and validates the simple predicate
173     * <p/>
174     * <b>Important:</b> This requires having <tt>camel-core</tt> on the classpath
175     *
176     * @param simple  the simple predicate
177     * @return validation result
178     * @deprecated use {@link #validateSimplePredicate(ClassLoader, String)}
179     */
180    @Deprecated
181    SimpleValidationResult validateSimplePredicate(String simple);
182
183    /**
184     * Parses and validates the simple predicate
185     * <p/>
186     * <b>Important:</b> This requires having <tt>camel-core</tt> on the classpath
187     *
188     * @param classLoader a custom classloader to use for loading the language from the classpath, or <tt>null</tt> for using default classloader
189     * @param simple  the simple predicate
190     * @return validation result
191     */
192    SimpleValidationResult validateSimplePredicate(ClassLoader classLoader, String simple);
193
194    /**
195     * Parses and validates the language as a predicate
196     * <p/>
197     * <b>Important:</b> This requires having <tt>camel-core</tt> and the language dependencies on the classpath
198     *
199     * @param classLoader a custom classloader to use for loading the language from the classpath, or <tt>null</tt> for using default classloader
200     * @param language the name of the language
201     * @param text  the predicate text
202     * @return validation result
203     */
204    LanguageValidationResult validateLanguagePredicate(ClassLoader classLoader, String language, String text);
205
206    /**
207     * Parses and validates the language as an expression
208     * <p/>
209     * <b>Important:</b> This requires having <tt>camel-core</tt> and the language dependencies on the classpath
210     *
211     * @param classLoader a custom classloader to use for loading the language from the classpath, or <tt>null</tt> for using default classloader
212     * @param language the name of the language
213     * @param text  the expression text
214     * @return validation result
215     */
216    LanguageValidationResult validateLanguageExpression(ClassLoader classLoader, String language, String text);
217
218    /**
219     * Returns the component name from the given endpoint uri
220     *
221     * @param uri  the endpoint uri
222     * @return the component name (aka scheme), or <tt>null</tt> if not possible to determine
223     */
224    String endpointComponentName(String uri);
225
226    /**
227     * Creates an endpoint uri in Java style from the information from the properties
228     *
229     * @param scheme the endpoint schema
230     * @param properties the properties as key value pairs
231     * @param encode whether to URL encode the returned uri or not
232     * @return the constructed endpoint uri
233     * @throws java.net.URISyntaxException is thrown if there is encoding error
234     */
235    String asEndpointUri(String scheme, Map<String, String> properties, boolean encode) throws URISyntaxException;
236
237    /**
238     * Creates an endpoint uri in XML style (eg escape & as &ampl;) from the information from the properties
239     *
240     * @param scheme the endpoint schema
241     * @param properties the properties as key value pairs
242     * @param encode whether to URL encode the returned uri or not
243     * @return the constructed endpoint uri
244     * @throws java.net.URISyntaxException is thrown if there is encoding error
245     */
246    String asEndpointUriXml(String scheme, Map<String, String> properties, boolean encode) throws URISyntaxException;
247
248}