1 package org.sapia.archie.jndi; 2 3 import java.util.Enumeration ; 4 import java.util.Vector ; 5 6 import javax.naming.InvalidNameException ; 7 import javax.naming.Name ; 8 9 import org.sapia.archie.NamePart; 10 import org.sapia.archie.impl.DefaultNamePart; 11 12 20 public class JndiName implements Name { 21 22 private org.sapia.archie.Name _name; 23 24 public JndiName(){ 25 _name = new org.sapia.archie.Name(); 26 } 27 public JndiName(org.sapia.archie.Name name){ 28 _name = name; 29 } 30 31 34 public Name add(int posn, String comp) throws InvalidNameException { 35 _name.addAt(posn, new DefaultNamePart(comp)); 36 return this; 37 } 38 39 42 public Name add(String comp) throws InvalidNameException { 43 _name.add(new DefaultNamePart(comp)); 44 return this; 45 } 46 47 50 public Name addAll(int posn, Name n) throws InvalidNameException { 51 52 for(int i = 0; i < n.size(); i++){ 53 _name.addAt(posn++, new DefaultNamePart(n.get(i))); 54 } 55 return this; 56 } 57 58 61 public Name addAll(Name suffix) throws InvalidNameException { 62 for(int i = 0; i < suffix.size(); i++){ 63 _name.add(new DefaultNamePart(suffix.get(i))); 64 } 65 return this; 66 } 67 68 71 public Object clone() { 72 return new JndiName(_name); 73 } 74 75 78 public int compareTo(Object obj) { 79 return 0; 80 } 81 82 85 public boolean endsWith(Name n) { 86 return _name.endsWith(((JndiName)n)._name); 87 } 88 89 92 public String get(int posn) { 93 return ((NamePart)_name.get(posn)).asString(); 94 } 95 96 99 public boolean equals(Object obj) { 100 try{ 101 return _name.equals(((JndiName)obj)._name); 102 }catch(ClassCastException e){ 103 return false; 104 } 105 } 106 107 108 111 public Enumeration getAll() { 112 Vector v = new Vector (); 113 for(int i = 0; i < _name.count(); i++){ 114 v.add(((NamePart)_name.get(i)).asString()); 115 } 116 return v.elements(); 117 } 118 119 122 public Name getPrefix(int posn) { 123 return new JndiName(_name.getTo(posn)); 124 } 125 126 129 public Name getSuffix(int posn) { 130 return new JndiName(_name.getFrom(posn)); 131 } 132 133 136 public boolean isEmpty() { 137 return _name.count() == 0; 138 } 139 140 143 public Object remove(int posn) throws InvalidNameException { 144 return _name.removeAt(posn).asString(); 145 } 146 147 150 public int size() { 151 return _name.count(); 152 } 153 154 157 public boolean startsWith(Name n) { 158 return _name.startsWith(((JndiName)n)._name); 159 } 160 161 public String toString() { 162 if (_name == null) { 163 return "null"; 164 } else { 165 StringBuffer buff = new StringBuffer (); 166 for(int i = 0; i < _name.count(); i++){ 167 buff.append(_name.get(i).asString()); 168 if(i < _name.count() - 1){ 169 buff.append('/'); 170 } 171 } 172 return buff.toString(); 173 } 174 } 175 176 } 177 | Popular Tags |