while (flag) {
            data = atomicInteger.incrementAndGet() + "";
            retValue = blockingQueue.offer(data, 2, TimeUnit.SECONDS);
            if (retValue) {
                System.out.println(Thread.currentThread().getName() + "\t插入队列" + data + "成功");
            } else {
                System.out.println(Thread.currentThread().getName() + "\t插入队列" + data + "失败");
            }
            TimeUnit.SECONDS.sleep(1);
        }

package com.jian8.juc.queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class ProdConsumer_BlockQueueDemo {

    public static void main(String[] args) {
        MyResource myResource = new MyResource(new ArrayBlockingQueue<>(10));
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t生产线程启动");
            try {
                myResource.myProd();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "Prod").start();
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t消费线程启动");
            try {
                myResource.myConsumer();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "Consumer").start();
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("5s后main叫停，线程结束");
        try {
            myResource.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class MyResource {

    // 默认开启，进行生产+消费
    private volatile boolean flag = true;

    private AtomicInteger atomicInteger = new AtomicInteger();

    BlockingQueue<String> blockingQueue = null;

    public MyResource(BlockingQueue<String> blockingQueue) {
        this.blockingQueue = blockingQueue;
        System.out.println(blockingQueue.getClass().getName());
    }

    public void myProd() throws Exception {
        String data = null;
        boolean retValue;

        System.out.println(Thread.currentThread().getName() + "\t大老板叫停了，flag=false，生产结束");
    }

    public void myConsumer() throws Exception {
        String result = null;
        while (flag) {
            result = blockingQueue.poll(2, TimeUnit.SECONDS);
            if (null == result || result.equalsIgnoreCase("")) {
                flag = false;
                System.out.println(Thread.currentThread().getName() + "\t超过2s没有取到蛋糕，消费退出");
                System.out.println();
                return;
            }
            System.out.println(Thread.currentThread().getName() + "\t消费队列" + result + "成功");
        }
    }

    public void stop() throws Exception {
        flag = false;
    }
}


try {
                myResource.myConsumer();
            } catch (Exception e) {
                e.printStackTrace();
            }

package com.jian8.juc.queue;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

public class ProdConsumer_BlockQueueDemo {

    public static void main(String[] args) {
        MyResource myResource = new MyResource(new ArrayBlockingQueue<>(10));
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t生产线程启动");
            try {
                myResource.myProd();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "Prod").start();
        new Thread(() -> {
            System.out.println(Thread.currentThread().getName() + "\t消费线程启动");

        }, "Consumer").start();
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("5s后main叫停，线程结束");
        try {
            myResource.stop();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

class MyResource {

    // 默认开启，进行生产+消费
    private volatile boolean flag = true;

    private AtomicInteger atomicInteger = new AtomicInteger();

    BlockingQueue<String> blockingQueue = null;

    public MyResource(BlockingQueue<String> blockingQueue) {
        this.blockingQueue = blockingQueue;
        System.out.println(blockingQueue.getClass().getName());
    }

    public void myProd() throws Exception {
        String data = null;
        boolean retValue;
        while (flag) {
            data = atomicInteger.incrementAndGet() + "";
            retValue = blockingQueue.offer(data, 2, TimeUnit.SECONDS);
            if (retValue) {
                System.out.println(Thread.currentThread().getName() + "\t插入队列" + data + "成功");
            } else {
                System.out.println(Thread.currentThread().getName() + "\t插入队列" + data + "失败");
            }
            TimeUnit.SECONDS.sleep(1);
        }
        System.out.println(Thread.currentThread().getName() + "\t大老板叫停了，flag=false，生产结束");
    }

    public void myConsumer() throws Exception {
        String result = null;
        while (flag) {
            result = blockingQueue.poll(2, TimeUnit.SECONDS);
            if (null == result || result.equalsIgnoreCase("")) {
                flag = false;
                System.out.println(Thread.currentThread().getName() + "\t超过2s没有取到蛋糕，消费退出");
                System.out.println();
                return;
            }
            System.out.println(Thread.currentThread().getName() + "\t消费队列" + result + "成功");
        }
    }

    public void stop() throws Exception {
        flag = false;
    }
}


public Input waitForAnyInputReady(Collection<Input> inputs) throws InterruptedException;

package org.apache.tez.runtime.api;

import java.io.IOException;
import java.util.Collection;
import javax.annotation.Nullable;

/**
 * Context handle for the Processor to initialize itself.
 */
public interface TezProcessorContext extends TezTaskContext {

    /**
     * Set the overall progress of this Task Attempt
     * @param progress Progress in the range from [0.0 - 1.0f]
     */
    public void setProgress(float progress);

    /**
     * Check whether this attempt can commit its output
     * @return true if commit allowed
     * @throws IOException
     */
    public boolean canCommit() throws IOException;

    /**
     * Blocking call which returns when any of the specified Inputs is ready for
     * consumption.
     *
     * There can be multiple parallel invocations of this function - where each
     * invocation blocks on the Inputs that it specifies.
     *
     * If multiple Inputs are ready, any one of them may be returned by this
     * method - including an Input which may have been returned in a previous
     * call. If invoking this method multiple times, it's recommended to remove
     * previously completed Inputs from the invocation list.
     *
     * @param inputs
     *          the list of Inputs to monitor
     * @return the Input which is ready for consumption
     * @throws InterruptedException
     */

    /**
     * Blocking call which returns only after all of the specified Inputs are
     * ready for consumption.
     *
     * There can be multiple parallel invocations of this function - where each
     * invocation blocks on the Inputs that it specifies.
     *
     * @param inputs
     *          the list of Inputs to monitor
     * @throws InterruptedException
     */
    public void waitForAllInputsReady(Collection<Input> inputs) throws InterruptedException;
}


static ModelIteratorInternal instanceFor(WrapIModelIterator data)

package agent.dbgmodel.impl.dbgmodel.main;

import java.util.Map;
import com.google.common.collect.ImmutableMap;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Guid.REFIID;
import agent.dbgmodel.dbgmodel.main.ModelIterator;
import agent.dbgmodel.impl.dbgmodel.DbgModelUtil;
import agent.dbgmodel.impl.dbgmodel.DbgModelUtil.InterfaceSupplier;
import agent.dbgmodel.jna.dbgmodel.main.IModelIterator;
import agent.dbgmodel.jna.dbgmodel.main.WrapIModelIterator;
import ghidra.util.datastruct.WeakValueHashMap;

public interface ModelIteratorInternal extends ModelIterator {

    Map<Pointer, ModelIteratorInternal> CACHE = new WeakValueHashMap<>();

{
        return DbgModelUtil.lazyWeakCache(CACHE, data, ModelIteratorImpl::new);
    }

    ImmutableMap.Builder<REFIID, Class<? extends WrapIModelIterator>> PREFERRED_DATA_SPACES_IIDS_BUILDER = ImmutableMap.builder();

    Map<REFIID, Class<? extends WrapIModelIterator>> PREFERRED_DATA_SPACES_IIDS = PREFERRED_DATA_SPACES_IIDS_BUILDER.put(new REFIID(IModelIterator.IID_IMODEL_ITERATOR), WrapIModelIterator.class).build();

    static ModelIteratorInternal tryPreferredInterfaces(InterfaceSupplier supplier) {
        return DbgModelUtil.tryPreferredInterfaces(ModelIteratorInternal.class, PREFERRED_DATA_SPACES_IIDS, supplier);
    }
}


{
        return DbgModelUtil.lazyWeakCache(CACHE, data, ModelIteratorImpl::new);
    }

package agent.dbgmodel.impl.dbgmodel.main;

import java.util.Map;
import com.google.common.collect.ImmutableMap;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Guid.REFIID;
import agent.dbgmodel.dbgmodel.main.ModelIterator;
import agent.dbgmodel.impl.dbgmodel.DbgModelUtil;
import agent.dbgmodel.impl.dbgmodel.DbgModelUtil.InterfaceSupplier;
import agent.dbgmodel.jna.dbgmodel.main.IModelIterator;
import agent.dbgmodel.jna.dbgmodel.main.WrapIModelIterator;
import ghidra.util.datastruct.WeakValueHashMap;

public interface ModelIteratorInternal extends ModelIterator {

    Map<Pointer, ModelIteratorInternal> CACHE = new WeakValueHashMap<>();

    static ModelIteratorInternal instanceFor(WrapIModelIterator data)

    ImmutableMap.Builder<REFIID, Class<? extends WrapIModelIterator>> PREFERRED_DATA_SPACES_IIDS_BUILDER = ImmutableMap.builder();

    Map<REFIID, Class<? extends WrapIModelIterator>> PREFERRED_DATA_SPACES_IIDS = PREFERRED_DATA_SPACES_IIDS_BUILDER.put(new REFIID(IModelIterator.IID_IMODEL_ITERATOR), WrapIModelIterator.class).build();

    static ModelIteratorInternal tryPreferredInterfaces(InterfaceSupplier supplier) {
        return DbgModelUtil.tryPreferredInterfaces(ModelIteratorInternal.class, PREFERRED_DATA_SPACES_IIDS, supplier);
    }
}


package agent.dbgmodel.impl.dbgmodel.main;

import java.util.Map;
import com.google.common.collect.ImmutableMap;
import com.sun.jna.Pointer;
import com.sun.jna.platform.win32.Guid.REFIID;
import agent.dbgmodel.dbgmodel.main.ModelIterator;
import agent.dbgmodel.impl.dbgmodel.DbgModelUtil;
import agent.dbgmodel.impl.dbgmodel.DbgModelUtil.InterfaceSupplier;
import agent.dbgmodel.jna.dbgmodel.main.IModelIterator;
import agent.dbgmodel.jna.dbgmodel.main.WrapIModelIterator;
import ghidra.util.datastruct.WeakValueHashMap;

public interface ModelIteratorInternal extends ModelIterator {

    Map<Pointer, ModelIteratorInternal> CACHE = new WeakValueHashMap<>();

    static ModelIteratorInternal instanceFor(WrapIModelIterator data) {
        return DbgModelUtil.lazyWeakCache(CACHE, d

    }

    ImmutableMap.Builder<REFIID, Class<? extends WrapIModelIterator>> PREFERRED_DATA_SPACES_IIDS_BUILDER = ImmutableMap.builder();

    Map<REFIID, Class<? extends WrapIModelIterator>> PREFERRED_DATA_SPACES_IIDS = PREFERRED_DATA_SPACES_IIDS_BUILDER.put(new REFIID(IModelIterator.IID_IMODEL_ITERATOR), WrapIModelIterator.class).build();

    static ModelIteratorInternal tryPreferredInterfaces(InterfaceSupplier supplier) {
        return DbgModelUtil.tryPreferredInterfaces(ModelIteratorInternal.class, PREFERRED_DATA_SPACES_IIDS, supplier);
    }
}


@Override
    public String getUniqueTaskKeyTableIdentifier()

package com.transferwise.tasks.dao;

import com.transferwise.tasks.TasksProperties;
import org.apache.commons.lang3.StringUtils;

public class PostgresTaskTables implements ITwTaskTables {

    private final String taskTableIdentifier;

    private final String uniqueTaskKeyIdentifier;

    private final String taskDataTableIdentifier;

    public PostgresTaskTables(TasksProperties tasksProperties) {
        if (StringUtils.isNotEmpty(tasksProperties.getTaskTablesSchemaName())) {
            taskTableIdentifier = tasksProperties.getTaskTablesSchemaName() + "." + tasksProperties.getTaskTableName();
            uniqueTaskKeyIdentifier = tasksProperties.getTaskTablesSchemaName() + "." + tasksProperties.getUniqueTaskKeyTableName();
            taskDataTableIdentifier = tasksProperties.getTaskTablesSchemaName() + "." + tasksProperties.getTaskDataTableName();
        } else {
            taskTableIdentifier = tasksProperties.getTaskTableName();
            uniqueTaskKeyIdentifier = tasksProperties.getUniqueTaskKeyTableName();
            taskDataTableIdentifier = tasksProperties.getTaskDataTableName();
        }
    }

    @Override
    public String getTaskTableIdentifier() {
        return taskTableIdentifier;
    }

{
        return uniqueTaskKeyIdentifier;
    }

    @Override
    public String getTaskDataTableIdentifier() {
        return taskDataTableIdentifier;
    }
}


{
        return uniqueTaskKeyIdentifier;
    }

package com.transferwise.tasks.dao;

import com.transferwise.tasks.TasksProperties;
import org.apache.commons.lang3.StringUtils;

public class PostgresTaskTables implements ITwTaskTables {

    private final String taskTableIdentifier;

    private final String uniqueTaskKeyIdentifier;

    private final String taskDataTableIdentifier;

    public PostgresTaskTables(TasksProperties tasksProperties) {
        if (StringUtils.isNotEmpty(tasksProperties.getTaskTablesSchemaName())) {
            taskTableIdentifier = tasksProperties.getTaskTablesSchemaName() + "." + tasksProperties.getTaskTableName();
            uniqueTaskKeyIdentifier = tasksProperties.getTaskTablesSchemaName() + "." + tasksProperties.getUniqueTaskKeyTableName();
            taskDataTableIdentifier = tasksProperties.getTaskTablesSchemaName() + "." + tasksProperties.getTaskDataTableName();
        } else {
            taskTableIdentifier = tasksProperties.getTaskTableName();
            uniqueTaskKeyIdentifier = tasksProperties.getUniqueTaskKeyTableName();
            taskDataTableIdentifier = tasksProperties.getTaskDataTableName();
        }
    }

    @Override
    public String getTaskTableIdentifier() {
        return taskTableIdentifier;
    }

    @Override
    public String getUniqueTaskKeyTableIdentifier()

    @Override
    public String getTaskDataTableIdentifier() {
        return taskDataTableIdentifier;
    }
}


package com.transferwise.tasks.dao;

import com.transferwise.tasks.TasksProperties;
import org.apache.commons.lang3.StringUtils;

public class PostgresTaskTables implements ITwTaskTables {

    private final String taskTableIdentifier;

    private final String uniqueTaskKeyIdentifier;

    private final String taskDataTableIdentifier;

    public PostgresTaskTables(TasksProperties tasksProperties) {
        if (StringUtils.isNotEmpty(tasksProperties.getTaskTablesSchemaName())) {
            taskTableIdentifier = tasksProperties.getTaskTablesSchemaName() + "." + tasksProperties.getTaskTableName();
            uniqueTaskKeyIdentifier = tasksProperties.getTaskTablesSchemaName() + "." + tasksProperties.getUniqueTaskKeyTableName();
            taskDataTableIdentifier = tasksProperties.getTaskTablesSchemaName() + "." + tasksProperties.getTaskDataTableName();
        } else {
            taskTableIdentifier = tasksProperties.getTaskTableName();
            uniqueTaskKeyIdentifier = tasksProperties.getUniqueTaskKeyTableName();
            taskDataTableIdentifier = tasksProperties.getTaskDataTableName();
        }
    }

    @Override
    public String getTaskTableIdentifier() {
        return taskTableIdentifier;
    }

    @Override
    public String getUniqueTaskKeyTableIdentifier() {
        return uniqueTaskKeyIdentifier;
    }

    @Override
    public String getTaskDataTableIdentifier() {
        return taskDataTableIde


package engine.util;

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Objects;

public class Color {

    public static final Color BLACK = Color.fromRGB(0x000000);

    public static final Color RED = Color.fromRGB(0xff0000);

    public static final Color GREEN = Color.fromRGB(0x00ff00);

    public static final Color BLUE = Color.fromRGB(0x0000ff);

    public static final Color WHITE = Color.fromRGB(0xffffff);

    public static final Color TRANSPARENT = new Color(0f, 0f, 0f, 0f);

    public static Color fromGray(int gray) {
        return new Color(gray, gray, gray);
    }

    public static Color fromGray(float gray) {
        return new Color(gray, gray, gray);
    }

    public static Color fromRGB(String rgb) {
        return fromRGB(Integer.parseInt(rgb, 16));
    }

    public static Color fromRGB(int rgb) {
        return new Color((rgb >> 16) & 255, (rgb >> 8) & 255, rgb & 255);
    }

    public static Color fromARGB(String argb) {
        return fromARGB(Integer.parseInt(argb, 16));
    }

    public static Color fromARGB(int argb) {
        return new Color((argb >> 16) & 255, (argb >> 8) & 255, argb & 255, (argb >> 24) & 255);
    }

    public static Color fromRGBA(String argb) {
        return fromRGBA(Integer.parseInt(argb, 16));
    }

    public static Color fromRGBA(int argb) {
        return new Color((argb >> 24) & 255, (argb >> 16) & 255, (argb >> 8) & 255, argb & 255);
    }

    private final float red;

    private final float green;

    private final float blue;

    private final float alpha;

    public Color(int red, int green, int blue) {
        this(red / 255f, green / 255f, blue / 255f, 1f);
    }

    public Color(float red, float green, float blue) {
        this(red, green, blue, 1f);
    }

    public Color(int red, int green, int blue, int alpha) {
        this(red / 255f, green / 255f, blue / 255f, alpha / 255f);
    }

    public Color(float red, float green, float blue, float alpha) {
        this.red = red;
        this.green = green;
        this.blue = blue;
        this.alpha = alpha;
    }

    public float getRed() {
        return red;
    }

    public float getGreen() {
        return green;
    }

    public float getBlue() {
        return blue;
    }

    public float getAlpha() {
        return alpha;
    }

    public int getRedAsInt() {
        return (int) (red * 255);
    }

{
        return (int) (green * 255);
    }

    public int getBlueAsInt() {
        return (int) (blue * 255);
    }

    public int getAlphaAsInt() {
        return (int) (alpha * 255);
    }

    public FloatBuffer get(FloatBuffer dst) {
        return get(dst.position(), dst);
    }

    public FloatBuffer get(int index, FloatBuffer dst) {
        dst.put(index, red);
        dst.put(index + 1, green);
        dst.put(index + 2, blue);
        dst.put(index + 3, alpha);
        return dst;
    }

    public ByteBuffer get(ByteBuffer dst) {
        return get(dst.position(), dst);
    }

    public ByteBuffer get(int index, ByteBuffer dst) {
        dst.putFloat(index, red);
        dst.putFloat(index + 4, green);
        dst.putFloat(index + 8, blue);
        dst.putFloat(index + 12, alpha);
        return dst;
    }

    public float[] get(float[] dst) {
        return get(0, dst);
    }

    public float[] get(int index, float[] dst) {
        dst[index] = red;
        dst[index + 1] = green;
        dst[index + 2] = blue;
        dst[index + 3] = alpha;
        return dst;
    }

    public FloatBuffer getRGB(FloatBuffer dst) {
        return get(dst.position(), dst);
    }

    public FloatBuffer getRGB(int index, FloatBuffer dst) {
        dst.put(index, red);
        dst.put(index + 1, green);
        dst.put(index + 2, blue);
        return dst;
    }

    public ByteBuffer getRGB(ByteBuffer dst) {
        return get(dst.position(), dst);
    }

    public ByteBuffer getRGB(int index, ByteBuffer dst) {
        dst.putFloat(index, red);
        dst.putFloat(index + 4, green);
        dst.putFloat(index + 8, blue);
        return dst;
    }

    public float[] getRGB(float[] dst) {
        return get(0, dst);
    }

    public float[] getRGB(int index, float[] dst) {
        dst[index] = red;
        dst[index + 1] = green;
        dst[index + 2] = blue;
        return dst;
    }

    public int toRGB() {
        return (getRedAsInt() << 16) | (getGreenAsInt() << 8) | getBlueAsInt();
    }

    public int toARGB() {
        return (getAlphaAsInt() << 24) | toRGB();
    }

    public int toRGBA() {
        return (toRGB() << 8) | getAlphaAsInt();
    }

    public float[] toRGBAFloatArray() {
        return new float[] { red, green, blue, alpha };
    }

    public Color invert() {
        return difference(Color.WHITE);
    }

    public Color difference(Color color) {
        return new Color(Math.abs(color.red - this.red) * color.alpha + red * (1 - color.alpha), Math.abs(color.green - this.green) * color.alpha + color.green * (1 - color.alpha), Math.abs(color.blue - this.blue) * color.alpha + blue * (1 - color.alpha), alpha);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        Color color = (Color) o;
        return Float.compare(color.red, red) == 0 && Float.compare(color.green, green) == 0 && Float.compare(color.blue, blue) == 0 && Float.compare(color.alpha, alpha) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hash(red, green, blue, alpha);
    }

    @Override
    public String toString() {
        return "Color{" + "red=" + red + ", green=" + green + ", blue=" + blue + ", alpha=" + alpha + '}';
    }
}


{
        return get(dst.position(), dst);
    }

package engine.util;

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Objects;

public class Color {

    public static final Color BLACK = Color.fromRGB(0x000000);

    public static final Color RED = Color.fromRGB(0xff0000);

    public static final Color GREEN = Color.fromRGB(0x00ff00);

    public static final Color BLUE = Color.fromRGB(0x0000ff);

    public static final Color WHITE = Color.fromRGB(0xffffff);

    public static final Color TRANSPARENT = new Color(0f, 0f, 0f, 0f);

    public static Color fromGray(int gray) {
        return new Color(gray, gray, gray);
    }

    public static Color fromGray(float gray) {
        return new Color(gray, gray, gray);
    }

    public static Color fromRGB(String rgb) {
        return fromRGB(Integer.parseInt(rgb, 16));
    }

    public static Color fromRGB(int rgb) {
        return new Color((rgb >> 16) & 255, (rgb >> 8) & 255, rgb & 255);
    }

    public static Color fromARGB(String argb) {
        return fromARGB(Integer.parseInt(argb, 16));
    }

    public static Color fromARGB(int argb) {
        return new Color((argb >> 16) & 255, (argb >> 8) & 255, argb & 255, (argb >> 24) & 255);
    }

    public static Color fromRGBA(String argb) {
        return fromRGBA(Integer.parseInt(argb, 16));
    }

    public static Color fromRGBA(int argb) {
        return new Color((argb >> 24) & 255, (argb >> 16) & 255, (argb >> 8) & 255, argb & 255);
    }

    private final float red;

    private final float green;

    private final float blue;

    private final float alpha;

    public Color(int red, int green, int blue) {
        this(red / 255f, green / 255f, blue / 255f, 1f);
    }

    public Color(float red, float green, float blue) {
        this(red, green, blue, 1f);
    }

    public Color(int red, int green, int blue, int alpha) {
        this(red / 255f, green / 255f, blue / 255f, alpha / 255f);
    }

    public Color(float red, float green, float blue, float alpha) {
        this.red = red;
        this.green = green;
        this.blue = blue;
        this.alpha = alpha;
    }

    public float getRed() {
        return red;
    }

    public float getGreen() {
        return green;
    }

    public float getBlue() {
        return blue;
    }

    public float getAlpha() {
        return alpha;
    }

    public int getRedAsInt() {
        return (int) (red * 255);
    }

    public int getGreenAsInt() {
        return (int) (green * 255);
    }

    public int getBlueAsInt() {
        return (int) (blue * 255);
    }

    public int getAlphaAsInt() {
        return (int) (alpha * 255);
    }

    public FloatBuffer get(FloatBuffer dst) {
        return get(dst.position(), dst);
    }

    public FloatBuffer get(int index, FloatBuffer dst) {
        dst.put(index, red);
        dst.put(index + 1, green);
        dst.put(index + 2, blue);
        dst.put(index + 3, alpha);
        return dst;
    }

    public ByteBuffer get(ByteBuffer dst)

    public ByteBuffer get(int index, ByteBuffer dst) {
        dst.putFloat(index, red);
        dst.putFloat(index + 4, green);
        dst.putFloat(index + 8, blue);
        dst.putFloat(index + 12, alpha);
        return dst;
    }

    public float[] get(float[] dst) {
        return get(0, dst);
    }

    public float[] get(int index, float[] dst) {
        dst[index] = red;
        dst[index + 1] = green;
        dst[index + 2] = blue;
        dst[index + 3] = alpha;
        return dst;
    }

    public FloatBuffer getRGB(FloatBuffer dst) {
        return get(dst.position(), dst);
    }

    public FloatBuffer getRGB(int index, FloatBuffer dst) {
        dst.put(index, red);
        dst.put(index + 1, green);
        dst.put(index + 2, blue);
        return dst;
    }

    public ByteBuffer getRGB(ByteBuffer dst) {
        return get(dst.position(), dst);
    }

    public ByteBuffer getRGB(int index, ByteBuffer dst) {
        dst.putFloat(index, red);
        dst.putFloat(index + 4, green);
        dst.putFloat(index + 8, blue);
        return dst;
    }

    public float[] getRGB(float[] dst) {
        return get(0, dst);
    }

    public float[] getRGB(int index, float[] dst) {
        dst[index] = red;
        dst[index + 1] = green;
        dst[index + 2] = blue;
        return dst;
    }

    public int toRGB() {
        return (getRedAsInt() << 16) | (getGreenAsInt() << 8) | getBlueAsInt();
    }

    public int toARGB() {
        return (getAlphaAsInt() << 24) | toRGB();
    }

    public int toRGBA() {
        return (toRGB() << 8) | getAlphaAsInt();
    }

    public float[] toRGBAFloatArray() {
        return new float[] { red, green, blue, alpha };
    }

    public Color invert() {
        return difference(Color.WHITE);
    }

    public Color difference(Color color) {
        return new Color(Math.abs(color.red - this.red) * color.alpha + red * (1 - color.alpha), Math.abs(color.green - this.green) * color.alpha + color.green * (1 - color.alpha), Math.abs(color.blue - this.blue) * color.alpha + blue * (1 - color.alpha), alpha);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        Color color = (Color) o;
        return Float.compare(color.red, red) == 0 && Float.compare(color.green, green) == 0 && Float.compare(color.blue, blue) == 0 && Float.compare(color.alpha, alpha) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hash(red, green, blue, alpha);
    }

    @Override
    public String toString() {
        return "Color{" + "red=" + red + ", green=" + green + ", blue=" + blue + ", alpha=" + alpha + '}';
    }
}


package engine.util;

import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.util.Objects;

public class Color {

    public static final Color BLACK = Color.fromRGB(0x000000);

    public static final Color RED = Color.fromRGB(0xff0000);

    public static final Color GREEN = Color.fromRGB(0x00ff00);

    public static final Color BLUE = Color.fromRGB(0x0000ff);

    public static final Color WHITE = Color.fromRGB(0xffffff);

    public static final Color TRANSPARENT = new Color(0f, 0f, 0f, 0f);

    public static Color fromGray(int gray) {
        return new Color(gray, gray, gray);
    }

    public static Color fromGray(float gray) {
        return new Color(gray, gray, gray);
    }

    public static Color fromRGB(String rgb) {
        return fromRGB(Integer.parseInt(rgb, 16));
    }

    public static Color fromRGB(int rgb) {
        return new Color((rgb >> 16) & 255, (rgb >> 8) & 255, rgb & 255);
    }

    public static Color fromARGB(String argb) {
        return fromARGB(Integer.parseInt(argb, 16));
    }

    public static Color fromARGB(int argb) {
        return new Color((argb >> 16) & 255, (argb >> 8) & 255, argb & 255, (argb >> 24) & 255);
    }

    public static Color fromRGBA(String argb) {
        return fromRGBA(Inte

    }

    public static Color fromRGBA(int argb) {
        return new Color((argb >> 24) & 255, (argb >> 16) & 255, (argb >> 8) & 255, argb & 255);
    }

    private final float red;

    private final float green;

    private final float blue;

    private final float alpha;

    public Color(int red, int green, int blue) {
        this(red / 255f, green / 255f, blue / 255f, 1f);
    }

    public Color(float red, float green, float blue) {
        this(red, green, blue, 1f);
    }

    public Color(int red, int green, int blue, int alpha) {
        this(red / 255f, green / 255f, blue / 255f, alpha / 255f);
    }

    public Color(float red, float green, float blue, float alpha) {
        this.red = red;
        this.green = green;
        this.blue = blue;
        this.alpha = alpha;
    }

    public float getRed() {
        return red;
    }

    public float getGreen() {
        return green;
    }

    public float getBlue() {
        return blue;
    }

    public float getAlpha() {
        return alpha;
    }

    public int getRedAsInt() {
        return (int) (red * 255);
    }

    public int getGreenAsInt() {
        return (int) (green * 255);
    }

    public int getBlueAsInt() {
        return (int) (blue * 255);
    }

    public int getAlphaAsInt() {
        return (int) (alpha * 255);
    }

    public FloatBuffer get(FloatBuffer dst) {
        return get(dst.position(), dst);
    }

    public FloatBuffer get(int index, FloatBuffer dst) {
        dst.put(index, red);
        dst.put(index + 1, green);
        dst.put(index + 2, blue);
        dst.put(index + 3, alpha);
        return dst;
    }

    public ByteBuffer get(ByteBuffer dst) {
        return get(dst.position(), dst);
    }

    public ByteBuffer get(int index, ByteBuffer dst) {
        dst.putFloat(index, red);
        dst.putFloat(index + 4, green);
        dst.putFloat(index + 8, blue);
        dst.putFloat(index + 12, alpha);
        return dst;
    }

    public float[] get(float[] dst) {
        return get(0, dst);
    }

    public float[] get(int index, float[] dst) {
        dst[index] = red;
        dst[index + 1] = green;
        dst[index + 2] = blue;
        dst[index + 3] = alpha;
        return dst;
    }

    public FloatBuffer getRGB(FloatBuffer dst) {
        return get(dst.position(), dst);
    }

    public FloatBuffer getRGB(int index, FloatBuffer dst) {
        dst.put(index, red);
        dst.put(index + 1, green);
        dst.put(index + 2, blue);
        return dst;
    }

    public ByteBuffer getRGB(ByteBuffer dst) {
        return get(dst.position(), dst);
    }

    public ByteBuffer getRGB(int index, ByteBuffer dst) {
        dst.putFloat(index, red);
        dst.putFloat(index + 4, green);
        dst.putFloat(index + 8, blue);
        return dst;
    }

    public float[] getRGB(float[] dst) {
        return get(0, dst);
    }

    public float[] getRGB(int index, float[] dst) {
        dst[index] = red;
        dst[index + 1] = green;
        dst[index + 2] = blue;
        return dst;
    }

    public int toRGB() {
        return (getRedAsInt() << 16) | (getGreenAsInt() << 8) | getBlueAsInt();
    }

    public int toARGB() {
        return (getAlphaAsInt() << 24) | toRGB();
    }

    public int toRGBA() {
        return (toRGB() << 8) | getAlphaAsInt();
    }

    public float[] toRGBAFloatArray() {
        return new float[] { red, green, blue, alpha };
    }

    public Color invert() {
        return difference(Color.WHITE);
    }

    public Color difference(Color color) {
        return new Color(Math.abs(color.red - this.red) * color.alpha + red * (1 - color.alpha), Math.abs(color.green - this.green) * color.alpha + color.green * (1 - color.alpha), Math.abs(color.blue - this.blue) * color.alpha + blue * (1 - color.alpha), alpha);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o)
            return true;
        if (o == null || getClass() != o.getClass())
            return false;
        Color color = (Color) o;
        return Float.compare(color.red, red) == 0 && Float.compare(color.green, green) == 0 && Float.compare(color.blue, blue) == 0 && Float.compare(color.alpha, alpha) == 0;
    }

    @Override
    public int hashCode() {
        return Objects.hash(red, green, blue, alpha);
    }

    @Override
    public String toString() {
        return "Color{" + "red=" + red + ", green=" + green + ", blue=" + blue + ", alpha=" + alpha + '}';
    }
}


private static Class[] extractArgumentTypes(Object[] pArguments)

package org.jolokia.util;

import java.io.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.*;

/**
 * Utility for class lookup.
 *
 * @author roland
 * @since 19.04.11
 */
public final class ClassUtil {

    private ClassUtil() {
    }

    /**
     * Lookup a class. See {@link ClassUtil#classForName(String, boolean,ClassLoader[])} for details. The class
     * gets initialized during lookup.
     *
     * @param pClassName name to lookup.
     * @return the class found or null if no class could be found.
     */
    public static <T> Class<T> classForName(String pClassName, ClassLoader... pClassLoaders) {
        return classForName(pClassName, true, pClassLoaders);
    }

    /**
     * Load a certain class. Several class loader are tried: Fires the current thread's context
     * class loader, then its parents. If this doesn't work, the class loader which
     * loaded this class is used (and its parents)
     *
     * @param pClassName class name to load
     * @param pInitialize whether the class must be initialized
     * @param pClassLoaders optional class loaders which are tried as well
     * @return the class class found or null if no class could be loaded
     */
    public static <T> Class<T> classForName(String pClassName, boolean pInitialize, ClassLoader... pClassLoaders) {
        Set<ClassLoader> tried = new HashSet<ClassLoader>();
        for (ClassLoader loader : findClassLoaders(pClassLoaders)) {
            // Go up the classloader stack to eventually find the server class. Sometimes the WebAppClassLoader
            // hide the server classes loaded by the parent class loader.
            while (loader != null) {
                try {
                    if (!tried.contains(loader)) {
                        return (Class<T>) Class.forName(pClassName, pInitialize, loader);
                    }
                } catch (ClassNotFoundException ignored) {
                }
                tried.add(loader);
                loader = loader.getParent();
            }
        }
        return null;
    }

    private static List<ClassLoader> findClassLoaders(ClassLoader... pClassLoaders) {
        List<ClassLoader> classLoadersToTry = new ArrayList<ClassLoader>(Arrays.asList(pClassLoaders));
        classLoadersToTry.add(Thread.currentThread().getContextClassLoader());
        classLoadersToTry.add(ClassUtil.class.getClassLoader());
        List<ClassLoader> ret = new ArrayList<ClassLoader>();
        Set<ClassLoader> visited = new HashSet<ClassLoader>();
        for (ClassLoader cll : classLoadersToTry) {
            if (cll != null && !visited.contains(cll)) {
                ret.add(cll);
                visited.add(cll);
            }
        }
        return ret;
    }

    /**
     * Get the given path as an input stream or return null if not found
     *
     * @param pPath path to lookup
     * @return input stream or null if not found.
     */
    public static InputStream getResourceAsStream(String pPath) {
        for (ClassLoader loader : new ClassLoader[] { Thread.currentThread().getContextClassLoader(), ClassUtil.class.getClassLoader() }) {
            if (loader != null) {
                InputStream is = loader.getResourceAsStream(pPath);
                if (is != null) {
                    return is;
                }
            }
        }
        return null;
    }

    /**
     * Check for the existence of a given class
     *
     * @param pClassName class name to check
     * @return true if the class could be loaded by the thread's conext class loader, false otherwise
     */
    public static boolean checkForClass(String pClassName) {
        return ClassUtil.classForName(pClassName, false) != null;
    }

    /**
     * Instantiate an instance of the given class with its default constructor. The context class loader is used
     * to lookup the class
     *
     * @param pClassName name of class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(String pClassName, Object... pArguments) {
        Class<T> clazz = classForName(pClassName);
        if (clazz == null) {
            throw new IllegalArgumentException("Cannot find " + pClassName);
        }
        return newInstance(clazz, pArguments);
    }

    /**
     * Instantiate an instance of the given class with its default constructor
     *
     * @param pClass class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(Class<T> pClass, Object... pArguments) {
        try {
            if (pClass != null) {
                if (pArguments.length == 0) {
                    return pClass.newInstance();
                } else {
                    Constructor<T> ctr = lookupConstructor(pClass, pArguments);
                    return ctr.newInstance(pArguments);
                }
            } else {
                throw new IllegalArgumentException("Given class must not be null");
            }
        } catch (InstantiationException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        }
    }

    /**
     * Apply a method to a given object with optional arguments. The method is looked up the whole class
     * hierarchy.
     *
     * @param pObject object on which to apply the method
     * @param pMethod the method name
     * @param pArgs optional arguments
     * @return return value (if any)
     */
    public static Object applyMethod(Object pObject, String pMethod, Object... pArgs) {
        Class<?> clazz = pObject.getClass();
        try {
            Method method = extractMethod(pMethod, clazz, pArgs);
            return method.invoke(pObject, pArgs);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        }
    }

    /**
     * Get all resources from the classpath which are specified by the given path.
     *
     * @param pResource resource specification to use for lookup
     * @return the list or URLs to loookup
     */
    public static Set<String> getResources(String pResource) throws IOException {
        List<ClassLoader> clls = findClassLoaders();
        if (clls.size() != 0) {
            Set<String> ret = new HashSet<String>();
            for (ClassLoader cll : clls) {
                Enumeration<URL> urlEnum = cll.getResources(pResource);
                ret.addAll(extractUrlAsStringsFromEnumeration(urlEnum));
            }
            return ret;
        } else {
            return extractUrlAsStringsFromEnumeration(ClassLoader.getSystemResources(pResource));
        }
    }

    private static Set<String> extractUrlAsStringsFromEnumeration(Enumeration<URL> urlEnum) {
        Set<String> ret = new HashSet<String>();
        while (urlEnum.hasMoreElements()) {
            ret.add(urlEnum.nextElement().toExternalForm());
        }
        return ret;
    }

    // Lookup appropriate constructor
    private static <T> Constructor<T> lookupConstructor(Class<T> clazz, Object[] pArguments) throws NoSuchMethodException {
        Class[] argTypes = extractArgumentTypes(pArguments);
        return clazz.getConstructor(argTypes);
    }

    private static Method extractMethod(String pMethod, Class<?> clazz, Object[] pArgs) throws NoSuchMethodException {
        for (Method method : clazz.getMethods()) {
            if (!method.getName().equals(pMethod)) {
                continue;
            }
            Class[] parameters = method.getParameterTypes();
            if (parametersMatch(parameters, pArgs)) {
                return method;
            }
        }
        throw new NoSuchMethodException("No " + pMethod + " on " + clazz + " with " + pArgs.length + " arguments found ");
    }

{
        Class[] argTypes = new Class[pArguments.length];
        int i = 0;
        for (Object arg : pArguments) {
            argTypes[i++] = arg.getClass();
        }
        return argTypes;
    }

    private static boolean parametersMatch(Class[] parameters, Object[] pArgs) {
        if (parameters.length != pArgs.length) {
            return false;
        }
        for (int i = 0; i < parameters.length; i++) {
            if (pArgs[i] == null) {
                continue;
            }
            Class argClass = pArgs[i].getClass();
            Class paramClass = parameters[i];
            if (!paramClass.isAssignableFrom(argClass)) {
                if (checkForPrimitive(argClass, paramClass)) {
                    continue;
                }
                return false;
            }
        }
        return true;
    }

    private static boolean checkForPrimitive(Class argClass, Class paramClass) {
        return paramClass.isPrimitive() && PRIMITIVE_TO_OBJECT_MAP.get(paramClass.getName()) != null;
    }

    private static final Map<String, Class> PRIMITIVE_TO_OBJECT_MAP = new HashMap<String, Class>();

    static {
        PRIMITIVE_TO_OBJECT_MAP.put("int", Integer.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("long", Long.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("double", Double.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("float", Float.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("bool", Boolean.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("char", Character.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("byte", Byte.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("void", Void.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("short", Short.TYPE);
    }
}


{
        return paramClass.isPrimitive() && PRIMITIVE_TO_OBJECT_MAP.get(paramClass.getName()) != null;
    }

package org.jolokia.util;

import java.io.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.*;

/**
 * Utility for class lookup.
 *
 * @author roland
 * @since 19.04.11
 */
public final class ClassUtil {

    private ClassUtil() {
    }

    /**
     * Lookup a class. See {@link ClassUtil#classForName(String, boolean,ClassLoader[])} for details. The class
     * gets initialized during lookup.
     *
     * @param pClassName name to lookup.
     * @return the class found or null if no class could be found.
     */
    public static <T> Class<T> classForName(String pClassName, ClassLoader... pClassLoaders) {
        return classForName(pClassName, true, pClassLoaders);
    }

    /**
     * Load a certain class. Several class loader are tried: Fires the current thread's context
     * class loader, then its parents. If this doesn't work, the class loader which
     * loaded this class is used (and its parents)
     *
     * @param pClassName class name to load
     * @param pInitialize whether the class must be initialized
     * @param pClassLoaders optional class loaders which are tried as well
     * @return the class class found or null if no class could be loaded
     */
    public static <T> Class<T> classForName(String pClassName, boolean pInitialize, ClassLoader... pClassLoaders) {
        Set<ClassLoader> tried = new HashSet<ClassLoader>();
        for (ClassLoader loader : findClassLoaders(pClassLoaders)) {
            // Go up the classloader stack to eventually find the server class. Sometimes the WebAppClassLoader
            // hide the server classes loaded by the parent class loader.
            while (loader != null) {
                try {
                    if (!tried.contains(loader)) {
                        return (Class<T>) Class.forName(pClassName, pInitialize, loader);
                    }
                } catch (ClassNotFoundException ignored) {
                }
                tried.add(loader);
                loader = loader.getParent();
            }
        }
        return null;
    }

    private static List<ClassLoader> findClassLoaders(ClassLoader... pClassLoaders) {
        List<ClassLoader> classLoadersToTry = new ArrayList<ClassLoader>(Arrays.asList(pClassLoaders));
        classLoadersToTry.add(Thread.currentThread().getContextClassLoader());
        classLoadersToTry.add(ClassUtil.class.getClassLoader());
        List<ClassLoader> ret = new ArrayList<ClassLoader>();
        Set<ClassLoader> visited = new HashSet<ClassLoader>();
        for (ClassLoader cll : classLoadersToTry) {
            if (cll != null && !visited.contains(cll)) {
                ret.add(cll);
                visited.add(cll);
            }
        }
        return ret;
    }

    /**
     * Get the given path as an input stream or return null if not found
     *
     * @param pPath path to lookup
     * @return input stream or null if not found.
     */
    public static InputStream getResourceAsStream(String pPath) {
        for (ClassLoader loader : new ClassLoader[] { Thread.currentThread().getContextClassLoader(), ClassUtil.class.getClassLoader() }) {
            if (loader != null) {
                InputStream is = loader.getResourceAsStream(pPath);
                if (is != null) {
                    return is;
                }
            }
        }
        return null;
    }

    /**
     * Check for the existence of a given class
     *
     * @param pClassName class name to check
     * @return true if the class could be loaded by the thread's conext class loader, false otherwise
     */
    public static boolean checkForClass(String pClassName) {
        return ClassUtil.classForName(pClassName, false) != null;
    }

    /**
     * Instantiate an instance of the given class with its default constructor. The context class loader is used
     * to lookup the class
     *
     * @param pClassName name of class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(String pClassName, Object... pArguments) {
        Class<T> clazz = classForName(pClassName);
        if (clazz == null) {
            throw new IllegalArgumentException("Cannot find " + pClassName);
        }
        return newInstance(clazz, pArguments);
    }

    /**
     * Instantiate an instance of the given class with its default constructor
     *
     * @param pClass class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(Class<T> pClass, Object... pArguments) {
        try {
            if (pClass != null) {
                if (pArguments.length == 0) {
                    return pClass.newInstance();
                } else {
                    Constructor<T> ctr = lookupConstructor(pClass, pArguments);
                    return ctr.newInstance(pArguments);
                }
            } else {
                throw new IllegalArgumentException("Given class must not be null");
            }
        } catch (InstantiationException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        }
    }

    /**
     * Apply a method to a given object with optional arguments. The method is looked up the whole class
     * hierarchy.
     *
     * @param pObject object on which to apply the method
     * @param pMethod the method name
     * @param pArgs optional arguments
     * @return return value (if any)
     */
    public static Object applyMethod(Object pObject, String pMethod, Object... pArgs) {
        Class<?> clazz = pObject.getClass();
        try {
            Method method = extractMethod(pMethod, clazz, pArgs);
            return method.invoke(pObject, pArgs);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        }
    }

    /**
     * Get all resources from the classpath which are specified by the given path.
     *
     * @param pResource resource specification to use for lookup
     * @return the list or URLs to loookup
     */
    public static Set<String> getResources(String pResource) throws IOException {
        List<ClassLoader> clls = findClassLoaders();
        if (clls.size() != 0) {
            Set<String> ret = new HashSet<String>();
            for (ClassLoader cll : clls) {
                Enumeration<URL> urlEnum = cll.getResources(pResource);
                ret.addAll(extractUrlAsStringsFromEnumeration(urlEnum));
            }
            return ret;
        } else {
            return extractUrlAsStringsFromEnumeration(ClassLoader.getSystemResources(pResource));
        }
    }

    private static Set<String> extractUrlAsStringsFromEnumeration(Enumeration<URL> urlEnum) {
        Set<String> ret = new HashSet<String>();
        while (urlEnum.hasMoreElements()) {
            ret.add(urlEnum.nextElement().toExternalForm());
        }
        return ret;
    }

    // Lookup appropriate constructor
    private static <T> Constructor<T> lookupConstructor(Class<T> clazz, Object[] pArguments) throws NoSuchMethodException {
        Class[] argTypes = extractArgumentTypes(pArguments);
        return clazz.getConstructor(argTypes);
    }

    private static Method extractMethod(String pMethod, Class<?> clazz, Object[] pArgs) throws NoSuchMethodException {
        for (Method method : clazz.getMethods()) {
            if (!method.getName().equals(pMethod)) {
                continue;
            }
            Class[] parameters = method.getParameterTypes();
            if (parametersMatch(parameters, pArgs)) {
                return method;
            }
        }
        throw new NoSuchMethodException("No " + pMethod + " on " + clazz + " with " + pArgs.length + " arguments found ");
    }

    private static Class[] extractArgumentTypes(Object[] pArguments) {
        Class[] argTypes = new Class[pArguments.length];
        int i = 0;
        for (Object arg : pArguments) {
            argTypes[i++] = arg.getClass();
        }
        return argTypes;
    }

    private static boolean parametersMatch(Class[] parameters, Object[] pArgs) {
        if (parameters.length != pArgs.length) {
            return false;
        }
        for (int i = 0; i < parameters.length; i++) {
            if (pArgs[i] == null) {
                continue;
            }
            Class argClass = pArgs[i].getClass();
            Class paramClass = parameters[i];
            if (!paramClass.isAssignableFrom(argClass)) {
                if (checkForPrimitive(argClass, paramClass)) {
                    continue;
                }
                return false;
            }
        }
        return true;
    }

    private static boolean checkForPrimitive(Class argClass, Class paramClass)

    private static final Map<String, Class> PRIMITIVE_TO_OBJECT_MAP = new HashMap<String, Class>();

    static {
        PRIMITIVE_TO_OBJECT_MAP.put("int", Integer.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("long", Long.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("double", Double.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("float", Float.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("bool", Boolean.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("char", Character.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("byte", Byte.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("void", Void.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("short", Short.TYPE);
    }
}


ist<ClassLoader> clls = findClassLoaders();

package org.jolokia.util;

import java.io.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.*;

/**
 * Utility for class lookup.
 *
 * @author roland
 * @since 19.04.11
 */
public final class ClassUtil {

    private ClassUtil() {
    }

    /**
     * Lookup a class. See {@link ClassUtil#classForName(String, boolean,ClassLoader[])} for details. The class
     * gets initialized during lookup.
     *
     * @param pClassName name to lookup.
     * @return the class found or null if no class could be found.
     */
    public static <T> Class<T> classForName(String pClassName, ClassLoader... pClassLoaders) {
        return classForName(pClassName, true, pClassLoaders);
    }

    /**
     * Load a certain class. Several class loader are tried: Fires the current thread's context
     * class loader, then its parents. If this doesn't work, the class loader which
     * loaded this class is used (and its parents)
     *
     * @param pClassName class name to load
     * @param pInitialize whether the class must be initialized
     * @param pClassLoaders optional class loaders which are tried as well
     * @return the class class found or null if no class could be loaded
     */
    public static <T> Class<T> classForName(String pClassName, boolean pInitialize, ClassLoader... pClassLoaders) {
        Set<ClassLoader> tried = new HashSet<ClassLoader>();
        for (ClassLoader loader : findClassLoaders(pClassLoaders)) {
            // Go up the classloader stack to eventually find the server class. Sometimes the WebAppClassLoader
            // hide the server classes loaded by the parent class loader.
            while (loader != null) {
                try {
                    if (!tried.contains(loader)) {
                        return (Class<T>) Class.forName(pClassName, pInitialize, loader);
                    }
                } catch (ClassNotFoundException ignored) {
                }
                tried.add(loader);
                loader = loader.getParent();
            }
        }
        return null;
    }

    private static List<ClassLoader> findClassLoaders(ClassLoader... pClassLoaders) {
        List<ClassLoader> classLoadersToTry = new ArrayList<ClassLoader>(Arrays.asList(pClassLoaders));
        classLoadersToTry.add(Thread.currentThread().getContextClassLoader());
        classLoadersToTry.add(ClassUtil.class.getClassLoader());
        List<ClassLoader> ret = new ArrayList<ClassLoader>();
        Set<ClassLoader> visited = new HashSet<ClassLoader>();
        for (ClassLoader cll : classLoadersToTry) {
            if (cll != null && !visited.contains(cll)) {
                ret.add(cll);
                visited.add(cll);
            }
        }
        return ret;
    }

    /**
     * Get the given path as an input stream or return null if not found
     *
     * @param pPath path to lookup
     * @return input stream or null if not found.
     */
    public static InputStream getResourceAsStream(String pPath) {
        for (ClassLoader loader : new ClassLoader[] { Thread.currentThread().getContextClassLoader(), ClassUtil.class.getClassLoader() }) {
            if (loader != null) {
                InputStream is = loader.getResourceAsStream(pPath);
                if (is != null) {
                    return is;
                }
            }
        }
        return null;
    }

    /**
     * Check for the existence of a given class
     *
     * @param pClassName class name to check
     * @return true if the class could be loaded by the thread's conext class loader, false otherwise
     */
    public static boolean checkForClass(String pClassName) {
        return ClassUtil.classForName(pClassName, false) != null;
    }

    /**
     * Instantiate an instance of the given class with its default constructor. The context class loader is used
     * to lookup the class
     *
     * @param pClassName name of class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(String pClassName, Object... pArguments) {
        Class<T> clazz = classForName(pClassName);
        if (clazz == null) {
            throw new IllegalArgumentException("Cannot find " + pClassName);
        }
        return newInstance(clazz, pArguments);
    }

    /**
     * Instantiate an instance of the given class with its default constructor
     *
     * @param pClass class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(Class<T> pClass, Object... pArguments) {
        try {
            if (pClass != null) {
                if (pArguments.length == 0) {
                    return pClass.newInstance();
                } else {
                    Constructor<T> ctr = lookupConstructor(pClass, pArguments);
                    return ctr.newInstance(pArguments);
                }
            } else {
                throw new IllegalArgumentException("Given class must not be null");
            }
        } catch (InstantiationException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        }
    }

    /**
     * Apply a method to a given object with optional arguments. The method is looked up the whole class
     * hierarchy.
     *
     * @param pObject object on which to apply the method
     * @param pMethod the method name
     * @param pArgs optional arguments
     * @return return value (if any)
     */
    public static Object applyMethod(Object pObject, String pMethod, Object... pArgs) {
        Class<?> clazz = pObject.getClass();
        try {
            Method method = extractMethod(pMethod, clazz, pArgs);
            return method.invoke(pObject, pArgs);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        }
    }

    /**
     * Get all resources from the classpath which are specified by the given path.
     *
     * @param pResource resource specification to use for lookup
     * @return the list or URLs to loookup
     */
    public static Set<String> getResources(String pResource) throws IOException {
        L

        if (clls.size() != 0) {
            Set<String> ret = new HashSet<String>();
            for (ClassLoader cll : clls) {
                Enumeration<URL> urlEnum = cll.getResources(pResource);
                ret.addAll(extractUrlAsStringsFromEnumeration(urlEnum));
            }
            return ret;
        } else {
            return extractUrlAsStringsFromEnumeration(ClassLoader.getSystemResources(pResource));
        }
    }

    private static Set<String> extractUrlAsStringsFromEnumeration(Enumeration<URL> urlEnum) {
        Set<String> ret = new HashSet<String>();
        while (urlEnum.hasMoreElements()) {
            ret.add(urlEnum.nextElement().toExternalForm());
        }
        return ret;
    }

    // Lookup appropriate constructor
    private static <T> Constructor<T> lookupConstructor(Class<T> clazz, Object[] pArguments) throws NoSuchMethodException {
        Class[] argTypes = extractArgumentTypes(pArguments);
        return clazz.getConstructor(argTypes);
    }

    private static Method extractMethod(String pMethod, Class<?> clazz, Object[] pArgs) throws NoSuchMethodException {
        for (Method method : clazz.getMethods()) {
            if (!method.getName().equals(pMethod)) {
                continue;
            }
            Class[] parameters = method.getParameterTypes();
            if (parametersMatch(parameters, pArgs)) {
                return method;
            }
        }
        throw new NoSuchMethodException("No " + pMethod + " on " + clazz + " with " + pArgs.length + " arguments found ");
    }

    private static Class[] extractArgumentTypes(Object[] pArguments) {
        Class[] argTypes = new Class[pArguments.length];
        int i = 0;
        for (Object arg : pArguments) {
            argTypes[i++] = arg.getClass();
        }
        return argTypes;
    }

    private static boolean parametersMatch(Class[] parameters, Object[] pArgs) {
        if (parameters.length != pArgs.length) {
            return false;
        }
        for (int i = 0; i < parameters.length; i++) {
            if (pArgs[i] == null) {
                continue;
            }
            Class argClass = pArgs[i].getClass();
            Class paramClass = parameters[i];
            if (!paramClass.isAssignableFrom(argClass)) {
                if (checkForPrimitive(argClass, paramClass)) {
                    continue;
                }
                return false;
            }
        }
        return true;
    }

    private static boolean checkForPrimitive(Class argClass, Class paramClass) {
        return paramClass.isPrimitive() && PRIMITIVE_TO_OBJECT_MAP.get(paramClass.getName()) != null;
    }

    private static final Map<String, Class> PRIMITIVE_TO_OBJECT_MAP = new HashMap<String, Class>();

    static {
        PRIMITIVE_TO_OBJECT_MAP.put("int", Integer.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("long", Long.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("double", Double.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("float", Float.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("bool", Boolean.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("char", Character.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("byte", Byte.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("void", Void.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("short", Short.TYPE);
    }
}


public static InputStream getResourceAsStream(String pPath) {
        for (ClassLoader loader : new ClassLoader[] { Thread.currentThread().getContextClassLoader(), ClassUtil.class.getClassLoader() }) {
            if (loader != null) {
                InputStream is = loader.getResourceAsStream(pPath);
                if (is != null) {
                    return is;
                }
            }
        }
        return null;
    }

package org.jolokia.util;

import java.io.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.*;

/**
 * Utility for class lookup.
 *
 * @author roland
 * @since 19.04.11
 */
public final class ClassUtil {

    private ClassUtil() {
    }

    /**
     * Lookup a class. See {@link ClassUtil#classForName(String, boolean,ClassLoader[])} for details. The class
     * gets initialized during lookup.
     *
     * @param pClassName name to lookup.
     * @return the class found or null if no class could be found.
     */
    public static <T> Class<T> classForName(String pClassName, ClassLoader... pClassLoaders) {
        return classForName(pClassName, true, pClassLoaders);
    }

    /**
     * Load a certain class. Several class loader are tried: Fires the current thread's context
     * class loader, then its parents. If this doesn't work, the class loader which
     * loaded this class is used (and its parents)
     *
     * @param pClassName class name to load
     * @param pInitialize whether the class must be initialized
     * @param pClassLoaders optional class loaders which are tried as well
     * @return the class class found or null if no class could be loaded
     */
    public static <T> Class<T> classForName(String pClassName, boolean pInitialize, ClassLoader... pClassLoaders) {
        Set<ClassLoader> tried = new HashSet<ClassLoader>();
        for (ClassLoader loader : findClassLoaders(pClassLoaders)) {
            // Go up the classloader stack to eventually find the server class. Sometimes the WebAppClassLoader
            // hide the server classes loaded by the parent class loader.
            while (loader != null) {
                try {
                    if (!tried.contains(loader)) {
                        return (Class<T>) Class.forName(pClassName, pInitialize, loader);
                    }
                } catch (ClassNotFoundException ignored) {
                }
                tried.add(loader);
                loader = loader.getParent();
            }
        }
        return null;
    }

    private static List<ClassLoader> findClassLoaders(ClassLoader... pClassLoaders) {
        List<ClassLoader> classLoadersToTry = new ArrayList<ClassLoader>(Arrays.asList(pClassLoaders));
        classLoadersToTry.add(Thread.currentThread().getContextClassLoader());
        classLoadersToTry.add(ClassUtil.class.getClassLoader());
        List<ClassLoader> ret = new ArrayList<ClassLoader>();
        Set<ClassLoader> visited = new HashSet<ClassLoader>();
        for (ClassLoader cll : classLoadersToTry) {
            if (cll != null && !visited.contains(cll)) {
                ret.add(cll);
                visited.add(cll);
            }
        }
        return ret;
    }

    /**
     * Get the given path as an input stream or return null if not found
     *
     * @param pPath path to lookup
     * @return input stream or null if not found.
     */

    /**
     * Check for the existence of a given class
     *
     * @param pClassName class name to check
     * @return true if the class could be loaded by the thread's conext class loader, false otherwise
     */
    public static boolean checkForClass(String pClassName) {
        return ClassUtil.classForName(pClassName, false) != null;
    }

    /**
     * Instantiate an instance of the given class with its default constructor. The context class loader is used
     * to lookup the class
     *
     * @param pClassName name of class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(String pClassName, Object... pArguments) {
        Class<T> clazz = classForName(pClassName);
        if (clazz == null) {
            throw new IllegalArgumentException("Cannot find " + pClassName);
        }
        return newInstance(clazz, pArguments);
    }

    /**
     * Instantiate an instance of the given class with its default constructor
     *
     * @param pClass class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(Class<T> pClass, Object... pArguments) {
        try {
            if (pClass != null) {
                if (pArguments.length == 0) {
                    return pClass.newInstance();
                } else {
                    Constructor<T> ctr = lookupConstructor(pClass, pArguments);
                    return ctr.newInstance(pArguments);
                }
            } else {
                throw new IllegalArgumentException("Given class must not be null");
            }
        } catch (InstantiationException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        }
    }

    /**
     * Apply a method to a given object with optional arguments. The method is looked up the whole class
     * hierarchy.
     *
     * @param pObject object on which to apply the method
     * @param pMethod the method name
     * @param pArgs optional arguments
     * @return return value (if any)
     */
    public static Object applyMethod(Object pObject, String pMethod, Object... pArgs) {
        Class<?> clazz = pObject.getClass();
        try {
            Method method = extractMethod(pMethod, clazz, pArgs);
            return method.invoke(pObject, pArgs);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        }
    }

    /**
     * Get all resources from the classpath which are specified by the given path.
     *
     * @param pResource resource specification to use for lookup
     * @return the list or URLs to loookup
     */
    public static Set<String> getResources(String pResource) throws IOException {
        List<ClassLoader> clls = findClassLoaders();
        if (clls.size() != 0) {
            Set<String> ret = new HashSet<String>();
            for (ClassLoader cll : clls) {
                Enumeration<URL> urlEnum = cll.getResources(pResource);
                ret.addAll(extractUrlAsStringsFromEnumeration(urlEnum));
            }
            return ret;
        } else {
            return extractUrlAsStringsFromEnumeration(ClassLoader.getSystemResources(pResource));
        }
    }

    private static Set<String> extractUrlAsStringsFromEnumeration(Enumeration<URL> urlEnum) {
        Set<String> ret = new HashSet<String>();
        while (urlEnum.hasMoreElements()) {
            ret.add(urlEnum.nextElement().toExternalForm());
        }
        return ret;
    }

    // Lookup appropriate constructor
    private static <T> Constructor<T> lookupConstructor(Class<T> clazz, Object[] pArguments) throws NoSuchMethodException {
        Class[] argTypes = extractArgumentTypes(pArguments);
        return clazz.getConstructor(argTypes);
    }

    private static Method extractMethod(String pMethod, Class<?> clazz, Object[] pArgs) throws NoSuchMethodException {
        for (Method method : clazz.getMethods()) {
            if (!method.getName().equals(pMethod)) {
                continue;
            }
            Class[] parameters = method.getParameterTypes();
            if (parametersMatch(parameters, pArgs)) {
                return method;
            }
        }
        throw new NoSuchMethodException("No " + pMethod + " on " + clazz + " with " + pArgs.length + " arguments found ");
    }

    private static Class[] extractArgumentTypes(Object[] pArguments) {
        Class[] argTypes = new Class[pArguments.length];
        int i = 0;
        for (Object arg : pArguments) {
            argTypes[i++] = arg.getClass();
        }
        return argTypes;
    }

    private static boolean parametersMatch(Class[] parameters, Object[] pArgs) {
        if (parameters.length != pArgs.length) {
            return false;
        }
        for (int i = 0; i < parameters.length; i++) {
            if (pArgs[i] == null) {
                continue;
            }
            Class argClass = pArgs[i].getClass();
            Class paramClass = parameters[i];
            if (!paramClass.isAssignableFrom(argClass)) {
                if (checkForPrimitive(argClass, paramClass)) {
                    continue;
                }
                return false;
            }
        }
        return true;
    }

    private static boolean checkForPrimitive(Class argClass, Class paramClass) {
        return paramClass.isPrimitive() && PRIMITIVE_TO_OBJECT_MAP.get(paramClass.getName()) != null;
    }

    private static final Map<String, Class> PRIMITIVE_TO_OBJECT_MAP = new HashMap<String, Class>();

    static {
        PRIMITIVE_TO_OBJECT_MAP.put("int", Integer.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("long", Long.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("double", Double.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("float", Float.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("bool", Boolean.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("char", Character.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("byte", Byte.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("void", Void.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("short", Short.TYPE);
    }
}


for (int i = 0; i < parameters.length; i++) {
            if (pArgs[i] == null) {
                continue;
            }
            Class argClass = pArgs[i].getClass();
            Class paramClass = parameters[i];
            if (!paramClass.isAssignableFrom(argClass)) {
                if (checkForPrimitive(argClass, paramClass)) {
                    continue;
                }
                return false;
            }
        }

package org.jolokia.util;

import java.io.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.*;

/**
 * Utility for class lookup.
 *
 * @author roland
 * @since 19.04.11
 */
public final class ClassUtil {

    private ClassUtil() {
    }

    /**
     * Lookup a class. See {@link ClassUtil#classForName(String, boolean,ClassLoader[])} for details. The class
     * gets initialized during lookup.
     *
     * @param pClassName name to lookup.
     * @return the class found or null if no class could be found.
     */
    public static <T> Class<T> classForName(String pClassName, ClassLoader... pClassLoaders) {
        return classForName(pClassName, true, pClassLoaders);
    }

    /**
     * Load a certain class. Several class loader are tried: Fires the current thread's context
     * class loader, then its parents. If this doesn't work, the class loader which
     * loaded this class is used (and its parents)
     *
     * @param pClassName class name to load
     * @param pInitialize whether the class must be initialized
     * @param pClassLoaders optional class loaders which are tried as well
     * @return the class class found or null if no class could be loaded
     */
    public static <T> Class<T> classForName(String pClassName, boolean pInitialize, ClassLoader... pClassLoaders) {
        Set<ClassLoader> tried = new HashSet<ClassLoader>();
        for (ClassLoader loader : findClassLoaders(pClassLoaders)) {
            // Go up the classloader stack to eventually find the server class. Sometimes the WebAppClassLoader
            // hide the server classes loaded by the parent class loader.
            while (loader != null) {
                try {
                    if (!tried.contains(loader)) {
                        return (Class<T>) Class.forName(pClassName, pInitialize, loader);
                    }
                } catch (ClassNotFoundException ignored) {
                }
                tried.add(loader);
                loader = loader.getParent();
            }
        }
        return null;
    }

    private static List<ClassLoader> findClassLoaders(ClassLoader... pClassLoaders) {
        List<ClassLoader> classLoadersToTry = new ArrayList<ClassLoader>(Arrays.asList(pClassLoaders));
        classLoadersToTry.add(Thread.currentThread().getContextClassLoader());
        classLoadersToTry.add(ClassUtil.class.getClassLoader());
        List<ClassLoader> ret = new ArrayList<ClassLoader>();
        Set<ClassLoader> visited = new HashSet<ClassLoader>();
        for (ClassLoader cll : classLoadersToTry) {
            if (cll != null && !visited.contains(cll)) {
                ret.add(cll);
                visited.add(cll);
            }
        }
        return ret;
    }

    /**
     * Get the given path as an input stream or return null if not found
     *
     * @param pPath path to lookup
     * @return input stream or null if not found.
     */
    public static InputStream getResourceAsStream(String pPath) {
        for (ClassLoader loader : new ClassLoader[] { Thread.currentThread().getContextClassLoader(), ClassUtil.class.getClassLoader() }) {
            if (loader != null) {
                InputStream is = loader.getResourceAsStream(pPath);
                if (is != null) {
                    return is;
                }
            }
        }
        return null;
    }

    /**
     * Check for the existence of a given class
     *
     * @param pClassName class name to check
     * @return true if the class could be loaded by the thread's conext class loader, false otherwise
     */
    public static boolean checkForClass(String pClassName) {
        return ClassUtil.classForName(pClassName, false) != null;
    }

    /**
     * Instantiate an instance of the given class with its default constructor. The context class loader is used
     * to lookup the class
     *
     * @param pClassName name of class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(String pClassName, Object... pArguments) {
        Class<T> clazz = classForName(pClassName);
        if (clazz == null) {
            throw new IllegalArgumentException("Cannot find " + pClassName);
        }
        return newInstance(clazz, pArguments);
    }

    /**
     * Instantiate an instance of the given class with its default constructor
     *
     * @param pClass class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(Class<T> pClass, Object... pArguments) {
        try {
            if (pClass != null) {
                if (pArguments.length == 0) {
                    return pClass.newInstance();
                } else {
                    Constructor<T> ctr = lookupConstructor(pClass, pArguments);
                    return ctr.newInstance(pArguments);
                }
            } else {
                throw new IllegalArgumentException("Given class must not be null");
            }
        } catch (InstantiationException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        }
    }

    /**
     * Apply a method to a given object with optional arguments. The method is looked up the whole class
     * hierarchy.
     *
     * @param pObject object on which to apply the method
     * @param pMethod the method name
     * @param pArgs optional arguments
     * @return return value (if any)
     */
    public static Object applyMethod(Object pObject, String pMethod, Object... pArgs) {
        Class<?> clazz = pObject.getClass();
        try {
            Method method = extractMethod(pMethod, clazz, pArgs);
            return method.invoke(pObject, pArgs);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        }
    }

    /**
     * Get all resources from the classpath which are specified by the given path.
     *
     * @param pResource resource specification to use for lookup
     * @return the list or URLs to loookup
     */
    public static Set<String> getResources(String pResource) throws IOException {
        List<ClassLoader> clls = findClassLoaders();
        if (clls.size() != 0) {
            Set<String> ret = new HashSet<String>();
            for (ClassLoader cll : clls) {
                Enumeration<URL> urlEnum = cll.getResources(pResource);
                ret.addAll(extractUrlAsStringsFromEnumeration(urlEnum));
            }
            return ret;
        } else {
            return extractUrlAsStringsFromEnumeration(ClassLoader.getSystemResources(pResource));
        }
    }

    private static Set<String> extractUrlAsStringsFromEnumeration(Enumeration<URL> urlEnum) {
        Set<String> ret = new HashSet<String>();
        while (urlEnum.hasMoreElements()) {
            ret.add(urlEnum.nextElement().toExternalForm());
        }
        return ret;
    }

    // Lookup appropriate constructor
    private static <T> Constructor<T> lookupConstructor(Class<T> clazz, Object[] pArguments) throws NoSuchMethodException {
        Class[] argTypes = extractArgumentTypes(pArguments);
        return clazz.getConstructor(argTypes);
    }

    private static Method extractMethod(String pMethod, Class<?> clazz, Object[] pArgs) throws NoSuchMethodException {
        for (Method method : clazz.getMethods()) {
            if (!method.getName().equals(pMethod)) {
                continue;
            }
            Class[] parameters = method.getParameterTypes();
            if (parametersMatch(parameters, pArgs)) {
                return method;
            }
        }
        throw new NoSuchMethodException("No " + pMethod + " on " + clazz + " with " + pArgs.length + " arguments found ");
    }

    private static Class[] extractArgumentTypes(Object[] pArguments) {
        Class[] argTypes = new Class[pArguments.length];
        int i = 0;
        for (Object arg : pArguments) {
            argTypes[i++] = arg.getClass();
        }
        return argTypes;
    }

    private static boolean parametersMatch(Class[] parameters, Object[] pArgs) {
        if (parameters.length != pArgs.length) {
            return false;
        }

        return true;
    }

    private static boolean checkForPrimitive(Class argClass, Class paramClass) {
        return paramClass.isPrimitive() && PRIMITIVE_TO_OBJECT_MAP.get(paramClass.getName()) != null;
    }

    private static final Map<String, Class> PRIMITIVE_TO_OBJECT_MAP = new HashMap<String, Class>();

    static {
        PRIMITIVE_TO_OBJECT_MAP.put("int", Integer.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("long", Long.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("double", Double.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("float", Float.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("bool", Boolean.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("char", Character.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("byte", Byte.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("void", Void.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("short", Short.TYPE);
    }
}


while (loader != null) {
                try {
                    if (!tried.contains(loader)) {
                        return (Class<T>) Class.forName(pClassName, pInitialize, loader);
                    }
                } catch (ClassNotFoundException ignored) {
                }
                tried.add(loader);
                loader = loader.getParent();
            }

package org.jolokia.util;

import java.io.*;
import java.lang.reflect.*;
import java.net.URL;
import java.util.*;

/**
 * Utility for class lookup.
 *
 * @author roland
 * @since 19.04.11
 */
public final class ClassUtil {

    private ClassUtil() {
    }

    /**
     * Lookup a class. See {@link ClassUtil#classForName(String, boolean,ClassLoader[])} for details. The class
     * gets initialized during lookup.
     *
     * @param pClassName name to lookup.
     * @return the class found or null if no class could be found.
     */
    public static <T> Class<T> classForName(String pClassName, ClassLoader... pClassLoaders) {
        return classForName(pClassName, true, pClassLoaders);
    }

    /**
     * Load a certain class. Several class loader are tried: Fires the current thread's context
     * class loader, then its parents. If this doesn't work, the class loader which
     * loaded this class is used (and its parents)
     *
     * @param pClassName class name to load
     * @param pInitialize whether the class must be initialized
     * @param pClassLoaders optional class loaders which are tried as well
     * @return the class class found or null if no class could be loaded
     */
    public static <T> Class<T> classForName(String pClassName, boolean pInitialize, ClassLoader... pClassLoaders) {
        Set<ClassLoader> tried = new HashSet<ClassLoader>();
        for (ClassLoader loader : findClassLoaders(pClassLoaders)) {
            // Go up the classloader stack to eventually find the server class. Sometimes the WebAppClassLoader
            // hide the server classes loaded by the parent class loader.

}
        return null;
    }

    private static List<ClassLoader> findClassLoaders(ClassLoader... pClassLoaders) {
        List<ClassLoader> classLoadersToTry = new ArrayList<ClassLoader>(Arrays.asList(pClassLoaders));
        classLoadersToTry.add(Thread.currentThread().getContextClassLoader());
        classLoadersToTry.add(ClassUtil.class.getClassLoader());
        List<ClassLoader> ret = new ArrayList<ClassLoader>();
        Set<ClassLoader> visited = new HashSet<ClassLoader>();
        for (ClassLoader cll : classLoadersToTry) {
            if (cll != null && !visited.contains(cll)) {
                ret.add(cll);
                visited.add(cll);
            }
        }
        return ret;
    }

    /**
     * Get the given path as an input stream or return null if not found
     *
     * @param pPath path to lookup
     * @return input stream or null if not found.
     */
    public static InputStream getResourceAsStream(String pPath) {
        for (ClassLoader loader : new ClassLoader[] { Thread.currentThread().getContextClassLoader(), ClassUtil.class.getClassLoader() }) {
            if (loader != null) {
                InputStream is = loader.getResourceAsStream(pPath);
                if (is != null) {
                    return is;
                }
            }
        }
        return null;
    }

    /**
     * Check for the existence of a given class
     *
     * @param pClassName class name to check
     * @return true if the class could be loaded by the thread's conext class loader, false otherwise
     */
    public static boolean checkForClass(String pClassName) {
        return ClassUtil.classForName(pClassName, false) != null;
    }

    /**
     * Instantiate an instance of the given class with its default constructor. The context class loader is used
     * to lookup the class
     *
     * @param pClassName name of class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(String pClassName, Object... pArguments) {
        Class<T> clazz = classForName(pClassName);
        if (clazz == null) {
            throw new IllegalArgumentException("Cannot find " + pClassName);
        }
        return newInstance(clazz, pArguments);
    }

    /**
     * Instantiate an instance of the given class with its default constructor
     *
     * @param pClass class to instantiate
     * @param pArguments optional constructor arguments. Works only for objects with the same class as declared in
     *                   the constructor types (no subclasses)
     * @param <T> type object type
     * @return instantiated object
     * @throws IllegalArgumentException if the class could not be found or instantiated
     */
    public static <T> T newInstance(Class<T> pClass, Object... pArguments) {
        try {
            if (pClass != null) {
                if (pArguments.length == 0) {
                    return pClass.newInstance();
                } else {
                    Constructor<T> ctr = lookupConstructor(pClass, pArguments);
                    return ctr.newInstance(pArguments);
                }
            } else {
                throw new IllegalArgumentException("Given class must not be null");
            }
        } catch (InstantiationException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot instantiate " + pClass + ": " + e, e);
        }
    }

    /**
     * Apply a method to a given object with optional arguments. The method is looked up the whole class
     * hierarchy.
     *
     * @param pObject object on which to apply the method
     * @param pMethod the method name
     * @param pArgs optional arguments
     * @return return value (if any)
     */
    public static Object applyMethod(Object pObject, String pMethod, Object... pArgs) {
        Class<?> clazz = pObject.getClass();
        try {
            Method method = extractMethod(pMethod, clazz, pArgs);
            return method.invoke(pObject, pArgs);
        } catch (NoSuchMethodException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (InvocationTargetException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        } catch (IllegalAccessException e) {
            throw new IllegalArgumentException("Cannot call method " + pMethod + " on " + pObject + ": " + e, e);
        }
    }

    /**
     * Get all resources from the classpath which are specified by the given path.
     *
     * @param pResource resource specification to use for lookup
     * @return the list or URLs to loookup
     */
    public static Set<String> getResources(String pResource) throws IOException {
        List<ClassLoader> clls = findClassLoaders();
        if (clls.size() != 0) {
            Set<String> ret = new HashSet<String>();
            for (ClassLoader cll : clls) {
                Enumeration<URL> urlEnum = cll.getResources(pResource);
                ret.addAll(extractUrlAsStringsFromEnumeration(urlEnum));
            }
            return ret;
        } else {
            return extractUrlAsStringsFromEnumeration(ClassLoader.getSystemResources(pResource));
        }
    }

    private static Set<String> extractUrlAsStringsFromEnumeration(Enumeration<URL> urlEnum) {
        Set<String> ret = new HashSet<String>();
        while (urlEnum.hasMoreElements()) {
            ret.add(urlEnum.nextElement().toExternalForm());
        }
        return ret;
    }

    // Lookup appropriate constructor
    private static <T> Constructor<T> lookupConstructor(Class<T> clazz, Object[] pArguments) throws NoSuchMethodException {
        Class[] argTypes = extractArgumentTypes(pArguments);
        return clazz.getConstructor(argTypes);
    }

    private static Method extractMethod(String pMethod, Class<?> clazz, Object[] pArgs) throws NoSuchMethodException {
        for (Method method : clazz.getMethods()) {
            if (!method.getName().equals(pMethod)) {
                continue;
            }
            Class[] parameters = method.getParameterTypes();
            if (parametersMatch(parameters, pArgs)) {
                return method;
            }
        }
        throw new NoSuchMethodException("No " + pMethod + " on " + clazz + " with " + pArgs.length + " arguments found ");
    }

    private static Class[] extractArgumentTypes(Object[] pArguments) {
        Class[] argTypes = new Class[pArguments.length];
        int i = 0;
        for (Object arg : pArguments) {
            argTypes[i++] = arg.getClass();
        }
        return argTypes;
    }

    private static boolean parametersMatch(Class[] parameters, Object[] pArgs) {
        if (parameters.length != pArgs.length) {
            return false;
        }
        for (int i = 0; i < parameters.length; i++) {
            if (pArgs[i] == null) {
                continue;
            }
            Class argClass = pArgs[i].getClass();
            Class paramClass = parameters[i];
            if (!paramClass.isAssignableFrom(argClass)) {
                if (checkForPrimitive(argClass, paramClass)) {
                    continue;
                }
                return false;
            }
        }
        return true;
    }

    private static boolean checkForPrimitive(Class argClass, Class paramClass) {
        return paramClass.isPrimitive() && PRIMITIVE_TO_OBJECT_MAP.get(paramClass.getName()) != null;
    }

    private static final Map<String, Class> PRIMITIVE_TO_OBJECT_MAP = new HashMap<String, Class>();

    static {
        PRIMITIVE_TO_OBJECT_MAP.put("int", Integer.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("long", Long.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("double", Double.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("float", Float.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("bool", Boolean.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("char", Character.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("byte", Byte.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("void", Void.TYPE);
        PRIMITIVE_TO_OBJECT_MAP.put("short", Short.TYPE);
    }
}