KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > versioning > system > cvss > util > CommandDuplicator


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.versioning.system.cvss.util;
21
22 import org.netbeans.lib.cvsclient.command.Command;
23 import org.netbeans.lib.cvsclient.command.log.RlogCommand;
24 import org.netbeans.lib.cvsclient.command.tag.RtagCommand;
25 import org.netbeans.lib.cvsclient.command.tag.TagCommand;
26 import org.netbeans.lib.cvsclient.command.remove.RemoveCommand;
27 import org.netbeans.lib.cvsclient.command.commit.CommitCommand;
28 import org.netbeans.lib.cvsclient.command.update.UpdateCommand;
29
30 /**
31  * Utility class that can create copies of commands.
32  *
33  * @author Maros Sandor
34  */

35 public abstract class CommandDuplicator {
36     
37     public static CommandDuplicator getDuplicator(Command src) {
38         if (src instanceof CommitCommand) return new CommitCloner((CommitCommand) src);
39         if (src instanceof UpdateCommand) return new UpdateCloner((UpdateCommand) src);
40         if (src instanceof RemoveCommand) return new RemoveCloner((RemoveCommand) src);
41         if (src instanceof RtagCommand) return new RtagCloner((RtagCommand) src);
42         if (src instanceof RlogCommand) return new RlogCloner((RlogCommand) src);
43         if (src instanceof TagCommand) return new TagCloner((TagCommand) src);
44         throw new IllegalArgumentException JavaDoc("Clone not supported for command type: " + src.getClass().getName()); // NOI18N
45
}
46
47     public abstract Command duplicate();
48     
49     private static class CommitCloner extends CommandDuplicator {
50         private final CommitCommand sample;
51
52         public CommitCloner(CommitCommand sample) {
53             this.sample = sample;
54         }
55
56         public Command duplicate() {
57             CommitCommand c = new CommitCommand();
58             c.setForceCommit(sample.isForceCommit());
59             c.setLogMessageFromFile(sample.getLogMessageFromFile());
60             c.setMessage(sample.getMessage());
61             c.setNoModuleProgram(sample.isNoModuleProgram());
62             c.setRecursive(sample.isRecursive());
63             c.setToRevisionOrBranch(sample.getToRevisionOrBranch());
64             return c;
65         }
66     }
67
68     private static class UpdateCloner extends CommandDuplicator {
69         private final UpdateCommand sample;
70
71         public UpdateCloner(UpdateCommand sample) {
72             this.sample = sample;
73         }
74
75         public Command duplicate() {
76             UpdateCommand c = new UpdateCommand();
77             c.setBuildDirectories(sample.isBuildDirectories());
78             c.setCleanCopy(sample.isCleanCopy());
79             c.setKeywordSubst(sample.getKeywordSubst());
80             c.setMergeRevision1(sample.getMergeRevision1());
81             c.setMergeRevision2(sample.getMergeRevision2());
82             c.setPipeToOutput(sample.isPipeToOutput());
83             c.setPruneDirectories(sample.isPruneDirectories());
84             c.setResetStickyOnes(sample.isResetStickyOnes());
85             c.setUpdateByDate(sample.getUpdateByDate());
86             c.setUpdateByRevision(sample.getUpdateByRevision());
87             c.setUseHeadIfNotFound(sample.isUseHeadIfNotFound());
88             c.setRecursive(sample.isRecursive());
89             return c;
90         }
91     }
92
93
94     private static class RemoveCloner extends CommandDuplicator {
95         private final RemoveCommand sample;
96
97         public RemoveCloner(RemoveCommand sample) {
98             this.sample = sample;
99         }
100
101         public Command duplicate() {
102             RemoveCommand c = new RemoveCommand();
103             c.setDeleteBeforeRemove(sample.isDeleteBeforeRemove());
104             c.setIgnoreLocallyExistingFiles(sample.isIgnoreLocallyExistingFiles());
105             c.setRecursive(sample.isRecursive());
106             return c;
107         }
108     }
109
110     private static class RtagCloner extends CommandDuplicator {
111         private final RtagCommand sample;
112
113         public RtagCloner(RtagCommand sample) {
114             this.sample = sample;
115         }
116
117         public Command duplicate() {
118             RtagCommand c = new RtagCommand();
119             c.setClearFromRemoved(sample.isClearFromRemoved());
120             c.setDeleteTag(sample.isDeleteTag());
121             c.setMakeBranchTag(sample.isMakeBranchTag());
122             c.setMatchHeadIfRevisionNotFound(sample.isMatchHeadIfRevisionNotFound());
123             c.setModules(sample.getModules());
124             c.setNoExecTagProgram(sample.isNoExecTagProgram());
125             c.setOverrideExistingTag(sample.isOverrideExistingTag());
126             c.setTag(sample.getTag());
127             c.setTagByDate(sample.getTagByDate());
128             c.setTagByRevision(sample.getTagByRevision());
129             c.setRecursive(sample.isRecursive());
130             return c;
131         }
132     }
133
134     private static class TagCloner extends CommandDuplicator {
135         private final TagCommand sample;
136
137         public TagCloner(TagCommand sample) {
138             this.sample = sample;
139         }
140
141         public Command duplicate() {
142             TagCommand c = new TagCommand();
143             c.setDeleteTag(sample.isDeleteTag());
144             c.setMakeBranchTag(sample.isMakeBranchTag());
145             c.setMatchHeadIfRevisionNotFound(sample.isMatchHeadIfRevisionNotFound());
146             c.setOverrideExistingTag(sample.isOverrideExistingTag());
147             c.setTag(sample.getTag());
148             c.setTagByDate(sample.getTagByDate());
149             c.setTagByRevision(sample.getTagByRevision());
150             c.setRecursive(sample.isRecursive());
151             c.setCheckThatUnmodified(sample.isCheckThatUnmodified());
152             return c;
153         }
154     }
155     
156     private static class RlogCloner extends CommandDuplicator {
157         private final RlogCommand sample;
158
159         public RlogCloner(RlogCommand sample) {
160             this.sample = sample;
161         }
162
163         public Command duplicate() {
164             RlogCommand c = new RlogCommand();
165             c.setDateFilter(sample.getDateFilter());
166             c.setDefaultBranch(sample.isDefaultBranch());
167             c.setHeaderAndDescOnly(sample.isHeaderAndDescOnly());
168             c.setHeaderOnly(sample.isHeaderOnly());
169             c.setNoTags(sample.isNoTags());
170             c.setRevisionFilter(sample.getRevisionFilter());
171             c.setStateFilter(sample.getStateFilter());
172             c.setSuppressHeader(sample.isSuppressHeader());
173             c.setUserFilter(sample.getUserFilter());
174             c.setModules(sample.getModules());
175             c.setRecursive(sample.isRecursive());
176             return c;
177         }
178     }
179 }
180
Popular Tags