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.spring.xml;
019
020 import java.util.ArrayList;
021
022 import org.apache.camel.builder.RouteBuilder;
023 import org.springframework.beans.BeansException;
024 import org.springframework.beans.factory.BeanFactory;
025 import org.springframework.beans.factory.BeanFactoryAware;
026 import org.springframework.beans.factory.FactoryBean;
027
028 /**
029 * A {@link FactoryBean} which creates a RouteBuilder by parsing an XML file
030 *
031 * @version $Revision: 521369 $
032 */
033 public class RouteBuilderFactory implements FactoryBean, BeanFactoryAware {
034 private ArrayList<BuilderStatement> routes;
035 private boolean singleton;
036 private BeanFactory beanFactory;
037
038 class SpringRouteBuilder extends RouteBuilder {
039 private ArrayList<BuilderStatement> routes;
040 private BeanFactory beanFactory;
041
042 @Override
043 public void configure() {
044 for (BuilderStatement routeFactory : routes) {
045 routeFactory.create(beanFactory, this);
046 }
047 }
048
049 public ArrayList<BuilderStatement> getRoutes() {
050 return routes;
051 }
052 public void setRoutes(ArrayList<BuilderStatement> routes) {
053 this.routes = routes;
054 }
055
056 public void setBeanFactory(BeanFactory beanFactory) {
057 this.beanFactory = beanFactory;
058 }
059 }
060
061 public Object getObject() throws Exception {
062 SpringRouteBuilder builder = new SpringRouteBuilder();
063 builder.setBeanFactory(beanFactory);
064 builder.setRoutes(routes);
065 return builder;
066 }
067
068 public Class getObjectType() {
069 return SpringRouteBuilder.class;
070 }
071
072 public boolean isSingleton() {
073 return singleton;
074 }
075 public void setSingleton(boolean singleton) {
076 this.singleton = singleton;
077 }
078
079 public ArrayList<BuilderStatement> getRoutes() {
080 return routes;
081 }
082 public void setRoutes(ArrayList<BuilderStatement> routes) {
083 this.routes = routes;
084 }
085
086 public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
087 this.beanFactory = beanFactory;
088 }
089
090 }