#14 Better validations - without subclassing

Release_1.0
pending
Tim Wood
5
2011-10-21
2009-05-24
No

What about better validations? For example:
@Option(shortName="c", longName = "commands", validators={FileExistsValidator.class, FileIsADirectoryValidator.class})
public File getDirectory();
must be written in this way:
@Option(shortName="c", longName = "commands")
public ExistingDirectory getDirectory();

public static class ExistingDirectory extends File{

private static final long serialVersionUID = 4490759682935809445L;

public ExistingDirectory(String name) throws IOException {
super(name);
if(!exists()){
throw new IOException("File "+name+" does not exist!");
}
if(!isDirectory()){
throw new IOException("File "+name+" is not a directory!");
}
}

}

Discussion

  • Tim Wood

    Tim Wood - 2011-10-21

    OK, what I am thinking for this is to allow an optional factory class to be specified

    factory={ExistingDirectoryFactory.class}

    I think this will satisfy a number of requirements in a straight-forward way. Including the problem of constructing a type that you cannot modify or extend.

     
  • Tim Wood

    Tim Wood - 2011-10-21
    • labels: --> Interface Improvements
    • milestone: --> Release_1.0
    • assigned_to: nobody --> flamingpenguin
    • status: open --> pending
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks