|
Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeNextSeqId.java
URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeNextSeqId.java?rev=1345652&r1=1345651&r2=1345652&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeNextSeqId.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeNextSeqId.java Sun Jun 3 11:13:32 2012 @@ -18,79 +18,107 @@ *******************************************************************************/ package org.ofbiz.minilang.method.entityops; -import org.ofbiz.base.util.Debug; -import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Look at existing values for a sub-entity with a sequenced secondary ID, and get the highest plus 1 + * Implements the <make-next-seq-id> element. */ -public class MakeNextSeqId extends MethodOperation { +public final class MakeNextSeqId extends MethodOperation { public static final String module = MakeNextSeqId.class.getName(); - String incrementByStr; - String numericPaddingStr; - String seqFieldName; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleStringExpander incrementByFse; + private final FlexibleStringExpander numericPaddingFse; + private final FlexibleStringExpander seqFieldNameFse; + private final FlexibleMapAccessor<GenericValue> valueFma; public MakeNextSeqId(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - seqFieldName = element.getAttribute("seq-field-name"); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - numericPaddingStr = element.getAttribute("numeric-padding"); - incrementByStr = element.getAttribute("increment-by"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "seq-field-name", "increment-by", "numeric-padding"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field", "seq-field-name"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + seqFieldNameFse = FlexibleStringExpander.getInstance(element.getAttribute("seq-field-name")); + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + numericPaddingFse = FlexibleStringExpander.getInstance(element.getAttribute("numeric-padding")); + incrementByFse = FlexibleStringExpander.getInstance(element.getAttribute("increment-by")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - String seqFieldName = methodContext.expandString(this.seqFieldName); - String numericPaddingStr = methodContext.expandString(this.numericPaddingStr); - String incrementByStr = methodContext.expandString(this.incrementByStr); + GenericValue value = valueFma.get(methodContext.getEnvMap()); + if (value == null) { + throw new MiniLangRuntimeException("Entity value not found with name: " + valueFma, this); + } + String seqFieldName = seqFieldNameFse.expandString(methodContext.getEnvMap()); + String numericPaddingStr = numericPaddingFse.expandString(methodContext.getEnvMap()); + String incrementByStr = incrementByFse.expandString(methodContext.getEnvMap()); int numericPadding = 5; - int incrementBy = 1; - try { - if (UtilValidate.isNotEmpty(numericPaddingStr)) { + if (!numericPaddingStr.isEmpty()) { + try { numericPadding = Integer.parseInt(numericPaddingStr); + } catch (Exception e) { + throw new MiniLangRuntimeException("Invalid number in \"numeric-padding\" attribute", this); } - } catch (Exception e) { - Debug.logError(e, "numeric-padding format invalid for [" + numericPaddingStr + "]", module); } - try { - if (UtilValidate.isNotEmpty(incrementByStr)) { + int incrementBy = 1; + if (!incrementByStr.isEmpty()) { + try { incrementBy = Integer.parseInt(incrementByStr); + } catch (Exception e) { + throw new MiniLangRuntimeException("Invalid number in \"increment-by\" attribute", this); } - } catch (Exception e) { - Debug.logError(e, "increment-by format invalid for [" + incrementByStr + "]", module); } - GenericValue value = valueAcsr.get(methodContext); methodContext.getDelegator().setNextSubSeqId(value, seqFieldName, numericPadding, incrementBy); return true; } @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<make-next-seq-id/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<make-next-seq-id "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + sb.append("seq-field-name=\"").append(this.seqFieldNameFse).append("\" "); + if (!incrementByFse.isEmpty()) { + sb.append("increment-by=\"").append(this.incrementByFse).append("\" "); + } + if (!numericPaddingFse.isEmpty()) { + sb.append("numeric-padding=\"").append(this.numericPaddingFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <make-next-seq-id> element. + */ public static final class MakeNextSeqIdFactory implements Factory<MakeNextSeqId> { + @Override public MakeNextSeqId createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new MakeNextSeqId(element, simpleMethod); } + @Override public String getName() { return "make-next-seq-id"; } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeValue.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeValue.java?rev=1345652&r1=1345651&r2=1345652&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeValue.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/MakeValue.java Sun Jun 3 11:13:32 2012 @@ -20,61 +20,87 @@ package org.ofbiz.minilang.method.entity import java.util.Map; -import org.ofbiz.minilang.artifact.ArtifactInfoContext; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; +import org.ofbiz.minilang.artifact.ArtifactInfoContext; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to find entity values by anding the map fields + * Implements the <make-value> element. */ -public class MakeValue extends MethodOperation { +public final class MakeValue extends MethodOperation { - String entityName; - ContextAccessor<Map<String, ? extends Object>> mapAcsr; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleStringExpander entityNameFse; + private final FlexibleMapAccessor<Map<String, ? extends Object>> mapFma; + private final FlexibleMapAccessor<GenericValue> valueFma; public MakeValue(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - entityName = element.getAttribute("entity-name"); - mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map"), element.getAttribute("map-name")); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "entity-name", "map"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field", "entity-name"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field", "map"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + entityNameFse = FlexibleStringExpander.getInstance(element.getAttribute("entity-name")); + mapFma = FlexibleMapAccessor.getInstance(element.getAttribute("map")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - String entityName = methodContext.expandString(this.entityName); - Map<String, ? extends Object> ctxMap = (mapAcsr.isEmpty() ? null : mapAcsr.get(methodContext)); - valueAcsr.put(methodContext, methodContext.getDelegator().makeValidValue(entityName, ctxMap)); + String entityName = entityNameFse.expandString(methodContext.getEnvMap()); + if (entityName.isEmpty()) { + throw new MiniLangRuntimeException("Entity name not found: " + entityNameFse, this); + } + valueFma.put(methodContext.getEnvMap(), methodContext.getDelegator().makeValidValue(entityName, mapFma.get(methodContext.getEnvMap()))); return true; } @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public void gatherArtifactInfo(ArtifactInfoContext aic) { - aic.addEntityName(entityName); + aic.addEntityName(entityNameFse.toString()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<make-value/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<make-value "); + sb.append("entity-name=\"").append(this.entityNameFse).append("\" "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + if (!mapFma.isEmpty()) { + sb.append("map=\"").append(this.mapFma).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <make-value> element. + */ public static final class MakeValueFactory implements Factory<MakeValue> { + @Override public MakeValue createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new MakeValue(element, simpleMethod); } + @Override public String getName() { return "make-value"; } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java?rev=1345652&r1=1345651&r2=1345652&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/OrderValueList.java Sun Jun 3 11:13:32 2012 @@ -20,61 +20,81 @@ package org.ofbiz.minilang.method.entity import java.util.List; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntity; import org.ofbiz.entity.util.EntityUtil; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Order the given list of GenericValue objects + * Implements the <order-value-list> element. */ -public class OrderValueList extends MethodOperation { +public final class OrderValueList extends MethodOperation { - ContextAccessor<List<? extends GenericEntity>> listAcsr; - ContextAccessor<List<String>> orderByListAcsr; - ContextAccessor<List<? extends GenericEntity>> toListAcsr; + private final FlexibleMapAccessor<List<? extends GenericEntity>> listFma; + private final FlexibleMapAccessor<List<String>> orderByListFma; + private final FlexibleMapAccessor<List<? extends GenericEntity>> toListFma; public OrderValueList(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - listAcsr = new ContextAccessor<List<? extends GenericEntity>>(element.getAttribute("list"), element.getAttribute("list-name")); - toListAcsr = new ContextAccessor<List<? extends GenericEntity>>(element.getAttribute("to-list"), element.getAttribute("to-list-name")); - if (toListAcsr.isEmpty()) { - toListAcsr = listAcsr; + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "list", "order-by-list", "to-list"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "list", "order-by-list"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "list", "order-by-list", "to-list"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + listFma = FlexibleMapAccessor.getInstance(element.getAttribute("list")); + orderByListFma = FlexibleMapAccessor.getInstance(element.getAttribute("order-by-list")); + String toListAttribute = element.getAttribute("to-list"); + if (toListAttribute.isEmpty()) { + toListFma = listFma; + } else { + toListFma = FlexibleMapAccessor.getInstance(toListAttribute); } - orderByListAcsr = new ContextAccessor<List<String>>(element.getAttribute("order-by-list"), element.getAttribute("order-by-list-name")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - List<String> orderByList = null; - if (!orderByListAcsr.isEmpty()) { - orderByList = orderByListAcsr.get(methodContext); - } - toListAcsr.put(methodContext, EntityUtil.orderBy(listAcsr.get(methodContext), orderByList)); + List<String> orderByList = orderByListFma.get(methodContext.getEnvMap()); + toListFma.put(methodContext.getEnvMap(), EntityUtil.orderBy(listFma.get(methodContext.getEnvMap()), orderByList)); return true; } @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<order-value-list/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<order-value-list "); + sb.append("list=\"").append(this.listFma).append("\" "); + sb.append("order-by-list=\"").append(this.orderByListFma).append("\" "); + sb.append("to-list=\"").append(this.toListFma).append("\" "); + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <order-value-list> element. + */ public static final class OrderValueListFactory implements Factory<OrderValueList> { + @Override public OrderValueList createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new OrderValueList(element, simpleMethod); } + @Override public String getName() { return "order-value-list"; } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RefreshValue.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RefreshValue.java?rev=1345652&r1=1345651&r2=1345652&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RefreshValue.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RefreshValue.java Sun Jun 3 11:13:32 2012 @@ -19,47 +19,53 @@ package org.ofbiz.minilang.method.entityops; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to refresh the specified value object entity from the datasource + * Implements the <refresh-value> element. */ -public class RefreshValue extends MethodOperation { +public final class RefreshValue extends MethodOperation { public static final String module = RemoveValue.class.getName(); - String doCacheClearStr; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleMapAccessor<GenericValue> valueFma; public RefreshValue(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - doCacheClearStr = element.getAttribute("do-cache-clear"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "do-cache-clear"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + doCacheClearFse = FlexibleStringExpander.getInstance(element.getAttribute("do-cache-clear")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - boolean doCacheClear = !"false".equals(methodContext.expandString(doCacheClearStr)); - GenericValue value = valueAcsr.get(methodContext); + GenericValue value = valueFma.get(methodContext.getEnvMap()); if (value == null) { - String errMsg = "In remove-value a value was not found with the specified valueAcsr: " + valueAcsr + ", not removing"; - Debug.logWarning(errMsg, module); - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; + throw new MiniLangRuntimeException("Entity value not found with name: " + valueFma, this); } + boolean doCacheClear = !"false".equals(doCacheClearFse.expandString(methodContext.getEnvMap())); try { methodContext.getDelegator().refresh(value, doCacheClear); } catch (GenericEntityException e) { - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem removing the " + valueAcsr + " value: " + e.getMessage() + "]"; - Debug.logError(e, errMsg, module); - methodContext.setErrorReturn(errMsg, simpleMethod); + String errMsg = "Exception thrown while refreshing value: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -67,21 +73,35 @@ public class RefreshValue extends Method @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<refresh-value/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<refresh-value "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + if (!doCacheClearFse.isEmpty()) { + sb.append("do-cache-clear=\"").append(this.doCacheClearFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <refresh-value> element. + */ public static final class RefreshValueFactory implements Factory<RefreshValue> { + @Override public RefreshValue createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new RefreshValue(element, simpleMethod); } + @Override public String getName() { return "refresh-value"; } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java?rev=1345652&r1=1345651&r2=1345652&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java Sun Jun 3 11:13:32 2012 @@ -21,48 +21,51 @@ package org.ofbiz.minilang.method.entity import java.util.Map; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; +import org.ofbiz.minilang.artifact.ArtifactInfoContext; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to remove entity values constrained by anding the map fields + * Implements the <remove-by-and> element. */ -public class RemoveByAnd extends MethodOperation { +public final class RemoveByAnd extends MethodOperation { public static final String module = RemoveByAnd.class.getName(); - String doCacheClearStr; - String entityName; - ContextAccessor<Map<String, ? extends Object>> mapAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleStringExpander entityNameFse; + private final FlexibleMapAccessor<Map<String, ? extends Object>> mapFma; public RemoveByAnd(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - entityName = element.getAttribute("entity-name"); - mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map"), element.getAttribute("map-name")); - doCacheClearStr = element.getAttribute("do-cache-clear"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "entity-name", "map", "do-cache-clear"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "entity-name", "map"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "map"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + entityNameFse = FlexibleStringExpander.getInstance(element.getAttribute("entity-name")); + mapFma = FlexibleMapAccessor.getInstance(element.getAttribute("map")); + doCacheClearFse = FlexibleStringExpander.getInstance(element.getAttribute("do-cache-clear")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - boolean doCacheClear = !"false".equals(doCacheClearStr); - String entityName = methodContext.expandString(this.entityName); + boolean doCacheClear = !"false".equals(doCacheClearFse.expandString(methodContext.getEnvMap())); + String entityName = entityNameFse.expandString(methodContext.getEnvMap()); try { - methodContext.getDelegator().removeByAnd(entityName, mapAcsr.get(methodContext), doCacheClear); + methodContext.getDelegator().removeByAnd(entityName, mapFma.get(methodContext.getEnvMap()), doCacheClear); } catch (GenericEntityException e) { - Debug.logError(e, module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem removing the " + entityName + " entity by and: " + e.getMessage() + "]"; - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } + String errMsg = "Exception thrown while removing entities: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -70,21 +73,41 @@ public class RemoveByAnd extends MethodO @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); + } + + @Override + public void gatherArtifactInfo(ArtifactInfoContext aic) { + aic.addEntityName(entityNameFse.toString()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<remove-by-and/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<remove-by-and "); + sb.append("entity-name=\"").append(this.entityNameFse).append("\" "); + sb.append("map=\"").append(this.mapFma).append("\" "); + if (!doCacheClearFse.isEmpty()) { + sb.append("do-cache-clear=\"").append(this.doCacheClearFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <remove-by-and> element. + */ public static final class RemoveByAndFactory implements Factory<RemoveByAnd> { + @Override public RemoveByAnd createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new RemoveByAnd(element, simpleMethod); } + @Override public String getName() { return "remove-by-and"; } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java?rev=1345652&r1=1345651&r2=1345652&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java Sun Jun 3 11:13:32 2012 @@ -21,59 +21,53 @@ package org.ofbiz.minilang.method.entity import java.util.List; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to remove the specified value object (or psuedo-pk) list from the datasource + * Implements the <remove-list> element. */ -public class RemoveList extends MethodOperation { +public final class RemoveList extends MethodOperation { public static final String module = RemoveList.class.getName(); - String doCacheClearStr; - ContextAccessor<List<GenericValue>> listAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleMapAccessor<List<GenericValue>> listFma; public RemoveList(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - listAcsr = new ContextAccessor<List<GenericValue>>(element.getAttribute("list"), element.getAttribute("list-name")); - doCacheClearStr = element.getAttribute("do-cache-clear"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "list", "do-cache-clear"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "list"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "list"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + listFma = FlexibleMapAccessor.getInstance(element.getAttribute("list")); + doCacheClearFse = FlexibleStringExpander.getInstance(element.getAttribute("do-cache-clear")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - boolean doCacheClear = !"false".equals(doCacheClearStr); - List<GenericValue> values = listAcsr.get(methodContext); + List<GenericValue> values = listFma.get(methodContext.getEnvMap()); if (values == null) { - String errMsg = "In remove-list a value list was not found with the specified listAcsr: " + listAcsr + ", not removing"; - Debug.logWarning(errMsg, module); - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } - return false; + throw new MiniLangRuntimeException("Entity value list not found with name: " + listFma, this); } + boolean doCacheClear = !"false".equals(doCacheClearFse.expandString(methodContext.getEnvMap())); try { methodContext.getDelegator().removeAll(values, doCacheClear); } catch (GenericEntityException e) { - Debug.logError(e, module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem removing the " + listAcsr + " value list: " + e.getMessage() + "]"; - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } + String errMsg = "Exception thrown while removing entities: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -81,21 +75,35 @@ public class RemoveList extends MethodOp @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<remove-list/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<remove-list "); + sb.append("list=\"").append(this.listFma).append("\" "); + if (!doCacheClearFse.isEmpty()) { + sb.append("do-cache-clear=\"").append(this.doCacheClearFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <remove-list> element. + */ public static final class RemoveListFactory implements Factory<RemoveList> { + @Override public RemoveList createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new RemoveList(element, simpleMethod); } + @Override public String getName() { return "remove-list"; } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java?rev=1345652&r1=1345651&r2=1345652&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java Sun Jun 3 11:13:32 2012 @@ -19,62 +19,57 @@ package org.ofbiz.minilang.method.entityops; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; +import org.ofbiz.minilang.artifact.ArtifactInfoContext; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to remove entities related to the specified value object from the datasource + * Implements the <remove-related> element. */ -public class RemoveRelated extends MethodOperation { +public final class RemoveRelated extends MethodOperation { public static final String module = RemoveRelated.class.getName(); - String doCacheClearStr; - String relationName; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleStringExpander relationNameFse; + private final FlexibleMapAccessor<GenericValue> valueFma; public RemoveRelated(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - relationName = element.getAttribute("relation-name"); - doCacheClearStr = element.getAttribute("do-cache-clear"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "relation-name", "do-cache-clear"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field", "relation-name"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + relationNameFse = FlexibleStringExpander.getInstance(element.getAttribute("relation-name")); + doCacheClearFse = FlexibleStringExpander.getInstance(element.getAttribute("do-cache-clear")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - boolean doCacheClear = !"false".equals(doCacheClearStr); - String relationName = methodContext.expandString(this.relationName); - GenericValue value = valueAcsr.get(methodContext); + GenericValue value = valueFma.get(methodContext.getEnvMap()); if (value == null) { - String errMsg = "In remove-related a value was not found with the specified valueAcsr: " + valueAcsr + ", not removing related"; - Debug.logWarning(errMsg, module); - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } - return false; + throw new MiniLangRuntimeException("Entity value not found with name: " + valueFma, this); } + String relationName = relationNameFse.expandString(methodContext.getEnvMap()); + boolean doCacheClear = !"false".equals(doCacheClearFse.expandString(methodContext.getEnvMap())); try { methodContext.getDelegator().removeRelated(relationName, value, doCacheClear); } catch (GenericEntityException e) { - Debug.logError(e, module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem removing the relation " + relationName + " of the value " + valueAcsr + " value: " + e.getMessage() + "]"; - if (methodContext.getMethodType() == MethodContext.EVENT) { - methodContext.putEnv(simpleMethod.getEventErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getEventResponseCodeName(), simpleMethod.getDefaultErrorCode()); - } else if (methodContext.getMethodType() == MethodContext.SERVICE) { - methodContext.putEnv(simpleMethod.getServiceErrorMessageName(), errMsg); - methodContext.putEnv(simpleMethod.getServiceResponseMessageName(), simpleMethod.getDefaultErrorCode()); - } + String errMsg = "Exception thrown while removing related entities: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -82,21 +77,41 @@ public class RemoveRelated extends Metho @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); + } + + @Override + public void gatherArtifactInfo(ArtifactInfoContext aic) { + aic.addEntityName(relationNameFse.toString()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<remove-related/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<remove-related "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + sb.append("relation-name=\"").append(this.relationNameFse).append("\" "); + if (!doCacheClearFse.isEmpty()) { + sb.append("do-cache-clear=\"").append(this.doCacheClearFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <remove-related> element. + */ public static final class RemoveRelatedFactory implements Factory<RemoveRelated> { + @Override public RemoveRelated createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new RemoveRelated(element, simpleMethod); } + @Override public String getName() { return "remove-related"; } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java?rev=1345652&r1=1345651&r2=1345652&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java Sun Jun 3 11:13:32 2012 @@ -19,47 +19,53 @@ package org.ofbiz.minilang.method.entityops; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.entity.GenericEntityException; import org.ofbiz.entity.GenericValue; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Uses the delegator to remove the specified value object entity from the datasource + * Implements the <remove-value> element. */ public class RemoveValue extends MethodOperation { public static final String module = RemoveValue.class.getName(); - String doCacheClearStr; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleMapAccessor<GenericValue> valueFma; public RemoveValue(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - doCacheClearStr = element.getAttribute("do-cache-clear"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "do-cache-clear"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + doCacheClearFse = FlexibleStringExpander.getInstance(element.getAttribute("do-cache-clear")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - boolean doCacheClear = !"false".equals(methodContext.expandString(doCacheClearStr)); - GenericValue value = valueAcsr.get(methodContext); + GenericValue value = valueFma.get(methodContext.getEnvMap()); if (value == null) { - String errMsg = "In remove-value a value was not found with the specified valueAcsr: " + valueAcsr + ", not removing"; - Debug.logWarning(errMsg, module); - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; + throw new MiniLangRuntimeException("Entity value not found with name: " + valueFma, this); } + boolean doCacheClear = !"false".equals(doCacheClearFse.expandString(methodContext.getEnvMap())); try { methodContext.getDelegator().removeValue(value, doCacheClear); } catch (GenericEntityException e) { - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem removing the " + valueAcsr + " value: " + e.getMessage() + "]"; - Debug.logError(e, errMsg, module); - methodContext.setErrorReturn(errMsg, simpleMethod); + String errMsg = "Exception thrown while removing entity value: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; @@ -67,21 +73,35 @@ public class RemoveValue extends MethodO @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<remove-value/>"; + return toString(); + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<remove-value "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + if (!doCacheClearFse.isEmpty()) { + sb.append("do-cache-clear=\"").append(this.doCacheClearFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <remove-value> element. + */ public static final class RemoveValueFactory implements Factory<RemoveValue> { + @Override public RemoveValue createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new RemoveValue(element, simpleMethod); } + @Override public String getName() { return "remove-value"; } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java?rev=1345652&r1=1345651&r2=1345652&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java Sun Jun 3 11:13:32 2012 @@ -18,82 +18,97 @@ *******************************************************************************/ package org.ofbiz.minilang.method.entityops; -import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; +import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.minilang.MiniLangException; +import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; -import org.ofbiz.minilang.method.ContextAccessor; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Gets a sequenced ID from the delegator and puts it in the env + * Implements the <sequenced-id> element. */ -public class SequencedIdToEnv extends MethodOperation { +public final class SequencedIdToEnv extends MethodOperation { - ContextAccessor<Object> envAcsr; - boolean getLongOnly; - String seqName; - long staggerMax = 1; + private final FlexibleMapAccessor<Object> fieldFma; + private final boolean getLongOnly; + private final FlexibleStringExpander sequenceNameFse; + private final long staggerMax; public SequencedIdToEnv(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - seqName = element.getAttribute("sequence-name"); - envAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("env-name")); - // default false, anything but true is false + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "sequence-name", "field", "get-long-only", "stagger-max"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "sequence-name", "field"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + sequenceNameFse = FlexibleStringExpander.getInstance(element.getAttribute("sequence-name")); + fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field")); getLongOnly = "true".equals(element.getAttribute("get-long-only")); - String staggerMaxStr = element.getAttribute("stagger-max"); - if (UtilValidate.isNotEmpty(staggerMaxStr)) { + long staggerMax = 1; + String staggerMaxAttribute = element.getAttribute("stagger-max"); + if (!staggerMaxAttribute.isEmpty()) { try { - this.staggerMax = Long.parseLong(staggerMaxStr); - if (this.staggerMax < 1) { - this.staggerMax = 1; + staggerMax = Long.parseLong(staggerMaxAttribute); + if (staggerMax < 1) { + staggerMax = 1; } } catch (NumberFormatException e) { - this.staggerMax = 1; + MiniLangValidate.handleError("Invalid stagger-max attribute value: " + e.getMessage(), simpleMethod, element); } } + this.staggerMax = staggerMax; } + @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - String seqName = methodContext.expandString(this.seqName); + String seqName = sequenceNameFse.expandString(methodContext.getEnvMap()); if (getLongOnly) { - envAcsr.put(methodContext, methodContext.getDelegator().getNextSeqIdLong(seqName, staggerMax)); + fieldFma.put(methodContext.getEnvMap(), methodContext.getDelegator().getNextSeqIdLong(seqName, staggerMax)); } else { - envAcsr.put(methodContext, methodContext.getDelegator().getNextSeqId(seqName, staggerMax)); + fieldFma.put(methodContext.getEnvMap(), methodContext.getDelegator().getNextSeqId(seqName, staggerMax)); } return true; } @Override public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); } @Override public String rawString() { - // TODO: something more than the empty tag - return "<sequenced-id-to-env/>"; + return toString(); } - public static final class SequencedIdFactory implements Factory<SequencedIdToEnv> { - public SequencedIdToEnv createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { - return new SequencedIdToEnv(element, simpleMethod); - } - - public String getName() { - return "sequenced-id"; - } + @Override + public String toString() { + StringBuilder sb = new StringBuilder("<sequenced-id "); + sb.append("sequence-name=\"").append(this.sequenceNameFse).append("\" "); + sb.append("field=\"").append(this.fieldFma).append("\" "); + sb.append("stagger-max=\"").append(this.staggerMax).append("\" "); + if (this.getLongOnly) { + sb.append("get-long-only=\"true\" "); + } + sb.append("/>"); + return sb.toString(); } - public static final class SequencedIdToEnvFactory implements Factory<SequencedIdToEnv> { + /** + * A factory for the <sequenced-id> element. + */ + public static final class SequencedIdFactory implements Factory<SequencedIdToEnv> { + @Override public SequencedIdToEnv createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new SequencedIdToEnv(element, simpleMethod); } + @Override public String getName() { - return "sequenced-id-to-env"; + return "sequenced-id"; } } } Modified: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Now.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Now.java?rev=1345652&r1=1345651&r2=1345652&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Now.java (original) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Now.java Sun Jun 3 11:13:32 2012 @@ -26,18 +26,37 @@ import org.ofbiz.base.util.collections.F import org.ofbiz.base.util.string.FlexibleStringExpander; import org.ofbiz.minilang.MiniLangException; import org.ofbiz.minilang.MiniLangRuntimeException; +import org.ofbiz.minilang.MiniLangUtil; import org.ofbiz.minilang.MiniLangValidate; import org.ofbiz.minilang.SimpleMethod; import org.ofbiz.minilang.ValidationException; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; +import org.w3c.dom.Document; import org.w3c.dom.Element; /** - * Sets a field to the current system time. + * Implements the <now>, <now-date-to-env>, and <now-timestamp> elements. */ public final class Now extends MethodOperation { + // This method is needed only during the v1 to v2 transition + private static boolean autoCorrect(Element element) { + String tagName = element.getTagName(); + if ("now-date-to-env".equals(tagName) || "now-timestamp".equals(tagName)) { + Document doc = element.getOwnerDocument(); + Element newElement = doc.createElement("now"); + newElement.setAttribute("field", element.getAttribute("field")); + if ("now-date-to-env".equals(tagName)) { + element.setAttribute("type", "java.sql.Date"); + newElement.setAttribute("type", "java.sql.Date"); + } + element.getParentNode().replaceChild(newElement, element); + return true; + } + return false; + } + private final FlexibleMapAccessor<Object> fieldFma; private final String type; private final Converter<Long, ? extends Object> converter; @@ -45,17 +64,25 @@ public final class Now extends MethodOpe public Now(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); if (MiniLangValidate.validationOn()) { + String tagName = element.getTagName(); + if ("now-date-to-env".equals(tagName) || "now-timestamp".equals(tagName)) { + MiniLangValidate.handleError("Deprecated - use <now>", simpleMethod, element); + } MiniLangValidate.attributeNames(simpleMethod, element, "field", "type"); MiniLangValidate.requiredAttributes(simpleMethod, element, "field"); MiniLangValidate.expressionAttributes(simpleMethod, element, "field"); MiniLangValidate.constantAttributes(simpleMethod, element, "type"); MiniLangValidate.noChildElements(simpleMethod, element); } + boolean elementModified = autoCorrect(element); + if (elementModified && MiniLangUtil.autoCorrectOn()) { + MiniLangUtil.flagDocumentAsCorrected(element); + } this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field")); this.type = element.getAttribute("type"); Class<?> targetClass = null; try { - if (this.type.length() > 0) { + if (!this.type.isEmpty()) { targetClass = ObjectType.loadClass(this.type); } if (targetClass == null) { @@ -93,7 +120,7 @@ public final class Now extends MethodOpe if (!this.fieldFma.isEmpty()) { sb.append("field=\"").append(this.fieldFma).append("\" "); } - if (this.type.length() > 0) { + if (!this.type.isEmpty()) { sb.append("type=\"").append(this.type).append("\" "); } sb.append("/>"); @@ -101,13 +128,48 @@ public final class Now extends MethodOpe } + /** + * A factory for the <now> element. + */ public static final class NowFactory implements Factory<Now> { + @Override public Now createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new Now(element, simpleMethod); } + @Override public String getName() { return "now"; } } + + /** + * A factory for the <now-date-to-env> element. + */ + public static final class NowDateToEnvFactory implements Factory<Now> { + @Override + public Now createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { + return new Now(element, simpleMethod); + } + + @Override + public String getName() { + return "now-date-to-env"; + } + } + + /** + * A factory for the <now-timestamp> element. + */ + public static final class NowTimestampFactory implements Factory<Now> { + @Override + public Now createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { + return new Now(element, simpleMethod); + } + + @Override + public String getName() { + return "now-timestamp"; + } + } } |
| Free forum by Nabble | Edit this page |
