Fields Summary |
---|
private static SecurityToken | classSecurityTokenThis class has a different security domain than the MIDlet suite. |
static Random | randomRandom generator for debug purpose |
private static final String | PAYMENT_ID_FILE_NAMEThe name of the file where to store the Midlet PaymentID |
private static final int | PAYMENT_ID_RECORDRecord ID for application payment ID store |
private TransactionStore | transactionStoreInstance of TransactionStore |
private Utils | utilitiesInstance of Utils class |
private Object | PreemptTokenan preempt token object to pass to donePreempting |
Methods Summary |
---|
public final void | cleanUp()The cleanUp method for the TCK tests. Should be removed when not
needed!!! Erases the transaction store.
getTransactionStore().cleanUp();
|
public TransactionModuleImpl | createTransactionModule(java.lang.Object object)It's a factory method for TransactionModuleImpl .
return new CldcTransactionModuleImpl(object);
|
public final java.lang.String[] | getMissedRecordsHeaders(int suiteId)Return missed(pending) transactions headers for given MIdlet suite.
CldcTransactionStoreImpl transactionStore =
(CldcTransactionStoreImpl) getTransactionStore();
CldcTransactionRecordImpl[] recs = null;
String[] headers = null;
try {
int appID = getPaymentID(suiteId);
recs = (CldcTransactionRecordImpl[])
transactionStore.getMissedTransactions(appID);
// there is no missed transaction
if (recs == null) {
return null;
}
headers = new String[recs.length];
StringBuffer buff = new StringBuffer();
for (int i = 0; i < headers.length; i++) {
buff.setLength(0);
buff.append(recs[i].getFeatureTitle());
buff.append(": ");
buff.append(recs[i].getPrice());
buff.append(recs[i].getCurrency());
headers[i] = buff.toString();
}
} catch (IOException e) {
// skip, return as it is
}
return headers;
|
public final int | getPaymentID(int suiteId)Return application payment ID for given midlet suite.
Create such ID if it is necessary.
RecordStoreImpl store = null;
int paymentID = -1;
try {
store = RecordStoreImpl.openRecordStore(
classSecurityToken, suiteId, PAYMENT_ID_FILE_NAME, false);
try {
byte[] data = new byte[4];
data = store.getRecord(1);
if (data.length == 4) {
paymentID = CldcTransactionStoreImpl.
getIntFromByteArray(data);
} else {
paymentID = -1;
}
} finally {
store.closeRecordStore();
}
} catch (RecordStoreNotFoundException ex) {
try {
int appPaymentId = PaymentModule.getInstance().
getNextApplicationID();
store = RecordStoreImpl.openRecordStore(
classSecurityToken, suiteId, PAYMENT_ID_FILE_NAME, true);
try {
byte[] data = CldcTransactionStoreImpl.
getByteArrayFromInt(appPaymentId);
store.addRecord(data, 0, data.length);
paymentID = appPaymentId;
} finally {
store.closeRecordStore();
}
} catch (RecordStoreException e) {
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_AMS,
"Storage Failure: Can not store Payment ID");
}
} catch (IOException e) {
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_AMS,
"getPaymentID threw an IOException: " +
e.getMessage());
}
}
} catch (RecordStoreException ex) {
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_AMS,
"Storage Failure: Can not read Payment ID");
}
}
return paymentID;
|
public final int | getSizeUsedInStore(int applicationID)Returns the size the given MIDlet suite uses in the transaction store.
This size doesn't include the size of the passed transactions (it
includes only the part of the store which is removed when the MIDletSuite
is uninstalled).
TransactionStore transactionStore = getTransactionStore();
int size = 0;
try {
size = transactionStore.getSizeUsedByApplication(applicationID);
} catch (IOException e) {
// ignore
}
return size;
|
public TransactionStore | getTransactionStore()Init and return instance of TransactionStore .
if (transactionStore == null) {
try {
transactionStore =
new CldcTransactionStoreImpl(classSecurityToken);
} catch (IOException e) {
}
}
return transactionStore;
|
protected Utils | getUtilities()Returns an instance of CldcUtils class.
if (utilities == null) {
utilities = new CldcUtils();
}
return utilities;
|
protected final boolean | handleAutoRequestMode(Transaction transaction)Handles the auto request debug mode for the given transaction. It's
called from the parts of the PaymentModule code where this
mode can be applied. If the auto request mode is in effect the
transaction state is set accordingly and the method returns
true .
PaymentInfo paymentInfo = getPaymentInfo(transaction);
if (!paymentInfo.isDemoMode()) {
return false;
}
switch (paymentInfo.getDbgAutoRequestMode()) {
case PaymentInfo.AUTO_REQUEST_REJECT:
transaction.setState(Transaction.REJECTED);
transaction.setNeedsUI(false);
break;
case PaymentInfo.AUTO_REQUEST_ACCEPT:
int[] providers = getValidProviders(paymentInfo);
// we do have at least one supported payment provider
assignTransaction(transaction, providers[0]);
break;
default:
return false;
}
return true;
|
protected final boolean | handleTransactionDebugMode(Transaction transaction)Handles the success/failure/random debug mode for the given transaction.
It's called from the parts of the PaymentModule code where
this mode can be applied. If the debug mode is in effect the transaction
state is set accordingly and the method returns true .
PaymentInfo paymentInfo = getPaymentInfo(transaction);
// (random.nextInt(128) < 64) = approx. one in two will fail
if (paymentInfo.isDemoMode()) {
if (paymentInfo.getDbgFailIO() ||
(paymentInfo.getDbgRandomTests() &&
(random.nextInt(128) < 64))) {
transaction.setState(Transaction.FAILED);
} else {
transaction.setState(Transaction.SUCCESSFUL);
}
transaction.setNeedsUI(false);
return true;
}
return false;
|
public final void | initializeTransactionStore(PaymentInfo paymentInfo, int suiteId, java.lang.String appName)Initializes the transaction store for the given MIDlet suite.
Generates fake missed transactions for the
Pay-Debug-MissedTransactions debug mode.
// === DEBUG MODE ===
int paymentID = getPaymentID(suiteId);
int numMissedTransactions = paymentInfo.getDbgMissedTransactions();
if (paymentInfo.isDemoMode() && (numMissedTransactions > 0)) {
CldcTransactionStoreImpl transactionStore =
(CldcTransactionStoreImpl) getTransactionStore();
try {
transactionStore.generateFakeRecords(
paymentID,
appName,
paymentInfo,
"Feature ",
getValidProviders(paymentInfo),
numMissedTransactions);
} catch (IOException e) {
// ignore
}
}
// === DEBUG MODE ===
|
protected void | preemptDisplay(SecurityToken token, Displayable nextDisplayable)Replaces the current Displayable with the new one if the
nextDisplayable is not null or it recovers
the previous Displayable if the nextDisplayable
is null .
DisplayEventHandler d =
DisplayEventHandlerFactory.getDisplayEventHandler(token);
if (nextDisplayable != null) {
try {
PreemptToken = d.preemptDisplay(nextDisplayable, true);
} catch (InterruptedException ex) {
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_NONE,
"preemptDisplay threw an InterruptedException: " +
ex.getMessage());
}
}
} else {
d.donePreempting(PreemptToken);
PreemptToken = null;
}
|
public final void | removeMissed(int suiteId)Remove missed transaction for given suite.
int id = getPaymentID(suiteId);
CldcTransactionStoreImpl transactionStore =
(CldcTransactionStoreImpl) getTransactionStore();
try {
transactionStore.removeMissedTransaction(id);
} catch (IOException e) {
// skip
}
|
public final void | uninstallFromStore(SecurityToken securityToken, int applicationID)Uninstalls the given MIDlet suite from the transaction store. It means
that the missed transaction records that belong to the suite are removed
from the transaction store.
securityToken.checkIfPermissionAllowed(Permissions.AMS);
TransactionStore transactionStore = getTransactionStore();
try {
transactionStore.removeApplicationRecords(applicationID);
} catch (IOException e) {
// ignore
}
|