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.impl;
018    
019    import java.util.ArrayList;
020    import java.util.Collection;
021    import java.util.List;
022    import java.util.Map;
023    
024    import org.apache.camel.Consumer;
025    import org.apache.camel.Route;
026    import org.apache.camel.Service;
027    import org.apache.camel.spi.RouteStartupOrder;
028    
029    /**
030     * Default implementation of {@link org.apache.camel.spi.RouteStartupOrder}.
031     *
032     * @version 
033     */
034    public class DefaultRouteStartupOrder implements RouteStartupOrder {
035    
036        private final int startupOrder;
037        private final Route route;
038        private final RouteService routeService;
039    
040        public DefaultRouteStartupOrder(int startupOrder, Route route, RouteService routeService) {
041            this.startupOrder = startupOrder;
042            this.route = route;
043            this.routeService = routeService;
044        }
045    
046        public int getStartupOrder() {
047            return startupOrder;
048        }
049    
050        public Route getRoute() {
051            return route;
052        }
053    
054        public List<Consumer> getInputs() {
055            List<Consumer> answer = new ArrayList<Consumer>();
056            Map<Route, Consumer> inputs = routeService.getInputs();
057            for (Consumer consumer : inputs.values()) {
058                answer.add(consumer);
059            }
060            return answer;
061        }
062    
063        public List<Service> getServices() {
064            List<Service> answer = new ArrayList<Service>();
065            Collection<Route> routes = routeService.getRoutes();
066            for (Route route : routes) {
067                answer.addAll(route.getServices());
068            }
069            return answer;
070        }
071    
072        public RouteService getRouteService() {
073            return routeService;
074        }
075    
076        @Override
077        public String toString() {
078            return "Route " + route.getId() + " starts in order " + startupOrder;
079        }
080    }