/** * Returns the enum representation of a string. This is case sensitive. * * @param str toString representation of a default field * @return default field associated with a string * @throws IllegalArgumentException if argument is not represented by a default field. */ public static Default fromString(String str) { for (Default field : Default.values()) { if (str.equals(field.toString())) { return field; } } throw new IllegalArgumentException(); }
@Override protected boolean parseInner(XmlPullParser parser, Pref instance) throws Exception { if (super.parseInner(parser, instance)) return true; String name = parser.getName(); if (Pref.AUTO_NAME.equals(name)) { Boolean save = ProviderUtils.parseBoolean(parser.getAttributeValue(null, Pref.SAVE_ATTRIBUTE)); if (save != null) { ScopeMode scope = null; try { scope = ScopeMode.fromString(parser.getAttributeValue(null, Pref.SCOPE_ATTRIBUTE)); } catch (NoSuchElementException e) { } instance.setAuto(save, scope); } return false; // Only tag attributes has bee read. } else if (Default.ELEMENT_NAME.equals(name)) { Default value = DefaultProvider.getInstance().provideInstance(parser); if (value.isValid()) instance.setDefault(value); } else if (Item.ELEMENT_NAME.equals(name)) { Item value = ItemProvider.getInstance().provideInstance(parser); if (value.isValid()) instance.addItem(value); } else if (Session.ELEMENT_NAME.equals(name)) { Session value = SessionProvider.getInstance().provideInstance(parser); if (value.isValid()) instance.addSession(value); } else if (Pref.METHOD_NAME.equals(name)) { TypeMode type = null; UseMode use = null; try { type = TypeMode.fromString(parser.getAttributeValue(null, Pref.TYPE_ATTRIBUTE)); } catch (NoSuchElementException e) { } try { use = UseMode.fromString(parser.getAttributeValue(null, Pref.USE_ATTRIBUTE)); } catch (NoSuchElementException e) { } if (type != null && use != null) instance.setMethod(type, use); return false; // Only tag attributes has bee read. } else return false; return true; }
/** * Retrieves default values from xml. * * @param list the configuration list */ private static void parseDefaults(NodeList list) { for (int i = 0; i < list.getLength(); ++i) { NamedNodeMap mapping = list.item(i).getAttributes(); String attribute = mapping.getNamedItem("attribute").getNodeValue(); String value = mapping.getNamedItem("value").getNodeValue(); try { Default field = Default.fromString(attribute); DEFAULTS.put(field, value); } catch (IllegalArgumentException exc) { logger.warn("Unrecognized default attribute: " + attribute); } } }