package org.jboss.resteasy.spi.metadata;

import java.lang.reflect.Constructor;
import java.lang.reflect.Parameter;

/**
 * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
 * @version $Revision: 1 $
 */
public class DefaultResourceConstructor implements ResourceConstructor {
    protected ResourceClass resourceClass;
    protected Constructor constructor;
    protected ConstructorParameter[] params = {};

    public DefaultResourceConstructor(final ResourceClass resourceClass, final Constructor constructor) {
        this.resourceClass = resourceClass;
        this.constructor = constructor;
        if (constructor.getParameterTypes() != null) {
            this.params = new ConstructorParameter[constructor.getParameterCount()];
            Parameter[] reflectionParameters = constructor.getParameters();
            for (int i = 0; i < constructor.getParameterCount(); i++) {
                this.params[i] = new ConstructorParameter(this, reflectionParameters[i].getName(),
                        constructor.getParameterTypes()[i], constructor.getGenericParameterTypes()[i],
                        constructor.getParameterAnnotations()[i]);
            }
        }
    }

    @Override
    public ResourceClass getResourceClass() {
        return resourceClass;
    }

    @Override
    public Constructor getConstructor() {
        return constructor;
    }

    @Override
    public ConstructorParameter[] getParams() {
        return params;
    }
}
