-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement more and louder validation of config properties.
- Loading branch information
Showing
7 changed files
with
104 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.mchange.v2.c3p0.cfg; | ||
|
||
public final class InvalidConfigException extends Exception | ||
{ | ||
public InvalidConfigException( String message, Throwable cause ) | ||
{ super( message, cause ); } | ||
|
||
public InvalidConfigException( String message ) | ||
{ this( message, null ); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package com.mchange.v2.c3p0.cfg; | ||
|
||
interface Validator<T> | ||
{ | ||
public T validate( T value ) throws InvalidConfigException; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.mchange.v2.c3p0.cfg; | ||
|
||
public final class Validators | ||
{ | ||
static abstract class AbstractValidator<T> implements Validator<T> | ||
{ | ||
String param; | ||
|
||
AbstractValidator( String param ) | ||
{ this.param = param; } | ||
|
||
abstract T _validate( T value ) throws InvalidConfigException; | ||
|
||
public T validate( T value ) throws InvalidConfigException | ||
{ | ||
try | ||
{ return _validate(value); } | ||
catch (InvalidConfigException ice) | ||
{ throw ice; } | ||
catch (Exception e) | ||
{ throw new InvalidConfigException("While validating '" + param + "', encountered Exception: " + e, e); } | ||
} | ||
} | ||
|
||
public static Validator<String> MarkSessionBoundaries = new AbstractValidator<String>("markSessionBoundaries") | ||
{ | ||
String _validate( String value ) throws InvalidConfigException | ||
{ | ||
String out = value.toLowerCase(); | ||
if ("always".equals(out)||"never".equals(out)||"if-no-statement-cache".equals(out)) | ||
return out; | ||
else | ||
throw new InvalidConfigException(param + " must be one of 'always', 'never', or 'if-no-statement-cache'. Found '" + value + "'."); | ||
} | ||
}; | ||
|
||
public static Validator<String> ContextClassLoaderSource = new AbstractValidator<String>("contextClassLoaderSource") | ||
{ | ||
String _validate( String value ) throws InvalidConfigException | ||
{ | ||
String out = value.toLowerCase(); | ||
if ("caller".equals(out)||"library".equals(out)||"none".equals(out)) | ||
return out; | ||
else | ||
throw new InvalidConfigException(param + " must be one of 'caller', 'library', or 'none'. Found '" + value + "'."); | ||
} | ||
}; | ||
|
||
private Validators() | ||
{} | ||
} |