blob: 13f5d15266b395aa96aef18a46dfab9fa11a6b4e [file] [log] [blame]
alision11e8e162013-05-28 10:33:14 -04001/*
2 * Copyright (C) 2004-2012 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 * Additional permission under GNU GPL version 3 section 7:
21 *
22 * If you modify this program, or any covered work, by linking or
23 * combining it with the OpenSSL project's OpenSSL library (or a
24 * modified version of that library), containing parts covered by the
25 * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc.
26 * grants you additional permission to convey the resulting work.
27 * Corresponding Source for a non-source form of such a combination
28 * shall include the source code for the parts of OpenSSL used as well
29 * as that of the covered work.
30 */
31
32package com.savoirfairelinux.sflphone.model;
33
34import android.os.Parcel;
35import android.os.Parcelable;
36import android.util.Log;
37
38public class Account implements Parcelable {
39
40 String accountID;
41 String host;
42 String registered_state;
43 String alias;
44
45 private Account(String bAccountID, String bHost, String bRegistered_state, String bAlias) {
46 accountID = bAccountID;
47 host = bHost;
48 registered_state = bRegistered_state;
49 alias = bAlias;
50 }
51
52 public String getAccountID() {
53 return accountID;
54 }
55
56 public void setAccountID(String accountID) {
57 this.accountID = accountID;
58 }
59
60 public String getHost() {
61 return host;
62 }
63
64 public void setHost(String host) {
65 this.host = host;
66 }
67
68 public String getRegistered_state() {
69 return registered_state;
70 }
71
72 public void setRegistered_state(String registered_state) {
73 this.registered_state = registered_state;
74 }
75
76 public String getAlias() {
77 return alias;
78 }
79
80 public void setAlias(String alias) {
81 this.alias = alias;
82 }
83
84 public Account(Parcel in) {
85 readFromParcel(in);
86 }
87
88 @Override
89 public int describeContents() {
90 return 0;
91 }
92
93 @Override
94 public void writeToParcel(Parcel dest, int arg1) {
95
96 dest.writeString(accountID);
97 dest.writeString(host);
98 dest.writeString(registered_state);
99 dest.writeString(alias);
100 }
101
102 private void readFromParcel(Parcel in) {
103
104 accountID = in.readString();
105 host = in.readString();
106 registered_state = in.readString();
107 alias = in.readString();
108 }
109
110 public static final Parcelable.Creator<Account> CREATOR = new Parcelable.Creator<Account>() {
111 @Override
112 public Account createFromParcel(Parcel in) {
113 return new Account(in);
114 }
115
116 @Override
117 public Account[] newArray(int size) {
118 return new Account[size];
119 }
120 };
121
122 public static class AccountBuilder {
123
124 String bAccountID;
125 String bHost;
126 String bRegistered_state;
127 String bAlias;
128
129 private static final String TAG = AccountBuilder.class.getSimpleName();
130
131 public AccountBuilder setHost(String h) {
132 Log.i(TAG, "setHost" + h);
133 bHost = h;
134 return this;
135 }
136
137 public AccountBuilder setAlias(String h) {
138 Log.i(TAG, "setAlias" + h);
139 bAlias = h;
140 return this;
141 }
142
143 public AccountBuilder setRegisteredState(String h) {
144 Log.i(TAG, "setRegisteredState" + h);
145 bRegistered_state = h;
146 return this;
147 }
148
149 public AccountBuilder setAccountID(String h) {
150 Log.i(TAG, "setAccountID" + h);
151 bAccountID = h;
152 return this;
153 }
154
155 public Account build() throws Exception {
156 if (bHost.contentEquals("") || bAlias.contentEquals("") || bAccountID.contentEquals("") || bRegistered_state.contentEquals("")) {
157 throw new Exception("Builders parameters missing");
158 }
159 return new Account(bAccountID, bHost, bRegistered_state, bAlias);
160 }
161
162 public static AccountBuilder getInstance() {
163 return new AccountBuilder();
164 }
165 }
166
167}