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    
021    import org.apache.camel.CamelContext;
022    import org.apache.camel.Endpoint;
023    import org.apache.camel.Exchange;
024    import org.apache.camel.Intercept;
025    import org.apache.camel.Processor;
026    import org.apache.camel.model.FromType;
027    import org.apache.camel.model.ProcessorType;
028    import org.apache.camel.model.RouteType;
029    import org.apache.camel.model.dataformat.DataFormatType;
030    
031    /**
032     * The context used to activate new routing rules
033     *
034     * @version $Revision: 1239 $
035     */
036    public interface RouteContext {
037    
038        /**
039         * Gets the endpoint
040         *
041         * @return the endpoint
042         */
043        Endpoint<? extends Exchange> getEndpoint();
044    
045        /**
046         * Gets the from type
047         *
048         * @return the from type
049         */
050        FromType getFrom();
051    
052        /**
053         * Get the route type
054         *
055         * @return the route type
056         */
057        RouteType 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(ProcessorType 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<? extends Exchange> 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<? extends Exchange> 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         * Lets complete the route creation, creating a single event driven route
103         * for the current from endpoint with any processors required
104         */
105        void commit();
106    
107        /**
108         * Adds an event driven processor
109         *
110         * @param processor the processor
111         */
112        void addEventDrivenProcessor(Processor processor);
113    
114        /**
115         * Intercepts with the given interceptor
116         *
117         * @param interceptor the interceptor
118         */
119        void intercept(Intercept interceptor);
120    
121        /**
122         * Creates a proceed processor
123         *
124         * @return the created proceed processor
125         */
126        Processor createProceedProcessor();
127    
128        /**
129         * This method retrieves the InterceptStrategy instances this route context.
130         *
131         * @return the strategy
132         */
133        List<InterceptStrategy> getInterceptStrategies();
134    
135        /**
136         * This method sets the InterceptStrategy instances on this route context.
137         *
138         * @param interceptStrategies the strategies
139         */
140        void setInterceptStrategies(List<InterceptStrategy> interceptStrategies);
141    
142        /**
143         * Adds a InterceptStrategy to this route context
144         *
145         * @param interceptStrategy the strategy
146         */
147        void addInterceptStrategy(InterceptStrategy interceptStrategy);
148    
149        /**
150         * This method retrieves the ErrorHandlerWrappingStrategy.
151         *
152         * @return the strategy
153         */
154        ErrorHandlerWrappingStrategy getErrorHandlerWrappingStrategy();
155        
156        /**
157         * This method sets the ErrorHandlerWrappingStrategy.
158         *
159         * @param strategy the strategy
160         */
161        void setErrorHandlerWrappingStrategy(ErrorHandlerWrappingStrategy strategy);
162    
163        /**
164         * If this flag is true, {@link ProcessorType#addRoutes(RouteContext, java.util.Collection)}
165         * will not add processor to addEventDrivenProcessor to the RouteContext and it
166         * will prevent from adding an EventDrivenRoute.
167         *
168         * @param value the flag
169         */
170        void setIsRouteAdded(boolean value);
171    
172        /**
173         * Returns the isRouteAdded flag
174         * 
175         * @return the flag
176         */
177        boolean isRouteAdded();
178        
179        /**
180         * Get a DataFormatType by ref name
181         *
182         * @param ref  the ref name to lookup
183         * @return the found object
184         */
185        DataFormatType getDataFormat(String ref);
186    }