// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) deadcode 
// Source File Name:   ClasspathEntry.java

package com.symantec.itools.lang.classpath;

import com.symantec.itools.lang.Debug;
import java.io.*;
import java.util.Hashtable;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

// Referenced classes of package com.symantec.itools.lang.classpath:
//            ClasspathElement, ClasspathEntryTypesIdentifier

public class ClasspathEntry
{

    static ClasspathEntry create(String s, int i)
    {
        ClasspathEntry classpathentry = null;
        if(i == 0 || i == 1)
        {
            classpathentry = (ClasspathEntry)pool.get(s);
            if(classpathentry == null)
                if(i == 0)
                {
                    classpathentry = new ClasspathEntry(s, true);
                    pool.put(s, classpathentry);
                } else
                {
                    classpathentry = new ClasspathEntry(s, false);
                }
        } else
        {
            classpathentry = new ClasspathEntry(s, false);
        }
        return classpathentry;
    }

    protected ClasspathEntry(String s, boolean flag)
    {
        type = 0;
        File file = new File(s);
        isFile = file.isFile();
        name = s;
        isFlyWeight = flag;
    }

    protected ZipFile getZipFile(String s)
        throws IOException
    {
        ZipFile zipfile = null;
        if(isFlyWeight)
        {
            if(zipFile == null)
                zipFile = new ZipFile(s);
            zipfile = zipFile;
        } else
        {
            zipfile = new ZipFile(s);
        }
        return zipfile;
    }

    public String getName()
    {
        return name;
    }

    public boolean isFile()
    {
        return isFile;
    }

    public boolean isDirectory()
    {
        return !isFile;
    }

    public int getType()
    {
        return type;
    }

    public int setType(ClasspathEntryTypesIdentifier classpathentrytypesidentifier)
    {
        if(classpathentrytypesidentifier.isBootEntry(this))
            type = 1;
        else
        if(classpathentrytypesidentifier.isExtensionEntry(this))
            type = 2;
        else
            type = 3;
        return type;
    }

    public boolean isBootEntry()
    {
        return type == 1;
    }

    public boolean isExtensionEntry()
    {
        return type == 2;
    }

    public boolean isApplicationEntry()
    {
        return type == 3;
    }

    public boolean equals(Object obj)
    {
        if(obj instanceof ClasspathEntry)
            return ((ClasspathEntry)obj).name.equals(name);
        else
            return false;
    }

    public int hashCode()
    {
        return name.hashCode();
    }

    public String toString()
    {
        return name + " " + (isFile ? "file" : "directory");
    }

    public boolean find(String s)
    {
        if(isFile)
        {
            boolean flag = false;
            ZipFile zipfile = null;
            try
            {
                zipfile = getZipFile(name);
                flag = zipfile.getEntry(s) != null;
            }
            catch(IOException ioexception)
            {
                ioexception.printStackTrace();
            }
            finally
            {
                if(zipfile != null && !isFlyWeight)
                    try
                    {
                        zipfile.close();
                    }
                    catch(IOException _ex) { }
            }
            return flag;
        } else
        {
            return (new File(name + File.separatorChar + s.replace('/', File.separatorChar))).exists();
        }
    }

    public InputStream getInputStream(String s)
    {
        try
        {
            if(isFile)
            {
                ZipFile zipfile = getZipFile(name);
                ZipEntry zipentry = zipfile.getEntry(s);
                return zipfile.getInputStream(zipentry);
            } else
            {
                return new FileInputStream(name + File.separatorChar + s.replace('/', File.separatorChar));
            }
        }
        catch(IOException _ex)
        {
            return null;
        }
    }

    public ClasspathElement findElement(String s)
    {
        ClasspathElement classpathelement = null;
        if(isFile)
        {
            try
            {
                ZipFile zipfile = getZipFile(name);
                ZipEntry zipentry = zipfile.getEntry(s);
                long l = zipentry.getTime();
                int i = (int)zipentry.getSize();
                classpathelement = new ClasspathElement(l, i);
                if(!isFlyWeight)
                    zipfile.close();
            }
            catch(IOException ioexception)
            {
                Debug.logException(ioexception);
                ioexception.printStackTrace();
            }
        } else
        {
            File file = new File(name + File.separatorChar + s.replace('/', File.separatorChar));
            long l1 = file.lastModified();
            int j = (int)file.length();
            classpathelement = new ClasspathElement(l1, j);
        }
        return classpathelement;
    }

    public static final int TYPEUNKNOWN = 0;
    public static final int TYPEBOOT = 1;
    public static final int TYPEEXT = 2;
    public static final int TYPEAPP = 3;
    public static final int ALLFLYWEIGHT = 0;
    public static final int NEWNOTFLYWEIGHT = 1;
    public static final int NOFLYWEIGHT = 2;
    protected static final Hashtable pool = new Hashtable();
    protected boolean isFile;
    protected String name;
    protected int type;
    protected boolean isFlyWeight;
    protected ZipFile zipFile;

}
