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.HashMap;
020    import java.util.Map;
021    import javax.xml.bind.JAXBException;
022    
023    import org.apache.camel.impl.DefaultCamelContext;
024    import org.apache.camel.impl.MainSupport;
025    import org.apache.camel.view.ModelFileGenerator;
026    
027    /**
028     * A command line tool for booting up a CamelContext
029     *
030     * @version 
031     */
032    public class Main extends MainSupport {
033        protected static Main instance;
034    
035        public Main() {
036        }
037    
038        public static void main(String... args) throws Exception {
039            Main main = new Main();
040            instance = main;
041            main.enableHangupSupport();
042            main.run(args);
043        }
044    
045        /**
046         * Returns the currently executing main
047         *
048         * @return the current running instance
049         */
050        public static Main getInstance() {
051            return instance;
052        }
053        
054        // Implementation methods
055        // -------------------------------------------------------------------------
056    
057        @Override
058        protected void doStart() throws Exception {
059            super.doStart();
060            postProcessContext();
061            getCamelContexts().get(0).start();
062        }
063    
064        protected void doStop() throws Exception {
065            super.doStop();
066            getCamelContexts().get(0).stop();
067        }
068    
069        protected ProducerTemplate findOrCreateCamelTemplate() {
070            return getCamelContexts().get(0).createProducerTemplate();
071        }
072    
073        protected Map<String, CamelContext> getCamelContextMap() {
074            Map<String, CamelContext> answer = new HashMap<String, CamelContext>();
075            answer.put("camel-1", new DefaultCamelContext());
076            return answer;
077        }
078    
079        protected ModelFileGenerator createModelFileGenerator() throws JAXBException {
080            return null;
081        }
082    }