@SuppressWarnings("unchecked") public static <T> T convert(String value, T defaultValue) { return convert(value, (Class<T>) defaultValue.getClass(), defaultValue); }
@SuppressWarnings("unchecked") public static <T> T convert(String value, Class<T> c) { return (T) Optional.ofNullable(c) .map(map::get) .map(p -> p.parse(value)) .orElseGet(() -> parseValue(value)); }
@SuppressWarnings("unchecked") private Object getListArg(ManagedList<XmlManagedNode> values, Class<?> setterParamType) { Collection<Object> collection = null; if (VerifyUtils.isNotEmpty(values.getTypeName())) { try { collection = (Collection<Object>) XmlApplicationContext.class .getClassLoader() .loadClass(values.getTypeName()) .newInstance(); } catch (Throwable t) { log.error("list inject error", t); } } else { collection = (setterParamType == null ? new ArrayList<>() : ConvertUtils.getCollectionObj(setterParamType)); } if (collection != null) { for (XmlManagedNode item : values) { Object listValue = getInjectArg(item, null); collection.add(listValue); } } return collection; }
@SuppressWarnings("unchecked") private Object getMapArg(ManagedMap<XmlManagedNode, XmlManagedNode> values, Class<?> setterParamType) { Map<Object, Object> m = null; if (VerifyUtils.isNotEmpty(values.getTypeName())) { try { m = (Map<Object, Object>) XmlApplicationContext.class.getClassLoader() .loadClass(values.getTypeName()) .newInstance(); } catch (Throwable t) { log.error("map inject error", t); } } else { m = (setterParamType == null ? new HashMap<>() : ConvertUtils.getMapObj(setterParamType)); if (m != null && log.isDebugEnabled()) { log.debug("map ret [{}]", m.getClass().getName()); } } if (m != null) { for (XmlManagedNode o : values.keySet()) { Object k = getInjectArg(o, null); Object v = getInjectArg(values.get(o), null); m.put(k, v); } } return m; }
@SuppressWarnings("unchecked") private Object getListArg(ManagedList<XmlManagedNode> values, Class<?> setterParamType) { Collection<Object> collection = null; if (VerifyUtils.isNotEmpty(values.getTypeName())) { try { collection = (Collection<Object>) XmlApplicationContext.class .getClassLoader() .loadClass(values.getTypeName()) .newInstance(); } catch (Throwable t) { log.error("list inject error", t); } } else { collection = (setterParamType == null ? new ArrayList<>() : ConvertUtils.getCollectionObj(setterParamType)); } if (collection != null) { for (XmlManagedNode item : values) { Object listValue = getInjectArg(item, null); collection.add(listValue); } } return collection; }
@SuppressWarnings("unchecked") private Object getMapArg(ManagedMap<XmlManagedNode, XmlManagedNode> values, Class<?> setterParamType) { Map<Object, Object> m = null; if (VerifyUtils.isNotEmpty(values.getTypeName())) { try { m = (Map<Object, Object>) XmlApplicationContext.class.getClassLoader() .loadClass(values.getTypeName()) .newInstance(); } catch (Throwable t) { log.error("map inject error", t); } } else { m = (setterParamType == null ? new HashMap<>() : ConvertUtils.getMapObj(setterParamType)); if (m != null && log.isDebugEnabled()) { log.debug("map ret [{}]", m.getClass().getName()); } } if (m != null) { for (XmlManagedNode o : values.keySet()) { Object k = getInjectArg(o, null); Object v = getInjectArg(values.get(o), null); m.put(k, v); } } return m; }
@SuppressWarnings("unchecked") public static <T> T convert(String value, T defaultValue) { return convert(value, (Class<T>) defaultValue.getClass(), defaultValue); }
@SuppressWarnings("unchecked") public static <T> T convert(String value, String argsType) { return (T) Optional.ofNullable(argsType) .map(map2::get) .map(p -> p.parse(value)) .orElseGet(() -> parseValue(value)); }
@SuppressWarnings("unchecked") public static <T> T convert(String value, T defaultValue) { return convert(value, (Class<T>) defaultValue.getClass(), defaultValue); }
@SuppressWarnings("unchecked") public static <T> T convert(String value, Class<T> c) { return (T) Optional.ofNullable(c) .map(map::get) .map(p -> p.parse(value)) .orElseGet(() -> parseValue(value)); }
public static <T> T convert(String value, Class<T> c, T defaultValue) { try { return Optional.ofNullable(value) .filter(StringUtils::hasText) .map(v -> convert(value, c)) .orElse(defaultValue); } catch (Throwable t) { return defaultValue; } }
@SuppressWarnings("unchecked") public static <T> T convert(String value, String argsType) { return (T) Optional.ofNullable(argsType) .map(map2::get) .map(p -> p.parse(value)) .orElseGet(() -> parseValue(value)); }
public static <T> T convert(String value, Class<T> c, T defaultValue) { try { return Optional.ofNullable(value) .filter(StringUtils::hasText) .map(v -> convert(value, c)) .orElse(defaultValue); } catch (Throwable t) { return defaultValue; } }
private Object getArrayArg(ManagedArray<XmlManagedNode> values, Class<?> setterParamType) { Collection<Object> collection = new ArrayList<>(); for (XmlManagedNode item : values) { Object listValue = getInjectArg(item, null); collection.add(listValue); } return ConvertUtils.convert(collection, setterParamType); }
private Object getArrayArg(ManagedArray<XmlManagedNode> values, Class<?> setterParamType) { Collection<Object> collection = new ArrayList<>(); for (XmlManagedNode item : values) { Object listValue = getInjectArg(item, null); collection.add(listValue); } return ConvertUtils.convert(collection, setterParamType); }
public static <T> T convert(String value, Class<T> c, T defaultValue) { try { if (!StringUtils.hasText(value)) { return defaultValue; } T ret = convert(value, c); return ret != null ? ret : defaultValue; } catch (Throwable t) { return defaultValue; } }
private Object getValueArg(ManagedValue managedValue, String typeName) { return ConvertUtils.convert(managedValue.getValue(), typeName); }
private Object getValueArg(ManagedValue managedValue, String typeName) { return ConvertUtils.convert(managedValue.getValue(), typeName); }
@Override public boolean parse(Action1<FileLog> action) { Dom dom = new DefaultDom(); Document doc = dom.getDocument(DEFAULT_XML_CONFIG_FILE_NAME); if (doc == null) { return false; } Element root = dom.getRoot(doc); List<Element> loggerList = dom.elements(root, "logger"); if (loggerList == null || loggerList.isEmpty()) { return false; } else { for (Element e : loggerList) { String name = dom.getTextValueByTagName(e, "name", DEFAULT_LOG_NAME); String level = dom.getTextValueByTagName(e, "level", DEFAULT_LOG_LEVEL); String path = dom.getTextValueByTagName(e, "path", DEFAULT_LOG_DIRECTORY.getAbsolutePath()); boolean consoleEnabled = ConvertUtils.convert(dom.getTextValueByTagName(e, "enable-console"), DEFAULT_CONSOLE_ENABLED); int maxFileSize = ConvertUtils.convert(dom.getTextValueByTagName(e, "max-file-size"), DEFAULT_MAX_FILE_SIZE); action.call(createLog(name, level, path, consoleEnabled, maxFileSize)); } } return true; }
c.setLevel(dom.getTextValueByTagName(e, "level", DEFAULT_LOG_LEVEL)); c.setPath(dom.getTextValueByTagName(e, "path", DEFAULT_LOG_DIRECTORY.getAbsolutePath())); c.setConsole(ConvertUtils.convert(dom.getTextValueByTagName(e, "enable-console"), DEFAULT_CONSOLE_ENABLED)); c.setMaxFileSize(ConvertUtils.convert(dom.getTextValueByTagName(e, "max-file-size"), DEFAULT_MAX_FILE_SIZE)); if (c.getMaxFileSize() < 1024 * 1024 * 10) { System.err.println("the max log file less than 10MB, please set a larger file size");