protected Factory getFactory()

in src/java/org/apache/fulcrum/factory/DefaultFactoryService.java [471:511]


	protected <T> Factory<T> getFactory(String className) throws FactoryException 
	{
		Factory<T> factory = (Factory<T>) objectFactories.get(className);
		if (factory == null) 
		{
			// No named factory for this; try the default, if one exists
			factory = (Factory<T>) objectFactories.get(DEFAULT_FACTORY);
		}
		
		if (factory == null) {
			
			/* Not yet instantiated... */
			String factoryClass = objectFactoryClasses.get(className);
			if (factoryClass == null) 
			{
				factoryClass = objectFactoryClasses.get(DEFAULT_FACTORY);
			}
			
			if (factoryClass == null) {
				return null;
			}

			try {
				factory = getInstance(factoryClass);
				factory.init(className);
			} 
			catch (ClassCastException x) 
			{
				throw new FactoryException("Incorrect factory " + factoryClass + " for class " + className, x);
			}
			
			Factory<T> _factory = (Factory<T>) objectFactories.putIfAbsent(className, factory);
			if (_factory != null) 
			{
				// Already created - take first instance
				factory = _factory;
			}
		}

		return factory;
	}