KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > filter > FilterCompoundCommand


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.filter;
19
20 import org.columba.api.command.ICommand;
21 import org.columba.api.plugin.IExtension;
22 import org.columba.api.plugin.IExtensionHandler;
23 import org.columba.core.command.CompoundCommand;
24 import org.columba.core.filter.AbstractFilterAction;
25 import org.columba.core.filter.Filter;
26 import org.columba.core.filter.FilterAction;
27 import org.columba.core.filter.FilterActionList;
28 import org.columba.core.filter.IFilter;
29 import org.columba.core.filter.IFilterAction;
30 import org.columba.core.filter.IFilterActionList;
31 import org.columba.core.folder.api.IFolder;
32 import org.columba.core.plugin.PluginManager;
33 import org.columba.mail.folder.IMailbox;
34
35 /**
36  * @author fdietz
37  *
38  */

39 public class FilterCompoundCommand extends CompoundCommand {
40
41     /**
42      *
43      */

44     public FilterCompoundCommand(IFilter filter, IFolder sourceFolder,
45             Object JavaDoc[] uids) throws Exception JavaDoc {
46         super();
47
48         // get plugin handler for filter actions
49
IExtensionHandler pluginHandler = PluginManager
50                 .getInstance().getExtensionHandler("org.columba.mail.filteraction");
51
52         // get list of all filter actions
53
IFilterActionList list = filter.getFilterActionList();
54
55         for (int i = 0; i < list.getChildCount(); i++) {
56             // interate through all filter actions
57
IFilterAction action = list.get(i);
58
59             // name is used to load plugin
60
String JavaDoc name = action.getAction();
61             AbstractFilterAction instance = null;
62
63             // try to get instance of FilterAction
64
try {
65                 IExtension extension = pluginHandler.getExtension(name);
66
67                 instance = (AbstractFilterAction) extension
68                         .instanciateExtension(null);
69             } catch (Exception JavaDoc ex) {
70                 ex.printStackTrace();
71             }
72
73             // retrieve Command of filter action
74
ICommand command = instance.getCommand(action,
75                     (IMailbox) sourceFolder, uids);
76
77             // add command to CompoundCommand
78
if (command != null) {
79                 add(command);
80             }
81         }
82     }
83
84 }
Popular Tags