KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > core > Atomic


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
20 package sync4j.framework.core;
21
22 import java.util.*;
23
24 /**
25  * Corresponds to the <Atomic> tag in the SyncML represent DTD
26  *
27  * @author Stefano Fornari
28  *
29  * @version $Id: Atomic.java,v 1.3 2005/03/02 20:57:37 harrie Exp $
30  */

31 public final class Atomic
32 extends AbstractCommand
33 implements java.io.Serializable JavaDoc {
34     
35     // --------------------------------------------------------------- Constants
36
public static String JavaDoc COMMAND_NAME = "Atomic";
37
38     // ------------------------------------------------------------ Private Data
39
private ArrayList commands = new ArrayList();
40     
41     // ------------------------------------------------------------ Constructors
42

43     /** For serialization purposes */
44     protected Atomic(){}
45
46     /**
47      * Creates a new Atomic object with the given command identifier, noResponse,
48      * meta and an array of abstract command
49      *
50      * @param cmdID the command identifier - NOT NULL
51      * @param noResp is true if no response is required
52      * @param meta the meta data
53      * @param commands an array of abstract command - NOT NULL
54      */

55     public Atomic(final CmdID cmdID,
56                   final boolean noResp,
57                   final Meta meta,
58                   final AbstractCommand[] commands) {
59         super(cmdID);
60         
61         this.noResp = (noResp) ? new Boolean JavaDoc(noResp) : null;
62         setMeta(meta);
63         setCommands(commands);
64         
65     }
66
67     // ---------------------------------------------------------- Public methods
68

69     /**
70      * Gets an array of AbstractCommand
71      *
72      * @return an array of command objects
73      */

74     public ArrayList getCommands() {
75         return this.commands;
76     }
77     
78     /**
79      * Sets an array of AbstractCommand
80      *
81      * @param commands the array of AbstractCommand
82      *
83      */

84     public void setCommands(AbstractCommand[] commands) {
85         if (commands == null || commands.length == 0) {
86             throw new IllegalArgumentException JavaDoc("commands cannot be null");
87         }
88
89         for (int i=0; i<commands.length; i++) {
90             if ((!(commands[i] instanceof Add))
91              && (!(commands[i] instanceof Delete))
92              && (!(commands[i] instanceof Copy))
93              && (!(commands[i] instanceof Map))
94              && (!(commands[i] instanceof Replace))
95              && (!(commands[i] instanceof Sequence))
96              && (!(commands[i] instanceof Sync))) {
97                 
98                 throw new IllegalArgumentException JavaDoc(
99                                     "illegal nested command: " + commands[i]);
100             }
101         }
102         this.commands.clear();
103         this.commands.addAll(Arrays.asList(commands));
104     }
105
106     /**
107      * Gets the command name property
108      *
109      * @return the command name property
110      */

111     public String JavaDoc getName() {
112         return Atomic.COMMAND_NAME;
113     }
114 }
Popular Tags