with Log;  
with Cmvc;
with Profile;
with Library;
with Object_Info;
package body Object_Operations is

    procedure Unprotect (This_Object : in Directory_Tools.Object.Handle;
                         Response : in String := "<PROFILE>") is
        --
        Old_Response_Profile : Profile.Response_Profile := Profile.Get;
        New_Response_Profile : Profile.Response_Profile :=
           Profile.Value (Response);
        --
        Object_Name : constant String :=
           Directory_Tools.Naming.Full_Name (This_Object);
        --
    begin
        --
        Profile.Set (New_Response_Profile);
        Log.Put_Line ("[Unprotect, This_Object => """ & Object_Name &
                      """, Response => """ & Response & """]",
                      Profile.Auxiliary_Msg);
        if (Object_Info.Any.Is_Good (This_Object)) then
            if (Object_Info.Any.Is_Frozen (This_Object)) then
                Library.Unfreeze (Existing => Object_Name,
                                  Response => Response);
            end if;  
            if (Object_Info.Cmvc.Is_Controlled (This_Object)) then
                if (Object_Info.Cmvc.Is_Checked_Out (This_Object)) then
                    Cmvc.Check_In (What_Object => Object_Name,
                                   Response => Response);
                end if;
                Cmvc.Check_Out (What_Object => Object_Name,
                                Response => Response);
            end if;
        end if;
        Log.Put_Line ("[end of Unprotect operation--no error(s) detected]");
        Profile.Set (Old_Response_Profile);
        --
    exception
        when others =>
            Log.Put_Line ("[end of Unprotect operation--error(s) detected]");
            Profile.Set (Old_Response_Profile);
            raise;
            --
    end Unprotect;

    procedure Protect (This_Object : in Directory_Tools.Object.Handle;
                       Response : in String := "<PROFILE>") is
        --
        Old_Response_Profile : Profile.Response_Profile := Profile.Get;
        New_Response_Profile : Profile.Response_Profile :=
           Profile.Value (Response);
        --
        Object_Name : constant String :=
           Directory_Tools.Naming.Full_Name (This_Object);
        --
    begin
        --
        Profile.Set (New_Response_Profile);
        Log.Put_Line ("[Protect, This_Object => """ & Object_Name &
                      """, Response => """ & Response & """]",
                      Profile.Auxiliary_Msg);
        if (Object_Info.Any.Is_Good (This_Object)) then
            if (Object_Info.Any.Is_Contained_By_Units_Directory_Of_View
                   (This_Object)) then
                if (not Object_Info.Cmvc.Is_Controlled (This_Object)) then
                    Cmvc.Make_Controlled (Object_Name, Response => Response);
                end if;
                if (Object_Info.Cmvc.Is_Checked_Out (This_Object)) then
                    Cmvc.Check_In (Object_Name, Response => Response);
                end if;
            end if;
            if (not Object_Info.Any.Is_Frozen (This_Object)) then
                Library.Freeze (Object_Name, Response => Response);
            end if;
        end if;
        Log.Put_Line ("[end of Protect operation--no error(s) detected]");
        Profile.Set (Old_Response_Profile);
        --
    exception
        when others =>
            Log.Put_Line ("[end of Protect operation--error(s) detected]");
            Profile.Set (Old_Response_Profile);
            raise;
            --
    end Protect;

end Object_Operations;