// Path: src/main/java/com/woinject/InjectableApplication.java
// public abstract class InjectableApplication extends ERXApplication {
//     public static InjectableApplication application() {
//         return (InjectableApplication) WOApplication.application();
//     }
// 
//     private final Injector injector;
// 
//     /**
//      * Creates an instance of an <code>InjectableApplication</code>. The methods
//      * and fields annotated with the <code>@Inject</code> will be injected
//      * during the application construction. Constructor injection is not
//      * supported at the present time.
//      * 
//      * @see Inject
//      */
//     public InjectableApplication() {
//         super();
// 
//         injector = createInjector();
// 
//         injector.injectMembers(this);
//     }
// 
//     /**
//      * Creates the injector to be used by the entire application.
//      * <p>
//      * The <code>WOInjectModule</code> is loaded by default in addition to all
//      * the <code>Module</code>s returned by the
//      * {@link InjectableApplication#modules()} method.
//      * <p>
//      * Override this method to create your own injector.
//      *
//      * @return The main <code>Injector</code> for the entire application
//      *
//      * @see Injector
//      * @see WOInjectModule
//      */
//     protected Injector createInjector() {
//         List<Module> modules = new ArrayList<Module>();
// 
//         @SuppressWarnings("unchecked")
//         Class<? extends WOSession> sessionClass = _sessionClass();
// 
//         modules.add(new WOInjectModule(sessionClass));
//         modules.addAll(Arrays.asList(modules()));
// 
//         return Guice.createInjector(stage(), modules);
//     }
// 
//     /**
//      * Obtain the injector created for this application.
//      * 
//      * @return The injector created during this application initialization
//      */
//     public Injector injector() {
//         return injector;
//     }
// 
//     /**
//      * Override this method to inform what <code>Module</code>s should be loaded
//      * by the injector during the initialization phase.
//      * 
//      * @return An array of <code>Module</code>s to be loaded when creating the
//      *         injector
//      * 
//      * @see InjectableApplication#createInjector()
//      * @see Module
//      */
//     protected Module[] modules() {
//         return new Module[] {};
//     }
// 
//     /**
//      * Obtain the <code>Stage</code> in which the application is running. This
//      * stage is to be used by the injector.
//      *
//      * Override this method to inform the stage in which the application is
//      * running
//      *
//      * @return The stage in which the application is running
//      * @see Stage
//      */
//     protected Stage stage() {
//         return isDevelopmentMode() ? Stage.DEVELOPMENT : Stage.PRODUCTION;
//     }
// }
// 
// Path: src/main/java/com/woinject/WOInjectException.java
// public class WOInjectException extends RuntimeException {
//     public WOInjectException() {
//         super();
//     }
// 
//     public WOInjectException(String message) {
//         super(message);
//     }
// 
//     public WOInjectException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public WOInjectException(Throwable cause) {
//         super(cause);
//     }
// }


import com.google.inject.Injector;
import com.woinject.InjectableApplication;
import com.woinject.WOInjectException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Constructor;
/**
 * Copyright (C) 2010 hprange <hprange@gmail.com>
 *
 * 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 com.webobjects.foundation;



/**
 * The InstantiatorInterceptor class creates objects and injects their
 * members (methods and fields only) automatically. This class is private
 * and is not intended to be used directly by users.
 *
 * @author <a href="mailto:hprange@gmail.com.br">Henrique Prange</a>
 * @since 1.0
 */
class InstantiationInterceptor {
    private static final Logger LOGGER = LoggerFactory.getLogger(InstantiationInterceptor.class);

    private static <T> Constructor<T> findConstructor(final Class<T> type, final Class<?>[] parameterTypes, boolean shouldThrow, boolean shouldLog) {
        try {
            return type.getConstructor(parameterTypes);
        } catch (Exception exception) {
            return handleException(type, exception, shouldThrow, shouldLog);
        }
    }

    private static <T, N> N handleException(Class<T> type, Exception exception, boolean shouldThrow, boolean shouldLog) {
        if (shouldLog) {
            LOGGER.error("The instantiation of " + type.getName() + " class has failed.", exception);
        }

        if (!shouldThrow) {
            return null;
        }

        throw new WOInjectException("The instantiation of " + type.getName() + " class has failed.", exception);
    }

