01: /*******************************************************************************
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: *******************************************************************************/package org.ofbiz.minilang.method.entityops;
19:
20: import java.util.List;
21:
22: import org.ofbiz.base.util.Debug;
23: import org.ofbiz.entity.GenericEntityException;
24: import org.ofbiz.minilang.SimpleMethod;
25: import org.ofbiz.minilang.method.ContextAccessor;
26: import org.ofbiz.minilang.method.MethodContext;
27: import org.ofbiz.minilang.method.MethodOperation;
28: import org.w3c.dom.Element;
29:
30: /**
31: * Uses the delegator to store the specified value object list in the datasource
32: */
33: public class StoreList extends MethodOperation {
34:
35: public static final String module = StoreList.class.getName();
36:
37: ContextAccessor listAcsr;
38: String doCacheClearStr;
39:
40: public StoreList(Element element, SimpleMethod simpleMethod) {
41: super (element, simpleMethod);
42: listAcsr = new ContextAccessor(element
43: .getAttribute("list-name"));
44: doCacheClearStr = element.getAttribute("do-cache-clear");
45: }
46:
47: public boolean exec(MethodContext methodContext) {
48: boolean doCacheClear = !"false".equals(methodContext
49: .expandString(doCacheClearStr));
50:
51: List values = (List) listAcsr.get(methodContext);
52: if (values == null) {
53: String errMsg = "In store-list a value list was not found with the specified listAcsr: "
54: + listAcsr + ", not storing";
55: Debug.logInfo(errMsg, module);
56: }
57:
58: try {
59: methodContext.getDelegator().storeAll(values, doCacheClear);
60: } catch (GenericEntityException e) {
61: Debug.logError(e, module);
62: String errMsg = "ERROR: Could not complete the "
63: + simpleMethod.getShortDescription()
64: + " process [problem storing the " + listAcsr
65: + " value list: " + e.getMessage() + "]";
66:
67: if (methodContext.getMethodType() == MethodContext.EVENT) {
68: methodContext.putEnv(simpleMethod
69: .getEventErrorMessageName(), errMsg);
70: methodContext.putEnv(simpleMethod
71: .getEventResponseCodeName(), simpleMethod
72: .getDefaultErrorCode());
73: } else if (methodContext.getMethodType() == MethodContext.SERVICE) {
74: methodContext.putEnv(simpleMethod
75: .getServiceErrorMessageName(), errMsg);
76: methodContext.putEnv(simpleMethod
77: .getServiceResponseMessageName(), simpleMethod
78: .getDefaultErrorCode());
79: }
80: return false;
81: }
82: return true;
83: }
84:
85: public String rawString() {
86: // TODO: something more than the empty tag
87: return "<store-list/>";
88: }
89:
90: public String expandedString(MethodContext methodContext) {
91: // TODO: something more than a stub/dummy
92: return this.rawString();
93: }
94: }
|