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.model;
018
019import java.io.InputStream;
020import java.util.Collection;
021import java.util.List;
022import java.util.Map;
023
024import org.apache.camel.CamelContext;
025import org.apache.camel.model.rest.RestDefinition;
026
027/**
028 * Model level interface for the {@link CamelContext}
029 */
030public interface ModelCamelContext extends CamelContext {
031
032    /**
033     * Returns a list of the current route definitions
034     *
035     * @return list of the current route definitions
036     */
037    List<RouteDefinition> getRouteDefinitions();
038
039    /**
040     * Gets the route definition with the given id
041     *
042     * @param id id of the route
043     * @return the route definition or <tt>null</tt> if not found
044     */
045    RouteDefinition getRouteDefinition(String id);
046
047    /**
048     * Loads a collection of route definitions from the given {@link java.io.InputStream}.
049     *
050     * @param is input stream with the route(s) definition to add
051     * @return the route definitions
052     * @throws Exception if the route definitions could not be loaded for whatever reason
053     */
054    RoutesDefinition loadRoutesDefinition(InputStream is) throws Exception;
055
056    /**
057     * Adds a collection of route definitions to the context
058     * <p/>
059     * <b>Important: </b> Each route in the same {@link org.apache.camel.CamelContext} must have an <b>unique</b> route id.
060     * If you use the API from {@link org.apache.camel.CamelContext} or {@link org.apache.camel.model.ModelCamelContext} to add routes, then any
061     * new routes which has a route id that matches an old route, then the old route is replaced by the new route.
062     *
063     * @param routeDefinitions the route(s) definition to add
064     * @throws Exception if the route definitions could not be created for whatever reason
065     */
066    void addRouteDefinitions(Collection<RouteDefinition> routeDefinitions) throws Exception;
067
068    /**
069     * Add a route definition to the context
070     * <p/>
071     * <b>Important: </b> Each route in the same {@link org.apache.camel.CamelContext} must have an <b>unique</b> route id.
072     * If you use the API from {@link org.apache.camel.CamelContext} or {@link org.apache.camel.model.ModelCamelContext} to add routes, then any
073     * new routes which has a route id that matches an old route, then the old route is replaced by the new route.
074     *
075     * @param routeDefinition the route definition to add
076     * @throws Exception if the route definition could not be created for whatever reason
077     */
078    void addRouteDefinition(RouteDefinition routeDefinition) throws Exception;
079
080    /**
081     * Removes a collection of route definitions from the context - stopping any previously running
082     * routes if any of them are actively running
083     *
084     * @param routeDefinitions route(s) definitions to remove
085     * @throws Exception if the route definitions could not be removed for whatever reason
086     */
087    void removeRouteDefinitions(Collection<RouteDefinition> routeDefinitions) throws Exception;
088
089    /**
090     * Removes a route definition from the context - stopping any previously running
091     * routes if any of them are actively running
092     *
093     * @param routeDefinition route definition to remove
094     * @throws Exception if the route definition could not be removed for whatever reason
095     */
096    void removeRouteDefinition(RouteDefinition routeDefinition) throws Exception;
097
098    /**
099     * Returns a list of the current REST definitions
100     *
101     * @return list of the current REST definitions
102     */
103    List<RestDefinition> getRestDefinitions();
104
105    /**
106     * Adds a collection of rest definitions to the context
107     *
108     * @param restDefinitions the rest(s) definition to add
109     * @throws Exception if the rest definitions could not be created for whatever reason
110     */
111    void addRestDefinitions(Collection<RestDefinition> restDefinitions) throws Exception;
112
113    /**
114     * Starts the given route if it has been previously stopped
115     *
116     * @param route the route to start
117     * @throws Exception is thrown if the route could not be started for whatever reason
118     * @deprecated favor using {@link CamelContext#startRoute(String)}
119     */
120    @Deprecated
121    void startRoute(RouteDefinition route) throws Exception;
122    
123    /**
124     * Stops the given route.
125     *
126     * @param route the route to stop
127     * @throws Exception is thrown if the route could not be stopped for whatever reason
128     * @deprecated favor using {@link CamelContext#stopRoute(String)}
129     */
130    @Deprecated
131    void stopRoute(RouteDefinition route) throws Exception;
132
133    /**
134     * Sets the data formats that can be referenced in the routes.
135     *
136     * @param dataFormats the data formats
137     */
138    void setDataFormats(Map<String, DataFormatDefinition> dataFormats);
139
140    /**
141     * Gets the data formats that can be referenced in the routes.
142     *
143     * @return the data formats available
144     */
145    Map<String, DataFormatDefinition> getDataFormats();
146
147    /**
148     * Resolve a data format definition given its name
149     *
150     * @param name the data format definition name or a reference to it in the {@link org.apache.camel.spi.Registry}
151     * @return the resolved data format definition, or <tt>null</tt> if not found
152     */
153    DataFormatDefinition resolveDataFormatDefinition(String name);
154    
155}