01: /*
02: * $Id: StoreList.java,v 1.1 2003/08/17 06:06:11 ajzeneski Exp $
03: *
04: * Copyright (c) 2001, 2002 The Open For Business Project - www.ofbiz.org
05: *
06: * Permission is hereby granted, free of charge, to any person obtaining a
07: * copy of this software and associated documentation files (the "Software"),
08: * to deal in the Software without restriction, including without limitation
09: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10: * and/or sell copies of the Software, and to permit persons to whom the
11: * Software is furnished to do so, subject to the following conditions:
12: *
13: * The above copyright notice and this permission notice shall be included
14: * in all copies or substantial portions of the Software.
15: *
16: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
21: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
22: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23: */
24: package org.ofbiz.minilang.method.entityops;
25:
26: import java.util.List;
27:
28: import org.ofbiz.base.util.Debug;
29: import org.ofbiz.entity.GenericEntityException;
30: import org.ofbiz.minilang.SimpleMethod;
31: import org.ofbiz.minilang.method.ContextAccessor;
32: import org.ofbiz.minilang.method.MethodContext;
33: import org.ofbiz.minilang.method.MethodOperation;
34: import org.w3c.dom.Element;
35:
36: /**
37: * Uses the delegator to store the specified value object list in the datasource
38: *
39: * @author <a href="mailto:jonesde@ofbiz.org">David E. Jones</a>
40: * @version $Revision: 1.1 $
41: * @since 2.0
42: */
43: public class StoreList extends MethodOperation {
44:
45: public static final String module = StoreList.class.getName();
46:
47: ContextAccessor listAcsr;
48: String doCacheClearStr;
49:
50: public StoreList(Element element, SimpleMethod simpleMethod) {
51: super (element, simpleMethod);
52: listAcsr = new ContextAccessor(element
53: .getAttribute("list-name"));
54: doCacheClearStr = element.getAttribute("do-cache-clear");
55: }
56:
57: public boolean exec(MethodContext methodContext) {
58: boolean doCacheClear = !"false".equals(methodContext
59: .expandString(doCacheClearStr));
60:
61: List values = (List) listAcsr.get(methodContext);
62: if (values == null) {
63: String errMsg = "In store-list a value list was not found with the specified listAcsr: "
64: + listAcsr + ", not storing";
65: Debug.logInfo(errMsg, module);
66: }
67:
68: try {
69: methodContext.getDelegator().storeAll(values, doCacheClear);
70: } catch (GenericEntityException e) {
71: Debug.logError(e, module);
72: String errMsg = "ERROR: Could not complete the "
73: + simpleMethod.getShortDescription()
74: + " process [problem storing the " + listAcsr
75: + " value list: " + e.getMessage() + "]";
76:
77: if (methodContext.getMethodType() == MethodContext.EVENT) {
78: methodContext.putEnv(simpleMethod
79: .getEventErrorMessageName(), errMsg);
80: methodContext.putEnv(simpleMethod
81: .getEventResponseCodeName(), simpleMethod
82: .getDefaultErrorCode());
83: } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
84: methodContext.putEnv(simpleMethod
85: .getServiceErrorMessageName(), errMsg);
86: methodContext.putEnv(simpleMethod
87: .getServiceResponseMessageName(), simpleMethod
88: .getDefaultErrorCode());
89: }
90: return false;
91: }
92: return true;
93: }
94: }
|