Methods Summary |
---|
public java.lang.String | getDisplayName()Gets a display name of this adapter.
return "Premium Priced SMS";
|
public static com.sun.j2me.payment.PPSMSAdapter | getInstance(java.lang.String configuration)Gets a new instance of this adapter.
return new PPSMSAdapter();
|
public static void | initSecurityToken(SecurityToken token)Initializes the security token for this class, so it can
perform actions that a normal MIDlet Suite cannot.
if (classSecurityToken != null) {
return;
}
classSecurityToken = token;
|
private java.lang.Object[] | parseAndValidateSpecInfo(java.lang.String paySpecificInfo)Parses and validates specific payment information from input parameter
Object[] info = null;
int firstIndex = paySpecificInfo.indexOf(',");
if (firstIndex == -1) {
return null;
}
int lastIndex = paySpecificInfo.lastIndexOf(',");
String msisdn = paySpecificInfo.substring(0, firstIndex).trim();
// check if msisdn is in right format
try {
long i = msisdn.startsWith("+")
? Long.parseLong(msisdn.substring(1))
: Long.parseLong(msisdn);
} catch (NumberFormatException nfe) {
return null;
}
String prefix = "";
String smsCount = null;
// no number of messages parameter
if (firstIndex == lastIndex) {
prefix = paySpecificInfo.substring(firstIndex + 1,
paySpecificInfo.length()).trim();
} else {
prefix = paySpecificInfo.substring(firstIndex + 1,
lastIndex).trim();
smsCount = paySpecificInfo.substring(lastIndex + 1,
paySpecificInfo.length()).trim();
}
// check if prefix meets all conditions described in specification
if (!prefix.equals("")) {
int maxLength = 8;
if (prefix.startsWith("0x") || prefix.startsWith("0X")) {
if (prefix.length() % 2 != 0) {
// the heximal value must have an even length
return null;
}
try {
prefix = prefix.substring(2);
// if prefix == 0xFFFFFFFFFFFFFFFF (allowed value),
// Long.parseLong would throw an exception, thus the
// string prefix has to be divided up
if (prefix.length() >= maxLength) {
Long.parseLong(prefix.substring(0, 7), 16);
Long.parseLong(prefix.substring(8), 16);
} else {
Long.parseLong(prefix, 16);
}
maxLength = 16;
} catch (NumberFormatException nfe) {
return null;
}
}
if (prefix.length() > maxLength) {
return null;
}
}
if (smsCount == null) {
info = new Object[2];
} else {
info = new Object[3];
try {
info[2] = Integer.valueOf(smsCount);
} catch (NumberFormatException nfe) {
return null;
}
}
info[0] = msisdn;
info[1] = prefix;
return info;
|
public Transaction | process(Transaction transaction)Processes the given transaction, updates its state and returns the same
transaction instance or a new one (an instance of
a Transaction subclass), which is based on the old
transaction, but adds more (adapter specific) information to it.
switch (transaction.getState()) {
case Transaction.ASSIGNED:
Thread thread = new PPSMSThread(transaction);
transaction.setWaiting(true);
thread.start();
break;
default:
return super.process(transaction);
}
return transaction;
|
public void | validatePriceInfo(double price, java.lang.String paySpecificPriceInfo)Validates the price information which are specified in the application
manifest file for the provider handled by this adapter. It throws an
PaymentException if the parameters are incorrect.
if ((paySpecificPriceInfo == null) ||
(paySpecificPriceInfo.length() == 0) ||
parseAndValidateSpecInfo(paySpecificPriceInfo) == null) {
throw new PaymentException(
PaymentException.INVALID_PRICE_INFORMATION,
paySpecificPriceInfo);
}
|