Author: nbelaevski
Date: 2010-10-27 11:58:31 -0400 (Wed, 27 Oct 2010)
New Revision: 19699
Added:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImportImpl.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptObjectElement.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptOptionElement.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashStatement.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/PassThrough.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptObjectStatement.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java
Removed:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstNotTreeNode.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/util/JavaUtils.java
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/util/Strings.java
branches/RF-7817/cdk/parent/pom.xml
Log:
Merged revisions
19156-19157,19159-19160,19176,19186-19187,19190,19194,19196,19199,19203-19204,19231-19234,19248-19249,19255-19256,19258-19262,19276,19279-19281,19283,19285,19291-19299,19307,19312,19315,19318-19319,19325,19341-19342,19345-19351,19353-19355,19358-19359,19364,19367-19369,19371,19374-19377,19379-19385,19387,19393-19394,19400,19402-19404,19418-19422,19426,19430-19431,19434-19441,19443-19444,19446,19468,19470,19477,19491,19498-19499,19501,19504,19506-19507,19517-19519,19525,19542-19543,19548,19550,19555,19557,19560-19561,19565-19566,19571-19573,19582-19585,19592-19593,19599,19601-19602,19613,19646,19657-19659,19665,19671-19674
via svnmerge from
https://svn.jboss.org/repos/richfaces/trunk
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -373,9 +373,7 @@
for (PropertyBase parentAttribute : parentComponent.getAttributes())
{
PropertyBase attribute =
component.getOrCreateAttribute(parentAttribute.getName());
attribute.merge(parentAttribute);
- // TODO Check generate status. Attribute should not be generated
if the parent component
- // represents
- // concrete class.
+ // already exists in parent component.
attribute.setGenerate(false);
}
} catch (NoSuchElementException e) {
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -19,7 +19,6 @@
@Override
public TemplateModel wrap(Object obj) throws TemplateModelException {
- // TODO wrap specified model classes.
TemplateModel templateModel;
if (obj instanceof JavaStatement) {
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.lang.reflect.Type;
+import java.text.MessageFormat;
import java.util.Collection;
import java.util.EnumSet;
import java.util.List;
@@ -58,13 +59,17 @@
import org.richfaces.cdk.templatecompiler.model.CdkIfElement;
import org.richfaces.cdk.templatecompiler.model.CdkObjectElement;
import org.richfaces.cdk.templatecompiler.model.CdkOtherwiseElement;
+import org.richfaces.cdk.templatecompiler.model.CdkScriptObjectElement;
+import org.richfaces.cdk.templatecompiler.model.CdkScriptOptionElement;
import org.richfaces.cdk.templatecompiler.model.CdkSwitchElement;
import org.richfaces.cdk.templatecompiler.model.CdkWhenElement;
+import org.richfaces.cdk.templatecompiler.model.ClassImport;
import org.richfaces.cdk.templatecompiler.model.CompositeImplementation;
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
import org.richfaces.cdk.templatecompiler.model.ResourceDependency;
import org.richfaces.cdk.templatecompiler.model.Template;
import org.richfaces.cdk.templatecompiler.model.TemplateVisitor;
+import org.richfaces.cdk.templatecompiler.statements.AddAttributesToScriptHashStatement;
import org.richfaces.cdk.templatecompiler.statements.AttributesStatement;
import org.richfaces.cdk.templatecompiler.statements.CaseStatement;
import org.richfaces.cdk.templatecompiler.statements.ConstantReturnMethodBodyStatement;
@@ -76,6 +81,8 @@
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.IfElseStatement;
import org.richfaces.cdk.templatecompiler.statements.IfStatement;
+import org.richfaces.cdk.templatecompiler.statements.ScriptObjectStatement;
+import org.richfaces.cdk.templatecompiler.statements.ScriptOptionStatement;
import org.richfaces.cdk.templatecompiler.statements.StartElementStatement;
import org.richfaces.cdk.templatecompiler.statements.StatementsContainer;
import org.richfaces.cdk.templatecompiler.statements.SwitchStatement;
@@ -85,6 +92,7 @@
import org.richfaces.cdk.util.Strings;
import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Lists;
import com.google.inject.Injector;
/**
@@ -131,11 +139,6 @@
*/
static final String CLIENT_ID_VARIABLE = "clientId";
- /**
- *
- */
- private static final String PASS_THROUGH_ATTRIBUTES_FIELD_NAME =
"PASS_THROUGH_ATTRIBUTES";
-
private final Logger log;
private final Injector injector;
@@ -148,8 +151,6 @@
private JavaClass generatedClass;
private Set<HelperMethod> addedHelperMethods =
EnumSet.noneOf(HelperMethod.class);
- private int passThroughCounter;
-
public RendererClassVisitor(CompositeInterface compositeInterface,
Collection<PropertyBase> attributes, Logger log,
Injector injector, TypesFactory typesFactory, HelperMethodFactory helperFactory)
{
this.compositeInterface = compositeInterface;
@@ -170,6 +171,18 @@
this.generatedClass.addImport(ResponseWriter.class);
this.generatedClass.addImport(UIComponent.class);
+ for (ClassImport classImport: compositeInterface.getClassImports()) {
+ List<String> importedNames = classImport.getNames();
+ if (importedNames == null || importedNames.isEmpty()) {
+ importedNames = Lists.newArrayList("*");
+ }
+
+ for (String importedName : importedNames) {
+
this.generatedClass.addImport(Strings.DOT_JOINER.join(classImport.getPackage(),
importedName),
+ classImport.isStatic());
+ }
+ }
+
// TODO - make this JavaDoc - Generated annotation is present since JDK6
// this.generatedClass.addAnnotation(Generated.class, "\"RichFaces
CDK\"");
// TODO remove this after improving Java model
@@ -603,7 +616,6 @@
*/
public void preProcess(CompositeImplementation impl) {
initializeJavaClass();
- passThroughCounter = -1;
}
/**
@@ -614,4 +626,51 @@
createRendersChildrenMethod();
}
+ @Override
+ public void startElement(CdkScriptObjectElement cdkScriptObjectElement) {
+ ScriptObjectStatement scriptObjectStatement =
pushStatement(ScriptObjectStatement.class);
+ scriptObjectStatement.setObject(cdkScriptObjectElement.getName(),
cdkScriptObjectElement.getBase());
+ }
+
+ @Override
+ public void endElement(CdkScriptObjectElement cdkScriptObjectElement) {
+ popStatement();
+ }
+
+ private void addScriptHashAttributesPassthroughStatement(List<String>
attributeNames, String wrapper) {
+ if (attributeNames == null || attributeNames.isEmpty()) {
+ return;
+ }
+
+ AddAttributesToScriptHashStatement statement =
addStatement(AddAttributesToScriptHashStatement.class);
+ statement.setWrapper(wrapper);
+ statement.setAttributes(attributeNames, attributes);
+ }
+
+ private void addScriptOptionStatement(String name, String value, String defaultValue,
String wrapper) {
+ ScriptOptionStatement scriptOptionStatement =
addStatement(ScriptOptionStatement.class);
+ scriptOptionStatement.setName(name);
+ scriptOptionStatement.setValueExpression(value);
+ scriptOptionStatement.setDefaultValue(defaultValue);
+ scriptOptionStatement.setWrapper(wrapper);
+ }
+
+ @Override
+ public void visitElement(CdkScriptOptionElement cdkScriptOptionElement) {
+
addScriptHashAttributesPassthroughStatement(cdkScriptOptionElement.getAttributes(),
cdkScriptOptionElement.getWrapper());
+
+ for (String variableName : cdkScriptOptionElement.getVariables()) {
+ addScriptOptionStatement(variableName,
+ MessageFormat.format("#'{'{0}'}'",
variableName),
+ cdkScriptOptionElement.getDefaultValue(),
+ cdkScriptOptionElement.getWrapper());
+ }
+
+ if (!Strings.isEmpty(cdkScriptOptionElement.getName())) {
+ addScriptOptionStatement(cdkScriptOptionElement.getName(),
+ cdkScriptOptionElement.getValue(),
+ cdkScriptOptionElement.getDefaultValue(),
+ cdkScriptOptionElement.getWrapper());
+ }
+ }
}
Deleted:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/ClassImport.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -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.templatecompiler.builder.model;
-
-/**
- * @author Maksim Kaszynski
- */
-public class ClassImport implements JavaImport {
- private Class<?> clazz;
-
- public ClassImport(Class<?> clazz) {
- super();
- this.clazz = clazz;
- }
-
- public String getName() {
- return clazz.getName();
- }
-
- @Override
- public boolean isDefault() {
- if(clazz.isPrimitive()){
- return true;
- } else if("java.lang".equals(clazz.getPackage().getName())){
- return true;
- }
- return false;
- }
-}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -71,18 +71,20 @@
public void addImport(String name) {
- addImport(new RuntimeImport(name));
+ addImport(new JavaImportImpl(name));
}
- public void addImport(JavaImport javaImport) {
- imports.add(javaImport);
+ public void addImport(String name, boolean _static) {
+ addImport(new JavaImportImpl(name, _static));
}
public void addImport(Class<?> claz) {
- if (shouldAddToImports(claz.getName())) {
- imports.add(new ClassImport(claz));
- }
+ addImport(claz.getName());
}
+
+ public void addImport(JavaImport javaImport) {
+ imports.add(javaImport);
+ }
public void addImports(Iterable<JavaImport> imports) {
for (JavaImport elType : imports) {
@@ -141,20 +143,4 @@
return simpleName;
}
- private boolean shouldAddToImports(String className) {
- if (className == null || className.length() == 0) {
- return false;
- }
-
- // default package & primitive types
- if (className.indexOf('.') == -1) {
- return false;
- }
-
- if (className.matches("^java\\.lang\\.[^\\.]+$")) {
- return false;
- }
-
- return true;
- }
}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -27,12 +27,17 @@
* @author Maksim Kaszynski
*/
public interface JavaImport {
+
public Comparator<? super JavaImport> COMPARATOR = new
Comparator<JavaImport>() {
public int compare(JavaImport o1, JavaImport o2) {
return o1.getName().compareTo(o2.getName());
}
};
- String getName();
-
- boolean isDefault();
+
+ public String getName();
+
+ public boolean isStatic();
+
+ public boolean isDefault();
+
}
Copied:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImportImpl.java
(from rev 19674,
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImportImpl.java)
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImportImpl.java
(rev 0)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImportImpl.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -0,0 +1,111 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.builder.model;
+
+import java.util.regex.Pattern;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class JavaImportImpl implements JavaImport {
+
+ private static final Pattern JAVA_LANG_PATTERN =
Pattern.compile("^java\\.lang\\.[^\\.]+$");
+
+ private String name;
+
+ private boolean _static;
+
+ public JavaImportImpl(String name) {
+ this(name, false);
+ }
+
+ public JavaImportImpl(Class<?> clazz) {
+ this(clazz.getName());
+ }
+
+ public JavaImportImpl(String name, boolean _static) {
+ super();
+ this.name = name;
+ this._static = _static;
+ }
+
+ public JavaImportImpl(Class<?> clazz, boolean _static) {
+ this(clazz.getName(), _static);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public boolean isStatic() {
+ return _static;
+ }
+
+ public boolean isDefault() {
+ String name = getName();
+
+ if (!name.contains(".")) {
+ return true;
+ }
+
+ if (JAVA_LANG_PATTERN.matcher(name).matches()) {
+ return true;
+ }
+
+ return false;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + (isStatic() ? 1231 : 1237);
+ result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ JavaImport other = (JavaImport) obj;
+ if (isStatic() != other.isStatic()) {
+ return false;
+ }
+ if (getName() == null) {
+ if (other.getName() != null) {
+ return false;
+ }
+ } else if (!getName().equals(other.getName())) {
+ return false;
+ }
+ return true;
+ }
+}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RequireImports.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -6,6 +6,7 @@
import com.google.common.base.Function;
public interface RequireImports {
+
public static final Function<RequireImports, Iterable<JavaImport>>
IMPORTS_TRANSFORM = new Function<RequireImports, Iterable<JavaImport>>() {
@Override
Deleted:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/RuntimeImport.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -1,59 +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.templatecompiler.builder.model;
-
-import java.util.regex.Pattern;
-
-/**
- * Implementation of import taht cannot be resolved in design time
- *
- * @author Maksim Kaszynski
- */
-public class RuntimeImport implements JavaImport {
-
- private static final Pattern JAVA_LANG_PATTERN =
Pattern.compile("^java\\.lang\\.[^\\.]+$");
-
- private String name;
-
- public RuntimeImport(String name) {
- super();
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public boolean isDefault() {
- // default package & primitive types
- if (name.indexOf('.') == -1) {
- return true;
- }
-
- if (JAVA_LANG_PATTERN.matcher(name).matches()) {
- return true;
- }
-
- return false;
- }
-}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstFunctionTreeNode.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -22,12 +22,18 @@
package org.richfaces.cdk.templatecompiler.el.node;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.COMMA;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.LEFT_BRACKET;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.RIGHT_BRACKET;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.THIS_PREFIX;
+
import org.jboss.el.parser.AstFunction;
import org.jboss.el.parser.Node;
-import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
import org.richfaces.cdk.templatecompiler.el.ParsingException;
import org.richfaces.cdk.templatecompiler.el.types.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+import org.richfaces.cdk.templatecompiler.statements.HelperMethod;
import org.richfaces.cdk.util.Strings;
/**
@@ -45,23 +51,68 @@
@Override
public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
AstFunction functionNode = (AstFunction) getNode();
- String functionPrefix = functionNode.getPrefix();
- String functionName = functionNode.getLocalName();
-
- String identifierName;
- if (!Strings.isEmpty(functionPrefix)) {
- // TODO: this should be a property getter, not property name. NB:
'this' & 'super' keywords
- identifierName = functionPrefix;
+
+ HelperMethod helperMethod = findMatchingHelperMethod(functionNode);
+ if (helperMethod != null) {
+ visitHelperMethod(sb, visitor, helperMethod, functionNode);
} else {
- identifierName = ELNodeConstants.THIS_PREFIX;
+ visitObjectMethod(sb, visitor, functionNode);
}
+ }
+ /**
+ * @param sb
+ * @param visitor
+ * @param helperMethod
+ * @param functionNode
+ * @throws ParsingException
+ */
+ private void visitHelperMethod(StringBuilder sb, ELVisitor visitor, HelperMethod
helperMethod,
+ AstFunction functionNode) throws ParsingException {
+ visitor.addHelperMethods(helperMethod);
+
+ visitor.setLiteral(false);
+
+ //TODO - helper method doesn't provide this info
+ visitor.setExpressionType(TypesFactory.OBJECT_TYPE);
+
+ sb.append(helperMethod.getName());
+ sb.append(LEFT_BRACKET);
+
+ for (int i = 0; i < functionNode.jjtGetNumChildren(); i++) {
+ if (i != 0) {
+ sb.append(COMMA);
+ }
+
+ String childOutput = getChildOutput(i, visitor);
+ sb.append(childOutput);
+ }
+
+ sb.append(RIGHT_BRACKET);
+ }
+
+ private HelperMethod findMatchingHelperMethod(AstFunction functionNode) {
+ if (Strings.isEmpty(functionNode.getPrefix())) {
+ for (HelperMethod helperMethod: HelperMethod.values()) {
+ if (helperMethod.getName().equals(functionNode.getLocalName())) {
+ return helperMethod;
+ }
+ }
+ }
+
+ return null;
+ }
+
+ private void visitObjectMethod(StringBuilder sb, ELVisitor visitor, AstFunction
functionNode)
+ throws ParsingException {
+
+ String identifierName = Strings.firstNonEmpty(functionNode.getPrefix(),
THIS_PREFIX);
sb.append(identifierName);
ELType identifierType = visitor.getVariable(identifierName);
visitor.setExpressionType(identifierType);
- visitMethod(sb, visitor, functionName);
+ visitMethod(sb, visitor, functionNode.getLocalName());
visitor.setLiteral(false);
}
}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstNotTreeNode.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstNotTreeNode.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/node/AstNotTreeNode.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -19,11 +19,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-
-
package org.richfaces.cdk.templatecompiler.el.node;
-
import org.jboss.el.parser.Node;
import org.richfaces.cdk.templatecompiler.el.ELNodeConstants;
import org.richfaces.cdk.templatecompiler.el.ELVisitor;
@@ -33,7 +30,6 @@
* This class extend AbstractTreeNode and wrap AstNot node.
*
* @author amarkhel
- *
*/
public class AstNotTreeNode extends AbstractTreeNode {
public AstNotTreeNode(Node node) {
@@ -44,11 +40,11 @@
public void visit(StringBuilder sb, ELVisitor visitor) throws ParsingException {
sb.append(ELNodeConstants.LEFT_BRACKET);
sb.append(ELNodeConstants.EXCLAMATION_MARK);
- String childOutput = coerceToBoolean(getChildOutput(0, visitor), visitor);
+ String childOutput = coerceToBoolean(getChildOutput(0, visitor), visitor);
sb.append(childOutput);
sb.append(ELNodeConstants.RIGHT_BRACKET);
-
+
//variable type has been already set by getChildOuput()
}
-
+
}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/PlainClassType.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -25,8 +25,8 @@
import java.util.Collections;
import java.util.Set;
-import org.richfaces.cdk.templatecompiler.builder.model.ClassImport;
import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImportImpl;
/**
* @author Nick Belaevski
@@ -48,7 +48,7 @@
}
this.clazz = clazz;
- this.imports = Collections.<JavaImport>singleton(new ClassImport(clazz));
+ this.imports = Collections.<JavaImport>singleton(new
JavaImportImpl(clazz));
}
public Class<?> getPlainJavaClass(){
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/TypesFactoryImpl.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -79,7 +79,8 @@
static final ImmutableMap<Class<?>, Class<?>>
PRIMITIVE_TO_WRAPPER_CLASSES_MAP = ImmutableMap
.<Class<?>, Class<?>> builder().put(Boolean.TYPE,
Boolean.class).put(Float.TYPE, Float.class)
.put(Long.TYPE, Long.class).put(Integer.TYPE, Integer.class).put(Short.TYPE,
Short.class)
- .put(Byte.TYPE, Byte.class).put(Double.TYPE, Double.class).put(Character.TYPE,
Character.class).build();
+ .put(Byte.TYPE, Byte.class).put(Double.TYPE, Double.class).put(Character.TYPE,
Character.class)
+ .put(Void.TYPE, Void.class).build();
static final ImmutableMap<String, Class<?>> PRIMITIVE_CLASSES_MAP;
Copied:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptObjectElement.java
(from rev 19674,
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptObjectElement.java)
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptObjectElement.java
(rev 0)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptObjectElement.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -0,0 +1,69 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.model;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "scriptObject", namespace = Template.CDK_NAMESPACE)
+public class CdkScriptObjectElement extends ModelFragment {
+
+ @XmlAttribute(required = true)
+ @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
+ private String name;
+
+ @XmlAttribute
+ private String base;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getBase() {
+ return base;
+ }
+
+ public void setBase(String base) {
+ this.base = base;
+ }
+
+ @Override
+ public void beforeVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.startElement(this);
+ }
+
+ @Override
+ public void afterVisit(TemplateVisitor visitor) throws CdkException {
+ visitor.endElement(this);
+ }
+}
Copied:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptOptionElement.java
(from rev 19674,
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptOptionElement.java)
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptOptionElement.java
(rev 0)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CdkScriptOptionElement.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -0,0 +1,110 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.model;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+import org.richfaces.cdk.CdkException;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+@XmlRootElement(name = "scriptOption", namespace = Template.CDK_NAMESPACE)
+public class CdkScriptOptionElement implements ModelElement {
+
+ @XmlAttribute
+ private List<String> variables = new ArrayList<String>();
+
+ @XmlAttribute
+ private List<String> attributes = new ArrayList<String>();
+
+ @XmlAttribute
+ private String name;
+
+ @XmlAttribute
+ private String value;
+
+ @XmlAttribute
+ private String defaultValue;
+
+ @XmlAttribute
+ private String wrapper;
+
+ public List<String> getVariables() {
+ return variables;
+ }
+
+ public void setVariables(List<String> variables) {
+ this.variables = variables;
+ }
+
+ public List<String> getAttributes() {
+ return attributes;
+ }
+
+ public void setAttributes(List<String> attributes) {
+ this.attributes = attributes;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ public String getWrapper() {
+ return wrapper;
+ }
+
+ public void setWrapper(String wrapper) {
+ this.wrapper = wrapper;
+ }
+
+ @Override
+ public void visit(TemplateVisitor visitor) throws CdkException {
+ visitor.visitElement(this);
+ }
+
+}
Copied:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java
(from rev 19674,
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java)
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java
(rev 0)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ClassImport.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -0,0 +1,87 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.model;
+
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ClassImport {
+
+ @XmlAttribute(required = true)
+ @XmlJavaTypeAdapter(NormalizedStringAdapter.class)
+ private String _package;
+
+ @XmlAttribute
+ private boolean _static;
+
+ @XmlAttribute
+ private List<String> names;
+
+ /**
+ * @return the package_
+ */
+ public String getPackage() {
+ return _package;
+ }
+
+ /**
+ * @param _package the package_ to set
+ */
+ public void setPackage(String _package) {
+ this._package = _package;
+ }
+
+ /**
+ * @return the static_
+ */
+ public boolean isStatic() {
+ return _static;
+ }
+
+ /**
+ * @param static_ the static_ to set
+ */
+ public void setStatic(boolean _static) {
+ this._static = _static;
+ }
+
+ /**
+ * @return the classes
+ */
+ public List<String> getNames() {
+ return names;
+ }
+
+ /**
+ * @param classes the classes to set
+ */
+ public void setNames(List<String> classes) {
+ this.names = classes;
+ }
+
+}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/CompositeInterface.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -67,6 +67,8 @@
private Boolean rendersChildren = null;
+ private List<ClassImport> classImports = Lists.newArrayList();
+
/**
* <p class="changed_added_4_0"></p>
*
@@ -243,4 +245,18 @@
this.attributesImports = attributesImports;
}
+ /**
+ * @return the classImports
+ */
+ @XmlElement(name = "import", namespace = Template.CDK_NAMESPACE)
+ public List<ClassImport> getClassImports() {
+ return classImports;
+ }
+
+ /**
+ * @param classImports the classImports to set
+ */
+ public void setClassImports(List<ClassImport> classImports) {
+ this.classImports = classImports;
+ }
}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/ModelFragment.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -19,7 +19,8 @@
*/
@XmlSeeAlso( { CdkCallElement.class, CdkBodyElement.class, CdkIfElement.class,
CdkObjectElement.class,
CdkChooseElement.class, CdkWhenElement.class, CdkOtherwiseElement.class,
CdkForEachElement.class,
- CdkSwitchElement.class, CdkCaseElement.class, CdkDefaultElement.class })
+ CdkSwitchElement.class, CdkCaseElement.class, CdkDefaultElement.class,
+ CdkScriptObjectElement.class, CdkScriptOptionElement.class })
public class ModelFragment implements LeafModelElement {
private List<Object> children = Lists.newArrayList();
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/TemplateVisitor.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -82,4 +82,10 @@
void postProcess(CompositeImplementation compositeImplementation);
+ void startElement(CdkScriptObjectElement cdkScriptObjectElement);
+
+ void endElement(CdkScriptObjectElement cdkScriptObjectElement);
+
+ void visitElement(CdkScriptOptionElement cdkScriptOptionElement);
+
}
Copied:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashStatement.java
(from rev 19674,
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashStatement.java)
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashStatement.java
(rev 0)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AddAttributesToScriptHashStatement.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -0,0 +1,142 @@
+/*
+ * 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.statements;
+
+import java.util.Collection;
+import java.util.NoSuchElementException;
+import java.util.concurrent.atomic.AtomicInteger;
+
+import javax.xml.namespace.QName;
+
+import org.richfaces.cdk.attributes.Attribute.Kind;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.Named.NamePredicate;
+import org.richfaces.cdk.model.PropertyBase;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.inject.Inject;
+
+/**
+ * @author Nick Belaevski
+ */
+public class AddAttributesToScriptHashStatement extends FreeMarkerTemplateStatementBase
{
+
+ /**
+ *
+ */
+ private static final String ATTRIBUTES_FIELD_NAME =
"ATTRIBUTES_FOR_SCRIPT_HASH";
+
+ private static AtomicInteger fieldCounter = new AtomicInteger(0);
+
+ private String fieldName;
+
+ private String wrapper;
+
+ private Collection<PassThrough> attributes = Lists.newArrayList();
+
+ private Collection<PropertyBase> componentAttributes;
+
+ @Inject
+ public AddAttributesToScriptHashStatement(@TemplateModel FreeMarkerRenderer renderer)
{
+ super(renderer, "add-attributes-to-script-hash");
+ fieldName = ATTRIBUTES_FIELD_NAME + fieldCounter.getAndIncrement();
+ }
+
+ /**
+ * @return the fieldName
+ */
+ public String getFieldName() {
+ return fieldName;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param fieldName the fieldName to set
+ */
+ public void setFieldName(String fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the attributes
+ */
+ public Collection<PassThrough> getAttributes() {
+ return this.attributes;
+ }
+
+ /**
+ * @return the wrapper
+ */
+ public String getWrapper() {
+ return wrapper;
+ }
+
+ /**
+ * @param wrapper the wrapper to set
+ */
+ public void setWrapper(String wrapper) {
+ this.wrapper = wrapper;
+ }
+
+ /**
+ * @param attributeNames
+ * @param attributes
+ */
+ public void setAttributes(Collection<String> attributeNames,
Collection<PropertyBase> componentAttributes) {
+ this.componentAttributes = componentAttributes;
+
+ for (String attributeName : attributeNames) {
+ PassThrough passThrough = new PassThrough();
+ passThrough.name = QName.valueOf(attributeName);
+ passThrough.componentAttribute = attributeName;
+
+ try {
+ PropertyBase componentAttribute = findComponentAttribute(attributeName);
+ for (EventName event : componentAttribute.getEventNames()) {
+ passThrough.behaviors.add(event.getName());
+ }
+ passThrough.defaultValue = componentAttribute.getDefaultValue();
+ passThrough.type = componentAttribute.getType().getSimpleName();
+
+ } catch (NoSuchElementException e) {
+ passThrough.type = Object.class.getName();
+ }
+
+ if (Boolean.TYPE.equals(passThrough.type) ||
Boolean.class.equals(passThrough.type)) {
+ passThrough.kind = Kind.BOOLEAN;
+ } else {
+ passThrough.kind = Kind.GENERIC;
+ }
+
+ attributes.add(passThrough);
+ }
+ }
+ private PropertyBase findComponentAttribute(final String name)
+ throws NoSuchElementException {
+
+ return Iterables.find(componentAttributes, new NamePredicate(name));
+ }
+}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/AttributesStatement.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -15,13 +15,12 @@
import org.richfaces.cdk.attributes.Element;
import org.richfaces.cdk.attributes.Schema;
import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.Named.NamePredicate;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.templatecompiler.model.AnyElement;
import org.richfaces.cdk.templatecompiler.model.Template;
-import
org.richfaces.cdk.templatecompiler.statements.WriteAttributesSetStatement.PassThrough;
import org.richfaces.cdk.util.Strings;
-import com.google.common.base.Predicate;
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
@@ -66,7 +65,7 @@
public void processAttributes(AnyElement element, Collection<PropertyBase>
componentAttributes) {
this.componentAttributes = componentAttributes;
Set<String> processedAttributes = Sets.newHashSet();
- TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes =
Sets.newTreeSet();
+ TreeSet<PassThrough> passThroughAttributes = Sets.newTreeSet();
this.elementName = element.getName();
processRegularAttributes(element, processedAttributes, passThroughAttributes);
String passThrough = element.getPassThrough();
@@ -81,7 +80,7 @@
}
private void processPassThroughWithExclusions(Set<String> processedAttributes,
- TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes,
String passThroughWithExclusions) {
+ TreeSet<PassThrough> passThroughAttributes, String
passThroughWithExclusions) {
if (null != passThroughWithExclusions) {
// cdk:passThroughWithExclusions="id,class,style"
Map<String, Element> elements = attributesSchema.getElements();
@@ -101,7 +100,7 @@
}
private void processPassThrough(Set<String> processedAttributes,
- TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes,
String passThrough) {
+ TreeSet<PassThrough> passThroughAttributes, String passThrough) {
if (null != passThrough) {
// cdk:passThrough="class:styleClass,style , id:clientId"
Iterable<String> split = PASS_THGOUGH_SPLITTER.split(passThrough);
@@ -117,7 +116,7 @@
}
private void processRegularAttributes(AnyElement element, Set<String>
processedAttributes,
- TreeSet<WriteAttributesSetStatement.PassThrough> passThroughAttributes) {
+ TreeSet<PassThrough> passThroughAttributes) {
for (Map.Entry<QName, Object> entry : element.getAttributes().entrySet())
{
QName qName = entry.getKey();
if (Template.CDK_NAMESPACE.equals(qName.getNamespaceURI())) {
@@ -174,13 +173,7 @@
private PropertyBase findComponentAttribute(final String name)
throws NoSuchElementException {
- return Iterables.find(componentAttributes, new Predicate<PropertyBase>() {
- @Override
- public boolean apply(PropertyBase input) {
- return name.equals(input.getName());
- }
- });
-
+ return Iterables.find(componentAttributes, new NamePredicate(name));
}
private WriteAttributeStatement setupAttributeStatement(QName qName, Object value,
Attribute schemaAttribute) {
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/FreeMarkerTemplateStatementBase.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -28,8 +28,8 @@
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImportImpl;
import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
-import org.richfaces.cdk.templatecompiler.builder.model.RuntimeImport;
import org.richfaces.cdk.templatecompiler.el.types.ReferencedType;
import org.richfaces.cdk.util.Strings;
@@ -121,7 +121,7 @@
}
public void addImport(String name) {
- imports.add(new RuntimeImport(name));
+ imports.add(new JavaImportImpl(name));
}
protected void addImports(Iterable<JavaImport> requiredImports) {
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethod.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -21,11 +21,20 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.*;
+import static com.google.common.collect.Iterators.forArray;
+import static com.google.common.collect.Iterators.toArray;
+import static com.google.common.collect.Iterators.transform;
+import static
org.richfaces.cdk.templatecompiler.el.ELNodeConstants.CONVERT_TO_BOOLEAN_FUNCTION;
+import static
org.richfaces.cdk.templatecompiler.el.ELNodeConstants.CONVERT_TO_STRING_FUNCTION;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.IS_EMPTY_FUNCTION;
+import static org.richfaces.cdk.templatecompiler.el.ELNodeConstants.IS_EQUAL_FUNCTION;
+import static org.richfaces.cdk.util.JavaUtils.CLASS_TO_CLASS_NAME;
import java.util.Collection;
import java.util.EnumMap;
import java.util.EnumSet;
+import java.util.Iterator;
+import java.util.Map;
import java.util.Set;
import javax.faces.component.UIComponent;
@@ -46,7 +55,14 @@
SHOULD_RENDER_ATTRIBUTE("shouldRenderAttribute", Boolean.TYPE,
Object.class),
CREATE_ATTRIBUTES("attributes", "Attributes"),
RENDER_ATTRIBUTES_SET("renderPassThroughAttributes",
Void.TYPE,FacesContext.class,UIComponent.class,Collection.class),
-
RENDER_ATTRIBUTE("renderAttribute",Void.TYPE,FacesContext.class,String.class,Object.class);
+
RENDER_ATTRIBUTE("renderAttribute",Void.TYPE,FacesContext.class,String.class,Object.class),
+ ADD_TO_SCRIPT_HASH("addToScriptHash", Void.TYPE.getName(),
Map.class.getName(), String.class.getName(),
+ Object.class.getName(), Object.class.getName(),
"ScriptHashVariableWrapper"),
+ ADD_TO_SCRIPT_HASH_ATTRIBUTES("addToScriptHash", Void.TYPE.getName(),
Map.class.getName(),
+ FacesContext.class.getName(), UIComponent.class.getName(),
+ "Attributes", "ScriptHashVariableWrapper"),
+ TO_SCRIPT_ARGS("toScriptArgs", String.class, Object[].class),
+ CONCAT("concat", String.class, String[].class);
public static final EnumMap<HelperMethod, String> METHOD_NAMES =
Maps.newEnumMap(HelperMethod.class);
@@ -56,7 +72,7 @@
private final String returnType;
- private final Class<?>[] argumentTypes;
+ private final String[] argumentTypes;
static {
for (HelperMethod method : HelperMethod.values()) {
@@ -64,14 +80,19 @@
}
}
- private HelperMethod(String name, String returnType, Class<?>... argumentTypes)
{
+ private static String[] transformClassesToClassNames(Class<?>[] s) {
+ Iterator<String> transformed = transform(forArray(s),
CLASS_TO_CLASS_NAME);
+ return toArray(transformed, String.class);
+ }
+
+ private HelperMethod(String name, String returnType, String... argumentTypes) {
this.name = name;
this.returnType = returnType;
this.argumentTypes = argumentTypes;
}
private HelperMethod(String name, Class<?> returnType, Class<?>...
argumentTypes) {
- this(name,returnType.getName(),argumentTypes);
+ this(name, CLASS_TO_CLASS_NAME.apply(returnType),
transformClassesToClassNames(argumentTypes));
}
public String getName() {
@@ -82,7 +103,7 @@
return returnType;
}
- public Class<?>[] getArgumentTypes() {
+ public String[] getArgumentTypes() {
return argumentTypes;
}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -91,6 +91,10 @@
arguments.add(new
Argument("attributes",typesFactory.getType("Attributes")));
renderAttributes.getExceptions().add(typesFactory.getType(IOException.class));
buildHelperMethod(HelperMethod.CREATE_ATTRIBUTES, true,
"create-attributes");
+ buildHelperMethod(HelperMethod.ADD_TO_SCRIPT_HASH, true, null);
+ buildHelperMethod(HelperMethod.ADD_TO_SCRIPT_HASH_ATTRIBUTES, true, null);
+ buildHelperMethod(HelperMethod.TO_SCRIPT_ARGS, true, null);
+ buildHelperMethod(HelperMethod.CONCAT, true, null);
}
private JavaMethod buildHelperMethod(HelperMethod helperMethod, boolean utilsMethod,
String templateName,
@@ -99,7 +103,7 @@
if (utilsMethod &&
!RendererUtilsMethod.BUILT_IN.equals(rendererUtilsClass)) {
helperJavaMethod = new RendererUtilsMethod(helperMethod,
rendererUtilsClass);
} else {
- Class<?>[] argumentTypes = helperMethod.getArgumentTypes();
+ String[] argumentTypes = helperMethod.getArgumentTypes();
Argument[] arguments = new Argument[argumentNames.length];
for (int i = 0; i < argumentNames.length; i++) {
arguments[i] = new Argument(argumentNames[i],
typesFactory.getType(argumentTypes[i]));
Copied:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/PassThrough.java
(from rev 19674,
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/PassThrough.java)
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/PassThrough.java
(rev 0)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/PassThrough.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -0,0 +1,78 @@
+package org.richfaces.cdk.templatecompiler.statements;
+
+import java.util.Set;
+
+import javax.xml.namespace.QName;
+
+import org.richfaces.cdk.attributes.Attribute.Kind;
+
+import com.google.common.collect.Sets;
+
+/**
+ * <p class="changed_added_4_0">object contains information about
attribute</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public final class PassThrough implements Comparable<PassThrough> {
+ QName name;
+ Kind kind = Kind.GENERIC;
+ String componentAttribute;
+ String type;
+ Object defaultValue;
+ Set<String> behaviors = Sets.newHashSet();
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the name
+ */
+ public QName getName() {
+ return this.name;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the kind
+ */
+ public Kind getKind() {
+ return this.kind;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the componentAttribute
+ */
+ public String getComponentAttribute() {
+ return this.componentAttribute;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the type
+ */
+ public String getType() {
+ return this.type;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the defaultValue
+ */
+ public Object getDefaultValue() {
+ return this.defaultValue;
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the behaviors
+ */
+ public Set<String> getBehaviors() {
+ return this.behaviors;
+ }
+ public String getBuilderMethod() {
+ if(Kind.BOOLEAN.equals(kind)){
+ return "bool";
+ } else {
+ return kind.toString().toLowerCase();
+ }
+ }
+ @Override
+
+ public int compareTo(PassThrough o) {
+ return name.toString().compareTo(o.name.toString());
+ }
+}
\ No newline at end of file
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/RendererUtilsMethod.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -26,8 +26,8 @@
import java.util.TreeSet;
import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImportImpl;
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
-import org.richfaces.cdk.templatecompiler.builder.model.RuntimeImport;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
@@ -45,9 +45,10 @@
public RendererUtilsMethod(HelperMethod helper,String rendererUtilsClassName) {
super(helper.getName());
- this.runtimeImport.add(new RuntimeImport("static "
+rendererUtilsClassName+".*"));
- this.runtimeImport.add(new RuntimeImport(rendererUtilsClassName));
- this.runtimeImport.add(new
RuntimeImport(rendererUtilsClassName+".Attributes"));
+ this.runtimeImport.add(new JavaImportImpl(rendererUtilsClassName +
".*", true));
+ this.runtimeImport.add(new JavaImportImpl(rendererUtilsClassName));
+ this.runtimeImport.add(new
JavaImportImpl(rendererUtilsClassName+".Attributes"));
+ this.runtimeImport.add(new
JavaImportImpl(rendererUtilsClassName+".ScriptHashVariableWrapper"));
}
@Override
Copied:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptObjectStatement.java
(from rev 19674,
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptObjectStatement.java)
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptObjectStatement.java
(rev 0)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptObjectStatement.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -0,0 +1,131 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static
org.richfaces.cdk.templatecompiler.builder.model.RequireImports.IMPORTS_TRANSFORM;
+import static
org.richfaces.cdk.templatecompiler.statements.TemplateStatement.FIELDS_TRANSFORM;
+
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.ELType;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.common.base.Strings;
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+
+
+/**
+ * @author Nick Belaevski
+ *
+ */
+//TODO - configure initial map size
+public class ScriptObjectStatement extends FreeMarkerTemplateStatementBase {
+
+ private String name;
+
+ private ELParser parser;
+
+ private TypedTemplateStatement base;
+
+ private Logger logger;
+
+ private TypesFactory typesFactory;
+
+ private ELType mapType;
+
+ private ELType mapImplementationType;
+
+ @Inject
+ public ScriptObjectStatement(@TemplateModel FreeMarkerRenderer renderer, ELParser
parser, Logger logger,
+ TypesFactory typesFactory) {
+
+ super(renderer, "script-object");
+
+ this.parser = parser;
+ this.logger = logger;
+ this.typesFactory = typesFactory;
+ }
+
+ /**
+ * @return the keyExpression
+ */
+ public TemplateStatement getBaseExpression() {
+ return base;
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ public ELType getType() {
+ return mapType;
+ }
+
+ public ELType getImplementationType() {
+ return mapImplementationType;
+ }
+
+ public void setObject(String name, String baseExpression) {
+ this.mapType = typesFactory.getType("Map<String, Object>");
+ this.mapImplementationType = typesFactory.getType("LinkedHashMap<String,
Object>");
+ this.name = name;
+
+ if (!Strings.isNullOrEmpty(baseExpression)) {
+ try {
+ this.base = parser.parse(baseExpression, this, getType());
+ base.setParent(this);
+ } catch (ParsingException e) {
+ logger.error("Error parse scriptObject statement expression",
e);
+ }
+ }
+
+ setVariable(name, getType());
+ }
+
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ return Iterables.concat(super.getRequiredImports(),
mapImplementationType.getRequiredImports(),
+ mapType.getRequiredImports(),
+ IMPORTS_TRANSFORM.apply(base));
+ }
+
+ @Override
+ public Iterable<HelperMethod> getRequiredMethods() {
+ return Iterables.concat(super.getRequiredMethods(),
+ METHODS_TRANSFORM.apply(base));
+ }
+
+ @Override
+ public Iterable<JavaField> getRequiredFields() {
+ return Iterables.concat(super.getRequiredFields(),
+ FIELDS_TRANSFORM.apply(base));
+ }
+}
Copied:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java
(from rev 19674,
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java)
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java
(rev 0)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ScriptOptionStatement.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc. and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.richfaces.cdk.templatecompiler.statements;
+
+import static
org.richfaces.cdk.templatecompiler.builder.model.RequireImports.IMPORTS_TRANSFORM;
+import static
org.richfaces.cdk.templatecompiler.statements.TemplateStatement.FIELDS_TRANSFORM;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.TemplateModel;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
+import org.richfaces.cdk.templatecompiler.builder.model.JavaImport;
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.common.collect.Iterables;
+import com.google.inject.Inject;
+/**
+ * @author Nick Belaevski
+ *
+ */
+public class ScriptOptionStatement extends FreeMarkerTemplateStatementBase {
+
+ private String name;
+
+ private String defaultValue;
+
+ private TypedTemplateStatement value;
+
+ private String wrapper;
+
+ private ELParser parser;
+
+ private Logger logger;
+
+ @Inject
+ public ScriptOptionStatement(@TemplateModel FreeMarkerRenderer renderer, ELParser
parser, Logger logger) {
+ super(renderer, "script-option");
+
+ this.parser = parser;
+ this.logger = logger;
+ }
+
+ /**
+ * @param defaultValue the defaultValue to set
+ */
+ public void setDefaultValue(String defaultValue) {
+ this.defaultValue = defaultValue;
+ }
+
+ /**
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * @param value the value to set
+ */
+ public void setValueExpression(String valueExpression) {
+ try {
+ this.value = parser.parse(valueExpression, this, TypesFactory.OBJECT_TYPE);
+ } catch (ParsingException e) {
+ logger.error("Error parse scriptOption value expression: " +
valueExpression, e);
+ }
+ }
+
+ /**
+ * @param wrapper the wrapper to set
+ */
+ public void setWrapper(String wrapper) {
+ this.wrapper = wrapper;
+ }
+
+ @Override
+ public List<TemplateStatement> getStatements() {
+ return value != null ? Collections.<TemplateStatement>singletonList(value)
:
+ Collections.<TemplateStatement>emptyList();
+ }
+
+ /**
+ * @return the name
+ */
+ public String getName() {
+ return name;
+ }
+
+ /**
+ * @return the value
+ */
+ public TypedTemplateStatement getValue() {
+ return value;
+ }
+
+ /**
+ * @return the defaultValue
+ */
+ public String getDefaultValue() {
+ return defaultValue;
+ }
+
+ /**
+ * @return the wrapper
+ */
+ public String getWrapper() {
+ return wrapper;
+ }
+
+ @Override
+ public Iterable<JavaField> getRequiredFields() {
+ return Iterables.concat(super.getRequiredFields(),
FIELDS_TRANSFORM.apply(value));
+ }
+
+ @Override
+ public Iterable<JavaImport> getRequiredImports() {
+ return Iterables.concat(super.getRequiredImports(),
IMPORTS_TRANSFORM.apply(value));
+ }
+
+ @Override
+ public Iterable<HelperMethod> getRequiredMethods() {
+ return Iterables.concat(super.getRequiredMethods(),
METHODS_TRANSFORM.apply(value));
+ }
+}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatement.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -3,17 +3,40 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import java.util.Collections;
+
import org.richfaces.cdk.templatecompiler.builder.model.JavaField;
import org.richfaces.cdk.templatecompiler.builder.model.JavaStatement;
import org.richfaces.cdk.templatecompiler.builder.model.RequireImports;
+import com.google.common.base.Function;
+
/**
* @author asmirnov
*
*/
public interface TemplateStatement extends JavaStatement, RequireImports {
+ public static final Function<TemplateStatement, Iterable<JavaField>>
FIELDS_TRANSFORM = new Function<TemplateStatement, Iterable<JavaField>>() {
+ public Iterable<JavaField> apply(TemplateStatement from) {
+ if (from == null) {
+ return Collections.emptyList();
+ }
+
+ return from.getRequiredFields();
+ };
+ };
+ public static final Function<TemplateStatement, Iterable<HelperMethod>>
METHODS_TRANSFORM = new Function<TemplateStatement, Iterable<HelperMethod>>()
{
+ public Iterable<HelperMethod> apply(TemplateStatement from) {
+ if (from == null) {
+ return Collections.emptyList();
+ }
+
+ return from.getRequiredMethods();
+ };
+ };
+
Iterable<JavaField> getRequiredFields();
Iterable<HelperMethod> getRequiredMethods();
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -22,17 +22,12 @@
package org.richfaces.cdk.templatecompiler.statements;
import java.util.Collection;
-import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
-import javax.xml.namespace.QName;
-
-import org.richfaces.cdk.attributes.Attribute.Kind;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.TemplateModel;
import com.google.inject.Inject;
-import com.google.inject.internal.Sets;
/**
* @author Nick Belaevski
@@ -40,75 +35,6 @@
public class WriteAttributesSetStatement extends FreeMarkerTemplateStatementBase {
/**
- * <p class="changed_added_4_0">object contains information about
attribute</p>
- * @author asmirnov(a)exadel.com
- *
- */
- public static final class PassThrough implements Comparable<PassThrough> {
- QName name;
- Kind kind = Kind.GENERIC;
- String componentAttribute;
- String type;
- Object defaultValue;
- Set<String> behaviors = Sets.newHashSet();
-
- /**
- * <p class="changed_added_4_0"></p>
- * @return the name
- */
- public QName getName() {
- return this.name;
- }
- /**
- * <p class="changed_added_4_0"></p>
- * @return the kind
- */
- public Kind getKind() {
- return this.kind;
- }
- /**
- * <p class="changed_added_4_0"></p>
- * @return the componentAttribute
- */
- public String getComponentAttribute() {
- return this.componentAttribute;
- }
- /**
- * <p class="changed_added_4_0"></p>
- * @return the type
- */
- public String getType() {
- return this.type;
- }
- /**
- * <p class="changed_added_4_0"></p>
- * @return the defaultValue
- */
- public Object getDefaultValue() {
- return this.defaultValue;
- }
- /**
- * <p class="changed_added_4_0"></p>
- * @return the behaviors
- */
- public Set<String> getBehaviors() {
- return this.behaviors;
- }
- public String getBuilderMethod() {
- if(Kind.BOOLEAN.equals(kind)){
- return "bool";
- } else {
- return kind.toString().toLowerCase();
- }
- }
- @Override
-
- public int compareTo(PassThrough o) {
- return name.toString().compareTo(o.name.toString());
- }
- }
-
- /**
*
*/
private static final String PASS_THROUGH_ATTRIBUTES_FIELD_NAME =
"PASS_THROUGH_ATTRIBUTES";
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/util/JavaUtils.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/util/JavaUtils.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/util/JavaUtils.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -31,6 +31,7 @@
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.xmlconfig.JAXBBinding;
+import com.google.common.base.Function;
import com.google.common.collect.ImmutableMap;
/**
@@ -43,6 +44,12 @@
Character.class).put(Byte.TYPE, Byte.class).put(Short.TYPE,
Short.class).put(Integer.TYPE, Integer.class)
.put(Long.TYPE, Long.class).put(Float.TYPE, Float.class).put(Double.TYPE,
Double.class).build();
+ public static final Function<Class<?>, String> CLASS_TO_CLASS_NAME = new
Function<Class<?>, String>() {
+ public String apply(java.lang.Class<?> from) {
+ return from.getName();
+ }
+ };
+
private JavaUtils() {
// private constructor
}
Modified:
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/util/Strings.java
===================================================================
---
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/util/Strings.java 2010-10-27
15:55:50 UTC (rev 19698)
+++
branches/RF-7817/cdk/generator/src/main/java/org/richfaces/cdk/util/Strings.java 2010-10-27
15:58:31 UTC (rev 19699)
@@ -23,12 +23,20 @@
package org.richfaces.cdk.util;
+import java.util.NoSuchElementException;
+
+import com.google.common.base.Joiner;
+
+
/**
* <p class="changed_added_4_0">String manipulation utils.</p>
*
* @author asmirnov(a)exadel.com
*/
public final class Strings {
+
+ public static final Joiner DOT_JOINER = Joiner.on('.');
+
private Strings() {
// this is utility class with static methods only.
@@ -88,4 +96,14 @@
public static boolean isEmpty(String type) {
return type == null || type.length() == 0;
}
+
+ public static String firstNonEmpty(String... strings) {
+ for (String s : strings) {
+ if (!isEmpty(s)) {
+ return s;
+ }
+ }
+
+ throw new NoSuchElementException();
+ }
}
Modified: branches/RF-7817/cdk/parent/pom.xml
===================================================================
--- branches/RF-7817/cdk/parent/pom.xml 2010-10-27 15:55:50 UTC (rev 19698)
+++ branches/RF-7817/cdk/parent/pom.xml 2010-10-27 15:58:31 UTC (rev 19699)
@@ -350,10 +350,7 @@
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.5</version>
<configuration>
- <configLocation>richfaces-checkstyle/richfaces-checkstyle.xml
- </configLocation>
- <suppressionsLocation>checkstyle-suppressions.xml
- </suppressionsLocation>
+ <configLocation>richfaces-checkstyle/richfaces-checkstyle.xml</configLocation>
</configuration>
</plugin>
</plugins>