1 24 package org.ofbiz.minilang.method.entityops; 25 26 import org.ofbiz.base.util.UtilValidate; 27 import org.ofbiz.minilang.SimpleMethod; 28 import org.ofbiz.minilang.method.ContextAccessor; 29 import org.ofbiz.minilang.method.MethodContext; 30 import org.ofbiz.minilang.method.MethodOperation; 31 import org.w3c.dom.Element ; 32 33 40 public class SequencedIdToEnv extends MethodOperation { 41 42 String seqName; 43 ContextAccessor envAcsr; 44 boolean getLongOnly; 45 long staggerMax = 1; 46 47 public SequencedIdToEnv(Element element, SimpleMethod simpleMethod) { 48 super(element, simpleMethod); 49 seqName = element.getAttribute("sequence-name"); 50 envAcsr = new ContextAccessor(element.getAttribute("env-name")); 51 getLongOnly = "true".equals(element.getAttribute("get-long-only")); 53 String staggerMaxStr = element.getAttribute("stagger-max"); 54 if (UtilValidate.isNotEmpty(staggerMaxStr)) { 55 try { 56 this.staggerMax = Long.parseLong(staggerMaxStr); 57 if (this.staggerMax < 1) { 58 this.staggerMax = 1; 59 } 60 } catch (NumberFormatException e) { 61 this.staggerMax = 1; 62 } 63 } 64 } 65 66 public boolean exec(MethodContext methodContext) { 67 String seqName = methodContext.expandString(this.seqName); 68 if (getLongOnly) { 69 envAcsr.put(methodContext, methodContext.getDelegator().getNextSeqIdLong(seqName, staggerMax)); 70 } else { 71 envAcsr.put(methodContext, methodContext.getDelegator().getNextSeqId(seqName, staggerMax)); 72 } 73 return true; 74 } 75 76 public String rawString() { 77 return "<sequenced-id-to-env/>"; 79 } 80 public String expandedString(MethodContext methodContext) { 81 return this.rawString(); 83 } 84 } 85 | Popular Tags |