All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.ajax4jsf.framework.renderer.ComponentRendererBase Maven / Gradle / Ivy

Go to download

Ajax4jsf is an open source extension to the JavaServer Faces standard that adds AJAX capability to JSF applications without requiring the writing of any JavaScript.

The newest version!
/**
 * Licensed under the Common Development and Distribution License,
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.sun.com/cddl/
 *   
 * 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.ajax4jsf.framework.renderer;

import java.util.HashMap;
import java.util.Stack;

import javax.faces.component.UIComponent;



/**
 * Components Base Renderer for all chameleon Skin's and components.
 * At most, make all common procedures and realise concrete work in "template" methods. 
 * @author [email protected] (latest modification by $Author: alexsmirnov $)
 * @version $Revision: 1.2 $ $Date: 2006/07/29 11:49:08 $
 *
 */
public abstract class ComponentRendererBase extends RendererBase{
	
	/**
	 * logger for common cases. 
	 */
	protected static final String COMPONENT_RENDERER_BASE = ComponentRendererBase.class.getName();


	public ComponentVariables  getVariables(UIComponent component) {
		HashMap components;
		Stack stackComponentsVariables;		
		ComponentVariables variables;
		
		
		
		components = (HashMap)component.getAttributes().get( COMPONENT_RENDERER_BASE );
		
		if ( components == null ) {
			components = new HashMap();
			component.getAttributes().put( COMPONENT_RENDERER_BASE, components );
		}

		stackComponentsVariables = (Stack)components.get( this.getClass().getName() );

		if ( stackComponentsVariables == null ) {
			stackComponentsVariables = new Stack();
			components.put( COMPONENT_RENDERER_BASE, stackComponentsVariables );	
		}

		if ( stackComponentsVariables.empty() ) {
			variables = new ComponentVariables();
			stackComponentsVariables.push( variables );
		} else {
			variables = (ComponentVariables)stackComponentsVariables.peek();
		}

		return variables;
	}

	public void removeVariables(UIComponent component) {
	        HashMap components;
                Stack stackComponentsVariables;
                ComponentVariables variables;



                components = (HashMap)component.getAttributes().get( COMPONENT_RENDERER_BASE );

                if ( components != null ) {
	
        	        stackComponentsVariables = (Stack)component.getAttributes().get( this.getClass().getName() );

                	if ( stackComponentsVariables != null ) {
                		if ( !stackComponentsVariables.empty() ) {
                			stackComponentsVariables.pop();
				}
				
				if ( stackComponentsVariables.empty()  ) {
					components.remove( this.getClass().getName() );
				}
			}

			if ( components.isEmpty()  ) {
                                component.getAttributes().remove( COMPONENT_RENDERER_BASE  );
                        }
				
					
                } 

	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy