KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > sql > rowset > spi > SyncProviderException


1 /*
2  * @(#)SyncProviderException.java 1.7 04/05/29
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.sql.rowset.spi;
9
10 import java.sql.SQLException JavaDoc;
11 import javax.sql.rowset.*;
12
13 /**
14  * Indicates an error with the <code>SyncProvider</code> mechanism. This exception
15  * is created by a <code>SyncProvider</code> abstract class extension if it
16  * encounters violations in reading from or writing to the originating data source.
17  * <P>
18  * If it is implemented to do so, the <code>SyncProvider</code> object may also create a
19  * <code>SyncResolver</code> object and either initialize the <code>SyncProviderException</code>
20  * object with it at construction time or set it with the <code>SyncProvider</code> object at
21  * a later time.
22  * <P>
23  * The method <code>acceptChanges</code> will throw this exception after the writer
24  * has finished checking for conflicts and has found one or more conflicts. An
25  * application may catch a <code>SyncProviderException</code> object and call its
26  * <code>getSyncResolver</code> method to get its <code>SyncResolver</code> object.
27  * See the code fragment in the interface comment for
28  * <a HREF="SyncResolver.java"><code>SyncResolver</code></a> for an example.
29  * This <code>SyncResolver</code> object will mirror the <code>RowSet</code>
30  * object that generated the exception, except that it will contain only the values
31  * from the data source that are in conflict. All other values in the <code>SyncResolver</code>
32  * object will be <code>null</code>.
33  * <P>
34  * The <code>SyncResolver</code> object may be used to examine and resolve
35  * each conflict in a row and then go to the next row with a conflict to
36  * repeat the procedure.
37  * <P>
38  * A <code>SyncProviderException</code> object may or may not contain a description of the
39  * condition causing the exception. The inherited method <code>getMessage</code> may be
40  * called to retrieve the description if there is one.
41  *
42  * @author Jonathan Bruce
43  * @see javax.sql.rowset.spi.SyncFactory
44  * @see javax.sql.rowset.spi.SyncResolver
45  * @see javax.sql.rowset.spi.SyncFactoryException
46  */

47 public class SyncProviderException extends java.sql.SQLException JavaDoc {
48      
49     /**
50      * The instance of <code>javax.sql.rowset.spi.SyncResolver</code> that
51      * this <code>SyncProviderException</code> object will return when its
52      * <code>getSyncResolver</code> method is called.
53      */

54      private SyncResolver JavaDoc syncResolver = null;
55      
56     /**
57      * Creates a new <code>SyncProviderException</code> object without a detail message.
58      */

59     public SyncProviderException() {
60         super();
61     }
62
63     /**
64      * Constructs a <code>SyncProviderException</code> object with the specified
65      * detail message.
66      *
67      * @param msg the detail message
68      */

69     public SyncProviderException(String JavaDoc msg) {
70         super(msg);
71     }
72     
73     /**
74      * Constructs a <code>SyncProviderException</code> object with the specified
75      * <code>SyncResolver</code> instance.
76      *
77      * @param syncResolver the <code>SyncResolver</code> instance used to
78      * to process the synchronization conflicts
79      * @throws IllegalArgumentException if the <code>SyncResolver</code> object
80      * is <code>null</code>.
81      */

82     public SyncProviderException(SyncResolver JavaDoc syncResolver) {
83         if (syncResolver == null) {
84             throw new IllegalArgumentException JavaDoc("Cannot instantiate a SyncProviderException " +
85                 "with a null SyncResolver object");
86         } else {
87             this.syncResolver = syncResolver;
88         }
89     }
90     
91     /**
92      * Retrieves the <code>SyncResolver</code> object that has been set for
93      * this <code>SyncProviderException</code> object, or
94      * if none has been set, an instance of the default <code>SyncResolver</code>
95      * implementation included in the reference implementation.
96      * <P>
97      * If a <code>SyncProviderException</code> object is thrown, an application
98      * may use this method to generate a <code>SyncResolver</code> object
99      * with which to resolve the conflict or conflicts that caused the
100      * exception to be thrown.
101      *
102      * @return the <code>SyncResolver</code> object set for this
103      * <code>SyncProviderException</code> object or, if none has
104      * been set, an instance of the default <code>SyncResolver</code>
105      * implementation. In addition, the default <code>SyncResolver</code>
106      * implementation is also returned if the <code>SyncResolver()</code> or
107      * <code>SyncResolver(String)</code> constructors are used to instantiate
108      * the <code>SyncResolver</code> instance.
109      */

110     public SyncResolver JavaDoc getSyncResolver() {
111         if (syncResolver != null) {
112             return syncResolver;
113         } else {
114             try {
115               syncResolver = new com.sun.rowset.internal.SyncResolverImpl();
116             } catch (SQLException JavaDoc sqle) {
117             }
118             return syncResolver;
119         }
120     }
121     
122     /**
123      * Sets the <code>SyncResolver</code> object for this
124      * <code>SyncProviderException</code> object to the one supplied.
125      * If the argument supplied is <code>null</code>, a call to the method
126      * <code>getSyncResolver</code> will return the default reference
127      * implementation of the <code>SyncResolver</code> interface.
128      *
129      * @param syncResolver the <code>SyncResolver</code> object to be set;
130      * cannot be <code>null</code>
131      * @throws IllegalArgumentException if the <code>SyncResolver</code> object
132      * is <code>null</code>.
133      * @see #getSyncResolver
134      */

135     public void setSyncResolver(SyncResolver JavaDoc syncResolver) {
136         if (syncResolver == null) {
137             throw new IllegalArgumentException JavaDoc("Cannot set a null SyncResolver " +
138                 "object");
139         } else {
140             this.syncResolver = syncResolver;
141         }
142     }
143     
144     static final long serialVersionUID = -939908523620640692L;
145         
146 }
147
148
149
Popular Tags