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