Author: alexsmirnov
Date: 2011-01-12 20:47:03 -0500 (Wed, 12 Jan 2011)
New Revision: 20976
Added:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/DummyPropertyImpl.java
Removed:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/PropertyImpl.java
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Attribute.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.java
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/component/AbstractTestComponent.java
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml
Log:
RESOLVED - issue RF-9798: CDK: template attributes are ignored
https://issues.jboss.org/browse/RF-9798
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java 2011-01-12
20:37:01 UTC (rev 20975)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/AptSourceUtils.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -116,7 +116,7 @@
if (beanProperties.containsKey(name)) {
return beanProperties.get(name);
} else {
- return new PropertyImpl(name);
+ return new DummyPropertyImpl(name);
}
}
@@ -129,13 +129,15 @@
* @return
*/
Map<String, AptBeanProperty> getBeanProperties(TypeElement type) {
- List<? extends Element> members =
this.processingEnv.getElementUtils().getAllMembers(type);
- // extract all getters/setters.
Map<String, AptBeanProperty> result = Maps.newHashMap();
- for (Element element : members) {
- if (ElementKind.METHOD.equals(element.getKind())) {
- ExecutableElement method = (ExecutableElement) element;
- processMethod(type, result, method);
+ if (null != type) {
+ List<? extends Element> members =
this.processingEnv.getElementUtils().getAllMembers(type);
+ // extract all getters/setters.
+ for (Element element : members) {
+ if (ElementKind.METHOD.equals(element.getKind())) {
+ ExecutableElement method = (ExecutableElement) element;
+ processMethod(type, result, method);
+ }
}
}
return result;
@@ -155,15 +157,16 @@
ExecutableElement method, boolean setter) {
String propertyName = getPropertyName(method);
if (!HIDDEN_PROPERTIES.contains(propertyName)) {
- ClassName propertyType =
asClassDescription(setter?method.getParameters().get(0).asType():method.getReturnType());
+ ClassName propertyType =
+ asClassDescription(setter ? method.getParameters().get(0).asType() :
method.getReturnType());
if (result.containsKey(propertyName)) {
// Merge property with existed one.
AptBeanProperty beanProperty = result.get(propertyName);
checkPropertyType(type, propertyName, propertyType, beanProperty);
- if (null != (setter?beanProperty.setter:beanProperty.getter)) {
+ if (null != (setter ? beanProperty.setter : beanProperty.getter)) {
log.debug("Two " + (setter ? "setter" :
"getter") + " methods for the same bean property "
+ propertyName + " in the class " +
type.getQualifiedName());
- if(!method.getModifiers().contains(Modifier.ABSTRACT)){
+ if (!method.getModifiers().contains(Modifier.ABSTRACT)) {
beanProperty.setAccessMethod(method, setter);
}
} else {
@@ -395,10 +398,10 @@
return processingEnv.getElementUtils().getTypeElement(type.toString());
}
- public boolean isClassExists(ClassName type){
+ public boolean isClassExists(ClassName type) {
return null != asTypeElement(type);
}
-
+
@Override
public TypeElement asTypeElement(TypeMirror mirror) {
if (TypeKind.DECLARED.equals(mirror.getKind())) {
Copied: trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/DummyPropertyImpl.java
(from rev 20968,
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/PropertyImpl.java)
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/DummyPropertyImpl.java
(rev 0)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/DummyPropertyImpl.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -0,0 +1,57 @@
+package org.richfaces.cdk.apt;
+
+import java.lang.annotation.Annotation;
+
+import javax.lang.model.element.AnnotationMirror;
+
+import org.richfaces.cdk.apt.SourceUtils.ACCESS_TYPE;
+import org.richfaces.cdk.apt.SourceUtils.BeanProperty;
+import org.richfaces.cdk.model.ClassName;
+
+public final class DummyPropertyImpl implements BeanProperty {
+ private final String name;
+
+ public DummyPropertyImpl(String name) {
+ this.name = name;
+ }
+
+ @Override
+ public boolean isExists() {
+ return false;
+ }
+
+ @Override
+ public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
{
+ return false;
+ }
+
+ @Override
+ public ClassName getType() {
+ return ClassName.get(Object.class);
+ }
+
+ @Override
+ public String getName() {
+ return this.name;
+ }
+
+ @Override
+ public String getDocComment() {
+ return null;
+ }
+
+ @Override
+ public AnnotationMirror getAnnotationMirror(Class<? extends Annotation>
annotationType) {
+ return null;
+ }
+
+ @Override
+ public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
+ return null;
+ }
+
+ @Override
+ public ACCESS_TYPE getAccessType() {
+ return ACCESS_TYPE.readWrite;
+ }
+}
\ No newline at end of file
Property changes on:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/DummyPropertyImpl.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/PropertyImpl.java
===================================================================
--- trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/PropertyImpl.java 2011-01-12
20:37:01 UTC (rev 20975)
+++ trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/PropertyImpl.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -1,57 +0,0 @@
-package org.richfaces.cdk.apt;
-
-import java.lang.annotation.Annotation;
-
-import javax.lang.model.element.AnnotationMirror;
-
-import org.richfaces.cdk.apt.SourceUtils.ACCESS_TYPE;
-import org.richfaces.cdk.apt.SourceUtils.BeanProperty;
-import org.richfaces.cdk.model.ClassName;
-
-public final class PropertyImpl implements BeanProperty {
- private final String name;
-
- public PropertyImpl(String name) {
- this.name = name;
- }
-
- @Override
- public boolean isExists() {
- return false;
- }
-
- @Override
- public boolean isAnnotationPresent(Class<? extends Annotation> annotationType)
{
- return false;
- }
-
- @Override
- public ClassName getType() {
- return ClassName.get(Object.class);
- }
-
- @Override
- public String getName() {
- return this.name;
- }
-
- @Override
- public String getDocComment() {
- return null;
- }
-
- @Override
- public AnnotationMirror getAnnotationMirror(Class<? extends Annotation>
annotationType) {
- return null;
- }
-
- @Override
- public <T extends Annotation> T getAnnotation(Class<T> annotationType) {
- return null;
- }
-
- @Override
- public ACCESS_TYPE getAccessType() {
- return ACCESS_TYPE.readWrite;
- }
-}
\ No newline at end of file
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java 2011-01-12
20:37:01 UTC (rev 20975)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/ProcessorBase.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -64,7 +64,8 @@
return tagModel;
}
- protected void setClassNames(TypeElement componentElement, GeneratedFacesComponent
modelElement, AnnotationMirror behavior) {
+ protected void setClassNames(TypeElement componentElement, GeneratedFacesComponent
modelElement,
+ AnnotationMirror behavior) {
SourceUtils sourceUtils = getSourceUtils();
if (componentElement.getModifiers().contains(Modifier.ABSTRACT)
|| !sourceUtils.isDefaultValue(behavior, "generate")) {
@@ -128,14 +129,17 @@
}
}
- protected String getAnnotationPropertyOrConstant(TypeElement element,
AnnotationMirror annotation, String annotationAttribute, String fieldName) {
+ protected String getAnnotationPropertyOrConstant(TypeElement element,
AnnotationMirror annotation,
+ String annotationAttribute, String fieldName) {
SourceUtils utils = getSourceUtils();
if (!utils.isDefaultValue(annotation, annotationAttribute)) {
- return utils.getAnnotationValue(annotation,
annotationAttribute,String.class);
+ return utils.getAnnotationValue(annotation, annotationAttribute,
String.class);
}
- Object value = utils.getConstant((TypeElement) element, fieldName);
- if (value != null) {
- return value.toString();
+ if (null != element) {
+ Object value = utils.getConstant((TypeElement) element, fieldName);
+ if (value != null) {
+ return value.toString();
+ }
}
return null;
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java 2011-01-12
20:37:01 UTC (rev 20975)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/apt/processors/RendererProcessor.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -34,20 +34,18 @@
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.RendererModel;
-import org.richfaces.cdk.util.Strings;
-
/**
* @author akolonitsky
* @since Dec 30, 2009
*/
-(a)SupportedAnnotationTypes({"javax.faces.component.FacesComponent",
JsfRenderer.NAME})
+@SupportedAnnotationTypes({ "javax.faces.component.FacesComponent",
JsfRenderer.NAME })
public class RendererProcessor extends ProcessorBase implements CdkAnnotationProcessor {
private static final String COMPONENT_FAMILY = "COMPONENT_FAMILY";
private static final String RENDERER_TYPE = "RENDERER_TYPE";
-
+
public void process(Element rendererElement, ComponentLibrary library) {
SourceUtils sourceUtils = getSourceUtils();
AnnotationMirror annotation = sourceUtils.getAnnotationMirror(rendererElement,
JsfRenderer.class);
@@ -58,33 +56,26 @@
setClassNames(rendererTypeElement, rendererModel, annotation);
setRendererType(rendererTypeElement, rendererModel, annotation);
-
+
setComponentFamily(rendererTypeElement, rendererModel, annotation);
setDescription(rendererModel, annotation, getDocComment(rendererElement));
- sourceUtils.setModelProperty(rendererModel, annotation,
"templatePath","template");
+ sourceUtils.setModelProperty(rendererModel, annotation, "templatePath",
"template");
String renderKitId = sourceUtils.getAnnotationValue(annotation,
"renderKitId", String.class);
library.addRenderer(renderKitId, rendererModel);
}
-
-
- private void setTemplate(RendererModel rendererModel, JsfRenderer annotation) {
- String template = annotation.template();
- if (!Strings.isEmpty(template)) {
- rendererModel.setTemplatePath(template);
- }
+ private void setComponentFamily(TypeElement rendererElement, RendererModel
rendererModel,
+ AnnotationMirror annotation) {
+
rendererModel.setFamily(FacesId.parseId(getAnnotationPropertyOrConstant(rendererElement,
annotation, "family",
+ COMPONENT_FAMILY)));
}
-
- private void setComponentFamily(TypeElement rendererElement, RendererModel
rendererModel, AnnotationMirror annotation) {
-
rendererModel.setFamily(FacesId.parseId(getAnnotationPropertyOrConstant(rendererElement,
annotation,"family",COMPONENT_FAMILY)));
- }
-
private void setRendererType(TypeElement rendererElement, RendererModel
rendererModel, AnnotationMirror annotation) {
-
rendererModel.setId(FacesId.parseId(getAnnotationPropertyOrConstant(rendererElement,
annotation,"type",RENDERER_TYPE)));
+
rendererModel.setId(FacesId.parseId(getAnnotationPropertyOrConstant(rendererElement,
annotation, "type",
+ RENDERER_TYPE)));
}
protected String getComponentType(TypeElement componentElement) {
Modified: trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java 2011-01-12
20:37:01 UTC (rev 20975)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -37,6 +37,8 @@
private String rendererTemplate;
+ private ComponentModel parent;
+
public ComponentModel(FacesId key) {
this.setId(key);
}
@@ -175,4 +177,13 @@
public String toString() {
return "Component {type: " + getId() + ", family: " +
getFamily() + "}";
}
+
+ public void setParent(ComponentModel parentComponent) {
+ this.parent = parentComponent;
+ }
+
+ @Merge
+ public ComponentModel getParent() {
+ return this.parent;
+ }
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java 2011-01-12
20:37:01 UTC (rev 20975)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -40,7 +40,9 @@
import org.richfaces.cdk.ModelValidator;
import org.richfaces.cdk.NamingConventions;
import org.richfaces.cdk.annotations.TagType;
+import org.richfaces.cdk.apt.DummyPropertyImpl;
import org.richfaces.cdk.apt.SourceUtils;
+import org.richfaces.cdk.apt.SourceUtils.BeanProperty;
import org.richfaces.cdk.model.BehaviorModel;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
@@ -48,10 +50,11 @@
import org.richfaces.cdk.model.ConverterModel;
import org.richfaces.cdk.model.DescriptionGroup;
import org.richfaces.cdk.model.EventModel;
-import org.richfaces.cdk.model.GeneratedFacesComponent;
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.FacetModel;
+import org.richfaces.cdk.model.GeneratedFacesComponent;
import org.richfaces.cdk.model.InvalidNameException;
+import org.richfaces.cdk.model.ModelElementBase;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.model.RenderKitModel;
import org.richfaces.cdk.model.RendererModel;
@@ -135,7 +138,7 @@
throw new CallbackException("Cannot infer Java class name for behavior
" + this.behavior);
}
}
-
+
private final class ConverterTypeCallback implements NamingConventionsCallback {
private final ConverterModel converter;
@@ -143,6 +146,7 @@
public ConverterTypeCallback(ConverterModel converter) {
this.converter = converter;
}
+
@Override
public FacesId inferType(ClassName targetClass) throws CallbackException {
// TODO use actual methods
@@ -168,7 +172,7 @@
public ClassName getDefaultClass() throws CallbackException {
return ClassName.get(Object.class);
}
-
+
}
private final class ValidatorTypeCallback implements NamingConventionsCallback {
@@ -204,7 +208,7 @@
public ClassName getDefaultClass() throws CallbackException {
return ClassName.get(Object.class);
}
-
+
}
private final class RendererTypeCallback implements NamingConventionsCallback {
@@ -296,9 +300,9 @@
public void verify(ComponentLibrary library) throws CdkException {
verifyComponents(library);
verifyEvents(library);
- verifyBehaviors(library);
verifyRenderers(library);
verifyTaglib(library);
+ verifyBehaviors(library);
verifyConverters(library);
verifyValidators(library);
}
@@ -307,7 +311,7 @@
for (ValidatorModel validator : library.getValidators()) {
verifyTypes(validator, new ValidatorTypeCallback(validator));
}
-
+
}
protected void verifyConverters(ComponentLibrary library) {
@@ -403,21 +407,50 @@
protected void vefifyRenderer(final ComponentLibrary library, final RendererModel
renderer) {
+ for (ComponentModel component : library.getComponents()) {
+ if (isTheSameTemplate(renderer, component) && null ==
renderer.getId()) {
+ renderer.setId(component.getRendererType());
+ }
+ }
// Check type.
verifyTypes(renderer, new RendererTypeCallback(library, renderer));
// Check component type.
for (ComponentModel component : library.getComponents()) {
if (renderer.getId().equals(component.getRendererType())) {
- renderer.getAttributes().addAll(component.getAttributes());
- renderer.setFamily(component.getFamily());
+ copyRendererAttributes(renderer, component);
+ } else if (isTheSameTemplate(renderer, component)) {
+ copyRendererAttributes(renderer, component);
+ component.setRendererType(renderer.getId());
}
}
// Check family.
if (null == renderer.getFamily()) {
- //
renderer.setFamily(namingConventions.inferRendererBaseName(renderer.getId()));
+ renderer.setFamily(namingConventions.inferRendererFamily(renderer.getId()));
}
}
+ private void copyRendererAttributes(final RendererModel renderer, ComponentModel
component) {
+ for (PropertyBase property : renderer.getAttributes()) {
+ PropertyBase attribute = component.getOrCreateAttribute(property.getName());
+ attribute.merge(property);
+ verifyAttribute(attribute, component);
+ }
+ renderer.setFamily(component.getFamily());
+ }
+
+ private boolean isTheSameTemplate(final RendererModel renderer, ComponentModel
component) {
+ String componentTemplatePath = component.getRendererTemplate();
+ if (null != componentTemplatePath) {
+ if (componentTemplatePath.equals(renderer.getTemplatePath())) {
+ return true;
+ } else if (null != renderer.getTemplate()
+ &&
renderer.getTemplate().getTemplatePath().endsWith(componentTemplatePath)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
protected void verifyComponents(ComponentLibrary library) throws CdkException {
// Verify types and classes. Do it first to be sure what all all values are set
before second stage.
for (ComponentModel component : library.getComponents()) {
@@ -427,6 +460,9 @@
HashSet<ComponentModel> verified = Sets.newHashSet();
for (ComponentModel component : library.getComponents()) {
verifyComponentAttributes(library, component, verified);
+ if(null == component.getFamily()){
+
component.setFamily(namingConventions.inferUIComponentFamily(component.getId()));
+ }
}
}
@@ -449,6 +485,10 @@
try {
// Step one, lookup for parent.
ComponentModel parentComponent = findParent(library.getComponents(),
component);
+ component.setParent(parentComponent);
+ if(null == component.getFamily()){
+ component.setFamily(parentComponent.getFamily());
+ }
// To be sure what all properties for parent component were
propagated.
verifyComponentAttributes(library, parentComponent, verified);
for (PropertyBase parentAttribute : parentComponent.getAttributes())
{
@@ -484,7 +524,7 @@
@Override
public boolean apply(T input) {
- return component.getBaseClass().equals(input.getTargetClass());
+ return component.getBaseClass().equals(input.getTargetClass()) &&
component != input;
}
});
}
@@ -518,10 +558,7 @@
*/
protected void verifyComponentType(ComponentModel component) throws
InvalidNameException {
// Check JsfComponent type.
- if (verifyTypes(component, new ComponentTypeCallback()) && null ==
component.getFamily()) {
- // Check family.
-
component.setFamily(namingConventions.inferUIComponentFamily(component.getId()));
- }
+ verifyTypes(component, new ComponentTypeCallback()) ;
}
/**
@@ -554,7 +591,7 @@
component.setTargetClass(callback.inferClass(component.getId()));
}
component.setGenerate(!sourceUtilsProvider.get().isClassExists(component.getTargetClass()));
- }
+ }
if (component.getGenerate()) {
verifyGeneratedClasses(component, callback);
} else if (null == component.getTargetClass()) {
@@ -570,7 +607,8 @@
return true;
}
- private void verifyGeneratedClasses(GeneratedFacesComponent component,
NamingConventionsCallback callback) throws CallbackException {
+ private void verifyGeneratedClasses(GeneratedFacesComponent component,
NamingConventionsCallback callback)
+ throws CallbackException {
if (null == component.getBaseClass()) {
component.setBaseClass(callback.getDefaultBaseClass());
// return;
@@ -592,11 +630,12 @@
return;
}
// Check type
+ BeanProperty beanProperty = findBeanProperty(attribute, component);
if (null == attribute.getType()) {
- log.error("Unknown type of attribute [" + attribute.getName() +
"]");
- return;
- }
- if(attribute.getType().isPrimitive() && null ==
attribute.getDefaultValue()){
+ log.warn("Unknown type of attribute [" + attribute.getName() +
"]");
+ attribute.setType(beanProperty.getType());
+ }
+ if (attribute.getType().isPrimitive() && null ==
attribute.getDefaultValue()) {
// Set default value for primitive
attribute.setDefaultValue(attribute.getType().getDefaultValue());
}
@@ -614,16 +653,10 @@
if (Boolean.TRUE.equals(component.getGenerate())) {
// TODO Attribute should be only generated if it does not exist or abstract
in the base class.
// Step one - check base class
- SourceUtils sourceUtils = sourceUtilsProvider.get();
if (SPECIAL_PROPERTIES.contains(attribute.getName())) {
attribute.setGenerate(false);
} else if (null == attribute.getGenerate()) {
- if (sourceUtils.isClassExists(component.getBaseClass())) {
-
attribute.setGenerate(!sourceUtils.getBeanProperty(component.getBaseClass(),
attribute.getName())
- .isExists());
- } else {
- attribute.setGenerate(true);
- }
+ attribute.setGenerate(!beanProperty.isExists());
}
} else {
attribute.setGenerate(false);
@@ -631,6 +664,27 @@
verifyDescription(attribute);
}
+ private BeanProperty findBeanProperty(PropertyBase attribute, GeneratedFacesComponent
component) {
+ SourceUtils sourceUtils = sourceUtilsProvider.get();
+ BeanProperty beanProperty = sourceUtils.getBeanProperty(component.getBaseClass(),
attribute.getName());
+ if (beanProperty instanceof DummyPropertyImpl && component instanceof
ComponentModel) {
+ ComponentModel model = (ComponentModel) component;
+ if (null != model.getParent()) {
+ beanProperty = findBeanProperty(attribute, model.getParent());
+ }
+ }
+ if (beanProperty instanceof DummyPropertyImpl && component instanceof
ModelElementBase) {
+ ModelElementBase model = (ModelElementBase) component;
+ for (ClassName interfaceName : model.getInterfaces()) {
+ beanProperty = sourceUtils.getBeanProperty(interfaceName,
attribute.getName());
+ if (!(beanProperty instanceof DummyPropertyImpl)) {
+ break;
+ }
+ }
+ }
+ return beanProperty;
+ }
+
protected void verifyDescription(DescriptionGroup element) {
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java 2011-01-12
20:37:01 UTC (rev 20975)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -36,13 +36,12 @@
import org.richfaces.cdk.FileManager;
import org.richfaces.cdk.Logger;
import org.richfaces.cdk.ModelBuilder;
-import org.richfaces.cdk.NamingConventions;
-import org.richfaces.cdk.RichFacesConventions;
import org.richfaces.cdk.Source;
import org.richfaces.cdk.Sources;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventName;
+import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.MethodSignature;
import org.richfaces.cdk.model.PropertyBase;
import org.richfaces.cdk.model.PropertyModel;
@@ -70,8 +69,8 @@
*/
public class RendererTemplateParser implements ModelBuilder {
- private static final Pattern PARAMETERS_STRING_PATTERN =
- Pattern.compile("^(\\S+)\\s+(\\S+)\\s*\\(([^\\)]*)\\)$",
Pattern.COMMENTS);
+ private static final Pattern PARAMETERS_STRING_PATTERN =
Pattern.compile("^(\\S+)\\s+(\\S+)\\s*\\(([^\\)]*)\\)$",
+ Pattern.COMMENTS);
private static final Pattern COMMA_SEPARATED_PATTERN =
Pattern.compile("\\s*,\\s*", Pattern.COMMENTS);
@@ -85,9 +84,6 @@
private FragmentParser fragmentParser;
- // @Inject
- private NamingConventions namingConventions;
-
/**
* <p class="changed_added_4_0">
* </p>
@@ -107,48 +103,6 @@
this.fragmentParser = fragmentParser;
}
- private Set<EventName> convert(Collection<ClientBehavior>
clientBehaviors) {
- if (clientBehaviors == null || clientBehaviors.isEmpty()) {
- return null;
- }
-
- Set<EventName> result = Sets.newLinkedHashSet();
- for (ClientBehavior clientBehavior : clientBehaviors) {
- EventName eventName = new EventName();
- eventName.setName(clientBehavior.getEvent());
- eventName.setDefaultEvent(clientBehavior.isDefaultEvent());
- result.add(eventName);
- }
-
- return result;
- }
-
- private MethodSignature parseSignature(String signatureString) {
-
- List<ClassName> parameters = Lists.newArrayList();
- MethodSignature signature = null;
- if (!Strings.isEmpty(signatureString)) {
- Matcher parametersStringMatcher =
PARAMETERS_STRING_PATTERN.matcher(signatureString);
- if (!parametersStringMatcher.find()) {
- throw new IllegalArgumentException(MessageFormat.format("Signature
string {0} cannot be parsed!",
- signatureString));
- }
- signature = new MethodSignature();
-
signature.setReturnType(ClassName.parseName(parametersStringMatcher.group(1)));
- String parametersString = parametersStringMatcher.group(3);
- if (parametersString.trim().length() != 0) {
- String[] parameterStrings =
COMMA_SEPARATED_PATTERN.split(parametersString);
- for (String parameter : parameterStrings) {
- String trimmedParameter = parameter.trim();
- parameters.add(ClassName.parseName(trimmedParameter));
- }
- signature.setParameters(parameters);
- }
-
- }
- return signature;
- }
-
/*
* (non-Javadoc)
*
@@ -188,7 +142,7 @@
return null;
}
}, absolutePath);
- Template template = parseTemplate(file);
+ Template template = parseTemplate(file);
mergeTemplateIntoModel(template, existedModel);
} catch (AlreadyProcessedException e) {
log.warn("Template " + absolutePath + "was already
processed");
@@ -204,8 +158,8 @@
renderKit.getRenderers().add(renderer);
}
renderer.setTemplate(template);
- setRendererType(template, compositeInterface, renderer);
- setFamily(compositeInterface, renderer); // TODO set default values according to
template name
+ setRendererType(compositeInterface, renderer);
+ setFamily(compositeInterface, renderer);
setRendererClass(compositeInterface, renderer);
setRendererBaseClass(compositeInterface, renderer);
@@ -215,26 +169,22 @@
}
List<ImportAttributes> attributesImports =
compositeInterface.getAttributesImports();
- if (attributesImports != null) {
- for (ImportAttributes attributesImport : attributesImports) {
- String importURI = attributesImport.getSource();
- Collection<PropertyBase> properties;
- try {
- properties = fragmentParser.parseProperties(importURI);
- if (properties != null) {
- renderer.getAttributes().addAll(properties);
- }
- } catch (FileNotFoundException e) {
- throw new CdkException("File for import not found", e);
+ for (ImportAttributes attributesImport : attributesImports) {
+ String importURI = attributesImport.getSource();
+ Collection<PropertyBase> properties;
+ try {
+ properties = fragmentParser.parseProperties(importURI);
+ if (properties != null) {
+ renderer.getAttributes().addAll(properties);
}
+ } catch (FileNotFoundException e) {
+ throw new CdkException("File for import not found", e);
}
}
List<Attribute> templateAttributes = compositeInterface.getAttributes();
- if (templateAttributes != null) {
- for (Attribute templateAttribute : templateAttributes) {
- renderer.getAttributes().add(buildProperty(templateAttribute));
- }
+ for (Attribute templateAttribute : templateAttributes) {
+ renderer.getAttributes().add(buildProperty(templateAttribute));
}
return renderer;
}
@@ -244,27 +194,16 @@
rendererProperty.setName(templateAttribute.getName());
rendererProperty.setDefaultValue(templateAttribute.getDefaultValue());
- // TODO is it the right one?
rendererProperty.setDescription(templateAttribute.getShortDescription());
rendererProperty.setDisplayName(templateAttribute.getDisplayName());
- Set<EventName> eventNamesSet =
convert(templateAttribute.getClientBehaviors());
- if (eventNamesSet != null) {
- rendererProperty.getEventNames().addAll(eventNamesSet);
- }
+ Set<EventName> eventNamesSet =
convertBehaviorsToEvents(templateAttribute.getClientBehaviors());
+ rendererProperty.getEventNames().addAll(eventNamesSet);
- // rendererProperty.setAliases(aliases)
- // rendererProperty.setExtension(extension)
- // rendererProperty.setGenerate(exists)
- // rendererProperty.setHidden(hidden)
- // rendererProperty.setIcon(icon)
- // rendererProperty.setLiteral(literal)
- // rendererProperty.setPassThrough(passThrough)
- // rendererProperty.setReadOnly(readOnly)
- // rendererProperty.setSuggestedValue(suggestedValue)
-
- rendererProperty.setRequired(templateAttribute.isRequired());
-
+ Boolean required = templateAttribute.getRequired();
+ if (null != required) {
+ rendererProperty.setRequired(required);
+ }
MethodSignature parsedSignature =
parseSignature(templateAttribute.getMethodSignature());
rendererProperty.setSignature(parsedSignature);
@@ -272,40 +211,81 @@
return rendererProperty;
}
+ private Set<EventName>
convertBehaviorsToEvents(Collection<ClientBehavior> clientBehaviors) {
+ Set<EventName> result = Sets.newLinkedHashSet();
+ for (ClientBehavior clientBehavior : clientBehaviors) {
+ EventName eventName = new EventName();
+ eventName.setName(clientBehavior.getEvent());
+ eventName.setDefaultEvent(clientBehavior.isDefaultEvent());
+ result.add(eventName);
+ }
+
+ return result;
+ }
+
+ private MethodSignature parseSignature(String signatureString) {
+
+ List<ClassName> parameters = Lists.newArrayList();
+ MethodSignature signature = null;
+ if (!Strings.isEmpty(signatureString)) {
+ Matcher parametersStringMatcher =
PARAMETERS_STRING_PATTERN.matcher(signatureString);
+ if (!parametersStringMatcher.find()) {
+ throw new IllegalArgumentException(MessageFormat.format("Signature
string {0} cannot be parsed!",
+ signatureString));
+ }
+ signature = new MethodSignature();
+
signature.setReturnType(ClassName.parseName(parametersStringMatcher.group(1)));
+ String parametersString = parametersStringMatcher.group(3);
+ if (parametersString.trim().length() != 0) {
+ String[] parameterStrings =
COMMA_SEPARATED_PATTERN.split(parametersString);
+ for (String parameter : parameterStrings) {
+ String trimmedParameter = parameter.trim();
+ parameters.add(ClassName.parseName(trimmedParameter));
+ }
+ signature.setParameters(parameters);
+ }
+
+ }
+ return signature;
+ }
+
private void setRendererClass(CompositeInterface compositeInterface, RendererModel
renderer) {
- renderer.setRendererClass(compositeInterface.getJavaClass());
+ ClassName javaClass = compositeInterface.getJavaClass();
+ if (null != javaClass) {
+ renderer.setRendererClass(javaClass);
+ }
}
private void setRendererBaseClass(CompositeInterface compositeInterface,
RendererModel renderer) {
- renderer.setBaseClass(compositeInterface.getBaseClass());
+ ClassName baseClass = compositeInterface.getBaseClass();
+ if (null != baseClass) {
+ renderer.setBaseClass(baseClass);
+ }
}
private void setFamily(CompositeInterface compositeInterface, RendererModel renderer)
{
- renderer.setFamily(compositeInterface.getComponentFamily());
+ FacesId componentFamily = compositeInterface.getComponentFamily();
+ if (null != componentFamily) {
+ renderer.setFamily(componentFamily);
+ }
}
- private void setRendererType(Template template, CompositeInterface
compositeInterface, RendererModel renderer) {
- renderer.setId(compositeInterface.getRendererType());
+
+ private void setRendererType(CompositeInterface compositeInterface, RendererModel
renderer) {
+ FacesId rendererType = compositeInterface.getRendererType();
+ if (null != rendererType) {
+ renderer.setId(rendererType);
+ }
}
protected Template parseTemplate(File file) throws CdkException {
try {
- Template template = jaxbBinding.unmarshal(file,
"http://jboss.org/schema/richfaces/cdk/cdk-template.xsd", Template.class);
+ Template template =
+ jaxbBinding.unmarshal(file,
"http://jboss.org/schema/richfaces/cdk/cdk-template.xsd", Template.class);
template.setTemplatePath(file.getAbsolutePath());
return template;
} catch (FileNotFoundException e) {
throw new CdkException("Template file not found " +
file.getAbsolutePath(), e);
}
}
-
- public NamingConventions getNamingConventions() {
- if (namingConventions == null) {
- namingConventions = new RichFacesConventions();
- }
- return namingConventions;
- }
-
- public void setNamingConventions(NamingConventions namingConventions) {
- this.namingConventions = namingConventions;
- }
}
Modified:
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Attribute.java
===================================================================
---
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Attribute.java 2011-01-12
20:37:01 UTC (rev 20975)
+++
trunk/cdk/generator/src/main/java/org/richfaces/cdk/templatecompiler/model/Attribute.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -66,13 +66,13 @@
private String targets;
@XmlAttribute
- private boolean required;
+ private Boolean required;
@XmlAttribute
- private boolean preferred;
+ private Boolean preferred;
@XmlAttribute
- private boolean expert;
+ private Boolean expert;
@XmlAttribute
@XmlJavaTypeAdapter(ClassAdapter.class)
@@ -194,7 +194,7 @@
*
* @return the required
*/
- public boolean isRequired() {
+ public Boolean getRequired() {
return this.required;
}
@@ -203,7 +203,7 @@
*
* @param required the required to set
*/
- public void setRequired(boolean required) {
+ public void setRequired(Boolean required) {
this.required = required;
}
@@ -212,7 +212,7 @@
*
* @return the preffered
*/
- public boolean isPreferred() {
+ public Boolean getPreferred() {
return this.preferred;
}
@@ -221,7 +221,7 @@
*
* @param preffered the preffered to set
*/
- public void setPreferred(boolean preffered) {
+ public void setPreferred(Boolean preffered) {
this.preferred = preffered;
}
@@ -230,7 +230,7 @@
*
* @return the expert
*/
- public boolean isExpert() {
+ public Boolean getExpert() {
return this.expert;
}
@@ -239,7 +239,7 @@
*
* @param expert the expert to set
*/
- public void setExpert(boolean expert) {
+ public void setExpert(Boolean expert) {
this.expert = expert;
}
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.java 2011-01-12
20:37:01 UTC (rev 20975)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/model/validator/ModelValidatorTest.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -86,14 +86,12 @@
FacesId type = FacesId.parseId("foo.Bar");
component.setTargetClass(className);
expect(namiingConventions.inferComponentType(className)).andReturn(type);
- expect(namiingConventions.inferUIComponentFamily(type)).andReturn(FOO_BAZ);
expect(utils.isClassExists(className)).andReturn(true);
replay(log, utils, namiingConventions);
// Validator should set component type from base class.
validator.verifyComponentType(component);
verify(log, utils, namiingConventions);
assertEquals(type, component.getId());
- assertEquals(FOO_BAZ, component.getFamily());
}
}
Modified:
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java
===================================================================
---
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java 2011-01-12
20:37:01 UTC (rev 20975)
+++
trunk/cdk/generator/src/test/java/org/richfaces/cdk/templatecompiler/model/TemplateParserTest.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -91,9 +91,9 @@
assertNull(attribute.getMethodSignature());
assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
+ assertNull(attribute.getRequired());
+ assertNull(attribute.getExpert());
+ assertNull(attribute.getPreferred());
attribute = attributes.get(1);
assertNotNull(attribute);
@@ -102,9 +102,9 @@
assertNull(attribute.getMethodSignature());
assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
+ assertNull(attribute.getRequired());
+ assertNull(attribute.getExpert());
+ assertNull(attribute.getPreferred());
attribute = attributes.get(2);
assertNotNull(attribute);
@@ -113,9 +113,9 @@
assertEquals("void action()", attribute.getMethodSignature());
assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
+ assertNull(attribute.getRequired());
+ assertNull(attribute.getExpert());
+ assertNull(attribute.getPreferred());
attribute = attributes.get(3);
assertNotNull(attribute);
@@ -124,9 +124,9 @@
assertEquals("void changeListener(ValueChangeEvent)",
attribute.getMethodSignature());
assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
assertEquals("changes changes1", attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
+ assertNull(attribute.getRequired());
+ assertNull(attribute.getExpert());
+ assertNull(attribute.getPreferred());
attribute = attributes.get(4);
assertNotNull(attribute);
@@ -135,9 +135,9 @@
assertNull(attribute.getMethodSignature());
assertEquals(ClassName.parseName("boolean"), attribute.getType());
assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
+ assertNull(attribute.getRequired());
+ assertNull(attribute.getExpert());
+ assertNull(attribute.getPreferred());
attribute = attributes.get(5);
assertNotNull(attribute);
@@ -146,9 +146,9 @@
assertNull(attribute.getMethodSignature());
assertEquals(ClassName.parseName("java.lang.Integer"),
attribute.getType());
assertNull(attribute.getTargets());
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
+ assertNull(attribute.getRequired());
+ assertNull(attribute.getExpert());
+ assertNull(attribute.getPreferred());
attribute = attributes.get(6);
assertNotNull(attribute);
@@ -157,13 +157,13 @@
assertNull(attribute.getMethodSignature());
assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
assertNull(attribute.getTargets());
- assertTrue(attribute.isRequired());
- assertFalse(attribute.isExpert());
- assertFalse(attribute.isPreferred());
+ assertTrue(attribute.getRequired());
+ assertNull(attribute.getExpert());
+ assertNull(attribute.getPreferred());
attribute = attributes.get(7);
assertNotNull(attribute);
- assertFalse(attribute.isRequired());
+ assertNull(attribute.getRequired());
assertEquals("experts", attribute.getName());
assertNull(attribute.getDefaultValue());
assertNull(attribute.getMethodSignature());
@@ -171,20 +171,20 @@
assertNull(attribute.getTargets());
assertEquals("For use by experts", attribute.getShortDescription());
assertEquals("Expert attribute", attribute.getDisplayName());
- assertTrue(attribute.isExpert());
- assertFalse(attribute.isPreferred());
+ assertTrue(attribute.getExpert());
+ assertNull(attribute.getPreferred());
attribute = attributes.get(8);
assertNotNull(attribute);
- assertFalse(attribute.isRequired());
- assertFalse(attribute.isExpert());
+ assertNull(attribute.getRequired());
+ assertNull(attribute.getExpert());
assertEquals("preferred", attribute.getName());
assertNull(attribute.getDefaultValue());
assertNull(attribute.getMethodSignature());
assertEquals(DEFAULT_ATTRIBUTE_TYPE, attribute.getType());
assertEquals("It's a preferred attribute",
attribute.getShortDescription());
assertEquals("Preferred attribute", attribute.getDisplayName());
- assertTrue(attribute.isPreferred());
+ assertTrue(attribute.getPreferred());
attribute = attributes.get(9);
assertNotNull(attribute);
Modified:
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/component/AbstractTestComponent.java
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/component/AbstractTestComponent.java 2011-01-12
20:37:01 UTC (rev 20975)
+++
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/java/org/richfaces/cdk/test/component/AbstractTestComponent.java 2011-01-13
01:47:03 UTC (rev 20976)
@@ -72,6 +72,7 @@
@RendererSpecificComponent(type =
"org.richfaces.cdk.test.TestHtmlDfn",
tag=@Tag(name="dfn"),
generate="org.richfaces.cdk.test.component.html.HtmlTestDfn",
+ renderer=(a)JsfRenderer(template="/testComponent.xml"),
attributes="html5.xml")
}
)
Modified:
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml
===================================================================
---
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml 2011-01-12
20:37:01 UTC (rev 20975)
+++
trunk/cdk/maven-cdk-plugin/src/it/annotated-component/src/main/templates/testComponent.xml 2011-01-13
01:47:03 UTC (rev 20976)
@@ -18,7 +18,7 @@
<cc:attribute name="onlistclick" >
<cc:clientBehavior event="listclick"/>
</cc:attribute>
- <cc:attribute name="mode" default="ajax" />
+ <cc:attribute name="mode" default=""ajax""
/>
<cc:attribute name="action" method-signature="void action()"
/>
<cc:attribute name="changeListener"
method-signature="void changeListener(ValueChangeEvent)"
targets="changes changes1" />