|
Modified: ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveByAnd.java Tue Jul 10 12:05:55 2012 @@ -21,70 +21,85 @@ 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. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Cremovebyand%3E}}">Mini-language Reference</a> */ -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; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + public void gatherArtifactInfo(ArtifactInfoContext aic) { + aic.addEntityName(entityNameFse.toString()); } @Override - public String rawString() { - // TODO: something more than the empty tag - return "<remove-by-and/>"; + 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/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveList.java Tue Jul 10 12:05:55 2012 @@ -21,81 +21,81 @@ 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. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Cremovelist%3E}}">Mini-language Reference</a> */ -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; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - // TODO: something more than the empty tag - return "<remove-list/>"; + 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/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveRelated.java Tue Jul 10 12:05:55 2012 @@ -19,84 +19,91 @@ 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. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Cremoverelated%3E}}">Mini-language Reference</a> */ -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; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); + public void gatherArtifactInfo(ArtifactInfoContext aic) { + aic.addEntityName(relationNameFse.toString()); } @Override - public String rawString() { - // TODO: something more than the empty tag - return "<remove-related/>"; + 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/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/RemoveValue.java Tue Jul 10 12:05:55 2012 @@ -19,69 +19,81 @@ 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. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Cremovevalue%3E}}">Mini-language Reference</a> */ -public class RemoveValue extends MethodOperation { +public final 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; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - // TODO: something more than the empty tag - return "<remove-value/>"; + 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/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SequencedIdToEnv.java Tue Jul 10 12:05:55 2012 @@ -18,82 +18,89 @@ *******************************************************************************/ 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. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Csequencedid%3E}}">Mini-language Reference</a> */ -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(); - } - - @Override - public String rawString() { - // TODO: something more than the empty tag - return "<sequenced-id-to-env/>"; + 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(); } + /** + * 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"; } } - - public static final class SequencedIdToEnvFactory implements Factory<SequencedIdToEnv> { - public SequencedIdToEnv createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { - return new SequencedIdToEnv(element, simpleMethod); - } - - public String getName() { - return "sequenced-id-to-env"; - } - } } Modified: ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetCurrentUserLogin.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetCurrentUserLogin.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetCurrentUserLogin.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetCurrentUserLogin.java Tue Jul 10 12:05:55 2012 @@ -18,57 +18,64 @@ *******************************************************************************/ package org.ofbiz.minilang.method.entityops; -import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; 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 create the specified value object entity in the datasource + * Implements the <set-current-user-login> element. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Csetcurrentuserlogin%3E}}">Mini-language Reference</a> */ -public class SetCurrentUserLogin extends MethodOperation { +public final class SetCurrentUserLogin extends MethodOperation { - public static final String module = SetCurrentUserLogin.class.getName(); - - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleMapAccessor<GenericValue> valueFma; public SetCurrentUserLogin(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.handleError("Deprecated - use the called service's userLogin IN attribute", simpleMethod, element); + MiniLangValidate.attributeNames(simpleMethod, element, "value-field"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - GenericValue userLogin = valueAcsr.get(methodContext); + GenericValue userLogin = valueFma.get(methodContext.getEnvMap()); if (userLogin == null) { - Debug.logWarning("In SetCurrentUserLogin a value was not found with the specified valueName: " + valueAcsr + ", not setting", module); - return true; + throw new MiniLangRuntimeException("Entity value not found with name: " + valueFma, this); } methodContext.setUserLogin(userLogin, this.simpleMethod.getUserLoginEnvName()); return true; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - // TODO: something more than the empty tag - return "<set-current-user-login/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<set-current-user-login "); + sb.append("value-field=\"").append(this.valueFma).append("\" />"); + return sb.toString(); } + /** + * A factory for the <set-current-user-login> element. + */ public static final class SetCurrentUserLoginFactory implements Factory<SetCurrentUserLogin> { + @Override public SetCurrentUserLogin createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new SetCurrentUserLogin(element, simpleMethod); } + @Override public String getName() { return "set-current-user-login"; } Modified: ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetNonpkFields.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetNonpkFields.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetNonpkFields.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetNonpkFields.java Tue Jul 10 12:05:55 2012 @@ -20,76 +20,78 @@ 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.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; /** - * Looks for each non-PK field in the named map and if it exists there it will copy it into the named value object. + * Implements the <set-nonpk-fields> element. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Csetnonpkfields%3E}}">Mini-language Reference</a> */ -public class SetNonpkFields extends MethodOperation { +public final class SetNonpkFields extends MethodOperation { - public static final String module = SetNonpkFields.class.getName(); - - ContextAccessor<Map<String, ? extends Object>> mapAcsr; - String setIfNullStr; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleMapAccessor<Map<String, ? extends Object>> mapFma; + private final FlexibleStringExpander setIfNullFse; + private final FlexibleMapAccessor<GenericValue> valueFma; public SetNonpkFields(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map"), element.getAttribute("map-name")); - setIfNullStr = element.getAttribute("set-if-null"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "set-if-null", "map"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field", "map"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field", "map"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + setIfNullFse = FlexibleStringExpander.getInstance(element.getAttribute("set-if-null")); + mapFma = FlexibleMapAccessor.getInstance(element.getAttribute("map")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - // if anything but false it will be true - boolean setIfNull = !"false".equals(methodContext.expandString(setIfNullStr)); - GenericValue value = valueAcsr.get(methodContext); + GenericValue value = valueFma.get(methodContext.getEnvMap()); if (value == null) { - String errMsg = "In set-nonpk-fields a value was not found with the specified valueAcsr: " + valueAcsr + ", not setting fields"; - 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); } - Map<String, ? extends Object> theMap = mapAcsr.get(methodContext); + Map<String, ? extends Object> theMap = mapFma.get(methodContext.getEnvMap()); if (theMap == null) { - Debug.logWarning("In set-nonpk-fields could not find map with name " + mapAcsr + ", not setting any fields", module); - } else { - value.setNonPKFields(theMap, setIfNull); + throw new MiniLangRuntimeException("Map not found with name: " + mapFma, this); } + boolean setIfNull = !"false".equals(setIfNullFse.expand(methodContext.getEnvMap())); + value.setNonPKFields(theMap, setIfNull); return true; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - // TODO: something more than the empty tag - return "<set-nonpk-fields/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<set-nonpk-fields "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + sb.append("map=\"").append(this.mapFma).append("\" "); + if (!setIfNullFse.isEmpty()) { + sb.append("set-if-null=\"").append(this.setIfNullFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <set-nonpk-fields> element. + */ public static final class SetNonpkFieldsFactory implements Factory<SetNonpkFields> { + @Override public SetNonpkFields createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new SetNonpkFields(element, simpleMethod); } + @Override public String getName() { return "set-nonpk-fields"; } Modified: ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetPkFields.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetPkFields.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetPkFields.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetPkFields.java Tue Jul 10 12:05:55 2012 @@ -20,77 +20,78 @@ 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.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; /** - * Looks for each PK field in the named map and if it exists there it will copy it into the named value object. + * Implements the <set-pk-fields> element. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Csetpkfields%3E}}">Mini-language Reference</a> */ -public class SetPkFields extends MethodOperation { +public final class SetPkFields extends MethodOperation { - public static final String module = SetPkFields.class.getName(); - - ContextAccessor<Map<String, ? extends Object>> mapAcsr; - String setIfNullStr; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleMapAccessor<Map<String, ? extends Object>> mapFma; + private final FlexibleStringExpander setIfNullFse; + private final FlexibleMapAccessor<GenericValue> valueFma; public SetPkFields(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - valueAcsr = new ContextAccessor<GenericValue>(element.getAttribute("value-field"), element.getAttribute("value-name")); - mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map"), element.getAttribute("map-name")); - setIfNullStr = element.getAttribute("set-if-null"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "value-field", "set-if-null", "map"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "value-field", "map"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "value-field", "map"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + valueFma = FlexibleMapAccessor.getInstance(element.getAttribute("value-field")); + setIfNullFse = FlexibleStringExpander.getInstance(element.getAttribute("set-if-null")); + mapFma = FlexibleMapAccessor.getInstance(element.getAttribute("map")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - // if anything but false it will be true - boolean setIfNull = !"false".equals(methodContext.expandString(setIfNullStr)); - GenericValue value = valueAcsr.get(methodContext); + GenericValue value = valueFma.get(methodContext.getEnvMap()); if (value == null) { - String errMsg = "In set-pk-fields a value was not found with the specified valueAcsr: " + valueAcsr + ", not setting fields"; - - 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); } - Map<String, ? extends Object> theMap = mapAcsr.get(methodContext); + Map<String, ? extends Object> theMap = mapFma.get(methodContext.getEnvMap()); if (theMap == null) { - Debug.logWarning("In set-pk-fields could not find map with name " + mapAcsr + ", not setting any fields", module); - } else { - value.setPKFields(theMap, setIfNull); + throw new MiniLangRuntimeException("Map not found with name: " + mapFma, this); } + boolean setIfNull = !"false".equals(setIfNullFse.expand(methodContext.getEnvMap())); + value.setPKFields(theMap, setIfNull); return true; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - // TODO: something more than the empty tag - return "<set-pk-fields/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<set-pk-fields "); + sb.append("value-field=\"").append(this.valueFma).append("\" "); + sb.append("map=\"").append(this.mapFma).append("\" "); + if (!setIfNullFse.isEmpty()) { + sb.append("set-if-null=\"").append(this.setIfNullFse).append("\" "); + } + sb.append("/>"); + return sb.toString(); } + /** + * A factory for the <set-pk-fields> element. + */ public static final class SetPkFieldsFactory implements Factory<SetPkFields> { + @Override public SetPkFields createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new SetPkFields(element, simpleMethod); } + @Override public String getName() { return "set-pk-fields"; } Modified: ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreList.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreList.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreList.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreList.java Tue Jul 10 12:05:55 2012 @@ -21,73 +21,81 @@ 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 store the specified value object list in the datasource + * Implements the <store-list> element. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Cstorelist%3E}}">Mini-language Reference</a> */ -public class StoreList extends MethodOperation { +public final class StoreList extends MethodOperation { public static final String module = StoreList.class.getName(); - String doCacheClearStr; - ContextAccessor<List<GenericValue>> listAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleMapAccessor<List<GenericValue>> listFma; public StoreList(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(methodContext.expandString(doCacheClearStr)); - List<GenericValue> values = listAcsr.get(methodContext); + List<GenericValue> values = listFma.get(methodContext.getEnvMap()); if (values == null) { - String errMsg = "In store-list a value list was not found with the specified listAcsr: " + listAcsr + ", not storing"; - Debug.logInfo(errMsg, module); + throw new MiniLangRuntimeException("Entity value list not found with name: " + listFma, this); } + boolean doCacheClear = !"false".equals(doCacheClearFse.expandString(methodContext.getEnvMap())); try { methodContext.getDelegator().storeAll(values, doCacheClear); } catch (GenericEntityException e) { - Debug.logError(e, module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem storing 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 storing entities: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - // TODO: something more than the empty tag - return "<store-list/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<store-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 <store-list> element. + */ public static final class StoreListFactory implements Factory<StoreList> { + @Override public StoreList createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new StoreList(element, simpleMethod); } + @Override public String getName() { return "store-list"; } Modified: ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java Tue Jul 10 12:05:55 2012 @@ -19,77 +19,81 @@ 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 store the specified value object entity in the datasource + * Implements the <store-value> element. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Cstorevalue%3E}}">Mini-language Reference</a> */ -public class StoreValue extends MethodOperation { +public final class StoreValue extends MethodOperation { public static final String module = StoreValue.class.getName(); - String doCacheClearStr; - ContextAccessor<GenericValue> valueAcsr; + private final FlexibleStringExpander doCacheClearFse; + private final FlexibleMapAccessor<GenericValue> valueFma; public StoreValue(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 = null; - try { - value = valueAcsr.get(methodContext); - } catch (ClassCastException e) { - String errMsg = "In store-value the value specified by valueAcsr [" + valueAcsr + "] was not an instance of GenericValue, not storing"; - Debug.logError(errMsg, module); - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; - } + GenericValue value = valueFma.get(methodContext.getEnvMap()); if (value == null) { - String errMsg = "In store-value a value was not found with the specified valueAcsr: " + valueAcsr + ", not storing"; - 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().store(value, doCacheClear); } catch (GenericEntityException e) { - Debug.logError(e, module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [problem storing the " + valueAcsr + " value: " + e.getMessage() + "]"; - methodContext.setErrorReturn(errMsg, simpleMethod); + String errMsg = "Exception thrown while storing entity value: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } return true; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - // TODO: something more than the empty tag - return "<store-value/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<store-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 <store-value> element. + */ public static final class StoreValueFactory implements Factory<StoreValue> { + @Override public StoreValue createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new StoreValue(element, simpleMethod); } + @Override public String getName() { return "store-value"; } Modified: ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionBegin.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionBegin.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionBegin.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionBegin.java Tue Jul 10 12:05:55 2012 @@ -19,27 +19,35 @@ package org.ofbiz.minilang.method.entityops; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.entity.transaction.GenericTransactionException; import org.ofbiz.entity.transaction.TransactionUtil; 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; /** - * Begins a transaction if one is not already in place; if does begin one puts true in the began-transaction-name env variable, otherwise it returns false. + * Implements the <transaction-begin> element. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Ctransactionbegin%3E}}">Mini-language Reference</a> */ -public class TransactionBegin extends MethodOperation { +public final class TransactionBegin extends MethodOperation { public static final String module = TransactionBegin.class.getName(); - ContextAccessor<Boolean> beganTransactionAcsr; + private final FlexibleMapAccessor<Boolean> beganTransactionFma; public TransactionBegin(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - beganTransactionAcsr = new ContextAccessor<Boolean>(element.getAttribute("began-transaction-name"), "beganTransaction"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "began-transaction-name"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "began-transaction-name"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + beganTransactionFma = FlexibleMapAccessor.getInstance(MiniLangValidate.checkAttribute(element.getAttribute("began-transaction-name"), "beganTransaction")); } @Override @@ -48,32 +56,32 @@ public class TransactionBegin extends Me try { beganTransaction = TransactionUtil.begin(); } catch (GenericTransactionException e) { - Debug.logError(e, "Could not begin transaction in simple-method, returning error.", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [error beginning a transaction: " + e.getMessage() + "]"; - methodContext.setErrorReturn(errMsg, simpleMethod); + String errMsg = "Exception thrown while beginning transaction: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } - beganTransactionAcsr.put(methodContext, beganTransaction); + beganTransactionFma.put(methodContext.getEnvMap(), beganTransaction); return true; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - // TODO: something more than the empty tag - return "<transaction-begin/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<transaction-begin "); + sb.append("began-transaction-name=\"").append(this.beganTransactionFma).append("\" />"); + return sb.toString(); } + /** + * A factory for the <transaction-begin> element. + */ public static final class TransactionBeginFactory implements Factory<TransactionBegin> { + @Override public TransactionBegin createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new TransactionBegin(element, simpleMethod); } + @Override public String getName() { return "transaction-begin"; } Modified: ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionCommit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionCommit.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionCommit.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionCommit.java Tue Jul 10 12:05:55 2012 @@ -19,65 +19,73 @@ package org.ofbiz.minilang.method.entityops; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.entity.transaction.GenericTransactionException; import org.ofbiz.entity.transaction.TransactionUtil; 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; /** - * Commits a transaction if beganTransaction is true, otherwise does nothing. + * Implements the <transaction-commit> element. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Ctransactioncommit%3E}}">Mini-language Reference</a> */ -public class TransactionCommit extends MethodOperation { +public final class TransactionCommit extends MethodOperation { public static final String module = TransactionCommit.class.getName(); - ContextAccessor<Boolean> beganTransactionAcsr; + private final FlexibleMapAccessor<Boolean> beganTransactionFma; public TransactionCommit(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - beganTransactionAcsr = new ContextAccessor<Boolean>(element.getAttribute("began-transaction-name"), "beganTransaction"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "began-transaction-name"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "began-transaction-name"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + beganTransactionFma = FlexibleMapAccessor.getInstance(MiniLangValidate.checkAttribute(element.getAttribute("began-transaction-name"), "beganTransaction")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { boolean beganTransaction = false; - Boolean beganTransactionBoolean = beganTransactionAcsr.get(methodContext); + Boolean beganTransactionBoolean = beganTransactionFma.get(methodContext.getEnvMap()); if (beganTransactionBoolean != null) { beganTransaction = beganTransactionBoolean.booleanValue(); } try { TransactionUtil.commit(beganTransaction); } catch (GenericTransactionException e) { - Debug.logError(e, "Could not commit transaction in simple-method, returning error.", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [error committing a transaction: " + e.getMessage() + "]"; - methodContext.setErrorReturn(errMsg, simpleMethod); + String errMsg = "Exception thrown while committing transaction: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } - beganTransactionAcsr.remove(methodContext); + beganTransactionFma.remove(methodContext.getEnvMap()); return true; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - // TODO: something more than the empty tag - return "<transaction-commit/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<transaction-commit "); + sb.append("began-transaction-name=\"").append(this.beganTransactionFma).append("\" />"); + return sb.toString(); } + /** + * A factory for the <transaction-commit> element. + */ public static final class TransactionCommitFactory implements Factory<TransactionCommit> { + @Override public TransactionCommit createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new TransactionCommit(element, simpleMethod); } + @Override public String getName() { return "transaction-commit"; } Modified: ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionRollback.java URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionRollback.java?rev=1359626&r1=1359625&r2=1359626&view=diff ============================================================================== --- ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionRollback.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionRollback.java Tue Jul 10 12:05:55 2012 @@ -19,65 +19,73 @@ package org.ofbiz.minilang.method.entityops; import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; import org.ofbiz.entity.transaction.GenericTransactionException; import org.ofbiz.entity.transaction.TransactionUtil; 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; /** - * Rolls back a transaction if beganTransaction is true, otherwise tries to do a setRollbackOnly. + * Implements the <transaction-rollback> element. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Ctransactionrollback%3E}}">Mini-language Reference</a> */ -public class TransactionRollback extends MethodOperation { +public final class TransactionRollback extends MethodOperation { public static final String module = TransactionRollback.class.getName(); - ContextAccessor<Boolean> beganTransactionAcsr; + private final FlexibleMapAccessor<Boolean> beganTransactionFma; public TransactionRollback(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - beganTransactionAcsr = new ContextAccessor<Boolean>(element.getAttribute("began-transaction-name"), "beganTransaction"); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "began-transaction-name"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "began-transaction-name"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + beganTransactionFma = FlexibleMapAccessor.getInstance(MiniLangValidate.checkAttribute(element.getAttribute("began-transaction-name"), "beganTransaction")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { boolean beganTransaction = false; - Boolean beganTransactionBoolean = beganTransactionAcsr.get(methodContext); + Boolean beganTransactionBoolean = beganTransactionFma.get(methodContext.getEnvMap()); if (beganTransactionBoolean != null) { beganTransaction = beganTransactionBoolean.booleanValue(); } try { TransactionUtil.rollback(beganTransaction, "Explicit rollback in simple-method [" + this.simpleMethod.getShortDescription() + "]", null); } catch (GenericTransactionException e) { - Debug.logError(e, "Could not rollback transaction in simple-method, returning error.", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [error rolling back a transaction: " + e.getMessage() + "]"; - methodContext.setErrorReturn(errMsg, simpleMethod); + String errMsg = "Exception thrown while rolling back transaction: " + e.getMessage(); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } - beganTransactionAcsr.remove(methodContext); + beganTransactionFma.remove(methodContext.getEnvMap()); return true; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - // TODO: something more than the empty tag - return "<transaction-rollback/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<transaction-rollback "); + sb.append("began-transaction-name=\"").append(this.beganTransactionFma).append("\" />"); + return sb.toString(); } + /** + * A factory for the <transaction-rollback> element. + */ public static final class TransactionRollbackFactory implements Factory<TransactionRollback> { + @Override public TransactionRollback createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new TransactionRollback(element, simpleMethod); } + @Override public String getName() { return "transaction-rollback"; } Copied: ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/envops/AddError.java (from r1335018, ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/AddError.java) URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/envops/AddError.java?p2=ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/envops/AddError.java&p1=ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/AddError.java&r1=1335018&r2=1359626&rev=1359626&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/AddError.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/envops/AddError.java Tue Jul 10 12:05:55 2012 @@ -22,26 +22,24 @@ import java.util.List; import javolution.util.FastList; -import org.ofbiz.base.util.UtilProperties; -import org.ofbiz.base.util.UtilXml; 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.MessageElement; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodOperation; import org.w3c.dom.Element; /** - * Adds an error message to an error message list. - */ + * Implements the <add-error> element. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Cadderror%3E}}">Mini-language Reference</a> +*/ public final class AddError extends MethodOperation { private final FlexibleMapAccessor<List<String>> errorListFma; - private final FlexibleStringExpander messageFse; - private final String propertykey; - private final String propertyResource; + private final MessageElement messageElement; public AddError(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); @@ -52,86 +50,49 @@ public final class AddError extends Meth MiniLangValidate.requireAnyChildElement(simpleMethod, element, "fail-message", "fail-property"); } errorListFma = FlexibleMapAccessor.getInstance(MiniLangValidate.checkAttribute(element.getAttribute("error-list-name"), "error_list")); - Element childElement = UtilXml.firstChildElement(element, "fail-message"); - if (childElement != null) { - if (MiniLangValidate.validationOn()) { - MiniLangValidate.attributeNames(simpleMethod, childElement, "message"); - MiniLangValidate.requiredAttributes(simpleMethod, childElement, "message"); - MiniLangValidate.constantPlusExpressionAttributes(simpleMethod, childElement, "message"); - } - this.messageFse = FlexibleStringExpander.getInstance(childElement.getAttribute("message")); - this.propertykey = null; - this.propertyResource = null; - } else { - childElement = UtilXml.firstChildElement(element, "fail-property"); - if (childElement != null) { - if (MiniLangValidate.validationOn()) { - MiniLangValidate.attributeNames(simpleMethod, childElement, "property", "resource"); - MiniLangValidate.requiredAttributes(simpleMethod, childElement, "property", "resource"); - MiniLangValidate.constantAttributes(simpleMethod, childElement, "property", "resource"); - } - this.messageFse = FlexibleStringExpander.getInstance(null); - this.propertykey = childElement.getAttribute("property"); - this.propertyResource = childElement.getAttribute("resource"); - } else { - this.messageFse = FlexibleStringExpander.getInstance(null); - this.propertykey = null; - this.propertyResource = null; - } - } + messageElement = MessageElement.fromParentElement(element, simpleMethod); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - String message = null; - if (!this.messageFse.isEmpty()) { - message = this.messageFse.expandString(methodContext.getEnvMap()); - } else if (this.propertyResource != null) { - message = UtilProperties.getMessage(this.propertyResource, this.propertykey, methodContext.getEnvMap(), methodContext.getLocale()); - } - if (message != null) { - List<String> messages = errorListFma.get(methodContext.getEnvMap()); - if (messages == null) { - messages = FastList.newInstance(); + if (messageElement != null) { + String message = messageElement.getMessage(methodContext); + if (message != null) { + List<String> messages = errorListFma.get(methodContext.getEnvMap()); + if (messages == null) { + messages = FastList.newInstance(); + errorListFma.put(methodContext.getEnvMap(), messages); + } + messages.add(message); } - errorListFma.put(methodContext.getEnvMap(), messages); - messages.add(message); } return true; } @Override - public String expandedString(MethodContext methodContext) { - return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); - } - - @Override - public String rawString() { - return toString(); - } - - @Override public String toString() { StringBuilder sb = new StringBuilder("<add-error "); if (!"error_list".equals(this.errorListFma.getOriginalName())) { sb.append("error-list-name=\"").append(this.errorListFma).append("\""); } - sb.append(">"); - if (!this.messageFse.isEmpty()) { - sb.append("<fail-message message=\"").append(this.messageFse).append("\" />"); - } - if (this.propertykey != null) { - sb.append("<fail-property property=\"").append(this.propertykey).append(" resource=\"").append(this.propertyResource).append("\" />"); + if (messageElement != null) { + sb.append(">").append(messageElement).append("</add-error>"); + } else { + sb.append("/>"); } - sb.append("</add-error>"); return sb.toString(); } + /** + * A factory for the <add-error> element. + */ public static final class AddErrorFactory implements Factory<AddError> { + @Override public AddError createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new AddError(element, simpleMethod); } + @Override public String getName() { return "add-error"; } Copied: ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java (from r1334997, ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java) URL: http://svn.apache.org/viewvc/ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java?p2=ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java&p1=ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java&r1=1334997&r2=1359626&rev=1359626&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java (original) +++ ofbiz/branches/release12.04/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java Tue Jul 10 12:05:55 2012 @@ -37,7 +37,9 @@ import org.ofbiz.minilang.method.conditi import org.w3c.dom.Element; /** - * Adds an error to the error list for each condition that evaluates to false. + * Implements the <assert> element. + * + * @see <a href="https://cwiki.apache.org/OFBADMIN/mini-language-reference.html#Mini-languageReference-{{%3Cassert%3E}}">Mini-language Reference</a> */ public final class Assert extends MethodOperation { @@ -68,11 +70,10 @@ public final class Assert extends Method @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - List<Object> messages = errorListFma.get(methodContext.getEnvMap()); - if (messages == null) { - messages = FastList.newInstance(); - errorListFma.put(methodContext.getEnvMap(), messages); + if (methodContext.isTraceOn()) { + outputTraceMessage(methodContext, "Begin assert."); } + List<Object> messages = errorListFma.get(methodContext.getEnvMap()); String title = titleExdr.expandString(methodContext.getEnvMap()); for (Conditional condition : conditionalList) { if (!condition.checkCondition(methodContext)) { @@ -84,39 +85,48 @@ public final class Assert extends Method } messageBuffer.append("failed: "); condition.prettyPrint(messageBuffer, methodContext); + if (messages == null) { + messages = FastList.newInstance(); + errorListFma.put(methodContext.getEnvMap(), messages); + } messages.add(messageBuffer.toString()); + if (methodContext.isTraceOn()) { + outputTraceMessage(methodContext, "Condition evaluated to false: " + condition + ", adding error message."); + } } } + if (methodContext.isTraceOn()) { + outputTraceMessage(methodContext, "End assert."); + } return true; } @Override - public String expandedString(MethodContext methodContext) { - String title = titleExdr.expandString(methodContext.getEnvMap()); + public String toString() { StringBuilder messageBuf = new StringBuilder("<assert"); - if (!title.isEmpty()) { + if (!titleExdr.isEmpty()) { messageBuf.append(" title=\""); - messageBuf.append(title); + messageBuf.append(titleExdr); messageBuf.append("\""); } messageBuf.append(">"); for (Conditional condition : conditionalList) { - condition.prettyPrint(messageBuf, methodContext); + messageBuf.append(condition); } messageBuf.append("</assert>"); return messageBuf.toString(); } - @Override - public String rawString() { - return expandedString(null); - } - + /** + * A factory for the <assert> element. + */ public static final class AssertFactory implements Factory<Assert> { + @Override public Assert createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new Assert(element, simpleMethod); } + @Override public String getName() { return "assert"; } |
| Free forum by Nabble | Edit this page |
