1 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 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.getAttribute("list-name")); 53 doCacheClearStr = element.getAttribute("do-cache-clear"); 54 } 55 56 public boolean exec(MethodContext methodContext) { 57 boolean doCacheClear = !"false".equals(methodContext.expandString(doCacheClearStr)); 58 59 List values = (List ) listAcsr.get(methodContext); 60 if (values == null) { 61 String errMsg = "In store-list a value list was not found with the specified listAcsr: " + listAcsr + ", not storing"; 62 Debug.logInfo(errMsg, module); 63 } 64 65 try { 66 methodContext.getDelegator().storeAll(values, doCacheClear); 67 } catch (GenericEntityException e) { 68 Debug.logError(e, module); 69 String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem storing the " + listAcsr + " value list: " + e.getMessage() + "]"; 70 71 if (methodContext.getMethodType() == MethodContext.EVENT) { 72 methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); 73 methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); 74 } else if (methodContext.getMethodType() == MethodContext.SERVICE) { 75 methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); 76 methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); 77 } 78 return false; 79 } 80 return true; 81 } 82 83 public String rawString() { 84 return "<store-list/>"; 86 } 87 public String expandedString(MethodContext methodContext) { 88 return this.rawString(); 90 } 91 } 92 | Popular Tags |