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