001: /*
002:
003: Derby - Class org.apache.derby.impl.drda.AppRequester
004:
005: Licensed to the Apache Software Foundation (ASF) under one or more
006: contributor license agreements. See the NOTICE file distributed with
007: this work for additional information regarding copyright ownership.
008: The ASF licenses this file to You under the Apache License, Version 2.0
009: (the "License"); you may not use this file except in compliance with
010: the License. You may obtain a copy of the License at
011:
012: http://www.apache.org/licenses/LICENSE-2.0
013:
014: Unless required by applicable law or agreed to in writing, software
015: distributed under the License is distributed on an "AS IS" BASIS,
016: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: See the License for the specific language governing permissions and
018: limitations under the License.
019:
020: */
021:
022: package org.apache.derby.impl.drda;
023:
024: import org.apache.derby.iapi.services.sanity.SanityManager;
025: import org.apache.derby.iapi.reference.DRDAConstants;
026: import org.apache.derby.iapi.reference.Limits;
027:
028: /**
029: AppRequester stores information about the application requester.
030: It is used so that multiple sessions can share information when they are
031: started from the same version of the application requester.
032: */
033: class AppRequester {
034:
035: protected static final int MGR_LEVEL_UNKNOWN = -1;
036:
037: protected static final int UNKNOWN_CLIENT = 0;
038: protected static final int JCC_CLIENT = 1;
039: protected static final int CCC_CLIENT = 2; // not yet supported.
040: protected static final int DNC_CLIENT = 3; // derby net client
041:
042: private static final int[] MIN_MGR_LEVELS = { 3, // AGENT - JCC comes in at 3
043: 4, // CCSIDMGR
044: 3, // CMNAPPC,
045: 4, // CMNSYNCPT
046: 5, // CMNTCPIP
047: 1, // DICTIONARY
048: 3, // RDB
049: 4, // RSYNCMGR
050: 1, // SECMGR
051: 6, // SQLAM
052: 1, // SUPERVISOR
053: 5, // SYNCPTMGR
054: 0 // XAMGR
055: };
056:
057: // Application requester information
058: protected String extnam; // External Name - EXCSAT
059: protected String srvnam; // Server Name - EXCSAT
060: protected String srvrlslv; // Server Product Release Level - EXCSAT
061: protected String srvclsnm; // Server Class Name - EXCSAT
062: protected String spvnam; // Supervisor Name - EXCSAT
063: protected String prdid; // Product specific identifier - ACCRDB protected
064: private int[] managerLevels = new int[CodePoint.MGR_CODEPOINTS.length];
065: private int clientType;
066: protected int versionLevel;
067: protected int releaseLevel;
068: protected int modifyLevel;
069:
070: // constructor
071: /**
072: * AppRequester constructor
073: *
074: * @exception throws IOException
075: */
076: AppRequester() {
077: for (int i = 0; i < CodePoint.MGR_CODEPOINTS.length; i++)
078: managerLevels[i] = MGR_LEVEL_UNKNOWN;
079: }
080:
081: /**
082: * get the Application requester manager level
083: *
084: * @param manager codepoint for manager we are looking for
085: *
086: * @return manager level for that manager
087: */
088: protected int getManagerLevel(int manager) {
089: int mindex = CodePoint.getManagerIndex(manager);
090: if (SanityManager.DEBUG) {
091: if (mindex < 0 || mindex > managerLevels.length)
092: SanityManager.THROWASSERT("Unknown manager " + manager
093: + " mindex = " + mindex);
094: }
095: return managerLevels[mindex];
096: }
097:
098: protected void setClientVersion(String productId) {
099: prdid = productId;
100:
101: versionLevel = Integer.parseInt(prdid.substring(3, 5));
102: releaseLevel = Integer.parseInt(prdid.substring(5, 7));
103: modifyLevel = Integer.parseInt(prdid.substring(7, 8));
104: if (srvrlslv == null) {
105: clientType = UNKNOWN_CLIENT;
106: } else if (srvrlslv.indexOf("JCC") != -1) {
107: clientType = JCC_CLIENT;
108: } else if ((srvrlslv
109: .indexOf(DRDAConstants.DERBY_DRDA_CLIENT_ID) != -1)) {
110: clientType = DNC_CLIENT;
111: } else {
112: clientType = UNKNOWN_CLIENT;
113: }
114: }
115:
116: /**
117: * Returns true if Derby's client driver supports SECMEC_USRSSBPWD
118: * DRDA security mechanism.
119: */
120: protected boolean supportsSecMecUSRSSBPWD() {
121: return ((clientType == DNC_CLIENT) && (greaterThanOrEqualTo(10,
122: 2, 0)));
123: }
124:
125: /**
126: * Check if the client expects QRYCLSIMP to be supported when the
127: * protocol is LMTBLKPRC.
128: *
129: * @return <code>true</code> if QRYCLSIMP is supported for
130: * LMTBLKPRC
131: */
132: protected final boolean supportsQryclsimpForLmtblkprc() {
133: return clientType == DNC_CLIENT;
134: }
135:
136: /**
137: * Check if provided JCC version level is greaterThanOrEqualTo current level
138: *
139: * @param vLevel Version level
140: * @param rLevel Release level
141: * @param mLevel Modification level
142: */
143:
144: protected boolean greaterThanOrEqualTo(int vLevel, int rLevel,
145: int mLevel) {
146: if (versionLevel > vLevel)
147: return true;
148: else if (versionLevel == vLevel) {
149: if (releaseLevel > rLevel)
150: return true;
151: else if (releaseLevel == rLevel)
152: if (modifyLevel >= mLevel)
153: return true;
154: }
155: return false;
156: }
157:
158: /**
159: * set Application requester manager level
160: * if the manager level is less than the minimum manager level,
161: * set the manager level to zero (saying we can't handle this
162: * level), this will be returned
163: * to the application requester and he can decide whether or not to
164: * proceed
165: * For CCSIDMGR, if the target server supports the CCSID manager but
166: * not the CCSID requested, the value returned is FFFF
167: * For now, we won't support the CCSIDMGR since JCC doesn't request it.
168: *
169: * @param manager codepoint of the manager
170: * @param managerLevel level for that manager
171: *
172: */
173: protected void setManagerLevel(int manager, int managerLevel) {
174: int i = CodePoint.getManagerIndex(manager);
175: if (SanityManager.DEBUG) {
176: if (i < 0 || i > managerLevels.length)
177: SanityManager.THROWASSERT("Unknown manager " + manager
178: + " i = " + i);
179: }
180: if (managerLevel >= MIN_MGR_LEVELS[i])
181: managerLevels[i] = managerLevel;
182: else
183: managerLevels[i] = 0;
184: }
185:
186: /**
187: * Check if the application requester is the same as this one
188: *
189: * @param a application requester to compare to
190: * @return true if same false otherwise
191: */
192: protected boolean equals(AppRequester a) {
193: // check prdid - this should be different if they are different
194: if (!prdid.equals(a.prdid))
195: return false;
196:
197: // check server product release level
198: if (notEquals(srvrlslv, a.srvrlslv))
199: return false;
200:
201: // check server names
202: if (notEquals(extnam, a.extnam))
203: return false;
204:
205: if (notEquals(srvnam, a.srvnam))
206: return false;
207:
208: if (notEquals(srvclsnm, a.srvclsnm))
209: return false;
210:
211: if (notEquals(spvnam, a.spvnam))
212: return false;
213:
214: // check manager levels
215: for (int i = 0; i < managerLevels.length; i++)
216: if (managerLevels[i] != a.managerLevels[i])
217: return false;
218:
219: // O.K. looks good
220: return true;
221: }
222:
223: /**
224: * Check whether two objects are not equal when 1 of the objects could
225: * be null
226: *
227: * @param a first object
228: * @param b second object
229: * @return true if not equals false otherwise
230: */
231: private boolean notEquals(Object a, Object b) {
232: if (a != null && b == null)
233: return true;
234: if (a == null && b != null)
235: return true;
236: if (a != null && !a.equals(b))
237: return true;
238: return false;
239: }
240:
241: /**
242: * Get the maximum length supported for an exception's message
243: * parameter string.
244: */
245:
246: protected int supportedMessageParamLength() {
247:
248: switch (clientType) {
249:
250: case JCC_CLIENT:
251: case DNC_CLIENT:
252: return Limits.DB2_JCC_MAX_EXCEPTION_PARAM_LENGTH;
253: default:
254: // Default is the max for C clients, since that is more
255: // restricted than for JCC clients. Note, though, that
256: // JCC clients are the only ones supported right now.
257: return Limits.DB2_CCC_MAX_EXCEPTION_PARAM_LENGTH;
258:
259: }
260:
261: }
262:
263: /**
264: * Get the type of the client.
265: */
266:
267: protected int getClientType() {
268:
269: return clientType;
270:
271: }
272:
273: /**
274: * Is this an AppRequester that supports XA
275: *
276: * return true if XAMGR >= 7, false otherwise
277: **/
278:
279: protected boolean isXARequester() {
280: return (getManagerLevel(CodePoint.XAMGR) >= 7);
281:
282: }
283:
284: }
|