1. XmlConfiguration的value方法
读取某个节点的值,并进行相应处理:修剪空字符串,解析并拼接结果
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);
}
2. XmlConfiguration的itemValue方法
读取单个节点的值,如果item是String类型,直接返回
如果是其它的tag,还需要调用对应的处理方法
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;
}
分享到:
相关推荐
eclipse jetty插件,从...下载run-jetty-run.zip文件,解压后再编写个links文件丢到eclipse的dropins目录下即可,省去了使用eclipse update方式安装的麻烦。 link文件样例如: path=d:\\eclipse_plugins\\run-jetty-run
安装方法为新加一个run-jetty-run.link文件,文件内容为 path=G:\\eclipse_plugins\\run-jetty-run 执行解压后的路径文件夹即可。 在线安装地址为: http://xzer.github.io/run-jetty-run-updatesite/nightly/ 支持...
android i-jetty servlet-api-2.5.jar jetty-servlet-7.6.0.RC4.jar jetty-server-7.6.0.RC4.jar jetty-http-7.6.0.RC4.jar
maven jetty 插件,直接放在ide的插件包即可
maven集成jetty必须jar包maven-jetty-plugin,内含多个版本
Android-I-Jetty服务器部署例子代码,第一运行起来I-Jetty服务器以后,一定想要例子测试一下;
Android-I-Jetty服务器源码,项目相关内容已经整理完成,拿来就可以运行了,希望对您有一定帮助
run-jetty-run是一个新的jetty eclipse插件通过该插件可以直接在Eclipse环境中启动、停止 Jetty ,同时进行在线调试而无需重启服务。
i-jetty环境搭配与编译,内附配置好的eclipse开发环境
这是i-jetty源码,在google code上也有,需要用maven编译后执行
maven-jetty-plugin-6.1.3.jar
maven-jetty-jspc-plugin-6.1.9.jar
maven-jetty-jspc-plugin-6.1.25-sources.jar
maven-jetty-plugin-6.1.7.jar
run-jetty-run_update-1.3.5-SNAPSHOT, Eclipse插件离线安装包 由源代码自行编译打包 编译日期: 2018-02-04 Github地址: https://github.com/xzer/run-jetty-run 在线安装地址: ...
maven-jetty6-plugin-1.0.jar
移动端的服务器 Jetty android 服务器 i-Jetty
run-jetty-run eclipse插件 离线安装包 Eclipse中Install New Software 然后Add -> Archive,选择该包安装即可 该插件为2016年1月份的release版,支持eclipse Neon (4.6), Mars (4.5), Luna (4.4), Kepler (4.3), ...
run-jetty-run eclipse插件 离线安装包 Eclipse中Install New Software 然后Add -> Archive,选择该包安装即可