FileDocCategorySizeDatePackage
PINEntryDialog.javaAPI DocphoneME MR2 API (J2ME)8336Wed May 02 18:00:38 BST 2007com.sun.satsa.acl

PINEntryDialog

public class PINEntryDialog extends Object implements CommandListener
Implements PIN entry dialog.

Fields Summary
private static final int
CANCELLED
Answer that indicates that the dialog was cancelled.
private static final int
CONFIRMED
Answer that indicates successful completion.
private com.sun.midp.lcdui.DisplayEventHandler
displayEventHandler
Caches the display manager reference.
private Command
okCmd
Command object for "OK" command.
private Command
cancelCmd
Command object for "Cancel" command.
private Object
preemptToken
Holds the preempt token so the form can end.
private int
answer
Holds the answer to the security question.
private TextField
tf1
PIN entry text field.
private TextField
tf2
PIN entry text field.
private PINAttributes
pin1
Attributes of the 1st PIN.
private PINAttributes
pin2
Attributes of the 2nd PIN.
private byte[]
data1
1st PIN data.
private byte[]
data2
2nd PIN data.
Constructors Summary
public PINEntryDialog(com.sun.midp.security.SecurityToken token, int action, PINAttributes attr1, PINAttributes attr2)
Construct PIN dialog.

param
token security token with the permission to peempt the foreground display
param
action PIN entry operation identifier.
param
attr1 1st PIN attributes.
param
attr2 2nd PIN attributes.
exception
InterruptedException if another thread interrupts the calling thread while this method is waiting to preempt the display.


                                                                     
        
                             
              

        String title = null;

        String label1 = attr1.label;
        String label2 = null;
        pin1 = attr1;
        pin2 = null;

        switch (action) {
            case ACLPermissions.CMD_VERIFY: {
                // "PIN verification"
                title = Resource.getString(ResourceConstants.
                    JSR177_PINDIALOG_TITLE_VERIFY);
                break;
            }
            case ACLPermissions.CMD_CHANGE: {
                // "Change PIN"
                title = Resource.getString(ResourceConstants.
                    JSR177_PINDIALOG_TITLE_CHANGE);
                // "New value" -> "Enter new PIN"
                label2 = Resource.getString(ResourceConstants.
                    JSR177_PINDIALOG_ENTERPIN);
                pin2 = attr1;
                break;
            }
            case ACLPermissions.CMD_DISABLE: {
                // "Disable PIN"
                title = Resource.getString(ResourceConstants.
                    JSR177_PINDIALOG_TITLE_DISABLE);
                break;
            }
            case ACLPermissions.CMD_ENABLE: {
                // "Enable PIN";
                title = Resource.getString(ResourceConstants.
                    JSR177_PINDIALOG_TITLE_ENABLE);
                break;
            }
            case ACLPermissions.CMD_UNBLOCK: {
                // "Unblock PIN"
                title = Resource.getString(ResourceConstants.
                    JSR177_PINDIALOG_TITLE_UNBLOCK);
                label1 = attr2.label;
                label2 = attr1.label + " - " + 
                    // "new value"
                    Resource.getString(ResourceConstants.
                        JSR177_PINDIALOG_NEWVALUE);
                pin1 = attr2;
                pin2 = attr1;
                break;
            }
        }

        Form form = new Form(title);

        int flags = TextField.PASSWORD;
        if (pin1.isNumeric()) {
            flags |= TextField.NUMERIC;
        }
        tf1  = new TextField(label1, "", pin1.getMaxLength(), flags);
        form.append(tf1);

        if (pin2 != null) {

            flags = TextField.SENSITIVE | TextField.NON_PREDICTIVE;
            if (pin2.isNumeric()) {
                flags |= TextField.NUMERIC;
            }
            tf2  = new TextField(label2, "", pin2.getMaxLength(), flags);
            form.append(tf2);

        }

        form.addCommand(cancelCmd);
        form.addCommand(okCmd);
        form.setCommandListener(this);
	if (displayEventHandler  == null) {
	    displayEventHandler = DisplayEventHandlerFactory
		.getDisplayEventHandler(token);
	}
        preemptToken = displayEventHandler.preemptDisplay(form, true);
    
Methods Summary
private booleancheckInput()
Verifies that the values entered are acceptable.

return
true if the values entered are acceptable.


        if (tf1.getString().trim().equals("")) {
            return false;
        }

        data1 = pin1.transform(tf1.getString());
        if (data1 == null) {
            // PIN can't be formatted, pass empty PIN to update counter
            data1 = new byte[8];
        }

        if (pin2 != null) {
            data2 = pin2.transform(tf2.getString());
            if (data2 == null) {
                tf2.setString("");
                return false;
            }
        } else {
            data2 = null;
        }
        return true;
    
public voidcommandAction(Command c, Displayable s)
Respond to a command issued on form.

param
c command activiated by the user
param
s the Displayable the command was on.

        if (c == okCmd) {
            if (! checkInput()) {
                return;
            }
            setAnswer(CONFIRMED);
        } else {
            setAnswer(CANCELLED);
        }

    
public java.lang.Object[]getPINs()
Get the entered values.

return
null if PIN entry was cancelled by user, otherwise an array containing PIN value(s).


        if (answer == CANCELLED) {
            return null;
        }

        if (pin2 == null) {
            return new Object[] {data1};
        }

        return new Object[] {data1, data2};
    
private voidsetAnswer(int theAnswer)
Sets the user's answer and notifies waitForAnswer and ends the form.

param
theAnswer user's answer or CANCEL if system cancelled the screen

        synchronized (this) {
            answer = theAnswer;
            displayEventHandler.donePreempting(preemptToken);
            notify();
        }

    
public intwaitForAnswer()
Waits for the user's answer.

return
user's answer

        synchronized (this) {
            if (preemptToken == null) {
                return CANCELLED;
            }

            try {
                wait();
            } catch (Throwable t) {
                return CANCELLED;
            }

            return answer;
        }