FileDocCategorySizeDatePackage
PopulationManager.javaAPI DocGlassfish v2 API9880Tue May 22 16:54:54 BST 2007oracle.toplink.essentials.tools.schemaframework

PopulationManager

public class PopulationManager extends Object

Purpose: This class is used to populate example data into the database, it allows for cirrcular references to be resolved.

Responsibilities:

  • Allow objects to be registered.
  • Allow objects to be looked up.
  • Store a globally accessable default instance.

Fields Summary
protected Hashtable
registeredObjects
Store the objects registered.
protected static PopulationManager
defaultManager
Store the default instance.
Constructors Summary
public PopulationManager()

        registeredObjects = new Hashtable();
    
Methods Summary
public voidaddAllObjectsForAbstractClass(java.lang.Class objectsClass, oracle.toplink.essentials.internal.sessions.AbstractSession session, java.util.Vector allObjects)
Add all of the objects of the class and all of its subclasses. The session is needed because there is no other way to find all subclasses.

        ClassDescriptor descriptor = session.getDescriptor(objectsClass);
        addAllObjectsForClass(objectsClass, allObjects);
        for (Enumeration enumeration = descriptor.getInheritancePolicy().getChildDescriptors().elements();
                 enumeration.hasMoreElements();) {
            addAllObjectsForAbstractClass(((ClassDescriptor)enumeration.nextElement()).getJavaClass(), session, allObjects);
        }
    
public voidaddAllObjectsForAbstractClass(java.lang.Class objectsClass, oracle.toplink.essentials.sessions.Session session, java.util.Vector allObjects)
Add all of the objects of the class and all of its subclasses. The session is needed because there is no other way to find all subclasses.

        addAllObjectsForAbstractClass(objectsClass, (AbstractSession)session, allObjects);
    
public voidaddAllObjectsForClass(java.lang.Class objectsClass, java.util.Vector allObjects)
Add all of the objects of the class.

        if (!getRegisteredObjects().containsKey(objectsClass)) {
            return;
        }

        for (Enumeration enumeration = ((Hashtable)getRegisteredObjects().get(objectsClass)).elements();
                 enumeration.hasMoreElements();) {
            allObjects.addElement(enumeration.nextElement());
        }
    
public booleancontainsObject(java.lang.Class objectsClass, java.lang.String objectsName)
Check if the object is registred given its name.

        return ((getRegisteredObjects().containsKey(objectsClass)) && (((Hashtable)getRegisteredObjects().get(objectsClass)).containsKey(objectsName)));
    
public booleancontainsObject(java.lang.Object objectToCheck, java.lang.String objectsName)
Check if the object is registred given its name.

        return containsObject(objectToCheck.getClass(), objectsName);
    
public java.util.VectorgetAllClasses()
Return all of the objects registered.

        Vector allClasses = new Vector();

        for (Enumeration e = getRegisteredObjects().keys(); e.hasMoreElements();) {
            allClasses.addElement(e.nextElement());
        }

        return allClasses;
    
public java.util.VectorgetAllObjects()
Return all of the objects registered.

        Vector allObjects;

        allObjects = new Vector();
        for (Enumeration e = getAllClasses().elements(); e.hasMoreElements();) {
            Class eachClass = (Class)e.nextElement();
            addAllObjectsForClass(eachClass, allObjects);
        }

        return allObjects;
    
public java.util.VectorgetAllObjectsForAbstractClass(java.lang.Class objectsClass, oracle.toplink.essentials.internal.sessions.AbstractSession session)
Return all of the objects of the class and all of its subclasses. The session is needed because there is no other way to find all subclasses.

        ClassDescriptor descriptor = session.getDescriptor(objectsClass);
        Vector allObjects = new Vector();
        addAllObjectsForClass(objectsClass, allObjects);
        if (descriptor.hasInheritance()) {
            for (Enumeration enumeration = descriptor.getInheritancePolicy().getChildDescriptors().elements();
                     enumeration.hasMoreElements();) {
                addAllObjectsForClass(((ClassDescriptor)enumeration.nextElement()).getJavaClass(), allObjects);
            }
        }

        return allObjects;
    
public java.util.VectorgetAllObjectsForAbstractClass(java.lang.Class objectsClass)
Return all of the objects of the class and all of its subclasses.

        Vector allObjects;

        allObjects = new Vector();
        // hummm, how can this be done....
        return allObjects;
    
public java.util.VectorgetAllObjectsForClass(java.lang.Class objectsClass)
Return all of the objects of the class.

        Vector allObjects;

        allObjects = new Vector();
        addAllObjectsForClass(objectsClass, allObjects);

        return allObjects;
    
public static oracle.toplink.essentials.tools.schemaframework.PopulationManagergetDefaultManager()
Lazy initialize the default instance.

        if (defaultManager == null) {
            defaultManager = new PopulationManager();
        }
        return defaultManager;
    
public java.lang.ObjectgetObject(java.lang.Class objectsClass, java.lang.String objectsName)
Return the object registred given its name.

        if (!(getRegisteredObjects().containsKey(objectsClass))) {
            return null;
        }

        return ((Hashtable)getRegisteredObjects().get(objectsClass)).get(objectsName);
    
public java.util.HashtablegetRegisteredObjects()
Return the registered objects.

        return registeredObjects;
    
public java.lang.ObjectregisterObject(java.lang.Class javaClass, java.lang.Object objectToRegister, java.lang.String objectsName)
Register the object given its name. The objects are represented as a hashtable of hashtables, lazy initialized on the class.

        if (!(getRegisteredObjects().containsKey(javaClass))) {
            getRegisteredObjects().put(javaClass, new Hashtable());
        }
        ((Hashtable)getRegisteredObjects().get(javaClass)).put(objectsName, objectToRegister);

        return objectToRegister;
    
public java.lang.ObjectregisterObject(java.lang.Object objectToRegister, java.lang.String objectsName)
Register the object given its name. The objects are represented as a hashtable of hashtables, lazy initialized on the class.

        if (!(getRegisteredObjects().containsKey(objectToRegister.getClass()))) {
            getRegisteredObjects().put(objectToRegister.getClass(), new Hashtable());
        }
        ((Hashtable)getRegisteredObjects().get(objectToRegister.getClass())).put(objectsName, objectToRegister);

        return objectToRegister;
    
public voidremoveObject(java.lang.Class classToRemove, java.lang.String objectsName)
Remove the object given its class and name.

        if (getRegisteredObjects().containsKey(classToRemove)) {
            ((Hashtable)getRegisteredObjects().get(classToRemove)).remove(objectsName);
        }
    
public java.lang.ObjectremoveObject(java.lang.Object objectToRemove, java.lang.String objectsName)
Remove the object given its name.

        removeObject(objectToRemove.getClass(), objectsName);

        return objectToRemove;
    
public static voidresetDefaultManager()
Reset the default instance.

        defaultManager = null;
    
public static voidsetDefaultManager(oracle.toplink.essentials.tools.schemaframework.PopulationManager theDefaultManager)
Set the default instance.

        defaultManager = theDefaultManager;
    
public voidsetRegisteredObjects(java.util.Hashtable registeredObjects)
Set the registered objects.

        this.registeredObjects = registeredObjects;