FileDocCategorySizeDatePackage
TransactionModuleImpl.javaAPI DocphoneME MR2 API (J2ME)11170Wed May 02 18:00:44 BST 2007com.sun.j2me.payment

TransactionModuleImpl

public abstract class TransactionModuleImpl extends Object
This class holds a "real" implementation of the transaction module. All calls to a transaction module instance are delegated to the instance of this class which has been associated with the delegating instance.
version

Fields Summary
protected javax.microedition.midlet.MIDlet
midlet
The caller MIDlet.
protected javax.microedition.payment.TransactionListener
listener
The listener set by the application or null if hasn't been set.
public static final int
PAYLOAD_LIMIT
The size limit of a payload from the specification.
Constructors Summary
protected TransactionModuleImpl(Object object)
Creates a new instance of TransactionModuleImpl. It requires a reference to the object, which originated the call. This object should be a MIDlet.

param
object the caller MIDlet
throws
TransactionModuleException indicates an error preventing the MIDlet from using the payment API
see
javax.microedition.payment.TransactionModule#TransactionModule

    
                                                             
       
              
        if (object == null) {
            throw new NullPointerException();
        }
        if (!(object instanceof MIDlet)) {
            throw new TransactionModuleException("The object is not referring to the application");
        }
         midlet = (MIDlet)object;

    
Methods Summary
protected abstract voidcheckForPermission(int permission, java.lang.String name)
Ensures that the MIDlet will have required privileges to do a protected operation.

param
permission the required permission
param
name an additional info string
throws
SecurityException if the permission is not granted
throws
InterruptedException if the thread waiting for the permission is interrupted

public voiddeliverMissedTransactions()
Makes the payment module to notify the listener about the MIDlet transactions which the listener couldn't have been notified about before (the MIDlet crashed or ended before the notification could take place).

throws
TransactionListenerException if the transaction listener hasn't been set prior the call
see
javax.microedition.payment.TransactionModule#deliverMissedTransactions

        if (listener == null) {
            throw new TransactionListenerException();
        }

        TransactionRecord[] allMissed = getMissedTransactions();

        if (allMissed != null) {
            PaymentModule.getInstance().addTransactionsForNotification(
                    allMissed, this);
        }
    
protected abstract intgetApplicationID()
Returns the MIDlet payment ID that can be used to store transaction records for the MIDlet initiated transactions into the transaction store.

return
the ID

final javax.microedition.payment.TransactionListenergetListener()
Returns the transaction listener.

return
the transaction listener

        return listener;
    
public final javax.microedition.midlet.MIDletgetMIDlet()
Returns the MIDlet.

return
the MIDlet

        return midlet;
    
protected javax.microedition.payment.TransactionRecord[]getMissedTransactions()
Returns an array of the missed transactions associated with the MIDlet suite.

return
an array of the missed transactions

        int applicationID = getApplicationID();
                
        TransactionStore transactionStore = 
                PaymentModule.getInstance().getTransactionStore();
        TransactionRecord[] allMissed = null;
        
        try {
            allMissed = transactionStore.getMissedTransactions(applicationID);
        } catch (IOException e) {
        }
        
        return allMissed;
    
protected javax.microedition.payment.TransactionRecord[]getPassedTransactions()
Returns an array of the passed transactions associated with the MIDlet suite.

return
an array of the passed transactions

        int applicationID = getApplicationID();
                
        TransactionStore transactionStore = 
                PaymentModule.getInstance().getTransactionStore();
        TransactionRecord[] allPassed = null;
        
        try {
            allPassed = transactionStore.getPassedTransactions(applicationID);
        } catch (IOException e) {
        }
        
        return allPassed;
    
public final javax.microedition.payment.TransactionRecord[]getPastTransactions(int max)
Returns an array of TransactionRecord objects that represent the past transactions, initiated by the MIDlet and about whose final state the MIDlet has been already notified.

param
max limits the number of returned transaction records
return
an array of the transaction records or null if max is set to 0 or there is no transaction to return
see
javax.microedition.payment.TransactionModule#getPastTransactions

        if (max == 0) {
            return null;
        }

        TransactionRecord[] allPassed = getPassedTransactions();
        
        if ((allPassed == null) || (allPassed.length <= max)) {
            return allPassed;
        }

        TransactionRecord[] truncated = new TransactionRecord[max];
        System.arraycopy(allPassed, 0, truncated, 0, max);

        return truncated;
    
protected abstract PaymentInfogetPaymentInfo()
Returns the payment provisioning information associated with the MIDlet.

return
the payment provisioning information

public final intprocess(int featureID, java.lang.String featureTitle, java.lang.String featureDescription, byte[] payload)
Initiates a new payment transaction from the given input values.

param
featureID the feature ID
param
featureTitle the feature title
param
featureDescription the feature description
param
payload the payload
return
the ID of the new transaction
throws
TransactionModuleException indicates incorrect input parameters or overloading of the payment module
throws
TransactionFeatureException if the featureID is incorrect
throws
TransactionListenerException if the transaction listener hasn't been set prior the call
throws
TransactionPayloadException if the payload exceed the limit allowed by the specification
see
javax.microedition.payment.TransactionModule#process
see
javax.microedition.payment.TransactionModuleException
see
javax.microedition.payment.TransactionFeatureException
see
javax.microedition.payment.TransactionListenerException
see
javax.microedition.payment.TransactionPayloadException

        
        // check for the javax.microedition.payment.process permission
        try {
            checkForPermission(Permissions.PAYMENT, null);
        } catch (InterruptedException e) {
            throw new SecurityException();
        }
        
        // null featureTitle or featureDescription
        if ((featureTitle == null) || (featureDescription == null)) {
            throw new TransactionModuleException("The " + 
                    ((featureTitle == null) ? 
                        "featureTitle" : "featureDescription") + " is null");
        }
        
        // empty featureTitle or featureDescription
        if ((featureTitle.length() == 0) || 
                (featureDescription.length() == 0)) {
            throw new TransactionModuleException("The " + 
                    ((featureTitle.length() == 0) ? 
                        "featureTitle" : "featureDescription") + " is empty");
        }

        // payload limit exceeded
        if ((payload != null) && (payload.length > PAYLOAD_LIMIT)) {
            throw new TransactionPayloadException();
        }

        // invalid feature ID
        if ((featureID < 0) || 
                (featureID >= getPaymentInfo().getNumFeatures())) {
            throw new TransactionFeatureException();
        }

        // listener hasn't been set
        if (listener == null) {
            throw new TransactionListenerException();
        }
        
        return PaymentModule.getInstance().addTransaction(this, featureID, 
                featureTitle, featureDescription, payload);
    
protected abstract voidsavePaymentInfo()
Stores the payment provisioning information associated with the MIDlet.

throws
IOException indicates an output error

public final synchronized voidsetListener(javax.microedition.payment.TransactionListener listener)
Sets the listener which should be notified about finishing of transactions or removes the listener which has been set before if listener is null.

param
listener the new listener or null
see
javax.microedition.payment.TransactionModule#setListener

        this.listener = listener;