KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > Main


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */

17 package org.apache.servicemix;
18
19 import java.io.File JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.apache.servicemix.jbi.config.spring.XBeanProcessor;
24 import org.apache.servicemix.jbi.container.SpringJBIContainer;
25 import org.springframework.beans.factory.DisposableBean;
26 import org.springframework.context.ApplicationContext;
27 import org.apache.xbean.server.repository.FileSystemRepository;
28 import org.apache.xbean.server.spring.configuration.ClassLoaderXmlPreprocessor;
29 import org.apache.xbean.spring.context.ClassPathXmlApplicationContext;
30 import org.apache.xbean.spring.context.FileSystemXmlApplicationContext;
31
32 /**
33  * A simple stand alone application which runs ServiceMix from the command line.
34  *
35  * @version $Revision: 438724 $
36  */

37 public class Main {
38
39     public static void main(String JavaDoc args[]) {
40         try {
41             String JavaDoc version = "";
42             Package JavaDoc p = Package.getPackage("org.apache.servicemix");
43             if (p != null) {
44                 version = ": " + p.getImplementationVersion();
45             }
46             System.out.println("Starting Apache ServiceMix ESB" + version);
47             System.out.println();
48
49             ApplicationContext context = null;
50             if (args.length <= 0) {
51                 System.out.println("Loading Apache ServiceMix from servicemix.xml on the CLASSPATH");
52                 context = new ClassPathXmlApplicationContext("servicemix.xml");
53             }
54             else {
55                 String JavaDoc file = args[0];
56
57                 if (file.equals("-?") || file.equals("?") || file.equals("--help") || file.equals("-h")) {
58                     System.out.println("Usage: Main [-v1] [xmlConfigFile]");
59                     System.out.println("If an XML config file is not specified then servicemix.xml is used from the CLASSPATH");
60                     return;
61                 }
62                 
63                 List JavaDoc processors = new ArrayList JavaDoc();
64                 processors.add(new ClassLoaderXmlPreprocessor(new FileSystemRepository(new File JavaDoc("."))));
65                 if (file.equals("-v1")) {
66                     
67                     processors.add(new XBeanProcessor());
68                     if (args.length <= 1) {
69                         System.out.println("Loading Apache ServiceMix (compatible 1.x) from servicemix.xml on the CLASSPATH");
70                         context = new ClassPathXmlApplicationContext("servicemix.xml", processors);
71                     }
72                     else {
73                         file = args[1];
74                         System.out.println("Loading Apache ServiceMix (compatible 1.x) from file: " + file);
75                         context = new FileSystemXmlApplicationContext(file, processors);
76                     }
77                 }
78                 else {
79                     System.out.println("Loading Apache ServiceMix from file: " + file);
80                     context = new FileSystemXmlApplicationContext(file, processors);
81                 }
82             }
83             SpringJBIContainer container = (SpringJBIContainer) context.getBean("jbi");
84             Object JavaDoc lock = new Object JavaDoc();
85             container.setShutdownLock(lock);
86
87             // lets wait until we're killed.
88
synchronized (lock) {
89                 lock.wait();
90             }
91             if (context instanceof DisposableBean) {
92                 ((DisposableBean) context).destroy();
93             }
94         }
95         catch (Exception JavaDoc e) {
96             System.out.println("Caught: " + e);
97             e.printStackTrace();
98         }
99     }
100 }
101
Popular Tags