    private static Injector injector() {
// Path: src/main/java/com/woinject/InjectableApplication.java
// public abstract class InjectableApplication extends ERXApplication {
//     public static InjectableApplication application() {
//         return (InjectableApplication) WOApplication.application();
//     }
// 
//     private final Injector injector;
// 
//     /**
//      * Creates an instance of an <code>InjectableApplication</code>. The methods
//      * and fields annotated with the <code>@Inject</code> will be injected
//      * during the application construction. Constructor injection is not
//      * supported at the present time.
//      * 
//      * @see Inject
//      */
//     public InjectableApplication() {
//         super();
// 
//         injector = createInjector();
// 
//         injector.injectMembers(this);
//     }
// 
//     /**
//      * Creates the injector to be used by the entire application.
//      * <p>
//      * The <code>WOInjectModule</code> is loaded by default in addition to all
//      * the <code>Module</code>s returned by the
//      * {@link InjectableApplication#modules()} method.
//      * <p>
//      * Override this method to create your own injector.
//      *
//      * @return The main <code>Injector</code> for the entire application
//      *
//      * @see Injector
//      * @see WOInjectModule
//      */
//     protected Injector createInjector() {
//         List<Module> modules = new ArrayList<Module>();
// 
//         @SuppressWarnings("unchecked")
//         Class<? extends WOSession> sessionClass = _sessionClass();
// 
//         modules.add(new WOInjectModule(sessionClass));
//         modules.addAll(Arrays.asList(modules()));
// 
//         return Guice.createInjector(stage(), modules);
//     }
// 
//     /**
//      * Obtain the injector created for this application.
//      * 
//      * @return The injector created during this application initialization
//      */
//     public Injector injector() {
//         return injector;
//     }
// 
//     /**
//      * Override this method to inform what <code>Module</code>s should be loaded
//      * by the injector during the initialization phase.
//      * 
//      * @return An array of <code>Module</code>s to be loaded when creating the
//      *         injector
//      * 
//      * @see InjectableApplication#createInjector()
//      * @see Module
//      */
//     protected Module[] modules() {
//         return new Module[] {};
//     }
// 
//     /**
//      * Obtain the <code>Stage</code> in which the application is running. This
//      * stage is to be used by the injector.
//      *
//      * Override this method to inform the stage in which the application is
//      * running
//      *
//      * @return The stage in which the application is running
//      * @see Stage
//      */
//     protected Stage stage() {
//         return isDevelopmentMode() ? Stage.DEVELOPMENT : Stage.PRODUCTION;
//     }
// }
// 
// Path: src/main/java/com/woinject/WOInjectException.java
// public class WOInjectException extends RuntimeException {
//     public WOInjectException() {
//         super();
//     }
// 
//     public WOInjectException(String message) {
//         super(message);
//     }
// 
//     public WOInjectException(String message, Throwable cause) {
//         super(message, cause);
//     }
// 
//     public WOInjectException(Throwable cause) {
//         super(cause);
//     }
// }


// Path: src/main/java/com/webobjects/foundation/InstantiationInterceptor.java
import com.google.inject.Injector;
import com.woinject.InjectableApplication;
import com.woinject.WOInjectException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.lang.reflect.Constructor;

/**
 * Copyright (C) 2010 hprange <hprange@gmail.com>
 *
 * 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 com.webobjects.foundation;



/**
 * The InstantiatorInterceptor class creates objects and injects their
 * members (methods and fields only) automatically. This class is private
 * and is not intended to be used directly by users.
 *
 * @author <a href="mailto:hprange@gmail.com.br">Henrique Prange</a>
 * @since 1.0
 */
class InstantiationInterceptor {
    private static final Logger LOGGER = LoggerFactory.getLogger(InstantiationInterceptor.class);

    private static <T> Constructor<T> findConstructor(final Class<T> type, final Class<?>[] parameterTypes, boolean shouldThrow, boolean shouldLog) {
        try {
            return type.getConstructor(parameterTypes);
        } catch (Exception exception) {
            return handleException(type, exception, shouldThrow, shouldLog);
        }
    }

    private static <T, N> N handleException(Class<T> type, Exception exception, boolean shouldThrow, boolean shouldLog) {
        if (shouldLog) {
            LOGGER.error("The instantiation of " + type.getName() + " class has failed.", exception);
        }

        if (!shouldThrow) {
            return null;
        }

        throw new WOInjectException("The instantiation of " + type.getName() + " class has failed.", exception);
    }

    private static Injector injector() {
        InjectableApplication application = InjectableApplication.application();