Author: nbelaevski
Date: 2010-05-10 15:29:51 -0400 (Mon, 10 May 2010)
New Revision: 16978
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConstantReturnMethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/constant-return.ftl
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/renders-children-default.template.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/renders-children.template.xml
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/RendersChildrenTest.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
Log:
Support for cdk:renders-children element added
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConstantReturnMethodBodyStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConstantReturnMethodBodyStatement.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConstantReturnMethodBodyStatement.java 2010-05-10
19:29:51 UTC (rev 16978)
@@ -0,0 +1,41 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ConstantReturnMethodBodyStatement extends BaseTemplateMethodBodyStatement {
+
+ private String returnValue;
+
+ public ConstantReturnMethodBodyStatement(String returnValue) {
+ super("constant-return");
+
+ this.returnValue = returnValue;
+ }
+
+ public String getReturnValue() {
+ return returnValue;
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-05-10
18:37:59 UTC (rev 16977)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-05-10
19:29:51 UTC (rev 16978)
@@ -23,10 +23,28 @@
package org.richfaces.cdk.templatecompiler;
-import com.google.common.base.Function;
-import com.google.common.collect.Collections2;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Lists;
+import static org.richfaces.cdk.templatecompiler.QNameComparator.QNAME_COMPARATOR;
+import static org.richfaces.cdk.util.JavaUtils.getEscapedString;
+import static org.richfaces.cdk.util.JavaUtils.getEscapedStringsArray;
+
+import java.io.IOException;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.EnumMap;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.context.ResponseWriter;
+import javax.faces.render.Renderer;
+import javax.xml.namespace.QName;
+
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.attributes.Attribute;
@@ -64,27 +82,11 @@
import org.richfaces.cdk.util.Strings;
import org.richfaces.cdk.xmlconfig.JAXB;
-import javax.faces.component.UIComponent;
-import javax.faces.context.FacesContext;
-import javax.faces.context.ResponseWriter;
-import javax.faces.render.Renderer;
-import javax.xml.namespace.QName;
-import java.io.IOException;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.EnumMap;
-import java.util.EnumSet;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
+import com.google.common.base.Function;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Lists;
-import static org.richfaces.cdk.templatecompiler.QNameComparator.QNAME_COMPARATOR;
-import static org.richfaces.cdk.util.JavaUtils.getEscapedString;
-import static org.richfaces.cdk.util.JavaUtils.getEscapedStringsArray;
-
/**
* <p class="changed_added_4_0">
* </p>
@@ -412,6 +414,23 @@
localsTypesMap.put(name, type);
}
+ private void createRendersChildrenMethod() {
+ Boolean rendersChildren = compositeInterface.getRendersChildren();
+ if (rendersChildren != null) {
+ JavaMethod rendersChildrenMethod = new
JavaMethod("getRendersChildren", Boolean.TYPE);
+ rendersChildrenMethod.addModifier(JavaModifier.PUBLIC);
+ rendersChildrenMethod.addAnnotation(Override.class);
+
+ MethodBody methodBody = new MethodBody();
+ rendersChildrenMethod.setMethodBody(methodBody);
+
+ generatedClass.addMethod(rendersChildrenMethod);
+
+ methodBody.addStatement(
+ new
ConstantReturnMethodBodyStatement(Boolean.toString(compositeInterface.getRendersChildren())));
+ }
+ }
+
protected void pushStatement(MethodBodyStatementsContainer container) {
currentStatement.addStatement(container);
statements.push(currentStatement);
@@ -778,6 +797,7 @@
*/
public void postProcess(CompositeImplementation impl) {
flushToEncodeMethod("encodeEnd");
+ createRendersChildrenMethod();
}
public static void clearCaches() {
Added:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/constant-return.ftl
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/constant-return.ftl
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/constant-return.ftl 2010-05-10
19:29:51 UTC (rev 16978)
@@ -0,0 +1 @@
+return ${modelItem.returnValue};
\ No newline at end of file
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/renders-children-default.template.xml
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/renders-children-default.template.xml
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/renders-children-default.template.xml 2010-05-10
19:29:51 UTC (rev 16978)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://richfaces.org/cdk/xhtml-el"
xmlns:cdk="http://richfaces.org/cdk/core"
+
xmlns:c="http://richfaces.org/cdk/jstl/core"
xmlns:cc="http://richfaces.org/cdk/jsf/composite"
+
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.cdk.renderkit.html.RendersChildrenDefaultRenderer</cdk:class>
+ <cdk:component-family>org.richfaces.cdk.RendersChildrenDefaultComponent</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.cdk.RendersChildrenDefaultRenderer</cdk:renderer-type>
+ </cc:interface>
+
+ <cc:implementation>
+ </cc:implementation>
+</cdk:root>
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/renders-children.template.xml
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/renders-children.template.xml
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/main/templates/renders-children.template.xml 2010-05-10
19:29:51 UTC (rev 16978)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<cdk:root
xmlns="http://richfaces.org/cdk/xhtml-el"
xmlns:cdk="http://richfaces.org/cdk/core"
+
xmlns:c="http://richfaces.org/cdk/jstl/core"
xmlns:cc="http://richfaces.org/cdk/jsf/composite"
+
xmlns:javaee="http://java.sun.com/xml/ns/javaee">
+
+ <cc:interface>
+ <cdk:class>org.richfaces.cdk.renderkit.html.RendersChildrenRenderer</cdk:class>
+ <cdk:component-family>org.richfaces.cdk.RendersChildrenComponent</cdk:component-family>
+ <cdk:renderer-type>org.richfaces.cdk.RendersChildrenRenderer</cdk:renderer-type>
+ <cdk:renders-children>true</cdk:renders-children>
+ </cc:interface>
+
+ <cc:implementation>
+ </cc:implementation>
+</cdk:root>
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/RendersChildrenTest.java
===================================================================
---
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/RendersChildrenTest.java
(rev 0)
+++
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/renderer-template-test/src/test/java/org/richfaces/cdk/RendersChildrenTest.java 2010-05-10
19:29:51 UTC (rev 16978)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software 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 software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.richfaces.cdk.renderkit.html.RendersChildrenDefaultRenderer;
+import org.richfaces.cdk.renderkit.html.RendersChildrenRenderer;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class RendersChildrenTest {
+
+ @Test
+ public void testRendersChildrenTrue() throws Exception {
+ RendersChildrenRenderer renderer = new RendersChildrenRenderer();
+ assertTrue(renderer.getRendersChildren());
+ }
+
+ @Test
+ public void testRendersChildrenDefault() throws Exception {
+ RendersChildrenDefaultRenderer renderer = new RendersChildrenDefaultRenderer();
+ assertFalse(renderer.getRendersChildren());
+ }
+}