Author: alexsmirnov
Date: 2010-03-05 19:18:24 -0500 (Fri, 05 Mar 2010)
New Revision: 16532
Added:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BeanModelBase.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/FacesId.java
Removed:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyMapModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Attributable.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Key.java
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/TagTemplateModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BehaviorModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BehaviorRenderer.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/ListenerModel.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/model/RenderKitModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/RendererModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateVisitorFactory.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/ComparatorUtils.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/AttributeBean.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/PropertyBean.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/taglib/TaglibTestBase.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/taglib/ValidatorTagGeneratorTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ModelBean.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JAXBCopyTest.java
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/TaglibGeneratorVisitorTest.java
Log:
CODING IN PROGRESS - issue RF-7736: Library model verifier.
https://jira.jboss.org/jira/browse/RF-7736
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ComponentProcessor.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -208,7 +208,7 @@
for (String attributesConfig : attributes.value()) {
// process additional properties.
- component.getAttributes().putAll(parseProperties(attributesConfig));
+ component.getAttributes().addAll(parseProperties(attributesConfig));
}
}
@@ -218,7 +218,7 @@
@Override
public void visit(ClassName type) {
try {
- component.getAttributes().putAll(
+ component.getAttributes().addAll(
parseProperties(CdkEntityResolver.URN_ATTRIBUTES +
type.toString() + ".xml"));
} catch (CdkException e) {
// TODO - log errors ?
@@ -234,7 +234,7 @@
continue;
}
- Property attribute = component.addAttribute(beanProperty.getName());
+ Property attribute = component.getOrCreateAttribute(beanProperty.getName());
// Documentation
attribute.setDescription(beanProperty.getDocComment());
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/apt/ProcessorBase.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -16,6 +16,8 @@
import javax.lang.model.type.MirroredTypeException;
import javax.lang.model.type.MirroredTypesException;
import javax.lang.model.type.TypeMirror;
+
+import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -96,8 +98,8 @@
return true;
}
- for (Map.Entry<String, Property> entry : model.getAttributes().entrySet())
{
- if (entry.getValue().isBingingAttribute()) {
+ for (Property entry : model.getAttributes()) {
+ if (entry.isBindingAttribute()) {
return true;
}
}
@@ -211,7 +213,7 @@
}
}
- protected Map<String, Property> parseProperties(String attributesConfig) {
+ protected Collection<Property> parseProperties(String attributesConfig) {
return getFragmentParser().parseProperties(CdkEntityResolver.URN_ATTRIBUTES +
attributesConfig + ".xml");
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/ModelElementBaseTemplateModel.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -107,7 +107,7 @@
if (null == eventNames) {
eventNames = Sets.newHashSet();
- for (Property property : model.getAttributes().values()) {
+ for (Property property : model.getAttributes()) {
eventNames.addAll(property.getEventNames());
}
}
@@ -116,20 +116,21 @@
}
private TemplateModel generatedAttributes() throws TemplateModelException {
- Map<String, Property> attributes = model.getAttributes();
+ Collection<Property> attributes = model.getAttributes();
Collection<PropertyModel> models = new
ArrayList<PropertyModel>(attributes.size());
- for (Map.Entry<String, Property> entry : attributes.entrySet()) {
- if (entry.getValue().isGenerate()) {
- models.add(new PropertyModel(entry.getKey(), entry.getValue(),
wrapper));
+ for (Property entry : attributes) {
+ if (entry.isGenerate() ) {
+ PropertyModel propertyModel = new PropertyModel(entry, wrapper);
+ models.add(propertyModel);
}
}
return wrapper.wrap(models);
}
private TemplateModel attributes() throws TemplateModelException {
- Map<String, Property> attributes = model.getAttributes();
+ Collection<Property> attributes = model.getAttributes();
Collection<PropertyModel> models = new
ArrayList<PropertyModel>(attributes.size());
- for (Map.Entry<String, Property> entry : attributes.entrySet()) {
- models.add(new PropertyModel(entry.getKey(), entry.getValue(), wrapper));
+ for (Property entry : attributes) {
+ models.add(new PropertyModel(entry, wrapper));
}
return wrapper.wrap(models);
}
Deleted:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyMapModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyMapModel.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyMapModel.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -1,75 +0,0 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.freemarker;
-
-import java.util.List;
-import java.util.Map;
-
-import org.richfaces.cdk.model.Property;
-
-import freemarker.ext.beans.BeansWrapper;
-import freemarker.ext.beans.MapModel;
-import freemarker.template.TemplateModel;
-import freemarker.template.TemplateModelException;
-
-/**
- * <p class="changed_added_4_0"></p>
- * @author asmirnov(a)exadel.com
- *
- */
-public class PropertyMapModel extends MapModel {
-
- private final Map<String, Property> map;
-
- /**
- * <p class="changed_added_4_0"></p>
- * @param map
- * @param wrapper
- */
- public PropertyMapModel(Map<String,Property> map, BeansWrapper wrapper) {
- super(map, wrapper);
- this.map = map;
- }
-
- @Override
- public TemplateModel get(String key) throws TemplateModelException {
- Property property = map.get(key);
- if(null != property){
- return new PropertyModel(key.toString(), property, wrapper);
- }
- return super.get(key);
- }
-
-
-
- @Override
- public Object exec(List arguments) throws TemplateModelException {
- Object key = unwrap((TemplateModel)arguments.get(0));
- Property property = map.get(key);
- if(null != property){
- return new PropertyModel(key.toString(), property, wrapper);
- }
- return super.exec(arguments);
- }
-}
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-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/PropertyModel.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -40,7 +40,6 @@
*/
public class PropertyModel extends BeanModel implements TemplateModel {
private final Property property;
- private final String name;
/**
* <p class="changed_added_4_0"></p>
@@ -48,9 +47,8 @@
* @param object
* @param wrapper
*/
- public PropertyModel(String name, Property object, BeansWrapper wrapper) {
+ public PropertyModel(Property object, BeansWrapper wrapper) {
super(object, wrapper);
- this.name = name;
property = object;
}
@@ -59,7 +57,7 @@
* @return the name
*/
public String getName() {
- return this.name;
+ return property.getName();
}
@Override
@@ -98,11 +96,11 @@
}
public boolean isBingingAttribute() {
- return this.property.isBingingAttribute();
+ return this.property.isBindingAttribute();
}
public boolean isBinging() {
- return this.property.isBinging();
+ return this.property.isBinding();
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/TagTemplateModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/TagTemplateModel.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/freemarker/TagTemplateModel.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -117,7 +117,7 @@
if (null == eventNames) {
eventNames = Sets.newHashSet();
- for (Property property : model.getModel().getAttributes().values()) {
+ for (Property property : model.getModel().getAttributes()) {
eventNames.addAll(property.getEventNames());
}
}
@@ -126,23 +126,21 @@
}
private TemplateModel generatedAttributes() throws TemplateModelException {
- Map<String, Property> attributes = model.getModel().getAttributes();
+ Collection<Property> attributes = model.getModel().getAttributes();
Collection<PropertyModel> models = new
ArrayList<PropertyModel>(attributes.size());
- for (Map.Entry<String, Property> entry : attributes.entrySet()) {
- if (entry.getValue().isGenerate()) {
- PropertyModel propertyModel = new PropertyModel(entry.getKey(),
entry.getValue(), wrapper);
- if (propertyModel.isBingingAttribute()) {
+ for (Property entry : attributes) {
+ if (entry.isGenerate() && entry.isBindingAttribute()) {
+ PropertyModel propertyModel = new PropertyModel(entry, wrapper);
models.add(propertyModel);
- }
}
}
return wrapper.wrap(models);
}
private TemplateModel attributes() throws TemplateModelException {
- Map<String, Property> attributes = model.getModel().getAttributes();
+ Collection<Property> attributes = model.getModel().getAttributes();
Collection<PropertyModel> models = new
ArrayList<PropertyModel>(attributes.size());
- for (Map.Entry<String, Property> entry : attributes.entrySet()) {
- models.add(new PropertyModel(entry.getKey(), entry.getValue(), wrapper));
+ for (Property entry : attributes) {
+ models.add(new PropertyModel(entry, wrapper));
}
return wrapper.wrap(models);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/generate/taglib/TaglibGeneratorVisitor.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -124,9 +124,9 @@
}
- private void appendAttributs(Element tag, Attributable model) {
- for (Map.Entry<String, Property> entry : model.getAttributes().entrySet())
{
- createAttributeElement(tag, entry.getKey(), entry.getValue());
+ private void appendAttributs(Element tag, BeanModelBase model) {
+ for (Property entry : model.getAttributes()) {
+ createAttributeElement(tag, entry.getName(), entry);
}
}
Deleted:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Attributable.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Attributable.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Attributable.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -1,61 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright , Red Hat, Inc. and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.richfaces.cdk.model;
-
-import java.util.Map;
-
-/**
- * @author akolonitsky
- * @since Jan 22, 2010
- *
- * Please rename it with more suitable name
- */
-public class Attributable extends DescriptionGroupBase {
-
- private final ModelMap<String,Property> attributes =
ModelMap.<String,Property>create();
-
- /**
- * <p class="changed_added_4_0">
- * Represents JSF component attributes and properties.
- * </p>
- *
- * @return the attributes
- */
- public Map<String,Property> getAttributes() {
- return attributes;
- }
-
- public Property getAttribute(String name) {
- return attributes.get(name);
- }
-
- public Property addAttribute(String attributeName) {
- Property attribute = attributes.get(attributeName);
- if (null == attribute) {
- attribute = new Property();
- attributes.put(attributeName, attribute);
- }
-
- return attribute;
- }
-}
Copied:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BeanModelBase.java
(from rev 16531,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Attributable.java)
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BeanModelBase.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BeanModelBase.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -0,0 +1,75 @@
+/*
+ * 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.model;
+
+import java.util.Collection;
+
+import org.richfaces.cdk.util.ComparatorUtils;
+
+/**
+ * This is the base class for all Java Bean-like JSF objects in the model.
+ * @author akolonitsky
+ * @since Jan 22, 2010
+ *
+ */
+public class BeanModelBase extends DescriptionGroupBase {
+
+ private final ModelCollection<Property> attributes =
ModelCollection.<Property>create();
+
+ /**
+ * <p class="changed_added_4_0">
+ * Represents JSF component attributes and properties.
+ * </p>
+ *
+ * @return the attributes
+ */
+ public Collection<Property> getAttributes() {
+ return attributes;
+ }
+
+ /**
+ * <p class="changed_added_4_0">Return bean attribute for given
name.</p>
+ * @param name
+ * @return
+ */
+ public Property getAttribute(String name) {
+ // OPTIMIZATION keep HashMap for name-property pair for fast lookup.
+ for (Property property : attributes) {
+ if(ComparatorUtils.nullSafeEquals(property.getName(), name)){
+ return property;
+ }
+ }
+ return null;
+ }
+
+ public Property getOrCreateAttribute(String attributeName) {
+ Property attribute = getAttribute(attributeName);
+ if (null == attribute) {
+ attribute = new Property();
+ attribute.setName(attributeName);
+ attributes.add(attribute);
+ }
+
+ return attribute;
+ }
+}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BehaviorModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BehaviorModel.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BehaviorModel.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -62,9 +62,8 @@
@Override
public void merge(BehaviorModel other) {
+ ComponentLibrary.merge(getAttributes(),other.getAttributes());
ComponentLibrary.merge(this, other);
-
- getAttributes().putAll(other.getAttributes());
}
@Override
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BehaviorRenderer.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BehaviorRenderer.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/BehaviorRenderer.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -109,7 +109,7 @@
*
*/
@SuppressWarnings("serial")
- public static final class Type extends Key {
+ public static final class Type extends FacesId {
/**
* <p class="changed_added_4_0"></p>
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-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ComponentModel.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -70,7 +70,7 @@
@Override
public void merge(ComponentModel otherComponent) {
//merge facets, renderers, events ...
- getAttributes().putAll(otherComponent.getAttributes());
+ ComponentLibrary.merge(getAttributes(),otherComponent.getAttributes());
facets.putAll(otherComponent.getFacets());
ComponentLibrary.merge(events, otherComponent.getEvents());
ComponentLibrary.merge(renderers, otherComponent.getRenderers());
@@ -183,7 +183,7 @@
return renderers;
}
- public static class Type extends Key {
+ public static class Type extends FacesId {
private static final long serialVersionUID = -6968199073379187423L;
public Type(String 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-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ConverterModel.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -76,9 +76,8 @@
@Override
public void merge(ConverterModel other) {
+ ComponentLibrary.merge(getAttributes(),other.getAttributes());
ComponentLibrary.merge(this, other);
-
- getAttributes().putAll(other.getAttributes());
}
@Override
Copied:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/FacesId.java (from
rev 16531,
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Key.java)
===================================================================
--- root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/FacesId.java
(rev 0)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/FacesId.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -0,0 +1,105 @@
+/*
+ * $Id$
+ *
+ * License Agreement.
+ *
+ * Rich Faces - Natural Ajax for Java Server Faces (JSF)
+ *
+ * Copyright (C) 2007 Exadel, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+package org.richfaces.cdk.model;
+
+import java.io.Serializable;
+
+/**
+ * <p class="changed_added_4_0">This is a FacesId class that should be
used to find JSF elements in {@link ComponentLibrary}</p>
+ *
+ * @author asmirnov(a)exadel.com
+ */
+public class FacesId implements Serializable {
+ private static final long serialVersionUID = -8199984910177820771L;
+
+ private final String type;
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ *
+ * @param type
+ */
+ public FacesId(String type) {
+ this.type = type;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ *
+ * @return the type
+ */
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public String toString() {
+ return type;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#hashCode()
+ */
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+
+ result = prime * result + ((type == null) ? 0 : type.hashCode());
+
+ return result;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see java.lang.Object#equals(java.lang.Object)
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+
+ if (obj == null) {
+ return false;
+ }
+
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+
+ FacesId other = (FacesId) obj;
+
+ if (type == null) {
+ if (other.type != null) {
+ return false;
+ }
+ } else if (!type.equals(other.type)) {
+ return false;
+ }
+
+ return true;
+ }
+}
Property changes on:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/FacesId.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ LastChangedDate LastChangedRevision LastChangedBy HeadURL Id
Deleted: root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Key.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Key.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Key.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -1,105 +0,0 @@
-/*
- * $Id$
- *
- * License Agreement.
- *
- * Rich Faces - Natural Ajax for Java Server Faces (JSF)
- *
- * Copyright (C) 2007 Exadel, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License version 2.1 as published by the Free Software Foundation.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-package org.richfaces.cdk.model;
-
-import java.io.Serializable;
-
-/**
- * <p class="changed_added_4_0">This is a Key class that should be used
to find JSF elements in {@link ComponentLibrary}</p>
- *
- * @author asmirnov(a)exadel.com
- */
-public class Key implements Serializable {
- private static final long serialVersionUID = -8199984910177820771L;
-
- private final String type;
-
- /**
- * <p class="changed_added_4_0"></p>
- *
- * @param type
- */
- public Key(String type) {
- this.type = type;
- }
-
- /**
- * <p class="changed_added_4_0"></p>
- *
- * @return the type
- */
- public String getType() {
- return type;
- }
-
- @Override
- public String toString() {
- return type;
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
-
- result = prime * result + ((type == null) ? 0 : type.hashCode());
-
- return result;
- }
-
- /*
- * (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
-
- if (obj == null) {
- return false;
- }
-
- if (getClass() != obj.getClass()) {
- return false;
- }
-
- Key other = (Key) obj;
-
- if (type == null) {
- if (other.type != null) {
- return false;
- }
- } else if (!type.equals(other.type)) {
- return false;
- }
-
- return true;
- }
-}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ListenerModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ListenerModel.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ListenerModel.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -83,7 +83,7 @@
return equals(other);
}
- public static final class Type extends Key {
+ public static final class Type extends FacesId {
public Type(String name) {
super(name);
}
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-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ModelElementBase.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -6,7 +6,7 @@
* @author asmirnov(a)exadel.com
*
*/
-public class ModelElementBase extends Attributable {
+public class ModelElementBase extends BeanModelBase {
private String id;
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-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/Property.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -27,6 +27,7 @@
import java.util.Set;
import org.richfaces.cdk.CdkException;
+import org.richfaces.cdk.util.ComparatorUtils;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
@@ -40,21 +41,30 @@
private static final long serialVersionUID = 3483864006602184580L;
+ /**
+ * <p class="changed_added_4_0">The name of bean property</p>
+ */
+ private String name;
+
private boolean hidden = false;
private boolean literal = false;
private boolean required = false;
private boolean readOnly = false;
private boolean passThrough = false;
- //TODO nick - ordering seems to be important!
private Set<EventName> eventNames = Sets.newLinkedHashSet();
private List<ClassName> signature = Lists.newArrayList();
private Set<String> aliases = Sets.newHashSet();
private String defaultValue;
private String suggestedValue;
+
private ClassName type;
+ private boolean bindingAttribute;
+
+ private boolean binding;
+
/**
* <p class="changed_added_4_0"></p>
*/
@@ -63,6 +73,22 @@
/**
* <p class="changed_added_4_0"></p>
+ * @return the name
+ */
+ public String getName() {
+ return this.name;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param name the name to set
+ */
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ /**
+ * <p class="changed_added_4_0"></p>
* @return the type
*/
@Merge
@@ -264,47 +290,32 @@
@Override
public boolean same(Property other) {
- return this == other;
+ return ComparatorUtils.nullSafeEquals(this.getName(), other.getName());
}
- public boolean isBingingAttribute() {
- return isBinging() || isInstanceof("javax.el.MethodExpression");
+ public boolean isBindingAttribute() {
+ return this.bindingAttribute;
}
- public boolean isBinging() {
- return isInstanceof("javax.faces.el.MethodBinding");
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param bindingAttribute the bindingAttribute to set
+ */
+ public void setBindingAttribute(boolean bindingAttribute) {
+ this.bindingAttribute = bindingAttribute;
}
- public boolean isInstanceof(String name) {
- String classname = getType().getName();
- if (null == classname) {
- String msg = "classname not set in " + getClass().getName() +
" for element " + name;
-// getLog().error(msg);
- throw new NullPointerException(msg);
- }
-
- if (classname.equals(name)) {
- return true;
- }
-
- try {
- if (!new ClassName(classname).isPrimitive()) {
- Class<?> beanClass = getLoader().loadClass(classname);
- Class<?> superClass = getLoader().loadClass(name);
- return superClass.isAssignableFrom(beanClass);
- }
- } catch (ClassNotFoundException e) {
- e.printStackTrace();
-// getLog().warn("Could't instantiate for testing class " +
classname);
- } catch (Exception e) {
-// getLog().warn("Error in testing class " + classname);
- e.printStackTrace();
- }
- return false;
+ public boolean isBinding() {
+ return this.binding;
}
- private ClassLoader getLoader() {
- return Thread.currentThread().getContextClassLoader(); // TODO ???
+ /**
+ * <p class="changed_added_4_0"></p>
+ * @param binding the binding to set
+ */
+ public void setBinding(boolean binding) {
+ this.binding = binding;
}
+
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/RenderKitModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/RenderKitModel.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/RenderKitModel.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -113,7 +113,7 @@
* @author asmirnov(a)exadel.com
*
*/
- public static final class Id extends Key {
+ public static final class Id extends FacesId {
private static final long serialVersionUID = 9169827614943311779L;
/**
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/RendererModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/RendererModel.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/RendererModel.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -34,7 +34,7 @@
*
*/
//@SuppressWarnings("serial")
-public class RendererModel extends Attributable implements
ModelElement<RendererModel> {
+public class RendererModel extends BeanModelBase implements
ModelElement<RendererModel> {
private static final long serialVersionUID = -5802466539382148578L;
@@ -187,11 +187,11 @@
}
/**
- * <p class="changed_added_4_0">Key for lookup renderer in the
model.</p>
+ * <p class="changed_added_4_0">FacesId for lookup renderer in the
model.</p>
* @author asmirnov(a)exadel.com
*
*/
- public static class Type extends Key {
+ public static class Type extends FacesId {
private static final long serialVersionUID = -7819560321446149642L;
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/ValidatorModel.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -64,9 +64,8 @@
@Override
public void merge(ValidatorModel other) {
+ ComponentLibrary.merge(getAttributes(),other.getAttributes());
ComponentLibrary.merge(this, other);
-
- getAttributes().putAll(other.getAttributes());
}
@Override
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/model/validator/ValidatorImpl.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -34,6 +34,7 @@
import org.richfaces.cdk.apt.SourceUtils;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
+import org.richfaces.cdk.model.Property;
import org.richfaces.cdk.model.RenderKitModel;
import org.richfaces.cdk.model.RendererModel;
@@ -135,10 +136,19 @@
component.setFamily(namingConventions.inferUIComponentFamily(component.getType()));
}
// Check attributes.
+ for (Property attribute : component.getAttributes()) {
+ verifyAttribute(attribute);
+ }
+ // compact(component.getAttributes());
// Check renderers.
-// compact(component.getAttributes());
+ // Check Tag
}
+ protected void verifyAttribute(Property attribute) {
+ // Check name.
+ // Check binding properties.
+
+ }
protected void compact(Collection<?> collection) {
// if (collection instanceof ModelCollection) {
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassGenerator.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -37,6 +37,7 @@
import org.richfaces.cdk.Outputs;
import org.richfaces.cdk.model.ComponentLibrary;
import org.richfaces.cdk.model.ComponentModel;
+import org.richfaces.cdk.model.ModelCollection;
import org.richfaces.cdk.model.Property;
import org.richfaces.cdk.model.RenderKitModel;
import org.richfaces.cdk.model.RendererModel;
@@ -118,15 +119,15 @@
for (RendererModel renderer : renderKit.getRenderers()) {
Template template = renderer.getTemplate();
if (null != template) {
- Map<String, Property> attributesMap = Maps.newHashMap();
+ Collection<Property> attributes =
ModelCollection.<Property>create();
ComponentModel component = findComponentByRenderer(renderer);
if (component != null) {
- attributesMap.putAll(component.getAttributes());
+ attributes.addAll(component.getAttributes());
}
- attributesMap.putAll(renderer.getAttributes());
- RendererClassVisitor visitor =
visitorFactory.createVisitor(template.getInterface(), attributesMap);
+ attributes.addAll(renderer.getAttributes());
+ RendererClassVisitor visitor =
visitorFactory.createVisitor(template.getInterface(), attributes);
try {
// TODO - put real parameters.
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererClassVisitor.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -79,6 +79,7 @@
import org.richfaces.cdk.templatecompiler.model.CompositeInterface;
import org.richfaces.cdk.templatecompiler.model.Template;
import org.richfaces.cdk.templatecompiler.model.TemplateVisitor;
+import org.richfaces.cdk.util.ComparatorUtils;
import org.richfaces.cdk.util.Strings;
import org.richfaces.cdk.xmlconfig.JAXB;
@@ -160,9 +161,9 @@
private Type lastCompiledExpressionType;
private int passThroughCounter;
- private Map<String, Property> attributes;
+ private Collection<Property> attributes;
- public RendererClassVisitor(CompositeInterface compositeInterface, Map<String,
Property> attributes,
+ public RendererClassVisitor(CompositeInterface compositeInterface,
Collection<Property> attributes,
ClassLoader classLoader, JAXB jaxbBinding, Logger log) {
this.compositeInterface = compositeInterface;
this.attributes = attributes;
@@ -294,24 +295,24 @@
sb.append(")");
}
- Property property = attributes.get(attributeName);
- if (property != null) {
- Set<EventName> eventNames = property.getEventNames();
- if (eventNames != null && !eventNames.isEmpty()) {
- sb.append(".setEventNames(");
- sb.append("new String[] {");
-
- Collection<String> eventNamesStrings =
Collections2.transform(eventNames,
- new Function<EventName, String>() {
- @Override
- public String apply(EventName from) {
- return from.getName();
- }
- });
-
- sb.append(getEscapedStringsArray(eventNamesStrings));
-
- sb.append("})");
+ // OPTIMIZATION - use ModelCollection with lookup method
+ for (Property property : attributes) {
+ if(attributeName.equals(property.getName())){
+ Set<EventName> eventNames = property.getEventNames();
+ if (eventNames != null && !eventNames.isEmpty()) {
+ sb.append(".setEventNames(");
+ sb.append("new String[] {");
+ Collection<String> eventNamesStrings =
Collections2.transform(eventNames,
+ new Function<EventName, String>() {
+ @Override
+ public String apply(EventName from) {
+ return from.getName();
+ }
+ });
+ sb.append(getEscapedStringsArray(eventNamesStrings));
+ sb.append("})");
+ }
+ break;
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/RendererTemplateParser.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -180,15 +180,15 @@
renderer.setRendersChildren(rendersChildren.booleanValue());
}
- Map<String, Property> rendererAttributes = renderer.getAttributes();
+ Collection<Property> rendererAttributes = renderer.getAttributes();
List<ImportAttributes> attributesImports =
compositeInterface.getAttributesImports();
if (attributesImports != null) {
for (ImportAttributes attributesImport : attributesImports) {
String importURI = attributesImport.getSource();
- Map<String, Property> properties =
fragmentParser.parseProperties(importURI);
+ Collection<Property> properties =
fragmentParser.parseProperties(importURI);
if (properties != null) {
- rendererAttributes.putAll(properties);
+ rendererAttributes.addAll(properties);
}
}
}
@@ -197,6 +197,7 @@
if (templateAttributes != null) {
for (Attribute templateAttribute : templateAttributes) {
Property rendererProperty = new Property();
+ rendererProperty.setName(templateAttribute.getName());
rendererProperty.setDefaultValue(templateAttribute.getDefaultValue());
// TODO is it the right one?
@@ -230,7 +231,7 @@
rendererProperty.setType(new ClassName(templateAttributeType));
}
- rendererAttributes.put(templateAttribute.getName(), rendererProperty);
+ rendererAttributes.add(rendererProperty);
}
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateVisitorFactory.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateVisitorFactory.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/TemplateVisitorFactory.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -23,6 +23,7 @@
package org.richfaces.cdk.templatecompiler;
+import java.util.Collection;
import java.util.Map;
import org.richfaces.cdk.model.Property;
@@ -36,6 +37,6 @@
*/
public interface TemplateVisitorFactory <T extends TemplateVisitor> {
- public T createVisitor(CompositeInterface composite,Map<String, Property>
attributes);
+ public T createVisitor(CompositeInterface composite,Collection<Property>
attributes);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/templatecompiler/VisitorFactoryImpl.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -23,7 +23,7 @@
package org.richfaces.cdk.templatecompiler;
-import java.util.Map;
+import java.util.Collection;
import org.richfaces.cdk.CdkClassLoader;
import org.richfaces.cdk.Logger;
@@ -61,7 +61,7 @@
* @see
org.richfaces.cdk.templatecompiler.TemplateVisitorFactory#createVisitor(org.richfaces.cdk.templatecompiler.model.CompositeInterface)
*/
@Override
- public RendererClassVisitor createVisitor(CompositeInterface composite,Map<String,
Property> attributes) {
+ public RendererClassVisitor createVisitor(CompositeInterface
composite,Collection<Property> attributes) {
return new RendererClassVisitor(composite, attributes,classLoader, jaxbBinding,
log);
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/ComparatorUtils.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/ComparatorUtils.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/util/ComparatorUtils.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -57,5 +57,22 @@
return t1.compareTo(t2);
}
}
-
+
+ /**
+ * <p class="changed_added_4_0">Null-safe equals check. Return true
if both arguments are null or equal.</p>
+ * @param <T> the type of objects to compare.
+ * @param t1
+ * @param t2
+ * @return true if both arguments are null or equal
+ */
+ public static <T> boolean nullSafeEquals(T t1, T t2) {
+ if (t1 == null) {
+ return t2 == null;
+ } else if (t2 == null) {
+ return false;
+ } else {
+ return t1.equals(t2);
+ }
+ }
+
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/FragmentParser.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -23,6 +23,7 @@
package org.richfaces.cdk.xmlconfig;
+import java.util.Collection;
import java.util.Collections;
import java.util.Map;
@@ -62,7 +63,7 @@
* @param url
* @return
*/
- public Map<String, Property> parseProperties(String url) throws CdkException {
+ public Collection<Property> parseProperties(String url) throws CdkException {
String schemaLocation = ComponentLibrary.FACES_CONFIG_SCHEMA_LOCATION;
Class<Fragment> bindClass = Fragment.class;
Fragment unmarshal = binding.unmarshal(url, schemaLocation, bindClass);
@@ -70,7 +71,7 @@
ComponentModel component = adapter.unmarshal(unmarshal);
return component.getAttributes();
} else {
- return Collections.<String, Property> emptyMap();
+ return Collections.<Property> emptySet();
}
}
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/AttributeBean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/AttributeBean.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/AttributeBean.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -37,6 +37,7 @@
*/
@XmlType(name = "faces-config-attributeType", namespace =
ComponentLibrary.FACES_CONFIG_NAMESPACE,
propOrder = {"key", "type", "defaultValue",
"suggestedValue", "extension"})
+(a)XmlJavaTypeAdapter(AttributeAdapter.class)
public class AttributeBean extends PropertyBase {
/**
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-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ComponentAdapter.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -54,7 +54,6 @@
@Override
protected void postMarshal(ComponentModel model, ComponentBean bean) {
// Copy properties/attributes
- bean.setAttributes(marshalMap(model.getAttributes(), ATTRIBUTE_ADAPTER));
bean.setFacets(marshalMap(model.getFacets(), FACET_ADAPTER));
}
@@ -69,8 +68,6 @@
model.setType(new Type(type.trim()));
}
// Copy properties/attributes
- model.getAttributes().putAll(this.<String, PropertyBase,
Property>unmarshalMap(
- bean.getAttributes(), ATTRIBUTE_ADAPTER));
model.getFacets().putAll(this.<String, FacetBean,
FacetModel>unmarshalMap(bean.getFacets(), FACET_ADAPTER));
Collection<RendererModel> renderers = model.getRenderers();
ComponentBean.ComponentExtension extension = bean.getExtension();
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-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/ComponentBean.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -30,10 +30,12 @@
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.ConfigExtension;
import org.richfaces.cdk.model.EventModel;
+import org.richfaces.cdk.model.Property;
import com.google.common.collect.Lists;
@@ -49,7 +51,7 @@
public class ComponentBean extends ExtensibleBean<ComponentBean.ComponentExtension>
{
private boolean generate = false;
- private List<PropertyBase> attributes = Lists.newArrayList();
+ private List<Property> attributes = Lists.newArrayList();
private List<FacetBean> facets = Lists.newArrayList();
private ClassName componentClass;
private String type;
@@ -101,15 +103,15 @@
@XmlElements({@XmlElement(
name = "property",
namespace = ComponentLibrary.FACES_CONFIG_NAMESPACE,
- type = PropertyBean.class
+ type = Property.class
), @XmlElement(
name = "attribute",
namespace = ComponentLibrary.FACES_CONFIG_NAMESPACE,
- type = AttributeBean.class
+ type = AttributeModel.class
)})
//
@XmlElement(name="attributes",namespace=ComponentLibrary.FACES_CONFIG_NAMESPACE)
- public List<PropertyBase> getAttributes() {
+ public List<Property> getAttributes() {
return attributes;
}
@@ -118,7 +120,7 @@
*
* @param property the attributes to set
*/
- public void setAttributes(List<PropertyBase> property) {
+ public void setAttributes(List<Property> property) {
this.attributes = property;
}
Modified:
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/PropertyBean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/PropertyBean.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/main/java/org/richfaces/cdk/xmlconfig/model/PropertyBean.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -37,6 +37,7 @@
*/
@XmlType(name="faces-config-propertyType",namespace=ComponentLibrary.FACES_CONFIG_NAMESPACE,
propOrder={"key","type","defaultValue","suggestedValue","extension"})
+(a)XmlJavaTypeAdapter(AttributeAdapter.class)
public class PropertyBean extends PropertyBase {
/**
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/apt/ComponentProcessorTest.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -118,7 +118,7 @@
assertEquals(1, components.size());
ComponentModel component = Iterables.get(components, 0);
- Map<String, Property> attributes = component.getAttributes();
+ Collection<Property> attributes = component.getAttributes();
assertEquals(3, attributes.size());
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/AbstractClassGeneratorTest.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -69,7 +69,7 @@
protected FileManager output;
protected static Property addAttribute(ModelElementBase model, String attributeName,
Class<?> type, boolean generate) {
- Property attribute = model.addAttribute(attributeName);
+ Property attribute = model.getOrCreateAttribute(attributeName);
attribute.setType(new ClassName(type));
attribute.setGenerate(generate);
return attribute;
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-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/java/ComponentClassGeneratorTest.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -87,23 +87,23 @@
component.setGenerate(true);
component.setClassNames("org.richfaces.cdk.generate.java.GeneratedComponent",
UIOutput.class.getName());
- Property attribute = component.addAttribute("testValue");
+ Property attribute = component.getOrCreateAttribute("testValue");
attribute.setType(new ClassName(Object.class));
attribute.setGenerate(true);
- attribute = component.addAttribute("testFlag");
+ attribute = component.getOrCreateAttribute("testFlag");
attribute.setType(new ClassName(Boolean.class));
attribute.setGenerate(true);
- attribute = component.addAttribute("testBinding");
+ attribute = component.getOrCreateAttribute("testBinding");
attribute.setType(new ClassName(MethodBinding.class));
attribute.setGenerate(true);
- attribute = component.addAttribute("testExpr");
+ attribute = component.getOrCreateAttribute("testExpr");
attribute.setType(new ClassName(MethodExpression.class));
attribute.setGenerate(true);
- attribute = component.addAttribute("id");
+ attribute = component.getOrCreateAttribute("id");
attribute.setType(new ClassName(String.class));
attribute.setGenerate(false);
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/taglib/TaglibTestBase.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/taglib/TaglibTestBase.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/taglib/TaglibTestBase.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -59,7 +59,6 @@
* @author akolonitsky
* @since Jan 18, 2010
*/
-(a)RunWith(CdkTestRunner.class)
public class TaglibTestBase extends CdkTestBase {
@@ -88,8 +87,9 @@
return event;
}
- protected Property createAttribute( Class<?> type, boolean generate) {
+ protected Property createAttribute( String name, Class<?> type, boolean
generate) {
Property attribute = new Property();
+ attribute.setName(name);
attribute.setType(new ClassName(type));
attribute.setGenerate(generate);
return attribute;
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/taglib/ValidatorTagGeneratorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/taglib/ValidatorTagGeneratorTest.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/generate/taglib/ValidatorTagGeneratorTest.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -68,12 +68,12 @@
validator.setGeneratedClass(UIOutput.class);
validator.setGenerate(true);
- Property attribute1 = createAttribute( Object.class, true);
- validator.getAttributes().put("testValue", attribute1);
- Property attribute2 = createAttribute( boolean.class, true);
- validator.getAttributes().put("testFlag", attribute2);
- Property attribute = createAttribute(String.class, false);
- validator.getAttributes().put("id", attribute);
+ Property attribute1 = createAttribute( "testValue", Object.class,
true);
+ validator.getAttributes().add( attribute1);
+ Property attribute2 = createAttribute( "testFlag", boolean.class,
true);
+ validator.getAttributes().add( attribute2);
+ Property attribute = createAttribute("id", String.class, false);
+ validator.getAttributes().add(attribute);
Set<EventName> eventNames = attribute.getEventNames();
eventNames.add(createEvent("id", false));
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ModelBean.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ModelBean.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/model/ModelBean.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -184,7 +184,7 @@
return null != getType() && getType().equals(other.getType());
}
- public static final class Type extends Key {
+ public static final class Type extends FacesId {
private static final long serialVersionUID = 6227413669285563473L;
public Type(String type) {
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/templatecompiler/RendererTemplateParserTest.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -46,7 +46,6 @@
import org.richfaces.cdk.Mock;
import org.richfaces.cdk.Source;
import org.richfaces.cdk.Sources;
-import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.*;
import org.richfaces.cdk.model.RenderKitModel.Id;
import org.richfaces.cdk.templatecompiler.model.Template;
@@ -299,23 +298,32 @@
assertEquals("org.richfaces.Dummy", renderer.getFamily());
assertSame(template, renderer.getTemplate());
- Map<String, Property> attributes = renderer.getAttributes();
+ Collection<Property> attributes = renderer.getAttributes();
assertNotNull(attributes);
- checkDummyComponentOnclick(attributes.get("onclick"));
- checkDummyComponentOnchange(attributes.get("onchange"));
- checkDummyComponentAction(attributes.get("action"));
- checkDummyComponentActionListener(attributes.get("actionListener"));
- checkDummyComponentCoolMethod(attributes.get("coolMethod"));
-
checkDummyComponentIntegerAttribute(attributes.get("integerAttribute"));
-
checkDummyComponentRequiredAttribute(attributes.get("requiredAttribute"));
+ checkDummyComponentOnclick(getAttribute(attributes,"onclick"));
+ checkDummyComponentOnchange(getAttribute(attributes,"onchange"));
+ checkDummyComponentAction(getAttribute(attributes,"action"));
+
checkDummyComponentActionListener(getAttribute(attributes,"actionListener"));
+ checkDummyComponentCoolMethod(getAttribute(attributes,"coolMethod"));
+
checkDummyComponentIntegerAttribute(getAttribute(attributes,"integerAttribute"));
+
checkDummyComponentRequiredAttribute(getAttribute(attributes,"requiredAttribute"));
-
checkDummyComponentImportedAttribute(attributes.get("anotherImportedStringProperty"),
String.class);
-
checkDummyComponentImportedAttribute(attributes.get("anotherImportedProperty"),
Object.class);
-
checkDummyComponentImportedAttribute(attributes.get("importedBooleanProperty"),
boolean.class);
-
checkDummyComponentImportedAttribute(attributes.get("importedIntegerProperty"),
Integer.class);
+
checkDummyComponentImportedAttribute(getAttribute(attributes,"anotherImportedStringProperty"),
String.class);
+
checkDummyComponentImportedAttribute(getAttribute(attributes,"anotherImportedProperty"),
Object.class);
+
checkDummyComponentImportedAttribute(getAttribute(attributes,"importedBooleanProperty"),
boolean.class);
+
checkDummyComponentImportedAttribute(getAttribute(attributes,"importedIntegerProperty"),
Integer.class);
assertEquals(11, attributes.size());
}
+ private Property getAttribute(Collection<Property> attributes, String string)
{
+ for (Property property : attributes) {
+ if(string.equals(property.getName())){
+ return property;
+ }
+ }
+ return null;
+ }
+
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FacesConfigTest.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -25,6 +25,7 @@
import static org.junit.Assert.*;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
@@ -111,7 +112,7 @@
assertEquals("Header facet", facet.getDescription());
assertTrue(facet.isGenerate());
- Map<String, Property> attributes = component.getAttributes();
+ Collection<Property> attributes = component.getAttributes();
assertEquals(3, attributes.size());
}
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/FragmentParserTest.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -25,6 +25,7 @@
import static org.junit.Assert.*;
+import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -43,6 +44,7 @@
import org.richfaces.cdk.model.Property;
import org.xml.sax.ext.EntityResolver2;
+import com.google.common.collect.Iterables;
import com.google.inject.Binder;
import com.google.inject.Inject;
@@ -84,7 +86,7 @@
@Test
public void parserTest() throws Exception {
- Map<String, Property> properties =
+ Collection<Property> properties =
parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/fragment.xml");
assertEquals(3, properties.size());
@@ -93,7 +95,7 @@
@Test
public void xincludeTest() throws Exception {
- Map<String, Property> properties =
+ Collection<Property> properties =
parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/parent.xml");
assertEquals(2, properties.size());
@@ -102,7 +104,7 @@
@Test
public void nestedXincludeTest() throws Exception {
- Map<String, Property> properties =
+ Collection<Property> properties =
parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/parent2.xml");
assertEquals(2, properties.size());
@@ -111,14 +113,14 @@
@Test
public void propertyTest() throws Exception {
- Map<String, Property> properties =
+ Collection<Property> properties =
parser.parseProperties("urn:resource:org/richfaces/cdk/xmlconfig/properties.xml");
assertEquals(1, properties.size());
- Property property = properties.get("ontest2");
+ Property property = Iterables.getOnlyElement(properties);
+ assertEquals("ontest2",property.getName());
- assertNotNull(property);
assertEquals("int", property.getType().getName());
assertEquals("test2 property", property.getDescription());
assertEquals("ontest2.png", property.getIcon().getSmallIcon());
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JAXBCopyTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JAXBCopyTest.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/JAXBCopyTest.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -2,12 +2,14 @@
import static org.junit.Assert.*;
+import java.util.Collection;
import java.util.List;
import org.junit.Test;
import org.junit.Ignore;
import org.richfaces.cdk.model.ClassName;
import org.richfaces.cdk.model.ComponentModel;
+import org.richfaces.cdk.model.Property;
import org.richfaces.cdk.xmlconfig.model.ComponentBean;
import org.richfaces.cdk.xmlconfig.model.PropertyBase;
import org.richfaces.cdk.xmlconfig.model.ComponentBean.ComponentExtension;
@@ -26,13 +28,13 @@
component.setDescription(FOO_DESCTIPTION);
component.setGeneratedClass(FOO_UI_BAR);
- component.addAttribute(BAZ);
+ component.getOrCreateAttribute(BAZ);
component.setFamily(FOO_FAMILY);
ComponentBean componentBean = null;
//JAXBBinding.createAdapter(ComponentBean.class, component);
assertEquals(FOO_BAR, componentBean.getType());
- List<PropertyBase> attributes = componentBean.getAttributes();
+ Collection<Property> attributes = componentBean.getAttributes();
assertEquals(0, attributes.size());
// assertEquals(BAZ, attributes.get(0).getKey().toString());
Modified:
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/TaglibGeneratorVisitorTest.java
===================================================================
---
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/TaglibGeneratorVisitorTest.java 2010-03-05
16:22:26 UTC (rev 16531)
+++
root/cdk/trunk/plugins/generator/src/test/java/org/richfaces/cdk/xmlconfig/TaglibGeneratorVisitorTest.java 2010-03-06
00:18:24 UTC (rev 16532)
@@ -67,7 +67,7 @@
}
private Property addAttribute(ValidatorModel validator, String attributeName,
Class<?> type, boolean generate) {
- Property attribute = validator.addAttribute(attributeName);
+ Property attribute = validator.getOrCreateAttribute(attributeName);
attribute.setType(new ClassName(type));
attribute.setGenerate(generate);
return attribute;