/*
 * Copyright (c) 2012 Mateusz Parzonka, Eric Bodden
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 * Mateusz Parzonka - initial API and implementation
 */
package prm4j.api;


public abstract class MatchHandler {

    /**
     * This {@link MatchHandler} does nothing.
     */
    public final static MatchHandler NO_OP = new MatchHandler0() {
	@Override
	public void handleMatch(Object auxiliaryData) {
	}
    };

    /**
     * Retrieve bound objects with getBoundObject(...) TODO doc method.
     *
     * @param bindings
     */
    public abstract void handleMatch(Binding[] bindings, Object auxiliaryData);

    /**
     * Retrieves the object which was stored in the monitor bindings. The object may be <code>null</code> if selected
     * object was already garbage collected in the monitored application.
     *
     * @param param
     *            selects the object from the bindings
     * @param bindings
     *            current bindings when the match was completed
     * @return the object which was bound to the given parameter. <code>null</code>, if the object was already garbage
     *         collected.
     */
    protected <P> P getBoundObject(Parameter<P> param, Binding[] bindings) {
	// matches are rare, so we simply search the bindings linearly
	for (Binding binding : bindings) {
	    if (binding != null && binding.getParameterIndex() == param.getIndex()) {
		@SuppressWarnings("unchecked")
		P boundObject = (P) binding.get();
		return boundObject;
	    }
	}
	throw new IllegalArgumentException("Bound object for parameter ["
		+ "] coult not be retrieved from the bindings!");
    }

}

@@ -631,16 +631,296 @@
     %7D;%0A%0A
+    /**%0A     * This %7B@link MatchHandler%7D prints on match to the standard output stream.%0A     */%0A    public final static MatchHandler SYS_OUT = new MatchHandler0() %7B%0A%09@Override%0A%09public void handleMatch(Object auxiliaryData) %7B%0A%09    System.out.println(%22Match detected!%22);%0A%09%7D%0A    %7D;%0A%0A
     /**%0A

Add static 'SYS_OUT' MatchHandler printing to standard out