001: /* CVS ID: $Id: PluginDependencyTree.java,v 1.1.1.1 2002/10/02 18:42:51 wastl Exp $ */
002: package net.wastl.webmail.server;
003:
004: import java.util.*;
005:
006: /*
007: * PluginDependencyTree.java
008: *
009: * Created: Sat Sep 11 14:52:22 1999
010: *
011: * Copyright (C) 1999-2000 Sebastian Schaffert
012: *
013: * This program is free software; you can redistribute it and/or
014: * modify it under the terms of the GNU General Public License
015: * as published by the Free Software Foundation; either version 2
016: * of the License, or (at your option) any later version.
017: *
018: * This program is distributed in the hope that it will be useful,
019: * but WITHOUT ANY WARRANTY; without even the implied warranty of
020: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
021: * GNU General Public License for more details.
022: *
023: * You should have received a copy of the GNU General Public License
024: * along with this program; if not, write to the Free Software
025: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
026: */
027: /**
028: *
029: * @author Sebastian Schaffert
030: * @version
031: */
032:
033: public class PluginDependencyTree {
034:
035: protected Plugin node;
036: protected String meprovides;
037:
038: protected Vector children;
039:
040: public PluginDependencyTree(Plugin p) {
041: this .node = p;
042: this .meprovides = p.provides();
043: children = new Vector();
044: }
045:
046: public PluginDependencyTree(String s) {
047: this .node = null;
048: this .meprovides = s;
049: children = new Vector();
050: }
051:
052: public boolean provides(String s) {
053: return s.equals(meprovides);
054: }
055:
056: public String provides() {
057: String s = meprovides;
058: Enumeration e = children.elements();
059: while (e.hasMoreElements()) {
060: PluginDependencyTree p = (PluginDependencyTree) e
061: .nextElement();
062: s += "," + p.provides();
063: }
064: return s;
065: }
066:
067: public boolean addPlugin(Plugin p) {
068: if (p.requires().equals(meprovides)) {
069: children.addElement(new PluginDependencyTree(p));
070: return true;
071: } else {
072: boolean flag = false;
073: Enumeration e = children.elements();
074: while (e.hasMoreElements()) {
075: PluginDependencyTree pt = (PluginDependencyTree) e
076: .nextElement();
077: flag = flag || pt.addPlugin(p);
078: }
079: return flag;
080: }
081: }
082:
083: public void register(WebMailServer parent) {
084: if (node != null) {
085: //System.err.print(node.getName()+" ");
086: //System.err.flush();
087: node.register(parent);
088: }
089:
090: /* Perform depth-first registraion. Breadth-first would be better, but
091: it will work anyway */
092: Enumeration e = children.elements();
093: while (e.hasMoreElements()) {
094: PluginDependencyTree p = (PluginDependencyTree) e
095: .nextElement();
096: p.register(parent);
097: }
098: }
099:
100: } // PluginDependencyTree
|