KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > impl > drda > AppRequester


1 /*
2
3    Derby - Class org.apache.derby.impl.drda.AppRequester
4
5    Licensed to the Apache Software Foundation (ASF) under one or more
6    contributor license agreements. See the NOTICE file distributed with
7    this work for additional information regarding copyright ownership.
8    The ASF licenses this file to You under the Apache License, Version 2.0
9    (the "License"); you may not use this file except in compliance with
10    the License. You may obtain a copy of the License at
11
12       http://www.apache.org/licenses/LICENSE-2.0
13
14    Unless required by applicable law or agreed to in writing, software
15    distributed under the License is distributed on an "AS IS" BASIS,
16    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17    See the License for the specific language governing permissions and
18    limitations under the License.
19
20  */

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 /**
28     AppRequester stores information about the application requester.
29     It is used so that multiple sessions can share information when they are
30     started from the same version of the application requester.
31 */

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; // not yet supported.
40
protected static final int DNC_CLIENT = 3; // derby net client
41

42     private static final int [] MIN_MGR_LEVELS = {
43                                             3, // AGENT - JCC comes in at 3
44
4, // CCSIDMGR
45
3, // CMNAPPC,
46
4, // CMNSYNCPT
47
5, // CMNTCPIP
48
1, // DICTIONARY
49
3, // RDB
50
4, // RSYNCMGR
51
1, // SECMGR
52
6, // SQLAM
53
1, // SUPERVISOR
54
5, // SYNCPTMGR
55
0 // XAMGR
56
};
57     
58     // Application requester information
59
protected String JavaDoc extnam; // External Name - EXCSAT
60
protected String JavaDoc srvnam; // Server Name - EXCSAT
61
protected String JavaDoc srvrlslv; // Server Product Release Level - EXCSAT
62
protected String JavaDoc srvclsnm; // Server Class Name - EXCSAT
63
protected String JavaDoc spvnam; // Supervisor Name - EXCSAT
64
protected String JavaDoc prdid; // Product specific identifier - ACCRDB protected
65
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     // constructor
73
/**
74      * AppRequester constructor
75      *
76      * @exception throws IOException
77      */

78     AppRequester ()
79     {
80         for (int i = 0; i < CodePoint.MGR_CODEPOINTS.length; i++)
81             managerLevels[i] = MGR_LEVEL_UNKNOWN;
82     }
83
84     /**
85      * get the Application requester manager level
86      *
87      * @param manager codepoint for manager we are looking for
88      *
89      * @return manager level for that manager
90      */

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 JavaDoc 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     /**
124      * Returns true if Derby's client driver supports SECMEC_USRSSBPWD
125      * DRDA security mechanism.
126      */

127     protected boolean supportsSecMecUSRSSBPWD()
128     {
129         return
130             (
131                 ( clientType == DNC_CLIENT ) &&
132                 ( greaterThanOrEqualTo( 10, 2, 0 ) )
133             );
134     }
135
136     /**
137      * Check if the client expects QRYCLSIMP to be supported when the
138      * protocol is LMTBLKPRC.
139      *
140      * @return <code>true</code> if QRYCLSIMP is supported for
141      * LMTBLKPRC
142      */

143     protected final boolean supportsQryclsimpForLmtblkprc() {
144         return clientType == DNC_CLIENT;
145     }
146
147     /**
148      * Check if provided JCC version level is greaterThanOrEqualTo current level
149      *
150      * @param vLevel Version level
151      * @param rLevel Release level
152      * @param mLevel Modification level
153      */

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     /**
170      * set Application requester manager level
171      * if the manager level is less than the minimum manager level,
172      * set the manager level to zero (saying we can't handle this
173      * level), this will be returned
174      * to the application requester and he can decide whether or not to
175      * proceed
176      * For CCSIDMGR, if the target server supports the CCSID manager but
177      * not the CCSID requested, the value returned is FFFF
178      * For now, we won't support the CCSIDMGR since JCC doesn't request it.
179      *
180      * @param manager codepoint of the manager
181      * @param managerLevel level for that manager
182      *
183      */

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     /**
199      * Check if the application requester is the same as this one
200      *
201      * @param a application requester to compare to
202      * @return true if same false otherwise
203      */

204     protected boolean equals(AppRequester a)
205     {
206         // check prdid - this should be different if they are different
207
if (!prdid.equals(a.prdid))
208             return false;
209
210         // check server product release level
211
if (notEquals(srvrlslv, a.srvrlslv))
212             return false;
213
214         // check server names
215
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         // check manager levels
228
for (int i = 0; i < managerLevels.length; i++)
229             if (managerLevels[i] != a.managerLevels[i])
230                 return false;
231
232         // O.K. looks good
233
return true;
234     }
235     /**
236      * Check whether two objects are not equal when 1 of the objects could
237      * be null
238      *
239      * @param a first object
240      * @param b second object
241      * @return true if not equals false otherwise
242      */

243     private boolean notEquals(Object JavaDoc a, Object JavaDoc 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     /**
255      * Get the maximum length supported for an exception's message
256      * parameter string.
257      */

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             // Default is the max for C clients, since that is more
268
// restricted than for JCC clients. Note, though, that
269
// JCC clients are the only ones supported right now.
270
return Limits.DB2_CCC_MAX_EXCEPTION_PARAM_LENGTH;
271
272         }
273
274     }
275
276     /**
277      * Get the type of the client.
278      */

279
280     protected int getClientType() {
281
282         return clientType;
283
284     }
285
286     /**
287      * Is this an AppRequester that supports XA
288      *
289      * return true if XAMGR >= 7, false otherwise
290      **/

291
292     protected boolean isXARequester()
293     {
294         return (getManagerLevel(CodePoint.XAMGR) >= 7);
295         
296     }
297
298 }
299
Popular Tags