001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.collab.channel.filesharing.eventhandler;
042:
043: import com.sun.collablet.CollabException;
044:
045: import java.util.ArrayList;
046: import java.util.List;
047:
048: import org.netbeans.modules.collab.channel.filesharing.FilesharingContext;
049: import org.netbeans.modules.collab.channel.filesharing.filehandler.CollabFileHandler;
050: import org.netbeans.modules.collab.channel.filesharing.filehandler.SharedFileGroup;
051: import org.netbeans.modules.collab.channel.filesharing.mdc.CollabContext;
052: import org.netbeans.modules.collab.channel.filesharing.mdc.EventContext;
053: import org.netbeans.modules.collab.channel.filesharing.msgbean.CCollab;
054: import org.netbeans.modules.collab.channel.filesharing.msgbean.FileChanged;
055: import org.netbeans.modules.collab.channel.filesharing.msgbean.FileChangedData;
056: import org.netbeans.modules.collab.channel.filesharing.msgbean.FileGroup;
057: import org.netbeans.modules.collab.channel.filesharing.msgbean.FileGroups;
058:
059: /**
060: * SendMessageJoin
061: *
062: * @author Ayub Khan, ayub.khan@sun.com
063: * @version 1.0
064: */
065: public class SendChangeHandler extends FilesharingEventHandler {
066: /**
067: * constructor
068: *
069: */
070: public SendChangeHandler(CollabContext context) {
071: super (context);
072: }
073:
074: ////////////////////////////////////////////////////////////////////////////
075: // Event Handler methods
076: ////////////////////////////////////////////////////////////////////////////
077:
078: /**
079: * constructMsg
080: *
081: * @param evContext Event Context
082: */
083: public CCollab constructMsg(EventContext evContext)
084: throws CollabException {
085: CCollab collab = null;
086: SharedFileGroup[] sharedFileGroups = getContext()
087: .getSharedFileGroupManager().getAllSharedFileGroup();
088:
089: if ((sharedFileGroups == null)
090: || (sharedFileGroups.length == 0)) {
091: return null;
092: }
093:
094: List tmpSavedSharedFileGroups = new ArrayList();
095:
096: for (int i = 0; i < sharedFileGroups.length; i++) {
097: String fileGroupName = sharedFileGroups[i].getName();
098: CollabFileHandler[] fileHandlers = sharedFileGroups[i]
099: .getFileHandlers();
100: int fileChangeCount = 0;
101:
102: for (int j = 0; j < fileHandlers.length; j++) {
103: CollabFileHandler collabFileHandler = fileHandlers[j];
104:
105: if ((collabFileHandler == null)
106: || !collabFileHandler.isValid()) {
107: continue;
108: }
109:
110: int fileHandlerState = collabFileHandler
111: .getCurrentState();
112:
113: if ((fileHandlerState == FilesharingContext.STATE_SENDFILE)
114: || (fileHandlerState == FilesharingContext.STATE_RECEIVEDSENDFILE)
115: || (fileHandlerState == FilesharingContext.STATE_RECEIVEDSENDCHANGE)
116: || (fileHandlerState == FilesharingContext.STATE_RECEIVEDLOCK)
117: || (fileHandlerState == FilesharingContext.STATE_RECEIVEDUNLOCK)) {
118: continue;
119: }
120:
121: boolean isFileChanged = collabFileHandler.isChanged();
122:
123: if (isFileChanged) {
124: fileChangeCount++;
125: }
126: }
127:
128: if (fileChangeCount == 0) {
129: continue;
130: } else {
131: tmpSavedSharedFileGroups.add(sharedFileGroups[i]);
132: }
133: }
134:
135: if (tmpSavedSharedFileGroups.size() == 0) //no changes send
136: {
137: return null;
138: }
139:
140: int totalChangeCount = 0;
141:
142: for (int i = 0; i < tmpSavedSharedFileGroups.size(); i++) {
143: SharedFileGroup sharedFileGroup = (SharedFileGroup) tmpSavedSharedFileGroups
144: .get(i);
145: String fileGroupName = sharedFileGroup.getName();
146: collab = new CCollab();
147: collab.setVersion(getVersion());
148:
149: FileChanged fileChanged = new FileChanged();
150: collab.setChFileChanged(fileChanged);
151:
152: FileGroups fileGroups = new FileGroups();
153: getContext().constructFileGroups(
154: fileGroups,
155: getContext().getSharedFileGroupManager()
156: .getSharedFileGroup(fileGroupName));
157: fileChanged.setFileGroups(fileGroups);
158:
159: CollabFileHandler[] fileHandlers = sharedFileGroups[i]
160: .getFileHandlers();
161: int fileChangeCount = 0;
162:
163: for (int j = 0; j < fileHandlers.length; j++) {
164: FileChangedData fileChangedData = fileHandlers[j]
165: .constructFileChangedData(fileChanged);
166:
167: if (fileChangedData != null) {
168: fileChangeCount++;
169: fileChanged.addFileChangedData(fileChangedData);
170: }
171: }
172:
173: if (fileChangeCount == 0) {
174: totalChangeCount++;
175:
176: continue;
177: }
178: }
179:
180: if (totalChangeCount == sharedFileGroups.length) //no changes send
181: {
182: return null;
183: }
184:
185: return collab;
186: }
187:
188: /**
189: * handleMsg
190: *
191: * @param collabBean
192: * @param messageOriginator
193: * @param isUserSame
194: */
195: public void handleMsg(CCollab collabBean, String messageOriginator,
196: boolean isUserSame) throws CollabException {
197: if (isUserSame) {
198: return;
199: }
200:
201: FileChanged fileChanged = collabBean.getChFileChanged();
202: FileGroup[] fileGroups = fileChanged.getFileGroups()
203: .getFileGroup();
204:
205: for (int i = 0; i < fileGroups.length; i++) {
206: String fileGroupName = fileGroups[i].getFileGroupName();
207: String user = fileGroups[i].getUser().getId();
208: String[] fileNames = fileGroups[i].getFileName();
209:
210: if (!getContext().getSharedFileGroupManager()
211: .isSharedFileGroupExist(fileGroupName)) {
212: throw new CollabException("No file exist: "
213: + fileGroupName);
214: }
215: }
216:
217: FileChangedData[] fileChangedData = fileChanged
218: .getFileChangedData();
219:
220: for (int i = 0; i < fileChangedData.length; i++) {
221: String fullPath = fileChangedData[i].getFileName();
222: CollabFileHandler collabFileHandler = getContext()
223: .getSharedFileGroupManager().getFileHandler(
224: fullPath);
225:
226: if (collabFileHandler == null) {
227: continue;
228: }
229:
230: collabFileHandler
231: .setCurrentState(FilesharingContext.STATE_RECEIVEDSENDCHANGE);
232: collabFileHandler.handleSendChange(messageOriginator,
233: fileChangedData[i]);
234: collabFileHandler
235: .setCurrentState(FilesharingContext.STATE_UNKNOWN);
236: }
237: }
238: }
|