[izpack-changes] r2008 - izpack-src/trunk/src/lib/com/izforge/izpack/panels

noreply at berlios.de noreply at berlios.de
Thu Jan 24 20:29:52 CET 2008


Author: jgordon
Date: 2008-01-24 20:29:48 +0100 (Thu, 24 Jan 2008)
New Revision: 2008

Modified:
   izpack-src/trunk/src/lib/com/izforge/izpack/panels/PasswordGroup.java
Log:
Added usage of ValidatorContainer to support multiple validators.

Modified: izpack-src/trunk/src/lib/com/izforge/izpack/panels/PasswordGroup.java
===================================================================
--- izpack-src/trunk/src/lib/com/izforge/izpack/panels/PasswordGroup.java	2008-01-24 19:27:57 UTC (rev 2007)
+++ izpack-src/trunk/src/lib/com/izforge/izpack/panels/PasswordGroup.java	2008-01-24 19:29:48 UTC (rev 2008)
@@ -18,9 +18,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-
 package com.izforge.izpack.panels;
 
+import com.izforge.izpack.installer.InstallData;
+import java.util.List;
 import java.util.Map;
 import java.util.Vector;
 
@@ -46,13 +47,19 @@
     // ------------------------------------------------------------------------
     private Vector fields = new Vector();
 
-    private Validator validator = null;
-
+    private List validatorContainers = null;
+//  private Validator validator = null;
+//  private boolean hasParams = false;
+//  private Map validatorParams = null;
     private Processor processor = null;
 
+    private int currentValidator = 0;
+
+    private InstallData idata;
+
     /*--------------------------------------------------------------------------*/
     /**
-     * Creates a passowrd group to manage one or more password fields.
+     * Creates a password group to manage one or more password fields.
      * 
      * @param validator A string that specifies a class that provides a password validation service.
      * The class must implement the <code>Validator</code> interface. If an attempt to instantiate
@@ -63,18 +70,25 @@
      * contents of the first field will be returned.
      */
     /*--------------------------------------------------------------------------*/
-    public PasswordGroup(String validator, String processor)
+    public PasswordGroup(InstallData idata, List validatorContainers, String processor)
     {
         // ----------------------------------------------------
         // attempt to create an instance of the Validator
         // ----------------------------------------------------
         try
         {
-            this.validator = (Validator) Class.forName(validator).newInstance();
-        }
-        catch (Throwable exception)
+            this.idata = idata;
+//      this.validator = (Validator) Class.forName(validator).newInstance();
+            this.validatorContainers = validatorContainers;
+//      this.validatorParams = validatorParams;
+//      if (validatorParams != null) {
+//        if (validatorParams.size() > 0) {
+//          hasParams = true;
+//        }
+//      }
+        } catch (Throwable exception)
         {
-            this.validator = null;
+            this.validatorContainers = null;
         }
 
         // ----------------------------------------------------
@@ -83,13 +97,17 @@
         try
         {
             this.processor = (Processor) Class.forName(processor).newInstance();
-        }
-        catch (Throwable exception)
+        } catch (Throwable exception)
         {
             this.processor = null;
         }
     }
 
