Author: alexsmirnov
Date: 2010-05-03 20:42:31 -0400 (Mon, 03 May 2010)
New Revision: 16879
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.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/util/JavaUtils.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/BehaviorBean.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ComponentAdapter.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ComponentBean.java
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/ElementAdapterBase.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ElementBeanBase.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorBean.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/ComponentAdapterTest.java
Log:
Integration test generates components from annotations.
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.java 2010-05-03
22:32:23 UTC (rev 16878)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/processors/ComponentProcessor.java 2010-05-04
00:42:31 UTC (rev 16879)
@@ -81,6 +81,7 @@
// Should that component be generated ?
setClassNames(componentElement, component, annotation.generate());
setComponentProperties(componentElement, component, annotation);
+ library.getComponents().add(component);
// Process the second level annotations.
for (final SubComponent subcomponent : annotation.components()) {
@@ -88,10 +89,10 @@
ComponentModel subcomponentModel = new ComponentModel();
subcomponentModel.setBaseClass(component.getTargetClass());
subcomponentModel.setTargetClass(ClassName.parseName(subcomponent.generate()));
+ subcomponentModel.setGenerate(!Strings.isEmpty(subcomponent.generate()));
setComponentProperties(null, subcomponentModel, subAnnotation);
- }
-
- library.getComponents().add(component);
+ library.getComponents().add(subcomponentModel);
+ }
}
/**
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-05-03
22:32:23 UTC (rev 16878)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ModelElementBase.java 2010-05-04
00:42:31 UTC (rev 16879)
@@ -2,6 +2,7 @@
import java.util.Collection;
+import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
/**
@@ -20,7 +21,7 @@
private final ModelCollection<TagModel> tags =
ModelCollection.<TagModel>create();
- private final Collection<ClassName> interfaces = Sets.newHashSet();
+ private final Collection<ClassName> interfaces = Lists.newArrayList();
/**
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/JavaUtils.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/JavaUtils.java 2010-05-03
22:32:23 UTC (rev 16878)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/JavaUtils.java 2010-05-04
00:42:31 UTC (rev 16879)
@@ -201,13 +201,16 @@
for (PropertyDescriptor sourceProperty : sourceProperties) {
if (!JAXBBinding.IGNORE_PROPERTIES.contains(name) &&
name.equals(sourceProperty.getName())) {
-
+ try {
writeProperty(source, destination, targetProperty,
sourceProperty);
+ } catch (Exception e) {
+ throw new CdkException("Error on copying property
"+name+" from object "+source.getClass()+" to
"+destination.getClass(), e);
+ }
}
}
}
} catch (Exception e) {
- throw new CdkException("Properties copiing error", e);
+ throw new CdkException("Properties copying error", e);
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/BehaviorBean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/BehaviorBean.java 2010-05-03
22:32:23 UTC (rev 16878)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/BehaviorBean.java 2010-05-04
00:42:31 UTC (rev 16879)
@@ -22,23 +22,24 @@
package org.richfaces.cdk.xmlconfig.model;
+import java.util.Collection;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.richfaces.cdk.model.AttributeModel;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.PropertyModel;
-import org.richfaces.cdk.model.AttributeModel;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import java.util.List;
-
/**
* @author akolonitsky
* @since Jan 21, 2010
*/
@XmlType(name = "faces-config-behaviorType", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE,
- propOrder={"id", "targetClass", "attributes",
"properties", "extension"})
+ propOrder={"id", "targetClass", "facesAttributes",
"properties", "extension"})
@XmlJavaTypeAdapter(BehaviorAdapter.class)
public class BehaviorBean extends ElementBeanBase<BehaviorBean.BehaviorExtension>
{
@@ -58,15 +59,15 @@
@Override
@XmlElement(name = "property", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE, type = PropertyBean.class)
@XmlJavaTypeAdapter(PropertyAdapter.class)
- public List<PropertyModel> getProperties() {
+ public Collection<PropertyModel> getProperties() {
return super.getProperties();
}
@Override
@XmlElement(name = "attribute", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE, type = AttributeBean.class)
@XmlJavaTypeAdapter(AttributeAdapter.class)
- public List<AttributeModel> getAttributes() {
- return super.getAttributes();
+ public Collection<AttributeModel> getFacesAttributes() {
+ return super.getFacesAttributes();
}
@XmlElement(name = "behavior-class", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE)
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ComponentAdapter.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ComponentAdapter.java 2010-05-03
22:32:23 UTC (rev 16878)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ComponentAdapter.java 2010-05-04
00:42:31 UTC (rev 16879)
@@ -48,18 +48,4 @@
return ComponentModel.class;
}
- @Override
- protected void postMarshal(ComponentModel model, ComponentBean bean) {
- super.postMarshal(model, bean);
-// TODO
-// if(null != model.getRenderer()){
-//
bean.getExtension().setRendererType(model.getRenderer().getType().getType());
-// }
- }
-
- @Override
- protected void postUnmarshal(ComponentBean bean, ComponentModel model) {
- super.postUnmarshal(bean, model);
- // TODO set renderer from type.
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ComponentBean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ComponentBean.java 2010-05-03
22:32:23 UTC (rev 16878)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ComponentBean.java 2010-05-04
00:42:31 UTC (rev 16879)
@@ -23,20 +23,23 @@
package org.richfaces.cdk.xmlconfig.model;
-import com.google.common.collect.Lists;
+import java.util.Collection;
+import java.util.List;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlType;
+import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import org.richfaces.cdk.model.AttributeModel;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.EventModel;
import org.richfaces.cdk.model.FacesId;
import org.richfaces.cdk.model.FacetModel;
import org.richfaces.cdk.model.PropertyModel;
-import org.richfaces.cdk.model.AttributeModel;
import org.richfaces.cdk.model.TagModel;
-import javax.xml.bind.annotation.XmlElement;
-import javax.xml.bind.annotation.XmlType;
-import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
-import java.util.List;
+import com.google.common.collect.Lists;
/**
* <p class="changed_added_4_0"></p>
@@ -44,7 +47,7 @@
* @author asmirnov(a)exadel.com
*/
@XmlType(name = "faces-config-componentType", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE,
- propOrder={"type", "targetClass", "facets",
"attributes", "properties", "extension"})
+ propOrder={"type", "targetClass", "facets",
"facesAttributes", "properties", "extension"})
@XmlJavaTypeAdapter(ComponentAdapter.class)
public class ComponentBean extends
ElementBeanBase<ComponentBean.ComponentExtension> {
@@ -74,15 +77,15 @@
@Override
@XmlElement(name = "property", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE, type = PropertyBean.class)
@XmlJavaTypeAdapter(PropertyAdapter.class)
- public List<PropertyModel> getProperties() {
+ public Collection<PropertyModel> getProperties() {
return super.getProperties();
}
@Override
@XmlElement(name = "attribute", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE, type = AttributeBean.class)
@XmlJavaTypeAdapter(AttributeAdapter.class)
- public List<AttributeModel> getAttributes() {
- return super.getAttributes();
+ public Collection<AttributeModel> getFacesAttributes() {
+ return super.getFacesAttributes();
}
/**
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-05-03
22:32:23 UTC (rev 16878)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ConverterBean.java 2010-05-04
00:42:31 UTC (rev 16879)
@@ -30,6 +30,8 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import java.util.Collection;
import java.util.List;
/**
@@ -37,7 +39,7 @@
* @since Jan 6, 2010
*/
@XmlType(name = "faces-config-converterType", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE,
- propOrder={"id", "converterForClass", "targetClass",
"attributes", "properties", "extension"})
+ propOrder={"id", "converterForClass", "targetClass",
"facesAttributes", "properties", "extension"})
@XmlJavaTypeAdapter(ConverterAdapter.class)
public class ConverterBean extends
ElementBeanBase<ConverterBean.ConverterExtension> {
@@ -60,15 +62,15 @@
@Override
@XmlElement(name = "property", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE, type = PropertyBean.class)
@XmlJavaTypeAdapter(PropertyAdapter.class)
- public List<PropertyModel> getProperties() {
+ public Collection<PropertyModel> getProperties() {
return super.getProperties();
}
@Override
@XmlElement(name = "attribute", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE, type = AttributeBean.class)
@XmlJavaTypeAdapter(AttributeAdapter.class)
- public List<AttributeModel> getAttributes() {
- return super.getAttributes();
+ public Collection<AttributeModel> getFacesAttributes() {
+ return super.getFacesAttributes();
}
@XmlElement(name = "converter-for-class", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE)
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ElementAdapterBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ElementAdapterBase.java 2010-05-03
22:32:23 UTC (rev 16878)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ElementAdapterBase.java 2010-05-04
00:42:31 UTC (rev 16879)
@@ -33,15 +33,5 @@
*/
public abstract class ElementAdapterBase<Bean extends ElementBeanBase, Model extends
BeanModelBase> extends AdapterBase<Bean, Model> {
- @Override
- protected void postUnmarshal(Bean bean, Model model) {
- model.addAttributes(bean.getAllProperties());
- }
-
- @Override
- protected void postMarshal(Model model, Bean bean) {
- bean.setAttributes(new ArrayList<AttributeModel>());
- bean.setAllProperties(new
ArrayList<org.richfaces.cdk.model.PropertyBase>(model.getAttributes()));
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ElementBeanBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ElementBeanBase.java 2010-05-03
22:32:23 UTC (rev 16878)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ElementBeanBase.java 2010-05-04
00:42:31 UTC (rev 16879)
@@ -22,67 +22,62 @@
package org.richfaces.cdk.xmlconfig.model;
-import com.google.common.collect.Lists;
+import java.util.Collection;
+
import org.richfaces.cdk.model.AttributeModel;
import org.richfaces.cdk.model.ConfigExtension;
-import org.richfaces.cdk.model.PropertyModel;
import org.richfaces.cdk.model.PropertyBase;
+import org.richfaces.cdk.model.PropertyModel;
-import java.util.ArrayList;
-import java.util.List;
+import com.google.common.base.Predicate;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.Lists;
/**
* TODO - is the tho different collections are necessary ?
* @author akolonitsky
* @since Mar 19, 2010
*/
+@SuppressWarnings("unchecked")
public abstract class ElementBeanBase<E extends ConfigExtension> extends
ExtensibleBean<E> {
- private List<PropertyModel> properties = Lists.newArrayList();
+ private static final Predicate<PropertyBase> propertyPredicate = new
Predicate<PropertyBase>() {
+ @Override
+ public boolean apply(PropertyBase input) {
+ return input instanceof PropertyModel;
+ }
+ };
- private List<AttributeModel> attributes = Lists.newArrayList();
+ private static final Predicate<PropertyBase> attributePredicate = new
Predicate<PropertyBase>() {
+ @Override
+ public boolean apply(PropertyBase input) {
+ return input instanceof AttributeModel;
+ }
+ };
- public List<PropertyModel> getProperties() {
+ private Collection<? extends PropertyBase> attributes = Lists.newArrayList();
+
+ private Collection<PropertyModel> properties =
(Collection<PropertyModel>) Collections2.filter(attributes, propertyPredicate);
+
+ private Collection<AttributeModel> facesAttributes =
(Collection<AttributeModel>) Collections2.filter(attributes, attributePredicate);
+
+ public Collection<PropertyModel> getProperties() {
return properties;
}
- public void setProperties(List<PropertyModel> properties) {
- this.properties = properties;
- }
- public List<AttributeModel> getAttributes() {
- return this.attributes;
+ public Collection<AttributeModel> getFacesAttributes() {
+ return this.facesAttributes;
}
- public void addAttributes(List<AttributeModel> attributes) {
- if (attributes == null) {
- return;
- }
- for (AttributeModel attribute : attributes) {
-// this.attributes.
- }
+ public Collection<PropertyBase> getAttributes() {
+ return (Collection<PropertyBase>) attributes;
}
- public void setAttributes(List<AttributeModel> attributes) {
+ public void setAttributes(Collection<PropertyBase> attributes) {
this.attributes = attributes;
+ properties = (Collection<PropertyModel>)
Collections2.filter(this.attributes, propertyPredicate);
+ facesAttributes = (Collection<AttributeModel>)
Collections2.filter(this.attributes, attributePredicate);
}
-
- public List<PropertyBase> getAllProperties() {
- List<PropertyBase> allProperties = new
ArrayList<PropertyBase>(attributes.size() + properties.size());
- allProperties.addAll(attributes);
- allProperties.addAll(properties);
- return allProperties;
- }
-
- public void setAllProperties(List<PropertyBase> allProperties) {
- for (PropertyBase propertyBase : allProperties) {
- if (propertyBase instanceof PropertyModel) {
- properties.add((PropertyModel) propertyBase);
- }
- if (propertyBase instanceof AttributeModel) {
- attributes.add((AttributeModel) propertyBase);
- }
- }
- }
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorBean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorBean.java 2010-05-03
22:32:23 UTC (rev 16878)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ValidatorBean.java 2010-05-04
00:42:31 UTC (rev 16879)
@@ -30,6 +30,8 @@
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlType;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
+
+import java.util.Collection;
import java.util.List;
/**
@@ -37,7 +39,7 @@
* @since Jan 13, 2010
*/
@XmlType(name = "faces-config-validatorType", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE,
- propOrder={"id", "targetClass", "attributes",
"properties", "extension"})
+ propOrder={"id", "targetClass", "facesAttributes",
"properties", "extension"})
@XmlJavaTypeAdapter(ValidatorAdapter.class)
public class ValidatorBean extends
ElementBeanBase<ValidatorBean.ValidatorExtension> {
@@ -59,15 +61,15 @@
@Override
@XmlElement(name = "property", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE, type = PropertyBean.class)
@XmlJavaTypeAdapter(PropertyAdapter.class)
- public List<PropertyModel> getProperties() {
+ public Collection<PropertyModel> getProperties() {
return super.getProperties();
}
@Override
@XmlElement(name = "attribute", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE, type = AttributeBean.class)
@XmlJavaTypeAdapter(AttributeAdapter.class)
- public List<AttributeModel> getAttributes() {
- return super.getAttributes();
+ public Collection<AttributeModel> getFacesAttributes() {
+ return super.getFacesAttributes();
}
@XmlElement(name = "validator-class", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE)
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/ComponentAdapterTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/ComponentAdapterTest.java 2010-05-03
22:32:23 UTC (rev 16878)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/ComponentAdapterTest.java 2010-05-04
00:42:31 UTC (rev 16879)
@@ -34,7 +34,7 @@
ComponentBean componentBean = componentAdapter.marshal(component);
assertEquals(FOO_BAR, componentBean.getType().toString());
- Collection<PropertyBase> attributes = componentBean.getAllProperties();
+ Collection<PropertyBase> attributes = componentBean.getAttributes();
assertEquals(1, attributes.size());
assertEquals(BAZ, Iterables.getOnlyElement(attributes).getName());