KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > core > dm > ddf > DMAcc


1 /**
2  * Copyright (C) 2003-2005 Funambol
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  */

18
19 package sync4j.framework.core.dm.ddf;
20
21 import java.util.Iterator JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.Set JavaDoc;
24
25 import org.apache.commons.collections.map.ListOrderedMap;
26
27 /**
28  * Corresponds to the <DMAcc> in the management tree
29  *
30  * @author Stefano Nichele @ Funambol
31  *
32  * @version $Id: DMAcc.java,v 1.1 2005/05/16 17:32:55 nichele Exp $
33  */

34 public class DMAcc implements java.io.Serializable JavaDoc {
35
36     // --------------------------------------------------------------- Constants
37

38    // ------------------------------------------------------------ Private data
39

40    private Map JavaDoc dmAccounts;
41
42
43
44    // ------------------------------------------------------------ Constructors
45
/** For serialization purposes */
46    public DMAcc() {}
47
48     /**
49      * Creates a new DMAcc object with the given <code>DMAccount</code> and the given name
50      *
51      * @param dmAccount the dm account
52      * @param accountName the name of the dm account
53      */

54     public DMAcc(final DMAccount dmAccount, final String JavaDoc accountName) {
55         this.dmAccounts = new ListOrderedMap();
56         this.dmAccounts.put(accountName, dmAccount);
57     }
58
59
60     // ---------------------------------------------------------- Public methods
61

62     /**
63      * Add new dm account
64      * @param dmAccount the dm account to add
65      * @param accountName the name of the dm account to add
66      */

67     public void addDMAccount(final DMAccount dmAccount, final String JavaDoc accountName) {
68         this.dmAccounts.put(accountName, dmAccount);
69     }
70
71     /**
72      * Gets the dm account with the given name
73      *
74      * @param accountName the name of the dm account
75      * @return the dm account with the given name.<br/><code>null</code> if not exists.
76      */

77     public DMAccount getDMAccount(final String JavaDoc accountName) {
78         return (DMAccount)this.dmAccounts.get(accountName);
79     }
80
81
82     /**
83      * Rename, if exists, a <code>DMAccount</code> contained in this <code>DMAcc</code>
84      *
85      * @param oldAccountName the name of the dm account to rename
86      * @param newAccountName the new name of the dm account to rename
87      */

88     public void renameDMAccount(String JavaDoc oldAccountName, String JavaDoc newAccountName) {
89
90         if (dmAccounts == null) {
91             // no accounts
92
return ;
93         }
94
95         //
96
// In order to rename a dmAccount maintaining the order, we must create
97
// a new ListOrderedMap
98
//
99
Set JavaDoc keys = dmAccounts.keySet();
100         Iterator JavaDoc itKeys = keys.iterator();
101         String JavaDoc accountName = null;
102         Map JavaDoc newDmAccounts = new ListOrderedMap();
103         while (itKeys.hasNext()) {
104             accountName = (String JavaDoc)itKeys.next();
105             if (accountName.equalsIgnoreCase(oldAccountName)) {
106                 newDmAccounts.put(newAccountName, dmAccounts.get(oldAccountName));
107             } else {
108                 newDmAccounts.put(accountName, dmAccounts.get(accountName));
109             }
110         }
111         this.dmAccounts = newDmAccounts;
112     }
113
114
115     /**
116      * Gets the dm accounts
117      *
118      * @return the dm accounts
119      */

120     public Map JavaDoc getDMAccounts() {
121         return dmAccounts;
122     }
123
124     /**
125      * Sets the dm accounts
126      *
127      * @param dmAccounts the dmAccount to set
128      */

129     public void setDMAccounts(Map JavaDoc dmAccounts) {
130         this.dmAccounts = dmAccounts;
131     }
132
133
134     /**
135      * Returns the number of dm accounts
136      *
137      * @return the number of dm accounts
138      */

139     public int numberOfDMAccounts() {
140         return dmAccounts.size();
141     }
142
143
144 }
Popular Tags