[richfaces-svn-commits] JBoss Rich Faces SVN: r1412 - in branches/refactor1/framework: api/src/main/java/org/ajax4jsf/framework/renderer and 1 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Fri Jun 29 12:41:58 EDT 2007


Author: alexsmirnov
Date: 2007-06-29 12:41:58 -0400 (Fri, 29 Jun 2007)
New Revision: 1412

Added:
   branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxRenderer.java
   branches/refactor1/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java
Removed:
   branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java
Modified:
   branches/refactor1/framework/api/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java
Log:
Exstract AjaxRenderer interface

Modified: branches/refactor1/framework/api/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java
===================================================================
--- branches/refactor1/framework/api/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java	2007-06-29 16:37:49 UTC (rev 1411)
+++ branches/refactor1/framework/api/src/main/java/org/ajax4jsf/ajax/repeat/UIDataAdaptor.java	2007-06-29 16:41:58 UTC (rev 1412)
@@ -48,6 +48,7 @@
 import javax.faces.render.Renderer;
 
 import org.ajax4jsf.framework.renderer.AjaxChildrenRenderer;
+import org.ajax4jsf.framework.renderer.AjaxRenderer;
 
 /**
  * Base class for iterable components, like dataTable, Tomahawk dataList,
@@ -356,14 +357,14 @@
 	resetDataModel();
 
 	Renderer renderer = getRenderer(context);
-	if (null != renderer && renderer instanceof AjaxChildrenRenderer) {
+	if (null != renderer && renderer instanceof AjaxRenderer) {
 	    // If renderer support partial encoding - call them.
-	    AjaxChildrenRenderer childrenRenderer = (AjaxChildrenRenderer) renderer;
+	    AjaxRenderer childrenRenderer = (AjaxRenderer) renderer;
 	    childrenRenderer.encodeAjaxChildren(context, this, path, ids,
 		    renderedAreas);
 	} else {
 	    // Use simple ajax children encoding for iterate other keys.
-	    final AjaxChildrenRenderer childrenRenderer = getChildrenRenderer();
+	    final AjaxRenderer childrenRenderer = getChildrenRenderer();
 	    final String childrenPath = path + getId() + NamingContainer.SEPARATOR_CHAR;
 	    ComponentVisitor ajaxVisitor = new ComponentVisitor() {
 
@@ -399,7 +400,7 @@
     /**
          * Instance of default renderer in ajax responses.
          */
-    private AjaxChildrenRenderer _childrenRenderer = null;
+    private AjaxRenderer _childrenRenderer = null;
 
     /**
          * getter for simple {@link AjaxChildrenRenderer} instance in case of
@@ -409,7 +410,7 @@
          * 
          * @return
          */
