// 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:   DefaultEntryTypesIdentifier.java

package com.symantec.itools.lang.classpath;

import com.symantec.itools.io.Directory;
import com.symantec.itools.io.FileSystem;
import com.symantec.itools.util.Properties;
import com.symantec.itools.util.StringTokenizer;
import java.io.File;
import java.io.IOException;

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

public class DefaultEntryTypesIdentifier
    implements ClasspathEntryTypesIdentifier
{

    protected DefaultEntryTypesIdentifier()
    {
    }

    public boolean isBootEntry(ClasspathEntry classpathentry)
    {
        if(bootClasspath != null)
            return isBootEntryReal(classpathentry);
        else
            return isBootEntryFake(classpathentry);
    }

    public boolean isExtensionEntry(ClasspathEntry classpathentry)
    {
        if(extensionClasspath != null)
            return isExtensionEntryReal(classpathentry);
        else
            return isExtensionEntryFake(classpathentry);
    }

    public boolean isApplicationEntry(ClasspathEntry classpathentry)
    {
        if(bootClasspath != null)
            return isApplicationEntryReal(classpathentry);
        else
            return isApplicationEntryFake(classpathentry);
    }

    protected boolean isBootEntryReal(ClasspathEntry classpathentry)
    {
        return findName(classpathentry.getName(), bootClasspathNames);
    }

    protected boolean isBootEntryFake(ClasspathEntry classpathentry)
    {
        boolean flag = false;
        for(int i = 0; i < fakeBootClassNames.length; i++)
        {
            if(!classpathentry.find(fakeBootClassNames[i]))
                continue;
            flag = true;
            break;
        }

        return flag;
    }

    protected boolean isExtensionEntryReal(ClasspathEntry classpathentry)
    {
        return findName(classpathentry.getName(), extensionClasspathNames);
    }

    protected boolean isExtensionEntryFake(ClasspathEntry classpathentry)
    {
        boolean flag = false;
        for(int i = 0; i < fakeExtClassNames.length; i++)
        {
            if(!classpathentry.find(fakeExtClassNames[i]))
                continue;
            flag = true;
            break;
        }

        return flag;
    }

    protected boolean isApplicationEntryReal(ClasspathEntry classpathentry)
    {
        return findName(classpathentry.getName(), applicationClasspathNames);
    }

    protected boolean isApplicationEntryFake(ClasspathEntry classpathentry)
    {
        if(isBootEntry(classpathentry))
            return false;
        else
            return isExtensionEntry(classpathentry);
    }

    protected boolean findName(String s, String as[])
    {
        for(int i = 0; i < as.length; i++)
            if(FileSystem.compareFilenames(s, as[i]))
                return true;

        return false;
    }

    private static String[] getNames(String s)
    {
        if(s == null)
            return null;
        StringTokenizer stringtokenizer = new StringTokenizer(s, File.pathSeparator);
        String as[] = stringtokenizer.getTokens();
        for(int i = 0; i < as.length; i++)
            as[i] = FileSystem.getCanonicalPath(as[i], true);

        if(as.length == 0)
            as = null;
        return as;
    }

    protected static final String bootClasspath = System.getProperty("sun.boot.class.path");
    protected static final String extensionClasspath;
    protected static final String applicationClasspath = System.getProperty("java.class.path");
    protected static final String bootClasspathNames[] = getNames(bootClasspath);
    protected static final String extensionClasspathNames[];
    protected static final String applicationClasspathNames[] = getNames(applicationClasspath);
    protected static final String fakeBootClassNames[];
    protected static final String fakeExtClassNames[];

    static 
    {
        Object obj = System.getProperty("java.ext.dirs");
        String s;
        String as1[];
        if(obj != null)
        {
            try
            {
                as1 = (new Directory(((String) (obj)))).list(false);
                StringBuffer stringbuffer = new StringBuffer();
                for(int i = 0; i < as1.length; i++)
                {
                    stringbuffer.append(as1[i]);
                    stringbuffer.append(File.pathSeparator);
                }

                s = stringbuffer.toString();
                if(s == null)
                    s = "";
            }
            catch(IOException _ex)
            {
                as1 = null;
                s = null;
            }
        } else
        {
            as1 = null;
            s = null;
        }
        extensionClasspathNames = as1;
        extensionClasspath = s;
        try
        {
            obj = new Properties("/com/symantec/itools/lang/classpath/DefaultEntryTypes.properties");
        }
        catch(Throwable throwable)
        {
            throwable.printStackTrace();
            obj = new Properties();
        }
        String as[];
        try
        {
            as = ((Properties) (obj)).getStringList("bootnames", new String[] {
                "java.lang.Object.class"
            });
        }
        catch(Throwable _ex)
        {
            as = (new String[] {
                "java.lang.Object.class"
            });
        }
        fakeBootClassNames = as;
        try
        {
            as = ((Properties) (obj)).getStringList("extnames", new String[] {
                ""
            });
        }
        catch(Throwable _ex)
        {
            as = new String[0];
        }
        if(as.length == 1 && as[0].equals(""))
            as = new String[0];
        fakeExtClassNames = as;
    }
}
