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;
018
019 import java.util.ArrayList;
020 import java.util.HashMap;
021 import java.util.List;
022 import java.util.Map;
023
024 /**
025 * A <a href="http://activemq.apache.org/camel/routes.html">Route</a>
026 * defines the processing used on an inbound message exchange
027 * from a specific {@see Endpoint} within a {@link CamelContext}
028 *
029 * @version $Revision: 563607 $
030 */
031 public class Route<E extends Exchange> {
032 private final Map<String, Object> properties = new HashMap<String, Object>(16);
033 private Endpoint<E> endpoint;
034 private List<Service> services = new ArrayList<Service>();
035
036 public Route(Endpoint<E> endpoint) {
037 this.endpoint = endpoint;
038 }
039
040 public Route(Endpoint<E> endpoint, Service... services) {
041 this(endpoint);
042 for (Service service : services) {
043 addService(service);
044 }
045 }
046
047 @Override
048 public String toString() {
049 return "Route";
050 }
051
052 public Endpoint<E> getEndpoint() {
053 return endpoint;
054 }
055
056 public void setEndpoint(Endpoint<E> endpoint) {
057 this.endpoint = endpoint;
058 }
059
060 /**
061 * This property map is used to associate information about
062 * the route.
063 *
064 * @return
065 */
066 public Map<String, Object> getProperties() {
067 return properties;
068 }
069
070 public List<Service> getServicesForRoute() throws Exception {
071 List<Service> servicesForRoute = new ArrayList<Service>(getServices());
072 addServices(servicesForRoute);
073 return servicesForRoute;
074 }
075
076 /**
077 * Returns the additional services required for this particular route
078 */
079 public List<Service> getServices() {
080 return services;
081 }
082
083 public void setServices(List<Service> services) {
084 this.services = services;
085 }
086
087 public void addService(Service service) {
088 getServices().add(service);
089 }
090
091 /**
092 * Strategy method to allow derived classes to lazily load services for the route
093 */
094 protected void addServices(List<Service> services) throws Exception {
095 }
096 }