1 17 package org.alfresco.filesys.smb.dcerpc; 18 19 import java.util.Vector ; 20 21 26 public abstract class DCEList 27 { 28 29 31 private int m_infoLevel; 32 33 35 private Vector <Object > m_dceObjects; 36 37 40 protected DCEList() 41 { 42 m_dceObjects = new Vector <Object >(); 43 } 44 45 50 protected DCEList(int infoLevel) 51 { 52 m_dceObjects = new Vector <Object >(); 53 m_infoLevel = infoLevel; 54 } 55 56 62 protected DCEList(DCEBuffer buf) throws DCEBufferException 63 { 64 65 68 m_infoLevel = buf.getInt(); 69 buf.skipBytes(4); 70 71 if (buf.getPointer() != 0) 72 { 73 74 76 m_dceObjects = new Vector <Object >(); 77 } 78 else 79 { 80 81 83 m_dceObjects = null; 84 } 85 } 86 87 92 public final int getInformationLevel() 93 { 94 return m_infoLevel; 95 } 96 97 102 public final int numberOfEntries() 103 { 104 return m_dceObjects != null ? m_dceObjects.size() : 0; 105 } 106 107 112 public final Vector getList() 113 { 114 return m_dceObjects; 115 } 116 117 123 public final Object getElement(int idx) 124 { 125 126 128 if (m_dceObjects == null || idx < 0 || idx >= m_dceObjects.size()) 129 return null; 130 131 133 return m_dceObjects.elementAt(idx); 134 } 135 136 141 protected final boolean containerIsValid() 142 { 143 return m_dceObjects != null ? true : false; 144 } 145 146 151 protected final void addObject(Object obj) 152 { 153 m_dceObjects.addElement(obj); 154 } 155 156 161 protected final void setInformationLevel(int infoLevel) 162 { 163 m_infoLevel = infoLevel; 164 } 165 166 171 protected final void setList(Vector <Object > list) 172 { 173 m_dceObjects = list; 174 } 175 176 181 protected abstract DCEReadable getNewObject(); 182 183 189 public void readList(DCEBuffer buf) throws DCEBufferException 190 { 191 192 194 if (containerIsValid() == false) 195 return; 196 197 199 int numEntries = buf.getInt(); 200 if (buf.getPointer() != 0) 201 { 202 203 205 int elemCnt = buf.getInt(); 206 207 if (elemCnt > 0) 208 { 209 210 212 while (elemCnt-- > 0) 213 { 214 215 217 DCEReadable element = getNewObject(); 218 addObject(element); 219 220 222 element.readObject(buf); 223 } 224 225 227 for (int i = 0; i < numberOfEntries(); i++) 228 { 229 230 232 DCEReadable element = (DCEReadable) getList().elementAt(i); 233 234 236 element.readStrings(buf); 237 } 238 } 239 } 240 } 241 242 248 public final void writeList(DCEBuffer buf) throws DCEBufferException 249 { 250 251 253 buf.putInt(getInformationLevel()); 254 buf.putInt(getInformationLevel()); 255 256 258 if (m_dceObjects != null) 259 { 260 261 263 buf.putPointer(true); 264 buf.putInt(m_dceObjects.size()); 265 266 268 buf.putPointer(true); 269 buf.putInt(m_dceObjects.size()); 270 271 274 DCEBuffer strBuf = new DCEBuffer(); 275 276 278 for (int i = 0; i < m_dceObjects.size(); i++) 279 { 280 281 283 DCEWriteable object = (DCEWriteable) m_dceObjects.elementAt(i); 284 285 289 object.writeObject(buf, strBuf); 290 } 291 292 294 buf.putBuffer(strBuf); 295 296 298 buf.putInt(m_dceObjects.size()); 299 300 302 buf.putInt(0); 303 } 304 else 305 { 306 307 309 buf.putZeroInts(4); 310 } 311 } 312 313 318 public String toString() 319 { 320 StringBuffer str = new StringBuffer (); 321 322 str.append("[Level="); 323 str.append(getInformationLevel()); 324 str.append(",Entries="); 325 str.append(numberOfEntries()); 326 str.append(",Class="); 327 str.append(getNewObject().getClass().getName()); 328 str.append("]"); 329 330 return str.toString(); 331 } 332 } 333 | Popular Tags |