package com.blazemeter.jmeter.debugger.elements;


import com.blazemeter.jmeter.debugger.engine.DebuggerEngine;
import com.blazemeter.jmeter.debugger.engine.StepTrigger;
import org.apache.jmeter.engine.StandardJMeterEngine;
import org.apache.jmeter.testbeans.TestBean;
import org.apache.jmeter.testbeans.TestBeanHelper;
import org.apache.jmeter.testelement.AbstractTestElement;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jmeter.threads.JMeterContextService;

public abstract class AbstractDebugElement<T> extends AbstractTestElement implements Wrapper<T>, OriginalLink<T> {
    protected T wrapped;
    private T original;

    @Override
    public void setWrappedElement(T wrapped) {
        this.wrapped = wrapped;
    }

    public T getWrappedElement() {
        return wrapped;
    }

    protected StepTrigger getHook() {
        StandardJMeterEngine engine = JMeterContextService.getContext().getEngine();
        if (engine instanceof DebuggerEngine) {
            return ((DebuggerEngine) engine).getStepper();
        }
        throw new IllegalStateException();
    }

    @Override
    public void addTestElement(TestElement el) {
        if (wrapped instanceof TestElement) {
            ((TestElement) wrapped).addTestElement(el);
        }
    }

    protected void prepareBean() {
        if (wrapped instanceof TestBean) {
            //noinspection deprecation
            TestBeanHelper.prepare((TestElement) wrapped); // the deprecation reason is not sufficient
        }
    }

    @Override
    public void setOriginal(T orig) {
        original = orig;
    }

    @Override
    public T getOriginal() {
        return original;
    }
}

@@ -213,24 +213,143 @@
 eterEngine;%0A
+import org.apache.jmeter.engine.event.LoopIterationEvent;%0Aimport org.apache.jmeter.engine.event.LoopIterationListener;%0A
 import org.a
@@ -532,32 +532,92 @@
 nt.TestElement;%0A
+import org.apache.jmeter.testelement.TestIterationListener;%0A
 import org.apach
@@ -768,16 +768,62 @@
 lLink%3CT%3E
+, LoopIterationListener, TestIterationListener
  %7B%0A    p
@@ -1899,11 +1899,457 @@
 l;%0A    %7D
+%0A%0A    @Override%0A    public void iterationStart(LoopIterationEvent iterEvent) %7B%0A        if (wrapped instanceof LoopIterationListener) %7B%0A            ((LoopIterationListener) wrapped).iterationStart(iterEvent);%0A        %7D%0A    %7D%0A%0A    @Override%0A    public void testIterationStart(LoopIterationEvent event) %7B%0A        if (wrapped instanceof TestIterationListener) %7B%0A            ((TestIterationListener) wrapped).testIterationStart(event);%0A        %7D%0A    %7D
 %0A%7D%0A

Fix timers not working on continue