home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: Java / Java.zip / jload18.zip / localdir.java < prev    next >
Text File  |  2000-04-13  |  2KB  |  94 lines

  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. public class localdir
  5. {
  6.  protected String name;
  7.  protected Hashtable objects;
  8.  
  9. /**
  10.  Vytvori localdir objekt , name=lokalni adresar s / nakonci
  11. */
  12.  public localdir(String name)
  13.  {
  14.   this.name=name;
  15.   objects=new Hashtable();    
  16.   localinit();
  17.  }
  18.  
  19.  protected void localinit()
  20.  {
  21.    if(this.name==null) this.name="."+File.separator; else 
  22.      if(!this.name.endsWith(File.separator)) 
  23.          this.name=this.name+File.separator;
  24.  
  25.    File f=new File(name);
  26.    f.mkdirs();
  27.    if(!f.exists()) 
  28.     { 
  29.       /* likvidujeme up-dirs, mozna je to konflikt se souborem */
  30.       File thisdir=new File(name.substring(0,name.length()-1));
  31.       while(true)
  32.       {  
  33.         String par;
  34.         thisdir.delete();
  35.         par=thisdir.getParent();
  36.         if(par==null) break;
  37.         thisdir=new File(par);
  38.       }
  39.       /* 2nd try */
  40.       f.mkdirs();
  41.    }
  42.  }
  43.  
  44.  public localurl getObject(String Obj)
  45.  {
  46.    localurl z;
  47.    synchronized(this)
  48.    {
  49.     z=(localurl)objects.get(Obj);
  50.     if(z!=null) return z;
  51.     z=new localurl(name,Obj);
  52.     objects.put(Obj,z);
  53.    }
  54.    return z; 
  55.  } 
  56.  
  57.  public int hashCode()
  58.  {
  59.    if(name==null) return 0;
  60.    return name.hashCode();
  61.  }
  62.  
  63.  public boolean equals(Object o)
  64.  {
  65.   if(o instanceof localdir)
  66.    {
  67.     localdir ld=(localdir)o;
  68.     return name.equals(ld.name);
  69.    }
  70.    return false;
  71.  }
  72.  
  73.  public void close()
  74.  {
  75.   // System.out.println("[debug] CLosing dir "+name);
  76.   File thisdir=new File(name.substring(0,name.length()-1));
  77.   
  78.    /* likvidujeme up-dirs*/
  79.    while(thisdir.delete())
  80.     {
  81.      String par;
  82.      par=thisdir.getParent();
  83.      if(par==null) break;
  84.      thisdir=new File(par);
  85.     }
  86.  }
  87.  
  88.  public static void init(String z[])
  89.  {
  90.  
  91.  }
  92.  
  93. }
  94.