|
Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetCurrentUserLogin.java
URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetCurrentUserLogin.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetCurrentUserLogin.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetCurrentUserLogin.java Mon Jul 2 20:11:49 2012 @@ -18,57 +18,62 @@ *******************************************************************************/ 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. */ -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/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetNonpkFields.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetNonpkFields.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetNonpkFields.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetNonpkFields.java Mon Jul 2 20:11:49 2012 @@ -20,76 +20,76 @@ 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. */ -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/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetPkFields.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetPkFields.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetPkFields.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/SetPkFields.java Mon Jul 2 20:11:49 2012 @@ -20,77 +20,76 @@ 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. */ -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/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreList.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreList.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreList.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreList.java Mon Jul 2 20:11:49 2012 @@ -21,73 +21,79 @@ 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. */ -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/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/StoreValue.java Mon Jul 2 20:11:49 2012 @@ -19,77 +19,79 @@ 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. */ -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/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionBegin.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionBegin.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionBegin.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionBegin.java Mon Jul 2 20:11:49 2012 @@ -19,27 +19,33 @@ 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. */ -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 +54,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/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionCommit.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionCommit.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionCommit.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionCommit.java Mon Jul 2 20:11:49 2012 @@ -19,65 +19,71 @@ 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. */ -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/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionRollback.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionRollback.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionRollback.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/entityops/TransactionRollback.java Mon Jul 2 20:11:49 2012 @@ -19,65 +19,71 @@ 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. */ -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"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/AddError.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/AddError.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/AddError.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/AddError.java Mon Jul 2 20:11:49 2012 @@ -23,7 +23,6 @@ import java.util.List; import javolution.util.FastList; 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; @@ -69,16 +68,6 @@ public final class AddError extends Meth } @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())) { Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Assert.java Mon Jul 2 20:11:49 2012 @@ -91,11 +91,6 @@ public final class Assert extends Method } @Override - public String expandedString(MethodContext methodContext) { - return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); - } - - @Override public String toString() { StringBuilder messageBuf = new StringBuilder("<assert"); if (!titleExdr.isEmpty()) { @@ -111,11 +106,6 @@ public final class Assert extends Method return messageBuf.toString(); } - @Override - public String rawString() { - return expandedString(null); - } - public static final class AssertFactory implements Factory<Assert> { public Assert createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new Assert(element, simpleMethod); Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Break.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Break.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Break.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Break.java Mon Jul 2 20:11:49 2012 @@ -39,12 +39,7 @@ public class Break extends MethodOperati } @Override - public String expandedString(MethodContext methodContext) { - return this.rawString(); - } - - @Override - public String rawString() { + public String toString() { return "<break/>"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckErrors.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckErrors.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckErrors.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckErrors.java Mon Jul 2 20:11:49 2012 @@ -63,11 +63,6 @@ public final class CheckErrors extends M return true; } - @Override - public String expandedString(MethodContext methodContext) { - return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); - } - private String getErrorCode(MethodContext methodContext) { String errorCode = this.errorCodeFse.expandString(methodContext.getEnvMap()); if (errorCode.length() == 0) { @@ -77,11 +72,6 @@ public final class CheckErrors extends M } @Override - public String rawString() { - return toString(); - } - - @Override public String toString() { StringBuilder sb = new StringBuilder("<check-errors "); if (!this.errorCodeFse.isEmpty()) { Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckId.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckId.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckId.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CheckId.java Mon Jul 2 20:11:49 2012 @@ -115,16 +115,6 @@ public final class CheckId extends Metho } @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("<check-id "); if (!this.fieldFma.isEmpty()) { Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/ClearField.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/ClearField.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/ClearField.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/ClearField.java Mon Jul 2 20:11:49 2012 @@ -18,70 +18,55 @@ *******************************************************************************/ package org.ofbiz.minilang.method.envops; -import java.util.Map; - -import javolution.util.FastMap; - -import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; 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; /** - * Clears the specified field + * Implements the <clear-field> element. */ -public class ClearField extends MethodOperation { +public final class ClearField extends MethodOperation { - public static final String module = ClearField.class.getName(); - - ContextAccessor<Object> fieldAcsr; - ContextAccessor<Map<String, Object>> mapAcsr; + private final FlexibleMapAccessor<Object> fieldFma; public ClearField(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - // the schema for this element now just has the "field" attribute, though the old "field-name" and "map-name" pair is still supported - fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name")); - mapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("map-name")); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "field"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "field"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "field"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - if (!mapAcsr.isEmpty()) { - Map<String, Object> toMap = mapAcsr.get(methodContext); - if (toMap == null) { - // it seems silly to create a new map, but necessary since whenever - // an env field like a Map or List is referenced it should be created, even if empty - if (Debug.verboseOn()) - Debug.logVerbose("Map not found with name " + mapAcsr + ", creating new map", module); - toMap = FastMap.newInstance(); - mapAcsr.put(methodContext, toMap); - } - fieldAcsr.put(toMap, null, methodContext); - } else { - fieldAcsr.put(methodContext, null); - } + fieldFma.put(methodContext.getEnvMap(), null); return true; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - return "<clear-field field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<set "); + sb.append("field=\"").append(this.fieldFma).append("\" />"); + return sb.toString(); } + /** + * A factory for the <clear-field> element. + */ public static final class ClearFieldFactory implements Factory<ClearField> { + @Override public ClearField createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new ClearField(element, simpleMethod); } + @Override public String getName() { return "clear-field"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Continue.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Continue.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Continue.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Continue.java Mon Jul 2 20:11:49 2012 @@ -39,12 +39,7 @@ public class Continue extends MethodOper } @Override - public String expandedString(MethodContext methodContext) { - return this.rawString(); - } - - @Override - public String rawString() { + public String toString() { return "<continue/>"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/CreateObject.java Mon Jul 2 20:11:49 2012 @@ -19,19 +19,18 @@ package org.ofbiz.minilang.method.envops; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import java.util.Map; - -import javolution.util.FastList; -import javolution.util.FastMap; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.ObjectType; import org.ofbiz.base.util.UtilXml; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; 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.FieldObject; import org.ofbiz.minilang.method.MethodContext; import org.ofbiz.minilang.method.MethodObject; @@ -40,57 +39,54 @@ import org.ofbiz.minilang.method.StringO import org.w3c.dom.Element; /** - * Creates a Java object using the given fields as parameters + * Implements the <create-object> element. */ -public class CreateObject extends MethodOperation { +public final class CreateObject extends MethodOperation { public static final String module = CreateObject.class.getName(); - String className; - ContextAccessor<Object> fieldAcsr; - ContextAccessor<Map<String, Object>> mapAcsr; - /** A list of MethodObject objects to use as the method call parameters */ - List<MethodObject<?>> parameters; + private final String className; + private final Class<?> targetClass; + private final FlexibleMapAccessor<Object> fieldFma; + private final List<MethodObject<?>> parameters; public CreateObject(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.handleError("<create-object> element is deprecated (use <script>)", simpleMethod, element); + MiniLangValidate.attributeNames(simpleMethod, element, "class-name", "field"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "field"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "class-name", "field"); + MiniLangValidate.childElements(simpleMethod, element, "string", "field"); + } className = element.getAttribute("class-name"); - // the schema for this element now just has the "field" attribute, though the old - // "field-name" and "map-name" pair is still supported - fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name")); - mapAcsr = new ContextAccessor<Map<String, Object>>(element.getAttribute("map-name")); + Class<?> targetClass = null; + try { + targetClass = ObjectType.loadClass(this.className); + } catch (ClassNotFoundException e) { + MiniLangValidate.handleError("Class not found with name " + this.className, simpleMethod, element); + } + this.targetClass = targetClass; + fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field")); List<? extends Element> parameterElements = UtilXml.childElementList(element); if (parameterElements.size() > 0) { - parameters = FastList.newInstance(); + ArrayList<MethodObject<?>> parameterList = new ArrayList<MethodObject<?>>(parameterElements.size()); for (Element parameterElement : parameterElements) { - MethodObject<?> methodObject = null; if ("string".equals(parameterElement.getNodeName())) { - methodObject = new StringObject(parameterElement, simpleMethod); + parameterList.add(new StringObject(parameterElement, simpleMethod)); } else if ("field".equals(parameterElement.getNodeName())) { - methodObject = new FieldObject<Object>(parameterElement, simpleMethod); - } else { - // whoops, invalid tag here, print warning - Debug.logWarning("Found an unsupported tag under the call-object-method tag: " + parameterElement.getNodeName() + "; ignoring", module); - } - if (methodObject != null) { - parameters.add(methodObject); + parameterList.add(new FieldObject<Object>(parameterElement, simpleMethod)); } } + parameterList.trimToSize(); + this.parameters = Collections.unmodifiableList(parameterList); + } else { + this.parameters = null; } } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - String className = methodContext.expandString(this.className); - Class<?> methodClass = null; - try { - methodClass = ObjectType.loadClass(className, methodContext.getLoader()); - } catch (ClassNotFoundException e) { - Debug.logError(e, "Class to create not found with name " + className + " in create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Class to create not found with name " + className + ": " + e.toString() + "]"; - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; - } Object[] args = null; Class<?>[] parameterTypes = null; if (parameters != null) { @@ -104,8 +100,8 @@ public class CreateObject extends Method typeClass = methodObjectDef.getTypeClass(methodContext); } catch (ClassNotFoundException e) { String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Parameter type not found with name " + methodObjectDef.getTypeName() + "]"; - Debug.logError(errMsg, module); - methodContext.setErrorReturn(errMsg, simpleMethod); + Debug.logWarning(e, errMsg, module); + simpleMethod.addErrorMessage(methodContext, errMsg); return false; } parameterTypes[i] = typeClass; @@ -113,75 +109,32 @@ public class CreateObject extends Method } } try { - Constructor<?> constructor = methodClass.getConstructor(parameterTypes); - try { - Object newObject = constructor.newInstance(args); - // if fieldAcsr is empty, ignore return value - if (!fieldAcsr.isEmpty()) { - if (!mapAcsr.isEmpty()) { - Map<String, Object> retMap = mapAcsr.get(methodContext); - if (retMap == null) { - retMap = FastMap.newInstance(); - mapAcsr.put(methodContext, retMap); - } - fieldAcsr.put(retMap, newObject, methodContext); - } else { - // no map name, use the env - fieldAcsr.put(methodContext, newObject); - } - } - } catch (InstantiationException e) { - Debug.logError(e, "Could not instantiate object in create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Could not instantiate object: " + e.toString() + "]"; - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; - } catch (IllegalAccessException e) { - Debug.logError(e, "Illegal access constructing object in create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Illegal access constructing object: " + e.toString() + "]"; - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; - } catch (IllegalArgumentException e) { - Debug.logError(e, "Illegal argument calling method in create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Illegal argument calling constructor: " + e.toString() + "]"; - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; - } catch (InvocationTargetException e) { - Debug.logError(e.getTargetException(), "Constructor in create-object operation threw an exception", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Constructor in create-object threw an exception: " + e.getTargetException() + "]"; - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; - } - } catch (NoSuchMethodException e) { - Debug.logError(e, "Could not find constructor to execute in simple-method create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Could not find constructor to execute: " + e.toString() + "]"; - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; - } catch (SecurityException e) { - Debug.logError(e, "Security exception finding constructor to execute in simple-method create-object operation", module); - String errMsg = "ERROR: Could not complete the " + simpleMethod.getShortDescription() + " process [Security exception finding constructor to execute: " + e.toString() + "]"; - methodContext.setErrorReturn(errMsg, simpleMethod); - return false; + Constructor<?> constructor = targetClass.getConstructor(parameterTypes); + fieldFma.put(methodContext.getEnvMap(),constructor.newInstance(args)); + } catch (Exception e) { + throw new MiniLangRuntimeException(e, this); } 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 "<create-object/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<create-object "); + sb.append("class-name=\"").append(this.className).append("\" "); + sb.append("field=\"").append(this.fieldFma).append("\" />"); + return sb.toString(); } + /** + * A factory for the <create-object> element. + */ public static final class CreateObjectFactory implements Factory<CreateObject> { + @Override public CreateObject createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new CreateObject(element, simpleMethod); } + @Override public String getName() { return "create-object"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/FieldToList.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/FieldToList.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/FieldToList.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/FieldToList.java Mon Jul 2 20:11:49 2012 @@ -19,82 +19,70 @@ package org.ofbiz.minilang.method.envops; import java.util.List; -import java.util.Map; import javolution.util.FastList; -import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; 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; /** - * Copies an environment field to a list + * Implements the <field-to-list> element. */ -public class FieldToList extends MethodOperation { +public final class FieldToList extends MethodOperation { - public static final String module = FieldToList.class.getName(); - - ContextAccessor<Object> fieldAcsr; - ContextAccessor<List<Object>> listAcsr; - ContextAccessor<Map<String, ? extends Object>> mapAcsr; + private final FlexibleMapAccessor<Object> fieldFma; + private final FlexibleMapAccessor<List<Object>> listFma; public FieldToList(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - // the schema for this element now just has the "field" attribute, though the old "field-name" and "map-name" pair is still supported - mapAcsr = new ContextAccessor<Map<String, ? extends Object>>(element.getAttribute("map-name")); - fieldAcsr = new ContextAccessor<Object>(element.getAttribute("field"), element.getAttribute("field-name")); - listAcsr = new ContextAccessor<List<Object>>(element.getAttribute("list"), element.getAttribute("list-name")); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.handleError("<field-to-list> element is deprecated (use <set>)", simpleMethod, element); + MiniLangValidate.attributeNames(simpleMethod, element, "field", "list"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "field", "list"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "field", "list"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field")); + listFma = FlexibleMapAccessor.getInstance(element.getAttribute("list")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - Object fieldVal = null; - if (!mapAcsr.isEmpty()) { - Map<String, ? extends Object> fromMap = mapAcsr.get(methodContext); - if (fromMap == null) { - Debug.logWarning("Map not found with name " + mapAcsr + ", Not copying to list", module); - return true; + Object fieldVal = fieldFma.get(methodContext.getEnvMap()); + if (fieldVal != null) { + List<Object> toList = listFma.get(methodContext.getEnvMap()); + if (toList == null) { + toList = FastList.newInstance(); + listFma.put(methodContext.getEnvMap(), toList); } - fieldVal = fieldAcsr.get(fromMap, methodContext); - } else { - // no map name, try the env - fieldVal = fieldAcsr.get(methodContext); - } - if (fieldVal == null) { - Debug.logWarning("Field value not found with name " + fieldAcsr + " in Map with name " + mapAcsr + ", Not copying to list", module); - return true; - } - List<Object> toList = listAcsr.get(methodContext); - if (toList == null) { - if (Debug.verboseOn()) - Debug.logVerbose("List not found with name " + listAcsr + ", creating new list", module); - toList = FastList.newInstance(); - listAcsr.put(methodContext, toList); + toList.add(fieldVal); } - toList.add(fieldVal); return true; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - return "<field-to-list list-name=\"" + this.listAcsr + "\" field-name=\"" + this.fieldAcsr + "\" map-name=\"" + this.mapAcsr + "\"/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<field-to-list "); + sb.append("field=\"").append(this.fieldFma).append("\" "); + sb.append("list=\"").append(this.listFma).append("\" />"); + return sb.toString(); } + /** + * A factory for the <field-to-list> element. + */ public static final class FieldToListFactory implements Factory<FieldToList> { + @Override public FieldToList createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new FieldToList(element, simpleMethod); } + @Override public String getName() { return "field-to-list"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/FirstFromList.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/FirstFromList.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/FirstFromList.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/FirstFromList.java Mon Jul 2 20:11:49 2012 @@ -20,62 +20,65 @@ package org.ofbiz.minilang.method.envops import java.util.List; -import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilValidate; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; 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; /** - * Get the first entry from the list + * Implements the <first-from-list> element. */ -public class FirstFromList extends MethodOperation { +public final class FirstFromList extends MethodOperation { - public static final String module = FirstFromList.class.getName(); - - ContextAccessor<Object> entryAcsr; - ContextAccessor<List<? extends Object>> listAcsr; + private final FlexibleMapAccessor<Object> entryFma; + private final FlexibleMapAccessor<List<Object>> listFma; public FirstFromList(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - this.entryAcsr = new ContextAccessor<Object>(element.getAttribute("entry"), element.getAttribute("entry-name")); - this.listAcsr = new ContextAccessor<List<? extends Object>>(element.getAttribute("list"), element.getAttribute("list-name")); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.handleError("<first-from-list> element is deprecated (use <set>)", simpleMethod, element); + MiniLangValidate.attributeNames(simpleMethod, element, "entry", "list"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "entry", "list"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "entry", "list"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + entryFma = FlexibleMapAccessor.getInstance(element.getAttribute("entry")); + listFma = FlexibleMapAccessor.getInstance(element.getAttribute("list")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - if (listAcsr.isEmpty()) { - Debug.logWarning("No list-name specified in iterate tag, doing nothing", module); - return true; - } - List<? extends Object> theList = listAcsr.get(methodContext); + List<? extends Object> theList = listFma.get(methodContext.getEnvMap()); if (UtilValidate.isEmpty(theList)) { - entryAcsr.put(methodContext, null); - return true; + entryFma.put(methodContext.getEnvMap(), null); + } else { + entryFma.put(methodContext.getEnvMap(), theList.get(0)); } - entryAcsr.put(methodContext, theList.get(0)); return true; } @Override - public String expandedString(MethodContext methodContext) { - // TODO: something more than a stub/dummy - return this.rawString(); - } - - @Override - public String rawString() { - return "<first-from-list list-name=\"" + this.listAcsr + "\" entry-name=\"" + this.entryAcsr + "\"/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<first-from-list "); + sb.append("entry=\"").append(this.entryFma).append("\" "); + sb.append("list=\"").append(this.listFma).append("\" />"); + return sb.toString(); } + /** + * A factory for the <first-from-list> element. + */ public static final class FirstFromListFactory implements Factory<FirstFromList> { + @Override public FirstFromList createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new FirstFromList(element, simpleMethod); } + @Override public String getName() { return "first-from-list"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Iterate.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Iterate.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Iterate.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Iterate.java Mon Jul 2 20:11:49 2012 @@ -26,7 +26,6 @@ import java.util.List; import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.UtilGenerics; 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.entity.util.EntityListIterator; @@ -163,11 +162,6 @@ public final class Iterate extends Metho } @Override - public String expandedString(MethodContext methodContext) { - return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); - } - - @Override public void gatherArtifactInfo(ArtifactInfoContext aic) { for (MethodOperation method : this.subOps) { method.gatherArtifactInfo(aic); @@ -175,11 +169,6 @@ public final class Iterate extends Metho } @Override - public String rawString() { - return toString(); - } - - @Override public String toString() { StringBuilder sb = new StringBuilder("<iterate "); if (!this.entryFma.isEmpty()) { Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/IterateMap.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/IterateMap.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/IterateMap.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/IterateMap.java Mon Jul 2 20:11:49 2012 @@ -24,7 +24,6 @@ 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.minilang.MiniLangException; import org.ofbiz.minilang.MiniLangRuntimeException; import org.ofbiz.minilang.MiniLangValidate; @@ -110,11 +109,6 @@ public final class IterateMap extends Me } @Override - public String expandedString(MethodContext methodContext) { - return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); - } - - @Override public void gatherArtifactInfo(ArtifactInfoContext aic) { for (MethodOperation method : this.subOps) { method.gatherArtifactInfo(aic); @@ -122,11 +116,6 @@ public final class IterateMap extends Me } @Override - public String rawString() { - return toString(); - } - - @Override public String toString() { StringBuilder sb = new StringBuilder("<iterate-map "); if (!this.mapFma.isEmpty()) { Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/ListToList.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/ListToList.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/ListToList.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/ListToList.java Mon Jul 2 20:11:49 2012 @@ -22,66 +22,66 @@ import java.util.List; import javolution.util.FastList; -import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.collections.FlexibleMapAccessor; 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; /** - * Copies an environment field to a list + * Implements the <list-to-list> element. */ -public class ListToList extends MethodOperation { +public final class ListToList extends MethodOperation { - public static final String module = ListToList.class.getName(); - - ContextAccessor<List<Object>> listAcsr; - ContextAccessor<List<Object>> toListAcsr; + private final FlexibleMapAccessor<List<Object>> listFma; + private final FlexibleMapAccessor<List<Object>> toListFma; public ListToList(Element element, SimpleMethod simpleMethod) throws MiniLangException { super(element, simpleMethod); - listAcsr = new ContextAccessor<List<Object>>(element.getAttribute("list"), element.getAttribute("list-name")); - toListAcsr = new ContextAccessor<List<Object>>(element.getAttribute("to-list"), element.getAttribute("to-list-name")); + if (MiniLangValidate.validationOn()) { + MiniLangValidate.attributeNames(simpleMethod, element, "to-list", "list"); + MiniLangValidate.requiredAttributes(simpleMethod, element, "to-list", "list"); + MiniLangValidate.expressionAttributes(simpleMethod, element, "to-list", "list"); + MiniLangValidate.noChildElements(simpleMethod, element); + } + toListFma = FlexibleMapAccessor.getInstance(element.getAttribute("to-list")); + listFma = FlexibleMapAccessor.getInstance(element.getAttribute("list")); } @Override public boolean exec(MethodContext methodContext) throws MiniLangException { - List<Object> fromList = listAcsr.get(methodContext); - List<Object> toList = toListAcsr.get(methodContext); - if (fromList == null) { - if (Debug.infoOn()) - Debug.logInfo("List not found with name " + listAcsr + ", not copying list", module); - return true; - } - if (toList == null) { - if (Debug.verboseOn()) - Debug.logVerbose("List not found with name " + toListAcsr + ", creating new list", module); - toList = FastList.newInstance(); - toListAcsr.put(methodContext, toList); + List<Object> fromList = listFma.get(methodContext.getEnvMap()); + if (fromList != null) { + List<Object> toList = toListFma.get(methodContext.getEnvMap()); + if (toList == null) { + toList = FastList.newInstance(); + toListFma.put(methodContext.getEnvMap(), toList); + } + toList.addAll(fromList); } - toList.addAll(fromList); 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 "<list-to-list/>"; + public String toString() { + StringBuilder sb = new StringBuilder("<list-to-list "); + sb.append("to-list=\"").append(this.toListFma).append("\" "); + sb.append("list=\"").append(this.listFma).append("\" />"); + return sb.toString(); } + /** + * A factory for the <list-to-list> element. + */ public static final class ListToListFactory implements Factory<ListToList> { + @Override public ListToList createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException { return new ListToList(element, simpleMethod); } + @Override public String getName() { return "list-to-list"; } Modified: ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Loop.java URL: http://svn.apache.org/viewvc/ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Loop.java?rev=1356450&r1=1356449&r2=1356450&view=diff ============================================================================== --- ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Loop.java (original) +++ ofbiz/branches/20120329_portletWidget/framework/minilang/src/org/ofbiz/minilang/method/envops/Loop.java Mon Jul 2 20:11:49 2012 @@ -91,11 +91,6 @@ public final class Loop extends MethodOp } @Override - public String expandedString(MethodContext methodContext) { - return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap()); - } - - @Override public void gatherArtifactInfo(ArtifactInfoContext aic) { for (MethodOperation method : this.subOps) { method.gatherArtifactInfo(aic); @@ -103,11 +98,6 @@ public final class Loop extends MethodOp } @Override - public String rawString() { - return toString(); - } - - @Override public String toString() { StringBuilder sb = new StringBuilder("<loop "); if (!this.countFse.isEmpty()) { |
| Free forum by Nabble | Edit this page |
