1 19 20 package org.netbeans.api.registry; 21 22 23 24 38 public final class ObjectRef { 39 40 private Context ctx; 41 private String bindingName; 42 private String ctxName; 43 44 45 private ObjectRef(Context rootCtx, Context ctx, String ctxName, String bindingName) { 46 this.bindingName = bindingName; 47 48 this.ctx = ctx; 49 this.ctxName = ctxName; 50 51 if (this.ctx != null && this.ctxName == null) { 52 this.ctxName = ctx.getAbsoluteContextName(); 53 } 54 if (this.ctx == null && this.ctxName != null && rootCtx != null) { 55 this.ctx = rootCtx.getSubcontext(ctxName.substring(1)); 56 } 57 } 58 59 66 public ObjectRef(Context rootContext, String absoluteContextName, String bindingName) { 67 this (rootContext, null, absoluteContextName, bindingName); 68 } 69 70 76 public ObjectRef(Context context, String bindingName) { 77 this (null, context, null, bindingName); 78 } 79 80 85 public Context getContext() { 86 return ctx; 87 } 88 89 94 public String getContextAbsoluteName() { 95 return ctxName; 96 } 97 98 103 public String getBindingName() { 104 return bindingName; 105 } 106 107 112 public Object getObject() { 113 if (isValid()) { 114 return getContext().getObject(getBindingName(), null); 115 } else { 116 return null; 117 } 118 } 119 120 125 public boolean isValid() { 126 return ctx != null; 127 } 128 129 public boolean equals(Object o) { 130 if (o == this) { 131 return true; 132 } 133 if (!(o instanceof ObjectRef)) { 134 return false; 135 } 136 ObjectRef or = (ObjectRef)o; 137 return (this.ctx == or.ctx && 138 this.bindingName.equals(or.bindingName) && 139 this.ctxName.equals(or.ctxName)); 140 } 141 142 public int hashCode() { 143 int result = 7; 144 result = 31*result + ctx.hashCode(); 145 result = 31*result + bindingName.hashCode(); 146 result = 31*result + ctxName.hashCode(); 147 return result; 148 } 149 150 public String toString() { 151 return "ObjectRef [context="+getContext()+", ctxName="+ 152 ctxName+", object="+getObject()+"] " + super.toString(); } 154 155 } 156 | Popular Tags |