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 legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2006-2009 Sun Microsystems, Inc. 025 * Portions Copyright 2014-2015 ForgeRock AS 026 */ 027package org.opends.server.util; 028import org.forgerock.i18n.LocalizableMessage; 029 030 031 032import 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) 045public 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 /** 060 * Indicates whether this exception is severe enough that it is no longer 061 * possible to keep reading. 062 */ 063 private final boolean canContinueReading; 064 065 /** The line number of the last line read from the LDIF source. */ 066 private final long lineNumber; 067 068 069 070 /** 071 * Creates a new LDIF exception with the provided information. 072 * 073 * @param message The message to use for this LDIF exception. 074 */ 075 public LDIFException(LocalizableMessage message) 076 { 077 super(message); 078 079 080 lineNumber = -1; 081 canContinueReading = true; 082 } 083 084 085 086 /** 087 * Creates a new LDIF exception with the provided information. 088 * 089 * @param message The message to use for this LDIF exception. 090 * @param cause The underlying cause that triggered this LDIF exception. 091 */ 092 public LDIFException(LocalizableMessage message, Throwable cause) 093 { 094 super(message, cause); 095 096 097 lineNumber = -1; 098 canContinueReading = true; 099 } 100 101 102 103 /** 104 * Creates a new LDIF exception with the provided information. 105 * 106 * @param message The message to use for this LDIF exception. 107 * @param lineNumber The line number of the last line read from the 108 * LDIF source. 109 * @param canContinueReading Indicates whether it is possible to continue 110 * reading from the LDIF input source. 111 */ 112 public LDIFException(LocalizableMessage message, Number lineNumber, 113 boolean canContinueReading) 114 { 115 super(message); 116 117 this.lineNumber = lineNumber.longValue(); 118 this.canContinueReading = canContinueReading; 119 } 120 121 122 123 /** 124 * Creates a new configuration exception with the provided message and 125 * underlying cause. 126 * 127 * @param message The message to use for this LDIF exception. 128 * @param canContinueReading Indicates whether it is possible to continue 129 * reading from the LDIF input source. 130 * @param lineNumber The line number of the last line read from the 131 * LDIF source. 132 * @param cause The underlying cause that triggered this LDIF 133 * exception. 134 */ 135 public LDIFException(LocalizableMessage message, Number lineNumber, 136 boolean canContinueReading, Throwable cause) 137 { 138 super(message, cause); 139 140 this.lineNumber = lineNumber.longValue(); 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