1 | /**
|
---|
2 | *#########################################################################
|
---|
3 | *
|
---|
4 | * A component of the Gatherer application, part of the Greenstone digital
|
---|
5 | * library suite from the New Zealand Digital Library Project at the
|
---|
6 | * University of Waikato, New Zealand.
|
---|
7 | *
|
---|
8 | * <BR><BR>
|
---|
9 | *
|
---|
10 | * Author: John Thompson, Greenstone Digital Library, University of Waikato
|
---|
11 | *
|
---|
12 | * <BR><BR>
|
---|
13 | *
|
---|
14 | * Copyright (C) 1999 New Zealand Digital Library Project
|
---|
15 | *
|
---|
16 | * <BR><BR>
|
---|
17 | *
|
---|
18 | * This program is free software; you can redistribute it and/or modify
|
---|
19 | * it under the terms of the GNU General Public License as published by
|
---|
20 | * the Free Software Foundation; either version 2 of the License, or
|
---|
21 | * (at your option) any later version.
|
---|
22 | *
|
---|
23 | * <BR><BR>
|
---|
24 | *
|
---|
25 | * This program is distributed in the hope that it will be useful,
|
---|
26 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
27 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
28 | * GNU General Public License for more details.
|
---|
29 | *
|
---|
30 | * <BR><BR>
|
---|
31 | *
|
---|
32 | * You should have received a copy of the GNU General Public License
|
---|
33 | * along with this program; if not, write to the Free Software
|
---|
34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
35 | *########################################################################
|
---|
36 | */
|
---|
37 |
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 |
|
---|
42 |
|
---|
43 | package org.greenstone.gatherer.cdm;
|
---|
44 | /**
|
---|
45 | * Title: The Gatherer<br>
|
---|
46 | * Description: The Gatherer: a tool for gathering and enriching digital collections.<br>
|
---|
47 | * Copyright: Copyright (c) 2001<br>
|
---|
48 | * Company: The University of Waikato<br>
|
---|
49 | * First Coded: 01/05/02
|
---|
50 | * @author John Thompson, Greenstone Digital Libraries
|
---|
51 | * @version 2.1
|
---|
52 | */
|
---|
53 | import java.io.Serializable;
|
---|
54 | import java.util.ArrayList;
|
---|
55 | import java.util.Collections;
|
---|
56 | import org.greenstone.gatherer.cdm.Argument;
|
---|
57 | import org.greenstone.gatherer.cdm.ArgumentContainer;
|
---|
58 | /** This class is responsible for storing information from a parsed pluginfo call in such a way that it allows easy access to parsed details for the purposes of user design and specification of plugins. */
|
---|
59 | // ####################################################################################
|
---|
60 | // Optimization Saving
|
---|
61 | // ####################################################################################
|
---|
62 | // Vector -> ArrayList + Memory, + Processor (pos. - Processor)
|
---|
63 | // ####################################################################################
|
---|
64 | public class PlugIn
|
---|
65 | extends ArrayList
|
---|
66 | implements ArgumentContainer, Comparable, Serializable {
|
---|
67 | /** A reference to the plugin that this one inherits from. */
|
---|
68 | private PlugIn super_plugin = null;
|
---|
69 | /** A string of custom arguments to pass to the plugin. */
|
---|
70 | private String custom = null;
|
---|
71 | /** A description of this plugin. */
|
---|
72 | private String desc = null;
|
---|
73 | /** The name of the plugin as it would appear in the collect.cfg file. */
|
---|
74 | private String name = null;
|
---|
75 | /** Default Constructor.
|
---|
76 | */
|
---|
77 | public PlugIn() {
|
---|
78 | super();
|
---|
79 | }
|
---|
80 | /** Constructor.
|
---|
81 | * @param name The name of this plugin as a <strong>String</strong>.
|
---|
82 | * @param desc A description of this plugin as a <strong>String</strong>.
|
---|
83 | * @param super_plugin The super class of this plugin, as a <strong>PlugIn</strong>.
|
---|
84 | */
|
---|
85 | public PlugIn(String name, String desc, PlugIn super_plugin) {
|
---|
86 | super();
|
---|
87 | this.desc = desc;
|
---|
88 | this.name = name;
|
---|
89 | this.super_plugin = super_plugin;
|
---|
90 | }
|
---|
91 | /** Method to add an argument to this plugin. Only adds the argument if it isn't already present.
|
---|
92 | * @param argument The <strong>Argument</strong> to add.
|
---|
93 | */
|
---|
94 | public void addArgument(Argument argument) {
|
---|
95 | if(!contains(argument)) {
|
---|
96 | add(argument);
|
---|
97 | argument.setOwner(name);
|
---|
98 | }
|
---|
99 | }
|
---|
100 | /** Method to compare two plugins for ordering.
|
---|
101 | * @param object The plugin we are comparing to, as an <strong>Object</strong>.
|
---|
102 | * @return An <i>int</i> specifying the plugin order, using values as set out in <strong>String</strong>.
|
---|
103 | * @see java.lang.String#compareTo
|
---|
104 | */
|
---|
105 | public int compareTo(Object object) {
|
---|
106 | if(object != null && object instanceof PlugIn) {
|
---|
107 | PlugIn plugin = (PlugIn) object;
|
---|
108 | return name.compareTo(plugin.getName());
|
---|
109 | }
|
---|
110 | return -1;
|
---|
111 | }
|
---|
112 | /** This method produces a deep copy of this plugin. Note that this also creates a new copy of each of the super classes of plugins as well. This is the way it should be, as each assigned plugin may have different values for the higher plugins (such as BasPlug).
|
---|
113 | * @return A newly created <strong>PlugIn</strong> with the same details and <strong>Argument</strong>s as this one.
|
---|
114 | */
|
---|
115 | public PlugIn copy() {
|
---|
116 | PlugIn copy = null;
|
---|
117 | if(super_plugin == null) {
|
---|
118 | copy = new PlugIn(name, desc, null);
|
---|
119 | }
|
---|
120 | else {
|
---|
121 | copy = new PlugIn(name, desc, super_plugin.copy());
|
---|
122 | }
|
---|
123 | for(int i = 0; i < size(); i++) {
|
---|
124 | copy.addArgument(((Argument)get(i)).copy());
|
---|
125 | }
|
---|
126 | return copy;
|
---|
127 | }
|
---|
128 | /** Method to determine if two plugins are equal.
|
---|
129 | * @param object The plugin to test against, as an <strong>Object</strong>.
|
---|
130 | * @return <i>true</i> if the plugin names match, <i>false</i> otherwise.
|
---|
131 | */
|
---|
132 | public boolean equals(Object object) {
|
---|
133 | if(object != null && compareTo(object) == 0) {
|
---|
134 | return true;
|
---|
135 | }
|
---|
136 | return false;
|
---|
137 | }
|
---|
138 | /** Method to retrieve an argument by its name.
|
---|
139 | * @param name The name of the argument as a <strong>String</strong>.
|
---|
140 | * @return The <strong>Argument</strong> requested, or <i>null</i> if no such argument.
|
---|
141 | */
|
---|
142 | public Argument getArgument(String name) {
|
---|
143 | // The name given may still include the '-'
|
---|
144 | if(name.startsWith("-")) {
|
---|
145 | name = name.substring(1);
|
---|
146 | }
|
---|
147 | ArrayList arguments = getArguments();
|
---|
148 | for(int i = 0; i < arguments.size(); i++) {
|
---|
149 | Argument argument = (Argument)arguments.get(i);
|
---|
150 | if(argument.getName().equals(name)) {
|
---|
151 | return argument;
|
---|
152 | }
|
---|
153 | }
|
---|
154 | return null;
|
---|
155 | }
|
---|
156 | /** Method to retrieve all of the arguments available to a plugin, including both specific and general ones.
|
---|
157 | * @return A <strong>Hashtable</strong> of arguments, with <name> -> <argument> entries.
|
---|
158 | */
|
---|
159 | public ArrayList getArguments() {
|
---|
160 | ArrayList all_arguments = new ArrayList(this);
|
---|
161 | Collections.sort(all_arguments);
|
---|
162 | if(super_plugin != null) {
|
---|
163 | ArrayList super_arguments = super_plugin.getArguments();
|
---|
164 | for(int i = 0; i < super_arguments.size(); i++) {
|
---|
165 | Object argument = super_arguments.get(i);
|
---|
166 | if(!all_arguments.contains(argument)) {
|
---|
167 | all_arguments.add(argument);
|
---|
168 | }
|
---|
169 | }
|
---|
170 | }
|
---|
171 | return all_arguments;
|
---|
172 | }
|
---|
173 | /** Method to retrieve a plugins custom argument information.
|
---|
174 | * @return The custom arguments as a <strong>String</strong>.
|
---|
175 | */
|
---|
176 | public String getCustom() {
|
---|
177 | return custom;
|
---|
178 | }
|
---|
179 | /** Method to retrieve a plugins name.
|
---|
180 | * @return A <strong>String</strong> containing the plugins name.
|
---|
181 | */
|
---|
182 | public String getName() {
|
---|
183 | return name;
|
---|
184 | }
|
---|
185 | public void setCustom(String custom) {
|
---|
186 | this.custom = custom;
|
---|
187 | }
|
---|
188 | /** Method to set the value of desc.
|
---|
189 | * @param desc The new value of desc as a <strong>String</strong>.
|
---|
190 | */
|
---|
191 | public void setDesc(String desc) {
|
---|
192 | this.desc = desc;
|
---|
193 | }
|
---|
194 | /** Method to set the value of name.
|
---|
195 | * @param name The new value of name as a <strong>String</strong>.
|
---|
196 | */
|
---|
197 | public void setName(String name) {
|
---|
198 | this.name = name;
|
---|
199 | }
|
---|
200 | /** Method to set the value of the super_plugin.
|
---|
201 | * @param super_plugin The new value of super_plugin as a <strong>PlugIn</strong>, or <i>null</i> if this class has no inheritance.
|
---|
202 | */
|
---|
203 | public void setSuper(PlugIn super_plugin) {
|
---|
204 | this.super_plugin = super_plugin;
|
---|
205 | }
|
---|
206 | /** Method to print out this plugin as it would appear as a command within the collection configuration file.
|
---|
207 | * @return A <strong>String</strong> containing a single plugin command.
|
---|
208 | */
|
---|
209 | public String toString() {
|
---|
210 | String text = "plugin " + name + " ";
|
---|
211 | ArrayList arguments = getArguments();
|
---|
212 | for(int i = 0; i < arguments.size(); i++) {
|
---|
213 | Argument argument = (Argument)arguments.get(i);
|
---|
214 | if(argument.isAssigned()) {
|
---|
215 | text = text + argument.toString();
|
---|
216 | if(i < arguments.size() - 1) {
|
---|
217 | text = text + " ";
|
---|
218 | }
|
---|
219 | }
|
---|
220 | }
|
---|
221 | // Now print custom arguments if any.
|
---|
222 | if(custom != null) {
|
---|
223 | text = text + " " + custom;
|
---|
224 | }
|
---|
225 | return text;
|
---|
226 | }
|
---|
227 | }
|
---|
228 |
|
---|
229 |
|
---|