01: /*
02: * Copyright 2001-2007 Geert Bevin <gbevin[remove] at uwyn dot com>
03: * Distributed under the terms of either:
04: * - the common development and distribution license (CDDL), v1.0; or
05: * - the GNU Lesser General Public License, v2.1 or later
06: * $Id: SoapXFireDeployer.java 3634 2007-01-08 21:42:24Z gbevin $
07: */
08: package com.uwyn.rife.engine.elements;
09:
10: import com.uwyn.rife.engine.ElementDeployer;
11: import com.uwyn.rife.engine.exceptions.EngineException;
12: import com.uwyn.rife.engine.exceptions.PropertyRequiredException;
13: import com.uwyn.rife.tools.ClassUtils;
14: import javax.servlet.http.HttpServletRequest;
15: import org.codehaus.xfire.XFire;
16: import org.codehaus.xfire.XFireFactory;
17: import org.codehaus.xfire.service.Service;
18: import org.codehaus.xfire.service.ServiceFactory;
19: import org.codehaus.xfire.service.binding.ObjectServiceFactory;
20: import org.codehaus.xfire.service.invoker.ObjectInvoker;
21: import org.codehaus.xfire.service.invoker.ScopePolicyEditor;
22: import org.codehaus.xfire.transport.http.XFireServletController;
23:
24: public class SoapXFireDeployer extends ElementDeployer {
25: private Service mService = null;
26: private XFireController mController = null;
27:
28: public SoapXFireDeployer() {
29: }
30:
31: public void deploy() throws EngineException {
32: if (!getElementInfo().containsProperty("home-class")) {
33: throw new PropertyRequiredException(getElementInfo()
34: .getDeclarationName(), "home-class");
35: }
36: if (!getElementInfo().containsProperty("home-api")) {
37: throw new PropertyRequiredException(getElementInfo()
38: .getDeclarationName(), "home-api");
39: }
40:
41: String home_class_classname = getElementInfo()
42: .getPropertyString("home-class");
43: String home_api_classname = getElementInfo().getPropertyString(
44: "home-api");
45: try {
46: Class home_class = loadClass(home_class_classname);
47: Class home_api = loadClass(home_api_classname);
48: String service_name = getElementInfo().getPropertyString(
49: "service-name",
50: ClassUtils.simpleClassName(home_class));
51: String scope = getElementInfo().getPropertyString("scope",
52: "");
53:
54: XFire xfire = XFireFactory.newInstance().getXFire();
55: ServiceFactory factory = new ObjectServiceFactory(xfire
56: .getTransportManager(), null);
57: mService = factory.create(home_api, service_name, null,
58: null);
59: mService.setInvoker(new SoapXFireObjectInvoker(
60: ScopePolicyEditor.toScopePolicy(scope)));
61: mService.setProperty(ObjectInvoker.SERVICE_IMPL_CLASS,
62: home_class);
63: xfire.getServiceRegistry().register(mService);
64: mController = new XFireController(xfire);
65: } catch (ClassNotFoundException e) {
66: throw new EngineException(e);
67: }
68: }
69:
70: XFireController getController() {
71: return mController;
72: }
73:
74: private Class loadClass(String className)
75: throws ClassNotFoundException {
76: ClassLoader loader = Thread.currentThread()
77: .getContextClassLoader();
78:
79: if (loader != null) {
80: return Class.forName(className, false, loader);
81: } else {
82: return Class.forName(className);
83: }
84: }
85:
86: class XFireController extends XFireServletController {
87: public XFireController(XFire xfire) {
88: super (xfire);
89: }
90:
91: protected String getService(HttpServletRequest request) {
92: return mService.getName().getLocalPart();
93: }
94: }
95: }
|