package hep.aida.ref;

/**
 * An object which can be stored in a tree.
 * Implementation of IManagedObject.
 *
 * @author The AIDA Team at SLAC
 *
 */
public class ManagedObject extends hep.aida.ref.event.AIDAObservable implements hep.aida.dev.IDevManagedObject {
    
    private String name;
    protected boolean fillable;

    /**
     * Creates a new instance of ManagedObject.
     * @param name The name of the ManagedObject as it will appear in the Tree.
     *
     */
    public ManagedObject(String name) {
        this.name = name;
        fillable = true;
    }

    /**
     * If ManagedObject is fillable, it can modified.
     * othervisw throws ReadOnlyException.
     */
    public void setFillable(boolean fillable) {
        this.fillable = fillable;
    }
    
    public boolean isFillable() {
        return fillable;
    }
    
    /**
     * Get the name of this ManagedObject.
     * Names can only be changed using the ITree.mv().
     * @return The name of the ManagedObject.
     *
     */ 
    public String name() {
        return name;
    }

    /**
     * Set the name of this ManagedObject.
     * @param name The new name of the ManagedObject.
     *
     */
    public void setName(String name) {
        this.name = name;
    }
    
    /**
     * Non-AIDA methods down here.
     *
     */
    
    public String getAIDAType()
    {
        Class[] interfaces = getClass().getInterfaces();
        for (int k = 0; k < interfaces.length; k++ )
        {
            if (interfaces[k].getName().startsWith("hep.aida.I") && interfaces[k] != hep.aida.IManagedObject.class ) {
                String className = interfaces[k].getName();
                return className.substring( className.lastIndexOf(".")+1 );
            }
        }
        return "IUnknown";
    }
}
    
    