JBoss Rich Faces SVN: r15934 - root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-11-19 21:19:52 -0500 (Thu, 19 Nov 2009)
New Revision: 15934
Modified:
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java
root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
Log:
https://jira.jboss.org/jira/browse/RF-7732 - updates in base and utility framework classes
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java 2009-11-20 02:18:05 UTC (rev 15933)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererBase.java 2009-11-20 02:19:52 UTC (rev 15934)
@@ -250,7 +250,10 @@
* Get base component slass , targetted for this renderer. Used for check arguments in decode/encode.
* @return
*/
- protected abstract Class<? extends UIComponent> getComponentClass();
+ protected Class<? extends UIComponent> getComponentClass() {
+ //TODO - do we need this function?
+ return UIComponent.class;
+ }
/**
* Template method for custom decoding of concrete renderer.
Modified: root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
--- root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2009-11-20 02:18:05 UTC (rev 15933)
+++ root/framework/trunk/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2009-11-20 02:19:52 UTC (rev 15934)
@@ -426,6 +426,12 @@
encodeAttribute(context, component, getComponentAttributeName(attribute), attribute);
}
+ public void writeText(ResponseWriter writer, Object value, String property) throws IOException {
+ if (value != null) {
+ writer.writeText(value, property);
+ }
+ }
+
/**
* Write html-attribute
*
15 years, 1 month
JBoss Rich Faces SVN: r15933 - in root/cdk/trunk/plugins/generator/src: main/java/org/richfaces/cdk/parser/el/node and 7 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-11-19 21:18:05 -0500 (Thu, 19 Nov 2009)
New Revision: 15933
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToStringMethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EmptinessCheckingMethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributesSetStatement.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/conversion-to-string-method.ftl
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/emptiness-check-method.ftl
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/macros/
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/macros/write-attribute.ftl
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-attributes-set.ftl
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
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/xmlconfig/FacesConfigParser.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/encode-method-preface.ftl
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-text.ftl
root/cdk/trunk/plugins/generator/src/main/script/SchemaAttributesParserTask.groovy
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java
Log:
https://jira.jboss.org/jira/browse/RF-7732
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -40,8 +40,9 @@
Class<?> collectionVariableType = null;
String lastIndexValue = "null";
Class<?> lastVariableType = null;
- boolean mixedExpression;
-
+ boolean useConversionToString;
+ boolean useEmptinessCheck;
+
private ELVisitor() {}
public static ELVisitor getInstance() {
@@ -54,14 +55,22 @@
return elVisitor;
}
- public boolean isMixedExpression() {
- return mixedExpression;
+ public boolean isUseConversionToString() {
+ return useConversionToString;
}
- public void setMixedExpression(boolean needConversion) {
- this.mixedExpression = needConversion;
+ public void setUseConversionToString(boolean needConversion) {
+ this.useConversionToString = needConversion;
}
+ public boolean isUseEmptinessCheck() {
+ return useEmptinessCheck;
+ }
+
+ public void setUseEmptinessCheck(boolean useCheckForEmpty) {
+ this.useEmptinessCheck = useCheckForEmpty;
+ }
+
public String getLastIndexValue() {
return lastIndexValue;
}
@@ -93,16 +102,15 @@
* @return generated Java code.
* @throws ParsingException - if error occurred during parsing.
*/
- public static String parse(String expression, Map<String, Class<?>> contextMap) throws ParsingException {
+ public String parse(String expression, Map<String, Class<?>> contextMap) throws ParsingException {
Node ret = ELParser.parse(expression);
- ELVisitor elVisitor = ELVisitor.getInstance();
if (ret instanceof AstCompositeExpression && ret.jjtGetNumChildren() >= 2) {
//AstCompositeExpression with 2+ children is a mixed expression
- elVisitor.setMixedExpression(true);
+ this.setUseConversionToString(true);
}
- return elVisitor.visit(ret, contextMap);
+ return this.visit(ret, contextMap);
}
private String visit(Node node, Map<String, Class<?>> context) throws ParsingException {
@@ -137,7 +145,8 @@
lastIndexValue = "null";
lastVariableType = null;
collectionVariableType = null;
- mixedExpression = false;
+ useConversionToString = false;
+ useEmptinessCheck = false;
}
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -48,7 +48,7 @@
int numChildren = getNode().jjtGetNumChildren();
for (int i = 0; i < numChildren; i++) {
- if (visitor.isMixedExpression()) {
+ if (visitor.isUseConversionToString()) {
sb.append(ELNodeConstants.CONVERT_TO_STRING_FUNCTION);
sb.append(ELNodeConstants.LEFT_BRACKET);
}
@@ -57,7 +57,7 @@
treeNode.visit(sb, context, visitor);
- if (visitor.isMixedExpression()) {
+ if (visitor.isUseConversionToString()) {
sb.append(ELNodeConstants.RIGHT_BRACKET);
}
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -44,7 +44,9 @@
@Override
public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
- StringBuilder sb1 = new StringBuilder();
+ visitor.setUseEmptinessCheck(true);
+
+ StringBuilder sb1 = new StringBuilder();
ITreeNode treeNode = getChild(0);
treeNode.visit(sb1, context, visitor);
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToStringMethodBodyStatement.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToStringMethodBodyStatement.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/ConversionToStringMethodBodyStatement.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -0,0 +1,33 @@
+/*
+ * 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 ConversionToStringMethodBodyStatement extends AbstractTemplateMethodBodyStatement {
+
+ public ConversionToStringMethodBodyStatement() {
+ super("conversion-to-string-method");
+ }
+}
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EmptinessCheckingMethodBodyStatement.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EmptinessCheckingMethodBodyStatement.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/EmptinessCheckingMethodBodyStatement.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -0,0 +1,33 @@
+/*
+ * 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 EmptinessCheckingMethodBodyStatement extends AbstractTemplateMethodBodyStatement {
+
+ public EmptinessCheckingMethodBodyStatement() {
+ super("emptiness-check-method");
+ }
+}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -84,6 +84,8 @@
rootMap.put("facesContextVariable", RendererClassVisitor.FACES_CONTEXT_VARIABLE);
rootMap.put("componentVariable", RendererClassVisitor.COMPONENT_VARIABLE);
rootMap.put("responseWriterVariable", RendererClassVisitor.RESPONSE_WRITER_VARIABLE);
+ rootMap.put("clientIdVariable", RendererClassVisitor.CLIENT_ID_VARIABLE);
+ rootMap.put("rendererUtilsVariable", RendererClassVisitor.RENDERER_UTILS_VARIABLE);
t.process(rootMap, writer);
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -24,10 +24,8 @@
package org.richfaces.cdk.templatecompiler;
import org.richfaces.builder.model.MethodBodyStatement;
-import org.richfaces.cdk.freemarker.LibraryModelWrapper;
import freemarker.ext.beans.BeanModel;
-import freemarker.ext.beans.BeansWrapper;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
@@ -56,7 +54,7 @@
public TemplateModel get(String key) throws TemplateModelException {
if("code".equals(key)){
//TODO - ?
- statement.getCode(modelWrapper.getConfiguration());
+ return modelWrapper.wrap(statement.getCode(modelWrapper.getConfiguration()));
}
return super.get(key);
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -74,7 +74,7 @@
if (null != template) {
// TODO - put real parameters.
RendererClassVisitor visitor = new RendererClassVisitor(
- template.getInterface());
+ template.getInterface(), context.getLoader());
visitor.preProcess();
template.getImplementation().visit(visitor);
visitor.postProcess();
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 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -26,17 +26,20 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
+import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
-import java.util.Locale;
import java.util.Map;
import java.util.Set;
-import java.util.regex.Pattern;
+import java.util.TreeSet;
+import javax.annotation.Generated;
import javax.faces.component.UIComponent;
+import javax.faces.component.behavior.Behavior;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
+import javax.faces.convert.Converter;
import javax.xml.namespace.QName;
import org.richfaces.builder.model.Argument;
@@ -59,6 +62,7 @@
import org.richfaces.cdk.templatecompiler.model.CdkOtherwiseElement;
import org.richfaces.cdk.templatecompiler.model.CdkWhenElement;
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
+import org.richfaces.cdk.templatecompiler.model.Template;
import org.richfaces.cdk.templatecompiler.model.TemplateVisitor;
import com.google.common.collect.Lists;
@@ -82,16 +86,43 @@
*
*/
static final String FACES_CONTEXT_VARIABLE = "facesContext";
+ /**
+ *
+ */
+ static final String CLIENT_ID_VARIABLE = "clientId";
+ /**
+ *
+ */
+ static final String RENDERER_UTILS_VARIABLE = "utils";
+
+ static final String RENDERER_UTILS_CLASS_NAME = "org.ajax4jsf.renderkit.RendererUtils";
+
private static final Set<String> DEFAULT_NAMESPACES = new HashSet<String>();
static {
DEFAULT_NAMESPACES.add("http://richfaces.org/xhtml-el");
DEFAULT_NAMESPACES.add("http://www.w3.org/1999/xhtml");
}
+
+ private static final String[] GUESS_PACKAGES;
- private static final Pattern EL_EXPRESSION = Pattern.compile("#\\{([^\\}]+)\\}");
- private static final Pattern COMPONENT_ATTRIBUTES_EXPRESSION =
- Pattern.compile("^component\\.attributes\\[(?:'|\")?([^'\"]+)(?:'|\")?\\]$");
+ static {
+ Class<?>[] GUESS_PACKAGES_CLASSES = {
+ UIComponent.class,
+ Behavior.class,
+ Converter.class,
+ FacesContext.class,
+ Collection.class,
+ Object.class,
+ };
+
+ GUESS_PACKAGES = new String[GUESS_PACKAGES_CLASSES.length];
+ int i = 0;
+ for (Class<?> guessPackageClass : GUESS_PACKAGES_CLASSES) {
+ GUESS_PACKAGES[i++] = guessPackageClass.getPackage().getName();
+ }
+ }
+
private static final Map<String, Set<String>> ELEMENTS_ATTRIBUTES;
private JavaClass rendererClass;
private CompositeInterface compositeInterface;
@@ -100,6 +131,9 @@
private final LinkedList<MethodBodyStatementsContainer> statements = Lists.newLinkedList();
private Map<String, Class<?>> localsTypesMap;
+ private ClassLoader classLoader;
+ private boolean isAddedMethodForConversionToString;
+ private boolean isAddedMethodForCheckingEmptiness;
static {
InputStream serializedAttributesStream = RendererClassVisitor.class.getResourceAsStream("/META-INF/schema/attributes.ser");
@@ -124,9 +158,73 @@
}
}
+ private void initializeJavaClass() {
+ this.rendererClass = createJavaClassByName(compositeInterface.getJavaClass());
+ this.rendererClass.addModifier(JavaModifier.PUBLIC);
+ this.rendererClass.setSuperClass(createJavaClassByName(compositeInterface.getBaseClass()));
+
+ this.rendererClass.addImport(FacesContext.class);
+ this.rendererClass.addImport(ResponseWriter.class);
+ this.rendererClass.addImport(UIComponent.class);
+ this.rendererClass.addImport(RENDERER_UTILS_CLASS_NAME);
+
+ this.rendererClass.addAnnotation(Generated.class, "\"RichFaces CDK\"");
+ //TODO remove this after improving Java model
+ this.rendererClass.addImport(Generated.class);
+
+ this.createMethodContext();
+ }
+
+ private void addMethodForConversionToString() {
+ if (!isAddedMethodForConversionToString) {
+ isAddedMethodForConversionToString = true;
+
+ JavaMethod conversionMethod = new JavaMethod("convertToString", String.class,
+ new Argument("object", Object.class));
+
+ conversionMethod.addModifier(JavaModifier.PRIVATE);
+ conversionMethod.addModifier(JavaModifier.FINAL);
+
+ MethodBody conversionMethodBody = new MethodBody(conversionMethod);
+ conversionMethod.setMethodBody(conversionMethodBody);
+ conversionMethodBody.addStatement(new ConversionToStringMethodBodyStatement());
+
+ rendererClass.addMethod(conversionMethod);
+ }
+ }
+
+ private void addMethodForCheckingEmptiness() {
+ if (!isAddedMethodForCheckingEmptiness) {
+ isAddedMethodForCheckingEmptiness = true;
+
+ JavaMethod checkingMethod = new JavaMethod("isEmpty", boolean.class,
+ new Argument("object", Object.class));
+
+ checkingMethod.addModifier(JavaModifier.PRIVATE);
+ checkingMethod.addModifier(JavaModifier.FINAL);
+
+ MethodBody checkingMethodBody = new MethodBody(checkingMethod);
+ checkingMethod.setMethodBody(checkingMethodBody);
+ checkingMethodBody.addStatement(new EmptinessCheckingMethodBodyStatement());
+
+ rendererClass.addMethod(checkingMethod);
+ }
+ }
+
private String compileEl(String expression, Class<?> type) {
try {
- return ELVisitor.parse(expression, localsTypesMap) + "/* " + expression.trim() + " */";
+ ELVisitor elVisitor = ELVisitor.getInstance();
+ String parsedExpression = elVisitor.parse(expression, localsTypesMap);
+
+ if (elVisitor.isUseConversionToString()) {
+ addMethodForConversionToString();
+ }
+
+ if (elVisitor.isUseEmptinessCheck()) {
+ addMethodForCheckingEmptiness();
+ }
+
+ return parsedExpression + "/* " + expression.trim() + " */";
} catch (ParsingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -151,66 +249,6 @@
return String.class.getName();
}
- private String toCharExpression(char c) {
- String prependingZeroesString;
- String hexString = Integer.toHexString(c);
-
- switch (hexString.length()) {
- case 1:
- prependingZeroesString = "000";
- break;
- case 2:
- prependingZeroesString = "00";
- break;
- case 3:
- prependingZeroesString = "0";
- break;
- case 4:
- prependingZeroesString = "";
- break;
- default:
- throw new IllegalArgumentException();
- }
-
- return "\\u" + prependingZeroesString + hexString.toUpperCase(Locale.US);
- }
-
- private String quote(String s) {
- StringBuilder result = new StringBuilder();
-
- result.append('\"');
-
- char[] chars = s.toCharArray();
-
- for (char c : chars) {
- if (c == '\n') {
- result.append("\\n");
- } else if (c == '\r') {
- result.append("\\r");
- } else if (c == '\t') {
- result.append("\\t");
- } else if (c == '\f') {
- result.append("\\f");
- } else if (c == '\b') {
- result.append("\\b");
- } else if (c == '\\') {
- result.append("\\\\");
- } else if (c == '"') {
- result.append("\\\"");
- } else {
- if (c < 0x20 || c > 0x7F) {
- result.append(toCharExpression(c));
- } else {
- result.append(c);
- }
- }
- }
-
- result.append('\"');
-
- return result.toString();
- }
-
private boolean isDefaultNamespace(String namespaceURI) {
//TODO - another namespaces
if (namespaceURI == null || namespaceURI.length() == 0) {
@@ -230,6 +268,7 @@
localsTypesMap.put(FACES_CONTEXT_VARIABLE, FacesContext.class);
localsTypesMap.put(RESPONSE_WRITER_VARIABLE, ResponseWriter.class);
localsTypesMap.put(COMPONENT_VARIABLE, UIComponent.class);
+ localsTypesMap.put(CLIENT_ID_VARIABLE, String.class);
}
private void flushToEncodeMethod(String encodeMethodName) {
@@ -267,18 +306,56 @@
return new JavaClass(simpleName, new JavaPackage(packageName));
}
- private void pushStatement(MethodBodyStatementsContainer container) {
+ private Class<?> getClasByObjectTypeByName(String type) {
+ Class<?> result = null;
+
+ int dotIndex = type.indexOf('.');
+ if (dotIndex < 0) {
+ //guess type
+ for (String guessPackage : GUESS_PACKAGES) {
+ try {
+ result = classLoader.loadClass(guessPackage + "." + type);
+ break;
+ } catch (ClassNotFoundException e) {
+ //ignore
+ }
+ }
+ }
+
+ if (result == null) {
+ try {
+ classLoader.loadClass(type);
+ } catch (ClassNotFoundException e) {
+ //ignore
+ }
+ }
+
+ if (result == null) {
+ result = Object.class;
+ }
+
+ return result;
+ }
+
+ private void defineObject(String type, String name, String initializationExpression) {
+ currentStatement.addStatement(new DefineObjectStatement(type, name, initializationExpression));
+ localsTypesMap.put(name, getClasByObjectTypeByName(type));
+ }
+
+
+ protected void pushStatement(MethodBodyStatementsContainer container) {
currentStatement.addStatement(container);
statements.push(currentStatement);
currentStatement = container;
}
- private void popStatement() {
+ protected void popStatement() {
currentStatement = statements.pop();
}
- public RendererClassVisitor(CompositeInterface compositeInterface) {
+ public RendererClassVisitor(CompositeInterface compositeInterface, ClassLoader classLoader) {
this.compositeInterface = compositeInterface;
+ this.classLoader = classLoader;
}
/**
@@ -326,15 +403,37 @@
if (!isDefaultNamespace(attributeName.getNamespaceURI())) {
//TODO: add support
- //TODO: cdk:passThrough
+
+ //TODO: optimize batch attributes encoding
+ if (Template.CDK_NAMESPACE.equals(attributeName.getNamespaceURI()) &&
+ "passThroughWithExclusions".equals(attributeName.getLocalPart())) {
+
+ //TODO check element namespace
+ Set<String> attributeSet = ELEMENTS_ATTRIBUTES.get(elementName.getLocalPart());
+ if (attributeSet != null) {
+ //make a copy of original set
+ TreeSet<String> actualAttributesSet = new TreeSet<String>(attributeSet);
+
+ if (attributeValue != null) {
+ String[] exclusions = attributeValue.toString().split("\\s+");
+ for (String exclusion : exclusions) {
+ actualAttributesSet.remove(exclusion);
+ }
+ }
+
+ if (!actualAttributesSet.isEmpty()) {
+ currentStatement.addStatement(new WriteAttributesSetStatement(actualAttributesSet));
+ }
+ }
+ }
+
+ //TODO: cdk:passThrough
+ } else {
+ currentStatement.addStatement(new WriteAttributeStatement(attributeName.getLocalPart(),
+ compileEl(attributeValue.toString(), String.class)));
}
-
- currentStatement.addStatement(new WriteAttributeStatement(attributeName.getLocalPart(),
- compileEl(attributeValue.toString(), String.class)));
}
}
-
-
}
/* (non-Javadoc)
@@ -354,7 +453,7 @@
if (text != null) {
String trimmedText = text.trim();
if (trimmedText.length() != 0) {
- currentStatement.addStatement(new WriteTextStatement(compileEl(trimmedText, String.class)));
+ currentStatement.addStatement(new WriteTextStatement(compileEl(trimmedText, String.class)));
}
}
}
@@ -459,7 +558,7 @@
value = compileEl(value, Object.class);
}
- currentStatement.addStatement(new DefineObjectStatement(type, name, value));
+ defineObject(type, name, value);
}
/* (non-Javadoc)
@@ -485,15 +584,7 @@
*
*/
public void preProcess() {
- this.rendererClass = createJavaClassByName(compositeInterface.getJavaClass());
- this.rendererClass.addModifier(JavaModifier.PUBLIC);
- this.rendererClass.setSuperClass(createJavaClassByName(compositeInterface.getBaseClass()));
-
- this.rendererClass.addImport(FacesContext.class);
- this.rendererClass.addImport(ResponseWriter.class);
- this.rendererClass.addImport(UIComponent.class);
-
- this.createMethodContext();
+ initializeJavaClass();
}
/**
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributesSetStatement.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributesSetStatement.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/WriteAttributesSetStatement.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+import java.util.Set;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class WriteAttributesSetStatement extends AbstractTemplateMethodBodyStatement {
+
+ private Set<String> attributesSet;
+
+ public WriteAttributesSetStatement(Set<String> attributesSet) {
+ super("write-attributes-set");
+ this.attributesSet = attributesSet;
+ }
+
+ /**
+ * @return the attributesSet
+ */
+ public Set<String> getAttributesSet() {
+ return attributesSet;
+ }
+}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigParser.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -63,7 +63,8 @@
FacesConfigBean unmarshal = unmarshalFacesConfig(file);
library.getComponents().addAll(unmarshal.getComponents());
-
+ library.getRenderKits().addAll(unmarshal.getRenderKits());
+
// TODO - merge changes into library.
// library.getRenderers().addAll(unmarshal.getRenderers());
// library.getValidators().addAll(unmarshal.getValidators);
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 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/schema/cdk-template.xsd 2009-11-20 02:18:05 UTC (rev 15933)
@@ -28,8 +28,7 @@
targetNamespace="http://richfaces.org/cdk" xmlns="http://richfaces.org/cdk"
elementFormDefault="qualified" attributeFormDefault="unqualified"
xmlns:xhtml="http://richfaces.org/xhtml-el" xmlns:javaee="http://java.sun.com/xml/ns/javaee"
- xmlns:c="http://java.sun.com/jsp/jstl/core"
- xmlns:cc="http://java.sun.com/jsf/composite">
+ xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:cc="http://java.sun.com/jsf/composite">
<xs:import schemaLocation="web-facesuicomponent_2_0.xsd" namespace="http://java.sun.com/xml/ns/javaee" />
<xs:import schemaLocation="cdk-composite.xsd" namespace="http://java.sun.com/jsf/composite" />
@@ -59,7 +58,7 @@
</xs:simpleType>
<xs:attributeGroup name="core.attrs">
- <xs:attribute name="passThroughWithExclusions" type="xs:NMTOKENS" />
+ <xs:attribute name="passThroughWithExclusions" type="xs:NMTOKENS" form="qualified" />
</xs:attributeGroup>
<xs:element name="root">
@@ -104,6 +103,7 @@
<xs:element name="class" type="javaee:fully-qualified-classType" />
<xs:element name="superclass" type="javaee:fully-qualified-classType" />
+ <xs:element name="component-class" type="javaee:fully-qualified-classType" />
<xs:element name="component-type" />
@@ -143,4 +143,10 @@
</xs:simpleContent>
</xs:complexType>
</xs:element>
+
+ <xs:element name="clientId">
+ <xs:complexType>
+ <xs:attribute name="var" type="literalExpression" default="clientId" />
+ </xs:complexType>
+ </xs:element>
</xs:schema>
Added: root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/conversion-to-string-method.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/conversion-to-string-method.ftl (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/conversion-to-string-method.ftl 2009-11-20 02:18:05 UTC (rev 15933)
@@ -0,0 +1 @@
+return (object != null ? object.toString() : "");
\ No newline at end of file
Added: root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/emptiness-check-method.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/emptiness-check-method.ftl (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/emptiness-check-method.ftl 2009-11-20 02:18:05 UTC (rev 15933)
@@ -0,0 +1 @@
+return object != null;
\ No newline at end of file
Modified: root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/encode-method-preface.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/encode-method-preface.ftl 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/encode-method-preface.ftl 2009-11-20 02:18:05 UTC (rev 15933)
@@ -1 +1,3 @@
-ResponseWriter ${responseWriterVariable} = ${facesContextVariable}.getResponseWriter();
\ No newline at end of file
+ResponseWriter ${responseWriterVariable} = ${facesContextVariable}.getResponseWriter();
+String ${clientIdVariable} = ${componentVariable}.getClientId(${facesContextVariable});
+RendererUtils ${rendererUtilsVariable} = RendererUtils.getInstance();
\ No newline at end of file
Added: root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/macros/write-attribute.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/macros/write-attribute.ftl (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/macros/write-attribute.ftl 2009-11-20 02:18:05 UTC (rev 15933)
@@ -0,0 +1,3 @@
+<#macro writeAttributeMacro attributeName attributeValue>
+ ${rendererUtilsVariable}.writeAttribute(${responseWriterVariable}, "${attributeName}", ${attributeValue});
+</#macro>
\ No newline at end of file
Modified: root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-attribute.ftl 2009-11-20 02:18:05 UTC (rev 15933)
@@ -1 +1,3 @@
-${responseWriterVariable}.writeAttribute("${modelItem.attributeName}", ${modelItem.valueExpression}, null);
\ No newline at end of file
+<#import './macros/write-attribute.ftl' as writeAttributeTemplate />
+
+<@writeAttributeTemplate.writeAttributeMacro attributeName="${modelItem.attributeName}" attributeValue="${modelItem.valueExpression}" />
\ No newline at end of file
Added: root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-attributes-set.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-attributes-set.ftl (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-attributes-set.ftl 2009-11-20 02:18:05 UTC (rev 15933)
@@ -0,0 +1,7 @@
+<#import './macros/write-attribute.ftl' as writeAttributeTemplate />
+
+//passThroughWithExclusions start
+<#list modelItem.attributesSet as attributeName>
+ <@writeAttributeTemplate.writeAttributeMacro attributeName="${attributeName}" attributeValue="${componentVariable}.getAttributes().get(\"${attributeName}\")" />
+</#list>
+//passThroughWithExclusions end
\ No newline at end of file
Modified: root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-text.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-text.ftl 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/write-text.ftl 2009-11-20 02:18:05 UTC (rev 15933)
@@ -1 +1 @@
-${responseWriterVariable}.writeText(${modelItem.textExpression}, null);
\ No newline at end of file
+${rendererUtilsVariable}.writeText(${responseWriterVariable}, ${modelItem.textExpression}, null);
\ No newline at end of file
Modified: root/cdk/trunk/plugins/generator/src/main/script/SchemaAttributesParserTask.groovy
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/script/SchemaAttributesParserTask.groovy 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/main/script/SchemaAttributesParserTask.groovy 2009-11-20 02:18:05 UTC (rev 15933)
@@ -1,7 +1,12 @@
import java.lang.Exception
-import java.io.FileOutputStream
+import java.net.URL;
import java.io.*;
import java.util.*;
+
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
import com.sun.xml.xsom.*;
import com.sun.xml.xsom.parser.*;
@@ -10,7 +15,7 @@
* for each element
*/
class SchemaParser {
-
+
Map<String, Set<String>> attributes = new HashMap<String, Set<String>>();
private Set<String> getAttributesSet(String elementName) {
@@ -41,7 +46,23 @@
public void parse(String schemaSource, String namespace) throws Exception {
XSOMParser parser = new XSOMParser();
- parser.parse(new File(schemaSource));
+ File schemaSourceFile = new File(schemaSource);
+
+ def entityResolver = {String publicId, systemId ->
+ def fileProtocolMatch = (systemId =~ /^file:.+/);
+ if (!fileProtocolMatch || !new File(fileProtocolMatch[0]).exists()) {
+ String schemaFileName = (systemId =~ /\/[^\/]+$/)[0];
+
+ File entityLocation = new File(schemaSourceFile.getParentFile(), schemaFileName);
+ return new InputSource(entityLocation.toURI().toString());
+ }
+
+ return new InputSource(systemId);
+ } as EntityResolver;
+
+ parser.setEntityResolver(entityResolver);
+ parser.parse(schemaSourceFile);
+
XSSchemaSet sset = parser.getResult();
XSSchema cdkXhtmlSchema = sset.getSchema(namespace);
Modified: root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java 2009-11-19 19:23:40 UTC (rev 15932)
+++ root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java 2009-11-20 02:18:05 UTC (rev 15933)
@@ -291,7 +291,7 @@
contextMap.put("action", org.richfaces.cdk.parser.el.test.Bean.class);
contextMap.put("clientId", String.class);
- String code = ELVisitor.parse(expression, contextMap);
+ String code = ELVisitor.getInstance().parse(expression, contextMap);
return code;
}
15 years, 1 month
JBoss Rich Faces SVN: r15932 - branches/enterprise/3.3.X/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2009-11-19 14:23:40 -0500 (Thu, 19 Nov 2009)
New Revision: 15932
Modified:
branches/enterprise/3.3.X/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/MethodCallElement.java
Log:
RFPL-252
Modified: branches/enterprise/3.3.X/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/MethodCallElement.java
===================================================================
--- branches/enterprise/3.3.X/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/MethodCallElement.java 2009-11-19 19:15:29 UTC (rev 15931)
+++ branches/enterprise/3.3.X/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/MethodCallElement.java 2009-11-19 19:23:40 UTC (rev 15932)
@@ -31,73 +31,88 @@
import java.util.Map;
import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
import javax.faces.el.MethodNotFoundException;
+import javax.faces.render.Renderer;
import org.ajax4jsf.Messages;
+import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.SAXException;
-
/**
* @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:47 $
- *
+ *
*/
-public class MethodCallElement extends ElementBase {
+public class MethodCallElement extends ElementBase {
public static final String UTILS_PREFIX = "utils.";
-
+
static final Log _log = LogFactory.getLog(MethodCallElement.class);
private String _name = null;
-
- private List parameters = new ArrayList();
-
- private Invoker invoker = new Invoker();
-
- private MethodCacheState state = new MethodCacheState();
-
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.renderkit.compiler.CompiledXML#encode(javax.faces.render.Renderer, javax.faces.context.FacesContext, javax.faces.component.UIComponent)
+
+ private List<MethodParameterElement> parameters = new ArrayList<MethodParameterElement>(
+ 3);
+
+ private volatile Invoker invoker;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.compiler.CompiledXML#encode(javax.faces.render
+ * .Renderer, javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
*/
- public void encode(TemplateContext context ) throws IOException {
- getValue(context);
+ public void encode(TemplateContext context) throws IOException {
+ getValue(context);
}
- /* (non-Javadoc)
- * @see org.ajax4jsf.renderkit.compiler.ElementBase#encode(org.ajax4jsf.renderkit.compiler.TemplateContext, java.lang.String)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.compiler.ElementBase#encode(org.ajax4jsf.renderkit
+ * .compiler.TemplateContext, java.lang.String)
*/
- public void encode(TemplateContext context, String breakPoint) throws IOException {
+ public void encode(TemplateContext context, String breakPoint)
+ throws IOException {
// Text not contain breakpoints.
encode(context);
}
-
-
+
public Object getValue(TemplateContext context) throws FacesException {
+ if (null == invoker) {
+ throw new FacesException(Messages
+ .getMessage(Messages.RENDERER_METHOD_NOT_SET_ERROR));
+ }
// prepare method params. we attempt to call 3 signatures :
// a) name(FacesContext,UIComponent [, param0...])
// b) name(TempalateContext [,param0...])
// c) name([param0...])
- state.init(parameters);
- Object[] values = state.computeParameterValues(context);
-
- InvokeData data = null;
- synchronized (state) {
- state.update(context, values, invoker);
- data = invoker.invokeMethod(context, state);
- }
- return invoker.invokeMethod(data);
+ Object[] values = computeParameterValues(context);
+
+ return invoker.invokeMethod(context, values);
// perform childrens.
// super.encode(renderer,context,component);
}
+ public Object[] computeParameterValues(TemplateContext context) {
+ Object[] ps = new Object[parameters.size()];
+ for (int i = 0; i < ps.length; i++) {
+ ps[i] = parameters.get(i).valueGetter.getValueOrDefault(context);
+ }
+ return ps;
+ }
-
- public void addParameter(MethodParameterElement parameter){
+ public void addParameter(MethodParameterElement parameter) {
parameters.add(parameter);
}
+
/**
* @return Returns the methodName.
*/
@@ -106,13 +121,14 @@
}
/**
- * @param methodName The methodName to set.
+ * @param methodName
+ * The methodName to set.
*/
public void setName(String methodName) {
- if(methodName.startsWith(UTILS_PREFIX)){
+ if (methodName.startsWith(UTILS_PREFIX)) {
this._name = methodName.substring(UTILS_PREFIX.length());
this.invoker = getRendererUtilsInvoker(_name);
- } else if(methodName.indexOf('.') >= 0) {
+ } else if (methodName.indexOf('.') >= 0) {
this._name = methodName;
this.invoker = getStaticInvoker(_name);
} else {
@@ -121,385 +137,430 @@
}
}
- static Map staticInvokers = new HashMap();
-
- public StaticInvoker getStaticInvoker(String methodName) {
- StaticInvoker invoker = (StaticInvoker)staticInvokers.get(methodName);
- if(invoker == null) {
- invoker = new StaticInvoker(methodName);
- staticInvokers.put(methodName, invoker);
- }
- return invoker;
+ public Invoker getStaticInvoker(String methodName) {
+ StaticInvoker invoker = new StaticInvoker(methodName);
+ return invoker;
}
- static Map rendererInvokers = new HashMap();
-
- public RendererInvoker getRendererInvoker(String methodName) {
- RendererInvoker invoker = (RendererInvoker)rendererInvokers.get(methodName);
- if(invoker == null) {
- invoker = new RendererInvoker(false, methodName);
- rendererInvokers.put(methodName, invoker);
- }
+ public Invoker getRendererInvoker(String methodName) {
+ RendererInvoker invoker = new RendererInvoker(methodName);
return invoker;
}
-
- static Map utilsInvokers = new HashMap();
- public RendererInvoker getRendererUtilsInvoker(String methodName) {
- RendererInvoker invoker = (RendererInvoker)utilsInvokers.get(methodName);
- if(invoker == null) {
- invoker = new RendererInvoker(true, methodName);
- utilsInvokers.put(methodName, invoker);
- }
+ public Invoker getRendererUtilsInvoker(String methodName) {
+ RendererInvoker invoker = new RendererUtilsInvoker(methodName);
return invoker;
}
-
+
public String getTag() {
- return HtmlCompiler.NS_PREFIX+HtmlCompiler.CALL_TAG;
+ return HtmlCompiler.NS_PREFIX + HtmlCompiler.CALL_TAG;
}
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.renderkit.compiler.ElementBase#setParent(org.ajax4jsf.renderkit.compiler.PreparedTemplate)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.compiler.ElementBase#setParent(org.ajax4jsf.renderkit
+ * .compiler.PreparedTemplate)
*/
- public void setParent(PreparedTemplate parent) throws SAXException {
+ public void setParent(PreparedTemplate parent) throws SAXException {
super.setParent(parent);
- if (getName()==null) {
- throw new SAXException(Messages.getMessage(Messages.NO_NAME_ATTRIBUTE_ERROR, getTag()));
+ if (getName() == null) {
+ throw new SAXException(Messages.getMessage(
+ Messages.NO_NAME_ATTRIBUTE_ERROR, getTag()));
}
}
-
-/* (non-Javadoc)
- * @see org.ajax4jsf.renderkit.compiler.ElementBase#getString(org.ajax4jsf.renderkit.compiler.TemplateContext)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.compiler.ElementBase#getString(org.ajax4jsf.renderkit
+ * .compiler.TemplateContext)
*/
public String getString(TemplateContext context) throws FacesException {
Object result = getValue(context);
- if (null == result || result.toString().length()==0) {
- result = "";
+ if (null == result || result.toString().length() == 0) {
+ result = "";
}
return result.toString();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.ajax4jsf.renderkit.compiler.ElementBase#getAllowedClasses()
*/
- protected Class[] getAllowedClasses() {
- // TODO Auto-generated method stub
- return new Class[]{
- MethodParameterElement.class,
- ResourceElement.class
- };
+ @SuppressWarnings("unchecked")
+ protected Class<? extends ElementBase>[] getAllowedClasses() {
+ return new Class[] { MethodParameterElement.class,
+ ResourceElement.class };
}
}
-class InvokeData {
- TemplateContext context;
- Method method;
- Object object;
- Object[] arguments;
- InvokeData(TemplateContext context, Method method, Object object, Object[] arguments) {
- this.context = context;
- this.method = method;
- this.object = object;
- this.arguments = (Object[]) arguments.clone();
- }
-}
+abstract class Invoker {
-class Invoker {
- String methodName;
+ protected volatile Signature current;
- InvokeData invokeMethod(TemplateContext context, MethodCacheState state) {
- throw new FacesException(Messages.getMessage(Messages.RENDERER_METHOD_NOT_SET_ERROR));
+ protected String methodName;
+
+ public Invoker(String name) {
+ this.methodName = name;
}
- void handleInvocationTargetException(TemplateContext context, InvocationTargetException e) {}
- void handleIllegalAccessException(TemplateContext context, IllegalAccessException e) {}
- void handleMethodNotFoundException(TemplateContext context) throws MethodNotFoundException {}
-
- InvokeData invokeMethod(TemplateContext context, Map methods, Class cls, Object object, MethodCacheState state) {
- Method method = provideMethod(methods, cls, object, state);
- return new InvokeData(context, method, object, state.current.arguments);
- }
-
- Object invokeMethod(InvokeData data) {
- if(data.method != null) {
+ public Object invokeMethod(TemplateContext context, Object[] parameters) {
+ Object result = null;
+ Class<?>[] parameterTypes = new Class[parameters.length];
+ for (int i = 0; i < parameters.length; i++) {
+ Object parameter = parameters[i];
+ if (null != parameter) {
+ parameterTypes[i] = parameter.getClass();
+ }
+ }
+ // Use a copy to avoid synchronization.
+ Signature signature = current;
+ if (null == signature
+ || !signature.isApplicable(context, getInvokedClass(context),
+ parameterTypes)) {
+ // Clalculate target signature
+ signature = provideMethod(context, parameterTypes);
+ current = signature;
+ }
try {
- return data.method.invoke(data.object, data.arguments);
+ result = signature.invoke(context, getInvokedObject(context),
+ parameters);
+ } catch (IllegalArgumentException e) {
+ throw new FacesException(e);
+ } catch (IllegalAccessException e) {
+ handleIllegalAccessException(context, e);
} catch (InvocationTargetException e) {
- handleInvocationTargetException(data.context, e);
- } catch (IllegalAccessException e) {
- handleIllegalAccessException(data.context, e);
+ handleInvocationTargetException(context, e);
}
- }
- handleMethodNotFoundException(data.context);
- return null;
+ return result;
}
-
- public Class getInvokedClass(TemplateContext context) {
- return null;
- }
-
- private Method provideMethod(Map methods, Class cls, Object object, MethodCacheState state) {
- if(state.method != null) return state.method;
- if(methods.size() > 0) {
- for (int i = 0; i < state.signatures.length; i++) {
- state.method = (Method)methods.get(getClassesKey(state.signatures[i].arguments));
- if(state.method != null) {
- state.current = state.signatures[i];
- return state.method;
+ abstract void handleInvocationTargetException(TemplateContext context,
+ InvocationTargetException e);
+
+ abstract void handleIllegalAccessException(TemplateContext context,
+ IllegalAccessException e);
+
+ abstract void handleMethodNotFoundException(TemplateContext context);
+
+ public abstract Class<?> getInvokedClass(TemplateContext context);
+
+ public abstract Object getInvokedObject(TemplateContext context);
+
+ protected Signature provideMethod(TemplateContext context,
+ Class<?>[] parameterTypes) {
+ Class<?> cls = getInvokedClass(context);
+ if (null != cls) {
+ // TODO - cache signatures ?
+ Object object = getInvokedObject(context);
+ Method[] methods = cls.getMethods();
+ for (int m = 0; m < methods.length; m++) {
+ if (methods[m].getName().equals(methodName)
+ && (object != null || Modifier.isStatic(methods[m]
+ .getModifiers()))) {
+ Signature s = new Signature0(methods[m]);
+ if (s.isApplicable(context, cls, parameterTypes)) {
+ return s;
+ }
+ s = new Signature1(methods[m]);
+ if (s.isApplicable(context, cls, parameterTypes)) {
+ return s;
+ }
+ s = new Signature2(methods[m]);
+ if (s.isApplicable(context, cls, parameterTypes)) {
+ return s;
+ }
}
}
}
-
- if(cls == null && object != null) cls = object.getClass();
- Method[] ms = cls.getMethods();
- for (int m = 0; m < ms.length; m++) {
- if(!ms[m].getName().equals(methodName)) continue;
- if(object == null && !Modifier.isStatic(ms[m].getModifiers())) continue;
- Class[] cs = ms[m].getParameterTypes();
- Signature s = getMatchingArguments(cs, state.signatures);
- if(s == null) continue;
- state.current = s;
- state.method = ms[m];
- methods.put(getClassesKey(s.arguments), ms[m]);
- return state.method;
- }
-
+ handleMethodNotFoundException(context);
return null;
}
- private String getClassesKey(Object[] args) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < args.length; i++) {
- String dk = args[i] == null ? "null" : args[i].getClass().getName();
- sb.append(";").append(dk);
- }
- return sb.toString();
- }
-
- private Signature getMatchingArguments(Class[] cs, Signature[] sgs) {
- for (int i = 0; i < sgs.length; i++) {
- if(isMatching(cs, sgs[i].arguments)) return sgs[i];
- }
- return null;
- }
-
- static boolean isMatching(Class[] cs, Object[] args) {
- if(cs.length != args.length) return false;
+ static boolean isMatching(Class<?>[] cs, Class<?>[] args) {
+ if (cs.length != args.length)
+ return false;
for (int i = 0; i < cs.length; i++) {
- if(args[i] != null && !cs[i].isAssignableFrom(args[i].getClass())) return false;
+ if (args[i] != null && !cs[i].isAssignableFrom(args[i]))
+ return false;
}
return true;
}
}
class RendererInvoker extends Invoker {
- boolean utils = false;
- Map renderers = new HashMap();
-
- public RendererInvoker(boolean utils, String methodName) {
- this.utils = utils;
- this.methodName = methodName;
+
+ public RendererInvoker(String methodName) {
+ super(methodName);
}
- public Class getInvokedClass(TemplateContext context) {
+ public Class<? extends Object> getInvokedClass(TemplateContext context) {
Object object = getInvokedObject(context);
- return (object != null) ? object.getClass() : null;
+ return (object != null) ? object.getClass() : Renderer.class;
}
-
- private Object getInvokedObject(TemplateContext context) {
- if(utils) {
- return context.getRenderer().getUtils();
- } else {
- return context.getRenderer();
- }
+
+ public Object getInvokedObject(TemplateContext context) {
+ return context.getRenderer();
}
-
- InvokeData invokeMethod(TemplateContext context, MethodCacheState state) {
+
+ void handleInvocationTargetException(TemplateContext context,
+ InvocationTargetException e) {
+ String logMessage = Messages.getMessage(Messages.METHOD_CALL_ERROR_1a,
+ methodName, context.getComponent().getId());
+ String excMessage = Messages.getMessage(Messages.METHOD_CALL_ERROR_2a,
+ new Object[] { methodName, context.getComponent().getId(),
+ e.getCause().getMessage() });
+ MethodCallElement._log.error(logMessage, e);
+ throw new FacesException(excMessage, e);
+ }
+
+ void handleIllegalAccessException(TemplateContext context,
+ IllegalAccessException e) {
+ String logMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_3a, methodName, context
+ .getComponent().getId()));
+ String excMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_4a, new Object[] { methodName,
+ context.getComponent().getId(),
+ e.getCause().getMessage() }));
+ MethodCallElement._log.error(logMessage, e);
+ throw new FacesException(excMessage, e);
+ }
+
+ void handleMethodNotFoundException(TemplateContext context)
+ throws MethodNotFoundException {
+ String logMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_5a, methodName, context
+ .getComponent().getId()));
+ String excMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_6a, methodName));
+ MethodCallElement._log.error(logMessage);
+ throw new FacesException(excMessage);
+ }
+}
+
+class RendererUtilsInvoker extends RendererInvoker {
+
+ public RendererUtilsInvoker(String methodName) {
+ super(methodName);
+ }
+
+ public Class<? extends Object> getInvokedClass(TemplateContext context) {
Object object = getInvokedObject(context);
- Map methods = getMethods(object);
- return invokeMethod(context, methods, null, object, state);
+ return (object != null) ? object.getClass() : RendererUtils.class;
}
-
- private Map getMethods(Object object) {
- if(object == null) return null;
- Map methods = (Map)renderers.get(object);
- if(methods == null) {
- methods = new HashMap();
- renderers.put(object, methods);
- }
- return methods;
+
+ public Object getInvokedObject(TemplateContext context) {
+ RendererBase renderer = context.getRenderer();
+ return null != renderer ? renderer.getUtils() : null;
}
- void handleInvocationTargetException(TemplateContext context, InvocationTargetException e) {
- String logMessage = (utils)
- ? Messages.getMessage(Messages.METHOD_CALL_ERROR_1, methodName, context.getComponent().getId())
- : Messages.getMessage(Messages.METHOD_CALL_ERROR_1a, methodName, context.getComponent().getId());
- String excMessage = (utils)
- ? Messages.getMessage(Messages.METHOD_CALL_ERROR_2, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()})
- : Messages.getMessage(Messages.METHOD_CALL_ERROR_2a, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()});
+ void handleInvocationTargetException(TemplateContext context,
+ InvocationTargetException e) {
+ String logMessage = Messages.getMessage(Messages.METHOD_CALL_ERROR_1,
+ methodName, context.getComponent().getId());
+ String excMessage = Messages.getMessage(Messages.METHOD_CALL_ERROR_2,
+ new Object[] { methodName, context.getComponent().getId(),
+ e.getCause().getMessage() });
MethodCallElement._log.error(logMessage, e);
throw new FacesException(excMessage, e);
}
- void handleIllegalAccessException(TemplateContext context, IllegalAccessException e) {
- String logMessage = (utils)
- ? Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_3, methodName, context.getComponent().getId()))
- : Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_3a, methodName, context.getComponent().getId()));
- String excMessage = (utils)
- ? Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_4, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()}))
- : Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_4a, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()}));
+
+ void handleIllegalAccessException(TemplateContext context,
+ IllegalAccessException e) {
+ String logMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_3, methodName, context
+ .getComponent().getId()));
+ String excMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_4, new Object[] { methodName,
+ context.getComponent().getId(),
+ e.getCause().getMessage() }));
MethodCallElement._log.error(logMessage, e);
throw new FacesException(excMessage, e);
}
-
- void handleMethodNotFoundException(TemplateContext context) throws MethodNotFoundException {
- String logMessage = (utils)
- ? Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_5, methodName, context.getComponent().getId()))
- : Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_5a, methodName, context.getComponent().getId()));
- String excMessage = (utils)
- ? Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_6, methodName))
- : Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_6a, methodName));
- MethodCallElement._log.error(logMessage);
+
+ void handleMethodNotFoundException(TemplateContext context)
+ throws MethodNotFoundException {
+ String logMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_5, methodName, context
+ .getComponent().getId()));
+ String excMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_6, methodName));
+ MethodCallElement._log.error(logMessage);
throw new FacesException(excMessage);
}
}
class StaticInvoker extends Invoker {
String className;
- Class cls;
- Map methods = new HashMap();
-
+ Class<?> cls;
+ Map<String, Method> methods = new HashMap<String, Method>();
+
StaticInvoker(String methodName) {
- this.methodName = methodName;
+ super(methodName);
int i = methodName.lastIndexOf('.');
className = methodName.substring(0, i);
this.methodName = methodName.substring(i + 1);
try {
- cls = Thread.currentThread().getContextClassLoader().loadClass(className);
+ cls = Thread.currentThread().getContextClassLoader().loadClass(
+ className);
} catch (ClassNotFoundException e) {
- //ignore, throw exception when invoking
+ // ignore, throw exception when invoking
}
}
- InvokeData invokeMethod(TemplateContext context, MethodCacheState state) {
- if(cls == null) throw new FacesException(className, new ClassNotFoundException(className));
- return invokeMethod(context, methods, cls, null, state);
+ @Override
+ public Class<?> getInvokedClass(TemplateContext context) {
+ return cls;
}
- void handleInvocationTargetException(TemplateContext context, InvocationTargetException e) {
- MethodCallElement._log.error(Messages.getMessage(Messages.METHOD_CALL_ERROR_1a, methodName, context.getComponent().getId()), e);
- throw new FacesException(Messages.getMessage(Messages.METHOD_CALL_ERROR_2a, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()}), e);
+ @Override
+ public Object getInvokedObject(TemplateContext context) {
+ return null;
}
- void handleIllegalAccessException(TemplateContext context, IllegalAccessException e) {
- MethodCallElement._log.error(Messages.getMessage(Messages.METHOD_CALL_ERROR_3a, methodName, context.getComponent().getId()), e);
- throw new FacesException(Messages.getMessage(Messages.METHOD_CALL_ERROR_4a, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()}), e);
- }
- void handleMethodNotFoundException(TemplateContext context) throws MethodNotFoundException {
- MethodCallElement._log.error(Messages.getMessage(Messages.METHOD_CALL_ERROR_5a, methodName, context.getComponent().getId()));
- throw new MethodNotFoundException(Messages.getMessage(Messages.METHOD_CALL_ERROR_6a, methodName));
+
+ void handleInvocationTargetException(TemplateContext context,
+ InvocationTargetException e) {
+ MethodCallElement._log.error(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_1a, methodName, context
+ .getComponent().getId()), e);
+ throw new FacesException(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_2a, new Object[] { methodName,
+ context.getComponent().getId(),
+ e.getCause().getMessage() }), e);
}
+
+ void handleIllegalAccessException(TemplateContext context,
+ IllegalAccessException e) {
+ MethodCallElement._log.error(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_3a, methodName, context
+ .getComponent().getId()), e);
+ throw new FacesException(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_4a, new Object[] { methodName,
+ context.getComponent().getId(),
+ e.getCause().getMessage() }), e);
+ }
+
+ void handleMethodNotFoundException(TemplateContext context)
+ throws MethodNotFoundException {
+ MethodCallElement._log.error(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_5a, methodName, context
+ .getComponent().getId()));
+ throw new MethodNotFoundException(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_6a, methodName));
+ }
+
}
-class MethodCacheState {
- private MethodParameterElement[] elements;
- private Class[] parameterClasses;
- private Object[] parameterValues;
- private Class lastCallingClass = null;
- public Method method;
- public Signature current;
- public Signature[] signatures;
-
- public void init(List parameters) {
- if(elements != null) return;
- synchronized (this) {
- if(elements != null) return;
- int size = parameters.size();
- parameterClasses = new Class[size];
- parameterValues = new Object[size];
- signatures = new Signature[3];
- signatures[0] = new Signature2(size);
- signatures[1] = new Signature1(size);
- signatures[2] = new Signature0(size);
- elements = (MethodParameterElement[])parameters.toArray(new MethodParameterElement[0]);
- }
+abstract class Signature {
+
+ Method method;
+
+ Signature(Method method) {
+ this.method = method;
}
-
- public Object[] computeParameterValues(TemplateContext context) {
- Object[] ps = new Object[elements.length];
- for (int i = 0; i < elements.length; i++) {
- ps[i] = elements[i].valueGetter.getValueOrDefault(context);
+
+ boolean isApplicable(TemplateContext context, Class targetClass,
+ Class<?>[] parameters) {
+ if (!method.getDeclaringClass().isAssignableFrom(targetClass)) {
+ return false;
}
- return ps;
- }
-
- public void update(TemplateContext context, Object[] values, Invoker invoker) {
- boolean changed = false;
- for (int i = 0; i < elements.length; i++) {
- Object parametr = values[i];
- Class c = (parametr == null) ? null : parametr.getClass();
- if(c != parameterClasses[i]) {
- parameterClasses[i] = c;
- changed = true;
- }
- parameterValues[i] = parametr;
+ Class<?>[] methodParameterTypes = this.method.getParameterTypes();
+ Class<?>[] parameterTypes = getParameterTypes(context, parameters);
+ if (methodParameterTypes.length != parameterTypes.length) {
+ return false;
}
- if(method != null && !changed && lastCallingClass != invoker.getInvokedClass(context)) {
- lastCallingClass = invoker.getInvokedClass(context);
- changed = true;
- }
- if(changed || current == null) {
- for (int i = 0; i < signatures.length; i++) {
- signatures[i].update(context, parameterValues);
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (null != parameterTypes[i]
+ && !methodParameterTypes[i]
+ .isAssignableFrom(parameterTypes[i])) {
+ return false;
}
- method = null;
- current = null;
- } else {
- current.update(context, parameterValues);
}
- }
-
-}
+ return true;
+ }
-abstract class Signature {
- Object[] arguments;
+ abstract Class<?>[] getParameterTypes(TemplateContext context,
+ Class<?>[] parameters);
- Signature() {}
+ abstract Object[] getParameterValues(TemplateContext context,
+ Object[] parameters);
- void update(TemplateContext context, Object[] parameters) {}
+ Object invoke(TemplateContext context, Object target, Object[] parameters)
+ throws IllegalArgumentException, IllegalAccessException,
+ InvocationTargetException {
+ return this.method.invoke(target, getParameterValues(context,
+ parameters));
+ }
+
}
class Signature0 extends Signature {
- Signature0(int size) {
- arguments = new Object[size];
+
+ Signature0(Method method) {
+ super(method);
}
- void update(TemplateContext context, Object[] parameters) {
- System.arraycopy(parameters, 0, arguments, 0, parameters.length);
+ @Override
+ Class<?>[] getParameterTypes(TemplateContext context, Class<?>[] parameters) {
+ return parameters;
}
-
+
+ @Override
+ Object[] getParameterValues(TemplateContext context, Object[] parameters) {
+ return parameters;
+ }
+
}
class Signature1 extends Signature {
- Signature1(int size) {
- arguments = new Object[size + 1];
+ Signature1(Method method) {
+ super(method);
}
- void update(TemplateContext context, Object[] parameters) {
- arguments[0] = context;
- System.arraycopy(parameters, 0, arguments, 1, parameters.length);
+
+ @Override
+ Class<?>[] getParameterTypes(TemplateContext context, Class<?>[] parameters) {
+ Class<?>[] types = new Class[parameters.length + 1];
+ types[0] = TemplateContext.class;
+ System.arraycopy(parameters, 0, types, 1, parameters.length);
+ return types;
}
-
+
+ @Override
+ Object[] getParameterValues(TemplateContext context, Object[] parameters) {
+ Object[] values = new Object[parameters.length + 1];
+ values[0] = context;
+ System.arraycopy(parameters, 0, values, 1, parameters.length);
+ return values;
+ }
+
}
class Signature2 extends Signature {
- Signature2(int size) {
- arguments = new Object[size + 2];
+ Signature2(Method method) {
+ super(method);
}
- void update(TemplateContext context, Object[] parameters) {
- arguments[0] = context.getFacesContext();
- arguments[1] = context.getComponent();
- System.arraycopy(parameters, 0, arguments, 2, parameters.length);
- }
+
+ @Override
+ Class<?>[] getParameterTypes(TemplateContext context, Class<?>[] parameters) {
+ Class<?>[] types = new Class[parameters.length + 2];
+ types[0] = FacesContext.class;
+ types[1] = context.getComponent().getClass();
+ System.arraycopy(parameters, 0, types, 2, parameters.length);
+ return types;
+ }
+
+ @Override
+ Object[] getParameterValues(TemplateContext context, Object[] parameters) {
+ Object[] values = new Object[parameters.length + 2];
+ values[0] = context.getFacesContext();
+ values[1] = context.getComponent();
+ System.arraycopy(parameters, 0, values, 2, parameters.length);
+ return values;
+ }
}
15 years, 1 month
JBoss Rich Faces SVN: r15931 - in tags: rf_363451/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2009-11-19 14:15:29 -0500 (Thu, 19 Nov 2009)
New Revision: 15931
Added:
tags/rf_363451/
Modified:
tags/rf_363451/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/MethodCallElement.java
Log:
RFPL-252
Copied: tags/rf_363451 (from rev 15930, branches/enterprise/3.3.X)
Modified: tags/rf_363451/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/MethodCallElement.java
===================================================================
--- branches/enterprise/3.3.X/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/MethodCallElement.java 2009-11-19 16:13:11 UTC (rev 15930)
+++ tags/rf_363451/framework/impl/src/main/java/org/ajax4jsf/renderkit/compiler/MethodCallElement.java 2009-11-19 19:15:29 UTC (rev 15931)
@@ -31,73 +31,88 @@
import java.util.Map;
import javax.faces.FacesException;
+import javax.faces.context.FacesContext;
import javax.faces.el.MethodNotFoundException;
+import javax.faces.render.Renderer;
import org.ajax4jsf.Messages;
+import org.ajax4jsf.renderkit.RendererBase;
+import org.ajax4jsf.renderkit.RendererUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.xml.sax.SAXException;
-
/**
* @author asmirnov(a)exadel.com (latest modification by $Author: alexsmirnov $)
* @version $Revision: 1.1.2.1 $ $Date: 2007/01/09 18:57:47 $
- *
+ *
*/
-public class MethodCallElement extends ElementBase {
+public class MethodCallElement extends ElementBase {
public static final String UTILS_PREFIX = "utils.";
-
+
static final Log _log = LogFactory.getLog(MethodCallElement.class);
private String _name = null;
-
- private List parameters = new ArrayList();
-
- private Invoker invoker = new Invoker();
-
- private MethodCacheState state = new MethodCacheState();
-
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.renderkit.compiler.CompiledXML#encode(javax.faces.render.Renderer, javax.faces.context.FacesContext, javax.faces.component.UIComponent)
+
+ private List<MethodParameterElement> parameters = new ArrayList<MethodParameterElement>(
+ 3);
+
+ private volatile Invoker invoker;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.compiler.CompiledXML#encode(javax.faces.render
+ * .Renderer, javax.faces.context.FacesContext,
+ * javax.faces.component.UIComponent)
*/
- public void encode(TemplateContext context ) throws IOException {
- getValue(context);
+ public void encode(TemplateContext context) throws IOException {
+ getValue(context);
}
- /* (non-Javadoc)
- * @see org.ajax4jsf.renderkit.compiler.ElementBase#encode(org.ajax4jsf.renderkit.compiler.TemplateContext, java.lang.String)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.compiler.ElementBase#encode(org.ajax4jsf.renderkit
+ * .compiler.TemplateContext, java.lang.String)
*/
- public void encode(TemplateContext context, String breakPoint) throws IOException {
+ public void encode(TemplateContext context, String breakPoint)
+ throws IOException {
// Text not contain breakpoints.
encode(context);
}
-
-
+
public Object getValue(TemplateContext context) throws FacesException {
+ if (null == invoker) {
+ throw new FacesException(Messages
+ .getMessage(Messages.RENDERER_METHOD_NOT_SET_ERROR));
+ }
// prepare method params. we attempt to call 3 signatures :
// a) name(FacesContext,UIComponent [, param0...])
// b) name(TempalateContext [,param0...])
// c) name([param0...])
- state.init(parameters);
- Object[] values = state.computeParameterValues(context);
-
- InvokeData data = null;
- synchronized (state) {
- state.update(context, values, invoker);
- data = invoker.invokeMethod(context, state);
- }
- return invoker.invokeMethod(data);
+ Object[] values = computeParameterValues(context);
+
+ return invoker.invokeMethod(context, values);
// perform childrens.
// super.encode(renderer,context,component);
}
+ public Object[] computeParameterValues(TemplateContext context) {
+ Object[] ps = new Object[parameters.size()];
+ for (int i = 0; i < ps.length; i++) {
+ ps[i] = parameters.get(i).valueGetter.getValueOrDefault(context);
+ }
+ return ps;
+ }
-
- public void addParameter(MethodParameterElement parameter){
+ public void addParameter(MethodParameterElement parameter) {
parameters.add(parameter);
}
+
/**
* @return Returns the methodName.
*/
@@ -106,13 +121,14 @@
}
/**
- * @param methodName The methodName to set.
+ * @param methodName
+ * The methodName to set.
*/
public void setName(String methodName) {
- if(methodName.startsWith(UTILS_PREFIX)){
+ if (methodName.startsWith(UTILS_PREFIX)) {
this._name = methodName.substring(UTILS_PREFIX.length());
this.invoker = getRendererUtilsInvoker(_name);
- } else if(methodName.indexOf('.') >= 0) {
+ } else if (methodName.indexOf('.') >= 0) {
this._name = methodName;
this.invoker = getStaticInvoker(_name);
} else {
@@ -121,385 +137,430 @@
}
}
- static Map staticInvokers = new HashMap();
-
- public StaticInvoker getStaticInvoker(String methodName) {
- StaticInvoker invoker = (StaticInvoker)staticInvokers.get(methodName);
- if(invoker == null) {
- invoker = new StaticInvoker(methodName);
- staticInvokers.put(methodName, invoker);
- }
- return invoker;
+ public Invoker getStaticInvoker(String methodName) {
+ StaticInvoker invoker = new StaticInvoker(methodName);
+ return invoker;
}
- static Map rendererInvokers = new HashMap();
-
- public RendererInvoker getRendererInvoker(String methodName) {
- RendererInvoker invoker = (RendererInvoker)rendererInvokers.get(methodName);
- if(invoker == null) {
- invoker = new RendererInvoker(false, methodName);
- rendererInvokers.put(methodName, invoker);
- }
+ public Invoker getRendererInvoker(String methodName) {
+ RendererInvoker invoker = new RendererInvoker(methodName);
return invoker;
}
-
- static Map utilsInvokers = new HashMap();
- public RendererInvoker getRendererUtilsInvoker(String methodName) {
- RendererInvoker invoker = (RendererInvoker)utilsInvokers.get(methodName);
- if(invoker == null) {
- invoker = new RendererInvoker(true, methodName);
- utilsInvokers.put(methodName, invoker);
- }
+ public Invoker getRendererUtilsInvoker(String methodName) {
+ RendererInvoker invoker = new RendererUtilsInvoker(methodName);
return invoker;
}
-
+
public String getTag() {
- return HtmlCompiler.NS_PREFIX+HtmlCompiler.CALL_TAG;
+ return HtmlCompiler.NS_PREFIX + HtmlCompiler.CALL_TAG;
}
-
- /* (non-Javadoc)
- * @see org.ajax4jsf.renderkit.compiler.ElementBase#setParent(org.ajax4jsf.renderkit.compiler.PreparedTemplate)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.compiler.ElementBase#setParent(org.ajax4jsf.renderkit
+ * .compiler.PreparedTemplate)
*/
- public void setParent(PreparedTemplate parent) throws SAXException {
+ public void setParent(PreparedTemplate parent) throws SAXException {
super.setParent(parent);
- if (getName()==null) {
- throw new SAXException(Messages.getMessage(Messages.NO_NAME_ATTRIBUTE_ERROR, getTag()));
+ if (getName() == null) {
+ throw new SAXException(Messages.getMessage(
+ Messages.NO_NAME_ATTRIBUTE_ERROR, getTag()));
}
}
-
-/* (non-Javadoc)
- * @see org.ajax4jsf.renderkit.compiler.ElementBase#getString(org.ajax4jsf.renderkit.compiler.TemplateContext)
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.ajax4jsf.renderkit.compiler.ElementBase#getString(org.ajax4jsf.renderkit
+ * .compiler.TemplateContext)
*/
public String getString(TemplateContext context) throws FacesException {
Object result = getValue(context);
- if (null == result || result.toString().length()==0) {
- result = "";
+ if (null == result || result.toString().length() == 0) {
+ result = "";
}
return result.toString();
}
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see org.ajax4jsf.renderkit.compiler.ElementBase#getAllowedClasses()
*/
- protected Class[] getAllowedClasses() {
- // TODO Auto-generated method stub
- return new Class[]{
- MethodParameterElement.class,
- ResourceElement.class
- };
+ @SuppressWarnings("unchecked")
+ protected Class<? extends ElementBase>[] getAllowedClasses() {
+ return new Class[] { MethodParameterElement.class,
+ ResourceElement.class };
}
}
-class InvokeData {
- TemplateContext context;
- Method method;
- Object object;
- Object[] arguments;
- InvokeData(TemplateContext context, Method method, Object object, Object[] arguments) {
- this.context = context;
- this.method = method;
- this.object = object;
- this.arguments = (Object[]) arguments.clone();
- }
-}
+abstract class Invoker {
-class Invoker {
- String methodName;
+ protected volatile Signature current;
- InvokeData invokeMethod(TemplateContext context, MethodCacheState state) {
- throw new FacesException(Messages.getMessage(Messages.RENDERER_METHOD_NOT_SET_ERROR));
+ protected String methodName;
+
+ public Invoker(String name) {
+ this.methodName = name;
}
- void handleInvocationTargetException(TemplateContext context, InvocationTargetException e) {}
- void handleIllegalAccessException(TemplateContext context, IllegalAccessException e) {}
- void handleMethodNotFoundException(TemplateContext context) throws MethodNotFoundException {}
-
- InvokeData invokeMethod(TemplateContext context, Map methods, Class cls, Object object, MethodCacheState state) {
- Method method = provideMethod(methods, cls, object, state);
- return new InvokeData(context, method, object, state.current.arguments);
- }
-
- Object invokeMethod(InvokeData data) {
- if(data.method != null) {
+ public Object invokeMethod(TemplateContext context, Object[] parameters) {
+ Object result = null;
+ Class<?>[] parameterTypes = new Class[parameters.length];
+ for (int i = 0; i < parameters.length; i++) {
+ Object parameter = parameters[i];
+ if (null != parameter) {
+ parameterTypes[i] = parameter.getClass();
+ }
+ }
+ // Use a copy to avoid synchronization.
+ Signature signature = current;
+ if (null == signature
+ || !signature.isApplicable(context, getInvokedClass(context),
+ parameterTypes)) {
+ // Clalculate target signature
+ signature = provideMethod(context, parameterTypes);
+ current = signature;
+ }
try {
- return data.method.invoke(data.object, data.arguments);
+ result = signature.invoke(context, getInvokedObject(context),
+ parameters);
+ } catch (IllegalArgumentException e) {
+ throw new FacesException(e);
+ } catch (IllegalAccessException e) {
+ handleIllegalAccessException(context, e);
} catch (InvocationTargetException e) {
- handleInvocationTargetException(data.context, e);
- } catch (IllegalAccessException e) {
- handleIllegalAccessException(data.context, e);
+ handleInvocationTargetException(context, e);
}
- }
- handleMethodNotFoundException(data.context);
- return null;
+ return result;
}
-
- public Class getInvokedClass(TemplateContext context) {
- return null;
- }
-
- private Method provideMethod(Map methods, Class cls, Object object, MethodCacheState state) {
- if(state.method != null) return state.method;
- if(methods.size() > 0) {
- for (int i = 0; i < state.signatures.length; i++) {
- state.method = (Method)methods.get(getClassesKey(state.signatures[i].arguments));
- if(state.method != null) {
- state.current = state.signatures[i];
- return state.method;
+ abstract void handleInvocationTargetException(TemplateContext context,
+ InvocationTargetException e);
+
+ abstract void handleIllegalAccessException(TemplateContext context,
+ IllegalAccessException e);
+
+ abstract void handleMethodNotFoundException(TemplateContext context);
+
+ public abstract Class<?> getInvokedClass(TemplateContext context);
+
+ public abstract Object getInvokedObject(TemplateContext context);
+
+ protected Signature provideMethod(TemplateContext context,
+ Class<?>[] parameterTypes) {
+ Class<?> cls = getInvokedClass(context);
+ if (null != cls) {
+ // TODO - cache signatures ?
+ Object object = getInvokedObject(context);
+ Method[] methods = cls.getMethods();
+ for (int m = 0; m < methods.length; m++) {
+ if (methods[m].getName().equals(methodName)
+ && (object != null || Modifier.isStatic(methods[m]
+ .getModifiers()))) {
+ Signature s = new Signature0(methods[m]);
+ if (s.isApplicable(context, cls, parameterTypes)) {
+ return s;
+ }
+ s = new Signature1(methods[m]);
+ if (s.isApplicable(context, cls, parameterTypes)) {
+ return s;
+ }
+ s = new Signature2(methods[m]);
+ if (s.isApplicable(context, cls, parameterTypes)) {
+ return s;
+ }
}
}
}
-
- if(cls == null && object != null) cls = object.getClass();
- Method[] ms = cls.getMethods();
- for (int m = 0; m < ms.length; m++) {
- if(!ms[m].getName().equals(methodName)) continue;
- if(object == null && !Modifier.isStatic(ms[m].getModifiers())) continue;
- Class[] cs = ms[m].getParameterTypes();
- Signature s = getMatchingArguments(cs, state.signatures);
- if(s == null) continue;
- state.current = s;
- state.method = ms[m];
- methods.put(getClassesKey(s.arguments), ms[m]);
- return state.method;
- }
-
+ handleMethodNotFoundException(context);
return null;
}
- private String getClassesKey(Object[] args) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < args.length; i++) {
- String dk = args[i] == null ? "null" : args[i].getClass().getName();
- sb.append(";").append(dk);
- }
- return sb.toString();
- }
-
- private Signature getMatchingArguments(Class[] cs, Signature[] sgs) {
- for (int i = 0; i < sgs.length; i++) {
- if(isMatching(cs, sgs[i].arguments)) return sgs[i];
- }
- return null;
- }
-
- static boolean isMatching(Class[] cs, Object[] args) {
- if(cs.length != args.length) return false;
+ static boolean isMatching(Class<?>[] cs, Class<?>[] args) {
+ if (cs.length != args.length)
+ return false;
for (int i = 0; i < cs.length; i++) {
- if(args[i] != null && !cs[i].isAssignableFrom(args[i].getClass())) return false;
+ if (args[i] != null && !cs[i].isAssignableFrom(args[i]))
+ return false;
}
return true;
}
}
class RendererInvoker extends Invoker {
- boolean utils = false;
- Map renderers = new HashMap();
-
- public RendererInvoker(boolean utils, String methodName) {
- this.utils = utils;
- this.methodName = methodName;
+
+ public RendererInvoker(String methodName) {
+ super(methodName);
}
- public Class getInvokedClass(TemplateContext context) {
+ public Class<? extends Object> getInvokedClass(TemplateContext context) {
Object object = getInvokedObject(context);
- return (object != null) ? object.getClass() : null;
+ return (object != null) ? object.getClass() : Renderer.class;
}
-
- private Object getInvokedObject(TemplateContext context) {
- if(utils) {
- return context.getRenderer().getUtils();
- } else {
- return context.getRenderer();
- }
+
+ public Object getInvokedObject(TemplateContext context) {
+ return context.getRenderer();
}
-
- InvokeData invokeMethod(TemplateContext context, MethodCacheState state) {
+
+ void handleInvocationTargetException(TemplateContext context,
+ InvocationTargetException e) {
+ String logMessage = Messages.getMessage(Messages.METHOD_CALL_ERROR_1a,
+ methodName, context.getComponent().getId());
+ String excMessage = Messages.getMessage(Messages.METHOD_CALL_ERROR_2a,
+ new Object[] { methodName, context.getComponent().getId(),
+ e.getCause().getMessage() });
+ MethodCallElement._log.error(logMessage, e);
+ throw new FacesException(excMessage, e);
+ }
+
+ void handleIllegalAccessException(TemplateContext context,
+ IllegalAccessException e) {
+ String logMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_3a, methodName, context
+ .getComponent().getId()));
+ String excMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_4a, new Object[] { methodName,
+ context.getComponent().getId(),
+ e.getCause().getMessage() }));
+ MethodCallElement._log.error(logMessage, e);
+ throw new FacesException(excMessage, e);
+ }
+
+ void handleMethodNotFoundException(TemplateContext context)
+ throws MethodNotFoundException {
+ String logMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_5a, methodName, context
+ .getComponent().getId()));
+ String excMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_6a, methodName));
+ MethodCallElement._log.error(logMessage);
+ throw new FacesException(excMessage);
+ }
+}
+
+class RendererUtilsInvoker extends RendererInvoker {
+
+ public RendererUtilsInvoker(String methodName) {
+ super(methodName);
+ }
+
+ public Class<? extends Object> getInvokedClass(TemplateContext context) {
Object object = getInvokedObject(context);
- Map methods = getMethods(object);
- return invokeMethod(context, methods, null, object, state);
+ return (object != null) ? object.getClass() : RendererUtils.class;
}
-
- private Map getMethods(Object object) {
- if(object == null) return null;
- Map methods = (Map)renderers.get(object);
- if(methods == null) {
- methods = new HashMap();
- renderers.put(object, methods);
- }
- return methods;
+
+ public Object getInvokedObject(TemplateContext context) {
+ RendererBase renderer = context.getRenderer();
+ return null != renderer ? renderer.getUtils() : null;
}
- void handleInvocationTargetException(TemplateContext context, InvocationTargetException e) {
- String logMessage = (utils)
- ? Messages.getMessage(Messages.METHOD_CALL_ERROR_1, methodName, context.getComponent().getId())
- : Messages.getMessage(Messages.METHOD_CALL_ERROR_1a, methodName, context.getComponent().getId());
- String excMessage = (utils)
- ? Messages.getMessage(Messages.METHOD_CALL_ERROR_2, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()})
- : Messages.getMessage(Messages.METHOD_CALL_ERROR_2a, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()});
+ void handleInvocationTargetException(TemplateContext context,
+ InvocationTargetException e) {
+ String logMessage = Messages.getMessage(Messages.METHOD_CALL_ERROR_1,
+ methodName, context.getComponent().getId());
+ String excMessage = Messages.getMessage(Messages.METHOD_CALL_ERROR_2,
+ new Object[] { methodName, context.getComponent().getId(),
+ e.getCause().getMessage() });
MethodCallElement._log.error(logMessage, e);
throw new FacesException(excMessage, e);
}
- void handleIllegalAccessException(TemplateContext context, IllegalAccessException e) {
- String logMessage = (utils)
- ? Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_3, methodName, context.getComponent().getId()))
- : Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_3a, methodName, context.getComponent().getId()));
- String excMessage = (utils)
- ? Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_4, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()}))
- : Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_4a, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()}));
+
+ void handleIllegalAccessException(TemplateContext context,
+ IllegalAccessException e) {
+ String logMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_3, methodName, context
+ .getComponent().getId()));
+ String excMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_4, new Object[] { methodName,
+ context.getComponent().getId(),
+ e.getCause().getMessage() }));
MethodCallElement._log.error(logMessage, e);
throw new FacesException(excMessage, e);
}
-
- void handleMethodNotFoundException(TemplateContext context) throws MethodNotFoundException {
- String logMessage = (utils)
- ? Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_5, methodName, context.getComponent().getId()))
- : Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_5a, methodName, context.getComponent().getId()));
- String excMessage = (utils)
- ? Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_6, methodName))
- : Messages.getMessage(Messages.getMessage(Messages.METHOD_CALL_ERROR_6a, methodName));
- MethodCallElement._log.error(logMessage);
+
+ void handleMethodNotFoundException(TemplateContext context)
+ throws MethodNotFoundException {
+ String logMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_5, methodName, context
+ .getComponent().getId()));
+ String excMessage = Messages.getMessage(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_6, methodName));
+ MethodCallElement._log.error(logMessage);
throw new FacesException(excMessage);
}
}
class StaticInvoker extends Invoker {
String className;
- Class cls;
- Map methods = new HashMap();
-
+ Class<?> cls;
+ Map<String, Method> methods = new HashMap<String, Method>();
+
StaticInvoker(String methodName) {
- this.methodName = methodName;
+ super(methodName);
int i = methodName.lastIndexOf('.');
className = methodName.substring(0, i);
this.methodName = methodName.substring(i + 1);
try {
- cls = Thread.currentThread().getContextClassLoader().loadClass(className);
+ cls = Thread.currentThread().getContextClassLoader().loadClass(
+ className);
} catch (ClassNotFoundException e) {
- //ignore, throw exception when invoking
+ // ignore, throw exception when invoking
}
}
- InvokeData invokeMethod(TemplateContext context, MethodCacheState state) {
- if(cls == null) throw new FacesException(className, new ClassNotFoundException(className));
- return invokeMethod(context, methods, cls, null, state);
+ @Override
+ public Class<?> getInvokedClass(TemplateContext context) {
+ return cls;
}
- void handleInvocationTargetException(TemplateContext context, InvocationTargetException e) {
- MethodCallElement._log.error(Messages.getMessage(Messages.METHOD_CALL_ERROR_1a, methodName, context.getComponent().getId()), e);
- throw new FacesException(Messages.getMessage(Messages.METHOD_CALL_ERROR_2a, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()}), e);
+ @Override
+ public Object getInvokedObject(TemplateContext context) {
+ return null;
}
- void handleIllegalAccessException(TemplateContext context, IllegalAccessException e) {
- MethodCallElement._log.error(Messages.getMessage(Messages.METHOD_CALL_ERROR_3a, methodName, context.getComponent().getId()), e);
- throw new FacesException(Messages.getMessage(Messages.METHOD_CALL_ERROR_4a, new Object[]{methodName, context.getComponent().getId(), e.getCause().getMessage()}), e);
- }
- void handleMethodNotFoundException(TemplateContext context) throws MethodNotFoundException {
- MethodCallElement._log.error(Messages.getMessage(Messages.METHOD_CALL_ERROR_5a, methodName, context.getComponent().getId()));
- throw new MethodNotFoundException(Messages.getMessage(Messages.METHOD_CALL_ERROR_6a, methodName));
+
+ void handleInvocationTargetException(TemplateContext context,
+ InvocationTargetException e) {
+ MethodCallElement._log.error(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_1a, methodName, context
+ .getComponent().getId()), e);
+ throw new FacesException(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_2a, new Object[] { methodName,
+ context.getComponent().getId(),
+ e.getCause().getMessage() }), e);
}
+
+ void handleIllegalAccessException(TemplateContext context,
+ IllegalAccessException e) {
+ MethodCallElement._log.error(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_3a, methodName, context
+ .getComponent().getId()), e);
+ throw new FacesException(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_4a, new Object[] { methodName,
+ context.getComponent().getId(),
+ e.getCause().getMessage() }), e);
+ }
+
+ void handleMethodNotFoundException(TemplateContext context)
+ throws MethodNotFoundException {
+ MethodCallElement._log.error(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_5a, methodName, context
+ .getComponent().getId()));
+ throw new MethodNotFoundException(Messages.getMessage(
+ Messages.METHOD_CALL_ERROR_6a, methodName));
+ }
+
}
-class MethodCacheState {
- private MethodParameterElement[] elements;
- private Class[] parameterClasses;
- private Object[] parameterValues;
- private Class lastCallingClass = null;
- public Method method;
- public Signature current;
- public Signature[] signatures;
-
- public void init(List parameters) {
- if(elements != null) return;
- synchronized (this) {
- if(elements != null) return;
- int size = parameters.size();
- parameterClasses = new Class[size];
- parameterValues = new Object[size];
- signatures = new Signature[3];
- signatures[0] = new Signature2(size);
- signatures[1] = new Signature1(size);
- signatures[2] = new Signature0(size);
- elements = (MethodParameterElement[])parameters.toArray(new MethodParameterElement[0]);
- }
+abstract class Signature {
+
+ Method method;
+
+ Signature(Method method) {
+ this.method = method;
}
-
- public Object[] computeParameterValues(TemplateContext context) {
- Object[] ps = new Object[elements.length];
- for (int i = 0; i < elements.length; i++) {
- ps[i] = elements[i].valueGetter.getValueOrDefault(context);
+
+ boolean isApplicable(TemplateContext context, Class targetClass,
+ Class<?>[] parameters) {
+ if (!method.getDeclaringClass().isAssignableFrom(targetClass)) {
+ return false;
}
- return ps;
- }
-
- public void update(TemplateContext context, Object[] values, Invoker invoker) {
- boolean changed = false;
- for (int i = 0; i < elements.length; i++) {
- Object parametr = values[i];
- Class c = (parametr == null) ? null : parametr.getClass();
- if(c != parameterClasses[i]) {
- parameterClasses[i] = c;
- changed = true;
- }
- parameterValues[i] = parametr;
+ Class<?>[] methodParameterTypes = this.method.getParameterTypes();
+ Class<?>[] parameterTypes = getParameterTypes(context, parameters);
+ if (methodParameterTypes.length != parameterTypes.length) {
+ return false;
}
- if(method != null && !changed && lastCallingClass != invoker.getInvokedClass(context)) {
- lastCallingClass = invoker.getInvokedClass(context);
- changed = true;
- }
- if(changed || current == null) {
- for (int i = 0; i < signatures.length; i++) {
- signatures[i].update(context, parameterValues);
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (null != parameterTypes[i]
+ && !methodParameterTypes[i]
+ .isAssignableFrom(parameterTypes[i])) {
+ return false;
}
- method = null;
- current = null;
- } else {
- current.update(context, parameterValues);
}
- }
-
-}
+ return true;
+ }
-abstract class Signature {
- Object[] arguments;
+ abstract Class<?>[] getParameterTypes(TemplateContext context,
+ Class<?>[] parameters);
- Signature() {}
+ abstract Object[] getParameterValues(TemplateContext context,
+ Object[] parameters);
- void update(TemplateContext context, Object[] parameters) {}
+ Object invoke(TemplateContext context, Object target, Object[] parameters)
+ throws IllegalArgumentException, IllegalAccessException,
+ InvocationTargetException {
+ return this.method.invoke(target, getParameterValues(context,
+ parameters));
+ }
+
}
class Signature0 extends Signature {
- Signature0(int size) {
- arguments = new Object[size];
+
+ Signature0(Method method) {
+ super(method);
}
- void update(TemplateContext context, Object[] parameters) {
- System.arraycopy(parameters, 0, arguments, 0, parameters.length);
+ @Override
+ Class<?>[] getParameterTypes(TemplateContext context, Class<?>[] parameters) {
+ return parameters;
}
-
+
+ @Override
+ Object[] getParameterValues(TemplateContext context, Object[] parameters) {
+ return parameters;
+ }
+
}
class Signature1 extends Signature {
- Signature1(int size) {
- arguments = new Object[size + 1];
+ Signature1(Method method) {
+ super(method);
}
- void update(TemplateContext context, Object[] parameters) {
- arguments[0] = context;
- System.arraycopy(parameters, 0, arguments, 1, parameters.length);
+
+ @Override
+ Class<?>[] getParameterTypes(TemplateContext context, Class<?>[] parameters) {
+ Class<?>[] types = new Class[parameters.length + 1];
+ types[0] = TemplateContext.class;
+ System.arraycopy(parameters, 0, types, 1, parameters.length);
+ return types;
}
-
+
+ @Override
+ Object[] getParameterValues(TemplateContext context, Object[] parameters) {
+ Object[] values = new Object[parameters.length + 1];
+ values[0] = context;
+ System.arraycopy(parameters, 0, values, 1, parameters.length);
+ return values;
+ }
+
}
class Signature2 extends Signature {
- Signature2(int size) {
- arguments = new Object[size + 2];
+ Signature2(Method method) {
+ super(method);
}
- void update(TemplateContext context, Object[] parameters) {
- arguments[0] = context.getFacesContext();
- arguments[1] = context.getComponent();
- System.arraycopy(parameters, 0, arguments, 2, parameters.length);
- }
+
+ @Override
+ Class<?>[] getParameterTypes(TemplateContext context, Class<?>[] parameters) {
+ Class<?>[] types = new Class[parameters.length + 2];
+ types[0] = FacesContext.class;
+ types[1] = context.getComponent().getClass();
+ System.arraycopy(parameters, 0, types, 2, parameters.length);
+ return types;
+ }
+
+ @Override
+ Object[] getParameterValues(TemplateContext context, Object[] parameters) {
+ Object[] values = new Object[parameters.length + 2];
+ values[0] = context.getFacesContext();
+ values[1] = context.getComponent();
+ System.arraycopy(parameters, 0, values, 2, parameters.length);
+ return values;
+ }
}
15 years, 1 month
JBoss Rich Faces SVN: r15930 - in root/cdk/trunk/plugins/generator/src: main/java/org/richfaces/cdk/parser/el/node and 3 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: nbelaevski
Date: 2009-11-19 11:13:11 -0500 (Thu, 19 Nov 2009)
New Revision: 15930
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELNodeConstants.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryOperationTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ConstantValueTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/DefineObjectStatement.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/define-object.ftl
Removed:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractArithmeticTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractBooleanTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstAndTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredExpressionTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDivTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEqualTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFalseTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstGreaterThanEqualTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstGreaterThanTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLessThanEqualTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLessThanTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMinusTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstModTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMultTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotEqualTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNullTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstOrTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPlusTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstTrueTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ELNodeConstants.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELReflectionUtils.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/StringUtils.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstBracketSuffixTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstChoiceTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFloatingPointTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFunctionTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIdentifierTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLiteralTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMethodSuffixTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNegativeTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstStringTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstValueTreeNode.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java
Log:
https://jira.jboss.org/jira/browse/RF-7732
Copied: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELNodeConstants.java (from rev 15919, root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ELNodeConstants.java)
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELNodeConstants.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELNodeConstants.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -0,0 +1,74 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - 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.richfaces.cdk.parser.el;
+
+public final class ELNodeConstants {
+
+ //operators
+ public static final String AND_OPERATOR = " && ";
+ public static final String DIV_OPERATOR = " / ";
+ public static final String EQUALITY_OPERATOR = " == ";
+ public static final String GREATER_THEN_OPERATOR = " > ";
+ public static final String GREATER_THEN_OR_EQUALITY_OPERATOR = " >= ";
+ public static final String LESS_THEN_OPERATOR = " < ";
+ public static final String LESS_THEN_OR_EQUALITY_OPERATOR = " <= ";
+ public static final String INEQUALITY_OPERATOR = " != ";
+ public static final String MINUS_OPERATOR = " - ";
+ public static final String MOD_OPERATOR = " % ";
+ public static final String MULT_OPERATOR = " * ";
+ public static final String OR_OPERATOR = " || ";
+ public static final String PLUS_OPERATOR = " + ";
+ //
+
+ //constant values
+ public static final String FALSE_VALUE = "false";
+ public static final String NULL_VALUE = "null";
+ public static final String TRUE_VALUE = "true";
+ //
+
+ public static final String ARRAY_INDICATOR = "[L";
+ public static final String COLON = " : ";
+ public static final String COMMA = ",";
+ public static final String CONVERT_TO_STRING_FUNCTION = "convertToString";
+ public static final String DOT = ".";
+ public static final String DOUBLE_VALUE_OF_FUNCTION = "Double.valueOf";
+ public static final String EXCLAMATION_MARK = "!";
+ public static final String GET_ELEMENT_BY_INDEX_FUNCTION = "getElementByIndex";
+ public static final String GET_FUNCTION = "get";
+ public static final String GET_UTILS_FUNCTION = "getUtils";
+ public static final String JAVA_UTIL_LIST = "java.util.List";
+ public static final String JAVA_UTIL_MAP = "java.util.Map";
+ public static final String LEFT_BRACKET = "(";
+ public static final String LEFT_SQUARE_BRACKET = "[";
+ public static final String NEGATIVE = "-";
+ public static final String QUESTION_SIGN = " ? ";
+ public static final String QUOTE = "\"";
+ public static final String RIGHT_BRACKET = ")";
+ public static final String RIGHT_SQUARE_BRACKET = "]";
+ public static final String THIS_GET_UTILS_IS_EMPTY_FUNCTION = "this.getUtils().isEmpty";
+ public static final String THIS_PREFIX = "this";
+ public static final String UTILS_PREFIX = "utils";
+
+ private ELNodeConstants() {}
+}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELReflectionUtils.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELReflectionUtils.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELReflectionUtils.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -28,12 +28,10 @@
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
-
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
-
import java.util.HashMap;
import java.util.Map;
@@ -42,6 +40,7 @@
import org.jboss.el.parser.AstChoice;
import org.jboss.el.parser.AstDeferredExpression;
import org.jboss.el.parser.AstDiv;
+import org.jboss.el.parser.AstDynamicExpression;
import org.jboss.el.parser.AstEmpty;
import org.jboss.el.parser.AstEqual;
import org.jboss.el.parser.AstFalse;
@@ -69,39 +68,23 @@
import org.jboss.el.parser.AstTrue;
import org.jboss.el.parser.AstValue;
import org.jboss.el.parser.Node;
-
-import org.richfaces.cdk.parser.el.node.AstAndTreeNode;
import org.richfaces.cdk.parser.el.node.AstBracketSuffixTreeNode;
import org.richfaces.cdk.parser.el.node.AstChoiceTreeNode;
-import org.richfaces.cdk.parser.el.node.AstDeferredExpressionTreeNode;
-import org.richfaces.cdk.parser.el.node.AstDivTreeNode;
+import org.richfaces.cdk.parser.el.node.AstDeferredOrDynamicExpressionTreeNode;
import org.richfaces.cdk.parser.el.node.AstEmptyTreeNode;
-import org.richfaces.cdk.parser.el.node.AstEqualTreeNode;
-import org.richfaces.cdk.parser.el.node.AstFalseTreeNode;
import org.richfaces.cdk.parser.el.node.AstFloatingPointTreeNode;
import org.richfaces.cdk.parser.el.node.AstFunctionTreeNode;
-import org.richfaces.cdk.parser.el.node.AstGreaterThanEqualTreeNode;
-import org.richfaces.cdk.parser.el.node.AstGreaterThanTreeNode;
import org.richfaces.cdk.parser.el.node.AstIdentifierTreeNode;
import org.richfaces.cdk.parser.el.node.AstIntegerTreeNode;
-import org.richfaces.cdk.parser.el.node.AstLessThanEqualTreeNode;
-import org.richfaces.cdk.parser.el.node.AstLessThanTreeNode;
import org.richfaces.cdk.parser.el.node.AstLiteralTreeNode;
import org.richfaces.cdk.parser.el.node.AstMethodSuffixTreeNode;
-import org.richfaces.cdk.parser.el.node.AstMinusTreeNode;
-import org.richfaces.cdk.parser.el.node.AstModTreeNode;
-import org.richfaces.cdk.parser.el.node.AstMultTreeNode;
import org.richfaces.cdk.parser.el.node.AstNegativeTreeNode;
-import org.richfaces.cdk.parser.el.node.AstNotEqualTreeNode;
import org.richfaces.cdk.parser.el.node.AstNotTreeNode;
-import org.richfaces.cdk.parser.el.node.AstNullTreeNode;
-import org.richfaces.cdk.parser.el.node.AstOrTreeNode;
-import org.richfaces.cdk.parser.el.node.AstPlusTreeNode;
import org.richfaces.cdk.parser.el.node.AstPropertySuffixTreeNode;
import org.richfaces.cdk.parser.el.node.AstStringTreeNode;
-import org.richfaces.cdk.parser.el.node.AstTrueTreeNode;
import org.richfaces.cdk.parser.el.node.AstValueTreeNode;
-import org.richfaces.cdk.parser.el.node.ELNodeConstants;
+import org.richfaces.cdk.parser.el.node.BinaryOperationTreeNode;
+import org.richfaces.cdk.parser.el.node.ConstantValueTreeNode;
import org.richfaces.cdk.parser.el.node.ITreeNode;
/**
@@ -137,8 +120,8 @@
treeNode = new AstStringTreeNode(child);
} else if (child instanceof AstFunction) {
treeNode = new AstFunctionTreeNode(child);
- } else if (child instanceof AstDeferredExpression) {
- treeNode = new AstDeferredExpressionTreeNode(child);
+ } else if (child instanceof AstDeferredExpression || child instanceof AstDynamicExpression) {
+ treeNode = new AstDeferredOrDynamicExpressionTreeNode(child);
} else if (child instanceof AstNot) {
treeNode = new AstNotTreeNode(child);
} else if (child instanceof AstChoice) {
@@ -148,41 +131,41 @@
} else if (child instanceof AstLiteralExpression) {
treeNode = new AstLiteralTreeNode(child);
} else if (child instanceof AstFalse) {
- treeNode = new AstFalseTreeNode(child);
+ treeNode = ConstantValueTreeNode.FALSE_NODE;
} else if (child instanceof AstTrue) {
- treeNode = new AstTrueTreeNode(child);
+ treeNode = ConstantValueTreeNode.TRUE_NODE;
+ } else if (child instanceof AstNull) {
+ treeNode = ConstantValueTreeNode.NULL_NODE;
} else if (child instanceof AstAnd) {
- treeNode = new AstAndTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.AND_OPERATOR);
} else if (child instanceof AstEqual) {
- treeNode = new AstEqualTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.EQUALITY_OPERATOR);
} else if (child instanceof AstGreaterThan) {
- treeNode = new AstGreaterThanTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.GREATER_THEN_OPERATOR);
} else if (child instanceof AstGreaterThanEqual) {
- treeNode = new AstGreaterThanEqualTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.GREATER_THEN_OR_EQUALITY_OPERATOR);
} else if (child instanceof AstLessThan) {
- treeNode = new AstLessThanTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.LESS_THEN_OPERATOR);
} else if (child instanceof AstLessThanEqual) {
- treeNode = new AstLessThanEqualTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.LESS_THEN_OR_EQUALITY_OPERATOR);
} else if (child instanceof AstNotEqual) {
- treeNode = new AstNotEqualTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.INEQUALITY_OPERATOR);
} else if (child instanceof AstOr) {
- treeNode = new AstOrTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.OR_OPERATOR);
} else if (child instanceof AstDiv) {
- treeNode = new AstDivTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.DIV_OPERATOR);
} else if (child instanceof AstMult) {
- treeNode = new AstMultTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.MULT_OPERATOR);
} else if (child instanceof AstMod) {
- treeNode = new AstModTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.MOD_OPERATOR);
} else if (child instanceof AstPlus) {
- treeNode = new AstPlusTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.PLUS_OPERATOR);
} else if (child instanceof AstMinus) {
- treeNode = new AstMinusTreeNode(child);
+ treeNode = new BinaryOperationTreeNode(child, ELNodeConstants.MINUS_OPERATOR);
} else if (child instanceof AstBracketSuffix) {
treeNode = new AstBracketSuffixTreeNode(child);
} else if (child instanceof AstNegative) {
treeNode = new AstNegativeTreeNode(child);
- } else if (child instanceof AstNull) {
- treeNode = new AstNullTreeNode(child);
} else if (child instanceof AstFloatingPoint) {
treeNode = new AstFloatingPointTreeNode(child);
} else if (child instanceof AstMethodSuffix) {
@@ -192,9 +175,11 @@
} else if (child instanceof AstBracketSuffix) {
treeNode = new AstBracketSuffixTreeNode(child);
} else {
- throw new ParsingException("Node " + child.getImage() + " is not recognized;");
+ throw new ParsingException("Node " + child.getClass().getSimpleName() + "[" + child.getImage() + "] is not recognized;");
}
+ //TODO: add support for closures
+
return treeNode;
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/ELVisitor.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -23,14 +23,11 @@
package org.richfaces.cdk.parser.el;
-import java.util.ArrayList;
-import java.util.List;
import java.util.Map;
-import org.jboss.el.parser.AstLiteralExpression;
+import org.jboss.el.parser.AstCompositeExpression;
import org.jboss.el.parser.ELParser;
import org.jboss.el.parser.Node;
-
import org.richfaces.cdk.parser.el.node.ITreeNode;
/**
@@ -43,8 +40,7 @@
Class<?> collectionVariableType = null;
String lastIndexValue = "null";
Class<?> lastVariableType = null;
- List<Object> propertyResolved = new ArrayList<Object>();
- boolean needConversion;
+ boolean mixedExpression;
private ELVisitor() {}
@@ -58,12 +54,12 @@
return elVisitor;
}
- public boolean isNeedConversion() {
- return needConversion;
+ public boolean isMixedExpression() {
+ return mixedExpression;
}
- public void setNeedConversion(boolean needConversion) {
- this.needConversion = needConversion;
+ public void setMixedExpression(boolean needConversion) {
+ this.mixedExpression = needConversion;
}
public String getLastIndexValue() {
@@ -97,10 +93,16 @@
* @return generated Java code.
* @throws ParsingException - if error occurred during parsing.
*/
- public String parse(String expression, Map<String, Class<?>> contextMap) throws ParsingException {
+ public static String parse(String expression, Map<String, Class<?>> contextMap) throws ParsingException {
Node ret = ELParser.parse(expression);
+ ELVisitor elVisitor = ELVisitor.getInstance();
- return ELVisitor.getInstance().visit(ret, contextMap);
+ if (ret instanceof AstCompositeExpression && ret.jjtGetNumChildren() >= 2) {
+ //AstCompositeExpression with 2+ children is a mixed expression
+ elVisitor.setMixedExpression(true);
+ }
+
+ return elVisitor.visit(ret, contextMap);
}
private String visit(Node node, Map<String, Class<?>> context) throws ParsingException {
@@ -110,10 +112,6 @@
for (int i = 0; i < numChildren; i++) {
Node child = node.jjtGetChild(i);
- if (child instanceof AstLiteralExpression) {
- this.setNeedConversion(true);
- }
-
ITreeNode treeNode = ELReflectionUtils.determineNodeType(child);
treeNode.visit(sb, context, this);
@@ -139,32 +137,7 @@
lastIndexValue = "null";
lastVariableType = null;
collectionVariableType = null;
- needConversion = false;
- propertyResolved = new ArrayList<Object>();
+ mixedExpression = false;
}
- /**
- * This method called after parse process handle AstValue node, to include special logic in that case.
- */
- public void setValueHandled() {
- propertyResolved.add(new Object());
- }
-
- /**
- * This method called after AstValue node is completely parsed.
- * NOTE: AstValue can be nested.
- */
- public void unSetValueHandled() {
- if (propertyResolved.size() > 0) {
- propertyResolved.remove(propertyResolved.size() - 1);
- }
- }
-
- /**
- * This method determine if AstValue node now parsed, to include special logic.
- * @return true if AstValue node now parsed, otherwise -false.
- */
- public boolean isValueHandled() {
- return propertyResolved.size() > 0;
- }
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/StringUtils.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/StringUtils.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/StringUtils.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -23,41 +23,65 @@
package org.richfaces.cdk.parser.el;
+import java.util.Locale;
+
public final class StringUtils {
private StringUtils() {}
- public static String getEscapedString(final String text) {
- StringBuffer buf = new StringBuffer();
- int i = 0;
+ private static String toCharExpression(char c) {
+ String prependingZeroesString;
+ String hexString = Integer.toHexString(c);
+
+ switch (hexString.length()) {
+ case 1:
+ prependingZeroesString = "000";
+ break;
+ case 2:
+ prependingZeroesString = "00";
+ break;
+ case 3:
+ prependingZeroesString = "0";
+ break;
+ case 4:
+ prependingZeroesString = "";
+ break;
+ default:
+ throw new IllegalArgumentException();
+ }
+
+ return "\\u" + prependingZeroesString + hexString.toUpperCase(Locale.US);
+ }
+
+ public static String getEscapedString(String s) {
+ StringBuilder result = new StringBuilder();
- while (i < text.length()) {
- char c = text.charAt(i);
+ char[] chars = s.toCharArray();
- if (isalnum(c)) {
- buf.append(c);
- } else {
- switch (c) {
- case '"' :
- buf.append("\\\"");
-
- break;
-
- case '\n' :
- buf.append("\\n");
-
- break;
-
- default :
- buf.append(c);
-
- break;
+ for (char c : chars) {
+ if (c == '\n') {
+ result.append("\\n");
+ } else if (c == '\r') {
+ result.append("\\r");
+ } else if (c == '\t') {
+ result.append("\\t");
+ } else if (c == '\f') {
+ result.append("\\f");
+ } else if (c == '\b') {
+ result.append("\\b");
+ } else if (c == '\\') {
+ result.append("\\\\");
+ } else if (c == '"') {
+ result.append("\\\"");
+ } else {
+ if (c < 0x20 || c > 0x7F) {
+ result.append(toCharExpression(c));
+ } else {
+ result.append(c);
}
- }
-
- i++;
+ }
}
- return buf.toString();
+ return result.toString();
}
/**
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractArithmeticTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractArithmeticTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractArithmeticTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,70 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import java.util.Map;
-
-import org.jboss.el.parser.Node;
-
-import org.richfaces.cdk.parser.el.ELVisitor;
-import org.richfaces.cdk.parser.el.ParsingException;
-
-/**
- * This class extend AbstractTreeNode and wrap any Arithmetic node.
- * getOperator() method must be overridden in subclasses.
- *
- * @author amarkhel
- *
- */
-public abstract class AbstractArithmeticTreeNode extends AbstractTreeNode {
- public AbstractArithmeticTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
- StringBuilder sb1 = new StringBuilder();
- StringBuilder sb2 = new StringBuilder();
- ITreeNode node1 = getChild(0);
-
- node1.visit(sb1, context, visitor);
-
- ITreeNode node2 = getChild(1);
-
- node2.visit(sb2, context, visitor);
- sb.append(ELNodeConstants.LEFT_BRACKET);
- sb.append(sb1);
- sb.append(getOperator());
- sb.append(sb2);
- sb.append(ELNodeConstants.RIGHT_BRACKET);
- }
-
- /**
- * This abstract method return string representation of arithmetic operation.
- *
- * @return string representation of arithmetic operation of current node.
- *
- */
- public abstract String getOperator();
-}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractBooleanTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractBooleanTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractBooleanTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,70 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import java.util.Map;
-
-import org.jboss.el.parser.Node;
-
-import org.richfaces.cdk.parser.el.ELVisitor;
-import org.richfaces.cdk.parser.el.ParsingException;
-
-/**
- * This class extend AbstractTreeNode and wrap any Boolean node.
- * getDelimiter() method must be overridden in subclasses.
- *
- * @author amarkhel
- *
- */
-public abstract class AbstractBooleanTreeNode extends AbstractTreeNode {
- public AbstractBooleanTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
- StringBuilder sb1 = new StringBuilder();
- StringBuilder sb2 = new StringBuilder();
- ITreeNode node1 = getChild(0);
-
- node1.visit(sb1, context, visitor);
-
- ITreeNode node2 = getChild(1);
-
- node2.visit(sb2, context, visitor);
- sb.append(ELNodeConstants.LEFT_BRACKET);
- sb.append(sb1);
- sb.append(getDelimiter());
- sb.append(sb2);
- sb.append(ELNodeConstants.RIGHT_BRACKET);
- }
-
- /**
- * This abstract method return string representation of comparison operation.
- *
- * @return string representation of comparison operation of current node.
- *
- */
- public abstract String getDelimiter();
-}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AbstractTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -43,6 +43,25 @@
public AbstractTreeNode(Node node) {
this.node = node;
}
+
+ /**
+ * Collects output from visiting child of the current node with the specified index and returns
+ * collected string.
+ *
+ * @param childIndex
+ * @param context
+ * @param visitor
+ * @return
+ * @throws ParsingException
+ */
+ protected String getChildOutput(int childIndex, Map<String, Class<?>> context,
+ ELVisitor visitor) throws ParsingException {
+
+ StringBuilder sb = new StringBuilder();
+ getChild(childIndex).visit(sb, context, visitor);
+
+ return sb.toString();
+ }
/**
* Return node of current wrapper.
@@ -83,4 +102,5 @@
*/
public abstract void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor)
throws ParsingException;
+
}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstAndTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstAndTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstAndTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstAnd node.
- *
- * @author amarkhel
- *
- */
-public class AstAndTreeNode extends AbstractBooleanTreeNode {
- public AstAndTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getDelimiter() {
- return ELNodeConstants.AND_DELIMITER;
- }
-}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstBracketSuffixTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstBracketSuffixTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstBracketSuffixTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -27,6 +27,7 @@
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
@@ -43,39 +44,31 @@
@Override
public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
- ITreeNode node = getChild(0);
+ String suffixValue = getChildOutput(0, context, visitor);
- node.visit(sb, context, visitor);
+ if (visitor.getLastVariableType() != null) {
+ if (visitor.getLastVariableType().getName().startsWith(ELNodeConstants.ARRAY_INDICATOR)) {
+ sb.append(ELNodeConstants.LEFT_SQUARE_BRACKET);
+ sb.append(suffixValue);
+ sb.append(ELNodeConstants.RIGHT_SQUARE_BRACKET);
+ visitor.setLastVariableType(visitor.getCollectionVariableType());
+ }
- String bracketSuffix = sb.toString();
-
- if (visitor.isValueHandled()) {
- sb.setLength(0);
-
- if (visitor.getLastVariableType() != null) {
- if (visitor.getLastVariableType().getName().startsWith(ELNodeConstants.ARRAY_INDICATOR)) {
- sb.append(ELNodeConstants.LEFT_SQUARE_BRACKET);
- sb.append(bracketSuffix);
- sb.append(ELNodeConstants.RIGHT_SQUARE_BRACKET);
- visitor.setLastVariableType(visitor.getCollectionVariableType());
- }
-
- if ((visitor.getLastVariableType().getName().compareTo(ELNodeConstants.JAVA_UTIL_LIST) == 0)
- || (visitor.getLastVariableType().getName().compareTo(ELNodeConstants.JAVA_UTIL_MAP) == 0)) {
- sb.append(ELNodeConstants.GET_FUNCTION);
- sb.append(ELNodeConstants.LEFT_BRACKET);
- sb.append(bracketSuffix);
- sb.append(ELNodeConstants.RIGHT_BRACKET);
- visitor.setLastVariableType(visitor.getCollectionVariableType());
- }
- } else {
- sb.append(ELNodeConstants.GET_ELELMENT_BY_INDEX_FUNCTION);
- sb.append(ELNodeConstants.LEFT_BRACKET);
- sb.append(visitor.getLastIndexValue());
- sb.append(ELNodeConstants.COMMA);
- sb.append(bracketSuffix);
- sb.append(ELNodeConstants.RIGHT_BRACKET);
- }
+ if ((visitor.getLastVariableType().getName().compareTo(ELNodeConstants.JAVA_UTIL_LIST) == 0)
+ || (visitor.getLastVariableType().getName().compareTo(ELNodeConstants.JAVA_UTIL_MAP) == 0)) {
+ sb.append(ELNodeConstants.GET_FUNCTION);
+ sb.append(ELNodeConstants.LEFT_BRACKET);
+ sb.append(suffixValue);
+ sb.append(ELNodeConstants.RIGHT_BRACKET);
+ visitor.setLastVariableType(visitor.getCollectionVariableType());
+ }
+ } else {
+ sb.append(ELNodeConstants.GET_ELEMENT_BY_INDEX_FUNCTION);
+ sb.append(ELNodeConstants.LEFT_BRACKET);
+ sb.append(visitor.getLastIndexValue());
+ sb.append(ELNodeConstants.COMMA);
+ sb.append(suffixValue);
+ sb.append(ELNodeConstants.RIGHT_BRACKET);
}
}
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstChoiceTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstChoiceTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstChoiceTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -27,6 +27,7 @@
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
@@ -43,26 +44,19 @@
@Override
public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
- StringBuilder sb1 = new StringBuilder();
- StringBuilder sb2 = new StringBuilder();
- StringBuilder sb3 = new StringBuilder();
- ITreeNode node1 = getChild(0);
-
- node1.visit(sb1, context, visitor);
-
- ITreeNode node2 = getChild(1);
-
- node2.visit(sb2, context, visitor);
-
- ITreeNode node3 = getChild(2);
-
- node3.visit(sb3, context, visitor);
sb.append(ELNodeConstants.LEFT_BRACKET);
- sb.append(sb1);
+
+ //condition ? correctConditionBranch : incorrectConditionBranch
+ String condition = getChildOutput(0, context, visitor);
+ String correctConditionBranch = getChildOutput(1, context, visitor);
+ String incorrectConditionBranch = getChildOutput(2, context, visitor);
+
+ sb.append(condition);
sb.append(ELNodeConstants.QUESTION_SIGN);
- sb.append(sb2);
+ sb.append(correctConditionBranch);
sb.append(ELNodeConstants.COLON);
- sb.append(sb3);
+ sb.append(incorrectConditionBranch);
+
sb.append(ELNodeConstants.RIGHT_BRACKET);
}
}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredExpressionTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredExpressionTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredExpressionTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,63 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import java.util.Map;
-
-import org.jboss.el.parser.Node;
-
-import org.richfaces.cdk.parser.el.ELVisitor;
-import org.richfaces.cdk.parser.el.ParsingException;
-
-/**
- * This class extend AbstractTreeNode and wrap AstDeferredExpression node.
- *
- * @author amarkhel
- *
- */
-public class AstDeferredExpressionTreeNode extends AbstractTreeNode {
- public AstDeferredExpressionTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
- int numChildren = getNode().jjtGetNumChildren();
-
- for (int i = 0; i < numChildren; i++) {
- if (visitor.isNeedConversion()) {
- sb.append(ELNodeConstants.CONVERT_TO_STRING_FUNCTION);
- sb.append(ELNodeConstants.LEFT_BRACKET);
- }
-
- ITreeNode treeNode = getChild(i);
-
- treeNode.visit(sb, context, visitor);
-
- if (visitor.isNeedConversion()) {
- sb.append(ELNodeConstants.RIGHT_BRACKET);
- }
- }
- }
-}
Copied: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java (from rev 15919, root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredExpressionTreeNode.java)
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDeferredOrDynamicExpressionTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -0,0 +1,65 @@
+/**
+ * License Agreement.
+ *
+ * Rich Faces - 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.richfaces.cdk.parser.el.node;
+
+import java.util.Map;
+
+import org.jboss.el.parser.Node;
+
+import org.richfaces.cdk.parser.el.ELNodeConstants;
+import org.richfaces.cdk.parser.el.ELVisitor;
+import org.richfaces.cdk.parser.el.ParsingException;
+
+/**
+ * This class extend AbstractTreeNode and wrap AstDeferredExpression node.
+ *
+ * @author amarkhel
+ *
+ */
+public class AstDeferredOrDynamicExpressionTreeNode extends AbstractTreeNode {
+
+ public AstDeferredOrDynamicExpressionTreeNode(Node node) {
+ super(node);
+ }
+
+ @Override
+ public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
+ int numChildren = getNode().jjtGetNumChildren();
+
+ for (int i = 0; i < numChildren; i++) {
+ if (visitor.isMixedExpression()) {
+ sb.append(ELNodeConstants.CONVERT_TO_STRING_FUNCTION);
+ sb.append(ELNodeConstants.LEFT_BRACKET);
+ }
+
+ ITreeNode treeNode = getChild(i);
+
+ treeNode.visit(sb, context, visitor);
+
+ if (visitor.isMixedExpression()) {
+ sb.append(ELNodeConstants.RIGHT_BRACKET);
+ }
+ }
+ }
+}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDivTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDivTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstDivTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstDiv node.
- *
- * @author amarkhel
- *
- */
-public class AstDivTreeNode extends AbstractArithmeticTreeNode {
- public AstDivTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getOperator() {
- return ELNodeConstants.DIV_OPERATOR;
- }
-}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEmptyTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -27,6 +27,7 @@
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEqualTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEqualTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstEqualTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstEqual node.
- *
- * @author amarkhel
- *
- */
-public class AstEqualTreeNode extends AbstractBooleanTreeNode {
- public AstEqualTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getDelimiter() {
- return ELNodeConstants.EQUAL;
- }
-}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFalseTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFalseTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFalseTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,48 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import java.util.Map;
-
-import org.jboss.el.parser.Node;
-
-import org.richfaces.cdk.parser.el.ELVisitor;
-import org.richfaces.cdk.parser.el.ParsingException;
-
-/**
- * This class extend AbstractTreeNode and wrap AstFalse node.
- *
- * @author amarkhel
- *
- */
-public class AstFalseTreeNode extends AbstractTreeNode {
- public AstFalseTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
- sb.append(ELNodeConstants.FALSE);
- }
-}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFloatingPointTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFloatingPointTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFloatingPointTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -26,7 +26,7 @@
import java.util.Map;
import org.jboss.el.parser.Node;
-
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFunctionTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFunctionTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstFunctionTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -28,6 +28,7 @@
import org.jboss.el.parser.AstFunction;
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstGreaterThanEqualTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstGreaterThanEqualTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstGreaterThanEqualTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstGreaterThanEqual node.
- *
- * @author amarkhel
- *
- */
-public class AstGreaterThanEqualTreeNode extends AbstractBooleanTreeNode {
- public AstGreaterThanEqualTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getDelimiter() {
- return ELNodeConstants.GREAT_THEN_EQUAL;
- }
-}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstGreaterThanTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstGreaterThanTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstGreaterThanTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstGreaterThan node.
- *
- * @author amarkhel
- *
- */
-public class AstGreaterThanTreeNode extends AbstractBooleanTreeNode {
- public AstGreaterThanTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getDelimiter() {
- return ELNodeConstants.GREAT_THEN;
- }
-}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIdentifierTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIdentifierTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstIdentifierTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -27,6 +27,7 @@
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
@@ -37,38 +38,30 @@
*
*/
public class AstIdentifierTreeNode extends AbstractTreeNode {
- public AstIdentifierTreeNode(Node node) {
- super(node);
- }
+ public AstIdentifierTreeNode(Node node) {
+ super(node);
+ }
- @Override
- public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
- String variableName = getNode().getImage();
+ @Override
+ public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
+ String variableName = getNode().getImage();
- if (visitor.isValueHandled()) {
- if (context.containsKey(variableName)) {
- visitor.setLastVariableType(context.get(variableName));
- sb.append(variableName);
- } else {
- if (variableName.equals(ELNodeConstants.THIS_PREFIX)) {
- sb.append(variableName);
- } else if (variableName.equals(ELNodeConstants.UTILS_PREFIX)) {
- sb.append(ELNodeConstants.THIS_PREFIX);
- sb.append(ELNodeConstants.DOT);
- sb.append(ELNodeConstants.GET_UTILS_FUNCTION);
- sb.append(ELNodeConstants.LEFT_BRACKET);
- sb.append(ELNodeConstants.RIGHT_BRACKET);
- } else {
- throw new ParsingException("No instance found in context for identifier " + variableName);
- }
- }
- } else {
- sb.append(ELNodeConstants.VARIABLES_GET_VARIABLE_FUNCTION);
- sb.append(ELNodeConstants.LEFT_BRACKET);
- sb.append(ELNodeConstants.QUOTE);
- sb.append(variableName);
- sb.append(ELNodeConstants.QUOTE);
- sb.append(ELNodeConstants.RIGHT_BRACKET);
- }
- }
+ if (context.containsKey(variableName)) {
+ visitor.setLastVariableType(context.get(variableName));
+ sb.append(variableName);
+ } else {
+ //TODO - what's then?
+ if (variableName.equals(ELNodeConstants.THIS_PREFIX)) {
+ sb.append(variableName);
+ } else if (variableName.equals(ELNodeConstants.UTILS_PREFIX)) {
+ sb.append(ELNodeConstants.THIS_PREFIX);
+ sb.append(ELNodeConstants.DOT);
+ sb.append(ELNodeConstants.GET_UTILS_FUNCTION);
+ sb.append(ELNodeConstants.LEFT_BRACKET);
+ sb.append(ELNodeConstants.RIGHT_BRACKET);
+ } else {
+// throw new ParsingException("No instance found in context for identifier " + variableName);
+ }
+ }
+ }
}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLessThanEqualTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLessThanEqualTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLessThanEqualTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstLessThanEqual node.
- *
- * @author amarkhel
- *
- */
-public class AstLessThanEqualTreeNode extends AbstractBooleanTreeNode {
- public AstLessThanEqualTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getDelimiter() {
- return ELNodeConstants.LESS_THEN_EQUAL;
- }
-}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLessThanTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLessThanTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLessThanTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstLessThan node.
- *
- * @author amarkhel
- *
- */
-public class AstLessThanTreeNode extends AbstractBooleanTreeNode {
- public AstLessThanTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getDelimiter() {
- return ELNodeConstants.LESS_THEN;
- }
-}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLiteralTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLiteralTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstLiteralTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -27,6 +27,7 @@
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
import org.richfaces.cdk.parser.el.StringUtils;
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMethodSuffixTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMethodSuffixTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMethodSuffixTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -27,6 +27,7 @@
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMinusTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMinusTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMinusTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstMinus node.
- *
- * @author amarkhel
- *
- */
-public class AstMinusTreeNode extends AbstractArithmeticTreeNode {
- public AstMinusTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getOperator() {
- return ELNodeConstants.MINUS_SIGN;
- }
-}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstModTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstModTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstModTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstMod node.
- *
- * @author amarkhel
- *
- */
-public class AstModTreeNode extends AbstractArithmeticTreeNode {
- public AstModTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getOperator() {
- return ELNodeConstants.MOD_SIGN;
- }
-}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMultTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMultTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstMultTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstMult node.
- *
- * @author amarkhel
- *
- */
-public class AstMultTreeNode extends AbstractArithmeticTreeNode {
- public AstMultTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getOperator() {
- return ELNodeConstants.MULT_SIGN;
- }
-}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNegativeTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNegativeTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNegativeTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -27,6 +27,7 @@
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotEqualTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotEqualTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotEqualTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstNotEqual node.
- *
- * @author amarkhel
- *
- */
-public class AstNotEqualTreeNode extends AbstractBooleanTreeNode {
- public AstNotEqualTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getDelimiter() {
- return ELNodeConstants.NOT_EQUAL;
- }
-}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNotTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -27,6 +27,7 @@
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNullTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNullTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstNullTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,48 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import java.util.Map;
-
-import org.jboss.el.parser.Node;
-
-import org.richfaces.cdk.parser.el.ELVisitor;
-import org.richfaces.cdk.parser.el.ParsingException;
-
-/**
- * This class extend AbstractTreeNode and wrap AstNull node.
- *
- * @author amarkhel
- *
- */
-public class AstNullTreeNode extends AbstractTreeNode {
- public AstNullTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
- sb.append(ELNodeConstants.NULL);
- }
-}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstOrTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstOrTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstOrTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstOr node.
- *
- * @author amarkhel
- *
- */
-public class AstOrTreeNode extends AbstractBooleanTreeNode {
- public AstOrTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getDelimiter() {
- return ELNodeConstants.OR;
- }
-}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPlusTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPlusTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPlusTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,43 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import org.jboss.el.parser.Node;
-
-/**
- * This class extend AbstractTreeNode and wrap AstPlus node.
- *
- * @author amarkhel
- *
- */
-public class AstPlusTreeNode extends AbstractArithmeticTreeNode {
- public AstPlusTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public String getOperator() {
- return ELNodeConstants.PLUS_SIGN;
- }
-}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstPropertySuffixTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -27,6 +27,7 @@
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELReflectionUtils;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstStringTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstStringTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstStringTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -27,9 +27,10 @@
import org.jboss.el.parser.AstString;
import org.jboss.el.parser.Node;
-
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
+import org.richfaces.cdk.parser.el.StringUtils;
/**
* This class extend AbstractTreeNode and wrap AstString node.
@@ -45,7 +46,7 @@
@Override
public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
sb.append(ELNodeConstants.QUOTE);
- sb.append(((AstString) getNode()).getString());
+ sb.append(StringUtils.getEscapedString(((AstString) getNode()).getString()));
sb.append(ELNodeConstants.QUOTE);
}
}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstTrueTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstTrueTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstTrueTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,48 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-import java.util.Map;
-
-import org.jboss.el.parser.Node;
-
-import org.richfaces.cdk.parser.el.ELVisitor;
-import org.richfaces.cdk.parser.el.ParsingException;
-
-/**
- * This class extend AbstractTreeNode and wrap AstTrue node.
- *
- * @author amarkhel
- *
- */
-public class AstTrueTreeNode extends AbstractTreeNode {
- public AstTrueTreeNode(Node node) {
- super(node);
- }
-
- @Override
- public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
- sb.append(ELNodeConstants.TRUE);
- }
-}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstValueTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstValueTreeNode.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/AstValueTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -29,6 +29,7 @@
import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
@@ -47,8 +48,6 @@
public void visit(StringBuilder sb, Map<String, Class<?>> context, ELVisitor visitor) throws ParsingException {
List<String> tokens = new ArrayList<String>();
- visitor.setValueHandled();
-
for (int i = 0; i < getNode().jjtGetNumChildren(); i++) {
StringBuilder sb1 = new StringBuilder();
ITreeNode subChild = getChild(i);
@@ -73,7 +72,6 @@
sb.append(visitor.getLastIndexValue());
}
- visitor.unSetValueHandled();
visitor.reset();
}
}
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryOperationTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryOperationTreeNode.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/BinaryOperationTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -0,0 +1,69 @@
+/*
+ * 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.parser.el.node;
+
+import java.util.Map;
+
+import org.jboss.el.parser.Node;
+import org.richfaces.cdk.parser.el.ELNodeConstants;
+import org.richfaces.cdk.parser.el.ELVisitor;
+import org.richfaces.cdk.parser.el.ParsingException;
+
+/**
+ * <p>Abstract class for all binary (having two operands) operation expression nodes</p>
+ * <p>For operands <code>A</code> and <code>B</code> and operator <code>x</code> output is <code>(A x B)</code></p>
+ *
+ * @author Nick Belaevski
+ */
+public class BinaryOperationTreeNode extends AbstractTreeNode {
+
+ private final String operatorString;
+
+ public BinaryOperationTreeNode(Node node, String operatorString) {
+ super(node);
+
+ this.operatorString = operatorString;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.parser.el.node.AbstractTreeNode#visit(java.lang.StringBuilder, java.util.Map, org.richfaces.cdk.parser.el.ELVisitor)
+ */
+ @Override
+ public void visit(StringBuilder sb, Map<String, Class<?>> context,
+ ELVisitor visitor) throws ParsingException {
+
+ sb.append(ELNodeConstants.LEFT_BRACKET);
+
+ String firstChildOutput = getChildOutput(0, context, visitor);
+ String secondChildOutput = getChildOutput(1, context, visitor);
+
+ sb.append(firstChildOutput);
+ sb.append(operatorString);
+ sb.append(secondChildOutput);
+
+ sb.append(ELNodeConstants.RIGHT_BRACKET);
+
+ }
+
+
+
+}
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ConstantValueTreeNode.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ConstantValueTreeNode.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ConstantValueTreeNode.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -0,0 +1,59 @@
+/*
+ * 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.parser.el.node;
+
+import java.util.Map;
+
+import org.richfaces.cdk.parser.el.ELNodeConstants;
+import org.richfaces.cdk.parser.el.ELVisitor;
+import org.richfaces.cdk.parser.el.ParsingException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ConstantValueTreeNode extends AbstractTreeNode {
+
+ private final String value;
+
+ public static final ConstantValueTreeNode NULL_NODE = new ConstantValueTreeNode(ELNodeConstants.NULL_VALUE);
+
+ public static final ConstantValueTreeNode TRUE_NODE = new ConstantValueTreeNode(ELNodeConstants.TRUE_VALUE);
+
+ public static final ConstantValueTreeNode FALSE_NODE = new ConstantValueTreeNode(ELNodeConstants.FALSE_VALUE);
+
+ private ConstantValueTreeNode(String value) {
+ super(null);
+ this.value = value;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.parser.el.node.AbstractTreeNode#visit(java.lang.StringBuilder, java.util.Map, org.richfaces.cdk.parser.el.ELVisitor)
+ */
+ @Override
+ public void visit(StringBuilder sb, Map<String, Class<?>> context,
+ ELVisitor visitor) throws ParsingException {
+
+ sb.append(value);
+ }
+
+}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ELNodeConstants.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ELNodeConstants.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/parser/el/node/ELNodeConstants.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -1,68 +0,0 @@
-/**
- * License Agreement.
- *
- * Rich Faces - 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.richfaces.cdk.parser.el.node;
-
-public final class ELNodeConstants {
- public static final String AND_DELIMITER = " && ";
- public static final String ARRAY_INDICATOR = "[L";
- public static final String COLON = " : ";
- public static final String COMMA = ",";
- public static final String CONVERT_TO_STRING_FUNCTION = "convertToString";
- public static final String DIV_OPERATOR = " / ";
- public static final String DOT = ".";
- public static final String DOUBLE_VALUE_OF_FUNCTION = "Double.valueOf";
- public static final String EQUAL = " == ";
- public static final String EXCLAMATION_MARK = "!";
- public static final String FALSE = "false";
- public static final String GET_ELELMENT_BY_INDEX_FUNCTION = "getElelmentByIndex";
- public static final String GET_FUNCTION = "get";
- public static final String GET_UTILS_FUNCTION = "getUtils";
- public static final String GREAT_THEN = " > ";
- public static final String GREAT_THEN_EQUAL = " >= ";
- public static final String JAVA_UTIL_LIST = "java.util.List";
- public static final String JAVA_UTIL_MAP = "java.util.Map";
- public static final String LEFT_BRACKET = "(";
- public static final String LEFT_SQUARE_BRACKET = "[";
- public static final String LESS_THEN = " < ";
- public static final String LESS_THEN_EQUAL = " <= ";
- public static final String MINUS_SIGN = " - ";
- public static final String MOD_SIGN = " % ";
- public static final String MULT_SIGN = " * ";
- public static final String NEGATIVE = "-";
- public static final String NOT_EQUAL = " != ";
- public static final String NULL = "null";
- public static final String OR = " || ";
- public static final String PLUS_SIGN = " + ";
- public static final String QUESTION_SIGN = " ? ";
- public static final String QUOTE = "\"";
- public static final String RIGHT_BRACKET = ")";
- public static final String RIGHT_SQUARE_BRACKET = "]";
- public static final String THIS_GET_UTILS_IS_EMPTY_FUNCTION = "this.getUtils().isEmpty";
- public static final String THIS_PREFIX = "this";
- public static final String TRUE = "true";
- public static final String UTILS_PREFIX = "utils";
- public static final String VARIABLES_GET_VARIABLE_FUNCTION = "variables.getVariable";
-
- private ELNodeConstants() {}
-}
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/DefineObjectStatement.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/DefineObjectStatement.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/DefineObjectStatement.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -0,0 +1,65 @@
+/*
+ * 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 DefineObjectStatement extends AbstractTemplateMethodBodyStatement {
+
+ private String type;
+
+ private String name;
+
+ private String initializationExpression;
+
+ public DefineObjectStatement(String type, String name, String initializationExpression) {
+ super("define-object");
+
+ this.type = type;
+ this.name = name;
+ this.initializationExpression = initializationExpression != null ? initializationExpression : "";
+ }
+
+ /**
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the initializationExpression
+ */
+ public String getInitializationExpression() {
+ return initializationExpression;
+ }
+
+}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -55,7 +55,8 @@
@Override
public TemplateModel get(String key) throws TemplateModelException {
if("code".equals(key)){
- statement.getCode(modelWrapper.getConfiguration());
+ //TODO - ?
+ statement.getCode(modelWrapper.getConfiguration());
}
return super.get(key);
}
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 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -26,6 +26,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Locale;
@@ -36,7 +37,6 @@
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.builder.model.Argument;
@@ -47,6 +47,8 @@
import org.richfaces.builder.model.MethodBody;
import org.richfaces.builder.model.MethodBodyStatementsContainer;
import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.parser.el.ELVisitor;
+import org.richfaces.cdk.parser.el.ParsingException;
import org.richfaces.cdk.templatecompiler.model.AnyElement;
import org.richfaces.cdk.templatecompiler.model.CdkBodyElement;
import org.richfaces.cdk.templatecompiler.model.CdkCallElement;
@@ -97,6 +99,8 @@
protected MethodBodyStatementsContainer currentStatement;
private final LinkedList<MethodBodyStatementsContainer> statements = Lists.newLinkedList();
+ private Map<String, Class<?>> localsTypesMap;
+
static {
InputStream serializedAttributesStream = RendererClassVisitor.class.getResourceAsStream("/META-INF/schema/attributes.ser");
@@ -121,12 +125,20 @@
}
private String compileEl(String expression, Class<?> type) {
- if (Boolean.class.isAssignableFrom(type)) {
- //TODO just a stub!
- return "false /* " + expression.trim() + " */";
- }
-
- return quote(expression) + " /* " + expression.trim() + " */";
+ try {
+ return ELVisitor.parse(expression, localsTypesMap) + "/* " + expression.trim() + " */";
+ } catch (ParsingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ throw new RuntimeException(e.getMessage());
+ }
+//
+// if (Boolean.class.isAssignableFrom(type)) {
+// //TODO just a stub!
+// return "false /* " + expression.trim() + " */";
+// }
+//
+// return quote(expression) + " /* " + expression.trim() + " */";
}
private String getElExpressionContainerType(String value) {
@@ -211,6 +223,14 @@
return false;
}
+
+ private void createMethodContext() {
+ this.currentStatement = new MethodBody();
+ this.localsTypesMap = new HashMap<String, Class<?>>();
+ localsTypesMap.put(FACES_CONTEXT_VARIABLE, FacesContext.class);
+ localsTypesMap.put(RESPONSE_WRITER_VARIABLE, ResponseWriter.class);
+ localsTypesMap.put(COMPONENT_VARIABLE, UIComponent.class);
+ }
private void flushToEncodeMethod(String encodeMethodName) {
if (!this.currentStatement.isEmpty()) {
@@ -228,8 +248,8 @@
methodBody.addStatement(0, new EncodeMethodPrefaceStatement());
rendererClass.addMethod(javaMethod);
}
-
- this.currentStatement = new MethodBody();
+
+ createMethodContext();
}
private JavaClass createJavaClassByName(String fullName) {
@@ -330,9 +350,12 @@
* @see org.richfaces.cdk.templatecompiler.model.TemplateVisitor#visitElement(java.lang.String)
*/
@Override
- public void visitElement(String child) throws CdkException {
- if (child != null && child.length() != 0) {
- currentStatement.addStatement(new WriteTextStatement(compileEl(child, String.class)));
+ public void visitElement(String text) throws CdkException {
+ if (text != null) {
+ String trimmedText = text.trim();
+ if (trimmedText.length() != 0) {
+ currentStatement.addStatement(new WriteTextStatement(compileEl(trimmedText, String.class)));
+ }
}
}
@@ -434,10 +457,9 @@
}
value = compileEl(value, Object.class);
- currentStatement.addStatement(type + " " + name + " = " + value + ";");
- } else {
- currentStatement.addStatement(type + " " + name + ";");
}
+
+ currentStatement.addStatement(new DefineObjectStatement(type, name, value));
}
/* (non-Javadoc)
@@ -468,11 +490,10 @@
this.rendererClass.setSuperClass(createJavaClassByName(compositeInterface.getBaseClass()));
this.rendererClass.addImport(FacesContext.class);
- this.rendererClass.addImport(Renderer.class);
this.rendererClass.addImport(ResponseWriter.class);
this.rendererClass.addImport(UIComponent.class);
- this.currentStatement = new MethodBody();
+ this.createMethodContext();
}
/**
Added: root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/define-object.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/define-object.ftl (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/java/define-object.ftl 2009-11-19 16:13:11 UTC (rev 15930)
@@ -0,0 +1 @@
+${modelItem.type} ${modelItem.name} <#if modelItem.initializationExpression.length() != 0> = ${modelItem.initializationExpression}</#if>;
\ No newline at end of file
Modified: root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java 2009-11-19 07:48:37 UTC (rev 15929)
+++ root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/parser/el/test/ELParserTest.java 2009-11-19 16:13:11 UTC (rev 15930)
@@ -30,12 +30,12 @@
import java.util.Map;
import org.junit.Test;
-
import org.richfaces.cdk.parser.el.ELVisitor;
import org.richfaces.cdk.parser.el.ParsingException;
public class ELParserTest {
- @Test
+
+ @Test
public void testNull() throws Exception {
assertEquals(resolveExpression("#{null}"), "null");
}
@@ -53,6 +53,7 @@
@Test
public void testFloat() throws Exception {
assertEquals(resolveExpression("#{5.0}"), "Double.valueOf(5.0)");
+ assertEquals(resolveExpression("#{5.012e+34}"), "Double.valueOf(5.012e+34)");
}
@Test
@@ -156,14 +157,17 @@
@Test
public void testString() throws Exception {
+ assertEquals(resolveExpression("#{\"nabc\"}"), "\"nabc\"");
assertEquals(resolveExpression("#{'nabc'}"), "\"nabc\"");
- assertEquals(resolveExpression("#{'\tabc'}"), "\"\tabc\"");
+ assertEquals(resolveExpression("#{'\tabc'}"), "\"\\tabc\"");
assertEquals(resolveExpression("#{'/nabc'}"), "\"/nabc\"");
+ assertEquals(resolveExpression("#{'na\"bc'}"), "\"na\\\"bc\"");
+ assertEquals(resolveExpression("#{'na\\\\bc'}"), "\"na\\\\bc\"");
}
@Test
public void testIdentifier() throws Exception {
- assertEquals(resolveExpression("#{clientId}"), "variables.getVariable(\"clientId\")");
+ assertEquals(resolveExpression("#{clientId}"), "clientId");
}
@Test
@@ -246,7 +250,7 @@
@Test
public void testLiteralWithDeferred2() throws Exception {
- assertEquals(resolveExpression("#{getType()} abs "), "this.getType() + \" abs \"");
+ assertEquals(resolveExpression("#{getType()} abs "), "convertToString(this.getType()) + \" abs \"");
}
@Test
@@ -265,7 +269,8 @@
resolveExpression("#{bean.property}");
fail("Parsing Exception is not thrown");
} catch (ParsingException pe) {
- assertEquals(pe.getMessage(), "No instance found in context for identifier bean");
+ //TODO - check message
+ //ignore exception
}
}
@@ -279,14 +284,15 @@
"property: property not found in class: class org.richfaces.cdk.parser.el.test.Bean");
}
}
-
+
private static String resolveExpression(String expression) throws ParsingException {
Map<String, Class<?>> contextMap = new HashMap<String, Class<?>>();
contextMap.put("action", org.richfaces.cdk.parser.el.test.Bean.class);
+ contextMap.put("clientId", String.class);
+
+ String code = ELVisitor.parse(expression, contextMap);
- String code = ELVisitor.getInstance().parse(expression, contextMap);
-
return code;
}
}
15 years, 1 month
JBoss Rich Faces SVN: r15929 - branches/sandbox/3.3.X_JSF2/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts.
by richfaces-svn-commits@lists.jboss.org
Author: Alex.Kolonitsky
Date: 2009-11-19 02:48:37 -0500 (Thu, 19 Nov 2009)
New Revision: 15929
Modified:
branches/sandbox/3.3.X_JSF2/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js
Log:
https://jira.jboss.org/jira/browse/RF-8074
Context menu destroyed not completely
Modified: branches/sandbox/3.3.X_JSF2/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js
===================================================================
--- branches/sandbox/3.3.X_JSF2/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js 2009-11-19 07:03:49 UTC (rev 15928)
+++ branches/sandbox/3.3.X_JSF2/ui/contextMenu/src/main/resources/org/richfaces/renderkit/html/scripts/context-menu.js 2009-11-19 07:48:37 UTC (rev 15929)
@@ -4,27 +4,40 @@
Richfaces.ContextMenu.prototype = {
initialize: function(id, delay, evaluator, options) {
- this.options = options || {};
- this.id = id;
- this.element = $(id);
- this.menuContent = null;
+ this.id = id;
+ this.element = $(id);
+ this.element.component = this;
+ this.menuContent = null;
+
+ this.options = options || {};
this.evaluator = evaluator;
- this.element.component = this;
this["rich:destructor"] = "destroy";
+
this.doShow = this.show;
this.doHide = this.hide;
this.delay = delay;
+
+ this.attachedToElementId = null;
+ this.attachedTo = [];
},
destroy: function() {
+ for (var elementId in this.attachedTo) {
+ var element = $(elementId);
+ if (element) {
+ var attached = this.attachedTo[elementId];
+ Event.stopObserving(element, attached['eventName'], attached['listener']);
+ }
+ }
+
this.enableDefaultContextMenu();
this.element.component = null;
this.element = null;
this.menuContent = null;
+ this.attachedTo = [];
},
- disableDefaultContextMenu: function (element, id, event, attachedToPerent)
- {
+ disableDefaultContextMenu: function (element, id, event, attachedToPerent) {
if (event=="oncontextmenu") {
this.attachedToElementId = id;
this.attachedToParent = attachedToPerent;
@@ -34,9 +47,8 @@
}
},
- enableDefaultContextMenu: function ()
- {
- if (this.eventName=="contextmenu" && this.attachedToElementId) {
+ enableDefaultContextMenu: function () {
+ if (this.eventName == "contextmenu" && this.attachedToElementIds.length) {
var element = $(this.attachedToElementId);
if (!element && this.attachedToParent) {
element = this.element;
@@ -72,18 +84,28 @@
// attach contextMenu to specified element
attachToElement : function(element, event, context) {
- if (element) {
- this.applyDecoration(element);
+ if (!element) {
+ return;
+ }
- //Strip 'on' here
- var evnName = event.substr(2);
- // http://jira.jboss.com/jira/browse/RF-3419
- if(evnName == 'contextmenu') {
- Richfaces.enableDefaultHandler('click');
- }
- var listener = this.show.bindAsEventListener(this, context);
- Event.observe(element, evnName, listener);
- }
+ this.applyDecoration(element);
+
+ var evnName = event.substr(2); //Strip 'on' here
+ // http://jira.jboss.com/jira/browse/RF-3419
+ if(evnName == 'contextmenu') {
+ Richfaces.enableDefaultHandler('click');
+ }
+
+ var listener = this.show.bindAsEventListener(this, context);
+ Event.observe(element, evnName, listener);
+ if (element.id) {
+ this.attachedTo[element.id] = {
+ 'eventName' : evnName,
+ 'listener' : listener
+ };
+ }
+
+
},
hide: function() {
@@ -140,13 +162,7 @@
},
applyDecoration : function(element) {
-
$(element).addClassName("rich-cm-attached");
-
- /*var f = this.options.applyDecorations;
- if (f) {
- f(element);
- }*/
}
};
@@ -159,7 +175,7 @@
Richfaces.enableDefaultHandler = function(event) {
if (event.startsWith('on')) {
- event = event.substr(2);
+ event = event.substr(2);
}
Event.stopObserving(document, event, Event.stop);
};
\ No newline at end of file
15 years, 1 month
JBoss Rich Faces SVN: r15928 - branches/sandbox/3.3.X_JSF2/samples.
by richfaces-svn-commits@lists.jboss.org
Author: lfryc(a)redhat.com
Date: 2009-11-19 02:03:49 -0500 (Thu, 19 Nov 2009)
New Revision: 15928
Modified:
branches/sandbox/3.3.X_JSF2/samples/pom.xml
Log:
change version to 3.3.3-jsf2
Modified: branches/sandbox/3.3.X_JSF2/samples/pom.xml
===================================================================
--- branches/sandbox/3.3.X_JSF2/samples/pom.xml 2009-11-19 01:34:17 UTC (rev 15927)
+++ branches/sandbox/3.3.X_JSF2/samples/pom.xml 2009-11-19 07:03:49 UTC (rev 15928)
@@ -3,12 +3,12 @@
<parent>
<artifactId>root</artifactId>
<groupId>org.richfaces</groupId>
- <version>3.3.3-SNAPSHOT</version>
+ <version>3.3.3-jsf2-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<groupId>org.richfaces</groupId>
<artifactId>samples</artifactId>
- <version>3.3.3-SNAPSHOT</version>
+ <version>3.3.3-jsf2-SNAPSHOT</version>
<packaging>pom</packaging>
<name>RichFaces Components Examples</name>
<url>http://labs.jboss.com/jbossrichfaces/samples</url>
@@ -484,4 +484,4 @@
<!--<module>themes</module>-->
<!--<module>violetRays</module>-->
</modules>
-</project>
\ No newline at end of file
+</project>
15 years, 1 month
JBoss Rich Faces SVN: r15927 - in root/cdk/trunk/plugins/generator/src/main/java/org/richfaces: cdk/apt and 2 other directories.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2009-11-18 20:34:17 -0500 (Wed, 18 Nov 2009)
New Revision: 15927
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
Removed:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RenderingContext.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementImpl.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementsContainer.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatementsContainer.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
Log:
https://jira.jboss.org/jira/browse/RF-7732
Revrite Renderer generator to avoid static context variables.
Create renderer template in the integration test.
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatement.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatement.java 2009-11-19 01:34:04 UTC (rev 15926)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatement.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -21,12 +21,14 @@
*/
package org.richfaces.builder.model;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
/**
* @author Nick Belaevski
*
*/
public interface MethodBodyStatement {
- public String getCode();
+ public String getCode(FreeMarkerRenderer renderer);
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementImpl.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementImpl.java 2009-11-19 01:34:04 UTC (rev 15926)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementImpl.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -21,6 +21,8 @@
*/
package org.richfaces.builder.model;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
/**
* @author Nick Belaevski
*
@@ -35,7 +37,7 @@
}
@Override
- public String getCode() {
+ public String getCode(FreeMarkerRenderer renderer) {
return code;
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementsContainer.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementsContainer.java 2009-11-19 01:34:04 UTC (rev 15926)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/model/MethodBodyStatementsContainer.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -26,7 +26,9 @@
import java.util.ArrayList;
import java.util.List;
+import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+
/**
* @author Nick Belaevski
* @since 4.0
@@ -63,10 +65,10 @@
* @see org.richfaces.builder.model.MethodBodyStatement#getCode()
*/
@Override
- public String getCode() {
+ public String getCode(FreeMarkerRenderer renderer) {
StringBuilder sb = new StringBuilder();
for (MethodBodyStatement statement: statements) {
- sb.append(statement.getCode());
+ sb.append(statement.getCode(renderer));
sb.append('\n');
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2009-11-19 01:34:04 UTC (rev 15926)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -181,7 +181,8 @@
setComponentDescription(componentElement, component);
processFacets(componentElement, component);
- // TODO - process Events attribute.
+ // process Events.
+ setEvents(componentElement, component);
// TODO - process renderers ( @Renderer and @RendererTemplate attribute.
// TODO - process @Test annotations.
// Process attributes.
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java 2009-11-19 01:34:04 UTC (rev 15926)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/CdkConfiguration.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -27,6 +27,8 @@
import org.richfaces.cdk.CdkContext;
+import freemarker.ext.beans.BeanModel;
+import freemarker.ext.beans.BeansWrapper;
import freemarker.template.Configuration;
import freemarker.template.TemplateHashModel;
import freemarker.template.TemplateModel;
@@ -52,18 +54,7 @@
setObjectWrapper(new LibraryModelWrapper());
// Add context variables
- this.setSharedVariable("context", new TemplateHashModel() {
- @Override
- public TemplateModel get(String key) throws TemplateModelException {
-
- // TODO - define context parameters that could be exposed to template.
- return null;
- }
- @Override
- public boolean isEmpty() throws TemplateModelException {
- return false;
- }
- });
+ this.setSharedVariable("context", new BeanModel(context,new BeansWrapper()));
}
/**
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java 2009-11-19 01:34:04 UTC (rev 15926)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatement.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -37,8 +37,8 @@
}
@Override
- public String getCode() {
- return RenderingContext.renderSnippet(templateName, this);
+ public String getCode(FreeMarkerRenderer renderer) {
+ return renderer.renderSnippet(templateName, this);
}
}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatementsContainer.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatementsContainer.java 2009-11-19 01:34:04 UTC (rev 15926)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/AbstractTemplateMethodBodyStatementsContainer.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -37,8 +37,8 @@
}
@Override
- public String getCode() {
- return RenderingContext.renderSnippet(templateName, this);
+ public String getCode(FreeMarkerRenderer renderer) {
+ return renderer.renderSnippet(templateName, this);
}
}
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -0,0 +1,15 @@
+package org.richfaces.cdk.templatecompiler;
+
+import java.io.IOException;
+import java.io.Writer;
+
+import freemarker.template.TemplateException;
+
+public interface FreeMarkerRenderer {
+
+ public void writeSnippet(String templateName, Object object, Writer writer)
+ throws IOException, TemplateException;
+
+ public String renderSnippet(String templateName, Object object);
+
+}
\ No newline at end of file
Property changes on: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -0,0 +1,115 @@
+/*
+ * $Id: JavaClassConfiguration.java 15790 2009-11-01 16:21:55Z Alex.Kolonitsky $
+ *
+ * License Agreement.
+ *
+ * Rich Faces - 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.richfaces.cdk.templatecompiler;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.richfaces.cdk.CdkContext;
+
+import freemarker.ext.beans.BeanModel;
+import freemarker.ext.beans.BeansWrapper;
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
+import freemarker.template.TemplateHashModel;
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class JavaClassConfiguration extends Configuration implements FreeMarkerRenderer {
+ private static final String TEMPLATES = "/META-INF/templates/java";
+ private final CdkContext context;
+
+ public JavaClassConfiguration(CdkContext context) {
+ super();
+ this.context = context;
+
+ // TODO set proper template loader.
+ setClassForTemplateLoading(context.getClass(), TEMPLATES);
+
+ // TODO create an object wrapper for library model.
+ setObjectWrapper(new JavaClassModelWrapper(this));
+
+ // Add context variables
+ this.setSharedVariable("context", new BeanModel(context,new BeansWrapper()));
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the context
+ */
+ public CdkContext getContext() {
+ return context;
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#writeSnippet(java.lang.String, java.lang.Object, java.io.Writer)
+ */
+ public void writeSnippet(String templateName, Object object, Writer writer) throws IOException, TemplateException {
+ Template t = getTemplate(templateName + ".ftl");
+ Map<String, Object> rootMap = new HashMap<String, Object>();
+ rootMap.put("modelItem", object);
+
+ rootMap.put("facesContextVariable", RendererClassVisitor.FACES_CONTEXT_VARIABLE);
+ rootMap.put("componentVariable", RendererClassVisitor.COMPONENT_VARIABLE);
+ rootMap.put("responseWriterVariable", RendererClassVisitor.RESPONSE_WRITER_VARIABLE);
+
+ t.process(rootMap, writer);
+ }
+
+ /* (non-Javadoc)
+ * @see org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#renderSnippet(java.lang.String, java.lang.Object)
+ */
+ public String renderSnippet(String templateName, Object object) {
+ StringWriter writer = new StringWriter();
+ try {
+ writeSnippet(templateName, object, writer);
+
+ return writer.toString();
+ } catch (IOException e) {
+ // TODO: handle exception
+ return e.getMessage();
+ } catch (TemplateException e) {
+ // TODO: handle exception
+ return e.getMessage();
+ } finally {
+ try {
+ writer.close();
+ } catch (IOException e) {
+ //do nothing
+ }
+ }
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -0,0 +1,43 @@
+package org.richfaces.cdk.templatecompiler;
+
+import org.richfaces.builder.model.MethodBodyStatement;
+import org.richfaces.cdk.freemarker.ComponentTemplateModel;
+import org.richfaces.cdk.freemarker.PropertyModel;
+import org.richfaces.cdk.model.Component;
+import org.richfaces.cdk.model.Property;
+
+import freemarker.ext.beans.BeansWrapper;
+import freemarker.template.ObjectWrapper;
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+
+public class JavaClassModelWrapper extends BeansWrapper implements ObjectWrapper {
+
+ private final JavaClassConfiguration configuration;
+
+ public JavaClassModelWrapper(JavaClassConfiguration configuration) {
+ this.configuration = configuration;
+ }
+ @Override
+ public TemplateModel wrap(Object obj) throws TemplateModelException {
+
+ // TODO wrap specified model classes.
+ TemplateModel templateModel;
+
+ if (obj instanceof MethodBodyStatement) {
+ templateModel = new MethodBodyTemplateModel((MethodBodyStatement) obj, this);
+ } else {
+ templateModel = super.wrap(obj);
+ }
+
+ return templateModel;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the configuration
+ */
+ public JavaClassConfiguration getConfiguration() {
+ return configuration;
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java (rev 0)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -0,0 +1,63 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - 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.richfaces.cdk.templatecompiler;
+
+import org.richfaces.builder.model.MethodBodyStatement;
+import org.richfaces.cdk.freemarker.LibraryModelWrapper;
+
+import freemarker.ext.beans.BeanModel;
+import freemarker.ext.beans.BeansWrapper;
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+
+/**
+ * <p class="changed_added_4_0"></p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class MethodBodyTemplateModel extends BeanModel implements TemplateModel {
+
+ private final MethodBodyStatement statement;
+ private final JavaClassModelWrapper modelWrapper;
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param statement
+ * @param javaClassModelWrapper
+ */
+ public MethodBodyTemplateModel(MethodBodyStatement statement, JavaClassModelWrapper javaClassModelWrapper) {
+ super(statement, javaClassModelWrapper);
+ this.statement = statement;
+ this.modelWrapper = javaClassModelWrapper;
+ }
+
+ @Override
+ public TemplateModel get(String key) throws TemplateModelException {
+ if("code".equals(key)){
+ statement.getCode(modelWrapper.getConfiguration());
+ }
+ return super.get(key);
+ }
+
+}
Property changes on: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/MethodBodyTemplateModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2009-11-19 01:34:04 UTC (rev 15926)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -32,7 +32,6 @@
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkWriter;
import org.richfaces.cdk.StandardOutputs;
-import org.richfaces.cdk.freemarker.CdkConfiguration;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.RenderKit;
import org.richfaces.cdk.model.Renderer;
@@ -91,15 +90,13 @@
try {
outputWriter = new PrintWriter(outFile);
- CdkConfiguration cdkConfiguration = new CdkConfiguration(context);
- RenderingContext.setCdkConfiguration(cdkConfiguration);
- RenderingContext.writeSnippet("class", javaClass, outputWriter);
+ JavaClassConfiguration cdkConfiguration = new JavaClassConfiguration(context);
+ cdkConfiguration.writeSnippet("class", javaClass, outputWriter);
} catch (IOException e) {
throw new CdkException(e);
} catch (TemplateException e) {
throw new CdkException(e);
} finally {
- RenderingContext.setCdkConfiguration(null);
if (outputWriter != null) {
outputWriter.close();
}
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 2009-11-19 01:34:04 UTC (rev 15926)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -103,7 +103,7 @@
try {
// TODO read default attributes values
- // TODO detect URI attributes
+ // TODO detect URI and boolean attributes
ObjectInputStream ois = new ObjectInputStream(serializedAttributesStream);
@SuppressWarnings("unchecked")
@@ -314,7 +314,6 @@
}
}
- // TODO Auto-generated method stub
}
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RenderingContext.java
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RenderingContext.java 2009-11-19 01:34:04 UTC (rev 15926)
+++ root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RenderingContext.java 2009-11-19 01:34:17 UTC (rev 15927)
@@ -1,80 +0,0 @@
-/*
- * 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;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.util.HashMap;
-import java.util.Map;
-
-import org.richfaces.cdk.freemarker.CdkConfiguration;
-
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
-
-/**
- * @author Nick Belaevski
- * @since 4.0
- */
-class RenderingContext {
-
- private static ThreadLocal<CdkConfiguration> cdkConfigurationHolder = new ThreadLocal<CdkConfiguration>();
-
- static void setCdkConfiguration(CdkConfiguration cdkConfiguration) {
- cdkConfigurationHolder.set(cdkConfiguration);
- }
-
- static void writeSnippet(String templateName, Object object, Writer writer) throws IOException, TemplateException {
- Template t = cdkConfigurationHolder.get().getTemplate("java/" + templateName + ".ftl");
- Map<String, Object> rootMap = new HashMap<String, Object>();
- rootMap.put("modelItem", object);
-
- rootMap.put("facesContextVariable", RendererClassVisitor.FACES_CONTEXT_VARIABLE);
- rootMap.put("componentVariable", RendererClassVisitor.COMPONENT_VARIABLE);
- rootMap.put("responseWriterVariable", RendererClassVisitor.RESPONSE_WRITER_VARIABLE);
-
- t.process(rootMap, writer);
- }
-
- static String renderSnippet(String templateName, Object object) {
- StringWriter writer = new StringWriter();
- try {
- writeSnippet(templateName, object, writer);
-
- return writer.toString();
- } catch (IOException e) {
- // TODO: handle exception
- return e.getMessage();
- } catch (TemplateException e) {
- // TODO: handle exception
- return e.getMessage();
- } finally {
- try {
- writer.close();
- } catch (IOException e) {
- //do nothing
- }
- }
- }
-
-}
15 years, 1 month
JBoss Rich Faces SVN: r15926 - in root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main: templates and 1 other directory.
by richfaces-svn-commits@lists.jboss.org
Author: alexsmirnov
Date: 2009-11-18 20:34:04 -0500 (Wed, 18 Nov 2009)
New Revision: 15926
Added:
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/templates/
root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml
Log:
https://jira.jboss.org/jira/browse/RF-7732
Revrite Renderer generator to avoid static context variables.
Create renderer template in the integration test.
Added: root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml
===================================================================
--- root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml (rev 0)
+++ root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml 2009-11-19 01:34:04 UTC (rev 15926)
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<cdk:root xmlns="http://www.w3.org/1999/xhtml" xmlns:cdk="http://richfaces.org/cdk"
+ xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:cc="http://java.sun.com/jsf/composite">
+ <cc:interface>
+ <cdk:class>org.richfaces.cdk.test.renderkit.rf4_xhtml.TestRenderer</cdk:class>
+ <cdk:superclass>javax.faces.render.Renderer</cdk:superclass>
+ <cdk:component-family>org.richfaces.cdk.test.Test</cdk:component-family>
+ <cdk:component-type>org.richfaces.cdk.test.TestComponent</cdk:component-type>
+ <cdk:renderer-type>org.richfaces.TestRenderer</cdk:renderer-type>
+ <cdk:renderkit-id>RF4_XHTML</cdk:renderkit-id>
+ <cdk:renders-children>false</cdk:renders-children>
+ <cc:attribute name="onclick" />
+ <cc:attribute name="mode" default="ajax" />
+ <cc:attribute name="action" method-signature="void action()" />
+ <cc:attribute name="changeListener"
+ method-signature="void changeListener(ValueChangeEvent)" targets="changes changes1" />
+ <cc:attribute name="disabled" type="boolean" />
+ <cc:attribute name="delay" type="java.lang.Integer" />
+ <cc:attribute name="id" required="true" />
+ <cc:attribute name="experts" shortDescription="For use by experts"
+ displayName="Expert attribute" expert="true" />
+ <cc:attribute name="preferred" shortDescription="It's a preferred attribute"
+ displayName="Preferred attribute" preferred="true" />
+ <cdk:resource-dependencies>
+ <cdk:resource-dependency name="jquery.js" />
+ <cdk:resource-dependency name="richfaces.css"
+ library="org.richfaces" />
+ <cdk:resource-dependency name="richfaces.js"
+ library="org.richfaces" target="body" />
+ </cdk:resource-dependencies>
+
+ </cc:interface>
+ <cc:implementation>
+ start
+ <c:if test="#{someTest}">if content</c:if>
+ <c:choose>
+ <c:when test="#{anotherTest}">when content</c:when>
+ <c:when test="#{coolTest}">
+ <c:if test="#{nestedIfTest}">nested if content</c:if>
+ </c:when>
+ <c:otherwise>otherwise content</c:otherwise>
+ </c:choose>
+ <c:forEach items="#{someCollection}" var="iterationVar">
+ "forEach content
+ </c:forEach>
+ finish
+ </cc:implementation>
+</cdk:root>
\ No newline at end of file
Property changes on: root/cdk/trunk/plugins/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 1 month
JBoss Rich Faces SVN: r15925 - root/examples-sandbox/trunk/components/tables/src/main/webapp.
by richfaces-svn-commits@lists.jboss.org
Author: konstantin.mishin
Date: 2009-11-18 14:08:28 -0500 (Wed, 18 Nov 2009)
New Revision: 15925
Modified:
root/examples-sandbox/trunk/components/tables/src/main/webapp/extendedtable.xhtml
Log:
RF-7852 ExtendedDataTable sample
Modified: root/examples-sandbox/trunk/components/tables/src/main/webapp/extendedtable.xhtml
===================================================================
--- root/examples-sandbox/trunk/components/tables/src/main/webapp/extendedtable.xhtml 2009-11-18 19:08:09 UTC (rev 15924)
+++ root/examples-sandbox/trunk/components/tables/src/main/webapp/extendedtable.xhtml 2009-11-18 19:08:28 UTC (rev 15925)
@@ -32,11 +32,17 @@
<h:head>
<title>Richfaces ExtendedDataTable</title>
- </h:head>
+ <style>
+ @charset "utf-8";
+ .extendedDataTable{
+ width:500px;
+ }
+ </style>
+ </h:head>
<h:body>
<h:form id="form1">
- <rich:extendedDataTable var="record" value="#{dataBean.employeeList}" style="width: 500px;">
+ <rich:extendedDataTable var="record" value="#{dataBean.employeeList}" styleClass="extendedDataTable">
<rich:column id="column_name">
<f:facet name="header">
<h:outputText id="columnHeader1" value="Column Header Facet"/>
15 years, 1 month