Clover coverage report - AdWT - 1.0.0
Coverage timestamp: sam. déc. 27 2003 15:14:10 CET
file stats: LOC: 271   Methods: 13
NCLOC: 127   Classes: 3
 
 Source file Conditionals Statements Methods TOTAL
HistoryServiceProvider.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * EJTools, the Enterprise Java Tools
 3   
  *
 4   
  * Distributable under LGPL license.
 5   
  * See terms of license at www.gnu.org.
 6   
  */
 7   
 package org.ejtools.adwt.service;
 8   
 
 9   
 import java.beans.beancontext.BeanContextServices;
 10   
 import java.net.URL;
 11   
 import java.util.Iterator;
 12   
 import java.util.Vector;
 13   
 
 14   
 import javax.swing.Action;
 15   
 
 16   
 import org.apache.log4j.Logger;
 17   
 import org.ejtools.adwt.action.Command;
 18   
 import org.ejtools.adwt.action.CommandAction;
 19   
 import org.ejtools.adwt.action.file.FileHistoryAction;
 20   
 import org.ejtools.adwt.action.file.FileHistoryActionTop;
 21   
 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider;
 22   
 import org.ejtools.util.KeyLimitedStack;
 23   
 
 24   
 /**
 25   
  * Description of the Class
 26   
  *
 27   
  * @author    Laurent Etiemble
 28   
  * @version   $Revision: 1.5 $
 29   
  * @todo      Javadoc to complete
 30   
  */
 31   
 public class HistoryServiceProvider extends CustomBeanContextServiceProvider implements HistoryService
 32   
 {
 33   
    /** Description of the Field */
 34   
    protected HistoryService.Holder holder = null;
 35   
    /** Description of the Field */
 36   
    protected int maxHistory;
 37   
    /** Description of the Field */
 38   
    protected Vector menus = null;
 39   
    /** Description of the Field */
 40   
    protected HistoryService service = null;
 41   
    /** Description of the Field */
 42   
    protected KeyLimitedStack stack = null;
 43   
    /** Description of the Field */
 44   
    private static Logger logger = Logger.getLogger(HistoryServiceProvider.class);
 45   
    /** Description of the Field */
 46   
    protected final static int MAX_WIDTH = 30;
 47   
 
 48   
 
 49   
    /**
 50   
     * Constructor for the HistoryServiceProvider object
 51   
     *
 52   
     * @param maxHistory  Description of Parameter
 53   
     * @param holder      Description of Parameter
 54   
     */
 55  0
    public HistoryServiceProvider(HistoryService.Holder holder, int maxHistory)
 56   
    {
 57  0
       this.service = this;
 58  0
       this.holder = holder;
 59  0
       this.maxHistory = maxHistory;
 60  0
       this.stack = new KeyLimitedStack(maxHistory);
 61  0
       this.menus = new Vector(maxHistory);
 62   
    }
 63   
 
 64   
 
 65   
    /**
 66   
     * Gets the currentServiceSelectors attribute of the HistoryServiceProvider object
 67   
     *
 68   
     * @param bcs           Description of Parameter
 69   
     * @param serviceClass  Description of Parameter
 70   
     * @return              The currentServiceSelectors value
 71   
     */
 72  0
    public Iterator getCurrentServiceSelectors(BeanContextServices bcs, Class serviceClass)
 73   
    {
 74  0
       return new Vector().iterator();
 75   
    }
 76   
 
 77   
 
 78   
    /**
 79   
     * Gets the service attribute of the HistoryServiceProvider object
 80   
     *
 81   
     * @param bcs              Description of Parameter
 82   
     * @param requestor        Description of Parameter
 83   
     * @param serviceClass     Description of Parameter
 84   
     * @param serviceSelector  Description of Parameter
 85   
     * @return                 The service value
 86   
     */
 87  0
    public Object getService(BeanContextServices bcs, Object requestor, Class serviceClass, Object serviceSelector)
 88   
    {
 89  0
       return service;
 90   
    }
 91   
 
 92   
 
 93   
    /**
 94   
     * Description of the Method
 95   
     *
 96   
     * @param url      Description of Parameter
 97   
     * @param context  Description of Parameter
 98   
     */
 99  0
    public void push(URL url, Object context)
 100   
    {
 101  0
       this.stack.push(new HistoryContext(url, context));
 102   
 
 103  0
       for (int i = 0; i < stack.size(); i++)
 104   
       {
 105  0
          HistoryContext hc = (HistoryContext) this.stack.elementAt(i);
 106  0
          URL theUrl = hc.getURL();
 107  0
          String s = theUrl.toString();
 108   
 
 109  0
          if (s.length() > MAX_WIDTH)
 110   
          {
 111  0
             s = "" + (i + 1) + ": " + theUrl.getProtocol() + "..." + s.substring(s.length() - 25);
 112   
          }
 113   
          else
 114   
          {
 115  0
             s = "" + (i + 1) + ": " + theUrl.toString();
 116   
          }
 117   
 
 118  0
          CommandAction action = (CommandAction) menus.elementAt(i);
 119  0
          action.putValue(Action.NAME, s);
 120  0
          action.setEnabled(true);
 121   
       }
 122   
    }
 123   
 
 124   
 
 125   
    /**
 126   
     * Description of the Method
 127   
     *
 128   
     * @param bcs        Description of Parameter
 129   
     * @param requestor  Description of Parameter
 130   
     * @param service    Description of Parameter
 131   
     */
 132  0
    public void releaseService(BeanContextServices bcs, Object requestor, Object service) { }
 133   
 
 134   
 
 135   
    /**
 136   
     * @return   The serviceClass value
 137   
     */
 138  0
    protected Class[] getServiceClass()
 139   
    {
 140  0
       return new Class[]{HistoryService.class};
 141   
    }
 142   
 
 143   
 
 144   
    /** Description of the Method */
 145  0
    protected void initializeBeanContextResources()
 146   
    {
 147  0
       super.initializeBeanContextResources();
 148   
 
 149  0
       CommandAction action;
 150   
 
 151  0
       for (int i = 0; i < this.maxHistory; i++)
 152   
       {
 153  0
          if (i == 0)
 154   
          {
 155  0
             action = new FileHistoryActionTop(
 156   
                new FileHistoryCommand(i)
 157   
                );
 158   
          }
 159   
          else
 160   
          {
 161  0
             action = new FileHistoryAction(
 162   
                new FileHistoryCommand(i)
 163   
                );
 164   
          }
 165  0
          action.setEnabled(false);
 166  0
          menus.add(action);
 167  0
          this.add(action);
 168   
       }
 169   
 
 170  0
       logger.debug("HistoryService added");
 171   
    }
 172   
 
 173   
 
 174   
    /**
 175   
     * Description of the Class
 176   
     *
 177   
     * @author    letiembl
 178   
     * @version   $Revision: 1.5 $
 179   
     */
 180   
    private class FileHistoryCommand implements Command
 181   
    {
 182   
       /** Description of the Field */
 183   
       private int position;
 184   
 
 185   
 
 186   
       /**
 187   
        * Constructor for the FileHistoryCommand object
 188   
        *
 189   
        * @param position  Description of Parameter
 190   
        */
 191  0
       public FileHistoryCommand(int position)
 192   
       {
 193  0
          this.position = position;
 194   
       }
 195   
 
 196   
 
 197   
       /** Description of the Method */
 198  0
       public void execute()
 199   
       {
 200  0
          HistoryContext hc = (HistoryContext) HistoryServiceProvider.this.stack.elementAt(position);
 201  0
          logger.info("Loading " + hc.getURL());
 202  0
          HistoryServiceProvider.this.holder.loadResource(hc.getURL(), hc.getContext());
 203   
       }
 204   
    }
 205   
 
 206   
 
 207   
    /**
 208   
     * Description of the Class
 209   
     *
 210   
     * @author    letiembl
 211   
     * @version   $Revision: 1.5 $
 212   
     */
 213   
    private class HistoryContext
 214   
    {
 215   
       /** Description of the Field */
 216   
       private Object context;
 217   
       /** Description of the Field */
 218   
       private URL url;
 219   
 
 220   
 
 221   
       /**
 222   
        * Constructor for the HistoryContext object
 223   
        *
 224   
        * @param url      Description of Parameter
 225   
        * @param context  Description of Parameter
 226   
        */
 227  0
       public HistoryContext(URL url, Object context)
 228   
       {
 229  0
          this.url = url;
 230  0
          this.context = context;
 231   
       }
 232   
 
 233   
 
 234   
       /**
 235   
        * Description of the Method
 236   
        *
 237   
        * @param o  Description of Parameter
 238   
        * @return   Description of the Returned Value
 239   
        */
 240  0
       public boolean equals(Object o)
 241   
       {
 242  0
          logger.debug("Object to test " + ((HistoryContext) o).getURL().toString());
 243  0
          logger.debug("The URL        " + this.url.toString());
 244  0
          return ((HistoryContext) o).getURL().equals(this.url);
 245   
       }
 246   
 
 247   
 
 248   
       /**
 249   
        * Gets the context attribute of the HistoryContext object
 250   
        *
 251   
        * @return   The context value
 252   
        */
 253  0
       public Object getContext()
 254   
       {
 255  0
          return this.context;
 256   
       }
 257   
 
 258   
 
 259   
       /**
 260   
        * Gets the uRL attribute of the HistoryContext object
 261   
        *
 262   
        * @return   The uRL value
 263   
        */
 264  0
       public URL getURL()
 265   
       {
 266  0
          return this.url;
 267   
       }
 268   
    }
 269   
 }
 270   
 
 271