Author: Alex.Kolonitsky
Date: 2010-01-20 09:52:59 -0500 (Wed, 20 Jan 2010)
New Revision: 16344
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/converter.ftl
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ConverterClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedConverterClass.java
Removed:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ComponentTemplateModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTemplateModel.java
Modified:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/StandardOutputs.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/LibraryModelWrapper.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ConverterModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ModelElementBase.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Visitable.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/component.ftl
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/validator.ftl
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ValidatorClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedClass.java
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/UIBar.java
Log:
https://jira.jboss.org/jira/browse/RF-8232
Tags support - converter class generator
Modified:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java
===================================================================
---
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -46,4 +46,5 @@
public Class<?> forClass() default Object.class;
+ public String converterClass() default "";
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/StandardOutputs.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/StandardOutputs.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/StandardOutputs.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -35,6 +35,7 @@
public enum StandardOutputs implements OutputType {
COMPONENT_CLASSES(StandardOutputFolders.JAVA_CLASSES),
VALIDATOR_CLASSES(StandardOutputFolders.JAVA_CLASSES),
+ CONVERTER_CLASSES(StandardOutputFolders.JAVA_CLASSES),
RENDERER_CLASSES(StandardOutputFolders.JAVA_CLASSES),
EVENT_LISTENER_CLASSES(StandardOutputFolders.JAVA_CLASSES),
EVENT_SOURCE_CLASSES(StandardOutputFolders.JAVA_CLASSES),
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -28,6 +28,7 @@
import javax.annotation.processing.SupportedAnnotationTypes;
import javax.lang.model.element.TypeElement;
+import javax.lang.model.element.Modifier;
import javax.lang.model.type.MirroredTypeException;
import java.lang.annotation.Annotation;
@@ -50,9 +51,9 @@
} catch (MirroredTypeException e) {
converterModel.setConverterForClass(new
ClassDescription(e.getTypeMirror().toString()));
}
- converterModel.setConverterClass(new
ClassDescription(element.getQualifiedName().toString()));
setDescription(element, converterModel);
+ setClassNames(element, converterModel, converter);
getLibrary().getConverters().add(converterModel);
}
@@ -62,4 +63,23 @@
return JsfConverter.class;
}
+ // TODO same method in the ValidatorProcessor move their in one class
+ public static void setClassNames(TypeElement componentElement, ConverterModel
converterModel, JsfConverter converter) {
+ String baseClass = componentElement.getQualifiedName().toString();
+ if (converter == null) {
+ converterModel.setClassNames(baseClass, null);
+ return;
+ }
+
+ String validatorClass = converter.converterClass();
+ if (validatorClass == null || validatorClass.isEmpty() ||
baseClass.equals(validatorClass)) {
+ if (componentElement.getModifiers().contains(Modifier.ABSTRACT)) {
+ throw new IllegalStateException("You can't use an abstract class
as a validator. Please set the validatorClass or remove the 'abstract'
modifier.");
+ } else {
+ converterModel.setClassNames(baseClass, null);
+ }
+ } else {
+ converterModel.setClassNames(validatorClass, baseClass);
+ }
+ }
}
Deleted:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ComponentTemplateModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ComponentTemplateModel.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ComponentTemplateModel.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -1,136 +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.freemarker;
-
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import org.richfaces.cdk.model.ComponentModel;
-import org.richfaces.cdk.model.EventName;
-import org.richfaces.cdk.model.Property;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-
-import freemarker.ext.beans.BeanModel;
-import freemarker.ext.beans.BeansWrapper;
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateModelException;
-
-/**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @author asmirnov(a)exadel.com
- *
- */
-public class ComponentTemplateModel extends BeanModel implements TemplateModel {
- private final ComponentModel component;
- private Set<EventName> eventNames;
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @param object
- * @param wrapper
- */
- public ComponentTemplateModel(ComponentModel object, BeansWrapper wrapper) {
- super(object, wrapper);
- component = object;
- }
-
- @Override
- public TemplateModel get(String key) throws TemplateModelException {
- if ("attributes".equals(key)) {
- return attributes();
- } else if ("generatedAttributes".equals(key)) {
- return generatedAttributes();
- } else if ("eventNames".equals(key)) {
- return eventNames();
- } else if ("defaultEvent".equals(key)) {
- return defaultEvent();
- }
-
- return super.get(key);
- }
-
- private TemplateModel eventNames() throws TemplateModelException {
- Set<EventName> eventNames = getEventNames();
-
- return wrapper.wrap(eventNames);
- }
-
- private TemplateModel defaultEvent() throws TemplateModelException {
- Set<EventName> names = getEventNames();
-
- try {
- EventName defaultEvent = Iterables.find(names, new
Predicate<EventName>() {
- @Override
- public boolean apply(EventName event) {
- return event.isDefaultEvent();
- }
- });
-
- return wrapper.wrap(defaultEvent);
- } catch (NoSuchElementException e) {
- return wrapper.wrap(null);
- }
- }
-
- private Set<EventName> getEventNames() {
- if (null == eventNames) {
- eventNames = Sets.newHashSet();
-
- for (Property property : component.getAttributes().values()) {
- eventNames.addAll(property.getEventNames());
- }
- }
-
- return eventNames;
- }
-
- private TemplateModel generatedAttributes() throws TemplateModelException {
- ArrayList<PropertyModel> models = new ArrayList<PropertyModel>();
- for (Map.Entry<String, Property> entry :
component.getAttributes().entrySet()) {
- if(entry.getValue().isGenerate()){
- models.add(new PropertyModel(entry.getKey(), entry.getValue(),
wrapper));
- }
- }
- return wrapper.wrap(models);
- }
- private TemplateModel attributes() throws TemplateModelException {
- ArrayList<PropertyModel> models = new ArrayList<PropertyModel>();
- for (Map.Entry<String, Property> entry :
component.getAttributes().entrySet()) {
- models.add(new PropertyModel(entry.getKey(), entry.getValue(), wrapper));
- }
- return wrapper.wrap(models);
- }
-
-}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/LibraryModelWrapper.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/LibraryModelWrapper.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/LibraryModelWrapper.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -25,13 +25,11 @@
package org.richfaces.cdk.freemarker;
-import org.richfaces.cdk.model.ComponentModel;
-import org.richfaces.cdk.model.ValidatorModel;
-
import freemarker.ext.beans.BeansWrapper;
import freemarker.template.ObjectWrapper;
import freemarker.template.TemplateModel;
import freemarker.template.TemplateModelException;
+import org.richfaces.cdk.model.ModelElementBase;
/**
* <p class="changed_added_4_0"></p>
@@ -50,18 +48,11 @@
@Override
public TemplateModel wrap(Object obj) throws TemplateModelException {
-
// TODO wrap specified model classes.
- TemplateModel templateModel;
-
- if (obj instanceof ComponentModel) {
- templateModel = new ComponentTemplateModel((ComponentModel) obj, this);
- } else if (obj instanceof ValidatorModel) {
- templateModel = new ValidatorTemplateModel((ValidatorModel) obj, this);
- } else {
- templateModel = super.wrap(obj);
+ if (obj instanceof ModelElementBase) {
+ return new ModelElementBaseTemplateModel((ModelElementBase) obj, this);
}
- return templateModel;
+ return super.wrap(obj);
}
}
Copied:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java
(from rev 16329,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ComponentTemplateModel.java)
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -0,0 +1,135 @@
+/*
+ * $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.freemarker;
+
+import com.google.common.base.Predicate;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Sets;
+import freemarker.ext.beans.BeanModel;
+import freemarker.ext.beans.BeansWrapper;
+import freemarker.template.TemplateModel;
+import freemarker.template.TemplateModelException;
+import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.ModelElementBase;
+import org.richfaces.cdk.model.Property;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Map;
+import java.util.NoSuchElementException;
+import java.util.Set;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ *
+ */
+public class ModelElementBaseTemplateModel extends BeanModel implements TemplateModel {
+ private final ModelElementBase model;
+ private Set<EventName> eventNames;
+
+ /**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @param object
+ * @param wrapper
+ */
+ public ModelElementBaseTemplateModel(ModelElementBase object, BeansWrapper wrapper)
{
+ super(object, wrapper);
+ model = object;
+ }
+
+ @Override
+ public TemplateModel get(String key) throws TemplateModelException {
+ if ("attributes".equals(key)) {
+ return attributes();
+ } else if ("generatedAttributes".equals(key)) {
+ return generatedAttributes();
+ } else if ("eventNames".equals(key)) {
+ return eventNames();
+ } else if ("defaultEvent".equals(key)) {
+ return defaultEvent();
+ }
+
+ return super.get(key);
+ }
+
+ private TemplateModel eventNames() throws TemplateModelException {
+ return wrapper.wrap(getEventNames());
+ }
+
+ private TemplateModel defaultEvent() throws TemplateModelException {
+ Set<EventName> names = getEventNames();
+
+ try {
+ EventName defaultEvent = Iterables.find(names, new
Predicate<EventName>() {
+ @Override
+ public boolean apply(EventName event) {
+ return event.isDefaultEvent();
+ }
+ });
+
+ return wrapper.wrap(defaultEvent);
+ } catch (NoSuchElementException e) {
+ return wrapper.wrap(null);
+ }
+ }
+
+ private Set<EventName> getEventNames() {
+ if (null == eventNames) {
+ eventNames = Sets.newHashSet();
+
+ for (Property property : model.getAttributes().values()) {
+ eventNames.addAll(property.getEventNames());
+ }
+ }
+
+ return eventNames;
+ }
+
+ private TemplateModel generatedAttributes() throws TemplateModelException {
+ Map<String, Property> attributes = model.getAttributes();
+ Collection<PropertyModel> models = new
ArrayList<PropertyModel>(attributes.size());
+ for (Map.Entry<String, Property> entry : attributes.entrySet()) {
+ if (entry.getValue().isGenerate()) {
+ models.add(new PropertyModel(entry.getKey(), entry.getValue(),
wrapper));
+ }
+ }
+ return wrapper.wrap(models);
+ }
+ private TemplateModel attributes() throws TemplateModelException {
+ Map<String, Property> attributes = model.getAttributes();
+ Collection<PropertyModel> models = new
ArrayList<PropertyModel>(attributes.size());
+ for (Map.Entry<String, Property> entry : attributes.entrySet()) {
+ models.add(new PropertyModel(entry.getKey(), entry.getValue(), wrapper));
+ }
+ return wrapper.wrap(models);
+ }
+
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTemplateModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTemplateModel.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTemplateModel.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -1,130 +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.freemarker;
-
-import freemarker.ext.beans.BeanModel;
-import freemarker.ext.beans.BeansWrapper;
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateModelException;
-import org.richfaces.cdk.model.EventName;
-import org.richfaces.cdk.model.Property;
-import org.richfaces.cdk.model.ValidatorModel;
-
-import java.util.Set;
-import java.util.NoSuchElementException;
-import java.util.ArrayList;
-import java.util.Map;
-import java.util.List;
-
-import com.google.common.collect.Iterables;
-import com.google.common.collect.Sets;
-import com.google.common.base.Predicate;
-
-/**
- * @author akolonitsky
- * @since Jan 18, 2010
- */
-public class ValidatorTemplateModel extends BeanModel implements TemplateModel {
- private final ValidatorModel component;
- private Set<EventName> eventNames;
-
- /**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @param object
- * @param wrapper
- */
- public ValidatorTemplateModel(ValidatorModel object, BeansWrapper wrapper) {
- super(object, wrapper);
- component = object;
- }
-
- @Override
- public TemplateModel get(String key) throws TemplateModelException {
- if ("attributes".equals(key)) {
- return attributes();
- } else if ("generatedAttributes".equals(key)) {
- return generatedAttributes();
- } else if ("eventNames".equals(key)) {
- return eventNames();
- } else if ("defaultEvent".equals(key)) {
- return defaultEvent();
- }
-
- return super.get(key);
- }
-
- private TemplateModel eventNames() throws TemplateModelException {
- Set<EventName> eventNames = getEventNames();
-
- return wrapper.wrap(eventNames);
- }
-
- private TemplateModel defaultEvent() throws TemplateModelException {
- Set<EventName> names = getEventNames();
-
- try {
- EventName defaultEvent = Iterables.find(names, new
Predicate<EventName>() {
- @Override
- public boolean apply(EventName event) {
- return event.isDefaultEvent();
- }
- });
-
- return wrapper.wrap(defaultEvent);
- } catch (NoSuchElementException e) {
- return wrapper.wrap(null);
- }
- }
-
- private Set<EventName> getEventNames() {
- if (null == eventNames) {
- eventNames = Sets.newHashSet();
-
- for (Property property : component.getAttributes().values()) {
- eventNames.addAll(property.getEventNames());
- }
- }
-
- return eventNames;
- }
-
- private TemplateModel generatedAttributes() throws TemplateModelException {
- List<PropertyModel> models = new
ArrayList<PropertyModel>(component.getAttributes().size());
- for (Map.Entry<String, Property> entry :
component.getAttributes().entrySet()) {
- if(entry.getValue().isGenerate()){
- models.add(new PropertyModel(entry.getKey(), entry.getValue(),
wrapper));
- }
- }
- return wrapper.wrap(models);
- }
- private TemplateModel attributes() throws TemplateModelException {
- List<PropertyModel> models = new
ArrayList<PropertyModel>(component.getAttributes().size());
- for (Map.Entry<String, Property> entry :
component.getAttributes().entrySet()) {
- models.add(new PropertyModel(entry.getKey(), entry.getValue(), wrapper));
- }
- return wrapper.wrap(models);
- }
-
-}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ConverterClassGenerator.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -0,0 +1,69 @@
+/*
+ * 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;
+
+import org.richfaces.cdk.CdkContext;
+import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.CdkWriter;
+import org.richfaces.cdk.StandardOutputs;
+import org.richfaces.cdk.freemarker.FreeMarkerRenderer;
+import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.model.ConverterModel;
+import org.richfaces.cdk.model.Visitable;
+
+import java.io.File;
+
+/**
+ * @author akolonitsky
+ * @since Jan 20, 2010
+ */
+public class ConverterClassGenerator extends FreeMarkerRenderer<ConverterModel,
ComponentLibrary> implements CdkWriter {
+ @Override
+ public void init(CdkContext context) {
+ super.init(context);
+ }
+
+ @Override
+ protected boolean isMyComponent(Visitable visitable) {
+ if (visitable instanceof ConverterModel) {
+ return ((ConverterModel) visitable).isGenerate();
+ }
+
+ return false;
+ }
+
+ @Override
+ protected String getOutputFile(ConverterModel converter) throws CdkException {
+ return converter.getConverterClass().getName().replace('.',
File.separatorChar) + ".java";
+ }
+
+ @Override
+ protected String getTemplateName() {
+ return "converter.ftl";
+ }
+
+ @Override
+ protected CdkContext.OutputType getOutputType() {
+ return StandardOutputs.CONVERTER_CLASSES;
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -36,13 +36,6 @@
/**
* <p class="changed_added_4_0">
- * Component attributes
- * </p>
- */
- private final ModelMap<String,Property> attributes =
ModelMap.<String,Property>create();
-
- /**
- * <p class="changed_added_4_0">
* Renderer for the final component. This is bidirectional many to many
* relation.
* </p>
@@ -87,7 +80,7 @@
@Override
public void merge(ComponentModel otherComponent) {
//merge facets, renderers, events ...
- attributes.putAll(otherComponent.getAttributes());
+ getAttributes().putAll(otherComponent.getAttributes());
facets.putAll(otherComponent.getFacets());
ComponentLibrary.merge(events, otherComponent.getEvents());
ComponentLibrary.merge(renderers, otherComponent.getRenderers());
@@ -202,27 +195,6 @@
}
/**
- * <p class="changed_added_4_0">
- * Represents JSF component attributes and properties.
- * </p>
- *
- * @return the attributes
- */
- public Map<String,Property> getAttributes() {
- return attributes;
- }
-
- public Property addAttribute(String attributeName) {
- Property attribute = attributes.get(attributeName);
- if(null == attribute){
- attribute = new Property();
- attributes.put(attributeName, attribute);
- }
-
- return attribute;
- }
-
- /**
* <p class="changed_added_4_0"></p>
* @return the facets
*/
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ConverterModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ConverterModel.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ConverterModel.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -25,8 +25,6 @@
import org.richfaces.cdk.CdkException;
-import java.util.Map;
-
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
@@ -36,14 +34,16 @@
private static final long serialVersionUID = -6238591637703737886L;
+ private boolean generate = false;
+
private String converterId;
private ClassDescription converterClass;
+ private ClassDescription baseClass;
+
private ClassDescription converterForClass;
- private final ModelMap<String,Property> attributes =
ModelMap.<String,Property>create();
-
public ConverterModel() {
}
@@ -52,6 +52,14 @@
this.converterClass = converterClass;
}
+ public boolean isGenerate() {
+ return generate;
+ }
+
+ public void setGenerate(boolean generate) {
+ this.generate = generate;
+ }
+
public String getConverterId() {
return converterId;
}
@@ -78,26 +86,23 @@
this.converterClass = converterClass;
}
+ public ClassDescription getBaseClass() {
+ return baseClass;
+ }
- /**
- * <p class="changed_added_4_0">
- * Represents JSF component attributes and properties.
- * </p>
- *
- * @return the attributes
- */
- public Map<String,Property> getAttributes() {
- return attributes;
+ public void setBaseClass(ClassDescription baseClass) {
+ this.baseClass = baseClass;
}
- public Property addAttribute(String attributeName) {
- Property attribute = attributes.get(attributeName);
- if (null == attribute) {
- attribute = new Property();
- attributes.put(attributeName, attribute);
+ public void setClassNames(String converterClass, String baseClass) {
+ this.converterClass = new ClassDescription(converterClass);
+
+ if (baseClass != null) {
+ this.baseClass = new ClassDescription(baseClass);
+ this.generate = true;
+ } else {
+ this.generate = false;
}
-
- return attribute;
}
@Override
@@ -109,7 +114,7 @@
public void merge(ConverterModel other) {
ComponentLibrary.merge(this, other);
- attributes.putAll(other.getAttributes());
+ getAttributes().putAll(other.getAttributes());
}
@Override
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ModelElementBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ModelElementBase.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ModelElementBase.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -1,5 +1,7 @@
package org.richfaces.cdk.model;
+import java.util.Map;
+
/**
* <p class="changed_added_4_0">Base class for the most JSF components
taht have description
* attributes and support extensions in faces-config.</p>
@@ -30,6 +32,8 @@
*/
private Icon icon;
+ private final ModelMap<String,Property> attributes =
ModelMap.<String,Property>create();
+
public ModelElementBase() {
super();
}
@@ -59,6 +63,28 @@
}
/**
+ * <p class="changed_added_4_0">
+ * Represents JSF component attributes and properties.
+ * </p>
+ *
+ * @return the attributes
+ */
+ public Map<String,Property> getAttributes() {
+ return attributes;
+ }
+
+ public Property addAttribute(String attributeName) {
+ Property attribute = attributes.get(attributeName);
+ if (null == attribute) {
+ attribute = new Property();
+ attributes.put(attributeName, attribute);
+ }
+
+ return attribute;
+ }
+
+
+ /**
* <p class="changed_added_4_0"></p>
*
* @return the extension
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -25,8 +25,6 @@
import org.richfaces.cdk.CdkException;
-import java.util.Map;
-
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
@@ -43,8 +41,6 @@
private ClassDescription baseClass;
- private final ModelMap<String,Property> attributes =
ModelMap.<String,Property>create();
-
public ValidatorModel() {
}
@@ -97,23 +93,6 @@
}
}
- public Map<String,Property> getAttributes() {
- return attributes;
- }
-
- public Property addAttribute(String attributeName) {
- Property attribute;
-
- attribute = attributes.get(attributeName);
- if(null == attribute){
- attribute = new Property();
- attributes.put(attributeName, attribute);
- }
-
- return attribute;
- }
-
-
@Override
public <R, P> R accept(LibraryVisitor<R, P> visitor, P param) throws
CdkException {
return visitor.visit(this, param);
@@ -123,7 +102,7 @@
public void merge(ValidatorModel other) {
ComponentLibrary.merge(this, other);
- attributes.putAll(other.getAttributes());
+ getAttributes().putAll(other.getAttributes());
}
@Override
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Visitable.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Visitable.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Visitable.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -11,6 +11,9 @@
* @param <P>
* @param visitor
* @param param
+ *
+ * @throws org.richfaces.cdk.CdkException
+ *
* @return
*/
public <R, P> R accept(LibraryVisitor<R, P> visitor, P param) throws
CdkException;
Modified:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/component.ftl
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/component.ftl 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/component.ftl 2010-01-20
14:52:59 UTC (rev 16344)
@@ -4,8 +4,6 @@
</#list>
</#macro>
/*
- * $Id$
- *
* License Agreement.
*
* Rich Faces - Natural Ajax for Java Server Faces (JSF)
Added:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/converter.ftl
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/converter.ftl
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/converter.ftl 2010-01-20
14:52:59 UTC (rev 16344)
@@ -0,0 +1,136 @@
+/*
+ * 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 ${converterClass.package};
+
+import javax.annotation.Generated;
+import javax.faces.component.StateHelper;
+import javax.faces.component.PartialStateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+/**
+ * ${description?if_exists}
+ **/
+@Generated({"RichFaces CDK", "4.0.0-SNAPSHOT"})
+public class ${converterClass.simpleName} extends ${baseClass} implements Converter,
PartialStateHolder {
+
+ public Object getAsObject(FacesContext context, UIComponent component, String value)
{
+ return null;
+ }
+
+ public String getAsString(FacesContext context, UIComponent component, Object value)
{
+ return null;
+ }
+
+ protected enum Properties {
+ <#list generatedAttributes as attribute>${attribute.name}<#if
attribute_has_next>${",\n "}</#if></#list>
+ }
+
+ <#list generatedAttributes as attribute>
+ /**
+ * ${attribute.description?if_exists}
+ **/
+ public ${attribute.type} ${attribute.getterName}(){
+ return (${attribute.type})getStateHelper().eval(Properties.${attribute.name});
+ }
+
+ /**
+ * Setter for ${attribute.name}
+ **/
+ public void ${attribute.setterName}(${attribute.type} ${attribute.name}){
+ getStateHelper().put(Properties.${attribute.name},${attribute.name});
+ }
+ </#list>
+
+
+
+ protected StateHelper getStateHelper() {
+ return getStateHelper(true);
+ }
+
+ protected StateHelper getStateHelper(boolean create) {
+ return null;
+ }
+
+ // ----------------------------------------------------- StateHolder Methods
+ @Override
+ public Object saveState(FacesContext context) {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+ if (!initialStateMarked()) {
+ Object values[] = new Object[1];
+ <#list generatedAttributes as attribute>
+ values[${attribute_index}] = this.${attribute.getterName}();
+ </#list>
+
+ return values;
+ }
+ return null;
+ }
+
+ @Override
+ public void restoreState(FacesContext context, Object state) {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+ if (state == null) {
+ return;
+ }
+
+ Object values[] = (Object[]) state;
+ <#list generatedAttributes as attribute>
+ ${attribute.setterName}((${attribute.type}) values[${attribute_index}]);
+ </#list>
+ }
+
+ private boolean transientValue = false;
+
+ @Override
+ public boolean isTransient() {
+ return this.transientValue;
+ }
+
+ @Override
+ public void setTransient(boolean transientValue) {
+ this.transientValue = transientValue;
+ }
+
+
+ private boolean initialState;
+
+ @Override
+ public void markInitialState() {
+ initialState = true;
+ }
+
+ @Override
+ public boolean initialStateMarked() {
+ return initialState;
+ }
+
+ @Override
+ public void clearInitialState() {
+ initialState = false;
+ }
+}
\ No newline at end of file
Modified:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/validator.ftl
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/validator.ftl 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/validator.ftl 2010-01-20
14:52:59 UTC (rev 16344)
@@ -1,6 +1,4 @@
/*
- * $Id: component.ftl 16229 2009-12-29 21:36:27Z alexsmirnov $
- *
* 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
Added:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -0,0 +1,107 @@
+/*
+ * 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;
+
+import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+import org.junit.Assert;
+import org.richfaces.cdk.CdkContext;
+import org.richfaces.cdk.CdkTestBase;
+import org.richfaces.cdk.StandardSources;
+import org.richfaces.cdk.model.ClassDescription;
+import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.ModelElementBase;
+import org.richfaces.cdk.model.Property;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.LineNumberReader;
+import java.io.Reader;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+/**
+ * @author akolonitsky
+ * @since Jan 20, 2010
+ */
+public abstract class AbstractClassGeneratorTest extends CdkTestBase {
+ protected CdkContext createMockContext() throws Exception {
+ CdkContext cdkContext = createMock(CdkContext.class);
+
+
expect(cdkContext.getSourceFolders(StandardSources.JAVA_SOURCES)).andStubReturn(testSourceDirectory);
+ expect(cdkContext.getOutputFolder((org.richfaces.cdk.CdkContext.OutputType)
anyObject())).andStubReturn(null);
+ expect(cdkContext.getLoader()).andStubReturn(createClassLoader());
+ replay(cdkContext);
+
+ return cdkContext;
+ }
+
+
+ protected static Property addAttribute(ModelElementBase model, String attributeName,
Class<?> type, boolean generate) {
+ Property attribute = model.addAttribute(attributeName);
+ attribute.setType(new ClassDescription(type));
+ attribute.setGenerate(generate);
+ return attribute;
+ }
+
+ protected static EventName getEvent(String name, boolean defaultEvent) {
+ EventName event = new EventName();
+ event.setName(name);
+ event.setDefaultEvent(defaultEvent);
+ return event;
+ }
+
+ protected void compare(StringWriter writer, String fileName) throws IOException {
+ InputStream expectedFacesConfigFile =
this.getClass().getResourceAsStream(fileName);
+ Assert.assertNotNull("File ("+fileName+") with expected result
wasn't found.", expectedFacesConfigFile);
+
+ compareTextFiles(
+ new StringReader(writer.toString()),
+ new InputStreamReader(expectedFacesConfigFile));
+ }
+
+ protected static void compareTextFiles(Reader reference, Reader output) throws
IOException {
+ LineNumberReader ref = new LineNumberReader(reference);
+ LineNumberReader out = new LineNumberReader(output);
+ String refLine = "", outLine = "";
+ while (refLine != null || outLine != null) {
+ if (refLine == null) {
+ Assert.fail("Output text is longer than reference text");
+ }
+ if (outLine == null) {
+ Assert.fail("Output text is shorter than reference text");
+ }
+
+ refLine = ref.readLine();
+ outLine = out.readLine();
+
+ if (refLine != null && outLine != null &&
!refLine.trim().equals(outLine.trim())) {
+ Assert.fail("Difference found on line " + ref.getLineNumber()
+ + ".\nReference text is: " + refLine + "\nOutput text
is: " + outLine);
+ }
+ }
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -29,36 +29,25 @@
import java.io.StringWriter;
import java.io.Writer;
-import java.io.Reader;
-import java.io.LineNumberReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringReader;
-import java.io.InputStreamReader;
import java.util.Set;
import javax.faces.component.UIOutput;
import org.junit.Test;
-import org.junit.Assert;
import org.richfaces.cdk.CdkContext;
import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.CdkTestBase;
-import org.richfaces.cdk.StandardSources;
import org.richfaces.cdk.model.ClassDescription;
import org.richfaces.cdk.model.ComponentModel;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventName;
import org.richfaces.cdk.model.Property;
-import org.xml.sax.SAXException;
-import org.custommonkey.xmlunit.Diff;
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
*
*/
-public class ComponentClassGeneratorTest extends CdkTestBase {
+public class ComponentClassGeneratorTest extends AbstractClassGeneratorTest {
/**
* Test method for {@link
org.richfaces.cdk.generate.java.ComponentClassGenerator#getOutputFile(org.richfaces.cdk.model.ComponentModel)}.
@@ -95,14 +84,9 @@
attribute.setType(new ClassDescription(String.class));
Set<EventName> eventNames = attribute.getEventNames();
- EventName event = new EventName();
+ eventNames.add(getEvent("id", false));
+ eventNames.add(getEvent("action", true));
- event.setName("id");
- eventNames.add(event);
- event = new EventName();
- event.setName("action");
- event.setDefaultEvent(true);
- eventNames.add(event);
attribute.setGenerate(false);
generator.visit(component, library);
System.out.println(output);
@@ -110,46 +94,4 @@
compare(output, "UIBar.java");
}
-
- private CdkContext createMockContext() throws Exception {
- CdkContext cdkContext = createMock(CdkContext.class);
-
-
expect(cdkContext.getSourceFolders(StandardSources.JAVA_SOURCES)).andStubReturn(testSourceDirectory);
- expect(cdkContext.getOutputFolder((org.richfaces.cdk.CdkContext.OutputType)
anyObject())).andStubReturn(null);
- expect(cdkContext.getLoader()).andStubReturn(createClassLoader());
- replay(cdkContext);
-
- return cdkContext;
- }
-
- private void compare(StringWriter writer, String fileName) throws IOException {
- InputStream expectedFacesConfigFile =
this.getClass().getResourceAsStream(fileName);
- Assert.assertNotNull("File ("+fileName+") with expected result
wasn't found.", expectedFacesConfigFile);
-
- compareTextFiles(
- new StringReader(writer.toString()),
- new InputStreamReader(expectedFacesConfigFile));
- }
-
- public static void compareTextFiles(Reader reference, Reader output) throws
IOException {
- LineNumberReader ref = new LineNumberReader(reference);
- LineNumberReader out = new LineNumberReader(output);
- String refLine = "", outLine = "";
- while (refLine != null || outLine != null) {
- if (refLine == null) {
- Assert.fail("Output text is longer than reference text");
- }
- if (outLine == null) {
- Assert.fail("Output text is shorter than reference text");
- }
-
- refLine = ref.readLine();
- outLine = out.readLine();
-
- if (refLine != null && outLine != null &&
!refLine.trim().equals(outLine.trim())) {
- Assert.fail("Difference found on line " + ref.getLineNumber()
- + ".\nReference text is: " + refLine + "\nOutput text
is: " + outLine);
- }
- }
- }
}
Added:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ConverterClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ConverterClassGeneratorTest.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ConverterClassGeneratorTest.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -0,0 +1,86 @@
+/*
+ * 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;
+
+import static org.easymock.EasyMock.verify;
+import org.junit.Test;
+import org.richfaces.cdk.CdkContext;
+import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.model.ClassDescription;
+import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.model.ConverterModel;
+import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.Property;
+import org.richfaces.cdk.model.ValidatorModel;
+
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Set;
+
+/**
+ * @author akolonitsky
+ * @since Jan 20, 2010
+ */
+public class ConverterClassGeneratorTest extends AbstractClassGeneratorTest {
+
+ /**
+ * Test method for {@link
org.richfaces.cdk.generate.java.ComponentClassGenerator#getOutputFile(org.richfaces.cdk.model.ComponentModel)}.
+ * @throws Exception
+ */
+ @Test
+ public void testGetOutputFileValidator() throws Exception {
+ final StringWriter output = new StringWriter();
+ ConverterClassGenerator generator = new ConverterClassGenerator() {
+ @Override
+ protected Writer getOutput(ConverterModel c) throws CdkException {
+ return output;
+ }
+ };
+ CdkContext mockContext = createMockContext();
+
+ generator.init(mockContext);
+
+ ConverterModel converter = new ConverterModel();
+ converter.setConverterId("foo.bar");
+
converter.setClassNames("org.richfaces.cdk.generate.java.GeneratedConverterClass",
"Object");
+
+ addAttribute(converter, "testValue", Object.class, true);
+ // TODO test with primitiv type 'boolean'
+ addAttribute(converter, "testFlag", Boolean.class, true);
+ Property attribute = addAttribute(converter, "id", String.class,
false);
+
+ Set<EventName> eventNames = attribute.getEventNames();
+ eventNames.add(getEvent("id", false));
+ eventNames.add(getEvent("action", true));
+
+ ComponentLibrary library = new ComponentLibrary();
+ library.getConverters().add(converter);
+ generator.visit(converter, library);
+
+ System.out.println(output);
+
+ verify(mockContext);
+
+ // TODO - check generated file.
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ValidatorClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ValidatorClassGeneratorTest.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ValidatorClassGeneratorTest.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -22,7 +22,6 @@
package org.richfaces.cdk.generate.java;
-import org.richfaces.cdk.CdkTestBase;
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkContext;
import org.richfaces.cdk.StandardSources;
@@ -38,7 +37,6 @@
import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.replay;
-import javax.faces.component.UIOutput;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Set;
@@ -47,7 +45,7 @@
* @author akolonitsky
* @since Jan 15, 2010
*/
-public class ValidatorClassGeneratorTest extends CdkTestBase {
+public class ValidatorClassGeneratorTest extends AbstractClassGeneratorTest {
/**
* Test method for {@link
org.richfaces.cdk.generate.java.ComponentClassGenerator#getOutputFile(org.richfaces.cdk.model.ComponentModel)}.
@@ -90,28 +88,4 @@
// TODO - check generated file.
}
- private EventName getEvent(String name, boolean defaultEvent) {
- EventName event = new EventName();
- event.setName(name);
- event.setDefaultEvent(defaultEvent);
- return event;
- }
-
- private Property addAttribute(ValidatorModel validator, String attributeName,
Class<?> type, boolean generate) {
- Property attribute = validator.addAttribute(attributeName);
- attribute.setType(new ClassDescription(type));
- attribute.setGenerate(generate);
- return attribute;
- }
-
- private CdkContext createMockContext() throws Exception {
- CdkContext cdkContext = createMock(CdkContext.class);
-
-
expect(cdkContext.getSourceFolders(StandardSources.JAVA_SOURCES)).andStubReturn(testSourceDirectory);
- expect(cdkContext.getOutputFolder((org.richfaces.cdk.CdkContext.OutputType)
anyObject())).andStubReturn(null);
- expect(cdkContext.getLoader()).andStubReturn(createClassLoader());
- replay(cdkContext);
-
- return cdkContext;
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedClass.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedClass.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedClass.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -1,6 +1,4 @@
/*
- * $Id: component.ftl 16229 2009-12-29 21:36:27Z alexsmirnov $
- *
* 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
Added:
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedConverterClass.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedConverterClass.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedConverterClass.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -0,0 +1,145 @@
+/*
+ * 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;
+
+import javax.annotation.Generated;
+import javax.faces.component.StateHelper;
+import javax.faces.component.PartialStateHolder;
+import javax.faces.component.UIComponent;
+import javax.faces.context.FacesContext;
+import javax.faces.convert.Converter;
+
+/**
+ *
+ **/
+@Generated({"RichFaces CDK", "4.0.0-SNAPSHOT"})
+public class GeneratedConverterClass extends Object implements Converter,
PartialStateHolder {
+ public Object getAsObject(FacesContext context, UIComponent component, String value)
{
+ return null;
+ }
+
+ public String getAsString(FacesContext context, UIComponent component, Object value)
{
+ return null;
+ }
+
+ protected enum Properties {
+ testValue,
+ testFlag
+ }
+
+ /**
+ *
+ **/
+ public java.lang.Object getTestValue(){
+ return (java.lang.Object)getStateHelper().eval(Properties.testValue);
+ }
+
+ /**
+ * Setter for testValue
+ **/
+ public void setTestValue(java.lang.Object testValue){
+ getStateHelper().put(Properties.testValue,testValue);
+ }
+ /**
+ *
+ **/
+ public java.lang.Boolean isTestFlag() {
+ return (java.lang.Boolean)getStateHelper().eval(Properties.testFlag);
+ }
+
+ /**
+ * Setter for testFlag
+ **/
+ public void setTestFlag(java.lang.Boolean testFlag){
+ getStateHelper().put(Properties.testFlag,testFlag);
+ }
+
+
+
+ protected StateHelper getStateHelper() {
+ return getStateHelper(true);
+ }
+
+ protected StateHelper getStateHelper(boolean create) {
+ return null;
+ }
+
+ // ----------------------------------------------------- StateHolder Methods
+ @Override
+ public Object saveState(FacesContext context) {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+ if (!initialStateMarked()) {
+ Object values[] = new Object[1];
+ values[0] = this.getTestValue();
+ values[1] = this.isTestFlag();
+
+ return values;
+ }
+ return null;
+ }
+
+ @Override
+ public void restoreState(FacesContext context, Object state) {
+ if (context == null) {
+ throw new NullPointerException();
+ }
+ if (state == null) {
+ return;
+ }
+
+ Object values[] = (Object[]) state;
+ setTestValue((java.lang.Object) values[0]);
+ setTestFlag((java.lang.Boolean) values[1]);
+ }
+
+ private boolean transientValue = false;
+
+ @Override
+ public boolean isTransient() {
+ return this.transientValue;
+ }
+
+ @Override
+ public void setTransient(boolean transientValue) {
+ this.transientValue = transientValue;
+ }
+
+
+ private boolean initialState;
+
+ @Override
+ public void markInitialState() {
+ initialState = true;
+ }
+
+ @Override
+ public boolean initialStateMarked() {
+ return initialState;
+ }
+
+ @Override
+ public void clearInitialState() {
+ initialState = false;
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/UIBar.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/UIBar.java 2010-01-20
14:39:07 UTC (rev 16343)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/UIBar.java 2010-01-20
14:52:59 UTC (rev 16344)
@@ -1,6 +1,4 @@
/*
- * $Id: component.ftl 16229 2009-12-29 21:36:27Z alexsmirnov $
- *
* License Agreement.
*
* Rich Faces - Natural Ajax for Java Server Faces (JSF)