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