1 45 package org.openejb.core.ivm.naming; 46 47 48 61 public class NameNode implements java.io.Serializable { 62 public String atomicName; 63 public int atomicHash; 64 public NameNode lessTree; 65 public NameNode grtrTree; 66 public NameNode subTree; 67 public NameNode parent; 68 public Object myObject; 69 public transient IvmContext myContext; 70 71 public NameNode(NameNode parent, ParsedName name, Object obj){ 72 atomicName = name.getComponent(); 73 atomicHash = name.getComponentHashCode(); 74 this.parent = parent; 75 if(name.next()) 76 subTree = new NameNode(this, name, obj); 77 else 78 myObject = obj; 79 } 80 public Object getBinding(){ 81 if(myObject != null) 82 return myObject; else{ 84 if(myContext == null) 85 myContext = new IvmContext(this); 86 return myContext; 87 } 88 } 89 public Object resolve(ParsedName name)throws javax.naming.NameNotFoundException { 90 int compareResult = name.compareTo(atomicHash); 91 92 if(compareResult == ParsedName.IS_EQUAL && name.getComponent().equals(atomicName)){ if(name.next()){ 94 if(subTree == null) throw new javax.naming.NameNotFoundException ("Can not resolve "+name); 95 return subTree.resolve(name); 96 }else 97 return getBinding(); 98 }else if(compareResult == ParsedName.IS_LESS){ if(lessTree == null) throw new javax.naming.NameNotFoundException ("Can not resolve "+name); 100 return lessTree.resolve(name); 101 102 }else{ if(grtrTree == null) throw new javax.naming.NameNotFoundException ("Can not resolve "+name); 105 return grtrTree.resolve(name); 106 } 107 } 108 109 public void bind(ParsedName name, Object obj) throws javax.naming.NameAlreadyBoundException { 110 int compareResult = name.compareTo(atomicHash); 111 if(compareResult == ParsedName.IS_EQUAL && name.getComponent().equals(atomicName)){ 112 if(name.next()){ 113 if( myObject != null) { 114 throw new javax.naming.NameAlreadyBoundException (); 115 } 116 if(subTree==null) 117 subTree = new NameNode(this, name,obj); 118 else 119 subTree.bind(name,obj); 120 } 121 else { 122 if( subTree != null) { 123 throw new javax.naming.NameAlreadyBoundException (); 124 } 125 myObject = obj; } 127 }else if(compareResult == ParsedName.IS_LESS){ 128 if(lessTree == null) 129 lessTree = new NameNode(this.parent, name, obj); 130 else 131 lessTree.bind(name,obj); 132 }else{ if(grtrTree == null) 135 grtrTree = new NameNode(this.parent, name, obj); 136 else 137 grtrTree.bind(name,obj); 138 } 139 } 140 141 public IvmContext createSubcontext( ParsedName name) throws javax.naming.NameAlreadyBoundException { 142 try { 143 bind( name, null); 144 name.reset(); 145 return (IvmContext)resolve( name); 146 } 147 catch( javax.naming.NameNotFoundException exception) { 148 exception.printStackTrace(); 149 throw new RuntimeException (); 150 } 151 } 152 } 153 | Popular Tags |