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.spi;
018    
019    import java.util.List;
020    import java.util.Map;
021    
022    import org.apache.camel.CamelContext;
023    import org.apache.camel.Endpoint;
024    import org.apache.camel.Intercept;
025    import org.apache.camel.Processor;
026    import org.apache.camel.model.DataFormatDefinition;
027    import org.apache.camel.model.FromDefinition;
028    import org.apache.camel.model.ProcessorDefinition;
029    import org.apache.camel.model.RouteDefinition;
030    
031    /**
032     * The context used to activate new routing rules
033     *
034     * @version $Revision: 782535 $
035     */
036    public interface RouteContext {
037    
038        /**
039         * Gets the endpoint
040         *
041         * @return the endpoint
042         */
043        Endpoint getEndpoint();
044    
045        /**
046         * Gets the from type
047         *
048         * @return the from type
049         */
050        FromDefinition getFrom();
051    
052        /**
053         * Get the route type
054         *
055         * @return the route type
056         */
057        RouteDefinition getRoute();
058    
059        /**
060         * Gets the camel context
061         *
062         * @return the camel context
063         */
064        CamelContext getCamelContext();
065    
066        /**
067         * Creates a processor
068         *
069         * @param node  the node
070         * @return the created processor
071         * @throws Exception can be thrown
072         */
073        Processor createProcessor(ProcessorDefinition node) throws Exception;
074    
075        /**
076         * Resolves an endpoint from the URI
077         *
078         * @param uri the URI
079         * @return the resolved endpoint
080         */
081        Endpoint resolveEndpoint(String uri);
082    
083        /**
084         * Resolves an endpoint from either a URI or a named reference
085         *
086         * @param uri  the URI or
087         * @param ref  the named reference
088         * @return the resolved endpoint
089         */
090        Endpoint resolveEndpoint(String uri, String ref);
091    
092        /**
093         * lookup an object by name and type
094         *
095         * @param name  the name to lookup
096         * @param type  the expected type
097         * @return the found object
098         */
099        <T> T lookup(String name, Class<T> type);
100    
101        /**
102         * lookup objects by type
103         *
104         * @param type the expected type
105         * @return the found objects with the name as the key in the map. Returns an empty map if none found.
106         */
107        <T> Map<String, T> lookupByType(Class<T> type);
108    
109        /**
110         * Lets complete the route creation, creating a single event driven route
111         * for the current from endpoint with any processors required
112         */
113        void commit();
114    
115        /**
116         * Adds an event driven processor
117         *
118         * @param processor the processor
119         */
120        void addEventDrivenProcessor(Processor processor);
121    
122        /**
123         * This method retrieves the InterceptStrategy instances this route context.
124         *
125         * @return the strategy
126         */
127        List<InterceptStrategy> getInterceptStrategies();
128    
129        /**
130         * This method sets the InterceptStrategy instances on this route context.
131         *
132         * @param interceptStrategies the strategies
133         */
134        void setInterceptStrategies(List<InterceptStrategy> interceptStrategies);
135    
136        /**
137         * Adds a InterceptStrategy to this route context
138         *
139         * @param interceptStrategy the strategy
140         */
141        void addInterceptStrategy(InterceptStrategy interceptStrategy);
142    
143        /**
144         * If this flag is true, {@link ProcessorDefinition#addRoutes(RouteContext, java.util.Collection)}
145         * will not add processor to addEventDrivenProcessor to the RouteContext and it
146         * will prevent from adding an EventDrivenRoute.
147         *
148         * @param value the flag
149         */
150        void setIsRouteAdded(boolean value);
151    
152        /**
153         * Returns the isRouteAdded flag
154         * 
155         * @return the flag
156         */
157        boolean isRouteAdded();
158        
159        /**
160         * Get a DataFormatType by ref name
161         *
162         * @param ref  the ref name to lookup
163         * @return the found object
164         */
165        DataFormatDefinition getDataFormat(String ref);
166    }