Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/apache/derby/impl/drda/AppRequester.java


1   /*
2   
3      Derby - Class org.apache.derby.impl.drda.AppRequester
4   
5      Copyright 2002, 2004 The Apache Software Foundation or its licensors, as applicable.
6   
7      Licensed under the Apache License, Version 2.0 (the "License");
8      you may not use this file except in compliance with the License.
9      You may obtain a copy of the License at
10  
11        http://www.apache.org/licenses/LICENSE-2.0
12  
13     Unless required by applicable law or agreed to in writing, software
14     distributed under the License is distributed on an "AS IS" BASIS,
15     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16     See the License for the specific language governing permissions and
17     limitations under the License.
18  
19   */
20  
21  package org.apache.derby.impl.drda;
22  import org.apache.derby.iapi.services.sanity.SanityManager;
23  import org.apache.derby.iapi.reference.Limits;
24  
25  /**
26    AppRequester stores information about the application requester.
27    It is used so that multiple sessions can share information when they are
28    started from the same version of the application requester.
29  */
30  class AppRequester
31  {
32  
33    protected static final int MGR_LEVEL_UNKNOWN = -1;
34  
35    protected static final int UNKNOWN_CLIENT = 0;
36    protected static final int JCC_CLIENT = 1;
37    protected static final int CCC_CLIENT = 2;    // not yet supported.
38    protected static final int DNC_CLIENT = 3;    // derby net client 
39  
40    private static final int [] MIN_MGR_LEVELS = {
41                        3, // AGENT - JCC comes in at 3
42                        4, // CCSIDMGR  
43                        3, // CMNAPPC, 
44                        4, // CMNSYNCPT
45                        5, // CMNTCPIP
46                        1, // DICTIONARY
47                        3, // RDB
48                        4, // RSYNCMGR
49                        1, // SECMGR  
50                        6, // SQLAM
51                        1, // SUPERVISOR  
52                        5, // SYNCPTMGR
53                        0  // XAMGR
54                        };
55    // Application requester information
56    protected String  extnam;      // External Name - EXCSAT
57    protected String  srvnam;      // Server Name - EXCSAT
58    protected String   srvrlslv;    // Server Product Release Level - EXCSAT
59    protected String  srvclsnm;    // Server Class Name - EXCSAT
60    protected String  spvnam;      // Supervisor Name - EXCSAT
61    protected String  prdid;      // Product specific identifier - ACCRDB protected
62    private int[]    managerLevels = new int[CodePoint.MGR_CODEPOINTS.length];
63    private int     clientType;
64    protected int    versionLevel;
65    protected int    releaseLevel;
66    protected int    modifyLevel;
67    
68  
69    // constructor 
70    /** 
71     * AppRequester constructor
72     * 
73     * @exception throws IOException
74     */
75    protected AppRequester () 
76    {
77      for (int i = 0; i < CodePoint.MGR_CODEPOINTS.length; i++)
78        managerLevels[i] = MGR_LEVEL_UNKNOWN;
79    }
80  
81    /**
82     * get the Application requester manager level
83     *
84     * @param manager  codepoint for manager we are looking for
85     *
86     * @return manager level for that manager
87     */
88    protected int getManagerLevel(int manager)
89    {
90      int mindex = CodePoint.getManagerIndex(manager);
91      if (SanityManager.DEBUG)
92      {
93        if (mindex < 0 || mindex > managerLevels.length)
94          SanityManager.THROWASSERT("Unknown manager "+ manager + " mindex = "+
95            mindex);
96      }
97      return managerLevels[mindex];
98    }
99  
100   protected void setClientVersion(String productId)
101   {
102     prdid = productId;
103 
104     versionLevel = Integer.parseInt(prdid.substring (3, 5));
105     releaseLevel = Integer.parseInt(prdid.substring (5, 7));
106     modifyLevel = Integer.parseInt(prdid.substring (7, 8));
107     if (srvrlslv == null)
108       clientType = UNKNOWN_CLIENT;
109     else if (srvrlslv.indexOf("JCC") != -1)
110       clientType = JCC_CLIENT;
111     else if (srvrlslv.indexOf("DNC") != -1)
112       clientType = DNC_CLIENT;
113     else
114       clientType = UNKNOWN_CLIENT;
115   }
116 
117   /**
118    * Check if provided JCC version level is greaterThanOrEqualTo current level
119    *
120    * @param vLevel  Version level
121    * @param rLevel  Release level
122    * @param mLevel  Modification level
123    */
124    
125   protected boolean greaterThanOrEqualTo(int vLevel, int rLevel, int mLevel)
126   {
127     if (versionLevel > vLevel)
128         return true;
129     else if (versionLevel == vLevel) {
130         if (releaseLevel > rLevel)
131             return true;
132         else if (releaseLevel == rLevel)
133             if (modifyLevel >= mLevel)
134                 return true;
135     }
136       return false;
137   }
138 
139   /** 
140    * set Application requester manager level
141    * if the manager level is less than the minimum manager level,
142    * set the manager level to zero (saying we can't handle this
143    * level), this will be returned
144    * to the application requester and he can decide whether or not to
145    * proceed
146    * For CCSIDMGR, if the target server supports the CCSID manager but
147    * not the CCSID requested, the value returned is FFFF
148    * For now, we won't support the CCSIDMGR since JCC doesn't request it.
149    *
150    * @param manager  codepoint of the manager
151    * @param managerLevel  level for that manager
152    *
153    */
154   protected void setManagerLevel(int manager, int managerLevel)
155   {
156     int i = CodePoint.getManagerIndex(manager);
157     if (SanityManager.DEBUG)
158     {
159       if (i < 0 || i > managerLevels.length)
160         SanityManager.THROWASSERT("Unknown manager "+ manager + " i = " + i);
161     }
162     if (managerLevel >= MIN_MGR_LEVELS[i])
163       managerLevels[i] = managerLevel;  
164     else
165       managerLevels[i] = 0;
166   }
167   
168   /**
169    * Check if the application requester is the same as this one
170    *
171    * @param a  application requester to compare to
172    * @return true if same false otherwise
173    */
174   protected boolean equals(AppRequester a)
175   {
176     // check prdid - this should be different if they are different
177     if (!prdid.equals(a.prdid))
178       return false;
179 
180     // check server product release level
181     if (notEquals(srvrlslv, a.srvrlslv))
182       return false;
183 
184     // check server names
185     if (notEquals(extnam, a.extnam))
186       return false;
187 
188     if (notEquals(srvnam, a.srvnam))
189       return false;
190 
191     if (notEquals(srvclsnm, a.srvclsnm))
192       return false;
193 
194     if (notEquals(spvnam, a.spvnam))
195       return false;
196 
197     // check manager levels
198     for (int i = 0; i < managerLevels.length; i++)
199       if (managerLevels[i] != a.managerLevels[i])
200         return false;
201 
202     // O.K. looks good
203     return true;
204   }
205   /**
206    * Check whether two objects are not equal when 1 of the objects could
207    * be null
208    *
209     * @param a  first object
210    * @param b second object
211    * @return true if not equals false otherwise
212    */
213   private boolean notEquals(Object a, Object b)
214   {
215     if (a != null && b == null)
216       return true;
217     if (a == null && b != null)
218       return true;
219     if (a != null && !a.equals(b))
220       return true;
221     return false;
222   }
223 
224   /**
225    * Get the maximum length supported for an exception's message
226    * parameter string.
227    */
228 
229   protected int supportedMessageParamLength() {
230 
231     switch (clientType) {
232 
233       case JCC_CLIENT:
234       case DNC_CLIENT:
235         return Limits.DB2_JCC_MAX_EXCEPTION_PARAM_LENGTH;
236       default:
237       // Default is the max for C clients, since that is more
238       // restricted than for JCC clients.  Note, though, that
239       // JCC clients are the only ones supported right now.
240         return Limits.DB2_CCC_MAX_EXCEPTION_PARAM_LENGTH;
241 
242     }
243 
244   }
245 
246   /**
247    * Get the type of the client.
248    */
249 
250   protected int getClientType() {
251 
252     return clientType;
253 
254   }
255 
256   /**
257    * Is this an AppRequester that supports XA 
258    *
259    * return true if XAMGR >= 7, false otherwise
260    **/
261 
262   protected  boolean isXARequester()
263   {
264     return (getManagerLevel(CodePoint.XAMGR) >= 7);
265     
266   }
267 
268 }