KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sync4j > framework > engine > SyncOperationImpl


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.engine;
19
20 import java.security.Principal JavaDoc;
21
22 import sync4j.framework.engine.SyncItem;
23 import sync4j.framework.engine.SyncOperation;
24
25 import org.apache.commons.lang.builder.ToStringBuilder;
26
27
28 /**
29  * This class is a concrete implementation of <i>SyncOperation</i>
30  * <p>
31  * The property <i>operation</i> contains the type of the operation to perform
32  * and the not null syncItemX selects on what source the operation has to be
33  * applied.
34  *
35  * @author Stefano Fornari @ Funambol
36  *
37  * @version $Id: SyncOperationImpl.java,v 1.8 2005/03/02 20:57:37 harrie Exp $
38  */

39 public class SyncOperationImpl implements SyncOperation {
40     
41     // -------------------------------------------------------------- Properties
42

43     private SyncItem syncItemA = null;
44     public SyncItem getSyncItemA() {
45         return this.syncItemA;
46     }
47     
48     public void setSyncItemA(SyncItem syncItemA) {
49         this.syncItemA = syncItemA;
50     }
51     
52     private SyncItem syncItemB = null;
53     public SyncItem getSyncItemB() {
54         return this.syncItemB;
55     }
56     
57     public void setSyncItemB(SyncItem syncItemB) {
58         this.syncItemB = syncItemB;
59     }
60     
61     private char operation = 0;
62     public char getOperation() {
63         return this.operation;
64     }
65     
66     public void setOperation(char operation) {
67         this.operation = operation;
68     }
69     
70     private Principal JavaDoc owner = null;
71     
72     /** The principal that requested this operation.
73      *
74      * @return the principal that requested this operation. It may be null.
75      *
76      */

77     public Principal JavaDoc getOwner() {
78         return this.owner;
79     }
80     
81     /**
82      * Set the owner of this operation
83      */

84     public void setOwner(Principal JavaDoc owner) {
85         this.owner = owner;
86     }
87     
88     private boolean aOperation = false;
89     
90     /** Getter for property aOperation.
91      * @return Value of property aOperation.
92      *
93      */

94     public boolean isAOperation() {
95         return aOperation;
96     }
97     
98     /** Setter for property aOperation.
99      * @param aOperation New value of property aOperation.
100      *
101      */

102     public void setAOperation(boolean aOperation) {
103         this.aOperation = aOperation;
104     }
105     
106     private boolean bOperation = false;
107     
108     /** Getter for property bOperation.
109      * @return Value of property bOperation.
110      *
111      */

112     public boolean isBOperation() {
113         return bOperation;
114     }
115     
116     /** Setter for property bOperation.
117      * @param bOperation New value of property aOperation.
118      *
119      */

120     public void setBOperation(boolean bOperation) {
121         this.bOperation = bOperation;
122     }
123         
124     // ------------------------------------------------------------ Constructors
125

126     public SyncOperationImpl() {
127     }
128     
129     /**
130      * Create a new SyncOperationImpl
131      *
132      * @param syncItemA the A item
133      * @param syncItemB the B item
134      * @param operation the operation
135      * @param aOperation is an operation to be performed on source A?
136      * @param bOperation is an operation to be performed on source B?
137      */

138     public SyncOperationImpl(Principal JavaDoc owner ,
139                              SyncItem syncItemA ,
140                              SyncItem syncItemB ,
141                              char operation ,
142                              boolean aOperation,
143                              boolean bOperation) {
144         this.owner = owner ;
145         this.syncItemA = syncItemA;
146         this.syncItemB = syncItemB;
147         this.operation = operation;
148         this.aOperation = aOperation;
149         this.bOperation = bOperation;
150     }
151
152     public SyncOperationImpl(SyncItem syncItemA,
153                              SyncItem syncItemB,
154                              char operation) {
155         //
156
// owner can be set later...
157
//
158
this(null, syncItemA, syncItemB, operation, false, false);
159     }
160     
161     // ---------------------------------------------------------- Public methods
162

163     public String JavaDoc toString() {
164         ToStringBuilder b = new ToStringBuilder(this);
165
166         b.append("A", "" + syncItemA);
167         b.append("B", "" + syncItemB);
168         String JavaDoc o = "";
169         switch (operation) {
170             case NEW : o = "NEW" ; break;
171             case DELETE: o = "DELETE" ; break;
172             case UPDATE: o = "UPDATE" ; break;
173             case CONFLICT: o = "CONFLICT" ; break;
174             case NOP: o = "NOP" ; break;
175             case ACCEPT_CHUNK: o = "ACCEPT_CHUNK"; break;
176         }
177         b.append("operation", o);
178         b.append("isAOperation", String.valueOf(aOperation));
179         b.append("isBOperation", String.valueOf(bOperation));
180         
181         return b.toString();
182     }
183 }
Popular Tags