ACSErr::Completion *ErrorComponent::completionFromCompletion(CORBA::Short depth) 
{
        ACS_TRACE("ErrorComponent::completionFromCompletion");
        CompletionImpl *comp;
        if(depth==1){
                ACSErrTypeCommon::GenericErrorCompletion *erg =
                        new ACSErrTypeCommon::GenericErrorCompletion(
                                        __FILE__, __LINE__,
                                        "ErrorComponent::completionFromCompletion");
                erg->setErrorDesc("Put an error trace in completionFromCompletion(depth 1, so not generated from another completion)");
                comp = erg;


        }
        else{
                comp = createCompletion(depth>0?depth-1:0);

                // if comp does not conatin error (=is error free) we return it 
                // otherwise we create a new completion which takes the error trace from a completion comp.
                if (!comp->isErrorFree())
                {
                        // comp is deleted inside the constructor
                        ACSErrTypeCommon::GenericErrorCompletion *erg = 
                                new ACSErrTypeCommon::GenericErrorCompletion(comp, 
                                                __FILE__, __LINE__, 
                                                "ErrorComponent::completionFromCompletion");
                        erg->setErrorDesc("Put an error trace in completionFromCompletion");
                        comp = erg;
                }//if
        }
        return comp->returnCompletion();
}//completionFromCompletion
/* ----------------------------------------------------------------*/
ACSErr::Completion *ErrorComponent::completionFromException(CORBA::Short depth) 
{
    ACS_TRACE("::ErrorComponent::completionFromException");
    // here we get LOCAL (C++) completion 
    CompletionImpl *er = createCompletion(depth);

    // returnCompletion() automatically deletes er
    //   NOTE: you can use returnCompletion() 
    //   just if completion is allocated on the heap. 
    //   If completion is allocated on the stack
    //   returnCompletion(false) has to be used. 
    return er->returnCompletion();
}//completionFromException
        ACSErr::Completion *ErrorComponent::completionOnStack(CORBA::Short depth) 
{
    ACS_TRACE("::ErrorComponent::completionOnStack");

    // here we get LOCAL (C++) completion 
    CompletionImpl *comp = createCompletion(depth);
    

    // if comp does not contain error (=is error free) we return it 
    // otherwise we create a new completion which takes the error trace from a completion comp.
    if (comp->isErrorFree())
	{
	// memory for comp is released in the call 
	return comp->returnCompletion();
	}
    else
	{
	// The constructor takes care for the memory manamgent 
	// for the passed completion or exception.
	// If a completion or an exception is passed as pointer the constructor assumes that
        // completion was created on the heap and thus it deletes it afterwards,
	// so it MUST NOT be deleted by the user !
	// If a completion or an exception is passed as an object (or reference to it) 
	// the constructor assumes that the it was created on the stack 
	// and thus it does not delete it.
        //
        // NOTE: do not pass a pointer of a completion or an exception 
	// which was created on the stack !! In this case just send the completion object.
	ACSErrTypeCommon::GenericErrorCompletion erg(comp, 
						     __FILE__, __LINE__, 
						     "ErrorComponent::completionOnStack");
	erg.setErrorDesc("Put an error trace in completionOnStack");
	return erg.returnCompletion(false); 
        // With false flag we tell returnCompletion() 
	// not to delete its object
	// since it is automatically deleted when we go out of scope
	}//if
}//completionOnStack