1 package org.codehaus.xfire.plexus.simple;
2
3 import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
4 import org.codehaus.plexus.configuration.PlexusConfiguration;
5 import org.codehaus.plexus.configuration.PlexusConfigurationException;
6 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Configurable;
7 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
8 import org.codehaus.plexus.personality.plexus.lifecycle.phase.ServiceLocator;
9 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Serviceable;
10 import org.codehaus.xfire.SOAPConstants;
11 import org.codehaus.xfire.XFireRuntimeException;
12 import org.codehaus.xfire.fault.FaultHandler;
13 import org.codehaus.xfire.handler.Handler;
14 import org.codehaus.xfire.service.ServiceRegistry;
15 import org.codehaus.xfire.service.SimpleService;
16
17 /***
18 * MockService
19 *
20 * @author <a href="mailto:dan@envoisolutions.com">Dan Diephouse</a>
21 */
22 public class PlexusSimpleService
23 extends SimpleService
24 implements Configurable, Initializable, Serviceable
25 {
26 private String faultHandlerHint;
27
28 private ServiceLocator manager;
29
30 private Handler serviceHandler;
31
32 /***
33 * Registers this service with the service registry.
34 *
35 * @see org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable#initialize()
36 */
37 public void initialize() throws Exception
38 {
39 getServiceRegistry().register( this );
40 }
41
42 public FaultHandler getFaultHandler()
43 {
44 try
45 {
46 return (FaultHandler) getServiceLocator().lookup( FaultHandler.ROLE, faultHandlerHint );
47 }
48 catch (ComponentLookupException e)
49 {
50 throw new XFireRuntimeException( "Couldn't find service provider!", e );
51 }
52 }
53
54 public String getFaultHandlerHint()
55 {
56 return faultHandlerHint;
57 }
58
59 public void setFaultHandlerHint(String faultHandlerHint)
60 {
61 this.faultHandlerHint = faultHandlerHint;
62 }
63
64 public void configure(PlexusConfiguration config)
65 throws PlexusConfigurationException
66 {
67 setName( config.getChild("name").getValue() );
68
69 setDefaultNamespace( config.getChild( "namespace" ).getValue("") );
70
71 setWSDLURL( config.getChild("wsdlURL").getValue("") );
72
73 setUse( config.getChild("use").getValue("literal") );
74
75 setStyle( config.getChild("style").getValue("wrapped") );
76
77 String soapNS = config.getChild( "soapVersion" ).getValue("1.1");
78
79 if ( soapNS.equals("1.1") )
80 setSoapVersion( SOAPConstants.SOAP11_ENVELOPE_NS );
81 else if ( soapNS.equals("1.2") )
82 setSoapVersion( SOAPConstants.SOAP12_ENVELOPE_NS );
83 else
84 throw new PlexusConfigurationException("Invalid soap version. Must be 1.1 or 1.2.");
85
86 setFaultHandlerHint( config.getChild( "faultHandler" ).getValue(soapNS) );
87 }
88
89 protected ServiceRegistry getServiceRegistry()
90 {
91 ServiceRegistry registry = null;
92
93 try
94 {
95 registry = (ServiceRegistry) getServiceLocator().lookup( ServiceRegistry.ROLE );
96 }
97 catch (ComponentLookupException e)
98 {
99 throw new RuntimeException( "Couldn't find the ServiceRegistry!", e );
100 }
101
102 return registry;
103 }
104
105 public void service( ServiceLocator manager )
106 {
107 this.manager = manager;
108 }
109
110 /***
111 * @return Returns the service manager.
112 */
113 protected ServiceLocator getServiceLocator()
114 {
115 return manager;
116 }
117 }