-    protected AjaxChildrenRenderer getChildrenRenderer() {
+    protected AjaxRenderer getChildrenRenderer() {
 	if (_childrenRenderer == null) {
 	    _childrenRenderer = new AjaxChildrenRenderer() {
 

Deleted: branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java
===================================================================
--- branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java	2007-06-29 16:37:49 UTC (rev 1411)
+++ branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java	2007-06-29 16:41:58 UTC (rev 1412)
@@ -1,205 +0,0 @@
-/**
- * License Agreement.
- *
- * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
- */
-
-package org.ajax4jsf.framework.renderer;
-
-import java.io.IOException;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.faces.component.NamingContainer;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-
-import org.ajax4jsf.ajax.UILoadBundle;
-import org.ajax4jsf.framework.ajax.AjaxChildrenEncoder;
-import org.ajax4jsf.framework.ajax.AjaxOutput;
-import org.ajax4jsf.framework.util.message.Messages;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-/**
- * @author shura
- *
- */
-public abstract class AjaxChildrenRenderer extends AjaxComponentRendererBase {
-	
-	public static final Log log = LogFactory.getLog(AjaxChildrenRenderer.class);
-
-	public static final String[] SPECIAL_COMPONENTS_TYPES = {
-				UILoadBundle.COMPONENT_TYPE, "org.apache.myfaces.AliasBean",
-				"org.apache.myfaces.AliasBeansScope" };
-	private static final String SPECIAL_TYPES_PARAMETER = "org.ajax4jsf.CONTROL_COMPONENTS";
-
-	/**
-	 * Iterate over all childs of components. If component id contains in list ,
-	 * or, if list is empty, compotents is submitted form - render it. TODO -
-	 * Instead of calculate full path for every component, build current Path
-	 * for componet and send as parameter.
-	 * 
-	 * @param context -
-	 *            current context
-	 * @param component -
-	 *            curent faces component.
-	 * @param ids -
-	 *            list of Id to render.
-	 * @throws IOException
-	 * @deprecated Use {@link #encodeAjaxChildren(FacesContext,UIComponent,String,Set,Set)} instead
-	 */
-	public void encodeAjaxChild(FacesContext context, UIComponent component, String path, Set ids, Set renderedAreas) throws IOException {
-	    encodeAjaxChildren(context, component, path, ids, renderedAreas);
-	}
-
-	/**
-	 * Iterate over all childs of components. If component id contains in list ,
-	 * or, if list is empty, compotents is submitted form - render it. TODO -
-	 * Instead of calculate full path for every component, build current Path
-	 * for componet and send as parameter.
-	 * 
-	 * @param context -
-	 *            current context
-	 * @param component -
-	 *            curent faces component.
-	 * @param ids -
-	 *            list of Id to render.
-	 * @throws IOException
-	 */
-	public void encodeAjaxChildren(FacesContext context, UIComponent component, String path, Set ids, Set renderedAreas) throws IOException {
-		if (log.isDebugEnabled()) {
-			log.debug(Messages.getMessage(Messages.ENCODE_CHILD_AJAX_INFO,
-					path, component.getId()));
-		}
-		String currentPath = path;
-		if (component instanceof NamingContainer) {
-			currentPath += component.getId() + NamingContainer.SEPARATOR_CHAR;
-		}
-		for (Iterator it = component.getFacetsAndChildren(); it.hasNext();) {
-			UIComponent element = (UIComponent) it.next();
-			encodeAjaxComponent(context, element, currentPath, ids, renderedAreas);
-		}
-	}
-
-	/**
-	 * @param context
-	 * @param component
-	 * @param currentPath
-	 * @param ids
-	 * @param renderedAreas
-	 * @throws IOException
-	 */
-	public void encodeAjaxComponent(FacesContext context, UIComponent component, String currentPath, Set ids, Set renderedAreas) throws IOException {
-	    if (component.isRendered()) { // skip not-rendered components.
-	    	boolean found = false;
-	    	if (!ids.isEmpty()) {
-	    		// list for rendering may contains absolute id ( best ),
-	    		// component Id or client ID
-	    		String elementId = component.getId();
-	    		String absoluteId = currentPath + elementId;
-	    		// String clientId = element.getClientId(context);
-	    		if (ids.contains(absoluteId) || ids.contains(elementId)) {
-	    			if (log.isDebugEnabled()) {
-	    				log
-	    						.debug(Messages.getMessage(
-	    								Messages.RENDER_AJAX_AREA_INFO,
-	    								absoluteId));
-	    			}
-	    			// renderChild(context, element);
-	    			found = true;
-	    		}
-	    	}
-	    	if (!found && component instanceof AjaxOutput) {
-	    		if (((AjaxOutput) component).isAjaxRendered()) {
-	    			// renderChild(context, element);
-	    			found = true;
-	    		}
-
-	    	}
-
-	    	if (!found) {
-	    		if (component instanceof AjaxChildrenEncoder) {
-	    			((AjaxChildrenEncoder) component).encodeAjaxChild(
-	    					context, currentPath, ids, renderedAreas);
-	    		} else {
-	    			// Special case - for control components, not produced
-	    			// html code - such as message bundles loaders,
-	    			// MyFaces aliases etc. we call encodeBegin/end methods
-	    			// even if components not in rendered areas.
-	    			boolean special = isSpecialElement(context, component);
-	    			if (special) {
-	    				component.encodeBegin(context);
-	    			}
-	    			encodeAjaxChildren(context, component, currentPath, ids,
-	    					renderedAreas);
-	    			if (special) {
-	    				component.encodeEnd(context);
-	    			}
-
-	    		}
-	    	} else {
-	    		renderedAreas.add(component.getClientId(context));
-	    		renderChild(context, component);
-	    	}
-	    }
-	}
-
-	private Set _specialComponentTypes = null;
-
-	/**
-	 * Detect component as special control case - such as messages bundle
-	 * loader, alias bean components etc. Type of component get by reflection
-	 * from static field COMPONENT_TYPE
-	 * 
-	 * @param context
-	 * @param component
-	 * @return true if encode methods must be called for this component even in
-	 *         not-rendered parts.
-	 */
-	private boolean isSpecialElement(FacesContext context, UIComponent component) {
-		if (_specialComponentTypes == null) {
-			_specialComponentTypes = new HashSet(10);
-			for (int i = 0; i < SPECIAL_COMPONENTS_TYPES.length; i++) {
-				_specialComponentTypes.add(SPECIAL_COMPONENTS_TYPES[i]);
-			}
-			String special = context.getExternalContext().getInitParameter(
-					SPECIAL_TYPES_PARAMETER);
-			if (null != special) {
-				String[] split = special.split(",");
-				for (int i = 0; i < split.length; i++) {
-					_specialComponentTypes.add(split[i]);
-				}
-			}
-		}
-		boolean result;
-		try {
-			String componentType = (String) component.getClass().getField(
-					"COMPONENT_TYPE").get(null);
-			result = _specialComponentTypes.contains(componentType);
-		} catch (Exception e) {
-			// exception occurs if component not have accesible COMPONENT_TYPE
-			// constant
-			// we assume that component not in special types.
-			result = false;
-		}
-		return result;
-	}
-
-}

Added: branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxRenderer.java
===================================================================
--- branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxRenderer.java	                        (rev 0)
+++ branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxRenderer.java	2007-06-29 16:41:58 UTC (rev 1412)
@@ -0,0 +1,40 @@
+package org.ajax4jsf.framework.renderer;
+
+import java.io.IOException;
+import java.util.Set;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+public interface AjaxRenderer {
+
+	/**
+	 * Iterate over all childs of components. If component id contains in list ,
+	 * or, if list is empty, compotents is submitted form - render it. TODO -
+	 * Instead of calculate full path for every component, build current Path
+	 * for componet and send as parameter.
+	 * 
+	 * @param context -
+	 *            current context
+	 * @param component -
+	 *            curent faces component.
+	 * @param ids -
+	 *            list of Id to render.
+	 * @throws IOException
+	 */
+	public void encodeAjaxChildren(FacesContext context, UIComponent component,
+			String path, Set ids, Set renderedAreas) throws IOException;
+
+	/**
+	 * @param context
+	 * @param component
+	 * @param currentPath
+	 * @param ids
+	 * @param renderedAreas
+	 * @throws IOException
+	 */
+	public void encodeAjaxComponent(FacesContext context,
+			UIComponent component, String currentPath, Set ids,
+			Set renderedAreas) throws IOException;
+
+}
\ No newline at end of file

Copied: branches/refactor1/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java (from rev 1411, branches/refactor1/framework/api/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java)
===================================================================
--- branches/refactor1/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java	                        (rev 0)
+++ branches/refactor1/framework/impl/src/main/java/org/ajax4jsf/framework/renderer/AjaxChildrenRenderer.java	2007-06-29 16:41:58 UTC (rev 1412)
@@ -0,0 +1,189 @@
+/**
+ * License Agreement.
+ *
+ * Ajax4jsf 1.1 - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
+ */
+
+package org.ajax4jsf.framework.renderer;
+
+import java.io.IOException;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
+import javax.faces.component.NamingContainer;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+
+import org.ajax4jsf.ajax.UILoadBundle;
+import org.ajax4jsf.framework.ajax.AjaxChildrenEncoder;
+import org.ajax4jsf.framework.ajax.AjaxOutput;
+import org.ajax4jsf.framework.util.message.Messages;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * @author shura
+ *
+ */
+public abstract class AjaxChildrenRenderer extends AjaxComponentRendererBase implements AjaxRenderer {
+	
+	public static final Log log = LogFactory.getLog(AjaxChildrenRenderer.class);
+
+	public static final String[] SPECIAL_COMPONENTS_TYPES = {
+				UILoadBundle.COMPONENT_TYPE, "org.apache.myfaces.AliasBean",
+				"org.apache.myfaces.AliasBeansScope" };
+	private static final String SPECIAL_TYPES_PARAMETER = "org.ajax4jsf.CONTROL_COMPONENTS";
+
+	/**
+	 * Iterate over all childs of components. If component id contains in list ,
+	 * or, if list is empty, compotents is submitted form - render it. TODO -
+	 * Instead of calculate full path for every component, build current Path
+	 * for componet and send as parameter.
+	 * 
+	 * @param context -
+	 *            current context
+	 * @param component -
+	 *            curent faces component.
+	 * @param ids -
+	 *            list of Id to render.
+	 * @throws IOException
+	 * @deprecated Use {@link #encodeAjaxChildren(FacesContext,UIComponent,String,Set,Set)} instead
+	 */
+	public void encodeAjaxChild(FacesContext context, UIComponent component, String path, Set ids, Set renderedAreas) throws IOException {
+	    encodeAjaxChildren(context, component, path, ids, renderedAreas);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.ajax4jsf.framework.renderer.AjaxRenderer#encodeAjaxChildren(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String, java.util.Set, java.util.Set)
+	 */
+	public void encodeAjaxChildren(FacesContext context, UIComponent component, String path, Set ids, Set renderedAreas) throws IOException {
+		if (log.isDebugEnabled()) {
+			log.debug(Messages.getMessage(Messages.ENCODE_CHILD_AJAX_INFO,
+					path, component.getId()));
+		}
+		String currentPath = path;
+		if (component instanceof NamingContainer) {
+			currentPath += component.getId() + NamingContainer.SEPARATOR_CHAR;
+		}
+		for (Iterator it = component.getFacetsAndChildren(); it.hasNext();) {
+			UIComponent element = (UIComponent) it.next();
+			encodeAjaxComponent(context, element, currentPath, ids, renderedAreas);
+		}
+	}
+
+	/* (non-Javadoc)
+	 * @see org.ajax4jsf.framework.renderer.AjaxRenderer#encodeAjaxComponent(javax.faces.context.FacesContext, javax.faces.component.UIComponent, java.lang.String, java.util.Set, java.util.Set)
+	 */
+	public void encodeAjaxComponent(FacesContext context, UIComponent component, String currentPath, Set ids, Set renderedAreas) throws IOException {
+	    if (component.isRendered()) { // skip not-rendered components.
+	    	boolean found = false;
+	    	if (!ids.isEmpty()) {
+	    		// list for rendering may contains absolute id ( best ),
+	    		// component Id or client ID
+	    		String elementId = component.getId();
+	    		String absoluteId = currentPath + elementId;
+	    		// String clientId = element.getClientId(context);
+	    		if (ids.contains(absoluteId) || ids.contains(elementId)) {
+	    			if (log.isDebugEnabled()) {
+	    				log
+	    						.debug(Messages.getMessage(
+	    								Messages.RENDER_AJAX_AREA_INFO,
+	    								absoluteId));
+	    			}
+	    			// renderChild(context, element);
+	    			found = true;
+	    		}
+	    	}
+	    	if (!found && component instanceof AjaxOutput) {
+	    		if (((AjaxOutput) component).isAjaxRendered()) {
+	    			// renderChild(context, element);
+	    			found = true;
+	    		}
+
+	    	}
+
+	    	if (!found) {
+	    		if (component instanceof AjaxChildrenEncoder) {
+	    			((AjaxChildrenEncoder) component).encodeAjaxChild(
+	    					context, currentPath, ids, renderedAreas);
+	    		} else {
+	    			// Special case - for control components, not produced
+	    			// html code - such as message bundles loaders,
+	    			// MyFaces aliases etc. we call encodeBegin/end methods
+	    			// even if components not in rendered areas.
+	    			boolean special = isSpecialElement(context, component);
+	    			if (special) {
+	    				component.encodeBegin(context);
+	    			}
+	    			encodeAjaxChildren(context, component, currentPath, ids,
+	    					renderedAreas);
+	    			if (special) {
+	    				component.encodeEnd(context);
+	    			}
+
+	    		}
+	    	} else {
+	    		renderedAreas.add(component.getClientId(context));
+	    		renderChild(context, component);
+	    	}
+	    }
+	}
+
+	private Set _specialComponentTypes = null;
+
+	/**
+	 * Detect component as special control case - such as messages bundle
+	 * loader, alias bean components etc. Type of component get by reflection
+	 * from static field COMPONENT_TYPE
+	 * 
+	 * @param context
+	 * @param component
+	 * @return true if encode methods must be called for this component even in
+	 *         not-rendered parts.
+	 */
+	private boolean isSpecialElement(FacesContext context, UIComponent component) {
+		if (_specialComponentTypes == null) {
+			_specialComponentTypes = new HashSet(10);
+			for (int i = 0; i < SPECIAL_COMPONENTS_TYPES.length; i++) {
+				_specialComponentTypes.add(SPECIAL_COMPONENTS_TYPES[i]);
+			}
+			String special = context.getExternalContext().getInitParameter(
+					SPECIAL_TYPES_PARAMETER);
+			if (null != special) {
+				String[] split = special.split(",");
+				for (int i = 0; i < split.length; i++) {
+					_specialComponentTypes.add(split[i]);
+				}
+			}
+		}
+		boolean result;
+		try {
+			String componentType = (String) component.getClass().getField(
+					"COMPONENT_TYPE").get(null);
+			result = _specialComponentTypes.contains(componentType);
+		} catch (Exception e) {
+			// exception occurs if component not have accesible COMPONENT_TYPE
+			// constant
+			// we assume that component not in special types.
+			result = false;
+		}
+		return result;
+	}
+
+}




More information about the richfaces-svn-commits mailing list