From: <mg...@us...> - 2008-01-30 18:48:08
|
Revision: 1428 http://obo.svn.sourceforge.net/obo/?rev=1428&view=rev Author: mgibson Date: 2008-01-30 10:48:13 -0800 (Wed, 30 Jan 2008) Log Message: ----------- putting in architecture for constraints juancarlos - not quite done yet but thought you might like to see where its going - and what do you think - seem reasonable? Modified Paths: -------------- phenote/trunk/src/java/phenote/gui/CharacterTableController.java Added Paths: ----------- phenote/trunk/src/java/phenote/dataadapter/Constraint.java phenote/trunk/src/java/phenote/dataadapter/ConstraintManager.java phenote/trunk/src/java/phenote/dataadapter/ConstraintStatus.java Added: phenote/trunk/src/java/phenote/dataadapter/Constraint.java =================================================================== --- phenote/trunk/src/java/phenote/dataadapter/Constraint.java (rev 0) +++ phenote/trunk/src/java/phenote/dataadapter/Constraint.java 2008-01-30 18:48:13 UTC (rev 1428) @@ -0,0 +1,21 @@ +package phenote.dataadapter; + +public interface Constraint { + + /** Return true if constraint should be checked at commit time to + dataadapter */ + public boolean isCommitConstraint(); + /** do constraint check for commit time - should char list be passed in? + return ConstraintStatus indication if constraint passed and error msg + should only be called if isCommitConstraint is true */ + public ConstraintStatus checkCommit(); + + /** Return true if constraint should be checked after user edits */ + public boolean isEditConstraint(); + /** do constraint check after user edit - should char list be passed in? + return ConstraintStatus indication if constraint passed and error msg + should only be called if isEditConstraint is true */ + public ConstraintStatus checkEdit(); + + +} Added: phenote/trunk/src/java/phenote/dataadapter/ConstraintManager.java =================================================================== --- phenote/trunk/src/java/phenote/dataadapter/ConstraintManager.java (rev 0) +++ phenote/trunk/src/java/phenote/dataadapter/ConstraintManager.java 2008-01-30 18:48:13 UTC (rev 1428) @@ -0,0 +1,53 @@ +package phenote.dataadapter; + +import java.util.ArrayList; +import java.util.List; + +/** ConstraintManager holds all constraints. a constraint can be for edit and/or + commit time. ConstraintStatus is returned from checking constraint that indicates + failure and gives error message. Singleton. + should there be a constraint package? subpackage? */ + +public class ConstraintManager { + + private static ConstraintManager singleton; + + private List<Constraint> constraintList = new ArrayList(4); + + public static ConstraintManager inst() { + if (singleton==null) singleton = new ConstraintManager(); + return singleton; + } + + /** private singleton constructor */ + private ConstraintManager() {} + + public ConstraintStatus checkCommitConstraints() { + ConstraintStatus statusList = ConstraintStatus.OK; //? + for (Constraint c : constraintList) { + if (c.isCommitConstraint()) { + ConstraintStatus cs = c.checkCommit(); + statusList.addStatusChild(cs); + } + } + return statusList; + } + + public ConstraintStatus checkEditConstraints() { + ConstraintStatus statusList = ConstraintStatus.OK; //? + for (Constraint c : constraintList) { + if (c.isEditConstraint()) { + ConstraintStatus cs = c.checkEdit(); + statusList.addStatusChild(cs); + } + } + return statusList; + } + + + + public void addConstraint(Constraint c) { + constraintList.add(c); + } + +} Added: phenote/trunk/src/java/phenote/dataadapter/ConstraintStatus.java =================================================================== --- phenote/trunk/src/java/phenote/dataadapter/ConstraintStatus.java (rev 0) +++ phenote/trunk/src/java/phenote/dataadapter/ConstraintStatus.java 2008-01-30 18:48:13 UTC (rev 1428) @@ -0,0 +1,67 @@ +package phenote.dataadapter; + +import java.util.ArrayList; +import java.util.List; + +/** A constraint returns creates & returns one of these, says whether contraint checks + out ok and gives error message + A constraintStatus is recursive - it can hold ConstraintStatus kids - so if theres + a list of constraints all their status is returned in one ConstraintStatus */ + +public class ConstraintStatus { + + /** is there more states than OK & Fail? if so will need an enum */ + private boolean isFailure = false; + private String message = ""; + private List<ConstraintStatus> kids; + + public static ConstraintStatus OK = new ConstraintStatus(false); + + public ConstraintStatus(boolean isFailure,String message) { + this(isFailure); + if (message!=null) this.message = message; + } + + public ConstraintStatus(boolean isFailure) { + this.isFailure = isFailure; + } + + public boolean constraintFailed() { + if (!hasKids()) + return isFailure; + else { + for (ConstraintStatus cs : kids) { + if (cs.constraintFailed()) return true; + } + return false; // ? + } + } + + public String getMessage() { + if (!hasKids()) + return message; + else { + StringBuffer sb = new StringBuffer(); + // can parent have independent message? + if (message!=null & !message.equals("")) sb.append(message).append("\n"); + for (ConstraintStatus kid : kids) { + sb.append(kid.getMessage()).append("\n\n"); + } + return sb.toString(); + } + } + + void addStatusChild(ConstraintStatus kid) { + getKids().add(kid); + } + + private boolean hasKids() { + return kids!= null && !kids.isEmpty(); + } + + private List<ConstraintStatus> getKids() { + if (kids==null) kids = new ArrayList<ConstraintStatus>(3); + return kids; + } + +} Modified: phenote/trunk/src/java/phenote/gui/CharacterTableController.java =================================================================== --- phenote/trunk/src/java/phenote/gui/CharacterTableController.java 2008-01-29 23:53:03 UTC (rev 1427) +++ phenote/trunk/src/java/phenote/gui/CharacterTableController.java 2008-01-30 18:48:13 UTC (rev 1428) @@ -164,6 +164,12 @@ * to call this method */ public void commitCharacters() { + + // ConstraintStatus cs = ConstraintManager.inst().checkCommitConstraints(); + // if (cs.hasFailed()) { + // JOptionPane.message(cs.getErrorMessage()) + // return; } + if (Config.inst().hasQueryableDataAdapter()) { Config.inst().getQueryableDataAdapter().commit( this.getCharacterListManager().getCharacterList()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |