001    /**
002     *
003     * Licensed to the Apache Software Foundation (ASF) under one or more
004     * contributor license agreements.  See the NOTICE file distributed with
005     * this work for additional information regarding copyright ownership.
006     * The ASF licenses this file to You under the Apache License, Version 2.0
007     * (the "License"); you may not use this file except in compliance with
008     * the License.  You may obtain a copy of the License at
009     *
010     * http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing, software
013     * distributed under the License is distributed on an "AS IS" BASIS,
014     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015     * See the License for the specific language governing permissions and
016     * limitations under the License.
017     */
018    package org.apache.camel;
019    
020    import java.util.ArrayList;
021    import java.util.HashMap;
022    import java.util.List;
023    import java.util.Map;
024    
025    /**
026     * A <a href="http://activemq.apache.org/camel/routes.html">Route</a>
027     * defines the processing used on an inbound message exchange
028     * from a specific {@see Endpoint} within a {@link CamelContext}
029     *
030     * @version $Revision: 541693 $
031     */
032    public abstract class Route<E extends Exchange> {
033        private final Map<String, Object> properties = new HashMap<String, Object>(16);
034        private Endpoint<E> endpoint;
035        private List<Service> services = new ArrayList<Service>();
036    
037        public Route(Endpoint<E> endpoint) {
038            this.endpoint = endpoint;
039        }
040    
041        public Endpoint<E> getEndpoint() {
042            return endpoint;
043        }
044    
045        public void setEndpoint(Endpoint<E> endpoint) {
046            this.endpoint = endpoint;
047        }
048    
049        /**
050         * This property map is used to associate information about
051         * the route.
052         *
053         * @return
054         */
055        public Map<String, Object> getProperties() {
056            return properties;
057        }
058    
059        public List<Service> getServicesForRoute() throws Exception {
060            List<Service> servicesForRoute = new ArrayList<Service>(getServices());
061            addServices(servicesForRoute);
062            return servicesForRoute;
063        }
064    
065        /**
066         * Returns the additional services required for this particular route
067         */
068        public List<Service> getServices() throws Exception {
069            return services;
070        }
071    
072        public void setServices(List<Service> services) {
073            this.services = services;
074        }
075    
076        /**
077         * Strategy method to allow derived classes to lazily load services for the route
078         */
079        protected abstract void addServices(List<Service> services) throws Exception;
080    }