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. package javax.sql.rowset.spi;
  8. import java.sql.SQLException;
  9. import javax.sql.rowset.*;
  10. /**
  11. * Indicates an error with the <code>SyncProvider</code> mechanism. This exception
  12. * is created by a <code>SyncProvider</code> abstract class extension if it
  13. * encounters violations in reading from or writing to the originating data source.
  14. * <P>
  15. * If it is implemented to do so, the <code>SyncProvider</code> object may also create a
  16. * <code>SyncResolver</code> object and either initialize the <code>SyncProviderException</code>
  17. * object with it at construction time or set it with the <code>SyncProvider</code> object at
  18. * a later time.
  19. * <P>
  20. * The method <code>acceptChanges</code> will throw this exception after the writer
  21. * has finished checking for conflicts and has found one or more conflicts. An
  22. * application may catch a <code>SyncProviderException</code> object and call its
  23. * <code>getSyncResolver</code> method to get its <code>SyncResolver</code> object.
  24. * See the code fragment in the interface comment for
  25. * <a href="SyncResolver.java"><code>SyncResolver</code></a> for an example.
  26. * This <code>SyncResolver</code> object will mirror the <code>RowSet</code>
  27. * object that generated the exception, except that it will contain only the values
  28. * from the data source that are in conflict. All other values in the <code>SyncResolver</code>
  29. * object will be <code>null</code>.
  30. * <P>
  31. * The <code>SyncResolver</code> object may be used to examine and resolve
  32. * each conflict in a row and then go to the next row with a conflict to
  33. * repeat the procedure.
  34. * <P>
  35. * A <code>SyncProviderException</code> object may or may not contain a description of the
  36. * condition causing the exception. The inherited method <code>getMessage</code> may be
  37. * called to retrieve the description if there is one.
  38. *
  39. * @author Jonathan Bruce
  40. * @see javax.sql.rowset.spi.SyncFactory
  41. * @see javax.sql.rowset.spi.SyncResolver
  42. * @see javax.sql.rowset.spi.SyncFactoryException
  43. */
  44. public class SyncProviderException extends java.sql.SQLException {
  45. /**
  46. * The instance of <code>javax.sql.rowset.spi.SyncResolver</code> that
  47. * this <code>SyncProviderException</code> object will return when its
  48. * <code>getSyncResolver</code> method is called.
  49. */
  50. private SyncResolver syncResolver = null;
  51. /**
  52. * Creates a new <code>SyncProviderException</code> object without a detail message.
  53. */
  54. public SyncProviderException() {
  55. super();
  56. }
  57. /**
  58. * Constructs a <code>SyncProviderException</code> object with the specified
  59. * detail message.
  60. *
  61. * @param msg the detail message
  62. */
  63. public SyncProviderException(String msg) {
  64. super(msg);
  65. }
  66. /**
  67. * Constructs a <code>SyncProviderException</code> object with the specified
  68. * <code>SyncResolver</code> instance.
  69. *
  70. * @param syncResolver the <code>SyncResolver</code> instance used to
  71. * to process the synchronization conflicts
  72. * @throws IllegalArgumentException if the <code>SyncResolver</code> object
  73. * is <code>null</code>.
  74. */
  75. public SyncProviderException(SyncResolver syncResolver) {
  76. if (syncResolver == null) {
  77. throw new IllegalArgumentException("Cannot instantiate a SyncProviderException " +
  78. "with a null SyncResolver object");
  79. } else {
  80. this.syncResolver = syncResolver;
  81. }
  82. }
  83. /**
  84. * Retrieves the <code>SyncResolver</code> object that has been set for
  85. * this <code>SyncProviderException</code> object, or
  86. * if none has been set, an instance of the default <code>SyncResolver</code>
  87. * implementation included in the reference implementation.
  88. * <P>
  89. * If a <code>SyncProviderException</code> object is thrown, an application
  90. * may use this method to generate a <code>SyncResolver</code> object
  91. * with which to resolve the conflict or conflicts that caused the
  92. * exception to be thrown.
  93. *
  94. * @return the <code>SyncResolver</code> object set for this
  95. * <code>SyncProviderException</code> object or, if none has
  96. * been set, an instance of the default <code>SyncResolver</code>
  97. * implementation. In addition, the default <code>SyncResolver</code>
  98. * implementation is also returned if the <code>SyncResolver()</code> or
  99. * <code>SyncResolver(String)</code> constructors are used to instantiate
  100. * the <code>SyncResolver</code> instance.
  101. */
  102. public SyncResolver getSyncResolver() {
  103. if (syncResolver != null) {
  104. return syncResolver;
  105. } else {
  106. try {
  107. syncResolver = new com.sun.rowset.internal.SyncResolverImpl();
  108. } catch (SQLException sqle) {
  109. }
  110. return syncResolver;
  111. }
  112. }
  113. /**
  114. * Sets the <code>SyncResolver</code> object for this
  115. * <code>SyncProviderException</code> object to the one supplied.
  116. * If the argument supplied is <code>null</code>, a call to the method
  117. * <code>getSyncResolver</code> will return the default reference
  118. * implementation of the <code>SyncResolver</code> interface.
  119. *
  120. * @param syncResolver the <code>SyncResolver</code> object to be set;
  121. * cannot be <code>null</code>
  122. * @throws IllegalArgumentException if the <code>SyncResolver</code> object
  123. * is <code>null</code>.
  124. * @see #getSyncResolver
  125. */
  126. public void setSyncResolver(SyncResolver syncResolver) {
  127. if (syncResolver == null) {
  128. throw new IllegalArgumentException("Cannot set a null SyncResolver " +
  129. "object");
  130. } else {
  131. this.syncResolver = syncResolver;
  132. }
  133. }
  134. static final long serialVersionUID = -939908523620640692L;
  135. }