use of org.apache.ofbiz.minilang.method.envops.Break.BreakElementException in project ofbiz-framework by apache.
the class Iterate method exec.
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
if (listFma.isEmpty()) {
if (Debug.verboseOn()) {
Debug.logVerbose("Collection not found, doing nothing: " + this, module);
}
return true;
}
Object oldEntryValue = entryFma.get(methodContext.getEnvMap());
Object objList = listFma.get(methodContext.getEnvMap());
if (objList instanceof EntityListIterator) {
try (EntityListIterator eli = (EntityListIterator) objList) {
GenericValue theEntry;
while ((theEntry = eli.next()) != null) {
entryFma.put(methodContext.getEnvMap(), theEntry);
try {
for (MethodOperation methodOperation : subOps) {
if (!methodOperation.exec(methodContext)) {
return false;
}
}
} catch (MiniLangException e) {
if (e instanceof BreakElementException) {
break;
}
if (e instanceof ContinueElementException) {
continue;
}
throw e;
}
}
} catch (GenericEntityException e) {
throw new MiniLangRuntimeException("Error with entityListIterator: " + e.getMessage(), this);
}
} else if (objList instanceof Collection<?>) {
Collection<Object> theCollection = UtilGenerics.checkCollection(objList);
if (theCollection.size() == 0) {
if (Debug.verboseOn()) {
Debug.logVerbose("Collection has zero entries, doing nothing: " + this, module);
}
return true;
}
for (Object theEntry : theCollection) {
entryFma.put(methodContext.getEnvMap(), theEntry);
try {
for (MethodOperation methodOperation : subOps) {
if (!methodOperation.exec(methodContext)) {
return false;
}
}
} catch (MiniLangException e) {
if (e instanceof BreakElementException) {
break;
}
if (e instanceof ContinueElementException) {
continue;
}
throw e;
}
}
} else if (objList instanceof Iterator<?>) {
Iterator<Object> theIterator = UtilGenerics.cast(objList);
if (!theIterator.hasNext()) {
if (Debug.verboseOn()) {
Debug.logVerbose("Iterator has zero entries, doing nothing: " + this, module);
}
return true;
}
while (theIterator.hasNext()) {
Object theEntry = theIterator.next();
entryFma.put(methodContext.getEnvMap(), theEntry);
try {
for (MethodOperation methodOperation : subOps) {
if (!methodOperation.exec(methodContext)) {
return false;
}
}
} catch (MiniLangException e) {
if (e instanceof BreakElementException) {
break;
}
if (e instanceof ContinueElementException) {
continue;
}
throw e;
}
}
} else {
if (Debug.verboseOn()) {
Debug.logVerbose("Cannot iterate over a " + objList == null ? "null object" : objList.getClass().getName() + ", doing nothing: " + this, module);
}
return true;
}
entryFma.put(methodContext.getEnvMap(), oldEntryValue);
return true;
}
use of org.apache.ofbiz.minilang.method.envops.Break.BreakElementException in project ofbiz-framework by apache.
the class IterateMap method exec.
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
if (mapFma.isEmpty()) {
throw new MiniLangRuntimeException("No map specified.", this);
}
Object oldKey = keyFma.get(methodContext.getEnvMap());
Object oldValue = valueFma.get(methodContext.getEnvMap());
if (oldKey != null) {
if (Debug.verboseOn()) {
Debug.logVerbose("In iterate-map the key had a non-null value before entering the loop for the operation: " + this, module);
}
}
if (oldValue != null) {
if (Debug.verboseOn()) {
Debug.logVerbose("In iterate-map the value had a non-null value before entering the loop for the operation: " + this, module);
}
}
Map<? extends Object, ? extends Object> theMap = mapFma.get(methodContext.getEnvMap());
if (theMap == null) {
if (Debug.verboseOn()) {
Debug.logVerbose("Map not found with name " + mapFma + ", doing nothing: " + this, module);
}
return true;
}
if (theMap.size() == 0) {
if (Debug.verboseOn()) {
Debug.logVerbose("Map with name " + mapFma + " has zero entries, doing nothing: " + this, module);
}
return true;
}
for (Map.Entry<? extends Object, ? extends Object> theEntry : theMap.entrySet()) {
keyFma.put(methodContext.getEnvMap(), theEntry.getKey());
valueFma.put(methodContext.getEnvMap(), theEntry.getValue());
try {
for (MethodOperation methodOperation : subOps) {
if (!methodOperation.exec(methodContext)) {
return false;
}
}
} catch (MiniLangException e) {
if (e instanceof BreakElementException) {
break;
}
if (e instanceof ContinueElementException) {
continue;
}
throw e;
}
}
return true;
}
use of org.apache.ofbiz.minilang.method.envops.Break.BreakElementException in project ofbiz-framework by apache.
the class Loop method exec.
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
String countStr = this.countFse.expandString(methodContext.getEnvMap());
int count = 0;
try {
count = Double.valueOf(countStr).intValue();
} catch (NumberFormatException e) {
throw new MiniLangRuntimeException("Error while converting \"" + countStr + "\" to a number: " + e.getMessage(), this);
}
if (count < 0) {
throw new MiniLangRuntimeException("Unable to execute loop operation because the count is negative: " + countStr, this);
}
for (int i = 0; i < count; i++) {
this.fieldFma.put(methodContext.getEnvMap(), i);
try {
for (MethodOperation methodOperation : subOps) {
if (!methodOperation.exec(methodContext)) {
return false;
}
}
} catch (MiniLangException e) {
if (e instanceof BreakElementException) {
break;
}
if (e instanceof ContinueElementException) {
continue;
}
throw e;
}
}
return true;
}
Aggregations