<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package loci.multiinstanceplugin;

import java.util.Map;
import java.util.HashMap;
import java.util.UUID;
import java.lang.reflect.AnnotatedElement;
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import loci.plugin.ImageWrapper;
import loci.plugin.annotations.Input;
import loci.plugin.annotations.Output;

/**
 * The LinkedPlugin represents a given plugin in a given stage of a pipeline.
 *
 * It listens for the set of input images that is required and launches instances
 * of the plugin once that set is acquired.
 *
 * @author <NAME>
 */
public class LinkedPlugin implements ILinkedPlugin {
    PluginAnnotations m_annotations;
    IPluginLauncher m_launcher;

    /**
     * Create an instance for a given class name.
     *
     * @param className
     */
    LinkedPlugin(String className) throws PluginClassException {

        // get associated class
        Class pluginClass = null;
        try {
            pluginClass = Class.forName(className);
        }
        catch (ClassNotFoundException e) {
            // class cannot be located
            System.out.println("Can't find " + className);
        }
        catch (ExceptionInInitializerError e) {
            // initialization provoked by this method fails
            System.out.println("Error initializing " + className + " " + e.getStackTrace());
        }
        catch (LinkageError e) {
            // linkage fails
            System.out.println("Linkage error " + className + " " + e.getStackTrace());
        }

        // validate class
        boolean success = false;
        if (null != pluginClass) {
            success = true;
            
            if (!pluginClass.isAssignableFrom(AbstractPlugin.class)) {
                success = false;
                System.out.println("Plugin should extend AbstractPlugin");
            }

            if (!pluginClass.isAssignableFrom(IPlugin.class)) {
                success = false;
                System.out.println("Plugin should implement IPlugin");
            }
        }
        
        if (success) {
            init(pluginClass);
        }
        else {
            throw new PluginClassException("Plugin class is invalid " + className);
        }
    }

    /**
     * Create an instance for a given class name.
     *
     * @param className
     */
    public LinkedPlugin(Class pluginClass) {
        init(pluginClass);
    }

    /**
     * Helper function for constructors.
     *
     * @param pluginClass<commit_msg>More documentation.<commit_after>//
// LinkedPlugin.java
//

/*
Multiple instance chainable plugin framework.

Copyright (c) 2010, UW-Madison LOCI
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
  * Redistributions of source code must retain the above copyright
    notice, this list of conditions and the following disclaimer.
  * Redistributions in binary form must reproduce the above copyright
    notice, this list of conditions and the following disclaimer in the
    documentation and/or other materials provided with the distribution.
  * Neither the name of the UW-Madison LOCI nor the
    names of its contributors may be used to endorse or promote products
    derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/

package loci.multiinstanceplugin;

import java.util.Set;

import loci.plugin.ImageWrapper;
import loci.plugin.annotations.Input;
import loci.plugin.annotations.Output;

/**
 * The LinkedPlugin represents a given plugin class in a given stage of a pipeline.
 *
 * It listens for the set of input images that is required and launches instances
 * of the plugin once that set is acquired.
 *
 * @author <NAME>
 */
public class LinkedPlugin implements ILinkedPlugin {
    PluginAnnotations m_annotations;
    IPluginLauncher m_launcher;

    /**
     * Create an instance for a given class name.
     *
     * @param className
     */
    LinkedPlugin(String className) throws PluginClassException {

        // get associated class
        Class pluginClass = null;
        try {
            pluginClass = Class.forName(className);
        }
        catch (ClassNotFoundException e) {
            // class cannot be located
            System.out.println("Can't find " + className);
        }
        catch (ExceptionInInitializerError e) {
            // initialization provoked by this method fails
            System.out.println("Error initializing " + className + " " + e.getStackTrace());
        }
        catch (LinkageError e) {
            // linkage fails
            System.out.println("Linkage error " + className + " " + e.getStackTrace());
        }

        // validate class
        boolean success = false;
        if (null != pluginClass) {
            success = true;
            
            if (!pluginClass.isAssignableFrom(AbstractPlugin.class)) {
                success = false;
                System.out.println("Plugin should extend AbstractPlugin");
            }

            if (!pluginClass.isAssignableFrom(IPlugin.class)) {
                success = false;
                System.out.println("Plugin should implement IPlugin");
            }
        }
        
        if (success) {
            init(pluginClass);
        }
        else {
            throw new PluginClassException("Plugin class is invalid " + className);
        }
    }

    /**
     * Create an instance for a given class.
     *
     * @param className
     */
    public LinkedPlugin(Class pluginClass) {
        init(pluginClass);
    }

    /**
     * Helper function for constructors.
     *
     * @param pluginClass
{'fraction_non_alphanumeric': 0.07669082125603864, 'fraction_numerical': 0.0006038647342995169, 'mean_word_length': 2.3904810644831116, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4737145', 'n_tokens_mistral': 1695, 'n_tokens_neox': 1606, 'n_words': 597}