001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.j2me.payment;
028:
029: import java.io.IOException;
030: import javax.microedition.payment.TransactionRecord;
031:
032: /**
033: * This interface defines method, which a class needs to implement to act as
034: * a transaction store. An implementation of this class must be thread safe.
035: *
036: * @version 1.3
037: * @see PaymentModule#getTransactionStore
038: */
039: public interface TransactionStore {
040: /**
041: * Returns an identification number, which can be used as
042: * <code>applicationID</code> in the other methods. During installation
043: * each payment supporting <code>MIDletSuite</code> should get such number
044: * and have it stored. From that point this number will identify that
045: * <code>MIDletSuite</code> to the transaction store.
046: *
047: * @return the payment application id
048: * @throws IOException indicates a storage failure
049: */
050: public int getNextApplicationID() throws IOException;
051:
052: /**
053: * Reserves space for the given transaction in the store. It should be
054: * called before any call to the <code>addTransaction</code> method to
055: * ensure that the <code>addTransaction</code> method won't fail later
056: * (when it is inappropriate) due to full store. This method can apply some
057: * store policies, like enforcing a maximum number of missed transactions
058: * per <code>MIDletSuite</code>.
059: *
060: * @param applicationID the application id
061: * @param transaction the transaction
062: * @return an unique ID created for the transaction
063: * @throws IOException indicates that the store is full or won't accept any
064: * further transaction records from that application
065: */
066: public int reserve(int applicationID, Transaction transaction)
067: throws IOException;
068:
069: /**
070: * Adds the given transaction to the store. It returns a new transaction
071: * record for the transaction. This transaction record must have its
072: * <code>wasMissed</code> flag cleared.
073: *
074: * @param transaction the transaction
075: * @return the new transaction record
076: * @throws IOException indicates a storage failure
077: */
078: public TransactionRecord addTransaction(Transaction transaction)
079: throws IOException;
080:
081: /**
082: * It returns <code>true</code> if the <code>setDelivered</code> method
083: * was called for the given transaction ID.
084: *
085: * @param transactionID the transaction ID
086: * @return true if the <code>setDelivered</code> method
087: * was called for the given transaction ID
088: *
089: * @throws IOException indicates a storage failure
090: */
091: public boolean wasDelivered(int transactionID) throws IOException;
092:
093: /**
094: * This method is called after the application is successfully notified
095: * about the transaction with the given transaction ID.
096: *
097: * @param transactionID the transaction ID
098: * @throws IOException indicates a storage failure
099: */
100: public void setDelivered(int transactionID) throws IOException;
101:
102: /**
103: * Returns an array of the missed transaction records for the given
104: * application ID. The transaction records are returned in the order in
105: * which they have been added to the store. Each transaction record must
106: * have its <code>wasMissed</code> flag set.
107: *
108: * @param applicationID the application ID
109: * @return the array of the missed transaction records
110: * @throws IOException indicates a storage failure
111: */
112: public TransactionRecord[] getMissedTransactions(int applicationID)
113: throws IOException;
114:
115: /**
116: * Returns an array of the past transaction records for the given
117: * application ID. The transaction record are returned in the reverse order
118: * as they have been added to the store (most recent first). Each
119: * transaction record must have its <code>wasMissed</code> flag cleared.
120: *
121: * @param applicationID the application ID
122: * @return the array of the missed transaction records
123: * @throws IOException indicates a storage failure
124: */
125: public TransactionRecord[] getPassedTransactions(int applicationID)
126: throws IOException;
127:
128: /**
129: * Returns the size which is used in the store by the application of the
130: * given application ID. This size doesn't include the size of the passed
131: * transactions (it includes only the part of the store which is
132: * removed/uninstalled by the <code>removeApplicationRecords</code> method).
133: *
134: * @param applicationID the application ID
135: * @return the size used by the application
136: * @throws IOException indicates a storage failure
137: */
138: public int getSizeUsedByApplication(int applicationID)
139: throws IOException;
140:
141: /**
142: * Removes the missed records used by the application of the given
143: * application ID. This is to be used, when the MIDlet suite is uninstalled.
144: *
145: * @param applicationID the application ID
146: * @throws IOException indicates a storage failure
147: */
148: public void removeApplicationRecords(int applicationID)
149: throws IOException;
150:
151: /**
152: * Removes all transaction records from the store. This is a helper method
153: * which is used in test suites to get clean state before test execution.
154: *
155: * @throws IOException indicates a storage failure
156: */
157: public void cleanUp() throws IOException;
158: }
|