[seam-commits] Seam SVN: r13556 - in modules/xml/trunk/impl/src: main/java/org/jboss/seam/xml/model and 2 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Thu Aug 5 07:18:32 EDT 2010
Author: swd847
Date: 2010-08-05 07:18:31 -0400 (Thu, 05 Aug 2010)
New Revision: 13556
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractValueXmlItem.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELFieldValueBeanTest.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELValueBean.java
modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/el-set-field-value-beans.xml
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java
Log:
improve el support and add tests for the collection case
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-08-05 10:07:05 UTC (rev 13555)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -37,7 +37,6 @@
import org.jboss.seam.xml.model.EntryXmlItem;
import org.jboss.seam.xml.util.TypeReader;
-import org.jboss.seam.xml.util.XmlObjectConverter;
import org.jboss.weld.extensions.util.properties.Property;
/**
@@ -50,7 +49,7 @@
public class MapFieldSet implements FieldValueObject
{
private final Property field;
- private final List<Entry<Object, FieldValue>> values;
+ private final List<Entry<FieldValue, FieldValue>> values;
private final Class<?> keyType;
private final Class<?> valueType;
private final Class<? extends Map> collectionType;
@@ -58,7 +57,7 @@
public MapFieldSet(Property field, List<EntryXmlItem> items)
{
this.field = field;
- this.values = new ArrayList<Entry<Object, FieldValue>>();
+ this.values = new ArrayList<Entry<FieldValue, FieldValue>>();
// figure out the collection type
Type type = field.getBaseType();
if (type instanceof ParameterizedType)
@@ -100,8 +99,7 @@
for (EntryXmlItem i : items)
{
- final Object key = XmlObjectConverter.convert(keyType, i.getKey().getInnerText());
- values.add(new EntryImpl(key, i.getValue().getValue()));
+ values.add(new EntryImpl(i.getKey().getValue(), i.getValue().getValue()));
}
}
@@ -113,8 +111,8 @@
field.setValue(instance, res);
for (int i = 0; i < values.size(); ++i)
{
- Entry<Object, FieldValue> e = values.get(i);
- res.put(e.getKey(), e.getValue().value(valueType, ctx, manager));
+ Entry<FieldValue, FieldValue> e = values.get(i);
+ res.put(e.getKey().value(keyType, ctx, manager), e.getValue().value(valueType, ctx, manager));
}
}
catch (Exception e)
@@ -123,18 +121,18 @@
}
}
- private final class EntryImpl implements Entry<Object, FieldValue>
+ private final class EntryImpl implements Entry<FieldValue, FieldValue>
{
- private Object key;
+ private FieldValue key;
private FieldValue value;
- public EntryImpl(Object key, FieldValue value)
+ public EntryImpl(FieldValue key, FieldValue value)
{
this.key = key;
this.value = value;
}
- public Object getKey()
+ public FieldValue getKey()
{
return key;
}
@@ -149,7 +147,7 @@
return this.value = value;
}
- public void setKey(Object key)
+ public void setKey(FieldValue key)
{
this.key = key;
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java 2010-08-05 10:07:05 UTC (rev 13555)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -94,6 +94,13 @@
}
if (!mapEntries.isEmpty())
{
+ for (EntryXmlItem entry : mapEntries)
+ {
+ // resolve inline beans if nessesary
+ Set<BeanResult<?>> beans = entry.getBeanResults(manager);
+ inlineBeans.addAll(beans);
+
+ }
fieldValue = new MapFieldSet(property, mapEntries);
}
}
@@ -105,6 +112,15 @@
}
if (!valueEntries.isEmpty())
{
+ for (ValueXmlItem value : valueEntries)
+ {
+ // resolve inline beans if nessesary
+ BeanResult<?> result = value.getBeanResult(manager);
+ if (result != null)
+ {
+ inlineBeans.add(result);
+ }
+ }
if (getFieldType().isArray())
{
fieldValue = new ArrayFieldSet(property, valueEntries);
@@ -127,7 +143,7 @@
}
ValueXmlItem value = valueEntries.get(0);
BeanResult<?> result = value.getBeanResult(manager);
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, valueEntries.get(0).getValue());
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, value.getValue());
if (result != null)
{
inlineBeans.add(result);
Added: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractValueXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractValueXmlItem.java (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractValueXmlItem.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -0,0 +1,86 @@
+package org.jboss.seam.xml.model;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.seam.xml.core.BeanResult;
+import org.jboss.seam.xml.fieldset.ConstantFieldValue;
+import org.jboss.seam.xml.fieldset.ELFieldValue;
+import org.jboss.seam.xml.fieldset.FieldValue;
+import org.jboss.seam.xml.fieldset.InlineBeanFieldValue;
+import org.jboss.seam.xml.fieldset.InlineBeanIdCreator;
+import org.jboss.seam.xml.fieldset.InlineBeanQualifier;
+import org.jboss.seam.xml.util.TypeOccuranceInformation;
+import org.jboss.seam.xml.util.XmlConfigurationException;
+
+public abstract class AbstractValueXmlItem extends AbstractXmlItem
+{
+
+ private int syntheticQualifierId;
+ private BeanResult<?> inlineBean;
+
+ public AbstractValueXmlItem(XmlItemType type, XmlItem parent, Class<?> javaClass, String innerText, Map<String, String> attributes, String document, int lineno)
+ {
+ super(type, parent, javaClass, innerText, attributes, document, lineno);
+ }
+
+ public Set<TypeOccuranceInformation> getAllowedItem()
+ {
+ return Collections.singleton(TypeOccuranceInformation.of(XmlItemType.CLASS, null, 1));
+ }
+
+ public BeanResult<?> getBeanResult(BeanManager manager)
+ {
+ List<ClassXmlItem> inlineBeans = getChildrenOfType(ClassXmlItem.class);
+ if (!inlineBeans.isEmpty())
+ {
+ ClassXmlItem inline = inlineBeans.get(0);
+ for (AnnotationXmlItem i : inline.getChildrenOfType(AnnotationXmlItem.class))
+ {
+ Class annotation = (Class) i.getJavaClass();
+ if (manager.isQualifier(annotation))
+ {
+ throw new XmlConfigurationException("Cannot define qualifiers on inline beans, Qualifier: " + annotation.getName(), i.getDocument(), i.getLineno());
+ }
+ else if (manager.isScope(annotation) && annotation != Dependent.class)
+ {
+ throw new XmlConfigurationException("Inline beans must have @Dependent scope, Scope: " + annotation.getName(), i.getDocument(), i.getLineno());
+ }
+ }
+ syntheticQualifierId = InlineBeanIdCreator.getId();
+ AnnotationXmlItem syntheticQualifier = new AnnotationXmlItem(this, InlineBeanQualifier.class, "" + syntheticQualifierId, Collections.EMPTY_MAP, getDocument(), getLineno());
+ inline.addChild(syntheticQualifier);
+ inlineBean = inline.createBeanResult(manager);
+ return inlineBean;
+ }
+ inlineBean = null;
+ return null;
+ }
+
+ public int getSyntheticQualifierId()
+ {
+ return syntheticQualifierId;
+ }
+
+ public FieldValue getValue()
+ {
+ if (inlineBean == null)
+ {
+ if (innerText.matches("^#\\{.*\\}$"))
+ {
+ return new ELFieldValue(innerText);
+ }
+ return new ConstantFieldValue(innerText);
+ }
+ else
+ {
+ return new InlineBeanFieldValue(syntheticQualifierId);
+ }
+ }
+
+}
\ No newline at end of file
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java 2010-08-05 10:07:05 UTC (rev 13555)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -26,6 +26,7 @@
import javax.enterprise.inject.spi.BeanManager;
+import org.jboss.seam.xml.core.BeanResult;
import org.jboss.seam.xml.util.TypeOccuranceInformation;
import org.jboss.seam.xml.util.XmlConfigurationException;
@@ -34,8 +35,8 @@
final Set<TypeOccuranceInformation> allowed = new HashSet<TypeOccuranceInformation>();
- XmlItem key;
- XmlItem value;
+ KeyXmlItem key;
+ ValueXmlItem value;
public EntryXmlItem(XmlItem parent, String document, int lineno)
{
@@ -64,7 +65,7 @@
{
throw new XmlConfigurationException("<entry> tags must have two children, a <key> and a <value>", getDocument(), getLineno());
}
- value = i;
+ value = (ValueXmlItem) i;
}
else if (i.getType() == XmlItemType.KEY)
{
@@ -72,13 +73,13 @@
{
throw new XmlConfigurationException("<entry> tags must have two children, a <key> and a <value>", getDocument(), getLineno());
}
- key = i;
+ key = (KeyXmlItem) i;
}
}
return true;
}
- public XmlItem getKey()
+ public KeyXmlItem getKey()
{
return key;
}
@@ -88,4 +89,26 @@
return (ValueXmlItem) value;
}
+ /**
+ * get the inline beans for the value and the key
+ *
+ * @param manager
+ * @return
+ */
+ public Set<BeanResult<?>> getBeanResults(BeanManager manager)
+ {
+ Set<BeanResult<?>> ret = new HashSet<BeanResult<?>>();
+ BeanResult<?> r = value.getBeanResult(manager);
+ if (r != null)
+ {
+ ret.add(r);
+ }
+ r = key.getBeanResult(manager);
+ if (r != null)
+ {
+ ret.add(r);
+ }
+ return ret;
+ }
+
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java 2010-08-05 10:07:05 UTC (rev 13555)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -26,7 +26,7 @@
import org.jboss.seam.xml.util.TypeOccuranceInformation;
-public class KeyXmlItem extends AbstractXmlItem
+public class KeyXmlItem extends AbstractValueXmlItem
{
public KeyXmlItem(XmlItem parent, String innerText, String document, int lineno)
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java 2010-08-05 10:07:05 UTC (rev 13555)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -21,86 +21,13 @@
*/
package org.jboss.seam.xml.model;
-import java.util.Collections;
-import java.util.List;
-import java.util.Set;
-import javax.enterprise.context.Dependent;
-import javax.enterprise.inject.spi.BeanManager;
-import org.jboss.seam.xml.core.BeanResult;
-import org.jboss.seam.xml.fieldset.ConstantFieldValue;
-import org.jboss.seam.xml.fieldset.ELFieldValue;
-import org.jboss.seam.xml.fieldset.FieldValue;
-import org.jboss.seam.xml.fieldset.InlineBeanFieldValue;
-import org.jboss.seam.xml.fieldset.InlineBeanIdCreator;
-import org.jboss.seam.xml.fieldset.InlineBeanQualifier;
-import org.jboss.seam.xml.util.TypeOccuranceInformation;
-import org.jboss.seam.xml.util.XmlConfigurationException;
-public class ValueXmlItem extends AbstractXmlItem
+public class ValueXmlItem extends AbstractValueXmlItem
{
- private int syntheticQualifierId;
- private BeanResult<?> inlineBean;
- private BeanManager manager;
-
public ValueXmlItem(XmlItem parent, String innerText, String document, int lineno)
{
super(XmlItemType.VALUE, parent, null, innerText, null, document, lineno);
}
-
- public Set<TypeOccuranceInformation> getAllowedItem()
- {
- return Collections.singleton(TypeOccuranceInformation.of(XmlItemType.CLASS, null, 1));
- }
-
- public BeanResult<?> getBeanResult(BeanManager manager)
- {
- this.manager = manager;
- List<ClassXmlItem> inlineBeans = getChildrenOfType(ClassXmlItem.class);
- if (!inlineBeans.isEmpty())
- {
- ClassXmlItem inline = inlineBeans.get(0);
- for (AnnotationXmlItem i : inline.getChildrenOfType(AnnotationXmlItem.class))
- {
- Class annotation = (Class) i.getJavaClass();
- if (manager.isQualifier(annotation))
- {
- throw new XmlConfigurationException("Cannot define qualifiers on inline beans, Qualifier: " + annotation.getName(), i.getDocument(), i.getLineno());
- }
- else if (manager.isScope(annotation) && annotation != Dependent.class)
- {
- throw new XmlConfigurationException("Inline beans must have @Dependent scope, Scope: " + annotation.getName(), i.getDocument(), i.getLineno());
- }
- }
- syntheticQualifierId = InlineBeanIdCreator.getId();
- AnnotationXmlItem syntheticQualifier = new AnnotationXmlItem(this, InlineBeanQualifier.class, "" + syntheticQualifierId, Collections.EMPTY_MAP, getDocument(), getLineno());
- inline.addChild(syntheticQualifier);
- inlineBean = inline.createBeanResult(manager);
- return inlineBean;
- }
- inlineBean = null;
- return null;
- }
-
- public int getSyntheticQualifierId()
- {
- return syntheticQualifierId;
- }
-
- public FieldValue getValue()
- {
- if (inlineBean == null)
- {
- if (innerText.matches("^#\\{.*\\}$"))
- {
- return new ELFieldValue(innerText);
- }
- return new ConstantFieldValue(innerText);
- }
- else
- {
- return new InlineBeanFieldValue(syntheticQualifierId);
- }
- }
}
Added: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELFieldValueBeanTest.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELFieldValueBeanTest.java (rev 0)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELFieldValueBeanTest.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.jboss.seam.xml.test.fieldset;
+
+import java.util.Map.Entry;
+
+import junit.framework.Assert;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.junit.Test;
+
+public class ELFieldValueBeanTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "el-set-field-value-beans.xml";
+ }
+
+ @Test
+ public void mapSetFieldValue()
+ {
+ ELValueBean bean = getReference(ELValueBean.class);
+ Assert.assertTrue(bean.array.length == 1);
+ Assert.assertEquals(bean.array[0], ELValueProducer.EL_VALUE_STRING);
+ Assert.assertTrue(bean.list.size() == 1);
+ Assert.assertEquals(bean.list.get(0), ELValueProducer.EL_VALUE_STRING);
+ Assert.assertTrue(bean.map.size() == 1);
+ Entry<String, String> entry = bean.map.entrySet().iterator().next();
+ Assert.assertEquals(entry.getKey(), ELValueProducer.EL_VALUE_STRING);
+ Assert.assertEquals(entry.getValue(), ELValueProducer.EL_VALUE_STRING);
+ }
+}
Added: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELValueBean.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELValueBean.java (rev 0)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/ELValueBean.java 2010-08-05 11:18:31 UTC (rev 13556)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, 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.jboss.seam.xml.test.fieldset;
+
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Bean that test values set via el in arrays, lists and maps
+ *
+ * @author stuart
+ *
+ */
+public class ELValueBean
+{
+ public List<String> list;
+ public Map<String, String> map;
+ public String[] array;
+}
Added: modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/el-set-field-value-beans.xml
===================================================================
--- modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/el-set-field-value-beans.xml (rev 0)
+++ modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/el-set-field-value-beans.xml 2010-08-05 11:18:31 UTC (rev 13556)
@@ -0,0 +1,20 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="urn:java:ee"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.fieldset">
+ <test:ELValueBean>
+ <replaces/>
+ <test:array>
+ <value>#{elValue}</value>
+ </test:array>
+ <test:list>
+ <value>#{elValue}</value>
+ </test:list>
+ <test:map>
+ <entry>
+ <key>#{elValue}</key>
+ <value>#{elValue}</value>
+ </entry>
+ </test:map>
+ </test:ELValueBean>
+
+</beans>
\ No newline at end of file
More information about the seam-commits
mailing list