01: package com.xoetrope.service.data;
02:
03: import java.io.StringReader;
04: import net.xoetrope.optional.data.XOptionalDataSource;
05: import net.xoetrope.optional.service.ServiceContext;
06: import net.xoetrope.optional.service.ServiceProxy;
07: import net.xoetrope.optional.service.ServiceProxyArgs;
08: import net.xoetrope.optional.service.ServiceProxyException;
09: import net.xoetrope.optional.service.XRouteManager;
10: import net.xoetrope.xml.XmlElement;
11: import net.xoetrope.xml.XmlSource;
12: import net.xoetrope.xui.XProject;
13: import net.xoetrope.xui.XProjectManager;
14: import net.xoetrope.xui.data.XBaseModel;
15:
16: /**
17: * The basic ServiceProxy class which needs to be subclassed in order to carry out
18: * transactional operations on a database connection. This class expects an
19: * XModel to be passed in the pass param specified by the ARG_NAME_MODELPARAM
20: * parameter. This class then loads the model into a temporary XModel and calls
21: * the processQueries function which should be overloaded in the derived class.
22: *
23: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
24: * the GNU Public License (GPL), please see license.txt for more details. If
25: * you make commercial use of this software you must purchase a commercial
26: * license from Xoetrope.</p>
27: * <p> $Revision: 1.6 $</p>
28: */
29: public class DataEntryService extends ServiceProxy {
30: /**
31: * The name of the parameter which stores the model data.
32: */
33: public static final String ARG_NAME_MODELPARAM = "dataentry:modelparam";
34:
35: /**
36: * The XModel object created from the passed XML
37: */
38: protected XBaseModel dataModel;
39:
40: protected XProject currentProject = XProjectManager
41: .getCurrentProject();
42:
43: /**
44: * Call this proxy with the specified arguments
45: * @return the result of the call
46: * @param context The ServiceContext contain pass and return parameters
47: * @param method the name of the service being called
48: * @throws net.xoetrope.optional.service.ServiceProxyException Throw an exception if there is a problem with the call
49: */
50: public Object call(String method, ServiceContext context)
51: throws ServiceProxyException {
52: if (side == XRouteManager.SERVER_SIDE) {
53: loadModel(context);
54: processQueries(method, context);
55: }
56: return callNextProxy(method, context, null);
57: }
58:
59: /**
60: * Needs to be overloaded by the subclass so that queries can be batched in transactions
61: * @param method The name of the service being called
62: * @param context The ServiceContext object
63: */
64: protected void processQueries(String method, ServiceContext context) {
65: }
66:
67: /**
68: * Retrieve the model XML and load it into the dataModel variable
69: * @param context The ServiceContext instance
70: */
71: protected void loadModel(ServiceContext context) {
72: ServiceProxyArgs args = context.getArgs();
73: String modelParamName = (String) args
74: .getPassParam(ARG_NAME_MODELPARAM);
75: String modelData = (String) args.getPassParam(modelParamName);
76: dataModel = new XBaseModel();
77:
78: StringReader sr = new StringReader(modelData);
79: XmlElement ele = XmlSource.read(sr);
80:
81: if (ele != null) {
82: XOptionalDataSource ds = new XOptionalDataSource(
83: currentProject);
84: ds.loadTable(ele, dataModel);
85: }
86: }
87: }
|