Author: Alex.Kolonitsky
Date: 2010-01-20 05:36:29 -0500 (Wed, 20 Jan 2010)
New Revision: 16339
Added:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfBehavior.java
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/JsfValidator.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
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/ValidatorClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedClass.java
Removed:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Behavior.java
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Converter.java
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Validator.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkWriter.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/DummyGenerator.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/BehaviorProcessor.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/apt/ValidatorProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.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/ValidatorModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.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/taglib/validator.ftl
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ValidatorProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/freemarker/ValidatorTaglibGeneratorTest.xml
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/test/component/MyConverter.java
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/test/component/MyValidator.java
Log:
https://jira.jboss.org/jira/browse/RF-8232
Tags support
- validator class generator
- rename annotations
- remove render(ComponentLibrary library) method
Deleted:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Behavior.java
===================================================================
---
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Behavior.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Behavior.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -1,55 +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.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @author asmirnov(a)exadel.com
- */
-(a)Retention(RetentionPolicy.CLASS)
-(a)Target(ElementType.TYPE)
-@Inherited
-public @interface Behavior {
-
- public static final String NAME =
"org.richfaces.cdk.annotations.Behavior";
-
- /**
- * <p class="changed_added_4_0">
- * behavior-id with which instances of implementation class can be created b JSF
Application implementation. If this
- * value an empty, behavior-id will be inferred from class name.
- * </p>
- *
- * @return converter type.
- */
- public String value();
-
-}
Deleted:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Converter.java
===================================================================
---
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Converter.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Converter.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -1,49 +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.annotations;
-
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * <p class="changed_added_4_0">
- * </p>
- *
- * @author asmirnov(a)exadel.com
- */
-(a)Retention(RetentionPolicy.CLASS)
-(a)Target(ElementType.TYPE)
-@Inherited
-public @interface Converter {
-
- public static final String NAME =
"org.richfaces.cdk.annotations.Converter";
-
- public String id() default "";
-
- public Class<?> forClass() default Object.class;
-
-}
Copied:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfBehavior.java
(from rev 16329,
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Behavior.java)
===================================================================
---
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfBehavior.java
(rev 0)
+++
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfBehavior.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -0,0 +1,55 @@
+/*
+ * $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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ */
+(a)Retention(RetentionPolicy.CLASS)
+(a)Target(ElementType.TYPE)
+@Inherited
+public @interface JsfBehavior {
+
+ public static final String NAME =
"org.richfaces.cdk.annotations.JsfBehavior";
+
+ /**
+ * <p class="changed_added_4_0">
+ * behavior-id with which instances of implementation class can be created b JSF
Application implementation. If this
+ * value an empty, behavior-id will be inferred from class name.
+ * </p>
+ *
+ * @return converter type.
+ */
+ public String value();
+
+}
Property changes on:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfBehavior.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Copied:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java
(from rev 16329,
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Converter.java)
===================================================================
---
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java
(rev 0)
+++
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -0,0 +1,49 @@
+/*
+ * $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.annotations;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * <p class="changed_added_4_0">
+ * </p>
+ *
+ * @author asmirnov(a)exadel.com
+ */
+(a)Retention(RetentionPolicy.CLASS)
+(a)Target(ElementType.TYPE)
+@Inherited
+public @interface JsfConverter {
+
+ public static final String NAME =
"org.richfaces.cdk.annotations.JsfConverter";
+
+ public String id() default "";
+
+ public Class<?> forClass() default Object.class;
+
+}
Property changes on:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfConverter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Copied:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfValidator.java
(from rev 16329,
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Validator.java)
===================================================================
---
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfValidator.java
(rev 0)
+++
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/JsfValidator.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -0,0 +1,23 @@
+package org.richfaces.cdk.annotations;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Inherited;
+
+/**
+ * @author akolonitsky
+ * @since Jan 13, 2010
+ */
+(a)Retention(RetentionPolicy.CLASS)
+(a)Target(ElementType.TYPE)
+@Inherited
+public @interface JsfValidator {
+
+ public static final String NAME =
"org.richfaces.cdk.annotations.JsfValidator";
+
+ public String id() default "";
+
+ public String validatorClass() default "";
+}
Deleted:
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Validator.java
===================================================================
---
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Validator.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/annotations/src/main/java/org/richfaces/cdk/annotations/Validator.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -1,21 +0,0 @@
-package org.richfaces.cdk.annotations;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Inherited;
-
-/**
- * @author akolonitsky
- * @since Jan 13, 2010
- */
-(a)Retention(RetentionPolicy.CLASS)
-(a)Target(ElementType.TYPE)
-@Inherited
-public @interface Validator {
-
- public static final String NAME =
"org.richfaces.cdk.annotations.Validator";
-
- public String id() default "";
-}
Modified: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkWriter.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkWriter.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkWriter.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -25,18 +25,12 @@
package org.richfaces.cdk;
-import org.richfaces.cdk.model.ComponentLibrary;
-
/**
* <p class="changed_added_4_0"></p>
* @author asmirnov(a)exadel.com
*
*/
public interface CdkWriter extends CdkWorker {
- /**
- * @deprecated Use {@link #render()} instead
- */
- public void render(ComponentLibrary library) throws CdkException;
public void render() throws CdkException;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/DummyGenerator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/DummyGenerator.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/DummyGenerator.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -25,8 +25,6 @@
package org.richfaces.cdk;
-import org.richfaces.cdk.model.ComponentLibrary;
-
/**
* <p class="changed_added_4_0">This is dummy generator for not yet
implemented output types</p>
* @author asmirnov(a)exadel.com
@@ -48,19 +46,7 @@
* (non-Javadoc)
* @see org.richfaces.cdk.CdkWriter#render(org.richfaces.cdk.model.ComponentLibrary)
*/
- /**
- * @deprecated Use {@link #render()} instead
- */
@Override
- public void render(ComponentLibrary library) throws CdkException {
- render();
- }
-
- /*
- * (non-Javadoc)
- * @see org.richfaces.cdk.CdkWriter#render(org.richfaces.cdk.model.ComponentLibrary)
- */
- @Override
public void render() throws CdkException {
// Do nothing
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
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/StandardOutputs.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -34,6 +34,7 @@
*/
public enum StandardOutputs implements OutputType {
COMPONENT_CLASSES(StandardOutputFolders.JAVA_CLASSES),
+ VALIDATOR_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/BehaviorProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/BehaviorProcessor.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/BehaviorProcessor.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -28,7 +28,7 @@
import javax.lang.model.element.TypeElement;
import org.richfaces.cdk.CdkProcessingException;
-import org.richfaces.cdk.annotations.Behavior;
+import org.richfaces.cdk.annotations.JsfBehavior;
/**
* <p class="changed_added_4_0"></p>
@@ -48,7 +48,7 @@
@Override
public Class<? extends Annotation> getProcessedAnnotation() {
- return Behavior.class;
+ return JsfBehavior.class;
}
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
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ConverterProcessor.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -22,7 +22,7 @@
package org.richfaces.cdk.apt;
import org.richfaces.cdk.CdkProcessingException;
-import org.richfaces.cdk.annotations.Converter;
+import org.richfaces.cdk.annotations.JsfConverter;
import org.richfaces.cdk.model.ClassDescription;
import org.richfaces.cdk.model.ConverterModel;
@@ -35,12 +35,12 @@
* @author akolonitsky
* @since Jan 4, 2010
*/
-(a)SupportedAnnotationTypes({"javax.faces.component.FacesComponent",
Converter.NAME})
+(a)SupportedAnnotationTypes({"javax.faces.component.FacesComponent",
JsfConverter.NAME})
public class ConverterProcessor extends ProcessorBase implements CdkAnnotationProcessor
{
@Override
public void process(TypeElement element) throws CdkProcessingException {
- Converter converter = element.getAnnotation(Converter.class);
+ JsfConverter converter = element.getAnnotation(JsfConverter.class);
ConverterModel converterModel = new ConverterModel();
converterModel.setConverterId(converter.id());
@@ -59,7 +59,7 @@
@Override
public Class<? extends Annotation> getProcessedAnnotation() {
- return Converter.class;
+ return JsfConverter.class;
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ValidatorProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ValidatorProcessor.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ValidatorProcessor.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -22,7 +22,7 @@
package org.richfaces.cdk.apt;
import org.richfaces.cdk.CdkProcessingException;
-import org.richfaces.cdk.annotations.Validator;
+import org.richfaces.cdk.annotations.JsfValidator;
import org.richfaces.cdk.model.ClassDescription;
import org.richfaces.cdk.model.ValidatorModel;
@@ -35,18 +35,15 @@
* @author akolonitsky
* @since Jan 13, 2010
*/
-(a)SupportedAnnotationTypes({"javax.faces.component.FacesComponent",
Validator.NAME})
+(a)SupportedAnnotationTypes({"javax.faces.component.FacesComponent",
JsfValidator.NAME})
public class ValidatorProcessor extends ProcessorBase implements CdkAnnotationProcessor
{
@Override
public void process(TypeElement element) throws CdkProcessingException {
- Validator validator = element.getAnnotation(Validator.class);
+ JsfValidator validator = element.getAnnotation(JsfValidator.class);
ValidatorModel validatorModel = new ValidatorModel(validator.id(), new
ClassDescription(element.getQualifiedName().toString()));
- if (element.getModifiers().contains(Modifier.ABSTRACT)) {
- validatorModel.setGenerate(true);
- }
-
+ setClassNames(element, validatorModel, validator);
setDescription(element, validatorModel);
getLibrary().getValidators().add(validatorModel);
@@ -54,6 +51,25 @@
@Override
public Class<? extends Annotation> getProcessedAnnotation() {
- return Validator.class;
+ return JsfValidator.class;
}
+
+ public static void setClassNames(TypeElement componentElement, ValidatorModel
validatorModel, JsfValidator validator) {
+ String baseClass = componentElement.getQualifiedName().toString();
+ if (validator == null) {
+ validatorModel.setClassNames(baseClass, null);
+ return;
+ }
+
+ String validatorClass = validator.validatorClass();
+ 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 {
+ validatorModel.setClassNames(baseClass, null);
+ }
+ } else {
+ validatorModel.setClassNames(validatorClass, baseClass);
+ }
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/FreeMarkerRenderer.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -25,23 +25,21 @@
package org.richfaces.cdk.freemarker;
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.Writer;
-
+import freemarker.template.Configuration;
+import freemarker.template.Template;
+import freemarker.template.TemplateException;
import org.richfaces.cdk.CdkContext;
+import org.richfaces.cdk.CdkContext.OutputType;
import org.richfaces.cdk.CdkException;
import org.richfaces.cdk.CdkWriter;
-import org.richfaces.cdk.CdkContext.OutputType;
-import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.LibraryVisitor;
import org.richfaces.cdk.model.Trackable;
import org.richfaces.cdk.model.Visitable;
-import freemarker.template.Configuration;
-import freemarker.template.Template;
-import freemarker.template.TemplateException;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.Writer;
/**
* <p class="changed_added_4_0">Base class for all output file buildes
that use FreeMarker as template engine.</p>
@@ -65,15 +63,7 @@
}
}
- /**
- * @deprecated Use {@link #render()} instead
- */
@Override
- public void render(ComponentLibrary library) throws CdkException {
- library.accept(this, getVisitorParameter());
- }
-
- @Override
public void render() throws CdkException {
context.getLibrary().accept(this, getVisitorParameter());
}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/java/ValidatorClassGenerator.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -0,0 +1,71 @@
+/*
+ * 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.ValidatorModel;
+import org.richfaces.cdk.model.Visitable;
+
+import java.io.File;
+
+/**
+ * @author akolonitsky
+ * @since Jan 15, 2010
+ */
+public class ValidatorClassGenerator extends FreeMarkerRenderer<ValidatorModel,
ComponentLibrary> implements CdkWriter {
+ @Override
+ public void init(CdkContext context) {
+ super.init(context);
+ }
+
+ @Override
+ protected boolean isMyComponent(Visitable visitable) {
+ if (visitable instanceof ValidatorModel) {
+ ValidatorModel validator = (ValidatorModel) visitable;
+
+ return validator.isGenerate();
+ }
+
+ return false;
+ }
+
+ @Override
+ protected String getOutputFile(ValidatorModel validator) throws CdkException {
+ return validator.getValidatorClass().getName().replace('.',
File.separatorChar) + ".java";
+ }
+
+ @Override
+ protected String getTemplateName() {
+ return "validator.ftl";
+ }
+
+ @Override
+ protected CdkContext.OutputType getOutputType() {
+ return StandardOutputs.VALIDATOR_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
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -86,8 +86,6 @@
@Override
public void merge(ComponentModel otherComponent) {
- ComponentLibrary.merge(renderers, otherComponent.getRenderers());
-
//merge facets, renderers, events ...
attributes.putAll(otherComponent.getAttributes());
facets.putAll(otherComponent.getFacets());
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
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -41,6 +41,8 @@
private ClassDescription validatorClass;
+ private ClassDescription baseClass;
+
private final ModelMap<String,Property> attributes =
ModelMap.<String,Property>create();
public ValidatorModel() {
@@ -76,6 +78,25 @@
this.validatorClass = validatorClass;
}
+ public ClassDescription getBaseClass() {
+ return baseClass;
+ }
+
+ public void setBaseClass(ClassDescription baseClass) {
+ this.baseClass = baseClass;
+ }
+
+ public void setClassNames(String validatorClass, String baseClass) {
+ this.validatorClass = new ClassDescription(validatorClass);
+
+ if (baseClass != null) {
+ this.baseClass = new ClassDescription(baseClass);
+ this.generate = true;
+ } else {
+ this.generate = false;
+ }
+ }
+
public Map<String,Property> getAttributes() {
return attributes;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -66,22 +66,7 @@
* org.richfaces.cdk.CdkWriter#render(org.richfaces.cdk.model.ComponentLibrary
* )
*/
- /**
- * @deprecated Use {@link #render()} instead
- */
@Override
- public void render(ComponentLibrary library) throws CdkException {
- render();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.richfaces.cdk.CdkWriter#render(org.richfaces.cdk.model.ComponentLibrary
- * )
- */
- @Override
public void render() throws CdkException {
ComponentLibrary library = context.getLibrary();
for (RenderKitModel renderKit : library.getRenderKits().values()) {
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FacesConfigGenerator.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -70,22 +70,7 @@
* org.richfaces.cdk.CdkWriter#render(org.richfaces.cdk.model.ComponentLibrary
* )
*/
- /**
- * @deprecated Use {@link #render()} instead
- */
@Override
- public void render(ComponentLibrary library) throws CdkException {
- render();
- }
-
- /*
- * (non-Javadoc)
- *
- * @see
- * org.richfaces.cdk.CdkWriter#render(org.richfaces.cdk.model.ComponentLibrary
- * )
- */
- @Override
public void render() throws CdkException {
ComponentLibrary library = context.getLibrary();
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
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/component.ftl 2010-01-20
10:36:29 UTC (rev 16339)
@@ -1,6 +1,6 @@
<#macro concat seq delimiter=",">
<#list seq as item>
- <#nested item/><#if item_has_next>${delimiter}</#if>
+ <#nested item/><#if item_has_next>${delimiter}</#if>
</#list>
</#macro>
/*
@@ -42,23 +42,23 @@
import javax.el.ValueExpression;
/**
- * ${description?if_exists}
+ * ${description?if_exists}
**/
@Generated({"RichFaces CDK", "4.0.0-SNAPSHOT"})
public class ${componentClass.simpleName} extends ${baseClass} <#if (eventNames?size
> 0)>implements ClientBehaviorHolder</#if> {
public static final String COMPONENT_TYPE="${type}";
-
+
<#if family?exists>
public static final String COMPONENT_FAMILY="${family}";
-
+
@Override
public String getFamily() {
return (COMPONENT_FAMILY);
}
</#if>
-
+
<#if (eventNames?size > 0)>
private static final Collection<String> EVENT_NAMES =
Collections.unmodifiableCollection(Arrays.asList(
<@concat seq=eventNames ; event>"${event.name}"</@concat>
@@ -73,7 +73,6 @@
</#if>
protected enum Properties {
<@concat seq=generatedAttributes ;
attribute>${attribute.name}</@concat>
- ;
}
<#list generatedAttributes as attribute>
Modified:
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/taglib/validator.ftl
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/taglib/validator.ftl 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/taglib/validator.ftl 2010-01-20
10:36:29 UTC (rev 16339)
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
-<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.x...
version="2.0">
+<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0">
<tag>
+ <tag-name>${validatorClass}</tag-name>
<validator>
<validator-id>${validatorId}</validator-id>
<handler-class>${validatorClass}</handler-class>
@@ -13,7 +16,6 @@
</#if>
<name>${attribute.name}</name>
<type>${attribute.type}</type>
- <required>${attribute.required}</required>
</attribute>
</#list>
</tag>
Added:
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
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/validator.ftl 2010-01-20
10:36:29 UTC (rev 16339)
@@ -0,0 +1,137 @@
+/*
+ * $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
+ * 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 ${validatorClass.package};
+
+import javax.annotation.Generated;
+import javax.faces.component.StateHelper;
+import javax.faces.component.UIComponent;
+import javax.faces.component.PartialStateHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+/**
+ * ${description?if_exists}
+ **/
+@Generated({"RichFaces CDK", "4.0.0-SNAPSHOT"})
+public class ${validatorClass.simpleName} extends ${baseClass} implements Validator,
PartialStateHolder {
+
+ @Override
+ public void validate(FacesContext context, UIComponent component, Object value)
throws ValidatorException {
+
+ }
+
+ 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/test/java/org/richfaces/cdk/apt/ValidatorProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ValidatorProcessorTest.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ValidatorProcessorTest.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -21,12 +21,21 @@
package org.richfaces.cdk.apt;
+import org.easymock.EasyMock;
+import org.junit.Assert;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import org.junit.Test;
+import org.richfaces.cdk.annotations.JsfValidator;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ValidatorModel;
+import javax.lang.model.element.Modifier;
+import javax.lang.model.element.Name;
+import javax.lang.model.element.TypeElement;
import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
/**
* @author akolonitsky
@@ -49,4 +58,126 @@
}
}
}
+
+ @Test
+ public void testSetNames() {
+ ValidatorModel model;
+
+ // @JsfValidator public class BaseClass { ...
+ model = getValidatorModelForSetNames(true, null, "BaseClass", false);
+ check("BaseClass", null, false, model);
+
+ // @JsfValidator(validatorClass = "") public class BaseClass { ...
+ model = getValidatorModelForSetNames(true, "", "BaseClass",
false);
+ check("BaseClass", null, false, model);
+
+ // @JsfValidator(validatorClass = BaseClass) public class BaseClass { ...
+ model = getValidatorModelForSetNames(true, "BaseClass",
"BaseClass", false);
+ check("BaseClass", null, false, model);
+
+ // @JsfValidator(validatorClass = GeneratedClass) public class BaseClass { ...
+ model = getValidatorModelForSetNames(true, "GeneratedClass",
"BaseClass", false);
+ check("GeneratedClass", "BaseClass", true, model);
+
+ ///////////////////////////////// ABSTRACT
///////////////////////////////////////
+ // @JsfValidator public abstract class BaseClass { ...
+ checkAbstractWithException(null);
+
+ // @JsfValidator(validatorClass = "") public abstract class BaseClass {
...
+ checkAbstractWithException("");
+
+ // @JsfValidator(validatorClass = BaseClass) public abstract class BaseClass {
...
+ checkAbstractWithException("BaseClass");
+
+ // @JsfValidator(validatorClass = GeneratedClass) public abstract class BaseClass
{ ...
+ model = getValidatorModelForSetNames(true, "GeneratedClass",
"BaseClass", true);
+ check("GeneratedClass", "BaseClass", true, model);
+ }
+
+ private void checkAbstractWithException(String validatorClass) {
+ try {
+ getValidatorModelForSetNames(true, validatorClass, "BaseClass",
true);
+ Assert.fail("Abstract class can't be a validator.");
+ } catch (IllegalStateException e) {
+ // Do nothing.
+ }
+ }
+
+ private void check(String validatorClass, String baseClass, boolean generate,
ValidatorModel model) {
+ if (baseClass != null) {
+ assertEquals(model.getBaseClass().toString(), baseClass);
+ } else {
+ assertNull(model.getBaseClass());
+ }
+
+ if (validatorClass != null) {
+ assertEquals(model.getValidatorClass().toString(), validatorClass);
+ } else {
+ assertNull(model.getValidatorClass());
+ }
+
+ assertEquals(generate, model.isGenerate());
+ }
+
+ private ValidatorModel getValidatorModelForSetNames(boolean isAnnotationDefined,
+ String validatorClass,
+ final String baseClass,
+ boolean isAbstractPresent) {
+ Name name = new MyName(baseClass);
+
+ TypeElement element = EasyMock.createMock(TypeElement.class);
+ EasyMock.expect(element.getQualifiedName()).andReturn(name);
+
+ Set<Modifier> set = new HashSet<Modifier>(1);
+ if (isAbstractPresent) {
+ set.add(Modifier.ABSTRACT);
+ }
+ EasyMock.expect(element.getModifiers()).andReturn(set);
+ EasyMock.replay(element);
+
+ ValidatorModel validatorModel = new ValidatorModel();
+ JsfValidator validator = null;
+ if (isAnnotationDefined) {
+ validator = EasyMock.createMock(JsfValidator.class);
+ EasyMock.expect(validator.validatorClass()).andReturn(validatorClass);
+ EasyMock.replay(validator);
+ }
+
+ EasyMock.verify();
+ ValidatorProcessor.setClassNames(element, validatorModel, validator);
+ return validatorModel;
+ }
+
+ private static class MyName implements Name {
+ private final String toString;
+
+ MyName(String toString) {
+ this.toString = toString;
+ }
+
+ @Override
+ public int length() {
+ return 0;
+ }
+
+ @Override
+ public char charAt(int index) {
+ return 0;
+ }
+
+ @Override
+ public CharSequence subSequence(int start, int end) {
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ return toString;
+ }
+
+ @Override
+ public boolean contentEquals(CharSequence cs) {
+ return false;
+ }
+ }
}
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
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -105,7 +105,7 @@
eventNames.add(event);
attribute.setGenerate(false);
generator.visit(component, library);
-// System.out.println(output);
+ System.out.println(output);
verify(mockContext);
compare(output, "UIBar.java");
Added:
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
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ValidatorClassGeneratorTest.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -0,0 +1,117 @@
+/*
+ * 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.CdkTestBase;
+import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.CdkContext;
+import org.richfaces.cdk.StandardSources;
+import org.richfaces.cdk.model.ComponentLibrary;
+import org.richfaces.cdk.model.ClassDescription;
+import org.richfaces.cdk.model.Property;
+import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.ValidatorModel;
+import org.junit.Test;
+import static org.easymock.EasyMock.verify;
+import static org.easymock.EasyMock.createMock;
+import static org.easymock.EasyMock.expect;
+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;
+
+/**
+ * @author akolonitsky
+ * @since Jan 15, 2010
+ */
+public class ValidatorClassGeneratorTest extends CdkTestBase {
+
+ /**
+ * 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();
+ ValidatorClassGenerator generator = new ValidatorClassGenerator() {
+ @Override
+ protected Writer getOutput(ValidatorModel c) throws CdkException {
+ return output;
+ }
+ };
+ CdkContext mockContext = createMockContext();
+
+ generator.init(mockContext);
+
+ ValidatorModel validator = new ValidatorModel();
+ validator.setValidatorId("foo.bar");
+
validator.setClassNames("org.richfaces.cdk.generate.java.GeneratedClass",
"Object");
+
+ addAttribute(validator, "testValue", Object.class, true);
+ // TODO test with primitiv type 'boolean'
+ addAttribute(validator, "testFlag", Boolean.class, true);
+ Property attribute = addAttribute(validator, "id", String.class,
false);
+
+ Set<EventName> eventNames = attribute.getEventNames();
+ eventNames.add(getEvent("id", false));
+ eventNames.add(getEvent("action", true));
+
+ ComponentLibrary library = new ComponentLibrary();
+ library.getValidators().add(validator);
+ generator.visit(validator, library);
+
+ System.out.println(output);
+
+ verify(mockContext);
+
+ // 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/freemarker/ValidatorTaglibGeneratorTest.xml
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/freemarker/ValidatorTaglibGeneratorTest.xml 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/freemarker/ValidatorTaglibGeneratorTest.xml 2010-01-20
10:36:29 UTC (rev 16339)
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="UTF-8"
standalone="yes"?>
-<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.x...
version="2.0">
+<facelet-taglib
xmlns="http://java.sun.com/xml/ns/javaee"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd"
version="2.0">
<tag>
+ <tag-name>javax.faces.component.UIOutput</tag-name>
<validator>
<validator-id>foo.bar</validator-id>
<handler-class>javax.faces.component.UIOutput</handler-class>
@@ -9,12 +12,10 @@
<attribute>
<name>testValue</name>
<type>java.lang.Object</type>
- <required>false</required>
</attribute>
<attribute>
<name>testFlag</name>
<type>boolean</type>
- <required>false</required>
</attribute>
</tag>
</facelet-taglib>
Added:
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
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/GeneratedClass.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -0,0 +1,147 @@
+/*
+ * $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
+ * 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.UIComponent;
+import javax.faces.component.PartialStateHolder;
+import javax.faces.context.FacesContext;
+import javax.faces.validator.Validator;
+import javax.faces.validator.ValidatorException;
+
+/**
+ *
+ **/
+@Generated({"RichFaces CDK", "4.0.0-SNAPSHOT"})
+public class GeneratedClass extends Object implements Validator, PartialStateHolder {
+
+ @Override
+ public void validate(FacesContext context, UIComponent component, Object value)
throws ValidatorException {
+
+ }
+
+ 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
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/UIBar.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -62,7 +62,6 @@
testValue,
testFlag
- ;
}
/**
Modified:
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/test/component/MyConverter.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/test/component/MyConverter.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/test/component/MyConverter.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -21,7 +21,7 @@
package org.richfaces.cdk.test.component;
-import org.richfaces.cdk.annotations.Converter;
+import org.richfaces.cdk.annotations.JsfConverter;
import javax.faces.context.FacesContext;
import javax.faces.component.UIComponent;
@@ -30,7 +30,7 @@
* @author akolonitsky
* @since Jan 14, 2010
*/
-@Converter(id = "my_converter", forClass = Integer.class)
+@JsfConverter(id = "my_converter", forClass = Integer.class)
public class MyConverter implements javax.faces.convert.Converter{
@Override
@@ -44,7 +44,7 @@
}
}
-@Converter(forClass = Integer.class)
+@JsfConverter(forClass = Integer.class)
class MyConverter01 implements javax.faces.convert.Converter{
@Override
@@ -58,7 +58,7 @@
}
}
-@Converter(id = "my_converter_02")
+@JsfConverter(id = "my_converter_02")
class MyConverter02 implements javax.faces.convert.Converter{
@Override
@@ -72,7 +72,7 @@
}
}
-@Converter
+@JsfConverter
class MyConverter03 implements javax.faces.convert.Converter{
@Override
Modified:
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/test/component/MyValidator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/test/component/MyValidator.java 2010-01-20
10:23:29 UTC (rev 16338)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/test/component/MyValidator.java 2010-01-20
10:36:29 UTC (rev 16339)
@@ -21,7 +21,7 @@
package org.richfaces.cdk.test.component;
-import org.richfaces.cdk.annotations.Validator;
+import org.richfaces.cdk.annotations.JsfValidator;
import javax.faces.validator.ValidatorException;
import javax.faces.context.FacesContext;
@@ -31,7 +31,7 @@
* @author akolonitsky
* @since Jan 14, 2010
*/
-@Validator(id = "my_validator")
+@JsfValidator(id = "my_validator")
public class MyValidator implements javax.faces.validator.Validator {
@Override
@@ -40,7 +40,7 @@
}
}
-@Validator
+@JsfValidator
class MyValidator01 implements javax.faces.validator.Validator {
@Override