1 21 22 package org.apache.derby.impl.drda; 23 import org.apache.derby.iapi.services.sanity.SanityManager; 24 import org.apache.derby.iapi.reference.DRDAConstants; 25 import org.apache.derby.iapi.reference.Limits; 26 27 32 class AppRequester 33 { 34 35 protected static final int MGR_LEVEL_UNKNOWN = -1; 36 37 protected static final int UNKNOWN_CLIENT = 0; 38 protected static final int JCC_CLIENT = 1; 39 protected static final int CCC_CLIENT = 2; protected static final int DNC_CLIENT = 3; 42 private static final int [] MIN_MGR_LEVELS = { 43 3, 4, 3, 4, 5, 1, 3, 4, 1, 6, 1, 5, 0 }; 57 58 protected String extnam; protected String srvnam; protected String srvrlslv; protected String srvclsnm; protected String spvnam; protected String prdid; private int[] managerLevels = new int[CodePoint.MGR_CODEPOINTS.length]; 66 private int clientType; 67 protected int versionLevel; 68 protected int releaseLevel; 69 protected int modifyLevel; 70 71 72 78 AppRequester () 79 { 80 for (int i = 0; i < CodePoint.MGR_CODEPOINTS.length; i++) 81 managerLevels[i] = MGR_LEVEL_UNKNOWN; 82 } 83 84 91 protected int getManagerLevel(int manager) 92 { 93 int mindex = CodePoint.getManagerIndex(manager); 94 if (SanityManager.DEBUG) 95 { 96 if (mindex < 0 || mindex > managerLevels.length) 97 SanityManager.THROWASSERT("Unknown manager "+ manager + " mindex = "+ 98 mindex); 99 } 100 return managerLevels[mindex]; 101 } 102 103 protected void setClientVersion(String productId) 104 { 105 prdid = productId; 106 107 versionLevel = Integer.parseInt(prdid.substring (3, 5)); 108 releaseLevel = Integer.parseInt(prdid.substring (5, 7)); 109 modifyLevel = Integer.parseInt(prdid.substring (7, 8)); 110 if (srvrlslv == null) 111 { clientType = UNKNOWN_CLIENT; } 112 else if (srvrlslv.indexOf("JCC") != -1) 113 { clientType = JCC_CLIENT; } 114 else if 115 ( 116 (srvrlslv.indexOf(DRDAConstants.DERBY_DRDA_CLIENT_ID) != -1) 117 ) 118 { clientType = DNC_CLIENT; } 119 else 120 { clientType = UNKNOWN_CLIENT; } 121 } 122 123 127 protected boolean supportsSecMecUSRSSBPWD() 128 { 129 return 130 ( 131 ( clientType == DNC_CLIENT ) && 132 ( greaterThanOrEqualTo( 10, 2, 0 ) ) 133 ); 134 } 135 136 143 protected final boolean supportsQryclsimpForLmtblkprc() { 144 return clientType == DNC_CLIENT; 145 } 146 147 154 155 protected boolean greaterThanOrEqualTo(int vLevel, int rLevel, int mLevel) 156 { 157 if (versionLevel > vLevel) 158 return true; 159 else if (versionLevel == vLevel) { 160 if (releaseLevel > rLevel) 161 return true; 162 else if (releaseLevel == rLevel) 163 if (modifyLevel >= mLevel) 164 return true; 165 } 166 return false; 167 } 168 169 184 protected void setManagerLevel(int manager, int managerLevel) 185 { 186 int i = CodePoint.getManagerIndex(manager); 187 if (SanityManager.DEBUG) 188 { 189 if (i < 0 || i > managerLevels.length) 190 SanityManager.THROWASSERT("Unknown manager "+ manager + " i = " + i); 191 } 192 if (managerLevel >= MIN_MGR_LEVELS[i]) 193 managerLevels[i] = managerLevel; 194 else 195 managerLevels[i] = 0; 196 } 197 198 204 protected boolean equals(AppRequester a) 205 { 206 if (!prdid.equals(a.prdid)) 208 return false; 209 210 if (notEquals(srvrlslv, a.srvrlslv)) 212 return false; 213 214 if (notEquals(extnam, a.extnam)) 216 return false; 217 218 if (notEquals(srvnam, a.srvnam)) 219 return false; 220 221 if (notEquals(srvclsnm, a.srvclsnm)) 222 return false; 223 224 if (notEquals(spvnam, a.spvnam)) 225 return false; 226 227 for (int i = 0; i < managerLevels.length; i++) 229 if (managerLevels[i] != a.managerLevels[i]) 230 return false; 231 232 return true; 234 } 235 243 private boolean notEquals(Object a, Object b) 244 { 245 if (a != null && b == null) 246 return true; 247 if (a == null && b != null) 248 return true; 249 if (a != null && !a.equals(b)) 250 return true; 251 return false; 252 } 253 254 258 259 protected int supportedMessageParamLength() { 260 261 switch (clientType) { 262 263 case JCC_CLIENT: 264 case DNC_CLIENT: 265 return Limits.DB2_JCC_MAX_EXCEPTION_PARAM_LENGTH; 266 default: 267 return Limits.DB2_CCC_MAX_EXCEPTION_PARAM_LENGTH; 271 272 } 273 274 } 275 276 279 280 protected int getClientType() { 281 282 return clientType; 283 284 } 285 286 291 292 protected boolean isXARequester() 293 { 294 return (getManagerLevel(CodePoint.XAMGR) >= 7); 295 296 } 297 298 } 299 | Popular Tags |