1 24 package org.ofbiz.minilang.method.entityops; 25 26 import java.util.Map ; 27 28 import org.ofbiz.base.util.Debug; 29 import org.ofbiz.entity.GenericValue; 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 SetNonpkFields extends MethodOperation { 44 45 public static final String module = SetNonpkFields.class.getName(); 46 47 ContextAccessor valueAcsr; 48 ContextAccessor mapAcsr; 49 String setIfNullStr; 50 51 public SetNonpkFields(Element element, SimpleMethod simpleMethod) { 52 super(element, simpleMethod); 53 valueAcsr = new ContextAccessor(element.getAttribute("value-name")); 54 mapAcsr = new ContextAccessor(element.getAttribute("map-name")); 55 setIfNullStr = element.getAttribute("set-if-null"); 56 } 57 58 public boolean exec(MethodContext methodContext) { 59 boolean setIfNull = !"false".equals(methodContext.expandString(setIfNullStr)); 61 62 GenericValue value = (GenericValue) valueAcsr.get(methodContext); 63 if (value == null) { 64 String errMsg = "In set-nonpk-fields a value was not found with the specified valueAcsr: " + valueAcsr + ", not setting fields"; 65 Debug.logWarning(errMsg, module); 66 if (methodContext.getMethodType() == MethodContext.EVENT) { 67 methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); 68 methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); 69 } else if (methodContext.getMethodType() == MethodContext.SERVICE) { 70 methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); 71 methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); 72 } 73 return false; 74 } 75 76 Map theMap = (Map ) mapAcsr.get(methodContext); 77 if (theMap == null) { 78 Debug.logWarning("In set-nonpk-fields could not find map with name " + mapAcsr + ", not setting any fields", module); 79 } else { 80 value.setNonPKFields(theMap, setIfNull); 81 } 82 return true; 83 } 84 85 public String rawString() { 86 return "<set-nonpk-fields/>"; 88 } 89 public String expandedString(MethodContext methodContext) { 90 return this.rawString(); 92 } 93 } 94 | Popular Tags |