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 {@link Endpoint} within a {@link CamelContext} 028 * 029 * @version $Revision: 701021 $ 030 */ 031 public class Route<E extends Exchange> { 032 public static final String ID_PROPERTY = "id"; 033 public static final String PARENT_PROPERTY = "parent"; 034 public static final String GROUP_PROPERTY = "group"; 035 036 private final Map<String, Object> properties = new HashMap<String, Object>(16); 037 private Endpoint<E> endpoint; 038 private List<Service> services = new ArrayList<Service>(); 039 040 public Route(Endpoint<E> endpoint) { 041 this.endpoint = endpoint; 042 } 043 044 public Route(Endpoint<E> endpoint, Service... services) { 045 this(endpoint); 046 for (Service service : services) { 047 addService(service); 048 } 049 } 050 051 @Override 052 public String toString() { 053 return "Route"; 054 } 055 056 public Endpoint<E> getEndpoint() { 057 return endpoint; 058 } 059 060 public void setEndpoint(Endpoint<E> endpoint) { 061 this.endpoint = endpoint; 062 } 063 064 /** 065 * This property map is used to associate information about 066 * the route. 067 */ 068 public Map<String, Object> getProperties() { 069 return properties; 070 } 071 072 public List<Service> getServicesForRoute() throws Exception { 073 List<Service> servicesForRoute = new ArrayList<Service>(getServices()); 074 addServices(servicesForRoute); 075 return servicesForRoute; 076 } 077 078 /** 079 * Returns the additional services required for this particular route 080 */ 081 public List<Service> getServices() { 082 return services; 083 } 084 085 public void setServices(List<Service> services) { 086 this.services = services; 087 } 088 089 public void addService(Service service) { 090 getServices().add(service); 091 } 092 093 /** 094 * Strategy method to allow derived classes to lazily load services for the route 095 */ 096 protected void addServices(List<Service> services) throws Exception { 097 } 098 }