+    public InstallData getIdata()
+    {
+        return idata;
+    }
+
     /*--------------------------------------------------------------------------*/
     /**
      * Returns the number of sub-fields.
@@ -115,7 +133,10 @@
     /*--------------------------------------------------------------------------*/
     public String getFieldContents(int index) throws IndexOutOfBoundsException
     {
-        if ((index < 0) || (index >= fields.size())) { throw (new IndexOutOfBoundsException()); }
+        if ((index < 0) || (index >= fields.size()))
+        {
+            throw (new IndexOutOfBoundsException());
+        }
 
         String contents = new String(((JPasswordField) fields.elementAt(index)).getPassword());
         return (contents);
@@ -145,18 +166,125 @@
      * rule exists. Otherwise <code>false</code> is returned.
      */
     /*--------------------------------------------------------------------------*/
-    public boolean validateContents()
+    public boolean validateContents(int i)
     {
-        if (validator != null)
+        boolean returnValue = true;
+        try
         {
-            return (validator.validate(this));
+            currentValidator = i;
+            ValidatorContainer container = getValidatorContainer(i);
+            Validator validator = container.getValidator();
+            if (validator != null)
+            {
+                returnValue = validator.validate(this);
+            }
+        } catch (Exception e)
+        {
+            System.out.println("validateContents(" + i + ") failed: " + e);
+        // just return true
         }
-        else
+        return returnValue;
+    }
+
+    public String getValidatorMessage(int i)
+    {
+        String returnValue = null;
+        try
         {
-            return (true);
+            ValidatorContainer container = getValidatorContainer(i);
+            if (container != null)
+            {
+                returnValue = container.getMessage();
+            }
+        } catch (Exception e)
+        {
+            System.out.println("getValidatorMessage(" + i + ") failed: " + e);
+        // just return true
         }
+        return returnValue;
     }
 
+    public int validatorSize()
+    {
+        int size = 0;
+        if (validatorContainers != null)
+        {
+            size = validatorContainers.size();
+        }
+        return size;
+    }
+
+    public ValidatorContainer getValidatorContainer()
+    {
+        return getValidatorContainer(currentValidator);
+    }
+
+    public ValidatorContainer getValidatorContainer(int i)
+    {
+        ValidatorContainer container = null;
+        try
+        {
+            container = (ValidatorContainer) validatorContainers.get(i);
+        } catch (Exception e)
+        {
+            container = null;
+        }
+        return container;
+    }
+
+    public boolean hasParams()
+    {
+        return hasParams(currentValidator);
+    }
+
+    public boolean hasParams(int i)
+    {
+        boolean returnValue = false;
+        try
+        {
+            ValidatorContainer container = getValidatorContainer(i);
+            if (container != null)
+            {
+                returnValue = container.hasParams();
+            }
+        } catch (Exception e)
+        {
+            System.out.println("hasParams(" + i + ") failed: " + e);
+        // just return true
+        }
+        return returnValue;
+    }
+
+    public Map getValidatorParams()
+    {
+        return getValidatorParams(currentValidator);
+    }
+
+    public Map getValidatorParams(int i)
+    {
+        Map returnValue = null;
+        try
+        {
+            ValidatorContainer container = getValidatorContainer(i);
+            if (container != null)
+            {
+                returnValue = container.getValidatorParams();
+            }
+        } catch (Exception e)
+        {
+            System.out.println("getValidatorParams(" + i + ") failed: " + e);
+        // just return true
+        }
+        return returnValue;
+    }
+
+    // This method was added to support changes to ProcessingClient interface
+    // it's use is non-deterministic in the newly implemented text validators.
+    public String getText()
+    {
+        return getValidatorMessage(currentValidator);
+    }
+
     /*--------------------------------------------------------------------------*/
     /**
      * Returns the password. If a processing service class was supplied it will be used to process
@@ -171,36 +299,18 @@
         if (processor != null)
         {
             return (processor.process(this));
-        }
-        else
+        } else
         {
             String contents = "";
 
             if (fields.size() > 0)
             {
-                contents = getText();
+                contents = new String(((JPasswordField) fields.elementAt(0)).getPassword());
             }
 
             return (contents);
         }
     }
 
-    // javadoc inherited
-    public String getText()
-    {
-        return new String(((JPasswordField) fields.elementAt(0)).getPassword());
-    }
-
-    // javadoc inherited
-    public Map getValidatorParams()
-    {
-        return null;
-    }
-
-    // javadoc inherited
-    public boolean hasParams()
-    {
-        return false;
-    }
 }
 /*---------------------------------------------------------------------------*/



More information about the izpack-changes mailing list