📄 modelmenuaction.java
字号:
} } public static class PropertyMap extends ModelMenuAction { protected FlexibleStringExpander resourceExdr; protected FlexibleMapAccessor mapNameAcsr; protected FlexibleStringExpander globalExdr; public PropertyMap(ModelMenu modelMenu, Element setElement) { super (modelMenu, setElement); this.resourceExdr = new FlexibleStringExpander(setElement.getAttribute("resource")); this.mapNameAcsr = new FlexibleMapAccessor(setElement.getAttribute("map-name")); this.globalExdr = new FlexibleStringExpander(setElement.getAttribute("global")); } public void runAction(Map context) { String globalStr = this.globalExdr.expandString(context); // default to false boolean global = "true".equals(globalStr); Locale locale = (Locale) context.get("locale"); String resource = this.resourceExdr.expandString(context, locale); Map propertyMap = UtilProperties.getResourceBundleMap(resource, locale); this.mapNameAcsr.put(context, propertyMap); if (global) { Map globalCtx = (Map) context.get("globalContext"); if (globalCtx != null) { this.mapNameAcsr.put(globalCtx, propertyMap); } } } } public static class PropertyToField extends ModelMenuAction { protected FlexibleStringExpander resourceExdr; protected FlexibleStringExpander propertyExdr; protected FlexibleMapAccessor fieldAcsr; protected FlexibleStringExpander defaultExdr; protected boolean noLocale; protected FlexibleMapAccessor argListAcsr; protected FlexibleStringExpander globalExdr; public PropertyToField(ModelMenu modelMenu, Element setElement) { super (modelMenu, setElement); this.resourceExdr = new FlexibleStringExpander(setElement.getAttribute("resource")); this.propertyExdr = new FlexibleStringExpander(setElement.getAttribute("property")); this.fieldAcsr = new FlexibleMapAccessor(setElement.getAttribute("field")); this.defaultExdr = new FlexibleStringExpander(setElement.getAttribute("default")); noLocale = "true".equals(setElement.getAttribute("no-locale")); this.argListAcsr = new FlexibleMapAccessor(setElement.getAttribute("arg-list-name")); this.globalExdr = new FlexibleStringExpander(setElement.getAttribute("global")); } public void runAction(Map context) { String globalStr = this.globalExdr.expandString(context); // default to false boolean global = "true".equals(globalStr); Locale locale = (Locale) context.get("locale"); String resource = this.resourceExdr.expandString(context, locale); String property = this.propertyExdr.expandString(context, locale); String value = null; if (noLocale) { value = UtilProperties.getPropertyValue(resource, property); } else { value = UtilProperties.getMessage(resource, property, locale); } if (value == null || value.length() == 0) { value = this.defaultExdr.expandString(context); } // note that expanding the value string here will handle defaultValue and the string from // the properties file; if we decide later that we don't want the string from the properties // file to be expanded we should just expand the defaultValue at the beginning of this method. value = FlexibleStringExpander.expandString(value, context); if (!argListAcsr.isEmpty()) { List argList = (List) argListAcsr.get(context); if (argList != null && argList.size() > 0) { value = MessageFormat.format(value, argList.toArray()); } } fieldAcsr.put(context, value); } } public static class Script extends ModelMenuAction { protected String location; public Script(ModelMenu modelMenu, Element scriptElement) { super (modelMenu, scriptElement); this.location = scriptElement.getAttribute("location"); } public void runAction(Map context) { if (location.endsWith(".bsh")) { try { BshUtil.runBshAtLocation(location, context); } catch (GeneralException e) { 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 screen script actions the script type is not yet support for location:" + location); } } } public static class Service extends ModelMenuAction { protected FlexibleStringExpander serviceNameExdr; protected FlexibleMapAccessor resultMapNameAcsr; protected FlexibleStringExpander autoFieldMapExdr; protected Map fieldMap; public Service(ModelMenu modelMenu, Element serviceElement) { super (modelMenu, 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")); List fieldMapElementList = UtilXml.childElementList(serviceElement, "field-map"); if (fieldMapElementList.size() > 0) { this.fieldMap = new HashMap(); Iterator fieldMapElementIter = fieldMapElementList.iterator(); while (fieldMapElementIter.hasNext()) { Element fieldMapElement = (Element) fieldMapElementIter.next(); // set the env-name for each field-name, noting that if no field-name is specified it defaults to the env-name this.fieldMap.put( new FlexibleMapAccessor(UtilFormatOut.checkEmpty(fieldMapElement.getAttribute("field-name"), fieldMapElement.getAttribute("env-name"))), new FlexibleMapAccessor(fieldMapElement.getAttribute("env-name"))); } } } 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.modelMenu.getDispacher().getDispatchContext().makeValidContext(serviceNameExpanded, ModelService.IN_PARAM, context); } else { serviceContext = new HashMap(); } if (this.fieldMap != null) { Iterator fieldMapEntryIter = this.fieldMap.entrySet().iterator(); while (fieldMapEntryIter.hasNext()) { Map.Entry entry = (Map.Entry) fieldMapEntryIter.next(); FlexibleMapAccessor serviceContextFieldAcsr = (FlexibleMapAccessor) entry.getKey(); FlexibleMapAccessor contextEnvAcsr = (FlexibleMapAccessor) entry.getValue(); serviceContextFieldAcsr.put(serviceContext, contextEnvAcsr.get(context)); } } Map result = this.modelMenu.getDispacher().runSync(serviceNameExpanded, serviceContext); if (this.resultMapNameAcsr != null) { this.resultMapNameAcsr.put(context, result); } else { context.putAll(result); } } 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 ModelMenuAction { protected PrimaryKeyFinder finder; public EntityOne(ModelMenu modelMenu, Element entityOneElement) { super (modelMenu, entityOneElement); finder = new PrimaryKeyFinder(entityOneElement); } public void runAction(Map context) { try { finder.runFind(context, this.modelMenu.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 ModelMenuAction { protected ByAndFinder finder; public EntityAnd(ModelMenu modelMenu, Element entityAndElement) { super (modelMenu, entityAndElement); finder = new ByAndFinder(entityAndElement); } public void runAction(Map context) { try { finder.runFind(context, this.modelMenu.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 EntityCondition extends ModelMenuAction { ByConditionFinder finder; public EntityCondition(ModelMenu modelMenu, Element entityConditionElement) { super (modelMenu, entityConditionElement); finder = new ByConditionFinder(entityConditionElement); } public void runAction(Map context) { try { finder.runFind(context, this.modelMenu.getDelegator()); } 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 + -