Author: alexsmirnov
Date: 2010-06-30 19:15:43 -0400 (Wed, 30 Jun 2010)
New Revision: 17692
Added:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java
Removed:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerRenderer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
Log:
improve template-based statements
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/Generator.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -36,7 +36,6 @@
import org.richfaces.cdk.apt.AptModule;
import org.richfaces.cdk.generate.freemarker.FreeMakerModule;
import org.richfaces.cdk.generate.java.ClassGeneratorModule;
-import org.richfaces.cdk.generate.java.taghandler.TagHandlerModule;
import org.richfaces.cdk.generate.taglib.TaglibModule;
import org.richfaces.cdk.model.ModelModule;
import org.richfaces.cdk.model.validator.ValidatorImpl;
@@ -48,9 +47,7 @@
import com.google.inject.Guice;
import com.google.inject.Injector;
import com.google.inject.Stage;
-import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
-import com.google.inject.util.Providers;
/**
* @author asmirnov
@@ -118,7 +115,7 @@
public void init() {
injector =
Guice.createInjector(Stage.PRODUCTION, new CdkConfigurationModule(), new
AptModule(), new ModelModule(),
- new ClassGeneratorModule(), new TagHandlerModule(), new
FreeMakerModule(), new TemplateModule(),
+ new FreeMakerModule(),new ClassGeneratorModule(), new TemplateModule(),
new XmlModule(), new TaglibModule());
if (!log.isDebugEnabled()) {
@@ -179,16 +176,9 @@
}
bind(NamingConventions.class).to(RichFacesConventions.class);
bind(ModelValidator.class).to(ValidatorImpl.class);
-
- bind(new TypeLiteral<Map<String, String>>() {
- }).annotatedWith(Names.named(OPTIONS)).toInstance(options);
- bindOption(RENDERER_UTILS_CLASS);
+ Names.bindProperties(binder(), options);
}
- private void bindOption(String name) {
- bind(String.class).annotatedWith(Names.named(name)).toProvider(
- Providers.of(options.get(name)));
- }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/CdkConfiguration.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -23,22 +23,30 @@
package org.richfaces.cdk.generate.freemarker;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Map;
+
import org.richfaces.cdk.Logger;
import com.google.inject.Inject;
import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
+import freemarker.template.TemplateException;
+import freemarker.template.TemplateModelException;
/**
- * <p class="changed_added_4_0"></p>
- *
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
*/
-public class CdkConfiguration extends Configuration {
-
+public class CdkConfiguration extends Configuration implements FreeMarkerRenderer {
+
private static final String TEMPLATES = "/META-INF/templates";
-
+
private Logger log;
@Inject
@@ -47,12 +55,56 @@
this.log = log;
// load templates from plugin classloader.
- setClassForTemplateLoading(this.getClass(), TEMPLATES);
+ setClassForTemplateLoading(this.getClass(), getTemplatesFolder());
setTemplateUpdateDelay(10000);// Forever...
setSharedVariable("utils", utils);
setObjectWrapper(wrapper);
-
// Add context variables
-// this.setSharedVariable("context", new BeanModel(context, new
BeansWrapper()));
+ // this.setSharedVariable("context", new BeanModel(context, new
BeansWrapper()));
}
+
+ @Inject(optional=true)
+ protected void setSharedVariables(Map<String,Object> variables) {
+ // template method for subclasses.
+ for (Map.Entry<String,Object> entry : variables.entrySet()) {
+ try {
+ setSharedVariable(entry.getKey(), entry.getValue());
+ } catch (TemplateModelException e) {
+ log.error("Error to set shared variable "+entry.getKey(), e);
+ }
+ }
+ }
+
+ @Override
+ public void writeTemplate(String templateName, Object object, Writer writer) throws
IOException, TemplateException {
+ getTemplate(templateName).process(object, writer);
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#renderSnippet(java.lang.String,
java.lang.Object)
+ */
+ @Override
+ public String renderTemplate(String templateName, Object object) {
+ StringWriter writer = new StringWriter();
+ try {
+ writeTemplate(templateName, object, writer);
+ return writer.toString();
+ } catch (IOException e) {
+ log.error("Error rendering template", e);
+ return e.getMessage();
+ } catch (TemplateException e) {
+ log.error("Error rendering template", e);
+ return e.getMessage();
+ }
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the templates
+ */
+ public static String getTemplatesFolder() {
+ return TEMPLATES;
+ }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMakerModule.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -25,9 +25,6 @@
import com.google.inject.AbstractModule;
-import freemarker.template.Configuration;
-import freemarker.template.ObjectWrapper;
-
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
@@ -37,8 +34,7 @@
@Override
protected void configure() {
- bind(Configuration.class).to(CdkConfiguration.class);
- bind(ObjectWrapper.class).to(LibraryModelWrapper.class);
+ bind(FreeMarkerRenderer.class).to(CdkConfiguration.class);
}
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerRenderer.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerRenderer.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerRenderer.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -1,104 +1,15 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-
-
package org.richfaces.cdk.generate.freemarker;
-import java.io.File;
import java.io.IOException;
import java.io.Writer;
-import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.CdkWriter;
-import org.richfaces.cdk.FileManager;
-import org.richfaces.cdk.model.ClassName;
-import org.richfaces.cdk.model.ComponentLibrary;
-import org.richfaces.cdk.model.ModelElementBase;
-import org.richfaces.cdk.model.Trackable;
-
-import freemarker.template.Configuration;
import freemarker.template.TemplateException;
-/**
- * <p class="changed_added_4_0">Base class for all output file buildes
that use FreeMarker as template engine.</p>
- * @author asmirnov(a)exadel.com
- *
- */
-public abstract class FreeMarkerRenderer<C> implements CdkWriter {
+public interface FreeMarkerRenderer {
+ public void writeTemplate(String templateName, Object object, Writer writer)
+ throws IOException, TemplateException;
- private final Configuration configuration;
+ public String renderTemplate(String templateName, Object object);
- private final FileManager output;
-
- public FreeMarkerRenderer(Configuration configuration, FileManager output) {
- this.configuration = configuration;
- this.output = output;
- }
-
- public void generate(ComponentLibrary library,C c) throws CdkException {
- try {
- Writer out = getOutput(library, c);
- if(null != out){
- configuration.getTemplate(getTemplateName()).process(c, out);
- out.close();
- }
- } catch (IOException e) {
- throw new CdkException(e);
- } catch (TemplateException e) {
- throw new CdkException(e);
- }
- }
-
- protected Writer getOutput(ComponentLibrary library, C c) throws CdkException {
- long lastModified = Long.MIN_VALUE;
-
- if (c instanceof Trackable) {
- Trackable trackuble = (Trackable) c;
- lastModified = trackuble.lastModified();
- }
-
- try {
- return output.createOutput(getOutputFileName(c), lastModified);
- } catch (IOException e) {
- throw new CdkException(e);
- }
- }
-
- protected String getOutputFileName(C c) throws CdkException {
- if (c instanceof ModelElementBase) {
- ModelElementBase modelElement = (ModelElementBase) c;
- return modelElement.getTargetClass().getName().replace('.',
File.separatorChar) + ".java";
- } else {
- throw new CdkException("Unknown model object " + c);
- }
- }
-
- protected String getJavaFileName(ClassName targetClass){
- return targetClass.getName().replace('.', File.separatorChar) +
".java";
- }
-
- protected abstract String getTemplateName();
-
-}
+}
\ No newline at end of file
Copied:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java
(from rev 17685,
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerRenderer.java)
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -0,0 +1,103 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+
+package org.richfaces.cdk.generate.freemarker;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.Writer;
+
+import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.FileManager;
+import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.model.ModelElementBase;
+import org.richfaces.cdk.model.Trackable;
+
+import freemarker.template.TemplateException;
+
+/**
+ * <p class="changed_added_4_0">Base class for all output file buildes
that use FreeMarker as template engine.</p>
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public abstract class FreeMarkerWriter<C> implements CdkWriter {
+
+
+ private final FreeMarkerRenderer configuration;
+
+ private final FileManager output;
+
+ public FreeMarkerWriter(FreeMarkerRenderer configuration, FileManager output) {
+ this.configuration = configuration;
+ this.output = output;
+ }
+
+ public void generate(ComponentLibrary library,C c) throws CdkException {
+ try {
+ Writer out = getOutput(library, c);
+ if(null != out){
+ configuration.writeTemplate(getTemplateName(),c, out);
+ out.close();
+ }
+ } catch (IOException e) {
+ throw new CdkException(e);
+ } catch (TemplateException e) {
+ throw new CdkException(e);
+ }
+ }
+
+ protected Writer getOutput(ComponentLibrary library, C c) throws CdkException {
+ long lastModified = Long.MIN_VALUE;
+
+ if (c instanceof Trackable) {
+ Trackable trackuble = (Trackable) c;
+ lastModified = trackuble.lastModified();
+ }
+
+ try {
+ return output.createOutput(getOutputFileName(c), lastModified);
+ } catch (IOException e) {
+ throw new CdkException(e);
+ }
+ }
+
+ protected String getOutputFileName(C c) throws CdkException {
+ if (c instanceof ModelElementBase) {
+ ModelElementBase modelElement = (ModelElementBase) c;
+ return modelElement.getTargetClass().getName().replace('.',
File.separatorChar) + ".java";
+ } else {
+ throw new CdkException("Unknown model object " + c);
+ }
+ }
+
+ protected String getJavaFileName(ClassName targetClass){
+ return targetClass.getName().replace('.', File.separatorChar) +
".java";
+ }
+
+ protected abstract String getTemplateName();
+
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/freemarker/FreeMarkerWriter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/BehaviorClassGenerator.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -30,21 +30,20 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.BehaviorModel;
import org.richfaces.cdk.model.ComponentLibrary;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* @author akolonitsky
* @since Jan 21, 2010
*/
-public class BehaviorClassGenerator extends FreeMarkerRenderer<BehaviorModel>
implements CdkWriter {
+public class BehaviorClassGenerator extends FreeMarkerWriter<BehaviorModel>
implements CdkWriter {
@Inject
- public BehaviorClassGenerator(Configuration configuration,
+ public BehaviorClassGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ClassGeneratorModule.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -23,19 +23,31 @@
package org.richfaces.cdk.generate.java;
+import java.util.Set;
+
import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.generate.freemarker.LibraryModelWrapper;
+import org.richfaces.cdk.generate.java.taghandler.ListenerTagHandlerGenerator;
+import org.richfaces.cdk.generate.java.taghandler.TagHandlerWriter;
-import com.google.inject.AbstractModule;
+import com.google.inject.PrivateModule;
+import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;
+import freemarker.template.ObjectWrapper;
+
/**
- * <p class="changed_added_4_0"></p>
+ * <p class="changed_added_4_0">
+ * </p>
+ *
* @author asmirnov(a)exadel.com
- *
+ *
*/
-public class ClassGeneratorModule extends AbstractModule {
+public class ClassGeneratorModule extends PrivateModule {
- /* (non-Javadoc)
+ /*
+ * (non-Javadoc)
+ *
* @see com.google.inject.AbstractModule#configure()
*/
@Override
@@ -46,6 +58,11 @@
setBinder.addBinding().to(ValidatorClassGenerator.class);
setBinder.addBinding().to(BehaviorClassGenerator.class);
setBinder.addBinding().to(EventSourceInterfaceGenerator.class);
+ setBinder.addBinding().to(TagHandlerWriter.class);
+ setBinder.addBinding().to(ListenerTagHandlerGenerator.class);
+ TypeLiteral<Set<CdkWriter>> writersType = new
TypeLiteral<Set<CdkWriter>>(){};
+ expose(writersType);
+ bind(ObjectWrapper.class).to(LibraryModelWrapper.class);
}
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ComponentClassGenerator.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -33,22 +33,21 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
*
*/
-public class ComponentClassGenerator extends FreeMarkerRenderer<ComponentModel>
implements CdkWriter {
+public class ComponentClassGenerator extends FreeMarkerWriter<ComponentModel>
implements CdkWriter {
@Inject
- public ComponentClassGenerator(Configuration configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public ComponentClassGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -30,21 +30,20 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ConverterModel;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* @author akolonitsky
* @since Jan 20, 2010
*/
-public class ConverterClassGenerator extends FreeMarkerRenderer<ConverterModel>
implements CdkWriter {
+public class ConverterClassGenerator extends FreeMarkerWriter<ConverterModel>
implements CdkWriter {
@Inject
- public ConverterClassGenerator(Configuration configuration,
+ public ConverterClassGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/EventSourceInterfaceGenerator.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -31,21 +31,20 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventModel;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* @author asmirnov
* @since Jan 20, 2010
*/
-public class EventSourceInterfaceGenerator extends FreeMarkerRenderer<EventModel>
implements CdkWriter {
+public class EventSourceInterfaceGenerator extends FreeMarkerWriter<EventModel>
implements CdkWriter {
@Inject
- public EventSourceInterfaceGenerator(Configuration configuration,
+ public EventSourceInterfaceGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -30,21 +30,20 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ValidatorModel;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* @author akolonitsky
* @since Jan 15, 2010
*/
-public class ValidatorClassGenerator extends FreeMarkerRenderer<ValidatorModel>
implements CdkWriter {
+public class ValidatorClassGenerator extends FreeMarkerWriter<ValidatorModel>
implements CdkWriter {
@Inject
- public ValidatorClassGenerator(Configuration configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public ValidatorClassGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/ListenerTagHandlerGenerator.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -32,22 +32,21 @@
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.annotations.TagType;
import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerWriter;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventModel;
import org.richfaces.cdk.model.TagModel;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
-
/**
* @author akolonitsky
* @since Jan 20, 2010
*/
-public class ListenerTagHandlerGenerator extends
FreeMarkerRenderer<TagWithModel<EventModel>> implements CdkWriter {
+public class ListenerTagHandlerGenerator extends
FreeMarkerWriter<TagWithModel<EventModel>> implements CdkWriter {
@Inject
- public ListenerTagHandlerGenerator(Configuration configuration,
+ public ListenerTagHandlerGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
super(configuration, output);
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerClassGenerator.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -30,13 +30,13 @@
import org.richfaces.cdk.FileManager;
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.model.ModelElementBase;
import org.richfaces.cdk.model.TagModel;
import org.richfaces.cdk.model.Trackable;
import com.google.inject.Inject;
-import freemarker.template.Configuration;
import freemarker.template.TemplateException;
/**
@@ -49,10 +49,10 @@
private final FileManager output;
- private final Configuration configuration;
+ private final FreeMarkerRenderer configuration;
@Inject
- public TagHandlerClassGenerator(Configuration configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
+ public TagHandlerClassGenerator(FreeMarkerRenderer configuration,
@Output(Outputs.JAVA_CLASSES) FileManager output) {
this.configuration = configuration;
this.output = output;
}
@@ -60,7 +60,7 @@
public boolean process(ModelElementBase model, TagModel tag) throws CdkException {
try {
Writer writer = getOutput(tag);
- configuration.getTemplate(TAGHANDLER_TEMPLATE).process(new
TagWithModel<ModelElementBase>(tag, model),
+ configuration.writeTemplate(TAGHANDLER_TEMPLATE,new
TagWithModel<ModelElementBase>(tag, model),
writer);
writer.close();
} catch (IOException e) {
Deleted:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerModule.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerModule.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/taghandler/TagHandlerModule.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -1,44 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright , 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.generate.java.taghandler;
-
-import org.richfaces.cdk.CdkWriter;
-
-import com.google.inject.AbstractModule;
-import com.google.inject.multibindings.Multibinder;
-
-/**
- * @author akolonitsky
- * @since Feb 22, 2010
- */
-public class TagHandlerModule extends AbstractModule {
-
- @Override
- protected void configure() {
- Multibinder<CdkWriter> multibinder = Multibinder.newSetBinder(binder(),
CdkWriter.class);
- multibinder
- .addBinding().to(TagHandlerWriter.class);
- multibinder
- .addBinding().to(ListenerTagHandlerGenerator.class);
- }
-}
Deleted:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/FreeMarkerRenderer.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -1,15 +0,0 @@
-package org.richfaces.cdk.templatecompiler;
-
-import java.io.IOException;
-import java.io.Writer;
-
-import freemarker.template.TemplateException;
-
-public interface FreeMarkerRenderer {
-
- public void writeSnippet(String templateName, Object object, Writer writer)
- throws IOException, TemplateException;
-
- public String renderSnippet(String templateName, Object object);
-
-}
\ No newline at end of file
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassConfiguration.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -29,6 +29,8 @@
import java.util.HashMap;
import java.util.Map;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
@@ -47,7 +49,7 @@
setClassForTemplateLoading(this.getClass(), TEMPLATES);
// TODO create an object wrapper for library model.
- setObjectWrapper(new JavaClassModelWrapper(this));
+ setObjectWrapper(new JavaClassModelWrapper());
// Add context variables
// this.setSharedVariable("context", new BeanModel(context, new
BeansWrapper()));
@@ -56,7 +58,7 @@
/* (non-Javadoc)
* @see
org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#writeSnippet(java.lang.String,
java.lang.Object, java.io.Writer)
*/
- public void writeSnippet(String templateName, Object object, Writer writer) throws
IOException, TemplateException {
+ public void writeTemplate(String templateName, Object object, Writer writer) throws
IOException, TemplateException {
Template t = getTemplate(templateName + ".ftl");
Map<String, Object> rootMap = new HashMap<String, Object>();
rootMap.put("modelItem", object);
@@ -72,10 +74,10 @@
/* (non-Javadoc)
* @see
org.richfaces.cdk.templatecompiler.FreeMarkerRenderer#renderSnippet(java.lang.String,
java.lang.Object)
*/
- public String renderSnippet(String templateName, Object object) {
+ public String renderTemplate(String templateName, Object object) {
StringWriter writer = new StringWriter();
try {
- writeSnippet(templateName, object, writer);
+ writeTemplate(templateName, object, writer);
return writer.toString();
} catch (IOException e) {
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/JavaClassModelWrapper.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -9,10 +9,8 @@
public class JavaClassModelWrapper extends BeansWrapper implements ObjectWrapper {
- private final JavaClassConfiguration configuration;
- public JavaClassModelWrapper(JavaClassConfiguration configuration) {
- this.configuration = configuration;
+ public JavaClassModelWrapper() {
}
@Override
@@ -30,13 +28,5 @@
return templateModel;
}
- /**
- * <p class="changed_added_4_0"></p>
- *
- * @return the configuration
- */
- public JavaClassConfiguration getConfiguration() {
- return configuration;
- }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -33,6 +33,7 @@
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.ModelSet;
@@ -115,7 +116,7 @@
output.createOutput(fullName.replace('.',
'/') + ".java", library.lastModified());
if (null != outFile) {
- this.renderer.writeSnippet("class", javaClass,
outFile);
+ this.renderer.writeTemplate("class", javaClass,
outFile);
outFile.close();
}
} catch (IOException e) {
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -104,6 +104,7 @@
import com.google.common.base.Function;
import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Injector;
@@ -145,6 +146,13 @@
*/
static final String CLIENT_ID_VARIABLE = "clientId";
+ static final ImmutableMap<String, Object> ENCODE_METHOD_VARIABLES =
ImmutableMap.<String, Object>builder()
+ .put("facesContextVariable", RendererClassVisitor.FACES_CONTEXT_VARIABLE)
+ .put("componentVariable", RendererClassVisitor.COMPONENT_VARIABLE)
+ .put("responseWriterVariable",
RendererClassVisitor.RESPONSE_WRITER_VARIABLE)
+ .put("clientIdVariable", RendererClassVisitor.CLIENT_ID_VARIABLE)
+ .build();
+
/**
*
*/
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateModule.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -23,6 +23,9 @@
package org.richfaces.cdk.templatecompiler;
+import java.util.Map;
+import java.util.Set;
+
import org.richfaces.cdk.CdkWriter;
import org.richfaces.cdk.ModelBuilder;
import org.richfaces.cdk.attributes.Schema;
@@ -33,18 +36,20 @@
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactory;
import org.richfaces.cdk.templatecompiler.statements.HelperMethodFactoryImpl;
-import com.google.inject.AbstractModule;
+import com.google.inject.PrivateModule;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.multibindings.Multibinder;
import com.google.inject.name.Names;
+import freemarker.template.ObjectWrapper;
+
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
*
*/
-public class TemplateModule extends AbstractModule {
+public class TemplateModule extends PrivateModule {
/* (non-Javadoc)
* @see com.google.inject.AbstractModule#configure()
@@ -53,13 +58,19 @@
protected void configure() {
Multibinder<ModelBuilder> modelBinder = Multibinder.newSetBinder(binder(),
ModelBuilder.class);
modelBinder.addBinding().to(RendererTemplateParser.class);
+ TypeLiteral<Set<ModelBuilder>> buildersType = new
TypeLiteral<Set<ModelBuilder>>(){};
+ expose(buildersType);
Multibinder.newSetBinder(binder(),
CdkWriter.class).addBinding().to(RendererClassGenerator.class);
+ TypeLiteral<Set<CdkWriter>> writersType = new
TypeLiteral<Set<CdkWriter>>(){};
+ expose(writersType);
+ // Private bindings.
bind(new
TypeLiteral<TemplateVisitorFactory<RendererClassVisitor>>(){}).to(VisitorFactoryImpl.class).in(Singleton.class);
- bind(FreeMarkerRenderer.class).to(JavaClassConfiguration.class);
bind(TypesFactory.class).to(TypesFactoryImpl.class);
bind(ELParser.class).to(ELParserImpl.class);
bind(HelperMethodFactory.class).to(HelperMethodFactoryImpl.class).in(Singleton.class);
bind(Schema.class).annotatedWith(Names.named(Template.XHTML_EL_NAMESPACE)).toProvider(XhtmlElSchemaProvider.class).in(Singleton.class);
+ bind(ObjectWrapper.class).to(JavaClassModelWrapper.class);
+ bind(new
TypeLiteral<Map<String,Object>>(){}).toInstance(RendererClassVisitor.ENCODE_METHOD_VARIABLES);
}
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaClass.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -22,7 +22,6 @@
package org.richfaces.cdk.templatecompiler.builder.model;
import java.util.ArrayList;
-import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
@@ -40,11 +39,7 @@
private static final ClassName DEFAULT_SUPERCLASS = ClassName.get(Renderer.class);
private List<JavaField> fields = new ArrayList<JavaField>();
private List<JavaMethod> methods = new ArrayList<JavaMethod>();
- private Set<JavaImport> imports = new TreeSet<JavaImport>(new
Comparator<JavaImport>() {
- public int compare(JavaImport o1, JavaImport o2) {
- return o1.getName().compareTo(o2.getName());
- }
- });
+ private Set<JavaImport> imports = new
TreeSet<JavaImport>(JavaImport.COMPARATOR);
private ClassName superClass = DEFAULT_SUPERCLASS;
private final JavaPackage pakg;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/builder/model/JavaImport.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,10 +21,18 @@
package org.richfaces.cdk.templatecompiler.builder.model;
+import java.util.Comparator;
+
/**
* @author Maksim Kaszynski
*/
public interface JavaImport {
- public String getName();
- public boolean isDefault();
+ 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();
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/ELVisitor.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -94,6 +94,7 @@
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.templatecompiler.statements.StatementsContainer;
import org.richfaces.cdk.templatecompiler.statements.TypedTemplateStatement;
/**
* Entry point for parsing EL expressions. @see parse() method.
@@ -117,6 +118,8 @@
private boolean mixedExpression;
private boolean literal = true;
+
+ private StatementsContainer parent;
public ELVisitor(Logger log, TypesFactory typesFactory) {
@@ -364,4 +367,10 @@
return treeNode;
}
+
+ @Override
+ public void setParent(StatementsContainer parent) {
+ this.parent = parent;
+ }
+
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/el/types/NullType.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -85,7 +85,7 @@
*/
@Override
public String toString() {
- return getClass().getName();
+ return "null";
}
/* (non-Javadoc)
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ConstantReturnMethodBodyStatement.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import com.google.inject.Inject;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/DefineObjectStatement.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,8 +21,14 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.ELParser;
+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.inject.Inject;
+
/**
* @author Nick Belaevski
*/
@@ -32,17 +38,52 @@
private String name;
- private String initializationExpression;
+ private final ELParser parser;
- public DefineObjectStatement(ELType type, String name, String
initializationExpression) {
- super("define-object");
+ private TypedTemplateStatement initializationStatement;
+ @Inject
+ public DefineObjectStatement(FreeMarkerRenderer renderer, ELParser parser) {
+ super(renderer, "define-object");
+ this.parser = parser;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param type
+ * the type to set
+ */
+ public void setType(ELType type) {
this.type = type;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param name
+ * the name to set
+ */
+ public void setName(String name) {
this.name = name;
- this.initializationExpression = initializationExpression != null ?
initializationExpression : "";
}
/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param initializationExpression
+ * the initializationExpression to set
+ * @throws ParsingException
+ */
+ public void setInitializationExpression(String initializationExpression) throws
ParsingException {
+ initializationStatement = parser.parse(initializationExpression, this,
TypesFactory.OBJECT_TYPE);
+ initializationStatement.setParent(this);
+ }
+
+ /**
* @return the type
*/
public ELType getType() {
@@ -59,8 +100,8 @@
/**
* @return the initializationExpression
*/
- public String getInitializationExpression() {
- return initializationExpression;
+ public TemplateStatement getInitializationExpression() {
+ return initializationStatement;
}
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ElementStatement.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
/**
* @author Nick Belaevski
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EncodeMethodPrefaceStatement.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import com.google.inject.Inject;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/EndElementStatement.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import com.google.inject.Inject;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/ForEachStatement.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,10 +21,14 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
*/
-public class ForEachStatement extends TemplateStatementsContainerBase {
+public class ForEachStatement extends TemplateStatementBase {
private String itemsExpression;
@@ -32,12 +36,9 @@
private String varType;
- public ForEachStatement(String itemsExpression,
- String var, String varType) {
- super("for-each");
- this.itemsExpression = itemsExpression;
- this.var = var;
- this.varType = varType;
+ @Inject
+ public ForEachStatement(FreeMarkerRenderer renderer) {
+ super(renderer,"for-each");
}
/**
@@ -61,4 +62,28 @@
return varType;
}
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param itemsExpression the itemsExpression to set
+ */
+ public void setItemsExpression(String itemsExpression) {
+ this.itemsExpression = itemsExpression;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param var the var to set
+ */
+ public void setVar(String var) {
+ this.var = var;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param varType the varType to set
+ */
+ public void setVarType(String varType) {
+ this.varType = varType;
+ }
+
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/HelperMethodFactoryImpl.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -26,7 +26,8 @@
import java.util.EnumMap;
import org.richfaces.cdk.Generator;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.Logger;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.templatecompiler.builder.model.Argument;
import org.richfaces.cdk.templatecompiler.builder.model.JavaMethod;
import org.richfaces.cdk.templatecompiler.builder.model.JavaModifier;
@@ -35,7 +36,6 @@
import com.google.common.collect.Maps;
import com.google.inject.Inject;
-import com.google.inject.internal.Nullable;
import com.google.inject.name.Named;
/**
@@ -47,30 +47,43 @@
*/
public class HelperMethodFactoryImpl implements HelperMethodFactory {
- private final FreeMarkerRenderer renderer;
- private final TypesFactory typesFactory;
- private final String rendererUtilsClass;
- private final EnumMap<HelperMethod, JavaMethod> helperMethods =
- Maps.newEnumMap(HelperMethod.class);
+ private TypesFactory typesFactory;
+ @Inject(optional = true)
+ @Named(Generator.RENDERER_UTILS_CLASS)
+ private String rendererUtilsClass =
"org.richfaces.renderkit.RenderKitUtils";
+ private FreeMarkerRenderer renderer;
+ private final EnumMap<HelperMethod, JavaMethod> helperMethods =
Maps.newEnumMap(HelperMethod.class);
+
+ private final Logger log;
+
@Inject
- public HelperMethodFactoryImpl(FreeMarkerRenderer renderer, TypesFactory
typesFactory,
- @Named(Generator.RENDERER_UTILS_CLASS) @Nullable String rendererUtilsClass) {
+ public HelperMethodFactoryImpl(Logger log) {
+ this.log = log;
+ }
+
+ /**
+ * <p class="changed_added_4_0">
+ * Initialization code. It should be called after field injection, so render kit
utils class name should have proper
+ * value here.
+ * </p>
+ *
+ * @param renderer
+ * @param typesFactory
+ */
+ @Inject
+ public void initHelperMethods(FreeMarkerRenderer renderer, TypesFactory typesFactory)
{
this.renderer = renderer;
this.typesFactory = typesFactory;
- this.rendererUtilsClass = rendererUtilsClass;
- initHelperMethods();
- }
-
- protected void initHelperMethods() {
buildHelperMethod(HelperMethod.EMPTINESS_CHECK, false,
"emptiness-check-method", "object");
buildHelperMethod(HelperMethod.EQUALS_CHECK, false,
"equals-check-method", "o1", "o2");
- buildHelperMethod(HelperMethod.TO_BOOLEAN_CONVERSION,
false,"conversion-to-boolean-method", "object");
+ buildHelperMethod(HelperMethod.TO_BOOLEAN_CONVERSION, false,
"conversion-to-boolean-method", "object");
buildHelperMethod(HelperMethod.TO_STRING_CONVERSION, false,
"conversion-to-string-method", "object");
}
- private JavaMethod buildHelperMethod(HelperMethod helperMethod, boolean utilsMethod,
String templateName, String... argumentNames) {
+ private JavaMethod buildHelperMethod(HelperMethod helperMethod, boolean utilsMethod,
String templateName,
+ String... argumentNames) {
JavaMethod helperJavaMethod;
if (utilsMethod && null != rendererUtilsClass) {
helperJavaMethod = new RendererUtilsMethod(helperMethod,
rendererUtilsClass);
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/IfElseStatement.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,14 +21,19 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
* @since 4.0
*/
-public class IfElseStatement extends TemplateStatementsContainerBase {
+public class IfElseStatement extends TemplateStatementBase {
- public IfElseStatement() {
- super("if-else");
+ @Inject
+ public IfElseStatement(FreeMarkerRenderer renderer) {
+ super(renderer,"if-else");
}
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StartElementStatement.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import com.google.inject.Inject;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/StatementsContainer.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -67,7 +67,7 @@
}
};
- private List<TemplateStatement> statements = new
ArrayList<TemplateStatement>();
+ private final List<TemplateStatement> statements = new
ArrayList<TemplateStatement>();
private StatementsContainer parent;
@@ -79,12 +79,12 @@
public void addStatement(TemplateStatement statement) {
statement.setParent(this);
- statements.add(statement);
+ getStatements().add(statement);
}
public void addStatement(int index, TemplateStatement statement) {
statement.setParent(this);
- statements.add(index, statement);
+ getStatements().add(index, statement);
}
/**
@@ -109,7 +109,7 @@
}
public boolean isEmpty() {
- return statements.isEmpty();
+ return getStatements().isEmpty();
}
/*
@@ -120,7 +120,7 @@
@Override
public String getCode() {
StringBuilder sb = new StringBuilder();
- for (TemplateStatement statement : statements) {
+ for (TemplateStatement statement : getStatements()) {
sb.append(statement.getCode());
sb.append('\n');
}
@@ -154,7 +154,7 @@
}
private <T> Iterable<T> concatStatements(Function<TemplateStatement,
Iterable<T>> transform) {
- Iterable<T> imports = Iterables.concat(Iterables.transform(statements,
transform));
+ Iterable<T> imports = Iterables.concat(Iterables.transform(getStatements(),
transform));
return imports;
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementBase.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,23 +21,38 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import java.util.Collections;
import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+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.JavaModifier;
+import org.richfaces.cdk.templatecompiler.builder.model.RuntimeImport;
+import org.richfaces.cdk.templatecompiler.builder.model.StatementImpl;
+import org.richfaces.cdk.templatecompiler.el.types.ReferencedType;
+import org.richfaces.cdk.util.Strings;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Sets;
+
/**
* @author Nick Belaevski
*
*/
-public class TemplateStatementBase implements TemplateStatement {
+public class TemplateStatementBase extends StatementsContainer {
protected StatementsContainer parent;
private final String templateName;
private final FreeMarkerRenderer renderer;
+ private final Set<JavaImport> imports =
Sets.newTreeSet(JavaImport.COMPARATOR);
private final EnumSet<HelperMethod> requiredMethods =
EnumSet.noneOf(HelperMethod.class);
+ private final List<JavaField> fields = Lists.newArrayList();
+
+ private boolean parsed = false;
+ private String code;
protected TemplateStatementBase(FreeMarkerRenderer renderer, String templateName) {
super();
@@ -45,29 +60,36 @@
this.templateName = templateName;
}
- @Override
- public void setParent(StatementsContainer parent) {
- this.parent = parent;
- }
@Override
public String getCode() {
- return renderer.renderSnippet(templateName, this);
+ parse();
+ return code;
}
+ private void parse() {
+ if(!parsed){
+ code = renderer.renderTemplate(templateName, this);
+ parsed = true;
+ }
+ }
+
@Override
public Iterable<JavaImport> getRequiredImports() {
- return Collections.emptySet();
+ parse();
+ return Iterables.concat(super.getRequiredImports(),imports);
}
@Override
public Iterable<JavaField> getRequiredFields() {
- return Collections.emptySet();
+ parse();
+ return Iterables.concat(super.getRequiredFields(),fields);
}
@Override
public Iterable<HelperMethod> getRequiredMethods() {
- return requiredMethods;
+ parse();
+ return Iterables.concat(super.getRequiredMethods(),requiredMethods);
}
protected void addRequiredMethods(HelperMethod... methods) {
@@ -75,4 +97,24 @@
requiredMethods.add(helperMethod);
}
}
+
+ public void addConstant(String type, String name, String code) {
+ JavaField field = new JavaField(new ReferencedType(type),name);
+ field.addModifier(JavaModifier.PRIVATE);
+ field.addModifier(JavaModifier.STATIC);
+ field.addModifier(JavaModifier.FINAL);
+ if(!Strings.isEmpty(code)){
+ field.setValue(new StatementImpl(code));
+ }
+ fields.add(field);
+ }
+
+ public void addImport(String name) {
+ imports.add(new RuntimeImport(name));
+ }
+
+ public void addRequiredMethod(String helperMethodName) {
+ HelperMethod helperMethod = HelperMethod.valueOf(helperMethodName);
+ requiredMethods.add(helperMethod);
+ }
}
\ No newline at end of file
Deleted:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/TemplateStatementsContainerBase.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -1,46 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2009, Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.richfaces.cdk.templatecompiler.statements;
-
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
-
-
-/**
- * @author Nick Belaevski
- */
-public class TemplateStatementsContainerBase extends StatementsContainer {
-
- private final String templateName;
- private final FreeMarkerRenderer renderer;
-
- protected TemplateStatementsContainerBase(FreeMarkerRenderer renderer,String
templateName) {
- super();
- this.renderer = renderer;
- this.templateName = templateName;
- }
-
- @Override
- public String getCode() {
- return renderer.renderSnippet(templateName, this);
- }
-
-}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributeStatement.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,7 +21,7 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
-import org.richfaces.cdk.templatecompiler.FreeMarkerRenderer;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import com.google.inject.Inject;
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteAttributesSetStatement.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,17 +21,30 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import java.util.concurrent.atomic.AtomicInteger;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
*/
public class WriteAttributesSetStatement extends TemplateStatementBase {
+ /**
+ *
+ */
+ private static final String PASS_THROUGH_ATTRIBUTES_FIELD_NAME =
"PASS_THROUGH_ATTRIBUTES";
+
+ private static AtomicInteger fieldCounter = new AtomicInteger(0);
+
private String passThroughFieldName;
- public WriteAttributesSetStatement(String passThroughFieldName) {
- super("write-attributes-set");
- this.passThroughFieldName = passThroughFieldName;
+ @Inject
+ public WriteAttributesSetStatement(FreeMarkerRenderer renderer) {
+ super(renderer, "write-attributes-set");
+ passThroughFieldName = PASS_THROUGH_ATTRIBUTES_FIELD_NAME +
fieldCounter.getAndIncrement();
}
/**
@@ -40,5 +53,5 @@
public String getPassThroughFieldName() {
return passThroughFieldName;
}
-
+
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/statements/WriteTextStatement.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -21,20 +21,46 @@
*/
package org.richfaces.cdk.templatecompiler.statements;
+import java.util.Collections;
+import java.util.List;
+
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.templatecompiler.ELParser;
+import org.richfaces.cdk.templatecompiler.el.ParsingException;
+import org.richfaces.cdk.templatecompiler.el.types.TypesFactory;
+
+import com.google.inject.Inject;
+
/**
* @author Nick Belaevski
*/
public class WriteTextStatement extends TemplateStatementBase {
- private String textExpression;
+ private TemplateStatement textStatement;
+ private final ELParser parser;
- public WriteTextStatement(String textExpression) {
- super("write-text");
- this.textExpression = textExpression;
+ @Inject
+ public WriteTextStatement(FreeMarkerRenderer renderer,ELParser parser) {
+ super(renderer,"write-text");
+ this.parser = parser;
}
- public String getTextExpression() {
- return textExpression;
+ public TemplateStatement getTextStatement() {
+ return textStatement;
}
+ @Override
+ public List<TemplateStatement> getStatements() {
+ return Collections.singletonList(textStatement);
+ }
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param textExpression the textExpression to set
+ * @throws ParsingException
+ */
+ public void setExpression(String textExpression) throws ParsingException {
+ textStatement = parser.parse(textExpression,this,TypesFactory.OBJECT_TYPE);
+ textStatement.setParent(this);
+ }
+
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/LibraryBuilderTest.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -14,7 +15,6 @@
import org.apache.maven.model.FileSet;
import org.apache.maven.plugin.MojoExecutionException;
import org.codehaus.plexus.util.DirectoryScanner;
-import org.junit.Ignore;
import org.junit.Test;
/**
@@ -25,7 +25,7 @@
private static final String[] JAVA_INCLUDES = new String[] { "**/*.java"
};
private static final String MAIN_CONFIG = "src/main/config";
private static final String MAIN_TEMPLATES = "src/main/templates";
- private static final String PROJECT_BASE =
"E:\\_richfaces\\svn\\richfaces_root\\ui\\components\\core\\";
+ private static final String PROJECT_BASE = "";
private static final String[] STRINGS_ARRAY = new String[0];
private static final String XML_INCLUDES = "**/*.xml";
@@ -45,15 +45,11 @@
* @param type
*/
private static void setOutput(Generator generator, File directory, Outputs type) {
- if (!directory.exists()) {
- directory.mkdirs();
- }
generator.addOutputFolder(type, directory);
}
@Test
- @Ignore
public void createInstance() throws Exception {
List<String> compileSourceRoots = Arrays.asList("");
@@ -89,7 +85,6 @@
// Build JSF library.
// LibraryBuilder builder = LibraryBuilder.createInstance(context);
generator.init();
- generator.execute();
} catch (CdkException e) {
throw new MojoExecutionException("CDK build error", e);
}
@@ -110,102 +105,16 @@
return new CdkClassLoader(this.getClass().getClassLoader());
}
- /**
- * Skan Array of filesets for selected resources.
- *
- * @param filesets
- * @return
- * @throws MojoExecutionException
- */
- @SuppressWarnings("unchecked")
- protected Collection<File> doScan(FileSet[] filesets) throws
MojoExecutionException {
- List<File> files = new ArrayList<File>();
-
- if (null != filesets) {
- for (FileSet fileSet : filesets) {
- String[] includes = (String[])
fileSet.getIncludes().toArray(STRINGS_ARRAY);
- String[] excludes = (String[])
fileSet.getExcludes().toArray(STRINGS_ARRAY);
- File fileSetDirectory = resolveRelativePath(new
File(fileSet.getDirectory()));
- String[] scan = doScan(includes, excludes, fileSetDirectory);
-
- for (String filename : scan) {
- files.add(resolveRelativePath(new File(fileSetDirectory,
filename)));
- }
- }
- }
-
- return files;
- }
-
- protected String[] doScan(String[] includes, String[] excludes, File rootFolder)
throws MojoExecutionException {
- try {
- DirectoryScanner directoryScanner = new DirectoryScanner();
-
- directoryScanner.setFollowSymlinks(true);
- directoryScanner.setBasedir(rootFolder);
- directoryScanner.setExcludes(excludes);
- directoryScanner.setIncludes(includes);
- directoryScanner.addDefaultExcludes();
- directoryScanner.scan();
-
- return directoryScanner.getIncludedFiles();
- } catch (IllegalStateException e) {
- throw new MojoExecutionException("Error scanning source root:
\'" + rootFolder + "\'", e);
- }
- }
-
private Iterable<File> findFacesConfigFiles() throws MojoExecutionException {
- FileSet[] facesConfigs = null;
- File defaultDirectory = resolveRelativePath(new File(MAIN_CONFIG));
- if (defaultDirectory.exists() && defaultDirectory.isDirectory()) {
- FileSet fileSet = new FileSet();
-
- fileSet.setDirectory(MAIN_CONFIG);
- fileSet.addInclude(XML_INCLUDES);
- facesConfigs = new FileSet[] { fileSet };
- }
-
- return doScan(facesConfigs);
+ return Collections.emptySet();
}
private Iterable<File> findJavaFiles() throws MojoExecutionException {
- Set<File> javaSources = new HashSet<File>();
- String[] includes = JAVA_INCLUDES;
- String[] compileSourceRoots = new String[] { PROJECT_BASE +
"\\src\\main\\java" };
- for (String compileRoot : compileSourceRoots) {
- File rootFolder = new File(compileRoot);
- String[] sources = doScan(includes, null, rootFolder);
-
- for (String src : sources) {
- javaSources.add(new File(rootFolder, src));
- }
- }
-
- return javaSources;
+ return Collections.emptySet();
}
private Iterable<File> findTemplateFiles() throws MojoExecutionException {
- FileSet[] templates = null;
- File defaultDirectory = resolveRelativePath(new File(MAIN_TEMPLATES));
-
- if (defaultDirectory.exists() && defaultDirectory.isDirectory()) {
- FileSet fileSet = new FileSet();
-
- fileSet.setDirectory(MAIN_TEMPLATES);
- fileSet.addInclude(XML_INCLUDES);
- templates = new FileSet[] { fileSet };
- }
-
- return doScan(templates);
+ return Collections.emptySet();
}
-
- private File resolveRelativePath(File file) {
- File result = file;
- if (!result.isAbsolute()) {
- result = new File(PROJECT_BASE, result.getPath());
- }
-
- return result;
- }
}
Modified:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -1,5 +1,5 @@
/*
- * JBoss, Home of Professional Open Source
+Fr * JBoss, Home of Professional Open Source
* Copyright , Red Hat, Inc. and individual contributors
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
@@ -39,6 +39,7 @@
import org.richfaces.cdk.Output;
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.generate.freemarker.CdkConfiguration;
+import org.richfaces.cdk.generate.freemarker.FreeMarkerRenderer;
import org.richfaces.cdk.generate.freemarker.LibraryModelWrapper;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
@@ -48,7 +49,6 @@
import com.google.inject.Inject;
-import freemarker.template.Configuration;
import freemarker.template.ObjectWrapper;
/**
@@ -59,7 +59,7 @@
@Inject
@As(CdkConfiguration.class)
- protected Configuration configuration;
+ protected FreeMarkerRenderer configuration;
@Inject
protected ComponentLibrary library;
Copied:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java
(from rev 17685,
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java)
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java
(rev 0)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -0,0 +1,400 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.templatecompiler.model;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.richfaces.cdk.model.ClassName;
+import org.richfaces.cdk.model.FacesId;
+import org.richfaces.cdk.xmlconfig.JaxbTestBase;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class TemplateParserTest extends JaxbTestBase {
+
+ public static final String TEMPLATE_PROLOG =
+ "<cdk:root
xmlns=\"http://www.w3.org/1999/xhtml\"
xmlns:cdk=\"http://richfaces.org/cdk/core\"
xmlns:c=\"http://richfaces.org/cdk/jstl/core\"
xmlns:cc=\"http://richfaces.org/cdk/jsf/composite\"><cc:i...;
+ private static final Object DEFAULT_ATTRIBUTE_TYPE = new ClassName(Object.class);
+ private static final String TEMPLATE_EPILOG =
"</cc:implementation></cdk:root>";
+ private static final String TEMPLATE_MIDDLE =
"</cc:interface><cc:implementation>";
+
+ @Test
+ public void testAttributes() throws Exception {
+ Template template =
+ unmarshal(
+ Template.class,
+ TEMPLATE_PROLOG
+ +
"<cdk:renders-children>true</cdk:renders-children>"
+ + "<cc:attribute name=\"onclick\" />"
+ + "<cc:attribute name=\"mode\"
default=\"ajax\" />"
+ + "<cc:attribute name=\"action\"
method-signature=\"void action()\" />"
+ + "<cc:attribute name=\"changeListener\"
method-signature=\"void changeListener(ValueChangeEvent)\"
targets=\"changes changes1\" />"
+ + "<cc:attribute name=\"disabled\"
type=\"boolean\" />"
+ + "<cc:attribute name=\"delay\"
type=\"java.lang.Integer\" />"
+ + "<cc:attribute name=\"id\"
required=\"true\" />"
+ + "<cc:attribute name=\"experts\"
shortDescription=\"For use by experts\" displayName=\"Expert
attribute\" expert=\"true\" />"
+ + "<cc:attribute name=\"preferred\"
shortDescription=\"It's a preferred attribute\" displayName=\"Preferred
attribute\" preferred=\"true\" />"
+ + "<cc:attribute name=\"onchange\">" +
"<cc:clientBehavior event=\"change\" />"
+ + "<cc:clientBehavior event=\"valueChange\"
default=\"true\" />" + "</cc:attribute>"
+ + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
+
+ CompositeInterface interfaceSection = template.getInterface();
+ assertNotNull(interfaceSection);
+
+ List<Attribute> attributes = interfaceSection.getAttributes();
+ assertNotNull(attributes);
+ assertEquals(10, attributes.size());
+
+ Attribute attribute;
+
+ attribute = attributes.get(0);
+ assertNotNull(attribute);
+ assertEquals("onclick", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertNull(attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(1);
+ assertNotNull(attribute);
+ assertEquals("mode", attribute.getName());
+ assertEquals("ajax", attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertNull(attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(2);
+ assertNotNull(attribute);
+ assertEquals("action", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertEquals("void action()", attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertNull(attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(3);
+ assertNotNull(attribute);
+ assertEquals("changeListener", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertEquals("void changeListener(ValueChangeEvent)",
attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertEquals("changes changes1", attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(4);
+ assertNotNull(attribute);
+ assertEquals("disabled", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(ClassName.parseName("boolean"), attribute.getType());
+ assertNull(attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(5);
+ assertNotNull(attribute);
+ assertEquals("delay", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(ClassName.parseName("java.lang.Integer"),
attribute.getType());
+ assertNull(attribute.getTargets());
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(6);
+ assertNotNull(attribute);
+ assertEquals("id", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertNull(attribute.getTargets());
+ assertTrue(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(7);
+ assertNotNull(attribute);
+ assertFalse(attribute.isRequired());
+ assertEquals("experts", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertNull(attribute.getTargets());
+ assertEquals("For use by experts", attribute.getShortDescription());
+ assertEquals("Expert attribute", attribute.getDisplayName());
+ assertTrue(attribute.isExpert());
+ assertFalse(attribute.isPreferred());
+
+ attribute = attributes.get(8);
+ assertNotNull(attribute);
+ assertFalse(attribute.isRequired());
+ assertFalse(attribute.isExpert());
+ assertEquals("preferred", attribute.getName());
+ assertNull(attribute.getDefaultValue());
+ assertNull(attribute.getMethodSignature());
+ assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
+ assertEquals("It's a preferred attribute",
attribute.getShortDescription());
+ assertEquals("Preferred attribute", attribute.getDisplayName());
+ assertTrue(attribute.isPreferred());
+
+ attribute = attributes.get(9);
+ assertNotNull(attribute);
+ assertEquals("onchange", attribute.getName());
+
+ List<ClientBehavior> clientBehaviors = attribute.getClientBehaviors();
+ assertNotNull(clientBehaviors);
+ assertEquals(2, clientBehaviors.size());
+
+ ClientBehavior clientBehavior;
+
+ clientBehavior = clientBehaviors.get(0);
+ assertNotNull(clientBehavior);
+ assertEquals("change", clientBehavior.getEvent());
+ assertFalse(clientBehavior.isDefaultEvent());
+
+ clientBehavior = clientBehaviors.get(1);
+ assertNotNull(clientBehavior);
+ assertEquals("valueChange", clientBehavior.getEvent());
+ assertTrue(clientBehavior.isDefaultEvent());
+
+ assertEquals(Boolean.TRUE, interfaceSection.getRendersChildren());
+ }
+
+ @Test
+ public void testImpl() throws Exception {
+ Template template =
+ unmarshal(
+ Template.class,
+ TEMPLATE_PROLOG
+ + TEMPLATE_MIDDLE
+ + "<cdk:call
expression=\"#{cc.clientId}\"/><table
width=\"200\"><tbody><cdk:call
expression=\"#{cc.fooMethod(clientId)}\"/></tbody></table>Header<div
class='bar'>foo</div>"
+ + TEMPLATE_EPILOG);
+
+ CompositeImplementation implementation = template.getImplementation();
+ assertNotNull(implementation);
+ List<Object> children = implementation.getChildren();
+ assertNotNull(children);
+ assertEquals(4, children.size());
+ assertEquals(CdkCallElement.class, children.get(0).getClass());
+ assertEquals(AnyElement.class, children.get(1).getClass());
+ assertEquals(String.class, children.get(2).getClass());
+ }
+
+ @Test
+ public void testInterface() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG
+ +
"<cdk:class>org.richfaces.renderkit.html.TreeRenderer</cdk:class>"
+ +
"<cdk:superclass>org.richfaces.renderkit.TreeRendererBase</cdk:superclass>"
+ +
"<cdk:component-family>org.richfaces.TreeFamily</cdk:component-family>"
+ +
"<cdk:renderer-type>org.richfaces.TreeRenderer</cdk:renderer-type>"
+ + "<cdk:renderkit-id>RF4_XHTML</cdk:renderkit-id>"
+ +
"<cdk:renders-children>false</cdk:renders-children>" +
TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
+
+ CompositeInterface interfaceSection = template.getInterface();
+ assertNotNull(interfaceSection);
+
+
assertEquals(ClassName.parseName("org.richfaces.renderkit.html.TreeRenderer"),
interfaceSection.getJavaClass());
+
assertEquals(ClassName.parseName("org.richfaces.renderkit.TreeRendererBase"),
interfaceSection.getBaseClass());
+ assertEquals(FacesId.parseId("org.richfaces.TreeFamily"),
interfaceSection.getComponentFamily());
+ assertEquals(FacesId.parseId("org.richfaces.TreeRenderer"),
interfaceSection.getRendererType());
+ assertEquals("RF4_XHTML", interfaceSection.getRenderKitId());
+ assertEquals(Boolean.FALSE, interfaceSection.getRendersChildren());
+
+ }
+
+ @Test
+ public void testJstlCoreElements() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE +
"start"
+ + "<c:if test=\"#{someTest}\">if
content</c:if>" + "<c:choose>"
+ + "<c:when test=\"#{anotherTest}\">when
content</c:when>" + "<c:when test=\"#{coolTest}\">"
+ + "<c:if test=\"#{nestedIfTest}\">nested if
content</c:if>" + "</c:when>"
+ + "<c:otherwise>otherwise content</c:otherwise>" +
"</c:choose>"
+ + "<c:forEach items=\"#{someCollection}\"
var=\"iterationVar\">" + "forEach content" +
"</c:forEach>"
+ + "finish" + TEMPLATE_EPILOG);
+
+ CompositeImplementation implementation = template.getImplementation();
+ assertNotNull(implementation);
+
+ List<Object> children = implementation.getChildren();
+ assertNotNull(children);
+ assertEquals(5, children.size());
+ assertEquals("start", children.get(0));
+ assertEquals(CdkIfElement.class, children.get(1).getClass());
+ CdkIfElement ifElement = (CdkIfElement) children.get(1);
+ assertEquals("#{someTest}", ifElement.getTest());
+ List<Object> ifChildren = ifElement.getChildren();
+ assertNotNull(ifChildren);
+ assertEquals(1, ifChildren.size());
+ assertEquals("if content", ifChildren.get(0));
+
+ assertEquals(CdkChooseElement.class, children.get(2).getClass());
+ CdkChooseElement chooseElement = (CdkChooseElement) children.get(2);
+ List<Object> chooseChildren = chooseElement.getChildren();
+ assertNotNull(chooseChildren);
+ assertEquals(3, chooseChildren.size());
+
+ assertEquals(CdkWhenElement.class, chooseChildren.get(0).getClass());
+ CdkWhenElement firstWhen = (CdkWhenElement) chooseChildren.get(0);
+ assertEquals("#{anotherTest}", firstWhen.getTest());
+ List<Object> childrenOfFirstWhen = firstWhen.getChildren();
+ assertNotNull(childrenOfFirstWhen);
+ assertEquals(1, childrenOfFirstWhen.size());
+ assertEquals("when content", childrenOfFirstWhen.get(0));
+
+ assertEquals(CdkWhenElement.class, chooseChildren.get(1).getClass());
+ CdkWhenElement secondWhen = (CdkWhenElement) chooseChildren.get(1);
+ assertEquals("#{coolTest}", secondWhen.getTest());
+
+ List<Object> childrenOfSecondWhen = secondWhen.getChildren();
+ assertNotNull(childrenOfSecondWhen);
+ assertEquals(1, childrenOfSecondWhen.size());
+
+ assertEquals(CdkIfElement.class, childrenOfSecondWhen.get(0).getClass());
+ CdkIfElement nestedIf = (CdkIfElement) childrenOfSecondWhen.get(0);
+ assertEquals("#{nestedIfTest}", nestedIf.getTest());
+ List<Object> childrenOfNestedIf = nestedIf.getChildren();
+ assertNotNull(childrenOfNestedIf);
+ assertEquals(1, childrenOfNestedIf.size());
+ assertEquals("nested if content", childrenOfNestedIf.get(0));
+
+ assertEquals(CdkOtherwiseElement.class, chooseChildren.get(2).getClass());
+ CdkOtherwiseElement otherwiseElement = (CdkOtherwiseElement)
chooseChildren.get(2);
+ List<Object> childrenOfOtherwiseElement = otherwiseElement.getChildren();
+ assertNotNull(childrenOfOtherwiseElement);
+ assertEquals(1, childrenOfOtherwiseElement.size());
+ assertEquals("otherwise content", childrenOfOtherwiseElement.get(0));
+
+ assertEquals(CdkForEachElement.class, children.get(3).getClass());
+ CdkForEachElement forEachElement = (CdkForEachElement) children.get(3);
+ assertEquals("#{someCollection}", forEachElement.getItems());
+ assertEquals("iterationVar", forEachElement.getVar());
+
+ List<Object> forEachChildren = forEachElement.getChildren();
+ assertNotNull(forEachChildren);
+ assertEquals(1, forEachChildren.size());
+ assertEquals("forEach content", forEachChildren.get(0));
+
+ assertEquals("finish", children.get(4));
+ }
+
+ @Test
+ public void testObject() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE
+ + "<cdk:object name=\"rowCount\" type=\"int\"
value=\"#{getRowCount(context)}\" />"
+ + "<cdk:object name=\"bodyExpression\"
type=\"java.lang.String\">"
+ + "\"test expression\" +\n\"second line\""
+ "</cdk:object>" +
+
+ TEMPLATE_EPILOG);
+
+ CompositeImplementation implementation = template.getImplementation();
+ assertNotNull(implementation);
+
+ List<Object> children = implementation.getChildren();
+ assertNotNull(children);
+ assertEquals(2, children.size());
+
+ assertEquals(CdkObjectElement.class, children.get(0).getClass());
+ CdkObjectElement firstObject = (CdkObjectElement) children.get(0);
+ assertNotNull(firstObject);
+ assertEquals("rowCount", firstObject.getName());
+ assertEquals("int", firstObject.getType());
+ assertEquals("#{getRowCount(context)}", firstObject.getValue());
+
+ assertEquals(CdkObjectElement.class, children.get(1).getClass());
+ CdkObjectElement secondObject = (CdkObjectElement) children.get(1);
+ assertNotNull(secondObject);
+ assertEquals("bodyExpression", secondObject.getName());
+ assertEquals("java.lang.String", secondObject.getType());
+ assertEquals("\"test expression\" +\n\"second
line\"", secondObject.getBodyValue());
+ }
+
+ @Test
+ public void testResourceDependencies() throws Exception {
+ Template template =
+ unmarshal(Template.class, TEMPLATE_PROLOG + "<cdk:resource-dependency
name=\"jquery.js\" />"
+ + "<cdk:resource-dependency name=\"richfaces.css\"
library=\"org.richfaces\" />"
+ + "<cdk:resource-dependency name=\"richfaces.js\"
library=\"org.richfaces\" target=\"body\" /> "
+
+ + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
+
+ CompositeInterface interfaceSection = template.getInterface();
+ assertNotNull(interfaceSection);
+
+ assertNull(interfaceSection.getRendersChildren());
+
+ List<ResourceDependency> resourceDependencies =
interfaceSection.getResourceDependencies();
+ assertNotNull(resourceDependencies);
+ assertEquals(3, resourceDependencies.size());
+
+ ResourceDependency resourceDependency;
+
+ resourceDependency = resourceDependencies.get(0);
+ assertNotNull(resourceDependency);
+ assertEquals("jquery.js", resourceDependency.getName());
+ assertNull(resourceDependency.getLibrary());
+ assertEquals("head", resourceDependency.getTarget());
+
+ resourceDependency = resourceDependencies.get(1);
+ assertNotNull(resourceDependency);
+ assertEquals("richfaces.css", resourceDependency.getName());
+ assertEquals("org.richfaces", resourceDependency.getLibrary());
+ assertEquals("head", resourceDependency.getTarget());
+
+ resourceDependency = resourceDependencies.get(2);
+ assertNotNull(resourceDependency);
+ assertEquals("richfaces.js", resourceDependency.getName());
+ assertEquals("org.richfaces", resourceDependency.getLibrary());
+ assertEquals("body", resourceDependency.getTarget());
+ }
+
+ @Test
+ public void testTemplate() throws Exception {
+ Template template = unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE +
TEMPLATE_EPILOG);
+ assertNotNull(template.getInterface());
+ assertNotNull(template.getImplementation());
+ }
+}
Property changes on:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Deleted:
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java
===================================================================
---
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java 2010-06-30
19:46:12 UTC (rev 17691)
+++
root/cdk/branches/RF8755/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateTest.java 2010-06-30
23:15:43 UTC (rev 17692)
@@ -1,400 +0,0 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.templatecompiler.model;
-
-import static org.junit.Assert.*;
-
-import java.util.List;
-
-import org.junit.Test;
-import org.richfaces.cdk.model.ClassName;
-import org.richfaces.cdk.model.FacesId;
-import org.richfaces.cdk.xmlconfig.JaxbTestBase;
-
-/**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public class TemplateTest extends JaxbTestBase {
-
- public static final String TEMPLATE_PROLOG =
- "<cdk:root
xmlns=\"http://www.w3.org/1999/xhtml\"
xmlns:cdk=\"http://richfaces.org/cdk/core\"
xmlns:c=\"http://richfaces.org/cdk/jstl/core\"
xmlns:cc=\"http://richfaces.org/cdk/jsf/composite\"><cc:i...;
- private static final Object DEFAULT_ATTRIBUTE_TYPE = new ClassName(Object.class);
- private static final String TEMPLATE_EPILOG =
"</cc:implementation></cdk:root>";
- private static final String TEMPLATE_MIDDLE =
"</cc:interface><cc:implementation>";
-
- @Test
- public void testAttributes() throws Exception {
- Template template =
- unmarshal(
- Template.class,
- TEMPLATE_PROLOG
- +
"<cdk:renders-children>true</cdk:renders-children>"
- + "<cc:attribute name=\"onclick\" />"
- + "<cc:attribute name=\"mode\"
default=\"ajax\" />"
- + "<cc:attribute name=\"action\"
method-signature=\"void action()\" />"
- + "<cc:attribute name=\"changeListener\"
method-signature=\"void changeListener(ValueChangeEvent)\"
targets=\"changes changes1\" />"
- + "<cc:attribute name=\"disabled\"
type=\"boolean\" />"
- + "<cc:attribute name=\"delay\"
type=\"java.lang.Integer\" />"
- + "<cc:attribute name=\"id\"
required=\"true\" />"
- + "<cc:attribute name=\"experts\"
shortDescription=\"For use by experts\" displayName=\"Expert
attribute\" expert=\"true\" />"
- + "<cc:attribute name=\"preferred\"
shortDescription=\"It's a preferred attribute\" displayName=\"Preferred
attribute\" preferred=\"true\" />"
- + "<cc:attribute name=\"onchange\">" +
"<cc:clientBehavior event=\"change\" />"
- + "<cc:clientBehavior event=\"valueChange\"
default=\"true\" />" + "</cc:attribute>"
- + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
-
- CompositeInterface interfaceSection = template.getInterface();
- assertNotNull(interfaceSection);
-
- List<Attribute> attributes = interfaceSection.getAttributes();
- assertNotNull(attributes);
- assertEquals(10, attributes.size());
-
- Attribute attribute;
-
- attribute = attributes.get(0);
- assertNotNull(attribute);
- assertEquals("onclick", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(1);
- assertNotNull(attribute);
- assertEquals("mode", attribute.getName());
- assertEquals("ajax", attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(2);
- assertNotNull(attribute);
- assertEquals("action", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertEquals("void action()", attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(3);
- assertNotNull(attribute);
- assertEquals("changeListener", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertEquals("void changeListener(ValueChangeEvent)",
attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertEquals("changes changes1", attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(4);
- assertNotNull(attribute);
- assertEquals("disabled", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(ClassName.parseName("boolean"), attribute.getType());
- assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(5);
- assertNotNull(attribute);
- assertEquals("delay", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(ClassName.parseName("java.lang.Integer"),
attribute.getType());
- assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(6);
- assertNotNull(attribute);
- assertEquals("id", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertNull(attribute.getTargets());
- assertTrue(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(7);
- assertNotNull(attribute);
- assertFalse(attribute.isRequired());
- assertEquals("experts", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertNull(attribute.getTargets());
- assertEquals("For use by experts", attribute.getShortDescription());
- assertEquals("Expert attribute", attribute.getDisplayName());
- assertTrue(attribute.isExpert());
- assertFalse(attribute.isPreferred());
-
- attribute = attributes.get(8);
- assertNotNull(attribute);
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertEquals("preferred", attribute.getName());
- assertNull(attribute.getDefaultValue());
- assertNull(attribute.getMethodSignature());
- assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
- assertEquals("It's a preferred attribute",
attribute.getShortDescription());
- assertEquals("Preferred attribute", attribute.getDisplayName());
- assertTrue(attribute.isPreferred());
-
- attribute = attributes.get(9);
- assertNotNull(attribute);
- assertEquals("onchange", attribute.getName());
-
- List<ClientBehavior> clientBehaviors = attribute.getClientBehaviors();
- assertNotNull(clientBehaviors);
- assertEquals(2, clientBehaviors.size());
-
- ClientBehavior clientBehavior;
-
- clientBehavior = clientBehaviors.get(0);
- assertNotNull(clientBehavior);
- assertEquals("change", clientBehavior.getEvent());
- assertFalse(clientBehavior.isDefaultEvent());
-
- clientBehavior = clientBehaviors.get(1);
- assertNotNull(clientBehavior);
- assertEquals("valueChange", clientBehavior.getEvent());
- assertTrue(clientBehavior.isDefaultEvent());
-
- assertEquals(Boolean.TRUE, interfaceSection.getRendersChildren());
- }
-
- @Test
- public void testImpl() throws Exception {
- Template template =
- unmarshal(
- Template.class,
- TEMPLATE_PROLOG
- + TEMPLATE_MIDDLE
- + "<cdk:call
expression=\"#{cc.clientId}\"/><table
width=\"200\"><tbody><cdk:call
expression=\"#{cc.fooMethod(clientId)}\"/></tbody></table>Header<div
class='bar'>foo</div>"
- + TEMPLATE_EPILOG);
-
- CompositeImplementation implementation = template.getImplementation();
- assertNotNull(implementation);
- List<Object> children = implementation.getChildren();
- assertNotNull(children);
- assertEquals(4, children.size());
- assertEquals(CdkCallElement.class, children.get(0).getClass());
- assertEquals(AnyElement.class, children.get(1).getClass());
- assertEquals(String.class, children.get(2).getClass());
- }
-
- @Test
- public void testInterface() throws Exception {
- Template template =
- unmarshal(Template.class, TEMPLATE_PROLOG
- +
"<cdk:class>org.richfaces.renderkit.html.TreeRenderer</cdk:class>"
- +
"<cdk:superclass>org.richfaces.renderkit.TreeRendererBase</cdk:superclass>"
- +
"<cdk:component-family>org.richfaces.TreeFamily</cdk:component-family>"
- +
"<cdk:renderer-type>org.richfaces.TreeRenderer</cdk:renderer-type>"
- + "<cdk:renderkit-id>RF4_XHTML</cdk:renderkit-id>"
- +
"<cdk:renders-children>false</cdk:renders-children>" +
TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
-
- CompositeInterface interfaceSection = template.getInterface();
- assertNotNull(interfaceSection);
-
-
assertEquals(ClassName.parseName("org.richfaces.renderkit.html.TreeRenderer"),
interfaceSection.getJavaClass());
-
assertEquals(ClassName.parseName("org.richfaces.renderkit.TreeRendererBase"),
interfaceSection.getBaseClass());
- assertEquals(FacesId.parseId("org.richfaces.TreeFamily"),
interfaceSection.getComponentFamily());
- assertEquals(FacesId.parseId("org.richfaces.TreeRenderer"),
interfaceSection.getRendererType());
- assertEquals("RF4_XHTML", interfaceSection.getRenderKitId());
- assertEquals(Boolean.FALSE, interfaceSection.getRendersChildren());
-
- }
-
- @Test
- public void testJstlCoreElements() throws Exception {
- Template template =
- unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE +
"start"
- + "<c:if test=\"#{someTest}\">if
content</c:if>" + "<c:choose>"
- + "<c:when test=\"#{anotherTest}\">when
content</c:when>" + "<c:when test=\"#{coolTest}\">"
- + "<c:if test=\"#{nestedIfTest}\">nested if
content</c:if>" + "</c:when>"
- + "<c:otherwise>otherwise content</c:otherwise>" +
"</c:choose>"
- + "<c:forEach items=\"#{someCollection}\"
var=\"iterationVar\">" + "forEach content" +
"</c:forEach>"
- + "finish" + TEMPLATE_EPILOG);
-
- CompositeImplementation implementation = template.getImplementation();
- assertNotNull(implementation);
-
- List<Object> children = implementation.getChildren();
- assertNotNull(children);
- assertEquals(5, children.size());
- assertEquals("start", children.get(0));
- assertEquals(CdkIfElement.class, children.get(1).getClass());
- CdkIfElement ifElement = (CdkIfElement) children.get(1);
- assertEquals("#{someTest}", ifElement.getTest());
- List<Object> ifChildren = ifElement.getChildren();
- assertNotNull(ifChildren);
- assertEquals(1, ifChildren.size());
- assertEquals("if content", ifChildren.get(0));
-
- assertEquals(CdkChooseElement.class, children.get(2).getClass());
- CdkChooseElement chooseElement = (CdkChooseElement) children.get(2);
- List<Object> chooseChildren = chooseElement.getChildren();
- assertNotNull(chooseChildren);
- assertEquals(3, chooseChildren.size());
-
- assertEquals(CdkWhenElement.class, chooseChildren.get(0).getClass());
- CdkWhenElement firstWhen = (CdkWhenElement) chooseChildren.get(0);
- assertEquals("#{anotherTest}", firstWhen.getTest());
- List<Object> childrenOfFirstWhen = firstWhen.getChildren();
- assertNotNull(childrenOfFirstWhen);
- assertEquals(1, childrenOfFirstWhen.size());
- assertEquals("when content", childrenOfFirstWhen.get(0));
-
- assertEquals(CdkWhenElement.class, chooseChildren.get(1).getClass());
- CdkWhenElement secondWhen = (CdkWhenElement) chooseChildren.get(1);
- assertEquals("#{coolTest}", secondWhen.getTest());
-
- List<Object> childrenOfSecondWhen = secondWhen.getChildren();
- assertNotNull(childrenOfSecondWhen);
- assertEquals(1, childrenOfSecondWhen.size());
-
- assertEquals(CdkIfElement.class, childrenOfSecondWhen.get(0).getClass());
- CdkIfElement nestedIf = (CdkIfElement) childrenOfSecondWhen.get(0);
- assertEquals("#{nestedIfTest}", nestedIf.getTest());
- List<Object> childrenOfNestedIf = nestedIf.getChildren();
- assertNotNull(childrenOfNestedIf);
- assertEquals(1, childrenOfNestedIf.size());
- assertEquals("nested if content", childrenOfNestedIf.get(0));
-
- assertEquals(CdkOtherwiseElement.class, chooseChildren.get(2).getClass());
- CdkOtherwiseElement otherwiseElement = (CdkOtherwiseElement)
chooseChildren.get(2);
- List<Object> childrenOfOtherwiseElement = otherwiseElement.getChildren();
- assertNotNull(childrenOfOtherwiseElement);
- assertEquals(1, childrenOfOtherwiseElement.size());
- assertEquals("otherwise content", childrenOfOtherwiseElement.get(0));
-
- assertEquals(CdkForEachElement.class, children.get(3).getClass());
- CdkForEachElement forEachElement = (CdkForEachElement) children.get(3);
- assertEquals("#{someCollection}", forEachElement.getItems());
- assertEquals("iterationVar", forEachElement.getVar());
-
- List<Object> forEachChildren = forEachElement.getChildren();
- assertNotNull(forEachChildren);
- assertEquals(1, forEachChildren.size());
- assertEquals("forEach content", forEachChildren.get(0));
-
- assertEquals("finish", children.get(4));
- }
-
- @Test
- public void testObject() throws Exception {
- Template template =
- unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE
- + "<cdk:object name=\"rowCount\" type=\"int\"
value=\"#{getRowCount(context)}\" />"
- + "<cdk:object name=\"bodyExpression\"
type=\"java.lang.String\">"
- + "\"test expression\" +\n\"second line\""
+ "</cdk:object>" +
-
- TEMPLATE_EPILOG);
-
- CompositeImplementation implementation = template.getImplementation();
- assertNotNull(implementation);
-
- List<Object> children = implementation.getChildren();
- assertNotNull(children);
- assertEquals(2, children.size());
-
- assertEquals(CdkObjectElement.class, children.get(0).getClass());
- CdkObjectElement firstObject = (CdkObjectElement) children.get(0);
- assertNotNull(firstObject);
- assertEquals("rowCount", firstObject.getName());
- assertEquals("int", firstObject.getType());
- assertEquals("#{getRowCount(context)}", firstObject.getValue());
-
- assertEquals(CdkObjectElement.class, children.get(1).getClass());
- CdkObjectElement secondObject = (CdkObjectElement) children.get(1);
- assertNotNull(secondObject);
- assertEquals("bodyExpression", secondObject.getName());
- assertEquals("java.lang.String", secondObject.getType());
- assertEquals("\"test expression\" +\n\"second
line\"", secondObject.getBodyValue());
- }
-
- @Test
- public void testResourceDependencies() throws Exception {
- Template template =
- unmarshal(Template.class, TEMPLATE_PROLOG + "<cdk:resource-dependency
name=\"jquery.js\" />"
- + "<cdk:resource-dependency name=\"richfaces.css\"
library=\"org.richfaces\" />"
- + "<cdk:resource-dependency name=\"richfaces.js\"
library=\"org.richfaces\" target=\"body\" /> "
-
- + TEMPLATE_MIDDLE + TEMPLATE_EPILOG);
-
- CompositeInterface interfaceSection = template.getInterface();
- assertNotNull(interfaceSection);
-
- assertNull(interfaceSection.getRendersChildren());
-
- List<ResourceDependency> resourceDependencies =
interfaceSection.getResourceDependencies();
- assertNotNull(resourceDependencies);
- assertEquals(3, resourceDependencies.size());
-
- ResourceDependency resourceDependency;
-
- resourceDependency = resourceDependencies.get(0);
- assertNotNull(resourceDependency);
- assertEquals("jquery.js", resourceDependency.getName());
- assertNull(resourceDependency.getLibrary());
- assertEquals("head", resourceDependency.getTarget());
-
- resourceDependency = resourceDependencies.get(1);
- assertNotNull(resourceDependency);
- assertEquals("richfaces.css", resourceDependency.getName());
- assertEquals("org.richfaces", resourceDependency.getLibrary());
- assertEquals("head", resourceDependency.getTarget());
-
- resourceDependency = resourceDependencies.get(2);
- assertNotNull(resourceDependency);
- assertEquals("richfaces.js", resourceDependency.getName());
- assertEquals("org.richfaces", resourceDependency.getLibrary());
- assertEquals("body", resourceDependency.getTarget());
- }
-
- @Test
- public void testTemplate() throws Exception {
- Template template = unmarshal(Template.class, TEMPLATE_PROLOG + TEMPLATE_MIDDLE +
TEMPLATE_EPILOG);
- assertNotNull(template.getInterface());
- assertNotNull(template.getImplementation());
- }
-}