/**
 * 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.woinject;

import java.security.AccessController;
import java.security.PrivilegedAction;

import javassist.ClassPool;
import javassist.CtClass;
import javassist.CtMethod;
import javassist.Loader;

/**
 * Experiment to avoid inheritance of Application, Session, DirectAction and
 * EnterpriseObject classes.
 * <p>
 * How to use:
 * 
 * <pre>
 * public static void main(String[] argv) {
 *     WOInject.main(argv, &quot;com.company.app.Application&quot;);
 * }
 * </pre>
 * 
 * @author <a href="mailto:hprange@gmail.com">Henrique Prange</a>
 * @since 1.0
 */
public class WOInject {
    public static void main(String[] args, String applicationClass) {
	final ClassPool pool = ClassPool.getDefault();

	Loader loader = AccessController.doPrivileged(new PrivilegedAction<Loader>() {
	    public Loader run() {
		return new Loader(pool);
	    }
	});

	try {
	    CtClass clazz = pool.get("com.webobjects.foundation._NSUtilities");
	    CtMethod method = clazz.getDeclaredMethod("instantiateObject");

	    method.insertBefore("{ return com.webobjects.foundation.InstantiationInterceptor.instantiateObject($1, $2, $3, $4, $5); }");

	    method = clazz.getDeclaredMethod("instantiateObjectWithConstructor");

	    method.insertBefore("{ return com.webobjects.foundation.InstantiationInterceptor.instantiateObject($1, $2, $3, $4, $5); }");

	    Thread.currentThread().setContextClassLoader(loader);

	    Class<?> erxApp = loader.loadClass("er.extensions.appserver.ERXApplication");

	    Class<?> app = loader.loadClass(applicationClass);

	    Class<?> injectableApp = loader.loadClass("com.woinject.InjectableApplication");

	    if (!injectableApp.isAssignableFrom(app)) {
		throw new Error("Cannot initialize the injector. The Application class doesn't extend InjectableApplication.");
	    }

	    erxApp.getDeclaredMethod("main", String[].class, Class.class).invoke(null, args, app);
	} catch (Throwable exception) {
	    throw new Error("Cannot initialize the application to take advantage of WOInject features.", exception);
	}
    }
}

@@ -1210,47 +1210,298 @@
     
-public static void main(String%5B%5D args, 
+/**%0A     * Initialize the %3Ccode%3EWOApplication%3C/code%3E with the WOInject capabilities.%0A     * %0A     * @param applicationClass%0A     *            the name of the application class%0A     * @param args%0A     *            the application's command line arguments%0A     */%0A    public static void init(
 Stri
@@ -1519,16 +1519,31 @@
 ionClass
+, String%5B%5D args
 ) %7B%0A%09fin

Rename the WOInject initialization method