KickJava   Java API By Example, From Geeks To Geeks.

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


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.beans.XMLEncoder JavaDoc;
22 import java.util.Map JavaDoc;
23 import java.util.HashMap JavaDoc;
24 import org.apache.commons.collections.map.ListOrderedMap;
25
26
27 /**
28  * Corresponds to the <SyncML DM> management object
29  *
30  * @author Stefano Nichele @ Funambol
31  *
32  * @version $Id: SyncMLDM.java,v 1.1 2005/05/16 17:32:55 nichele Exp $
33  */

34
35 public class SyncMLDM implements java.io.Serializable JavaDoc {
36
37     // --------------------------------------------------------------- Constants
38
public static final String JavaDoc SYNCML_DM_BASE_URI = "./SyncML";
39    public static final String JavaDoc SYNCML_DM_DMACC = "/DMAcc";
40    public static final String JavaDoc SYNCML_DM_CON = "/Con" ;
41
42
43    // ------------------------------------------------------------ Private data
44
private DMAcc dmAcc;
45    private ConNode con;
46
47
48    // ------------------------------------------------------------ Constructors
49
/** For serialization purposes */
50    public SyncMLDM() {}
51
52     /**
53      * Creates a new SyncMLDM object with the given parameters
54      *
55      * @param dmAcc the dm account node
56      * @param con the connection node
57      *
58      */

59     public SyncMLDM(final DMAcc dmAcc,
60                     final ConNode con) {
61         this.dmAcc = dmAcc;
62         this.con = con;
63     }
64
65
66     // ---------------------------------------------------------- Public methods
67

68     /**
69      * Gets the dmAcc
70      *
71      * @return the dmAcc
72      */

73     public DMAcc getDmAcc() {
74         return dmAcc;
75     }
76
77     /**
78      * Sets the dmAcc
79      *
80      * @param the dmAcc
81      */

82     public void setDmAcc(DMAcc dmAcc) {
83         this.dmAcc = dmAcc;
84     }
85
86     /**
87      * Gets the con
88      *
89      * @return the con
90      */

91     public ConNode getCon() {
92         return con;
93     }
94
95     /**
96      * Sets the con
97      *
98      * @param the con
99      */

100     public void setCon(ConNode con) {
101         this.con = con;
102     }
103
104
105     /**
106      * Used to test
107      * @param args String[]
108      */

109     public static void main(String JavaDoc[] args) {
110         SyncMLDM syncmlDm = new SyncMLDM();
111
112         DMAcc acc = new DMAcc();
113         Map JavaDoc accounts = new ListOrderedMap();
114
115         DMAccount account = new DMAccount();
116         accounts.put("AccountName", account);
117
118         DMAccount account2 = new DMAccount();
119         accounts.put("AccountName2", account2);
120         account2.setAddressType(2);
121         account2.setClientNonce(new byte[] {23,24,25,26});
122
123         acc.setDMAccounts(accounts);
124         syncmlDm.setDmAcc(acc);
125
126         account.setConRef("ConnectionName");
127
128         Ext ext = new Ext();
129         ext.setNode("service", "5");
130
131         XMLEncoder JavaDoc enc = new XMLEncoder JavaDoc(System.out);
132         enc.writeObject(ext);
133         enc.flush();
134         enc.close();
135
136         Map JavaDoc auths = new ListOrderedMap();
137         Auth auth = new Auth("id", "secret");
138         auths.put("auth-method", auth );
139         NAP nap = new NAP("napBearer", "napAddress", "napAddressType");
140         nap.setAuths(auths);
141
142         Map JavaDoc authsPx = new ListOrderedMap();
143         Auth authPx = new Auth("id", "secret");
144         authsPx.put("auth-method", authPx );
145         PX px = new PX("portNbr", "pxAddress", "pxAddressType");
146         px.setAuths(authsPx);
147
148         Connection con = new Connection(ext, nap, px);
149         ConNode conNode = new ConNode(con, "ConnectionName");
150
151         syncmlDm.setCon(conNode);
152
153         enc = new XMLEncoder JavaDoc(System.out);
154         enc.writeObject(syncmlDm);
155         enc.flush();
156         enc.close();
157     }
158
159 }
Popular Tags