1 23 24 package com.sun.enterprise.admin.meta.naming; 25 26 import java.io.Serializable ; 27 import java.util.Vector ; 28 import java.util.Iterator ; 29 30 import javax.management.MalformedObjectNameException ; 31 32 46 47 public final class Name implements Serializable 48 { 49 50 public static final long serialVersionUID = 4479037048166596417L; 51 public static final int kInvalidIndex = -1; 52 53 private String mString = null; 54 59 private Vector mNameParts = null; 60 61 74 75 public Name(String nameString) throws MalformedObjectNameException 76 { 77 80 NameParser parser = new NameParser(); 81 parser.parseIt(nameString); 82 Iterator iter = parser.getParts(); 83 mNameParts = new Vector (); 84 85 while (iter.hasNext()) 86 { 87 Object element = iter.next(); 88 mNameParts.addElement(element); 89 } 90 91 mString = nameString; 92 } 93 112 113 public Name getNamePart(int partNum) 114 { 115 Name namePart = null; 116 String namePartString = null; 117 int lowerLimit = -1; int upperLimit = mNameParts.size(); 120 122 namePartString = (String )mNameParts.elementAt(partNum); 123 124 try 125 { 126 namePart = new Name(namePartString); 127 } 128 catch(Exception e) 129 { 130 } 132 return namePart; 133 } 134 135 136 154 155 public Name getParent() 156 { 157 Name parentName = null; 158 159 161 int size = mNameParts.size(); 162 163 if(size > 1) 164 { 165 String nameSubstring = createPartialNameString(0, size - 1); 166 try 167 { 168 parentName = new Name(nameSubstring); 169 } 170 catch(MalformedObjectNameException e) 171 { 172 } 175 } 176 return ( parentName ); 177 } 178 179 180 187 188 public int getNumParts() 189 { 190 return ( mNameParts.size() ); 191 } 192 193 205 206 public boolean isIndexed() 207 { 208 boolean indexed = false; 209 210 211 212 if(mString.charAt(mString.length() - 1) == Tokens.kSubScriptEnderChar) 213 { 214 indexed = true; 215 } 216 217 return ( indexed ); 218 } 219 220 221 228 229 public int getIndex() 230 { 231 int index = kInvalidIndex; 232 String indexString = null; 233 int startPos, endPos; 234 235 if (isIndexed()) 236 { 237 243 startPos = mString.lastIndexOf(Tokens.kSubScriptBeginnerChar); 244 endPos = mString.lastIndexOf(Tokens.kSubScriptEnderChar); 245 246 248 indexString = mString.substring(startPos + 1, endPos); 249 try 250 { 251 index = Integer.parseInt(indexString); 252 } 253 catch(NumberFormatException e) 254 { 255 } 257 } 258 return index; 259 } 260 261 262 268 269 public String toString() 270 { 271 return ( mString ); 272 } 273 274 275 285 286 public boolean equals(Object other) 287 { 288 boolean isSame = false; 289 290 if (other instanceof Name) 291 { 292 Name otherName = (Name) other; 293 if (this.mString.equals(otherName.mString)) 294 { 295 isSame = true; 296 } 297 } 298 return ( isSame ); 299 } 300 301 302 311 312 public int hashCode() 313 { 314 return ( mString.length() * 2 + 1 ); 315 } 316 317 private String createPartialNameString(int beginIndex, int endIndex) 318 { 319 boolean isInputValid = (beginIndex <= endIndex) && 320 (endIndex < mNameParts.size()) && 321 (beginIndex >= 0); 322 StringBuffer nameBuffer = new StringBuffer (); 324 for(int i = beginIndex ; i < endIndex ; i++) 325 { 326 String aPart = (String )mNameParts.elementAt(i); 327 nameBuffer.append(aPart); 328 if(i < endIndex - 1) 329 { 330 nameBuffer.append(Tokens.kDelimiterChar); 331 } 332 } 333 334 return ( nameBuffer.toString() ); 335 } 336 337 } | Popular Tags |