001    /*
002      $Id: DaemonPluginManager.java,v 1.6 2003/03/26 23:07:43 culdesac Exp $
003     */
004    
005    package sharpster.daemon.daemonplugin;
006    
007    import java.util.LinkedList;
008    import java.util.ListIterator;
009    
010    import sharpster.common.*;
011    
012    /**
013     * Class responsible for interpreting plug-in data on behalf of the
014     * File Management Module
015     */
016    public class DaemonPluginManager extends PluginManager {
017    
018      /**
019       * Extract the <code>PluginData</code> stored in the collection
020       * and calls the accurate plug-ins.
021       */
022      public ResponseCollection extractParts(FileCollection originalFiles,
023                                             String role) {
024        FileCollection retval = new FileCollection();
025        FileResponse respval = new FileResponse();
026        ResponseCollection resp = new ResponseCollection();
027    
028        for (int i = 0; i < originalFiles.getFileCount(); i++) {
029          SharedFile origFile = originalFiles.getFile(i);
030          PluginData pd = origFile.getPluginData();
031          if (null != pd) {
032            PartOfFilePlugin plugin = getPluginFromName(pd.getPluginName());
033            //retval.addFile(plugin.extractParts(origFile, role));
034            resp.appendCollection(plugin.extractParts(origFile, role));
035          }
036          else {
037            System.out.println("DP::Warning: Plugin data is null");
038            //retval.addFile(origFile);
039            retval.addFile(origFile);
040            respval.setFiles(retval);
041            resp.addResponse(respval);
042          }
043        }
044    
045        return resp;
046      }
047    
048      /**
049       * Calls the accurate plug-in to execute the insertPart command.
050       */
051      public ResponseCollection mergeParts(FileCollection originalFiles,
052                                           FileCollection partOfFiles,
053                                           String role) {
054        FileCollection retval = new FileCollection();
055        FileResponse respval = new FileResponse();
056        ResponseCollection resp = new ResponseCollection();
057    
058        for (int i = 0; i < partOfFiles.getFileCount(); i++) {
059          /* get the part file */
060          SharedFile partFile = partOfFiles.getFile(i);
061          for (int j = 0; j < originalFiles.getFileCount(); j++) {
062            /* search for the originalfile */
063            SharedFile origFile = originalFiles.getFile(j);
064            if (origFile.getFullPath().equals(partFile.getFullPath())) {
065              PluginData pd = origFile.getPluginData();
066              if (pd != null) {
067                PartOfFilePlugin pp = getPluginFromName(pd.getPluginName());
068                //retval.addFile(pp.mergeParts(origFile, partFile, role));
069                resp.appendCollection(pp.mergeParts(origFile, partFile, role));
070                break;
071              }
072              else {
073                System.out.println("DP::Warning: Plugin data is null");
074                //retval.addFile(partFile);
075                retval.addFile(partFile);
076                respval.setFiles(retval);
077                resp.addResponse(respval);
078              }
079            }
080          }
081        }
082    
083        return resp;
084      }
085    }