1 19 package org.openide.nodes; 20 21 import java.util.logging.Level ; 22 import java.util.logging.Logger ; 23 24 25 36 public final class DefaultHandle extends Object implements Node.Handle { 37 private static final long serialVersionUID = -8739127064355983273L; 38 39 40 private Node.Handle parent; 41 42 43 private String path; 44 45 49 DefaultHandle(Node.Handle parent, String path) { 50 this.parent = parent; 51 this.path = path; 52 } 53 54 59 public Node getNode() throws java.io.IOException { 60 Node parentNode = parent.getNode(); 61 Node child = parentNode.getChildren().findChild(path); 62 63 if (child != null) { 64 return child; 65 } else { 66 throw new NodeNotFoundException(parentNode, path, 0); 67 } 68 } 69 70 81 public static DefaultHandle createHandle(final Node node) { 82 try { 83 Children.PR.enterReadAccess(); 84 85 String childPath = node.getName(); 86 87 if (childPath == null) { 88 return null; 89 } 90 91 Node parentNode = node.getParentNode(); 92 93 if (parentNode == null) { 94 return null; 95 } 96 97 Node foundChild = parentNode.getChildren().findChild(childPath); 98 if (foundChild != node) { 99 Logger.getLogger(DefaultHandle.class.getName()).log(Level.WARNING, 100 "parent could not find own child: node={0} parentNode={1} childPath={2} foundChild={3}", 101 new Object [] {node, parentNode, childPath, foundChild}); 102 return null; 103 } 104 105 Node.Handle parentHandle = parentNode.getHandle(); 106 107 if (parentHandle == null) { 108 return null; 109 } 110 111 return new DefaultHandle(parentHandle, childPath); 112 } finally { 113 Children.PR.exitReadAccess(); 114 } 115 } 116 117 public String toString() { 118 return "DefaultHandle[" + parent + "|" + path + "]"; } 120 } 121 | Popular Tags |