1 21 22 package com.izforge.izpack.panels; 23 24 import java.util.Vector ; 25 26 import javax.swing.JPasswordField ; 27 28 29 39 40 public class PasswordGroup implements ProcessingClient 41 { 42 43 private Vector fields = new Vector (); 47 48 private Validator validator = null; 49 50 private Processor processor = null; 51 52 53 64 65 public PasswordGroup(String validator, String processor) 66 { 67 try 71 { 72 this.validator = (Validator) Class.forName(validator).newInstance(); 73 } 74 catch (Throwable exception) 75 { 76 this.validator = null; 77 } 78 79 try 83 { 84 this.processor = (Processor) Class.forName(processor).newInstance(); 85 } 86 catch (Throwable exception) 87 { 88 this.processor = null; 89 } 90 } 91 92 93 98 99 public int getNumFields() 100 { 101 return (fields.size()); 102 } 103 104 105 114 115 public String getFieldContents(int index) throws IndexOutOfBoundsException 116 { 117 if ((index < 0) || (index >= fields.size())) { throw (new IndexOutOfBoundsException ()); } 118 119 String contents = new String (((JPasswordField ) fields.elementAt(index)).getPassword()); 120 return (contents); 121 } 122 123 124 129 130 public void addField(JPasswordField field) 131 { 132 if (field != null) 133 { 134 fields.add(field); 135 } 136 } 137 138 139 146 147 public boolean validateContents() 148 { 149 if (validator != null) 150 { 151 return (validator.validate(this)); 152 } 153 else 154 { 155 return (true); 156 } 157 } 158 159 160 167 168 public String getPassword() 169 { 170 if (processor != null) 171 { 172 return (processor.process(this)); 173 } 174 else 175 { 176 String contents = ""; 177 178 if (fields.size() > 0) 179 { 180 contents = new String (((JPasswordField ) fields.elementAt(0)).getPassword()); 181 } 182 183 return (contents); 184 } 185 } 186 } 187 188 | Popular Tags |