public static void dumpPropStructure(ConfigurationManager cm) { Map map = ConfigurationManagerUtils.listAllsPropNames(cm); [email protected](new StringBuilder().append("Property-structure of '").append(cm.getConfigURL()).append("':").toString()); [email protected]("\nUnambiguous properties = "); Iterator iterator = map.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry)iterator.next(); if (((List)entry.getValue()).size() == 1) { [email protected](new StringBuilder().append((string)entry.getKey()).append(", ").toString()); } } [email protected]("\n\nAmbiguous properties: "); iterator = map.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry)iterator.next(); if (((List)entry.getValue()).size() != 1) { [email protected](new StringBuilder().append((string)entry.getKey()).append('=').toString()); Iterator iterator2 = ((List)entry.getValue()).iterator(); while (iterator2.hasNext()) { PropertySheet propertySheet = (PropertySheet)iterator2.next(); [email protected](new StringBuilder().append(propertySheet.getInstanceName()).append(", ").toString()); } [email protected](); } } }
private static string propSheet2XML(string text, PropertySheet propertySheet) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("\t<component name=\"").append(text).append("\" type=\"").append(propertySheet.getConfigurableClass().getName()).append("\">"); Iterator iterator = propertySheet.getRegisteredProperties().iterator(); while (iterator.hasNext()) { string text2 = (string)iterator.next(); string text3 = new StringBuilder().append("\n\t\t<property name=\"").append(text2).append("\" ").toString(); if (propertySheet.getRawNoReplacement(text2) != null) { if (ConfigurationManagerUtils_1._SwitchMap_edu_cmu_sphinx_util_props_PropertyType[propertySheet.getType(text2).ordinal()] == 1) { stringBuilder.append("\n\t\t<propertylist name=\"").append(text2).append("\">"); List list = ConfigurationManagerUtils.toStringList(propertySheet.getRawNoReplacement(text2)); Iterator iterator2 = list.iterator(); while (iterator2.hasNext()) { string text4 = (string)iterator2.next(); stringBuilder.append("\n\t\t\t<item>").append(text4).append("</item>"); } stringBuilder.append("\n\t\t</propertylist>"); } else { stringBuilder.append(text3).append("value=\"").append(propertySheet.getRawNoReplacement(text2)).append("\"/>"); } } } stringBuilder.append("\n\t</component>\n\n"); return(stringBuilder.toString()); }
public static string toXML(ConfigurationManager cm) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"); stringBuilder.append("\n<!-- Sphinx-4 Configuration file--> \n\n"); stringBuilder.append("<config>"); Pattern pattern = Pattern.compile("\\_\\{(\\w+)\\}"); Map globalProperties = cm.getGlobalProperties(); Iterator iterator = globalProperties.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry)iterator.next(); string text = (string)entry.getKey(); Pattern pattern2 = pattern; object _ref = text; CharSequence charSequence = CharSequence.Cast(_ref); Matcher matcher = pattern2.matcher(charSequence); text = ((!matcher.matches()) ? text : matcher.group(1)); stringBuilder.append("\n\t<property name=\"").append(text).append("\" value=\"").append((string)entry.getValue()).append("\"/>"); } iterator = cm.getComponentNames().iterator(); while (iterator.hasNext()) { string text2 = (string)iterator.next(); stringBuilder.append("\n\n").append(ConfigurationManagerUtils.propSheet2XML(text2, cm.getPropertySheet(text2))); } stringBuilder.append("\n</config>"); return(stringBuilder.toString()); }
public static bool isImplementingInterface(Class aClass, Class interfaceClass) { if (!ConfigurationManagerUtils.assertionsDisabled && !interfaceClass.isInterface()) { throw new AssertionError(); } Class superclass = aClass.getSuperclass(); if (superclass != null && ConfigurationManagerUtils.isImplementingInterface(superclass, interfaceClass)) { return(true); } Class[] interfaces = aClass.getInterfaces(); int num = interfaces.Length; for (int i = 0; i < num; i++) { Class @class = interfaces[i]; if (Object.instancehelper_equals(@class, interfaceClass) || ConfigurationManagerUtils.isImplementingInterface(@class, interfaceClass)) { return(true); } } return(false); }
public static void showConfig(ConfigurationManager cm) { [email protected](" ============ config ============= "); Iterator iterator = cm.getInstanceNames(ClassLiteral <Configurable> .Value).iterator(); while (iterator.hasNext()) { string name = (string)iterator.next(); ConfigurationManagerUtils.showConfig(cm, name); } }
public virtual List getPropSheets(Class confClass) { ArrayList arrayList = new ArrayList(); Iterator iterator = this.symbolTable.values().iterator(); while (iterator.hasNext()) { PropertySheet propertySheet = (PropertySheet)iterator.next(); if (ConfigurationManagerUtils.isDerivedClass(propertySheet.getConfigurableClass(), confClass)) { arrayList.add(propertySheet); } } return(arrayList); }
public virtual RawPropertyData flatten(ConfigurationManager cm) { RawPropertyData rawPropertyData = new RawPropertyData(this.name, this.className); Iterator iterator = this.properties.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry)iterator.next(); object obj = entry.getValue(); if (obj is string && String.instancehelper_startsWith((string)obj, "_{")) { obj = cm.getGloPropReference(ConfigurationManagerUtils.stripGlobalSymbol((string)obj)); } rawPropertyData.properties.put(entry.getKey(), obj); } return(rawPropertyData); }
public virtual void renameConfigurable(string oldName, string newName) { PropertySheet propertySheet = this.getPropertySheet(oldName); if (propertySheet == null) { string text = new StringBuilder().append("no configurable (to be renamed) named ").append(oldName).append(" is contained in the CM").toString(); throw new RuntimeException(text); } ConfigurationManagerUtils.renameComponent(this, oldName, newName); this.symbolTable.remove(oldName); this.symbolTable.put(newName, propertySheet); RawPropertyData rawPropertyData = (RawPropertyData)this.rawPropertyMap.remove(oldName); this.rawPropertyMap.put(newName, new RawPropertyData(newName, rawPropertyData.getClassName(), rawPropertyData.getProperties())); this.fireRenamedConfigurable(oldName, newName); }
public virtual Collection getInstanceNames(Class type) { ArrayList arrayList = new ArrayList(); Iterator iterator = this.symbolTable.values().iterator(); while (iterator.hasNext()) { PropertySheet propertySheet = (PropertySheet)iterator.next(); if (propertySheet.isInstanciated()) { if (ConfigurationManagerUtils.isDerivedClass(propertySheet.getConfigurableClass(), type)) { arrayList.add(propertySheet.getInstanceName()); } } } return(arrayList); }
public static void configureLogger(ConfigurationManager cm) { if (java.lang.System.getProperty("java.util.logging.config.class") != null || java.lang.System.getProperty("java.util.logging.config.file") != null) { return; } string logPrefix = ConfigurationManagerUtils.getLogPrefix(cm); Logger logger = Logger.getLogger(String.instancehelper_substring(logPrefix, 0, String.instancehelper_length(logPrefix) - 1)); Level level = Logger.getLogger("").getLevel(); ConfigurationManagerUtils.configureLogger(logger); string text = cm.getGlobalProperty("logLevel"); if (text == null) { text = Level.WARNING.getName(); } logger.setLevel(Level.parse(text)); Logger.getLogger("").setLevel(level); }
public virtual Logger getLogger() { string text = new StringBuilder().append(ConfigurationManagerUtils.getLogPrefix(this.cm)).append(this.ownerClass.getName()).toString(); Logger logger; if (this.instanceName != null) { logger = Logger.getLogger(new StringBuilder().append(text).append('.').append(this.instanceName).toString()); } else { logger = Logger.getLogger(text); } object obj = this.rawProps.get("logLevel"); if (obj != null) { logger.setLevel((!(obj is string)) ? ((Level)obj) : Level.parse((string)obj)); } return(logger); }
protected internal new virtual PropertySheet clone() { PropertySheet propertySheet = (PropertySheet)base.clone(); propertySheet.registeredProperties = new HashMap(this.registeredProperties); propertySheet.propValues = new HashMap(this.propValues); propertySheet.rawProps = new HashMap(this.rawProps); Iterator iterator = propertySheet.getRegisteredProperties().iterator(); while (iterator.hasNext()) { string text = (string)iterator.next(); if (this.getType(text) == PropertyType.__COMPONENT_LIST) { propertySheet.rawProps.put(text, ConfigurationManagerUtils.toStringList(this.rawProps.get(text))); propertySheet.propValues.put(text, null); } } propertySheet.cm = this.cm; propertySheet.owner = null; propertySheet.instanceName = this.instanceName; return(propertySheet); }
public static void save(ConfigurationManager cm, File cmLocation) { if (!String.instancehelper_endsWith(cmLocation.getName(), ".sxl")) { java.lang.System.err.println("WARNING: Serialized s4-configuration should have the suffix '.sxl'"); } if (!ConfigurationManagerUtils.assertionsDisabled && cm == null) { throw new AssertionError(); } try { PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(cmLocation), Charset.forName("UTF-8"))); string text = ConfigurationManagerUtils.toXML(cm); printWriter.print(text); printWriter.flush(); printWriter.close(); } catch (FileNotFoundException ex) { Throwable.instancehelper_printStackTrace(ex); } }
public ConfigurationManager(URL url) { this.changeListeners = new ArrayList(); this.symbolTable = new LinkedHashMap(); this.rawPropertyMap = new HashMap(); this.globalProperties = new HashMap(); this.configURL = url; try { this.rawPropertyMap = new SaxLoader(url, this.globalProperties).load(); } catch (IOException ex) { throw new RuntimeException(ex); } ConfigurationManagerUtils.applySystemProperties(this.rawPropertyMap, this.globalProperties); ConfigurationManagerUtils.configureLogger(this); string text = (string)this.globalProperties.get("showCreations"); if (text != null) { this.showCreations = String.instancehelper_equals("true", text); } }
public static URL getResource(string name, PropertySheet ps) { string @string = ps.getString(name); if (@string == null) { string instanceName = ps.getInstanceName(); string text = new StringBuilder().append("Required resource property '").append(name).append("' not set").toString(); throw new InternalConfigurationException(instanceName, name, text); } URL result; try { URL url = ConfigurationManagerUtils.resourceToURL(@string); result = url ?? throw new InternalConfigurationException(ps.getInstanceName(), name, new StringBuilder().append("Can't locate ").append(@string).toString()); } catch (MalformedURLException ex) { throw new InternalConfigurationException(ex, ps.getInstanceName(), name, new StringBuilder().append("Bad URL ").append(@string).append(Throwable.instancehelper_getMessage(ex)).toString()); } return(result); }
public virtual List getStringList(string name) { this.getProperty(name, ClassLiteral <S4StringList> .Value); return(ConfigurationManagerUtils.toStringList(this.propValues.get(name))); }
internal static void renameComponent(ConfigurationManager configurationManager, string text, string text2) { if (!ConfigurationManagerUtils.assertionsDisabled && configurationManager == null) { throw new AssertionError(); } if (!ConfigurationManagerUtils.assertionsDisabled && (text == null || text2 == null)) { throw new AssertionError(); } if (configurationManager.getPropertySheet(text) == null) { string text3 = new StringBuilder().append("no configurable (to be renamed) named ").append(text).append(" is contained in the CM").toString(); throw new RuntimeException(text3); } Iterator iterator = configurationManager.getComponentNames().iterator(); while (iterator.hasNext()) { string instanceName = (string)iterator.next(); PropertySheet propertySheet = configurationManager.getPropertySheet(instanceName); Iterator iterator2 = propertySheet.getRegisteredProperties().iterator(); while (iterator2.hasNext()) { string text4 = (string)iterator2.next(); if (propertySheet.getRawNoReplacement(text4) != null) { int num = ConfigurationManagerUtils_1._SwitchMap_edu_cmu_sphinx_util_props_PropertyType[propertySheet.getType(text4).ordinal()]; if (num == 1) { List list = ConfigurationManagerUtils.toStringList(propertySheet.getRawNoReplacement(text4)); for (int i = 0; i < list.size(); i++) { string text5 = (string)list.get(i); if (String.instancehelper_equals(text5, text)) { list.set(i, text2); } } } else if (num == 2) { if (Object.instancehelper_equals(propertySheet.getRawNoReplacement(text4), text)) { propertySheet.setRaw(text4, text2); } } } } } PropertySheet propertySheet2 = configurationManager.getPropertySheet(text); propertySheet2.setInstanceName(text2); Iterator iterator3 = configurationManager.getGlobalProperties().entrySet().iterator(); while (iterator3.hasNext()) { Map.Entry entry = (Map.Entry)iterator3.next(); if (String.instancehelper_equals((string)entry.getValue(), text)) { configurationManager.setGlobalProperty((string)entry.getKey(), text2); } } }
public static void setProperty(ConfigurationManager cm, string propName, string propValue) { if (!ConfigurationManagerUtils.assertionsDisabled && propValue == null) { throw new AssertionError(); } Map map = ConfigurationManagerUtils.listAllsPropNames(cm); Set componentNames = cm.getComponentNames(); object _ref; CharSequence charSequence; if (!map.containsKey(propName)) { string text = propName; _ref = "->"; charSequence = CharSequence.Cast(_ref); if (!String.instancehelper_contains(text, charSequence) && !componentNames.contains(propName)) { string text2 = new StringBuilder().append("No property or configurable '").append(propName).append("' in configuration '").append(cm.getConfigURL()).append("'!").toString(); throw new RuntimeException(text2); } } if (componentNames.contains(propName)) { try { Class confClass = Class.forName(propValue, ConfigurationManagerUtils.__GetCallerID()).asSubclass(ClassLiteral <Configurable> .Value); ConfigurationManagerUtils.setClass(cm.getPropertySheet(propName), confClass); } catch (ClassNotFoundException ex) { throw new RuntimeException(ex); } } string text3 = propName; _ref = "->"; charSequence = CharSequence.Cast(_ref); if (!String.instancehelper_contains(text3, charSequence) && ((List)map.get(propName)).size() > 1) { string text4 = new StringBuilder().append("Property-name '").append(propName).append("' is ambiguous with respect to configuration '").append(cm.getConfigURL()).append("'. Use 'componentName->propName' to disambiguate your request.").toString(); throw new RuntimeException(text4); } string text5 = propName; _ref = "->"; charSequence = CharSequence.Cast(_ref); string componentName; if (String.instancehelper_contains(text5, charSequence)) { string[] array = String.instancehelper_split(propName, "->"); componentName = array[0]; propName = array[1]; } else { componentName = ((PropertySheet)((List)map.get(propName)).get(0)).getInstanceName(); } ConfigurationManagerUtils.setProperty(cm, componentName, propName, propValue); }
public ConfigurationManager(string configFileName) : this(ConfigurationManagerUtils.getURL(new File(configFileName))) { }
public virtual Logger getRootLogger() { return(Logger.getLogger(ConfigurationManagerUtils.getLogPrefix(this))); }
public virtual string getStrippedComponentName(string propertyName) { if (!ConfigurationManager.assertionsDisabled && propertyName == null) { throw new AssertionError(); } while (String.instancehelper_startsWith(propertyName, "_")) { propertyName = String.instancehelper_toString((string)this.globalProperties.get(ConfigurationManagerUtils.stripGlobalSymbol(propertyName))); } return(propertyName); }