/*
 * Copyright 2016 Red Hat, Inc, and individual contributors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.projectodd.vdx.core;

import org.projectodd.vdx.core.handlers.DuplicateAttributeHandler;
import org.projectodd.vdx.core.handlers.DuplicateElementHandler;
import org.projectodd.vdx.core.handlers.InvalidAttributeValueHandler;
import org.projectodd.vdx.core.handlers.RequiredAttributeMissingHandler;
import org.projectodd.vdx.core.handlers.RequiredElementMissingHandler;
import org.projectodd.vdx.core.handlers.RequiredElementsMissingHandler;
import org.projectodd.vdx.core.handlers.UnexpectedAttributeHandler;
import org.projectodd.vdx.core.handlers.UnexpectedElementHandler;
import org.projectodd.vdx.core.handlers.UnknownErrorHandler;
import org.projectodd.vdx.core.handlers.UnsupportedElementHandler;

public enum ErrorType {
    DUPLICATE_ATTRIBUTE(DuplicateAttributeHandler.class),
    DUPLICATE_ELEMENT(DuplicateElementHandler.class),
    INVALID_ATTRIBUTE_VALUE(InvalidAttributeValueHandler.class),
    REQUIRED_ATTRIBUTE_MISSING(RequiredAttributeMissingHandler.class),
    REQUIRED_ELEMENT_MISSING(RequiredElementMissingHandler.class),
    REQUIRED_ELEMENTS_MISSING(RequiredElementsMissingHandler.class),
    UNEXPECTED_ATTRIBUTE(UnexpectedAttributeHandler.class),
    UNEXPECTED_ELEMENT(UnexpectedElementHandler.class),
    UNKNOWN_ERROR(UnknownErrorHandler.class),
    UNSUPPORTED_ELEMENT(UnsupportedElementHandler.class);

    private final Class<? extends ErrorHandler> handlerClass;

    public ErrorHandler handler() {
        try {
            return this.handlerClass.newInstance();
        } catch (IllegalAccessException | InstantiationException e) {
            throw new RuntimeException(e);
        }
    }

    ErrorType(Class<? extends ErrorHandler> handlerClass) {
        this.handlerClass = handlerClass;
    }
}

@@ -650,16 +650,159 @@
 .core;%0A%0A
+import java.lang.reflect.Constructor;%0Aimport java.lang.reflect.InvocationTargetException;%0Aimport java.util.Arrays;%0Aimport java.util.Optional;%0A%0A
 import o
@@ -2232,32 +2232,422 @@
     
-return this.handlerClass
+Optional%3CConstructor%3C?%3E%3E ctor = Arrays.stream(this.handlerClass.getConstructors())%0A                    .filter(c -%3E c.getGenericParameterTypes().length == 0)%0A                    .findFirst();%0A%0A            if (!ctor.isPresent()) %7B%0A%0A                throw new RuntimeException(%22Class %22 + this.handlerClass.getCanonicalName() + %22 has no 0-arity constructor%22);%0A            %7D%0A%0A            return (ErrorHandler)ctor.get()
 .new
@@ -2727,13 +2727,42 @@
 ion 
+%7C InvocationTargetException 
 e) %7B%0A
+%0A
     

Use Constructor.newInstance() instead of deprecated Object.newInstance()