use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class ValidateMethodCondition method checkCondition.
@Override
public boolean checkCondition(MethodContext methodContext) throws MiniLangException {
Object fieldVal = fieldFma.get(methodContext.getEnvMap());
if (fieldVal == null) {
fieldVal = "";
} else if (!(fieldVal instanceof String)) {
try {
fieldVal = MiniLangUtil.convertType(fieldVal, String.class, methodContext.getLocale(), methodContext.getTimeZone(), null);
} catch (Exception e) {
throw new MiniLangRuntimeException(e, this);
}
}
Object[] params = new Object[] { fieldVal };
try {
Class<?> valClass = methodContext.getLoader().loadClass(className);
Method valMethod = valClass.getMethod(methodName, paramTypes);
Boolean resultBool = (Boolean) valMethod.invoke(null, params);
return resultBool.booleanValue();
} catch (Exception e) {
throw new MiniLangRuntimeException(e, this);
}
}
use of org.apache.ofbiz.minilang.MiniLangException in project ofbiz-framework by apache.
the class CreateObject method exec.
@Override
public boolean exec(MethodContext methodContext) throws MiniLangException {
Object[] args = null;
Class<?>[] parameterTypes = null;
if (parameters != null) {
args = new Object[parameters.size()];
parameterTypes = new Class<?>[parameters.size()];
int i = 0;
for (MethodObject<?> methodObjectDef : parameters) {
args[i] = methodObjectDef.getObject(methodContext);
Class<?> typeClass = null;
try {
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.logWarning(e, errMsg, module);
simpleMethod.addErrorMessage(methodContext, errMsg);
return false;
}
parameterTypes[i] = typeClass;
i++;
}
}
try {
Constructor<?> constructor = targetClass.getConstructor(parameterTypes);
fieldFma.put(methodContext.getEnvMap(), constructor.newInstance(args));
} catch (Exception e) {
throw new MiniLangRuntimeException(e, this);
}
return true;
}
use of org.apache.ofbiz.minilang.MiniLangException 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.MiniLangException in project ofbiz-framework by apache.
the class SimpleEventHandler method invoke.
/**
* @see org.apache.ofbiz.webapp.event.EventHandler#invoke(ConfigXMLReader.Event, ConfigXMLReader.RequestMap, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
*/
public String invoke(Event event, RequestMap requestMap, HttpServletRequest request, HttpServletResponse response) throws EventHandlerException {
boolean beganTransaction = false;
String xmlResource = event.path;
String eventName = event.invoke;
Locale locale = UtilHttp.getLocale(request);
if (Debug.verboseOn())
Debug.logVerbose("[Set path/method]: " + xmlResource + " / " + eventName, module);
if (xmlResource == null) {
throw new EventHandlerException("XML Resource (eventPath) cannot be null");
}
if (eventName == null) {
throw new EventHandlerException("Event Name (eventMethod) cannot be null");
}
if (Debug.verboseOn())
Debug.logVerbose("[Processing]: SIMPLE Event", module);
try {
beganTransaction = TransactionUtil.begin();
String eventReturn = SimpleMethod.runSimpleEvent(xmlResource, eventName, request, response);
if (Debug.verboseOn())
Debug.logVerbose("[Event Return]: " + eventReturn, module);
return eventReturn;
} catch (MiniLangException e) {
Debug.logError(e, module);
String errMsg = UtilProperties.getMessage(SimpleEventHandler.err_resource, "simpleEventHandler.event_not_completed", (locale != null ? locale : Locale.getDefault())) + ": ";
request.setAttribute("_ERROR_MESSAGE_", errMsg + e.getMessage());
return "error";
} catch (GenericTransactionException e) {
Debug.logError(e, module);
return "error";
} finally {
try {
TransactionUtil.commit(beganTransaction);
} catch (GenericTransactionException e) {
Debug.logError(e, module);
}
}
}
use of org.apache.ofbiz.minilang.MiniLangException 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;
}
Aggregations