KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > ca > directory > jxplorer > broker > CBGraphicsOps


1 package com.ca.directory.jxplorer.broker;
2
3
4 import com.ca.commons.cbutil.*;
5 import com.ca.commons.jndi.*;
6 import com.ca.commons.naming.*;
7 import com.ca.commons.security.JXSSLSocketFactory;
8 import com.ca.directory.jxplorer.JXplorer;
9
10 import javax.naming.*;
11 import javax.naming.directory.*;
12 import java.util.ArrayList JavaDoc;
13 import java.util.logging.Logger JavaDoc;
14
15 /**
16  * A wrapper for BasicOps that overrides log() and error()
17  * in an application specific way.
18  */

19 public class CBGraphicsOps extends DXOps
20 {
21     public boolean quietMode = false; // whether to supress gui error reporting
22
public boolean errorWhileQuietFlag = false; // whether an error occured while quiet.
23
public Exception JavaDoc quietException = null; // what that quiet error was... (or the last one, if multiple errors occured)
24
private CBpbar pbar = null;
25
26     private static Logger JavaDoc log = Logger.getLogger(CBGraphicsOps.class.getName());
27     
28     /**
29      * Initialise with the directory context.
30      */

31      
32     public CBGraphicsOps(DirContext ctx)
33         throws NamingException
34     {
35         super(ctx);
36     }
37
38     /**
39      * Initialise with a cData object.
40      */

41
42     public CBGraphicsOps(ConnectionData cData)
43         throws NamingException
44     {
45         super(addSSLFactoryToConnectionData(cData));
46     }
47
48     /**
49      * Sets quiet error mode on or off, and clears
50      * any stored 'quietException'.
51      */

52      
53     public void setQuietMode(boolean status)
54     {
55         quietMode = status;
56         
57         if (quietMode == true)
58         {
59             errorWhileQuietFlag = false;
60             quietException = null;
61         }
62     }
63     
64     /**
65      * This override passes errors to CBUtility.error.
66      *
67      * @param msg User friendly error message
68      * @param e The exception
69      * @return returns false (always) for easy chaining.
70      */

71      
72     public boolean error(String JavaDoc msg, Exception JavaDoc e)
73     {
74         if (quietMode)
75         {
76             errorWhileQuietFlag = true;
77             quietException = e;
78             
79             log.warning(msg+"\n (details) " + ((e==null)?"no error details supplied":e.toString()));
80         }
81         else
82             CBUtility.error(msg, e);
83             
84         return false;
85     }
86
87    /**
88     * This override passes a confirmation message to CBError.confirm after a
89     * successful modify.
90     * @param dn distinguished name of object to modify
91     * @param modList a list of ModificationItems
92     * .
93     */

94     
95     public void modifyAttributes(Name dn, ModificationItem[] modList)
96         throws NamingException
97     {
98         super.modifyAttributes(dn, modList);
99         
100         if ("true".equalsIgnoreCase(JXplorer.getProperty("option.confirmTableEditorUpdates")))
101         {
102             CBUtility.confirm(CBIntText.get("Entry: {0} was successfully updated", new String JavaDoc[] {dn.toString()})); //TE: confirmation dialog.
103
}
104     }
105
106
107
108
109     /**
110      * overload this method for progress tracker.
111      */

112
113     public void startOperation(String JavaDoc heading, String JavaDoc operationName)
114     {
115         setPbar(new CBpbar(CBUtility.getDefaultDisplay(), heading, operationName));
116     }
117
118
119
120     /**
121      * overload this method for progress tracker.
122      */

123
124     public void stopOperation()
125     {
126         super.stopOperation();
127         if (getPbar()==null)
128             return;
129             
130         getPbar().close();
131         setPbar(null);
132     }
133     
134     
135
136     /**
137      * overload this method for progress tracker.
138      */

139
140     public void pop() { if (getPbar() != null) getPbar().pop();}
141
142     /**
143      * overload this method for progress tracker. Note that elements
144      * is passed to allow determination of the number of objects - but
145      * the Enumeration must be returned without being reset, so be carefull
146      * when using it...
147      */

148
149     public NamingEnumeration push(NamingEnumeration elements)
150     {
151         DXNamingEnumeration DXelements = new DXNamingEnumeration(elements);
152         int size = DXelements.size(); // this *doesn't* use up the enumeration - it gets refreshed...
153
if (getPbar()!=null) getPbar().push(size);
154         return DXelements;
155     }
156
157     /**
158      * overload this method for progress tracker. Note that elements
159      * is passed to allow determination of the number of objects - but
160      * the Enumeration must be returned without being reset, so be carefull
161      * when using it...
162      */

163
164     public void push(ArrayList JavaDoc elements)
165     {
166         int size = elements.size();
167         if (getPbar()!=null) getPbar().push(size);
168     }
169
170     /**
171      * overload this method for progress tracker.
172      */

173
174     public void inc() { if (getPbar()!=null) getPbar().inc();}
175
176
177     /**
178     * This sets the connctionData to use our advanced SSL Socket Factory, after initialising
179     * that socket factory.
180     *
181     * @param connectionData a data object contain all the connection details.
182     */

183
184     public static ConnectionData addSSLFactoryToConnectionData(ConnectionData connectionData)
185         throws NamingException
186     {
187         //System.out.println("*** connection data *** ");
188
//System.out.println(connectionData.toString());
189
//System.out.println("*** end connection data *** ");
190

191         if (connectionData.useSSL)
192         {
193
194 // we could fall back to the old ssl socket factory for SASL, which must be set up right from the start, so there's
195
// no point allowing on-the-fly addition of certificates...
196
// if (connectionData.clientKeystorePwd != null)
197
// {
198
// connectionData.sslSocketFactory = "com.ca.commons.jndi.JndiSocketFactory";
199
// }
200
// else
201
// {
202
try
203                 {
204                     JXSSLSocketFactory.init(connectionData.cacerts, connectionData.clientcerts,
205                                             connectionData.caKeystorePwd, connectionData.clientKeystorePwd,
206                                             connectionData.caKeystoreType, connectionData.clientKeystoreType, CBUtility.getDefaultDisplay());
207
208                     JXSSLSocketFactory.setDebug(JXplorer.debugLevel >= 9);
209
210                     connectionData.sslSocketFactory = "com.ca.commons.security.JXSSLSocketFactory";
211                 }
212                 // this is a little hacky. We have to throw NamingException to conform with the original
213
// method signiture of the over-ridden method.
214
catch (Exception JavaDoc e)
215                 {
216                     NamingException ne = new NamingException("error pre-initialising SSL for JNDI connection: " + e.toString());
217                     ne.setRootCause(e);
218                     throw ne;
219                 }
220 // }
221
}
222
223
224         return connectionData;
225     }
226
227     public CBpbar getPbar()
228     {
229         return pbar;
230     }
231
232     public void setPbar(CBpbar pbar)
233     {
234         this.pbar = pbar;
235     }
236
237 }
Popular Tags