KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > webservice > EngineConfigurationFinder


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.webservice;
8
9 // $Id: EngineConfigurationFinder.java,v 1.6.4.2 2005/03/02 14:32:35 tdiesler Exp $
10

11 import org.jboss.axis.EngineConfiguration;
12 import org.jboss.axis.configuration.FileProvider;
13 import org.jboss.logging.Logger;
14
15 import java.io.File JavaDoc;
16 import java.io.IOException JavaDoc;
17 import java.io.InputStream JavaDoc;
18 import java.net.MalformedURLException JavaDoc;
19 import java.net.URL JavaDoc;
20
21 /**
22  * Discover the Axis EngineConfiguration.
23  *
24  * @author Thomas.Diesler@jboss.org
25  * @since 30-April-2004
26  */

27 public final class EngineConfigurationFinder
28 {
29    // provide logging
30
private static final Logger log = Logger.getLogger(EngineConfigurationFinder.class);
31
32    public static final String JavaDoc DEFAULT_SERVER_CONFIG = "META-INF/axis-server-config.xml";
33    public static final String JavaDoc DEFAULT_CLIENT_CONFIG = "META-INF/axis-client-config.xml";
34
35    /**
36     * Get the AxisClient EngineConfiguration.
37     * <p/>
38     * 1. Read the config location from the system property {@link Constants.CLIENT_CONFIG}
39     * 2. If not set, fall back to 'META-INF/axis-client-config.xml'
40     * 3. Try to access the config location as URL
41     * 4. Try to access the config location as File
42     * 5. Try to access the config location as Resource
43     *
44     * @return The client EngineConfiguration, or null
45     */

46    public static EngineConfiguration getClientEngineConfiguration()
47    {
48       String JavaDoc configLocation = System.getProperty(Constants.CLIENT_CONFIG);
49       if (configLocation == null)
50          configLocation = DEFAULT_CLIENT_CONFIG;
51
52       return getEngineConfiguration(configLocation);
53    }
54
55    /**
56     * Get the AxisClient EngineConfiguration.
57     * <p/>
58     * 1. Read the config location from the system property {@link org.jboss.webservice.Constants.SERVER_CONFIG}
59     * 2. If not set, fall back to 'META-INF/axis-server-config.xml'
60     * 3. Try to access the config location as URL
61     * 4. Try to access the config location as File
62     * 5. Try to access the config location as Resource
63     *
64     * @return The client EngineConfiguration, or null
65     */

66    public static EngineConfiguration getServerEngineConfiguration()
67    {
68       String JavaDoc configLocation = System.getProperty(Constants.SERVER_CONFIG);
69       if (configLocation == null)
70          configLocation = DEFAULT_SERVER_CONFIG;
71
72       return getEngineConfiguration(configLocation);
73
74
75    }
76
77    /**
78     * Do the discovery in the way described above.
79     */

80    private static EngineConfiguration getEngineConfiguration(String JavaDoc configLocation)
81    {
82       EngineConfiguration config = null;
83
84       // Try to load it from a URL
85
try
86       {
87          URL JavaDoc url = new URL JavaDoc(configLocation);
88          InputStream JavaDoc is = url.openStream();
89          if (is != null)
90             config = new FileProvider(is);
91       }
92       catch (MalformedURLException JavaDoc e)
93       {
94          // its not a url
95
}
96       catch (IOException JavaDoc e)
97       {
98          // there is nothing at that url
99
}
100
101       // Try to load it from a file
102
if (config == null && new File JavaDoc(configLocation).exists())
103       {
104          config = new FileProvider(configLocation);
105       }
106
107
108       // Try to load it from the class loader that loaded this class
109
if (config == null)
110       {
111          ClassLoader JavaDoc cl = EngineConfigurationFinder.class.getClassLoader();
112          URL JavaDoc configURL = cl.getResource(configLocation);
113          if (configURL != null)
114          {
115             log.debug("Found config at: " + configURL);
116             try
117             {
118                InputStream JavaDoc is = configURL.openStream();
119                if (is != null)
120                   config = new FileProvider(is);
121             }
122             catch (IOException JavaDoc e)
123             {
124                log.debug("Failed to open config", e);
125             }
126          }
127       }
128
129       if (config == null)
130          log.warn("Cannot find engine configuration at: " + configLocation);
131
132       return config;
133    }
134 }
135
Popular Tags