1 2 package com.ca.commons.naming; 3 4 import com.ca.commons.cbutil.*; 5 6 import javax.naming.*; 7 import javax.naming.directory.*; 8 9 import java.util.*; 10 11 16 17 18 19 public class DXEntry extends DXAttributes 20 { 21 24 25 DN dn = null; 26 27 31 32 public static final int NORMAL = 0; 33 34 38 39 public static final int NEW = 1; 40 41 47 48 public static final int NEW_WRITTEN = 2; 49 50 private int status = NORMAL; 51 52 56 57 public DXEntry() { super(); } 58 public DXEntry(DN dn) { super(); this.dn = dn;} 59 public DXEntry(Attribute a) { super(a); } 60 public DXEntry(Attributes a) { super(a); } 61 public DXEntry(Attributes a, DN dn) { super(a); this.dn = dn;} 62 public DXEntry(Hashtable newAtts) { super(newAtts); } 63 public DXEntry(NamingEnumeration newAtts) { super(newAtts); } 64 public DXEntry(DXEntry copyMe) 65 { 66 super(copyMe); 67 this.dn = copyMe.dn; 68 this.status = copyMe.status; 69 } 70 71 72 73 77 78 public Attribute put(Attribute attr) 79 { 80 if (attr.getID().equalsIgnoreCase("dn")) 81 { 82 try 83 { 84 Object o = attr.get(); 85 86 if (o instanceof String ) 87 dn = new DN((String )o); 88 89 else 90 dn = new DN(o.toString()); } 92 catch (NamingException e) 93 { 94 CBUtility.error("Unexpected exception in DXEntry.put.", e); 95 } 96 return null; } 98 else 99 return super.put(attr); 100 } 101 102 112 113 public void setStatus(int entryStatus) { status = entryStatus; } 114 115 121 122 public int getStatus() { return status; } 123 124 130 131 public String getStringStatus() 132 { 133 switch (status) 134 { 135 case NORMAL: return "Normal"; 136 137 case NEW: return "New"; 138 139 case NEW_WRITTEN: return "Newly Written"; 140 } 141 142 return "Unknown"; 143 } 144 145 146 151 152 public boolean isNewEntry() { return (status==NEW || status == NEW_WRITTEN); } 153 154 159 160 public void putDN(DN dn) 161 { 162 setDN(dn); 163 } 164 165 166 public void setDN(DN dn) 167 { 168 this.dn = dn; 169 } 170 171 176 177 public DN getDN() 178 { 179 return (dn==null)?new DN():dn; 180 } 181 182 186 187 public String toString() 188 { 189 return ("entry = " + getDN().toString() + "\n status: " + 190 getStringStatus() + "\n" + 191 super.toString()); 192 } 193 194 200 201 public String getString(String id) 202 { 203 Attribute a = get(id); 204 try 205 { 206 return a.get().toString(); 207 } 208 catch (Exception e) 209 { 210 return null; 211 } 212 } 213 214 219 220 public RDN getRDN() 221 { 222 if (dn == null) 223 return null; 224 225 return dn.getLowestRDN(); 226 } 227 228 } | Popular Tags |