1/*
2 * Copyright (C) 2007 Esmertec AG.
3 * Copyright (C) 2007 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *      http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18package com.android.mms.transaction;
19
20import android.net.Uri;
21
22/**
23 * TransactionState intends to encapsulate all the informations which would
24 * be known by the observers of transactions. To encapsulate Transaction-
25 * State into an intent, it should implement Parcelable interface.
26 */
27public class TransactionState {
28    /**
29     * Result code indicates the Transaction has not started.
30     */
31    public static final int INITIALIZED = 0;
32    /**
33     * Result code indicates the Transaction successfully complete.
34     */
35    public static final int SUCCESS = 1;
36    /**
37     * Result code indicates the Transaction failed.
38     */
39    public static final int FAILED  = 2;
40
41    private Uri mContentUri;
42    private int mState;
43
44    public TransactionState() {
45        mState = INITIALIZED;
46        mContentUri = null;
47    }
48
49    /**
50     * To represent the current state(or the result of processing) to the
51     * ones who wants to know the state.
52     *
53     * @return Current state of the Transaction.
54     */
55    public synchronized int getState() {
56        return mState;
57    }
58
59    /**
60     * To set the state of transaction. This method is only invoked by
61     * the transactions.
62     *
63     * @param state The current state of transaction.
64     */
65    synchronized void setState(int state) {
66        if ((state < INITIALIZED) && (state > FAILED)) {
67            throw new IllegalArgumentException("Bad state: " + state);
68        }
69        mState = state;
70    }
71
72    /**
73     * To represent the result uri of transaction such as uri of MM.
74     *
75     * @return Result uri.
76     */
77    public synchronized Uri getContentUri() {
78        return mContentUri;
79    }
80
81    /**
82     * To set the result uri. This method is only invoked by the transactions.
83     *
84     * @param uri The result uri.
85     */
86    synchronized void setContentUri(Uri uri) {
87        mContentUri = uri;
88    }
89}
90