/*
 * Copyright (c) 2010 Célio Cidral Junior
 * 
 *    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.tomighty.ioc;

import java.util.HashMap;
import java.util.Map;

public class Container {
	
	private final Factory factory = new Factory();
	
	private final Injector injector = new Injector();
	
	private final Map<Class<?>, Object> map = new HashMap<Class<?>, Object>();
	
	public Container() {
		map.put(Container.class, this);
		map.put(Factory.class, factory);
		map.put(Injector.class, injector);
		factory.container(this);
		injector.container(this);
	}
	
	public <T> T get(Class<T> clazz) {
		return get(clazz, null);
	}

	@SuppressWarnings("unchecked")
	public <T> T get(Class<T> clazz, Object needer) {
		Object instance = map.get(clazz);
		if(instance == null) {
			instance = factory.create(clazz, needer);
			map.put(clazz, instance);
		}
		return (T) instance;
	}

}

@@ -1211,16 +1211,317 @@
 %0D%0A%09%7D%0D%0A%0D%0A
+%09@SuppressWarnings(%22unchecked%22)%0D%0A%09public %3CT%3E T get(String className) %7B%0D%0A%09%09try %7B%0D%0A%09%09%09Class%3CT%3E clazz = (Class%3CT%3E) Class.forName(className);%0D%0A%09%09%09return get(clazz, null);%0D%0A%09%09%7D catch (ClassNotFoundException cause) %7B%0D%0A%09%09%09throw new IllegalArgumentException(%22Class not found: %22+className, cause);%0D%0A%09%09%7D%0D%0A%09%7D%0D%0A%0D%0A
 %09@Suppre

Add method to get objects by class name