1 23 24 package com.sun.enterprise.admin.common; 25 26 import java.io.Serializable ; 27 import java.util.Vector ; 28 import java.util.Iterator ; 29 30 44 45 public final class Name implements Serializable 46 { 47 48 public static final long serialVersionUID = 4479037048166596417L; 49 public static final int kInvalidIndex = -1; 50 51 private String mString = null; 52 57 private Vector mNameParts = null; 58 59 72 73 public Name(String nameString) throws MalformedNameException 74 { 75 78 NameParser parser = new NameParser(); 79 parser.parseIt(nameString); 80 Iterator iter = parser.getParts(); 81 mNameParts = new Vector (); 82 83 while (iter.hasNext()) 84 { 85 Object element = iter.next(); 86 mNameParts.addElement(element); 87 } 88 89 mString = nameString; 90 } 91 110 111 public Name getNamePart(int partNum) 112 { 113 Name namePart = null; 114 String namePartString = null; 115 int lowerLimit = -1; int upperLimit = mNameParts.size(); 118 120 namePartString = (String )mNameParts.elementAt(partNum); 121 122 try 123 { 124 namePart = new Name(namePartString); 125 } 126 catch(Exception e) 127 { 128 } 130 return namePart; 131 } 132 133 134 152 153 public Name getParent() 154 { 155 Name parentName = null; 156 157 159 int size = mNameParts.size(); 160 161 if(size > 1) 162 { 163 String nameSubstring = createPartialNameString(0, size - 1); 164 try 165 { 166 parentName = new Name(nameSubstring); 167 } 168 catch(MalformedNameException e) 169 { 170 } 173 } 174 return ( parentName ); 175 } 176 177 178 185 186 public int getNumParts() 187 { 188 return ( mNameParts.size() ); 189 } 190 191 203 204 public boolean isIndexed() 205 { 206 boolean indexed = false; 207 208 209 210 if(mString.charAt(mString.length() - 1) == Tokens.kSubScriptEnderChar) 211 { 212 indexed = true; 213 } 214 215 return ( indexed ); 216 } 217 218 219 226 227 public int getIndex() 228 { 229 int index = kInvalidIndex; 230 String indexString = null; 231 int startPos, endPos; 232 233 if (isIndexed()) 234 { 235 241 startPos = mString.lastIndexOf(Tokens.kSubScriptBeginnerChar); 242 endPos = mString.lastIndexOf(Tokens.kSubScriptEnderChar); 243 244 246 indexString = mString.substring(startPos + 1, endPos); 247 try 248 { 249 index = Integer.parseInt(indexString); 250 } 251 catch(NumberFormatException e) 252 { 253 } 255 } 256 return index; 257 } 258 259 260 266 267 public String toString() 268 { 269 return ( mString ); 270 } 271 272 273 283 284 public boolean equals(Object other) 285 { 286 boolean isSame = false; 287 288 if (other instanceof Name) 289 { 290 Name otherName = (Name) other; 291 if (this.mString.equals(otherName.mString)) 292 { 293 isSame = true; 294 } 295 } 296 return ( isSame ); 297 } 298 299 300 309 310 public int hashCode() 311 { 312 return ( mString.length() * 2 + 1 ); 313 } 314 315 private String createPartialNameString(int beginIndex, int endIndex) 316 { 317 boolean isInputValid = (beginIndex <= endIndex) && 318 (endIndex < mNameParts.size()) && 319 (beginIndex >= 0); 320 StringBuffer nameBuffer = new StringBuffer (); 322 for(int i = beginIndex ; i < endIndex ; i++) 323 { 324 String aPart = (String )mNameParts.elementAt(i); 325 nameBuffer.append(aPart); 326 if(i < endIndex - 1) 327 { 328 nameBuffer.append(Tokens.kDelimiterChar); 329 } 330 } 331 332 return ( nameBuffer.toString() ); 333 } 334 335 } | Popular Tags |