[richfaces-svn-commits] JBoss Rich Faces SVN: r15933 - in root/cdk/trunk/plugins/generator/src: main/java/org/richfaces/cdk/parser/el/node and 7 other directories.

richfaces-svn-commits at lists.jboss.org richfaces-svn-commits at lists.jboss.org
Thu Nov 19 21:18:06 EST 2009


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;
     }



More information about the richfaces-svn-commits mailing list