Author: nbelaevski
Date: 2010-07-01 09:15:39 -0400 (Thu, 01 Jul 2010)
New Revision: 17695
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/CaseStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/SwitchStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl
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/model/ModelFragment.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd
Log:
Added support for cdk:switch/cdk:case/cdk:default elements
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/CaseStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/CaseStatement.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/CaseStatement.java 2010-07-01
13:15:39 UTC (rev 17695)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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 CaseStatement extends AbstractTemplateMethodBodyStatementsContainer {
+
+ private String[] values;
+
+ public CaseStatement() {
+ this(null);
+ }
+
+ public CaseStatement(String[] values) {
+ super("case");
+ this.values = values;
+ }
+
+ public String[] getValues() {
+ return values;
+ }
+
+ public boolean isDefault() {
+ return values == null;
+ }
+}
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-07-01
07:44:12 UTC (rev 17694)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-07-01
13:15:39 UTC (rev 17695)
@@ -23,8 +23,9 @@
package org.richfaces.cdk.templatecompiler;
-import static org.richfaces.cdk.templatecompiler.QNameComparator.*;
-import static org.richfaces.cdk.util.JavaUtils.*;
+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;
@@ -68,11 +69,14 @@
import org.richfaces.cdk.templatecompiler.model.AnyElement;
import org.richfaces.cdk.templatecompiler.model.CdkBodyElement;
import org.richfaces.cdk.templatecompiler.model.CdkCallElement;
+import org.richfaces.cdk.templatecompiler.model.CdkCaseElement;
import org.richfaces.cdk.templatecompiler.model.CdkChooseElement;
+import org.richfaces.cdk.templatecompiler.model.CdkDefaultElement;
import org.richfaces.cdk.templatecompiler.model.CdkForEachElement;
import org.richfaces.cdk.templatecompiler.model.CdkIfElement;
import org.richfaces.cdk.templatecompiler.model.CdkObjectElement;
import org.richfaces.cdk.templatecompiler.model.CdkOtherwiseElement;
+import org.richfaces.cdk.templatecompiler.model.CdkSwitchElement;
import org.richfaces.cdk.templatecompiler.model.CdkWhenElement;
import org.richfaces.cdk.templatecompiler.model.CompositeImplementation;
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
@@ -783,6 +787,39 @@
popStatement();
}
+ @Override
+ public void startElement(CdkSwitchElement cdkSwitchElement) {
+ String key = cdkSwitchElement.getKey();
+ String keyExpression = compileEl(key, Object.class);
+
+ pushStatement(new SwitchStatement(keyExpression));
+ }
+
+ @Override
+ public void endElement(CdkSwitchElement cdkSwitchElement) {
+ popStatement();
+ }
+
+ @Override
+ public void startElement(CdkCaseElement cdkCaseElement) {
+ pushStatement(new CaseStatement(cdkCaseElement.getValues()));
+ }
+
+ @Override
+ public void endElement(CdkCaseElement cdkCaseElement) {
+ popStatement();
+ }
+
+ @Override
+ public void startElement(CdkDefaultElement cdkDefaultElement) {
+ pushStatement(new CaseStatement());
+ }
+
+ @Override
+ public void endElement(CdkDefaultElement cdkDefaultElement) {
+ popStatement();
+ }
+
/**
*
*/
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/SwitchStatement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/SwitchStatement.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/SwitchStatement.java 2010-07-01
13:15:39 UTC (rev 17695)
@@ -0,0 +1,42 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, 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 SwitchStatement extends AbstractTemplateMethodBodyStatementsContainer {
+
+ private String keyExpression;
+
+ public SwitchStatement(String keyExpression) {
+ super("switch");
+ this.keyExpression = keyExpression;
+ }
+
+ /**
+ * @return the keyExpression
+ */
+ public String getKeyExpression() {
+ return keyExpression;
+ }
+}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkCaseElement.java 2010-07-01
13:15:39 UTC (rev 17695)
@@ -0,0 +1,56 @@
+/*
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "case", namespace = Template.CDK_NAMESPACE)
+public class CdkCaseElement extends ModelFragment {
+
+ @XmlAttribute
+ private String[] values;
+
+ public String[] getValues() {
+ return values;
+ }
+
+ public void setValues(String[] values) {
+ this.values = values;
+ }
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkDefaultElement.java 2010-07-01
13:15:39 UTC (rev 17695)
@@ -0,0 +1,44 @@
+/*
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "default", namespace = Template.CDK_NAMESPACE)
+public class CdkDefaultElement extends ModelFragment {
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkSwitchElement.java 2010-07-01
13:15:39 UTC (rev 17695)
@@ -0,0 +1,56 @@
+/*
+ * 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.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "switch", namespace = Template.CDK_NAMESPACE)
+public class CdkSwitchElement extends ModelFragment {
+
+ @XmlAttribute
+ private String key;
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-07-01
07:44:12 UTC (rev 17694)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-07-01
13:15:39 UTC (rev 17695)
@@ -22,7 +22,10 @@
CdkChooseElement.class,
CdkWhenElement.class,
CdkOtherwiseElement.class,
- CdkForEachElement.class
+ CdkForEachElement.class,
+ CdkSwitchElement.class,
+ CdkCaseElement.class,
+ CdkDefaultElement.class
})
public class ModelFragment implements LeafModelElement {
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-07-01
07:44:12 UTC (rev 17694)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-07-01
13:15:39 UTC (rev 17695)
@@ -66,6 +66,18 @@
void endElement(CdkForEachElement cdkForEachElement);
+ void startElement(CdkSwitchElement cdkSwitchElement);
+
+ void endElement(CdkSwitchElement cdkSwitchElement);
+
+ void startElement(CdkCaseElement cdkCaseElement);
+
+ void endElement(CdkCaseElement cdkCaseElement);
+
+ void startElement(CdkDefaultElement cdkDefaultElement);
+
+ void endElement(CdkDefaultElement cdkDefaultElement);
+
void preProcess(CompositeImplementation compositeImplementation);
void postProcess(CompositeImplementation compositeImplementation);
Modified:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-07-01
07:44:12 UTC (rev 17694)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2010-07-01
13:15:39 UTC (rev 17695)
@@ -518,4 +518,30 @@
</xs:choice>
</xs:sequence>
</xs:complexType>
+
+ <xs:element name="switch">
+ <xs:complexType>
+ <xs:sequence>
+ <xs:sequence>
+ <xs:element name="case"
maxOccurs="unbounded">
+ <xs:complexType>
+ <xs:complexContent>
+ <xs:extension base="c:arbitraryContent">
+ <xs:attribute name="values"
form="unqualified" use="required" type="xs:NMTOKENS" />
+ </xs:extension>
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:element name="default" minOccurs="0">
+ <xs:complexType>
+ <xs:complexContent>
+ <xs:extension base="c:arbitraryContent" />
+ </xs:complexContent>
+ </xs:complexType>
+ </xs:element>
+ </xs:sequence>
+ <xs:attribute name="key" use="required"
form="unqualified" type="elStrictExpression" />
+ </xs:complexType>
+ </xs:element>
</xs:schema>
Added:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/case.ftl 2010-07-01
13:15:39 UTC (rev 17695)
@@ -0,0 +1,12 @@
+<#if modelItem.default>
+ default:
+<#else>
+ <#list modelItem.values as value>
+ case ${value}:
+ </#list>
+</#if>
+ <#list modelItem.statements as subStatement>
+ ${subStatement.code}
+ </#list>
+
+ break;
\ No newline at end of file
Added:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/switch.ftl 2010-07-01
13:15:39 UTC (rev 17695)
@@ -0,0 +1,5 @@
+switch (${modelItem.keyExpression}) {
+ <#list modelItem.statements as subStatement>
+ ${subStatement.code}
+ </#list>
+}
\ No newline at end of file