/**
 * 
 */
package org.richfaces.ui.application;

import javax.faces.application.Application;
import javax.faces.application.ApplicationFactory;

/**
 * @author asmirnov
 *
 */
public class StateApplicationFactory extends ApplicationFactory {

	private ApplicationFactory parent;
	
	private Application application;
	
	/**
	 * @param parent
	 */
	public StateApplicationFactory(ApplicationFactory parent) {
		super();
		this.parent = parent;
	}


	/* (non-Javadoc)
	 * @see javax.faces.application.ApplicationFactory#getApplication()
	 */
	@Override
	public Application getApplication() {
		if (application == null) {
			application = new StateApplication(parent.getApplication());
			
		}

		return application;
	}

	/* (non-Javadoc)
	 * @see javax.faces.application.ApplicationFactory#setApplication(javax.faces.application.Application)
	 */
	@Override
	public void setApplication(Application application) {
		parent.setApplication(application);
		this.application = new StateApplication(application);
	}

}
