METHOD_RETURN_TYPE DocumentCopyingContextDriver::ReplaceSourceObjects(const ARGS_TYPE& args)
{
    // getting a dictionary mapping source to target object, translating to the C++ map...and on we go
	CREATE_ISOLATE_CONTEXT;
	CREATE_ESCAPABLE_SCOPE;

    DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This());
    
    if(!copyingContextDriver->CopyingContext)
    {
		THROW_EXCEPTION("copying context object not initialized, create using pdfWriter.createPDFCopyingContext or PDFWriter.createPDFCopyingContextForModifiedFile");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    if(args.Length() != 0 ||
       !args[0]->IsObject())
    {
 		THROW_EXCEPTION("Wrong arguments. provide 1 arugment, which is an object mapping source object ids to map to target object IDs");
        SET_FUNCTION_RETURN_VALUE(UNDEFINED);
    }
    
    // create an object that will serve as the map
    ObjectIDTypeToObjectIDTypeMap resultMap;
    
    Handle<Object> anObject = args[0]->ToObject();
    
    Handle<Array> objectKeys = anObject->GetOwnPropertyNames();
    
    for(unsigned long i=0; i < objectKeys->Length(); ++i)
    {
        Handle<String> key  = objectKeys->Get(NEW_NUMBER(0))->ToString();
        Handle<Value> value = anObject->Get(key);
        
        resultMap.insert(ObjectIDTypeToObjectIDTypeMap::value_type(ObjectIDTypeObject(*String::Utf8Value(key)),value->ToNumber()->Uint32Value()));
        
    }
    
    copyingContextDriver->CopyingContext->ReplaceSourceObjects(resultMap);
    
    SET_FUNCTION_RETURN_VALUE(UNDEFINED);
}
Handle<Value> DocumentCopyingContextDriver::ReplaceSourceObjects(const v8::Arguments& args)
{
    // getting a dictionary mapping source to target object, translating to the C++ map...and on we go
    HandleScope scope;
    
    DocumentCopyingContextDriver* copyingContextDriver = ObjectWrap::Unwrap<DocumentCopyingContextDriver>(args.This());
    
    if(!copyingContextDriver->CopyingContext)
    {
		ThrowException(Exception::TypeError(String::New("copying context object not initialized, create using pdfWriter.createPDFCopyingContext or PDFWriter.createPDFCopyingContextForModifiedFile")));
        return scope.Close(Undefined());
    }
    
    if(args.Length() != 0 ||
       !args[0]->IsObject())
    {
 		ThrowException(Exception::TypeError(String::New("Wrong arguments. provide 1 arugment, which is an object mapping source object ids to map to target object IDs")));
        return scope.Close(Undefined());
    }
    
    // create an object that will serve as the map
    ObjectIDTypeToObjectIDTypeMap resultMap;
    
    Handle<Object> anObject = args[0]->ToObject();
    
    Handle<Array> objectKeys = anObject->GetOwnPropertyNames();
    
    for(unsigned long i=0; i < objectKeys->Length(); ++i)
    {
        Handle<String> key  = objectKeys->Get(Number::New(0))->ToString();
        Handle<Value> value = anObject->Get(key);
        
        resultMap.insert(ObjectIDTypeToObjectIDTypeMap::value_type(ObjectIDTypeObject(*String::Utf8Value(key)),value->ToNumber()->Uint32Value()));
        
    }
    
    copyingContextDriver->CopyingContext->ReplaceSourceObjects(resultMap);
    
    return scope.Close(Undefined());
}