Author: Alex.Kolonitsky
Date: 2010-01-18 09:30:05 -0500 (Mon, 18 Jan 2010)
New Revision: 16321
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTaglibGenerator.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTemplateModel.java
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/taglib/
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/freemarker/ValidatorTaglibGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/freemarker/
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/
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/UIBar.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContextBase.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/freemarker/PropertyModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentLibrary.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/Property.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ConverterBean.java
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/xmlconfig/testmodel/ConverterBeanTest.java
Log:
https://jira.jboss.org/jira/browse/RF-8232
Tags support
- taglib generator for validator
- remove jaxb annotation from model classes
- check result for java code generators (ComponentClassGenerator...)
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContextBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContextBase.java 2010-01-18
12:10:45 UTC (rev 16320)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/CdkContextBase.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -36,6 +36,7 @@
import org.richfaces.cdk.templatecompiler.RendererTemplateParser;
import org.richfaces.cdk.xmlconfig.FacesConfigGenerator;
import org.richfaces.cdk.xmlconfig.FacesConfigParser;
+import org.richfaces.cdk.freemarker.ValidatorTaglibGenerator;
import com.google.common.collect.ClassToInstanceMap;
import com.google.common.collect.ImmutableMap;
@@ -56,6 +57,7 @@
static final ImmutableMap<OutputType, Class<? extends CdkWriter>> WRITERS
=
ImmutableMap.<OutputType, Class<? extends CdkWriter>>builder()
.put(StandardOutputs.COMPONENT_CLASSES, ComponentClassGenerator.class)
+ .put(StandardOutputs.TAG_LIBRARY, ValidatorTaglibGenerator.class)
.put(StandardOutputs.RENDERER_CLASSES, RendererClassGenerator.class)
.put(StandardOutputs.FACES_CONFIG, FacesConfigGenerator.class)
.build();
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-18
12:10:45 UTC (rev 16320)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/LibraryModelWrapper.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -26,6 +26,7 @@
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;
@@ -55,6 +56,8 @@
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);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyModel.java 2010-01-18
12:10:45 UTC (rev 16320)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyModel.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -72,6 +72,8 @@
value = getSetterName();
} else if ("name".equals(key)) {
value = getName();
+ } else if ("required".equals(key)) {
+ value = String.valueOf(this.property.isRequired());
} else {
return super.get(key);
}
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTaglibGenerator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTaglibGenerator.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTaglibGenerator.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -0,0 +1,59 @@
+/*
+ * 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 org.richfaces.cdk.CdkContext;
+import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.StandardOutputs;
+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 18, 2010
+ */
+public class ValidatorTaglibGenerator extends FreeMarkerRenderer<ValidatorModel,
ComponentLibrary>{
+
+ @Override
+ protected String getOutputFile(ValidatorModel validatorModel) throws CdkException {
+ return validatorModel.getValidatorClass().getName().replace('.',
File.separatorChar) + "-taglib.xml";
+ }
+
+ @Override
+ protected boolean isMyComponent(Visitable visitable) {
+ return visitable instanceof ValidatorModel;
+ }
+
+ @Override
+ protected String getTemplateName() {
+ return "taglib/validator.ftl";
+ }
+
+ @Override
+ protected CdkContext.OutputType getOutputType() {
+ return StandardOutputs.TAG_LIBRARY;
+ }
+}
Added:
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
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ValidatorTemplateModel.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -0,0 +1,130 @@
+/*
+ * 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 new PropertyMapModel(component.getAttributes(),wrapper);
+ } 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);
+ }
+
+}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentLibrary.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentLibrary.java 2010-01-18
12:10:45 UTC (rev 16320)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentLibrary.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -25,6 +25,9 @@
package org.richfaces.cdk.model;
+import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.model.RenderKitModel.Id;
+
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
@@ -35,13 +38,6 @@
import java.util.Map;
import java.util.NoSuchElementException;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlRootElement;
-import javax.xml.bind.annotation.XmlType;
-
-import org.richfaces.cdk.CdkException;
-import org.richfaces.cdk.model.RenderKitModel.Id;
-
/**
* <p class="changed_added_4_0">
* That class contains model of all JSF components asscoiated with that project
@@ -54,13 +50,13 @@
* @author asmirnov(a)exadel.com
*
*/
-@XmlRootElement(name = "faces-config", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE)
-@XmlType(namespace = ComponentLibrary.FACES_CONFIG_NAMESPACE, name =
"faces-configType")
public class ComponentLibrary implements Serializable, Extensible<ConfigExtension>,
Trackable {
public static final String CDK_EXTENSIONS_NAMESPACE =
"http://richfaces.org/cdk/extensions";
public static final String FACES_CONFIG_NAMESPACE =
"http://java.sun.com/xml/ns/javaee";
public static final String FACES_CONFIG_SCHEMA_LOCATION =
"http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd";
+ public static final String TAGLIB_SCHEMA_LOCATION =
+ "http://java.sun.com/xml/ns/javaee/web-facelettaglibrary_2_0.xsd";
/**
* <p class="changed_added_4_0">
@@ -147,7 +143,6 @@
*
* @return the components
*/
- @XmlElement
public Collection<ComponentModel> getComponents() {
return components;
}
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-18
12:10:45 UTC (rev 16320)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -1,27 +1,20 @@
package org.richfaces.cdk.model;
+import org.richfaces.cdk.CdkException;
+
import java.util.Collection;
import java.util.Map;
-import javax.xml.bind.annotation.XmlAccessType;
-import javax.xml.bind.annotation.XmlAccessorType;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlElements;
-import javax.xml.bind.annotation.XmlType;
-
-import org.richfaces.cdk.CdkException;
-
/**
* That class represents JSF component in the CDK.
* That is mapped to faces-config "component" element.
* @author asmirnov(a)exadel.com
*
*/
-@SuppressWarnings("serial")
-@XmlType(name = "faces-config-componentType")
-(a)XmlAccessorType(XmlAccessType.NONE)
public final class ComponentModel extends ModelElementBase implements
ModelElement<ComponentModel> {
+ private static final long serialVersionUID = 2297349356280370771L;
+
/**
* <p class="changed_added_4_0">Is that component c</p>
*/
@@ -108,12 +101,10 @@
if(null != getType() && null != other.getType()){
// Both types not null, compare them.
return getType().equals(other.getType());
- }
- // one or both types are null, compare classes.
- if(null != getComponentClass() &&
getComponentClass().equals(other.getComponentClass())){
- return true;
}
- return false;
+
+ // one or both types are null, compare classes.
+ return null != getComponentClass() &&
getComponentClass().equals(other.getComponentClass());
}
/**
* <p class="changed_added_4_0"></p>
@@ -123,7 +114,6 @@
this.type = type;
}
- @XmlElement(name = "component-type", required = true)
public Type getType() {
return type;
}
@@ -170,7 +160,6 @@
* @param componentClass
* the componentClass to set
*/
- @XmlElement(name = "component-class")
public void setComponentClass(ClassDescription componentClass) {
this.componentClass = componentClass;
}
@@ -221,16 +210,12 @@
*
* @return the attributes
*/
- @XmlElements({@XmlElement(name = "property", type = Property.class) ,
- @XmlElement(name = "attribute", type = AttributeModel.class)
})
public Map<String,Property> getAttributes() {
return attributes;
}
public Property addAttribute(String attributeName) {
- Property attribute;
-
- attribute = attributes.get(attributeName);
+ Property attribute = attributes.get(attributeName);
if(null == attribute){
attribute = new Property();
attributes.put(attributeName, attribute);
@@ -283,6 +268,8 @@
}
public static class Type extends Key {
+ private static final long serialVersionUID = -6968199073379187423L;
+
public Type(String type) {
super(type);
}
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-18
12:10:45 UTC (rev 16320)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ConverterModel.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -25,8 +25,6 @@
import org.richfaces.cdk.CdkException;
-import javax.xml.bind.annotation.XmlElements;
-import javax.xml.bind.annotation.XmlElement;
import java.util.Map;
/**
@@ -88,8 +86,6 @@
*
* @return the attributes
*/
- @XmlElements({@XmlElement(name = "property", type = Property.class) ,
- @XmlElement(name = "attribute", type = AttributeModel.class)
})
public Map<String,Property> getAttributes() {
return attributes;
}
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-18
12:10:45 UTC (rev 16320)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ModelElementBase.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -1,7 +1,5 @@
package org.richfaces.cdk.model;
-import javax.xml.bind.annotation.XmlElement;
-
/**
* <p class="changed_added_4_0">Base class for the most JSF components
taht have description
* attributes and support extensions in faces-config.</p>
@@ -36,7 +34,6 @@
super();
}
- @XmlElement
public final String getDescription() {
return description;
}
@@ -45,7 +42,6 @@
this.description = description;
}
- @XmlElement(name = "display-name")
public final String getDisplayname() {
return displayname;
}
@@ -54,7 +50,6 @@
this.displayname = displayname;
}
- @XmlElement
public final Icon getIcon() {
return icon;
}
@@ -68,7 +63,6 @@
*
* @return the extension
*/
- @XmlElement(name = "component-extensions")
public final ConfigExtension getExtension() {
return extension;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Property.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Property.java 2010-01-18
12:10:45 UTC (rev 16320)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Property.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -36,9 +36,10 @@
* @author asmirnov(a)exadel.com
*
*/
-@SuppressWarnings("serial")
public class Property extends ModelElementBase implements ModelElement<Property> {
+ private static final long serialVersionUID = 3483864006602184580L;
+
/**
* <p class="changed_added_4_0">Is that bean property generate in
the class or should be generated ?</p>
*/
@@ -58,7 +59,6 @@
/**
* <p class="changed_added_4_0"></p>
- * @param name
*/
public Property() {
}
@@ -91,7 +91,7 @@
/**
* <p class="changed_added_4_0"></p>
- * @param defaultValue the defaultValue to set
+ * @param dafaultValue - the defaultValue to set
*/
public void setDefaultValue(String dafaultValue) {
this.defaultValue = dafaultValue;
@@ -125,7 +125,7 @@
/**
* <p class="changed_added_4_0"></p>
- * @param generate the generate to set
+ * @param exists - the generate to set
*/
public void setGenerate(boolean exists) {
this.generate = exists;
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ConverterBean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ConverterBean.java 2010-01-18
12:10:45 UTC (rev 16320)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ConverterBean.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -78,12 +78,6 @@
this.converterClass = converterClass;
}
- @XmlElement(name = "converter-extension", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE)
- @Override
- public ConverterExtension getExtension() {
- return super.getExtension();
- }
-
/**
* <p class="changed_added_4_0"></p>
*
@@ -98,7 +92,6 @@
namespace = ComponentLibrary.FACES_CONFIG_NAMESPACE,
type = AttributeBean.class
)})
-
public List<PropertyBase> getAttributes() {
return attributes;
}
@@ -117,8 +110,11 @@
super.setExtension(extension);
}
- public static class ConverterExtension extends ConfigExtension {
-
+ @XmlElement(name = "converter-extension", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE, nillable = true)
+ @Override
+ public ConverterExtension getExtension() {
+ return super.getExtension();
}
+ public static class ConverterExtension extends ConfigExtension { }
}
Added:
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
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/resources/META-INF/templates/taglib/validator.ftl 2010-01-18
14:30:05 UTC (rev 16321)
@@ -0,0 +1,20 @@
+<?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">
+ <tag>
+ <validator>
+ <validator-id>${validatorId}</validator-id>
+ <handler-class>${validatorClass}</handler-class>
+ </validator>
+
+ <#list generatedAttributes as attribute>
+ <attribute>
+ <#if attribute.description?exists>
+ <description>${attribute.description}</description>
+ </#if>
+ <name>${attribute.name}</name>
+ <type>${attribute.type}</type>
+ <required>${attribute.required}</required>
+ </attribute>
+ </#list>
+ </tag>
+</facelet-taglib>
\ No newline at end of file
Added:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/freemarker/ValidatorTaglibGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/freemarker/ValidatorTaglibGeneratorTest.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/freemarker/ValidatorTaglibGeneratorTest.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -0,0 +1,149 @@
+/*
+ * 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 org.custommonkey.xmlunit.Diff;
+import org.custommonkey.xmlunit.Validator;
+import static org.easymock.EasyMock.*;
+import org.junit.Assert;
+import org.junit.Test;
+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.ComponentLibrary;
+import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.Property;
+import org.richfaces.cdk.model.ValidatorModel;
+import org.richfaces.cdk.xmlconfig.CdkEntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
+
+import javax.faces.component.UIOutput;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.Set;
+
+/**
+ * @author akolonitsky
+ * @since Jan 18, 2010
+ */
+public class ValidatorTaglibGeneratorTest extends CdkTestBase {
+
+ /**
+ * Test method for {@link
org.richfaces.cdk.generate.java.ComponentClassGenerator#getOutputFile(org.richfaces.cdk.model.ComponentModel)}.
+ * @throws Exception
+ */
+ @Test
+ public void testGetOutputFileComponent() throws Exception {
+ final StringWriter output = new StringWriter();
+ ValidatorTaglibGenerator generator = new ValidatorTaglibGenerator() {
+ @Override
+ protected Writer getOutput(ValidatorModel c) throws CdkException {
+ return output;
+ }
+ };
+
+ CdkContext mockContext = createMockContext();
+ generator.init(mockContext);
+
+ ValidatorModel validator = new ValidatorModel("foo.bar", new
ClassDescription(UIOutput.class));
+ validator.setGenerate(true);
+
+ addAttribute(validator, "testValue", Object.class, true);
+ 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);
+
+ checkXmlStructure(output);
+
+ // TODO validate xml by xsd
+// validateXml(output);
+ }
+
+ 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;
+ }
+
+ // TODO move it in other class
+ protected void validateXml(StringWriter facesConfig) throws SAXException, IOException
{
+ InputSource is = new InputSource(new StringReader(facesConfig.toString()));
+ Validator validator = new Validator(is);
+ validator.useXMLSchema(true);
+ InputSource source = new CdkEntityResolver(null)
+ .resolveEntity(null, ComponentLibrary.TAGLIB_SCHEMA_LOCATION);
+ validator.setJAXP12SchemaSource(source);
+
+ validator.assertIsValid();
+ }
+
+ protected void checkXmlStructure(StringWriter writer) throws SAXException,
IOException {
+ Class<?> testClass = this.getClass();
+ InputStream expectedFacesConfigFile =
testClass.getResourceAsStream(testClass.getSimpleName() + ".xml");
+ if (expectedFacesConfigFile == null) {
+ return;
+ }
+
+ Diff xmlDiff = new Diff(
+ new StringReader(writer.toString()),
+ new InputStreamReader(expectedFacesConfigFile));
+
+ Assert.assertTrue("XML was not similar", xmlDiff.similar());
+ }
+}
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-18
12:10:45 UTC (rev 16320)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -29,11 +29,18 @@
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;
@@ -43,6 +50,8 @@
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>
@@ -80,7 +89,7 @@
attribute.setType(new ClassDescription(Object.class));
attribute.setGenerate(true);
attribute = component.addAttribute("testFlag");
- attribute.setType(new ClassDescription(boolean.class));
+ attribute.setType(new ClassDescription(Boolean.class));
attribute.setGenerate(true);
attribute = component.addAttribute("id");
attribute.setType(new ClassDescription(String.class));
@@ -96,10 +105,10 @@
eventNames.add(event);
attribute.setGenerate(false);
generator.visit(component, library);
- System.out.println(output);
+// System.out.println(output);
verify(mockContext);
- // TODO - check generated file.
+ compare(output, "UIBar.java");
}
private CdkContext createMockContext() throws Exception {
@@ -112,4 +121,35 @@
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);
+ }
+ }
+ }
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.java 2010-01-18
12:10:45 UTC (rev 16320)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/testmodel/ConverterBeanTest.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -38,7 +38,7 @@
public class ConverterBeanTest extends ModelBeanTest {
@Test
- public void testMarshalResultStringT() throws Exception {
+ public void testMarshal() throws Exception {
ComponentLibrary library = new ComponentLibrary();
ConverterModel converterModel = new ConverterModel("my_converter", new
ClassDescription(Object.class));
Added:
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
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/freemarker/ValidatorTaglibGeneratorTest.xml 2010-01-18
14:30:05 UTC (rev 16321)
@@ -0,0 +1,20 @@
+<?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">
+ <tag>
+ <validator>
+ <validator-id>foo.bar</validator-id>
+ <handler-class>javax.faces.component.UIOutput</handler-class>
+ </validator>
+
+ <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/UIBar.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/UIBar.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/test/resources/org/richfaces/cdk/generate/java/UIBar.java 2010-01-18
14:30:05 UTC (rev 16321)
@@ -0,0 +1,95 @@
+/*
+ * $Id: component.ftl 16229 2009-12-29 21:36:27Z alexsmirnov $
+ *
+ * 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 foo.bar;
+
+// Import declarations
+import javax.annotation.Generated;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.List;
+
+import javax.faces.context.FacesContext;
+import javax.faces.component.behavior.ClientBehaviorHolder;
+import javax.el.MethodExpression;
+import javax.el.ValueExpression;
+
+/**
+ *
+ **/
+@Generated({"RichFaces CDK", "4.0.0-SNAPSHOT"})
+public class UIBar extends javax.faces.component.UIOutput implements ClientBehaviorHolder
{
+
+
+ public static final String COMPONENT_TYPE="foo.bar";
+
+
+ private static final Collection<String> EVENT_NAMES =
Collections.unmodifiableCollection(Arrays.asList(
+ "id",
+ "action"
+
+ ));
+ public Collection<String> getEventNames() {
+ return EVENT_NAMES; }
+
+
+ public String getDefaultEventName() {
+ return "action";
+ }
+ 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);
+ }
+
+}