KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > protocol > v11 > ManagementActionsRequirements


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 package sync4j.framework.protocol.v11;
19
20 import java.util.List JavaDoc;
21 import java.util.Iterator JavaDoc;
22
23 import sync4j.framework.core.*;
24
25 import sync4j.framework.protocol.ProtocolException;
26 import sync4j.framework.protocol.v11.BasicRequirements;
27 import sync4j.framework.protocol.v11.Errors;
28
29 /**
30  * This class groups utility methods used for checking that a management actions
31  * response massage follows the requirements that the protocol mandates.
32  *
33  * @author Stefano Fornari @ Funambol
34  */

35 public class ManagementActionsRequirements
36 extends BasicRequirements
37 implements Errors {
38     
39     // --------------------------------------------------------------- Constants
40

41     // ---------------------------------------------------------- Public methods
42

43     /**
44      * Checks if the Results commands follow the specs
45      *
46      * @param results the result commands
47      *
48      * @throws ProtocolException
49      */

50     static public void checkResults(List JavaDoc results) throws ProtocolException {
51         Results r;
52         List JavaDoc items;
53         
54         Iterator JavaDoc i = results.iterator();
55         
56         while (i.hasNext()) {
57             r = (Results)i.next();
58             
59             items = r.getItems();
60             if (items.size() == 0) {
61                 Object JavaDoc[] args = new Object JavaDoc[] { r.getCmdID().getCmdID() };
62                 throw new ProtocolException(ERRMSG_NO_ITEM_IN_RESULTS, args);
63             }
64             
65             Iterator JavaDoc j = items.iterator();
66             while (j.hasNext()) {
67                 if (((Item)j.next()).getSource() == null) {
68                     throw new ProtocolException(ERRMSG_MISSING_SOURCE_ITEM);
69                 }
70             }
71         }
72     }
73 }
Popular Tags