001package jmri.jmrit.logixng.actions; 002 003import java.util.Locale; 004import java.util.Map; 005 006import jmri.InstanceManager; 007import jmri.jmrit.logixng.*; 008 009/** 010 * This action prints the local variables to the log. 011 * 012 * @author Daniel Bergqvist Copyright 2021 013 */ 014public class LogLocalVariables extends AbstractDigitalAction { 015 016 private boolean _includeGlobalVariables = true; 017 private boolean _expandArraysAndMaps = false; 018 private boolean _showClassName = false; 019 020 021 public LogLocalVariables(String sys, String user) 022 throws BadUserNameException, BadSystemNameException { 023 super(sys, user); 024 } 025 026 @Override 027 public Base getDeepCopy(Map<String, String> systemNames, Map<String, String> userNames) { 028 DigitalActionManager manager = InstanceManager.getDefault(DigitalActionManager.class); 029 String sysName = systemNames.get(getSystemName()); 030 String userName = userNames.get(getSystemName()); 031 if (sysName == null) sysName = manager.getAutoSystemName(); 032 LogLocalVariables copy = new LogLocalVariables(sysName, userName); 033 copy.setComment(getComment()); 034 copy._includeGlobalVariables = _includeGlobalVariables; 035 copy._expandArraysAndMaps = _expandArraysAndMaps; 036 copy._showClassName = _showClassName; 037 return manager.registerAction(copy); 038 } 039 040 public void setIncludeGlobalVariables(boolean value) { 041 _includeGlobalVariables = value; 042 } 043 044 public boolean isIncludeGlobalVariables() { 045 return _includeGlobalVariables; 046 } 047 048 public void setExpandArraysAndMaps(boolean value) { 049 _expandArraysAndMaps = value; 050 } 051 052 public boolean isExpandArraysAndMaps() { 053 return _expandArraysAndMaps; 054 } 055 056 public void setShowClassName(boolean value) { 057 _showClassName = value; 058 } 059 060 public boolean isShowClassName() { 061 return _showClassName; 062 } 063 064 /** {@inheritDoc} */ 065 @Override 066 public Category getCategory() { 067 return Category.OTHER; 068 } 069 070 /** {@inheritDoc} */ 071 @edu.umd.cs.findbugs.annotations.SuppressFBWarnings( value="SLF4J_FORMAT_SHOULD_BE_CONST", 072 justification="I18N in Warning strings.") 073 @Override 074 public void execute() { 075 ConditionalNG c = getConditionalNG(); 076 log.warn(Bundle.getMessage("LogLocalVariables_Start")); 077 for (SymbolTable.Symbol s : c.getSymbolTable().getSymbols().values()) { 078 SymbolTable.printVariable( 079 log, 080 " ", 081 s.getName(), 082 c.getSymbolTable().getValue(s.getName()), 083 _expandArraysAndMaps, 084 _showClassName, 085 Bundle.getMessage("LogLocalVariables_VariableName"), 086 Bundle.getMessage("LogLocalVariables_VariableValue")); 087 } 088 if (_includeGlobalVariables) { 089 log.warn(Bundle.getMessage("LogLocalVariables_GlobalVariables_Start")); 090 for (GlobalVariable gv : InstanceManager.getDefault(GlobalVariableManager.class).getNamedBeanSet()) { 091 SymbolTable.printVariable( 092 log, 093 " ", 094 gv.getUserName(), 095 gv.getValue(), 096 _expandArraysAndMaps, 097 _showClassName, 098 Bundle.getMessage("LogLocalVariables_GlobalVariableName"), 099 Bundle.getMessage("LogLocalVariables_GlobalVariableValue")); 100 } 101 } 102 log.warn(Bundle.getMessage("LogLocalVariables_End")); 103 } 104 105 @Override 106 public FemaleSocket getChild(int index) throws IllegalArgumentException, UnsupportedOperationException { 107 throw new UnsupportedOperationException("Not supported."); 108 } 109 110 @Override 111 public int getChildCount() { 112 return 0; 113 } 114 115 @Override 116 public String getShortDescription(Locale locale) { 117 return Bundle.getMessage(locale, "LogLocalVariables_Short"); 118 } 119 120 @Override 121 public String getLongDescription(Locale locale) { 122 return Bundle.getMessage(locale, "LogLocalVariables_Long"); 123 } 124 125 /** {@inheritDoc} */ 126 @Override 127 public void setup() { 128 // Do nothing 129 } 130 131 /** {@inheritDoc} */ 132 @Override 133 public void registerListenersForThisClass() { 134 } 135 136 /** {@inheritDoc} */ 137 @Override 138 public void unregisterListenersForThisClass() { 139 } 140 141 /** {@inheritDoc} */ 142 @Override 143 public void disposeMe() { 144 } 145 146 private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LogLocalVariables.class); 147}