1 package org.codehaus.ivory.plexus;
2
3 import javax.servlet.ServletContext;
4
5 import org.apache.avalon.framework.service.ServiceException;
6 import org.apache.avalon.framework.service.ServiceManager;
7 import org.apache.axis.AxisFault;
8 import org.apache.axis.AxisProperties;
9 import org.apache.axis.server.AxisServer;
10 import org.apache.axis.transport.http.AdminServlet;
11 import org.codehaus.ivory.AxisService;
12 import org.codehaus.ivory.DefaultAxisService;
13
14 /***
15 * An implementation of the Axis AdminServlet which retrieves the AxisEngine
16 * from the ServiceManager.
17 *
18 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
19 * @since Mar 8, 2003
20 */
21 public class PlexusAdminServlet
22 extends AdminServlet
23 {
24 ServiceManager manager;
25
26 AxisService axisService;
27
28 public PlexusAdminServlet()
29 {
30 }
31
32 /***
33 * Provide the AxisEngine to the base servlet class.
34 *
35 * @return AxisServer
36 * @see org.apache.axis.transport.http.AxisServletBase#getEngine()
37 */
38 public AxisServer getEngine() throws AxisFault
39 {
40 manager = getServiceManager();
41
42 try
43 {
44 axisService = ( AxisService ) manager.lookup( AxisService.ROLE );
45 }
46 catch (ServiceException e)
47 {
48 throw new AxisFault( "Could not find the AxisService.", e );
49 }
50
51 return axisService.getAxisServer();
52 }
53
54 /***
55 * Retrieve the ServiceBroker from the ServletContext. This presupposes
56 * that the installation is using Plexus.
57 *
58 * @return ServiceBroker
59 */
60 public ServiceManager getServiceManager()
61 {
62 return DefaultAxisService.getServiceManager();
63 }
64
65 public void destroy()
66 {
67 super.destroy();
68
69 if ( axisService != null )
70 manager.release( axisService );
71 }
72
73 protected String getOption(ServletContext context,
74 String param,
75 String dephault)
76 {
77 String value = AxisProperties.getProperty(param);
78
79 if (value == null) value = getInitParameter(param);
80
81 if (value == null) value = context.getInitParameter(param);
82 try
83 {
84 AxisServer engine = getEngine();
85 if (value == null && engine != null) value = (String) engine
86 .getOption(param);
87 }
88 catch (AxisFault axisFault)
89 {
90 }
91
92 return (value != null) ? value : dephault;
93 }
94 }