📄 capturestatephaselistener.java
字号:
attrNode.setLeafNode(true);
attrNode.setName(me.getKey().toString());
attrNode.setValue(toString(me.getValue()));
attrsNode.addChild(attrNode);
}
parent.addChild(attrsNode);
if (comp.getChildCount() > 0) {
TreeNode kidsNode = new TreeNode();
kidsNode.setName("Children");
Iterator kids = comp.getChildren().iterator();
while (kids.hasNext()) {
UIComponent child = (UIComponent) kids.next();
TreeNode childNode = new TreeNode();
childNode.setName(child.getClientId(context) +
" [" + child.getClass().getName() + "]");
kidsNode.addChild(childNode);
addComponentNodes(context, childNode, child);
}
parent.addChild(kidsNode);
}
Map facetsMap = comp.getFacets();
if (facetsMap.size() > 0) {
TreeNode facetsNode = new TreeNode();
facetsNode.setName("Facets");
Iterator facets = facetsMap.entrySet().iterator();
while (facets.hasNext()) {
Map.Entry me = (Map.Entry) facets.next();
UIComponent child = (UIComponent) me.getValue();
TreeNode childNode = new TreeNode();
childNode.setName((String) me.getKey());
facetsNode.addChild(childNode);
addComponentNodes(context, childNode, child);
}
parent.addChild(facetsNode);
}
}
/**
* Add a TreeNode instance for each entry in the Map, with the
* entry key (converted to a String) as the node name, the entry value
* (converted to a String) as the node value, and with the "leafNode"
* property set to "true".
*/
private void addLeafNodes(TreeNode parent, Map map) {
Iterator i = map.entrySet().iterator();
while (i.hasNext()) {
Map.Entry me = (Map.Entry) i.next();
TreeNode leaf = new TreeNode();
leaf.setLeafNode(true);
leaf.setName(me.getKey().toString());
leaf.setValue(toString(me.getValue()));
parent.addChild(leaf);
}
}
/**
* Returns the value as a String in an appropriate format
* depending on the data type. A null value is returned as
* "null", an Object or primitive type array or a Collection
* is returned as a comma-separated list of values, a Map
* is returned as a comma-separated list of "key=value" entries.
*/
private String toString(Object value) {
if (value == null) {
return "null";
}
String string = null;
// Use element values for common mutable types
if (value.getClass().isArray()) {
if (value.getClass().getComponentType().isPrimitive()) {
if (value.getClass().getComponentType() == Boolean.TYPE) {
Object[] arr = toObjects((boolean[]) value);
string = format(Arrays.asList(arr).iterator());
}
if (value.getClass().getComponentType() == Byte.TYPE) {
Object[] arr = toObjects((byte[]) value);
string = format(Arrays.asList(arr).iterator());
}
if (value.getClass().getComponentType() == Character.TYPE) {
Object[] arr = toObjects((char[]) value);
string = format(Arrays.asList(arr).iterator());
}
if (value.getClass().getComponentType() == Double.TYPE) {
Object[] arr = toObjects((double[]) value);
string = format(Arrays.asList(arr).iterator());
}
if (value.getClass().getComponentType() == Float.TYPE) {
Object[] arr = toObjects((float[]) value);
string = format(Arrays.asList(arr).iterator());
}
if (value.getClass().getComponentType() == Integer.TYPE) {
Object[] arr = toObjects((int[]) value);
string = format(Arrays.asList(arr).iterator());
}
if (value.getClass().getComponentType() == Long.TYPE) {
Object[] arr = toObjects((long[]) value);
string = format(Arrays.asList(arr).iterator());
}
if (value.getClass().getComponentType() == Short.TYPE) {
Object[] arr = toObjects((short[]) value);
string = format(Arrays.asList(arr).iterator());
}
}
else {
string = format(Arrays.asList((Object[]) value).iterator());
}
}
else if (value instanceof Collection) {
string = format(((Collection) value).iterator());
}
else if (value instanceof Map) {
string = format((Map) value);
}
else {
string = value.toString();
}
return string;
}
/**
* Returns an Object array with the values of the array.
*/
private Object[] toObjects(boolean[] arr) {
Object[] objects = new Object[Array.getLength(arr)];
for (int i = 0; i < arr.length; i++) {
objects[i] = Array.get(arr, i);
}
return objects;
}
/**
* Returns an Object array with the values of the array.
*/
private Object[] toObjects(byte[] arr) {
Object[] objects = new Object[Array.getLength(arr)];
for (int i = 0; i < arr.length; i++) {
objects[i] = Array.get(arr, i);
}
return objects;
}
/**
* Returns an Object array with the values of the array.
*/
private Object[] toObjects(char[] arr) {
Object[] objects = new Object[Array.getLength(arr)];
for (int i = 0; i < arr.length; i++) {
objects[i] = Array.get(arr, i);
}
return objects;
}
/**
* Returns an Object array with the values of the array.
*/
private Object[] toObjects(double[] arr) {
Object[] objects = new Object[Array.getLength(arr)];
for (int i = 0; i < arr.length; i++) {
objects[i] = Array.get(arr, i);
}
return objects;
}
/**
* Returns an Object array with the values of the array.
*/
private Object[] toObjects(float[] arr) {
Object[] objects = new Object[Array.getLength(arr)];
for (int i = 0; i < arr.length; i++) {
objects[i] = Array.get(arr, i);
}
return objects;
}
/**
* Returns an Object array with the values of the array.
*/
private Object[] toObjects(int[] arr) {
Object[] objects = new Object[Array.getLength(arr)];
for (int i = 0; i < arr.length; i++) {
objects[i] = Array.get(arr, i);
}
return objects;
}
/**
* Returns an Object array with the values of the array.
*/
private Object[] toObjects(short[] arr) {
Object[] objects = new Object[Array.getLength(arr)];
for (int i = 0; i < arr.length; i++) {
objects[i] = Array.get(arr, i);
}
return objects;
}
/**
* Returns an Object array with the values of the array.
*/
private Object[] toObjects(long[] arr) {
Object[] objects = new Object[Array.getLength(arr)];
for (int i = 0; i < arr.length; i++) {
objects[i] = Array.get(arr, i);
}
return objects;
}
/**
* Returns a String with comma-separated list of the values
* represented by the Iterator.
*/
private String format(Iterator i) {
StringBuffer sb = new StringBuffer();
boolean first = true;
while (i.hasNext()) {
Object o = i.next();
if (!first) {
sb.append(", ");
}
first = false;
sb.append(o);
}
return sb.toString();
}
/**
* Returns a String with comma-separated list of the Map entries,
* with each entry as "key = value".
*/
private String format(Map map) {
Iterator i = map.entrySet().iterator();
StringBuffer sb = new StringBuffer();
boolean first = true;
while (i.hasNext()) {
Map.Entry me = (Map.Entry) i.next();
if (!first) {
sb.append(", ");
}
first = false;
sb.append(me.getKey()).append("=").append(me.getValue());
}
return sb.toString();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -