📄 modeltreeaction.java
字号:
String errMsg = "Error running BSH script at location [" + location + "]: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } } else { throw new IllegalArgumentException("For tree script actions the script type is not yet support for location:" + location); } } } public static class Service extends ModelTreeAction { protected FlexibleStringExpander serviceNameExdr; protected FlexibleMapAccessor resultMapNameAcsr; protected FlexibleStringExpander autoFieldMapExdr; protected FlexibleStringExpander resultMapListNameExdr; protected FlexibleStringExpander resultMapListIteratorNameExdr; protected FlexibleStringExpander resultMapValueNameExdr; protected FlexibleStringExpander valueNameExdr; protected Map fieldMap; public Service(ModelTree.ModelNode modelNode, Element serviceElement) { super (modelNode, serviceElement); initService(serviceElement); } public Service(ModelTree.ModelNode.ModelSubNode modelSubNode, Element serviceElement) { super (modelSubNode, serviceElement); initService(serviceElement); } public void initService( Element serviceElement ) { this.serviceNameExdr = new FlexibleStringExpander(serviceElement.getAttribute("service-name")); this.resultMapNameAcsr = UtilValidate.isNotEmpty(serviceElement.getAttribute("result-map-name")) ? new FlexibleMapAccessor(serviceElement.getAttribute("result-map-name")) : null; this.autoFieldMapExdr = new FlexibleStringExpander(serviceElement.getAttribute("auto-field-map")); this.resultMapListNameExdr = new FlexibleStringExpander(serviceElement.getAttribute("result-map-list-name")); this.resultMapListIteratorNameExdr = new FlexibleStringExpander(serviceElement.getAttribute("result-map-list-iterator-name")); this.resultMapValueNameExdr = new FlexibleStringExpander(serviceElement.getAttribute("result-map-value-name")); this.valueNameExdr = new FlexibleStringExpander(serviceElement.getAttribute("value-name")); this.fieldMap = EntityFinderUtil.makeFieldMap(serviceElement); } public void runAction(Map context) { String serviceNameExpanded = this.serviceNameExdr.expandString(context); if (UtilValidate.isEmpty(serviceNameExpanded)) { throw new IllegalArgumentException("Service name was empty, expanded from: " + this.serviceNameExdr.getOriginal()); } String autoFieldMapString = this.autoFieldMapExdr.expandString(context); boolean autoFieldMapBool = !"false".equals(autoFieldMapString); try { Map serviceContext = null; if (autoFieldMapBool) { serviceContext = this.modelTree.getDispatcher().getDispatchContext().makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); } else { serviceContext = new HashMap(); } if (this.fieldMap != null) { EntityFinderUtil.expandFieldMapToContext(this.fieldMap, context, serviceContext); } Map result = this.modelTree.getDispatcher().runSync(serviceNameExpanded, serviceContext); if (this.resultMapNameAcsr != null) { this.resultMapNameAcsr.put(context, result); String queryString = (String)result.get("queryString"); context.put("queryString", queryString); context.put("queryStringMap", result.get("queryStringMap")); if (UtilValidate.isNotEmpty(queryString)){ try { String queryStringEncoded = queryString.replaceAll("&", "%26"); context.put("queryStringEncoded", queryStringEncoded); } catch (PatternSyntaxException e) { } } } else { context.putAll(result); } String resultMapListName = resultMapListNameExdr.expandString(context); String resultMapListIteratorName = resultMapListIteratorNameExdr.expandString(context); String resultMapValueName = resultMapValueNameExdr.expandString(context); String valueName = valueNameExdr.expandString(context); if (this.modelSubNode != null) { //ListIterator iter = null; if (UtilValidate.isNotEmpty(resultMapListIteratorName)) { this.modelSubNode.setListIterator((ListIterator)result.get(resultMapListIteratorName)); } else if (UtilValidate.isNotEmpty(resultMapListName)) { List lst = (List)result.get(resultMapListName); if (lst != null ) { this.modelSubNode.setListIterator(lst.listIterator()); } } } else { if (UtilValidate.isNotEmpty(resultMapValueName)) { if (UtilValidate.isNotEmpty(valueName)) { context.put(valueName, result.get(resultMapValueName)); } else { context.putAll((Map)result.get(resultMapValueName)); } } } } catch (GenericServiceException e) { String errMsg = "Error calling service with name " + serviceNameExpanded + ": " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } } } public static class EntityOne extends ModelTreeAction { protected PrimaryKeyFinder finder; String valueName; public EntityOne(ModelTree.ModelNode modelNode, Element entityOneElement) { super (modelNode, entityOneElement); this.valueName = UtilFormatOut.checkEmpty(entityOneElement.getAttribute("value-name"), null); entityOneElement.setAttribute( "value-name", this.valueName); finder = new PrimaryKeyFinder(entityOneElement); } public void runAction(Map context) { try { finder.runFind(context, this.modelTree.getDelegator()); } catch (GeneralException e) { String errMsg = "Error doing entity query by condition: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } } } public static class EntityAnd extends ModelTreeAction { protected ByAndFinder finder; String listName; public EntityAnd(ModelTree.ModelNode.ModelSubNode modelSubNode, Element entityAndElement) { super (modelSubNode, entityAndElement); boolean useCache = "true".equalsIgnoreCase(entityAndElement.getAttribute("use-cache")); Document ownerDoc = entityAndElement.getOwnerDocument(); if (!useCache) UtilXml.addChildElement(entityAndElement, "use-iterator", ownerDoc); this.listName = UtilFormatOut.checkEmpty(entityAndElement.getAttribute("list-name"), "_LIST_ITERATOR_"); entityAndElement.setAttribute( "list-name", this.listName); finder = new ByAndFinder(entityAndElement); } public void runAction(Map context) { try { context.put(this.listName, null); finder.runFind(context, this.modelTree.getDelegator()); Object obj = context.get(this.listName); if (obj != null && (obj instanceof EntityListIterator || obj instanceof ListIterator)) { this.modelSubNode.setListIterator((ListIterator)obj); } else { if (obj instanceof List) this.modelSubNode.setListIterator(((List)obj).listIterator()); } } catch (GeneralException e) { String errMsg = "Error doing entity query by condition: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } } } public static class EntityCondition extends ModelTreeAction { ByConditionFinder finder; String listName; public EntityCondition(ModelTree.ModelNode.ModelSubNode modelSubNode, Element entityConditionElement) { super (modelSubNode, entityConditionElement); Document ownerDoc = entityConditionElement.getOwnerDocument(); boolean useCache = "true".equalsIgnoreCase(entityConditionElement.getAttribute("use-cache")); if (!useCache) UtilXml.addChildElement(entityConditionElement, "use-iterator", ownerDoc); this.listName = UtilFormatOut.checkEmpty(entityConditionElement.getAttribute("list-name"), "_LIST_ITERATOR_"); entityConditionElement.setAttribute( "list-name", this.listName); finder = new ByConditionFinder(entityConditionElement); } public void runAction(Map context) { try { context.put(this.listName, null); finder.runFind(context, this.modelTree.getDelegator()); Object obj = context.get(this.listName); if (obj != null && (obj instanceof EntityListIterator || obj instanceof ListIterator)) { this.modelSubNode.setListIterator((ListIterator)obj); } else { if (obj instanceof List) this.modelSubNode.setListIterator(((List)obj).listIterator()); } } catch (GeneralException e) { String errMsg = "Error doing entity query by condition: " + e.toString(); Debug.logError(e, errMsg, module); throw new IllegalArgumentException(errMsg); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -