Skip to content
Snippets Groups Projects
Commit 64e0a25a authored by ribeaudc's avatar ribeaudc
Browse files

change: - Backporting changes made in 8.04.x for the parser exceptions.

SVN: 6248
parent 3b077539
No related branches found
No related tags found
No related merge requests found
......@@ -129,8 +129,8 @@ public abstract class AbstractParserObjectFactory<E> implements IParserObjectFac
}
if (propertyCodes.size() > 0)
{
throw new UnmatchedPropertiesException(clazz, allPropertyCodes, mandatoryPropertyCodes,
beanAnalyzer.getOptionalProperties(), propertyCodes);
throw new UnmatchedPropertiesException(mandatoryPropertyCodes, beanAnalyzer
.getOptionalProperties(), propertyCodes);
}
}
......
......@@ -28,38 +28,24 @@ import ch.systemsx.cisd.common.utilities.StringUtilities;
*/
public final class IndexOutOfBoundsException extends ParserException
{
private static final long serialVersionUID = 1L;
private final int column;
private static final String MESSAGE_FORMAT =
"Not enough columns available. Looking for %s column but we have only %d columns (%s).";
private final String[] lineTokens;
private static final long serialVersionUID = 1L;
public IndexOutOfBoundsException(final int index, final String[] lineTokens)
{
super(createMessage(index, lineTokens));
this.column = index;
this.lineTokens = lineTokens;
}
private final static String createMessage(final int index, final String[] lineTokens)
{
assert lineTokens != null : "Line tokens can not be null.";
assert index >= lineTokens.length : "Index must be out of range (otherwise no reason to call this exception).";
return String
.format(
"Not enough columns available. Looking for %s column but we have only %d columns (%s).",
StringUtilities.getOrdinal(index + 1), lineTokens.length, CollectionUtils
.abbreviate(lineTokens, -1, CollectionStyle.SINGLE_QUOTE_BOUNDARY));
}
public final int getColumn()
{
return column;
}
public final String[] getLineTokens()
{
return lineTokens;
assert index >= lineTokens.length : "Index must be out of range (otherwise no reason "
+ "to call this exception).";
return String.format(MESSAGE_FORMAT, StringUtilities.getOrdinal(index + 1),
lineTokens.length, CollectionUtils.abbreviate(lineTokens, -1,
CollectionStyle.SINGLE_QUOTE_BOUNDARY));
}
}
......@@ -16,7 +16,6 @@
package ch.systemsx.cisd.common.parser;
import java.util.Collections;
import java.util.Set;
import ch.systemsx.cisd.common.collections.CollectionStyle;
......@@ -29,21 +28,15 @@ import ch.systemsx.cisd.common.collections.CollectionUtils;
*/
public final class MandatoryPropertyMissingException extends ParserException
{
private static final long serialVersionUID = 1L;
/** The mandatory property codes that could not be found in the parsed file. */
private final Set<String> missingMandatoryProperties;
private static final String MESSAGE_FORMAT =
"Mandatory column(s) %s are missing (mandatory columns are %s).";
/** The fields that are mandatory. */
private final Set<String> mandatoryFields;
private static final long serialVersionUID = 1L;
public MandatoryPropertyMissingException(final Set<String> mandatoryFields,
final Set<String> missingMandatoryProperties)
{
super(createMessage(missingMandatoryProperties, mandatoryFields));
assert mandatoryFields != null && mandatoryFields.size() > 0 : "Unspecified mandatory fields.";
this.mandatoryFields = mandatoryFields;
this.missingMandatoryProperties = missingMandatoryProperties;
}
private final static String createMessage(final Set<String> missingMandatoryProperties,
......@@ -51,8 +44,8 @@ public final class MandatoryPropertyMissingException extends ParserException
{
assert missingMandatoryProperties != null : "Missing mandatory properties can not be null.";
assert missingMandatoryProperties.size() > 0 : "No reason to throw this exception.";
return String.format("Mandatory column(s) %s are missing (mandatory columns are %s).",
toString(missingMandatoryProperties), toString(mandatoryFields));
return String.format(MESSAGE_FORMAT, toString(missingMandatoryProperties),
toString(mandatoryFields));
}
final static String toString(final Set<String> set)
......@@ -60,13 +53,4 @@ public final class MandatoryPropertyMissingException extends ParserException
return CollectionUtils.abbreviate(set, -1, CollectionStyle.SINGLE_QUOTE_BOUNDARY);
}
public final Set<String> getMissingMandatoryProperties()
{
return Collections.unmodifiableSet(missingMandatoryProperties);
}
public final Set<String> getMandatoryFields()
{
return Collections.unmodifiableSet(mandatoryFields);
}
}
......@@ -16,7 +16,6 @@
package ch.systemsx.cisd.common.parser;
import java.util.Collections;
import java.util.Set;
import ch.systemsx.cisd.common.collections.CollectionStyle;
......@@ -31,46 +30,19 @@ public final class UnmatchedPropertiesException extends ParserException
{
private static final long serialVersionUID = 1L;
/** The bean this is set during the parsing process. */
private final Class<?> beanClass;
/** The property codes found in the parsed file. */
private final Set<String> allPropertyCodes;
/** The mandatory property codes found in the bean. */
private final Set<String> mandatoryCodes;
/** The optional property codes found in the bean. */
private final Set<String> optionalCodes;
/**
* The property codes of {@link #allPropertyCodes} that can neither be found in
* {@link #mandatoryCodes} nor in {@link #optionalCodes}.
*/
private final Set<String> propertyCodes;
public UnmatchedPropertiesException(final Class<?> beanClass,
final Set<String> allPropertyCodes, final Set<String> mandatoryCodes,
final Set<String> optionalCodes, final Set<String> propertyCodes)
public UnmatchedPropertiesException(final Set<String> mandatoryNames,
final Set<String> optionalNames, final Set<String> propertyNames)
{
super(createMessage(propertyCodes, mandatoryCodes, optionalCodes));
assert allPropertyCodes != null : "All property codes can not be null.";
assert mandatoryCodes != null : "Mandatory codes can not be null.";
assert optionalCodes != null : "Optional codes can not be null.";
this.beanClass = beanClass;
this.allPropertyCodes = allPropertyCodes;
this.mandatoryCodes = mandatoryCodes;
this.optionalCodes = optionalCodes;
this.propertyCodes = propertyCodes;
super(createMessage(propertyNames, mandatoryNames, optionalNames));
}
private final static String createMessage(Set<String> propertyCodes,
private final static String createMessage(Set<String> propertyNames,
Set<String> mandatoryNames, Set<String> optionalNames)
{
assert propertyCodes != null : "Property codes can not be null.";
assert propertyCodes.size() > 0 : "There is no reason to throw this exception.";
assert propertyNames != null : "Property names can not be null.";
assert propertyNames.size() > 0 : "There is no reason to throw this exception.";
final StringBuilder builder = new StringBuilder();
builder.append("Columns ").append(toString(propertyCodes)).append(
builder.append("Columns ").append(toString(propertyNames)).append(
" specified in the header are not expected (");
final boolean hasMandatory = mandatoryNames.size() > 0;
if (hasMandatory)
......@@ -97,29 +69,4 @@ public final class UnmatchedPropertiesException extends ParserException
return CollectionUtils.abbreviate(set, -1, CollectionStyle.SINGLE_QUOTE_BOUNDARY);
}
public final Class<?> getBeanClass()
{
return beanClass;
}
public final Set<String> getAllPropertyCodes()
{
return Collections.unmodifiableSet(allPropertyCodes);
}
public final Set<String> getPropertyCodes()
{
return Collections.unmodifiableSet(propertyCodes);
}
public final Set<String> getMandatoryNames()
{
return Collections.unmodifiableSet(mandatoryCodes);
}
public final Set<String> getOptionalNames()
{
return Collections.unmodifiableSet(optionalCodes);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment