Chapter 2 - Jetty读取配置文件和Loader (2)
编程技术  /  houtizong 发布于 3年前   49
private Object value(Object obj, XmlParser.Node node) throws Exception { Object value = null; // Get the type String type = node.getAttribute("type"); // Try a ref lookup String ref = node.getAttribute("ref"); if (ref != null) { value = _idMap.get(ref); } else { // handle trivial case if (node.size() == 0) { if ("String".equals(type)) return ""; return null; } // Trim values int first = 0; int last = node.size() - 1; // Handle default trim type if (type == null || !"String".equals(type)) { // Skip leading white Object item = null; while (first <= last) { item = node.get(first); if (!(item instanceof String)) break; item = ((String) item).trim(); if (((String) item).length() > 0) break; first++; } // Skip trailing white while (first < last) { item = node.get(last); if (!(item instanceof String)) break; item = ((String) item).trim(); if (((String) item).length() > 0) break; last--; } // All white, so return null if (first > last) return null; } if (first == last) // Single Item value value = itemValue(obj, node.get(first)); else { // Get the multiple items as a single string StringBuffer buf = new StringBuffer(); synchronized (buf) { for (int i = first; i <= last; i++) { Object item = node.get(i); buf.append(itemValue(obj, item)); } value = buf.toString(); } } } // Untyped or unknown if (value == null) { if ("String".equals(type)) return ""; return null; } // Try to type the object if (type == null) { if (value != null && value instanceof String) return ((String) value).trim(); return value; } if ("String".equals(type) || "java.lang.String".equals(type)) return value.toString(); Class pClass = TypeUtil.fromName(type); if (pClass != null) return TypeUtil.valueOf(pClass, value.toString()); if ("URL".equals(type) || "java.net.URL".equals(type)) { if (value instanceof URL) return value; try { return new URL(value.toString()); } catch (MalformedURLException e) { throw new InvocationTargetException(e); } } if ("InetAddress".equals(type) || "java.net.InetAddress".equals(type)) { if (value instanceof InetAddress) return value; try { return InetAddress.getByName(value.toString()); } catch (UnknownHostException e) { throw new InvocationTargetException(e); } } throw new IllegalStateException("Unknown type " + type); }
private Object itemValue(Object obj, Object item) throws Exception { // String value if (item instanceof String) return item; XmlParser.Node node = (XmlParser.Node) item; String tag = node.getTag(); if ("Call".equals(tag)) return call(obj, node); if ("Get".equals(tag)) return get(obj, node); if ("New".equals(tag)) return newObj(obj, node); if ("Ref".equals(tag)) return refObj(obj, node); if ("Array".equals(tag)) return newArray(obj, node); if ("Map".equals(tag)) return newMap(obj, node); if ("Property".equals(tag)) return propertyObj(obj,node); if ("SystemProperty".equals(tag)) { String name = node.getAttribute("name"); String defaultValue = node.getAttribute("default"); return System.getProperty(name, defaultValue); } Log.warn("Unknown value tag: " + node, new Throwable()); return null; }
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接