CldcTransactionModuleImplpublic class CldcTransactionModuleImpl extends TransactionModuleImpl This class implements parts of TransactionModuleImpl which
are dependent on the CLDC. It's created by a factory method in the payment
module. |
Fields Summary |
---|
private MIDletSuite | midletSuiteMDIletSuite being run | private static final String | PAYMENT_UPDATE_FILE_NAMEThe name of the file where the Midlet Payment Update Info is stored. | public static final String | PAY_VERSION_PROPMIDlet property for the Payment Version. | private PaymentInfo | paymentInfoMIDletSuite payment info |
Constructors Summary |
---|
protected CldcTransactionModuleImpl(Object object)Creates a new instance of CldcTransactionModuleImpl .
Requires a reference to the application MIDlet which initiated the
payment.
Handles the Pay-Debug-FailInitialize debug mode.
super(object);
PaymentInfo paymentInfo = getPaymentInfo();
if (paymentInfo == null) {
throw new TransactionModuleException("Missing provisioning " +
"information");
}
/* Check if MIDletSuite is Trusted */
// Removed - SecurityException is thrown if untrusted MIDlet tries to use
// restricted permission, so no additional check is required
// if (!paymentInfo.isDemoMode() && !getMIDletSuite().isTrusted()) {
// throw new TransactionModuleException("MidletSuite is untrusted");
// }
// === DEBUG MODE ===
// (PaymentModule.random.nextInt(192) < 64) = approx. one in three will
// fail in this way
if (paymentInfo.isDemoMode() && (
paymentInfo.getDbgFailInitialize() ||
paymentInfo.getDbgRandomTests() &&
(CldcPaymentModule.random.nextInt(192) < 64))) {
throw new TransactionModuleException("Debug mode");
}
// === DEBUG MODE ===
|
Methods Summary |
---|
protected void | checkForPermission(int permission, java.lang.String name)Ensures that the MIDlet will have required privileges to do a protected
operation.
getMIDletSuite().checkForPermission(permission, name);
| protected int | getApplicationID()Returns the MIDlet payment ID that can be used to store transaction
records for the MIDlet initiated transactions into the transaction store.
return ((CldcPaymentModule) PaymentModule.getInstance())
.getPaymentID(getMIDletSuite().getID());
| private MIDletSuite | getMIDletSuite()Returns the MIDlet suite of the MIDlet.
if (midletSuite == null) {
midletSuite =
(MIDletSuite) Scheduler.getScheduler().getMIDletSuite();
}
return midletSuite;
| protected javax.microedition.payment.TransactionRecord[] | getMissedTransactions()Returns an array of the missed transactions associated with the MIDlet
suite.
It handles the Pay-Debug-MissedTransactions debug mode.
// === DEBUG MODE ===
PaymentInfo paymentInfo = getPaymentInfo();
if (paymentInfo.isDemoMode() &&
paymentInfo.getDbgMissedTransactions() >= 0) {
int applicationID = getApplicationID();
CldcPaymentModule paymentModule = (CldcPaymentModule)
PaymentModule.getInstance();
CldcTransactionStoreImpl transactionStore =
(CldcTransactionStoreImpl) paymentModule.getTransactionStore();
TransactionRecord[] fakeMissed = null;
try {
fakeMissed = transactionStore.getMissedTransactions(
applicationID, true);
} catch (IOException e) {
}
return fakeMissed;
}
// === DEBUG MODE ===
return super.getMissedTransactions();
| protected PaymentInfo | getPaymentInfo()Returns the payment provisioning information associated with the MIDlet.
if (paymentInfo == null) {
if (getMIDletSuite().getProperty(PAY_VERSION_PROP) == null) {
// quick check
return null;
}
RecordStore store;
PropertiesWraper props = new PropertiesWraper(getMIDletSuite());
// try to read updated provision info
try {
store = RecordStore.openRecordStore(PAYMENT_UPDATE_FILE_NAME,
false);
try {
byte[] data = new byte[store.getRecordSize(1)];
data = store.getRecord(1);
InputStream bis = new ByteArrayInputStream(data);
JadProperties payProps = new JadProperties();
payProps.load(bis);
bis.close();
paymentInfo = PaymentInfo.createFromProperties(
props, payProps);
} finally {
store.closeRecordStore();
}
} catch (RecordStoreNotFoundException ex) {
// if the is no update file try to read payment info from
// suite properties
try {
paymentInfo = PaymentInfo.createFromProperties(
props, props);
} catch (PaymentException e) {
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_AMS,
"getPaymentInfo threw an PaymentException: " +
e.getMessage());
}
}
} catch (RecordStoreException ex) {
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_AMS,
"getPaymentInfo threw an RecordStoreException: " +
ex.getMessage());
}
} catch (PaymentException ex) {
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_AMS,
"getPaymentInfo threw an PaymentException: " +
ex.getMessage());
}
} catch (IOException ex) {
if (Logging.REPORT_LEVEL <= Logging.ERROR) {
Logging.report(Logging.ERROR, LogChannels.LC_AMS,
"getPaymentInfo threw an IOException: " +
ex.getMessage());
}
}
if (paymentInfo != null) {
// initialize the transaction store for this MIDletSuite only
// for once
((CldcPaymentModule) PaymentModule.getInstance())
.initializeTransactionStore(paymentInfo,
midletSuite.getID(),
midletSuite.getProperty(MIDletSuiteImpl.SUITE_NAME_PROP));
}
}
return paymentInfo;
| protected void | savePaymentInfo()Stores the payment provisioning information associated with the MIDlet.
PaymentInfo pInfo = getPaymentInfo();
if (pInfo != null) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
OutputStreamWriter os = new OutputStreamWriter(bos, "UTF-8");
byte[] data;
try {
pInfo.export(os);
data = bos.toByteArray();
} finally {
os.close();
}
RecordStore store = null;
try {
store = RecordStore.openRecordStore(PAYMENT_UPDATE_FILE_NAME,
true);
try {
if (store.getNumRecords() == 0) {
/* Record Store is EMPTY - add new record */
store.addRecord(data, 0, data.length);
} else {
/* Replace first record */
store.setRecord(1, data, 0, data.length);
}
} finally {
store.closeRecordStore();
}
} catch (RecordStoreException e) {
throw new IOException(
"Storage Failure: Can not store Payment Info");
}
}
|
|