001    /*
002     * CDDL HEADER START
003     *
004     * The contents of this file are subject to the terms of the
005     * Common Development and Distribution License, Version 1.0 only
006     * (the "License").  You may not use this file except in compliance
007     * with the License.
008     *
009     * You can obtain a copy of the license at
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2006-2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.util;
028    import org.opends.messages.Message;
029    
030    
031    
032    import org.opends.server.types.IdentifiedException;
033    
034    
035    
036    /**
037     * This class defines an exception that may be thrown while attempting to parse
038     * LDIF content.
039     */
040    @org.opends.server.types.PublicAPI(
041         stability=org.opends.server.types.StabilityLevel.UNCOMMITTED,
042         mayInstantiate=true,
043         mayExtend=false,
044         mayInvoke=true)
045    public final class LDIFException
046           extends IdentifiedException
047    {
048      /**
049       * The serial version identifier required to satisfy the compiler because this
050       * class extends <CODE>java.lang.Exception</CODE>, which implements the
051       * <CODE>java.io.Serializable</CODE> interface.  This value was generated
052       * using the <CODE>serialver</CODE> command-line utility included with the
053       * Java SDK.
054       */
055      private static final long serialVersionUID = 2291731429121120364L;
056    
057    
058    
059      // Indicates whether this exception is severe enough that it is no longer
060      // possible to keep reading.
061      private final boolean canContinueReading;
062    
063      // The line number of the last line read from the LDIF source.
064      private final long lineNumber;
065    
066    
067    
068      /**
069       * Creates a new LDIF exception with the provided information.
070       *
071       * @param  message    The message to use for this LDIF exception.
072       */
073      public LDIFException(Message message)
074      {
075        super(message);
076    
077    
078        lineNumber         = -1;
079        canContinueReading = true;
080      }
081    
082    
083    
084      /**
085       * Creates a new LDIF exception with the provided information.
086       *
087       * @param  message    The message to use for this LDIF exception.
088       * @param  cause      The underlying cause that triggered this LDIF exception.
089       */
090      public LDIFException(Message message, Throwable cause)
091      {
092        super(message, cause);
093    
094    
095        lineNumber         = -1;
096        canContinueReading = true;
097      }
098    
099    
100    
101      /**
102       * Creates a new LDIF exception with the provided information.
103       *
104       * @param  message             The message to use for this LDIF exception.
105       * @param  lineNumber          The line number of the last line read from the
106       *                             LDIF source.
107       * @param  canContinueReading  Indicates whether it is possible to continue
108       *                             reading from the LDIF input source.
109       */
110      public LDIFException(Message message, long lineNumber,
111                           boolean canContinueReading)
112      {
113        super(message);
114    
115    
116        this.lineNumber         = lineNumber;
117        this.canContinueReading = canContinueReading;
118      }
119    
120    
121    
122      /**
123       * Creates a new configuration exception with the provided message and
124       * underlying cause.
125       *
126       * @param  message             The message to use for this LDIF exception.
127       * @param  canContinueReading  Indicates whether it is possible to continue
128       *                             reading from the LDIF input source.
129       * @param  lineNumber          The line number of the last line read from the
130       *                             LDIF source.
131       * @param  cause               The underlying cause that triggered this LDIF
132       *                             exception.
133       */
134      public LDIFException(Message message, long lineNumber,
135                           boolean canContinueReading, Throwable cause)
136      {
137        super(message, cause);
138    
139    
140        this.lineNumber         = lineNumber;
141        this.canContinueReading = canContinueReading;
142      }
143    
144    
145    
146      /**
147       * Retrieves the line number of the last line read from the LDIF source.
148       *
149       * @return  The line number of the last line read from the LDIF source.
150       */
151      public long getLineNumber()
152      {
153        return lineNumber;
154      }
155    
156    
157    
158      /**
159       * Indicates whether the nature of this exception allows the caller to
160       * continue reading LDIF data.  If this method returns <CODE>false</CODE>,
161       * then the associated reader should be closed by the caller.
162       *
163       * @return  <CODE>true</CODE> if the problem was with a single entry but it is
164       *          possible to continue reading with the next entry, or
165       *          <CODE>false</CODE> if the problem was such that it is no longer
166       *          possible to continue reading the data.
167       */
168      public boolean canContinueReading()
169      {
170        return canContinueReading;
171      }
172    }
173