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

package hep.rootio.implementation;

import hep.rootio.*;

import java.io.IOException;
import java.io.InputStream;
import java.util.*;

// Referenced classes of package hep.rootio.implementation:
//            StreamerInfoString, SpecificRootClass, GenericRootClass

public class DefaultClassFactory
    implements RootClassFactory
{

    public DefaultClassFactory(RootFileReader rfr)
    {
        classMap = new Hashtable();
        try
        {
            Properties typedef = new Properties();
            InputStream in = getClass().getResourceAsStream("Typedef.properties");
            typedef.load(in);
            in.close();
            Properties streamerInfo = new Properties();
            in = getClass().getResourceAsStream("StreamerInfo.properties");
            streamerInfo.load(in);
            in.close();
            String classPackages[] = {
                "hep.rootio.reps"
            };
            init(typedef, streamerInfo, classPackages, rfr);
        }
        catch(IOException ioexception)
        {
            throw new RuntimeException("Unable to load default properties");
        }
    }

    private void init(Properties typedef, Properties streamerInfo, String packageList[], RootFileReader rfr)
    {
        this.packageList = packageList;
        try
        {
            Object key;
            Class intrinsic;
            for(Enumeration e = typedef.keys(); e.hasMoreElements(); classMap.put(key, intrinsic.newInstance()))
            {
                key = e.nextElement();
                Object value = typedef.get(key);
                intrinsic = Class.forName("hep.rootio.implementation." + value);
                if(!(hep.rootio.implementation.IntrinsicRootClass.class).isAssignableFrom(intrinsic))
                    throw new RuntimeException("Typedef class is not an intrinsic: " + value);
            }

        }
        catch(Exception exception)
        {
            throw new RuntimeException("Error interpreting typedef table");
        }
        try
        {
            for(Enumeration e = streamerInfo.keys(); e.hasMoreElements();)
            {
                String key = (String)e.nextElement();
                Object value = streamerInfo.get(key);
                StreamerInfo info = new StreamerInfoString((String)value);
                Class c = findClass(key);
                if(c != null)
                    classMap.put(key, new SpecificRootClass(c, key, info, rfr));
                else
                    classMap.put(key, new GenericRootClass(key, info, rfr));
            }

        }
        catch(Exception exception1)
        {
            throw new RuntimeException("Error interpreting typedef table");
        }
        try
        {
            RootClass info;
            for(Enumeration e = classMap.elements(); e.hasMoreElements(); info.resolve(this))
                info = (RootClass)e.nextElement();

        }
        catch(RootClassNotFound x)
        {
            throw new RuntimeException("Could not resolve class " + x.getClassName());
        }
    }

    public RootClass create(String name)
        throws RootClassNotFound
    {
        RootClass result = (RootClass)classMap.get(name);
        if(result != null)
            return result;
        else
            throw new RootClassNotFound(name);
    }

    Class findClass(String name)
    {
        for(int i = 0; i < packageList.length;)
            try
            {
                return Class.forName(packageList[i] + "." + name);
            }
            catch(Exception exception)
            {
                i++;
            }

        return null;
    }

    private Hashtable classMap;
    private String packageList[];
    private RootFileReader rfr;
}

 

Ads help maintain this website.