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