Author: alexsmirnov
Date: 2009-11-10 20:28:26 -0500 (Tue, 10 Nov 2009)
New Revision: 15861
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/templates/RendererClassGenerator.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/templates/RendererTemplateParser.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Renderer.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java
Log:
Switch to new template parser.
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/templates/RendererClassGenerator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/templates/RendererClassGenerator.java 2009-11-10
18:04:00 UTC (rev 15860)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/templates/RendererClassGenerator.java 2009-11-11
01:28:26 UTC (rev 15861)
@@ -70,6 +70,7 @@
public void render(ComponentLibrary library) throws CdkException {
for (RenderKit renderKit : library.getRenderKits()) {
for (Renderer renderer : renderKit.getRenderers()) {
+ /* TODO - make model compatible with old parser ?
JavaClass javaClass = renderer.getTemplate();
String fullName = javaClass.getFullName();
File outFile =
context.createOutputFile(StandardOutputs.RENDERER_CLASSES,
@@ -82,6 +83,7 @@
throw new CdkException(e);
}
}
+ */
}
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/templates/RendererTemplateParser.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/templates/RendererTemplateParser.java 2009-11-10
18:04:00 UTC (rev 15860)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/builder/templates/RendererTemplateParser.java 2009-11-11
01:28:26 UTC (rev 15861)
@@ -58,9 +58,9 @@
RootElementConsumer template = TemplateReader.parseTemplate(new
FileInputStream(file));
RenderKit renderKit =
library.findOrCreateRenderKit(template.getRenderKitId());
Renderer renderer =
renderKit.findOrCreateRenderer(template.getRendererType());
+ // TODO - make model compatible with that parser ?
+// renderer.setTemplate(template.getJavaClass());
- renderer.setTemplate(template.getJavaClass());
-
String componentType = template.getComponentType();
if (null != componentType) {
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java 2009-11-10
18:04:00 UTC (rev 15860)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/LibraryBuilder.java 2009-11-11
01:28:26 UTC (rev 15861)
@@ -27,8 +27,8 @@
import com.google.common.collect.ImmutableMap;
-import org.richfaces.builder.templates.RendererClassGenerator;
-import org.richfaces.builder.templates.RendererTemplateParser;
+import org.richfaces.cdk.templatecompiler.RendererClassGenerator;
+import org.richfaces.cdk.templatecompiler.RendererTemplateParser;
import org.richfaces.cdk.CdkContext.SourceType;
import org.richfaces.cdk.CdkWriter.OutputType;
import org.richfaces.cdk.apt.AptBuilder;
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Renderer.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Renderer.java 2009-11-10
18:04:00 UTC (rev 15860)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Renderer.java 2009-11-11
01:28:26 UTC (rev 15861)
@@ -27,6 +27,7 @@
import org.richfaces.builder.model.JavaClass;
import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.templatecompiler.model.Template;
/**
* <p class="changed_added_4_0"></p>
@@ -37,7 +38,7 @@
public class Renderer extends ModelElementBase implements ModelElement<Renderer,
Renderer.Type> {
private String family;
private ClassDescription rendererClass;
- private JavaClass template;
+ private Template template;
private Type type;
public Renderer() {}
@@ -71,7 +72,7 @@
* @return the template
*/
@Merge
- public JavaClass getTemplate() {
+ public Template getTemplate() {
return template;
}
@@ -79,7 +80,7 @@
* <p class="changed_added_4_0"></p>
* @param template the template to set
*/
- public void setTemplate(JavaClass template) {
+ public void setTemplate(Template template) {
this.template = template;
}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2009-11-11
01:28:26 UTC (rev 15861)
@@ -0,0 +1,93 @@
+/*
+ * $Id: RendererClassGenerator.java 15789 2009-11-01 16:17:29Z Alex.Kolonitsky $
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+
+
+package org.richfaces.cdk.templatecompiler;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+
+import org.richfaces.builder.model.JavaClass;
+import org.richfaces.builder.render.JavaClassRenderer;
+import org.richfaces.cdk.CdkContext;
+import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.StandardOutputs;
+import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.model.Renderer;
+import org.richfaces.cdk.model.RenderKit;
+import org.richfaces.cdk.templatecompiler.model.Template;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class RendererClassGenerator implements CdkWriter {
+ private CdkContext context;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.richfaces.cdk.CdkWriter#init(org.richfaces.cdk.CdkContext)
+ */
+ @Override
+ public void init(CdkContext context) throws CdkException {
+ this.context = context;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.richfaces.cdk.CdkWriter#render(org.richfaces.cdk.model.ComponentLibrary
+ * )
+ */
+ @Override
+ public void render(ComponentLibrary library) throws CdkException {
+ for (RenderKit renderKit : library.getRenderKits()) {
+ for (Renderer renderer : renderKit.getRenderers()) {
+ Template template = renderer.getTemplate();
+ // TODO - put real parameters.
+ RendererClassVisitor visitor = new
RendererClassVisitor(template.getInterface());
+ template.getImplementation().visit(visitor);
+ JavaClass javaClass = visitor.getRendererClass();
+ String fullName = javaClass.getFullName();
+ File outFile =
context.createOutputFile(StandardOutputs.RENDERER_CLASSES,
+ fullName.replace('.', '/') +
".java", library.lastModified());
+
+ if (null != outFile) {
+ try {
+ new JavaClassRenderer().render(javaClass, new
PrintWriter(outFile));
+ } catch (FileNotFoundException e) {
+ throw new CdkException(e);
+ }
+ }
+ }
+ }
+ }
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2009-11-10
18:04:00 UTC (rev 15860)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2009-11-11
01:28:26 UTC (rev 15861)
@@ -56,7 +56,7 @@
Pattern.compile("^component\\.attributes\\[(?:'|\")?([^'\"]+)(?:'|\")?\\]$");
private static final Map<String, Set<String>> ELEMENTS_ATTRIBUTES;
private final LinkedList<MethodBodyStatement> statements =
Lists.newLinkedList();
- private final JavaClass renderer;
+ private final JavaClass rendererClass;
private final CompositeInterface compositeInterface;
protected MethodBodyStatement currentStatement;
@@ -84,8 +84,15 @@
public RendererClassVisitor(CompositeInterface compositeInterface) {
this.compositeInterface = compositeInterface;
- renderer = new JavaClass();
+ rendererClass = new JavaClass();
}
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @return the rendererClass
+ */
+ public JavaClass getRendererClass() {
+ return this.rendererClass;
+ }
/* (non-Javadoc)
* @see
org.richfaces.cdk.templatecompiler.model.TemplateVisitor#endElement(org.richfaces.cdk.templatecompiler.model.AnyElement)
*/
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java 2009-11-10
18:04:00 UTC (rev 15860)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java 2009-11-11
01:28:26 UTC (rev 15861)
@@ -30,6 +30,7 @@
import org.richfaces.cdk.ModelBuilder;
import org.richfaces.cdk.StandardSources;
import org.richfaces.cdk.model.*;
+import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
import org.richfaces.cdk.templatecompiler.model.Template;
import org.richfaces.cdk.xmlconfig.JAXBBinding;
@@ -59,6 +60,25 @@
for (File file : getContext().getSources(StandardSources.RENDERER_TEMPLATES)) {
try {
Template template = parseTemplate(file);
+ CompositeInterface compositeInterface = template.getInterface();
+ // TODO - infer values ?
+ RenderKit renderKit =
library.findOrCreateRenderKit(compositeInterface.getRenderKitId());
+ Renderer renderer =
renderKit.findOrCreateRenderer(compositeInterface.getRendererType());
+ String componentType = compositeInterface.getComponentType();
+
+ if (null != componentType) {
+ Component component = library.findOrCreateComponent(componentType);
+
+ component.getRenderers().add(renderer);
+ }
+
+ String family = compositeInterface.getFamily();
+
+ if (null != family) {
+ renderer.setFamily(family);
+ }
+ renderer.setRendererClass(new
ClassDescription(compositeInterface.getJavaClass()));
+ renderer.setTemplate(template);
// } catch (FileNotFoundException e) {
// throw new CdkException(e);
// } catch (XMLStreamException e) {
Show replies by date