commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dflo...@apache.org
Subject cvs commit: jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/util MainWrapper.java InteractiveMainWrapper.java
Date Sat, 18 Dec 2004 13:52:16 GMT
dflorey     2004/12/18 05:52:16

  Modified:    contract/src/examples/org/apache/commons/contract/example
                        SpeedCalculator.java
               contract/src/config constraints.xml example.xml
               contract/src/java/org/apache/commons/contract/constraints
                        BooleanConstraints.java Unconstrained.java
                        MapConstraints.java DateConstraints.java
                        ArrayConstraints.java ListConstraints.java
                        LocaleConstraints.java
               contract/src/java/org/apache/commons/contract/util
                        MainWrapper.java InteractiveMainWrapper.java
  Added:       contract/src/examples/org/apache/commons/contract/example
                        TestLogin.java LoginProcessor.java
                        TestSpeedCalculator.java
  Removed:     contract/src/examples/org/apache/commons/contract/example
                        SimpleMain.java
  Log:
  Improved constraint classes
  
  Revision  Changes    Path
  1.2       +21 -17    jakarta-commons-sandbox/contract/src/examples/org/apache/commons/contract/example/SpeedCalculator.java
  
  Index: SpeedCalculator.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/examples/org/apache/commons/contract/example/SpeedCalculator.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SpeedCalculator.java	8 Oct 2004 10:44:57 -0000	1.1
  +++ SpeedCalculator.java	18 Dec 2004 13:52:16 -0000	1.2
  @@ -43,35 +43,39 @@
       private final static String MINUTES = "min";
       private final static String HOURS = "h";
   
  -    ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[]{
  -            new ParameterDescriptor(DISTANCE, new ParameterMessage("computeSpeed/parameter/distance"),

  -                    new NumberConstraints(
  +    private ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[]{
  +            new ParameterDescriptor(DISTANCE, new ParameterMessage(
  +                    "computeSpeed/parameter/distance"), new NumberConstraints(
                       new Integer(0), null, true)),
  -            new ParameterDescriptor(UNIT, new ParameterMessage("computeSpeed/parameter/unit"),

  -                    new StringConstraints(
  +            new ParameterDescriptor(UNIT, new ParameterMessage(
  +                    "computeSpeed/parameter/unit"), new StringConstraints(
                       new String[]{SECONDS, MINUTES, HOURS})),
  -            new ParameterDescriptor(TIME, new ParameterMessage("computeSpeed/parameter/time"),

  -                    NumberConstraints.POSITIVE)};
  -    
  -    ResultDescriptor[] resultDescriptors = new ResultDescriptor[]{new ResultDescriptor(
  +            new ParameterDescriptor(TIME, new ParameterMessage(
  +                    "computeSpeed/parameter/time"), NumberConstraints.POSITIVE)};
  +
  +    private ResultDescriptor[] resultDescriptors = new ResultDescriptor[]{new ResultDescriptor(
               StateDescriptor.OK_DESCRIPTOR,
               new ResultEntryDescriptor[]{new ResultEntryDescriptor(SPEED,
                       new LocalizedMessage("computeSpeed/result/speed"),
  -                    new NumberConstraints(new Float(0.1), new Integer(Integer.MAX_VALUE)))})};
  -    
  +                    new NumberConstraints(new Float(0.1), new Integer(
  +                            Integer.MAX_VALUE)))})};
  +
       /**
        * Computes the speed in meter per second from the given distance and time.
        * The time can be given in seconds, minutes or hours, depending on the
        * content of timeUnit.
        */
       public Result process(Map parameters, Context context) {
  -        float distance = ((Number)parameters.get(DISTANCE)).floatValue();
  -        float time = ((Number)parameters.get(TIME)).floatValue();
  -        String timeUnit = (String)parameters.get(UNIT);
  +        float distance = ((Number) parameters.get(DISTANCE)).floatValue();
  +        float time = ((Number) parameters.get(TIME)).floatValue();
  +        String timeUnit = (String) parameters.get(UNIT);
           float speed;
  -        if (timeUnit.equals("s")) speed = distance / time;
  -        else if (timeUnit.equals("min")) speed = distance*60 / time;
  -        else speed = distance*3600 / time;
  +        if (timeUnit.equals("s"))
  +            speed = distance / time;
  +        else if (timeUnit.equals("min"))
  +            speed = distance * 60 / time;
  +        else
  +            speed = distance * 3600 / time;
           return new Result(StateDescriptor.OK, SPEED, new Float(speed));
       }
   
  
  
  
  1.1                  jakarta-commons-sandbox/contract/src/examples/org/apache/commons/contract/example/TestLogin.java
  
  Index: TestLogin.java
  ===================================================================
  /*
  *
  * ====================================================================
  *
  * Copyright 2004 The Apache Software Foundation 
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  */
  package org.apache.commons.contract.example;
  
  import org.apache.commons.contract.Result;
  import org.apache.commons.contract.util.InteractiveMainWrapper;
  import org.apache.commons.i18n.MessageManager;
  
  public class TestLogin {
      public static void main(String[] args) {
          MessageManager.install("contract/example", Thread.currentThread().getContextClassLoader().getResourceAsStream("example.xml"));
          Result result = InteractiveMainWrapper.main(args, new LoginProcessor());
          if ( result != Result.OK ) {
              System.out.println("Login ist fehlgeschlagen.");
          } else {
              System.out.println("Login erfolgreich");
          }
      }
  }
  
  
  1.1                  jakarta-commons-sandbox/contract/src/examples/org/apache/commons/contract/example/LoginProcessor.java
  
  Index: LoginProcessor.java
  ===================================================================
  /*
   *
   * ====================================================================
   *
   * Copyright 2004 The Apache Software Foundation 
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   *
   */
  package org.apache.commons.contract.example;
  
  import java.util.Map;
  
  import org.apache.commons.contract.Context;
  import org.apache.commons.contract.Information;
  import org.apache.commons.contract.Processor;
  import org.apache.commons.contract.Result;
  import org.apache.commons.contract.constraints.StringConstraints;
  import org.apache.commons.contract.descriptor.ParameterDescriptor;
  import org.apache.commons.contract.descriptor.ResultDescriptor;
  import org.apache.commons.contract.descriptor.StateDescriptor;
  import org.apache.commons.contract.i18n.ParameterMessage;
  import org.apache.commons.i18n.LocalizedError;
  import org.apache.commons.i18n.LocalizedMessage;
  
  /**
   * @author Daniel Florey
   *  
   */
  public class LoginProcessor implements Processor {
      public final static String LOGIN_FAILED = "loginFailed";
      public final static StateDescriptor LOGIN_FAILED_DESCRIPTOR = new StateDescriptor(
              LOGIN_FAILED, new LocalizedMessage(
                      "loginProcessor/state/loginFailed"));
  
      private final static String USERNAME = "login";
      private final static String PASSWORD = "password";
      private final int PWD_MIN_LENGTH = 4, PWD_MAX_LENGTH = 14;
  
      private ParameterDescriptor[] parameterDescriptors = new ParameterDescriptor[]{
              new ParameterDescriptor(USERNAME, new ParameterMessage(
                      "loginProcessor/parameter/username"),
                      StringConstraints.NOT_EMPTY),
              new ParameterDescriptor(PASSWORD, new ParameterMessage(
                      "loginProcessor/parameter/password"), new StringConstraints(
                      PWD_MIN_LENGTH, PWD_MAX_LENGTH))};
  
      private ResultDescriptor[] resultDescriptors = new ResultDescriptor[]{
              new ResultDescriptor(StateDescriptor.OK_DESCRIPTOR),
              new ResultDescriptor(LOGIN_FAILED_DESCRIPTOR)};
  
      public Result process(Map parameter, Context context) throws Exception {
          String username = (String) parameter.get(USERNAME);
          String password = (String) parameter.get(PASSWORD);
          if (username.equals("Daniel") && !password.equals("Florey")) {
              context.addInformation(new Information(Information.ERROR,
                      new LocalizedError("loginProcessor/information/wrongPassword"),
                      new String[]{ USERNAME, PASSWORD }));
              return new Result(LOGIN_FAILED);
          }
          return Result.OK;
      }
  
      public ParameterDescriptor[] getParameterDescriptors() {
          return parameterDescriptors;
      }
  
      public ResultDescriptor[] getResultDescriptors() {
          return resultDescriptors;
      }
  }
  
  
  1.1                  jakarta-commons-sandbox/contract/src/examples/org/apache/commons/contract/example/TestSpeedCalculator.java
  
  Index: TestSpeedCalculator.java
  ===================================================================
  /*
  *
  * ====================================================================
  *
  * Copyright 2004 The Apache Software Foundation 
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *     http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  *
  */
  package org.apache.commons.contract.example;
  
  import org.apache.commons.contract.Result;
  import org.apache.commons.contract.util.InteractiveMainWrapper;
  import org.apache.commons.i18n.MessageManager;
  
  public class TestSpeedCalculator {
      public static void main(String[] args) {
          MessageManager.install("contract/example", Thread.currentThread().getContextClassLoader().getResourceAsStream("example.xml"));
          Result result = InteractiveMainWrapper.main(args, new SpeedCalculator());
          if ( result != null ) {
              System.out.println("Speed: "+result.getResultEntries().get(SpeedCalculator.SPEED));
          }
      }
  }
  
  
  
  1.2       +82 -3     jakarta-commons-sandbox/contract/src/config/constraints.xml
  
  Index: constraints.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/config/constraints.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- constraints.xml	8 Oct 2004 09:36:20 -0000	1.1
  +++ constraints.xml	18 Dec 2004 13:52:16 -0000	1.2
  @@ -1,6 +1,8 @@
   <?xml version="1.0" encoding="UTF-8" ?>
   <messages>
  -	<message id="booleanOnly">
  +	<!-- Verbosed constraints -->
  +	<!-- Date constraints -->
  +	<message id="unconstrainedBoolean">
   		<locale language="en"> 
   			<entry key="text">Boolean values ('true' or 'false') are valid.</entry>
   		</locale> 
  @@ -8,7 +10,8 @@
   			<entry key="text">Wahrheitswerte (Boolean), also 'true' oder 'false' sind erlaubt.</entry>
   		</locale> 
   	</message>
  -	<message id="datesOnly">
  +	<!-- Date constraints -->
  +	<message id="unconstrainedDate">
   		<locale language="en"> 
   			<entry key="text">Date values are valid.</entry>
   		</locale> 
  @@ -16,7 +19,7 @@
   			<entry key="text">Datumswerte sind erlaubt.</entry>
   		</locale> 
   	</message>
  -	<message id="datesBetweenOnly">
  +	<message id="constrainedDateRange">
   		<locale language="en"> 
   			<entry key="text">Date values between {0} and {1} are valid.</entry>
   		</locale> 
  @@ -24,6 +27,74 @@
   			<entry key="text">Datumswerte zwischen {0} sind {1} erlaubt.</entry>
   		</locale> 
   	</message>
  +	<!-- Array constraints -->
  +	<message id="unconstrainedArray">
  +		<locale language="en"> 
  +			<entry key="text">Array values are valid.</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="text">Arraywerte sind erlaubt.</entry>
  +		</locale> 
  +	</message>
  +	<message id="constrainedArray">
  +		<locale language="en"> 
  +			<entry key="text">All array values must match the following constraints: {0}</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="text">Alle Werte des Arrays müssen folgende Bedingung erfüllen:
{0}</entry>
  +		</locale> 
  +	</message>
  +	<!-- List constraints -->
  +	<message id="unconstrainedList">
  +		<locale language="en"> 
  +			<entry key="text">List values are valid.</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="text">Listen sind erlaubt.</entry>
  +		</locale> 
  +	</message>
  +	<message id="constrainedList">
  +		<locale language="en"> 
  +			<entry key="text">All list values must match the following constraints: {0}</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="text">Alle Einträge der Liste müssen folgende Bedingung erfüllen:
{0}</entry>
  +		</locale> 
  +	</message>
  +	<!-- Locale constraints -->
  +	<message id="unconstrainedLocale">
  +		<locale language="en"> 
  +			<entry key="text">Locale values are valid.</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="text">Alle Objekte vom Typ Locale sind erlaubt.</entry>
  +		</locale> 
  +	</message>
  +	<!-- Unconstrained constraints, similar to a typed java method parameter -->
  +	<message id="unconstrained">
  +		<locale language="en"> 
  +			<entry key="text">All values are valid.</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="text">Alle Werte sind erlaubt.</entry>
  +		</locale> 
  +	</message>
  +	<message id="constrainedUnconstrained">
  +		<locale language="en"> 
  +			<entry key="text">All values of type {0} are valid.</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="text">Alle Werte vom Typ {0} sind erlaubt.</entry>
  +		</locale> 
  +	</message>
  +	<message id="invalidObjectType">
  +		<locale language="en"> 
  +			<entry key="text">The given value {1} can not be casted to the requred type {0}.</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="text">Der gegebene Wert {1} ist nicht vom geforderten Typ {0}.</entry>
  +		</locale> 
  +	</message>
   	<!-- Number constraints -->
   	<message id="uncastableNumber">
   		<locale language="en">
  @@ -118,6 +189,14 @@
   		</locale> 
   		<locale language="de"> 
   			<entry key="text">Die folgenden Zeichenketten sind erlaubt: {0}</entry>
  +		</locale> 
  +	</message>
  +	<message id="stringLengthGreater">
  +		<locale language="en"> 
  +			<entry key="text">The strings must contain at least {0} characters</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="text">Die Zeichenkette muss mindestens {0} Buchstaben enthalten</entry>
   		</locale> 
   	</message>
   </messages>
  
  
  
  1.2       +39 -2     jakarta-commons-sandbox/contract/src/config/example.xml
  
  Index: example.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/config/example.xml,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- example.xml	8 Oct 2004 09:36:20 -0000	1.1
  +++ example.xml	18 Dec 2004 13:52:16 -0000	1.2
  @@ -1,5 +1,6 @@
   <?xml version="1.0" encoding="UTF-8" ?>
   <messages>
  +	<!-- Messages for speed calculator example -->
   	<message id="computeSpeed/parameter/distance">
   		<locale language="en"> 
   			<entry key="title">Distance</entry>
  @@ -12,7 +13,7 @@
   			<entry key="prompt">Bitte geben Sie die Entfernung an:</entry>
   		</locale> 
   	</message>
  -		<message id="computeSpeed/parameter/unit">
  +	<message id="computeSpeed/parameter/unit">
   		<locale language="en"> 
   			<entry key="title">Unit</entry>
   			<entry key="text">The measuring unit for the time</entry>
  @@ -24,7 +25,7 @@
   			<entry key="prompt">Bitte geben Sie die Maßeinheit ein:</entry>
   		</locale> 
   	</message>
  -		<message id="computeSpeed/parameter/time">
  +	<message id="computeSpeed/parameter/time">
   		<locale language="en"> 
   			<entry key="title">Time</entry>
   			<entry key="text">The time in the chosen unit</entry>
  @@ -34,6 +35,42 @@
   			<entry key="title">Zeit</entry>
   			<entry key="text">Die Zeit in der festgelegten Maßeinheit</entry>
   			<entry key="prompt">Bitte geben Sie die Zeit ein:</entry>
  +		</locale> 
  +	</message>
  +
  +	<!-- Messages for login processor example -->
  +	<message id="loginProcessor/parameter/username">
  +		<locale language="en"> 
  +			<entry key="title">Username</entry>
  +			<entry key="text">Name of the user to log in</entry>
  +			<entry key="prompt">Enter the username:</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="title">Benutzer</entry>
  +			<entry key="text">Der Name des anzumeldenden Benutzers</entry>
  +			<entry key="prompt">Bitte geben Sie den Benutzernamen an:</entry>
  +		</locale> 
  +	</message>
  +	<message id="loginProcessor/parameter/password">
  +		<locale language="en"> 
  +			<entry key="title">Password</entry>
  +			<entry key="text">The password of the given user</entry>
  +			<entry key="prompt">Enter the password:</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="title">Passwort</entry>
  +			<entry key="text">Das Passwort des gewählten Benutzers</entry>
  +			<entry key="prompt">Bitte geben Sie das Password ein:</entry>
  +		</locale> 
  +	</message>
  +	<message id="loginProcessor/information/wrongPassword">
  +		<locale language="en"> 
  +			<entry key="title">Wrong password!</entry>
  +			<entry key="text">The given password is wrong</entry>
  +		</locale> 
  +		<locale language="de"> 
  +			<entry key="title">Passwort falsch!</entry>
  +			<entry key="text">Das Passwort ist ungültig</entry>
   		</locale> 
   	</message>
   </messages>
  
  
  
  1.2       +1 -1      jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/BooleanConstraints.java
  
  Index: BooleanConstraints.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/BooleanConstraints.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- BooleanConstraints.java	8 Oct 2004 09:36:19 -0000	1.1
  +++ BooleanConstraints.java	18 Dec 2004 13:52:16 -0000	1.2
  @@ -23,6 +23,6 @@
       }
       
       public LocalizedText verboseConstraints() {
  -        return new LocalizedText("booleansOnly");
  +        return new LocalizedText("unconstrainedBoolean");
       }
   }
  
  
  
  1.2       +19 -1     jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/Unconstrained.java
  
  Index: Unconstrained.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/Unconstrained.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Unconstrained.java	8 Oct 2004 09:36:19 -0000	1.1
  +++ Unconstrained.java	18 Dec 2004 13:52:16 -0000	1.2
  @@ -1,19 +1,37 @@
   package org.apache.commons.contract.constraints;
   
   import org.apache.commons.contract.Context;
  +import org.apache.commons.i18n.LocalizedError;
   import org.apache.commons.i18n.LocalizedText;
   
   public class Unconstrained implements Constraints {
       public final static Unconstrained UNCONSTRAINED = new Unconstrained();
   
  +    private Class clazz;
  +    
  +    public Unconstrained() {
  +        this.clazz = null;
  +    }
  +    
  +    public Unconstrained(Class clazz) {
  +        this.clazz = clazz;
  +    }
  +    
       public Object cast(Object value, Context context) throws CastException {
           return value;
       }
       
       public void validate(Object value, Context context) throws ValidationException {
  +        if ( clazz != null && !clazz.isInstance(value) ) {
  +            throw new ValidationException(new LocalizedError("invalidObjectType", new Object[]
{ clazz, value }));
  +        }
       }
       
       public LocalizedText verboseConstraints() {
  -        return new LocalizedText("booleansOnly");
  +        if ( clazz == null ) {
  +            return new LocalizedText("unconstrained");
  +        } else {
  +            return new LocalizedText("constrainedUnconstrained");
  +        }
       }
   }
  
  
  
  1.2       +4 -1      jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/MapConstraints.java
  
  Index: MapConstraints.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/MapConstraints.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- MapConstraints.java	8 Oct 2004 09:36:19 -0000	1.1
  +++ MapConstraints.java	18 Dec 2004 13:52:16 -0000	1.2
  @@ -115,7 +115,10 @@
      }
       
       public LocalizedText verboseConstraints() {
  -        return new LocalizedText("booleansOnly");
  +        if ( entryConstraints.isEmpty() ) {
  +            return new LocalizedText("invalidMapConstraints");
  +        }
  +        return new LocalizedText("unconstrainedMap");
       }
   
   }
  
  
  
  1.2       +2 -2      jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/DateConstraints.java
  
  Index: DateConstraints.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/DateConstraints.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- DateConstraints.java	8 Oct 2004 09:36:19 -0000	1.1
  +++ DateConstraints.java	18 Dec 2004 13:52:16 -0000	1.2
  @@ -71,8 +71,8 @@
       
       public LocalizedText verboseConstraints() {
           if ( constrained ) {
  -            return new LocalizedText("datesBetweenOnly", new Object[] { earliest, latest
});
  +            return new LocalizedText("constrainedDateRange", new Object[] { earliest, latest
});
           } 
  -        return new LocalizedText("datesOnly");
  +        return new LocalizedText("unconstrainedDate");
       }
   }
  
  
  
  1.2       +6 -2      jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/ArrayConstraints.java
  
  Index: ArrayConstraints.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/ArrayConstraints.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ArrayConstraints.java	8 Oct 2004 09:36:19 -0000	1.1
  +++ ArrayConstraints.java	18 Dec 2004 13:52:16 -0000	1.2
  @@ -69,7 +69,11 @@
       }
       
       public LocalizedText verboseConstraints() {
  -        return new LocalizedText("booleansOnly");
  +        if ( entryValueDescriptor == Unconstrained.UNCONSTRAINED ) {
  +            return new LocalizedText("unconstrainedArray");
  +        } else {
  +            LocalizedText verbosedEntryContrstaints = entryValueDescriptor.verboseConstraints();
  +            return new LocalizedText("constrainedArray", new String[] {  verbosedEntryContrstaints.getText()
});
  +        }
       }
  -
   }
  
  
  
  1.2       +6 -1      jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/ListConstraints.java
  
  Index: ListConstraints.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/ListConstraints.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ListConstraints.java	8 Oct 2004 09:36:19 -0000	1.1
  +++ ListConstraints.java	18 Dec 2004 13:52:16 -0000	1.2
  @@ -64,6 +64,11 @@
       }
       
       public LocalizedText verboseConstraints() {
  -        return new LocalizedText("booleansOnly");
  +        if ( entryValueDescriptor == Unconstrained.UNCONSTRAINED ) {
  +            return new LocalizedText("unconstrainedList");
  +        } else {
  +            LocalizedText verbosedEntryContrstaints = entryValueDescriptor.verboseConstraints();
  +            return new LocalizedText("constrainedList", new String[] { verbosedEntryContrstaints.getText()
});
  +        }
       }
   }
  
  
  
  1.2       +1 -1      jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/LocaleConstraints.java
  
  Index: LocaleConstraints.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/constraints/LocaleConstraints.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- LocaleConstraints.java	8 Oct 2004 09:36:19 -0000	1.1
  +++ LocaleConstraints.java	18 Dec 2004 13:52:16 -0000	1.2
  @@ -24,6 +24,6 @@
   	}
       
       public LocalizedText verboseConstraints() {
  -        return new LocalizedText("booleansOnly");
  +        return new LocalizedText("unconstrainedLocale");
       }
   }
  
  
  
  1.4       +10 -0     jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/util/MainWrapper.java
  
  Index: MainWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/util/MainWrapper.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- MainWrapper.java	7 Dec 2004 20:52:18 -0000	1.3
  +++ MainWrapper.java	18 Dec 2004 13:52:16 -0000	1.4
  @@ -20,11 +20,14 @@
   package org.apache.commons.contract.util;
   
   import java.util.HashMap;
  +import java.util.Iterator;
  +import java.util.List;
   import java.util.Map;
   
   import org.apache.commons.contract.Context;
   import org.apache.commons.contract.ContractViolationException;
   import org.apache.commons.contract.Executor;
  +import org.apache.commons.contract.Information;
   import org.apache.commons.contract.Processor;
   import org.apache.commons.contract.Result;
   import org.apache.commons.contract.context.VMContext;
  @@ -101,5 +104,12 @@
               }
           }
           System.out.println();
  +    }
  +
  +    public static void printInformations(List informations) {
  +        for ( Iterator i = informations.iterator(); i.hasNext(); ) {
  +            Information information = (Information)i.next();
  +            System.out.println("Folgendes: "+information.getLocalizedError().getText());
  +        }
       }
   }
  
  
  
  1.3       +4 -1      jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/util/InteractiveMainWrapper.java
  
  Index: InteractiveMainWrapper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/contract/src/java/org/apache/commons/contract/util/InteractiveMainWrapper.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- InteractiveMainWrapper.java	7 Dec 2004 20:52:17 -0000	1.2
  +++ InteractiveMainWrapper.java	18 Dec 2004 13:52:16 -0000	1.3
  @@ -37,6 +37,7 @@
   public class InteractiveMainWrapper extends MainWrapper {
       public static Result main(String []args, Processor processor) {
           Executor.init();
  +        printUsage(processor);
           Context context = new VMContext();
           ParameterDescriptor[] parameterDescriptors = processor.getParameterDescriptors();
           Map parameters = new HashMap();
  @@ -60,7 +61,9 @@
               parameters.put(parameterDescriptors[i].getName(), value);
           }
           try {
  -            return Executor.process(processor, parameters, context);
  +            Result result = Executor.process(processor, parameters, context);
  +            printInformations(context.getInformations());
  +            return result;
           } catch ( ContractViolationException exception ) {
               printException(exception);
               System.out.println();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message