1 17 package org.alfresco.filesys.smb.dcerpc; 18 19 22 public class PolicyHandle 23 { 24 25 27 public static final int POLICY_HANDLE_SIZE = 20; 28 29 31 private byte[] m_handle; 32 33 35 private String m_name; 36 37 40 public PolicyHandle() 41 { 42 setName(""); 43 } 44 45 51 public PolicyHandle(byte[] buf, int off) 52 { 53 initialize(buf, off); 54 setName(""); 55 } 56 57 64 public PolicyHandle(String name, byte[] buf, int off) 65 { 66 initialize(buf, off); 67 setName(name); 68 } 69 70 75 public final boolean isValid() 76 { 77 return m_handle != null ? true : false; 78 } 79 80 85 public final byte[] getBytes() 86 { 87 return m_handle; 88 } 89 90 95 public final String getName() 96 { 97 return m_name; 98 } 99 100 105 public final void setName(String name) 106 { 107 m_name = name; 108 } 109 110 117 public final int storePolicyHandle(byte[] buf, int off) 118 { 119 120 122 if (isValid() == false) 123 return -1; 124 125 127 for (int i = 0; i < POLICY_HANDLE_SIZE; i++) 128 buf[off + i] = m_handle[i]; 129 130 132 return off + POLICY_HANDLE_SIZE; 133 } 134 135 142 public final int loadPolicyHandle(byte[] buf, int off) 143 { 144 145 147 initialize(buf, off); 148 return off + POLICY_HANDLE_SIZE; 149 } 150 151 154 protected final void clearHandle() 155 { 156 m_handle = null; 157 } 158 159 165 private final void initialize(byte[] buf, int off) 166 { 167 168 170 if ((off + POLICY_HANDLE_SIZE) <= buf.length) 171 { 172 173 175 m_handle = new byte[POLICY_HANDLE_SIZE]; 176 177 179 for (int i = 0; i < POLICY_HANDLE_SIZE; i++) 180 m_handle[i] = buf[off + i]; 181 } 182 } 183 184 189 public String toString() 190 { 191 StringBuffer str = new StringBuffer (); 192 193 str.append("["); 194 195 if (getName() != null) 196 str.append(getName()); 197 str.append(":"); 198 199 if (isValid()) 200 { 201 for (int i = 0; i < POLICY_HANDLE_SIZE; i++) 202 { 203 int val = (int) (m_handle[i] & 0xFF); 204 if (val <= 16) 205 str.append("0"); 206 str.append(Integer.toHexString(val).toUpperCase()); 207 str.append("-"); 208 } 209 str.setLength(str.length() - 1); 210 str.append("]"); 211 } 212 213 return str.toString(); 214 } 215 } 216 | Popular Tags |