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