[seam-commits] Seam SVN: r13540 - in modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml: model and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Sun Aug 1 08:05:50 EDT 2010
Author: swd847
Date: 2010-08-01 08:05:49 -0400 (Sun, 01 Aug 2010)
New Revision: 13540
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ConstantFieldValue.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/FieldValue.java
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanFieldValue.java
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/SimpleFieldValue.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/FieldXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java
Log:
refactor inline bean implementation
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java 2010-08-01 10:07:24 UTC (rev 13539)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -28,8 +28,6 @@
import javax.enterprise.context.spi.CreationalContext;
import org.jboss.seam.xml.model.ValueXmlItem;
-import org.jboss.seam.xml.model.XmlItem;
-import org.jboss.seam.xml.util.XmlObjectConverter;
import org.jboss.weld.extensions.util.properties.Property;
/**
@@ -41,18 +39,17 @@
public class ArrayFieldSet implements FieldValueObject
{
final private Property field;
- final private List<Object> values;
+ final private List<FieldValue> values;
final private Class<?> arrayType;
public ArrayFieldSet(Property<?> field, List<ValueXmlItem> items)
{
this.field = field;
- this.values = new ArrayList<Object>();
+ this.values = new ArrayList<FieldValue>();
arrayType = field.getJavaClass().getComponentType();
- for (XmlItem i : items)
+ for (ValueXmlItem i : items)
{
- Object fv = XmlObjectConverter.convert(arrayType, i.getInnerText());
- values.add(fv);
+ values.add(i.getValue());
}
}
@@ -65,7 +62,7 @@
field.setValue(instance, array);
for (int i = 0; i < values.size(); ++i)
{
- Array.set(array, i, values.get(i));
+ Array.set(array, i, values.get(i).value(arrayType, ctx));
}
}
catch (Exception e)
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java 2010-08-01 10:07:24 UTC (rev 13539)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -36,9 +36,7 @@
import javax.enterprise.context.spi.CreationalContext;
import org.jboss.seam.xml.model.ValueXmlItem;
-import org.jboss.seam.xml.model.XmlItem;
import org.jboss.seam.xml.util.TypeReader;
-import org.jboss.seam.xml.util.XmlObjectConverter;
import org.jboss.weld.extensions.util.properties.Property;
/**
@@ -53,14 +51,14 @@
public class CollectionFieldSet implements FieldValueObject
{
private final Property field;
- private final List<Object> values;
+ private final List<FieldValue> values;
private final Class<?> elementType;
private final Class<? extends Collection> collectionType;
public CollectionFieldSet(Property field, List<ValueXmlItem> items)
{
this.field = field;
- this.values = new ArrayList<Object>();
+ this.values = new ArrayList<FieldValue>();
Type type = field.getBaseType();
if (type instanceof ParameterizedType)
@@ -114,10 +112,9 @@
throw new RuntimeException("Could not determine element type for " + field.getDeclaringClass().getName() + "." + field.getName());
}
- for (XmlItem i : items)
+ for (ValueXmlItem i : items)
{
- final Object fv = XmlObjectConverter.convert(elementType, i.getInnerText());
- values.add(fv);
+ values.add(i.getValue());
}
}
@@ -129,7 +126,7 @@
field.setValue(instance, res);
for (int i = 0; i < values.size(); ++i)
{
- res.add(values.get(i));
+ res.add(values.get(i).value(elementType, ctx));
}
}
catch (Exception e)
Added: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ConstantFieldValue.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ConstantFieldValue.java (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ConstantFieldValue.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -0,0 +1,47 @@
+/*
+ * 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.fieldset;
+
+import javax.enterprise.context.spi.CreationalContext;
+
+import org.jboss.seam.xml.util.XmlObjectConverter;
+
+/**
+ * Represents a simple field value in an XML document
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class ConstantFieldValue implements FieldValue
+{
+ private final String stringValue;
+
+ public ConstantFieldValue(String stringValue)
+ {
+ this.stringValue = stringValue;
+ }
+
+ public Object value(Class<?> type, CreationalContext<?> cyx)
+ {
+ return XmlObjectConverter.convert(type, stringValue);
+ }
+}
Added: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/FieldValue.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/FieldValue.java (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/FieldValue.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -0,0 +1,36 @@
+/*
+ * 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.fieldset;
+
+import javax.enterprise.context.spi.CreationalContext;
+
+/**
+ * represents an initial field value. This may just be a wrapper around a
+ * constant value, or it could be an inline bean declaration or EL expression
+ *
+ * @author Stuart Douglas
+ *
+ */
+public interface FieldValue
+{
+ public Object value(Class<?> type, CreationalContext<?> ctx);
+}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanFieldValue.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanFieldValue.java 2010-08-01 10:07:24 UTC (rev 13539)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanFieldValue.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -25,53 +25,37 @@
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
-import org.jboss.weld.extensions.util.properties.Property;
-
/**
* Field value object for an inline bean definition
*
* @author Stuart Douglas
*
*/
-public class InlineBeanFieldValue implements FieldValueObject
+public class InlineBeanFieldValue implements FieldValue
{
- private final Property field;
-
private final int beanId;
- private final Class<?> type;
-
private final InlineBeanQualifier.InlineBeanQualifierLiteral literal;
private final BeanManager manager;
private Bean<?> bean;
- public InlineBeanFieldValue(Class<?> type, int syntheticBeanQualifierNo, Property setter, BeanManager manager)
+ public InlineBeanFieldValue(int syntheticBeanQualifierNo, BeanManager manager)
{
this.beanId = syntheticBeanQualifierNo;
- this.field = setter;
- this.type = type;
this.literal = new InlineBeanQualifier.InlineBeanQualifierLiteral(beanId);
this.manager = manager;
}
- public void setValue(Object instance, CreationalContext<?> ctx)
+ public Object value(Class<?> type, CreationalContext<?> ctx)
{
if (bean == null)
{
bean = manager.resolve(manager.getBeans(type, literal));
}
- Object obj = manager.getReference(bean, type, ctx);
- try
- {
- field.setValue(instance, obj);
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
+ return manager.getReference(bean, type, ctx);
}
}
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-01 10:07:24 UTC (rev 13539)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -49,7 +49,7 @@
public class MapFieldSet implements FieldValueObject
{
private final Property field;
- private final List<Entry<Object, Object>> values;
+ private final List<Entry<Object, FieldValue>> values;
private final Class<?> keyType;
private final Class<?> valueType;
private final Class<? extends Map> collectionType;
@@ -57,7 +57,7 @@
public MapFieldSet(Property field, List<EntryXmlItem> items)
{
this.field = field;
- this.values = new ArrayList<Entry<Object, Object>>();
+ this.values = new ArrayList<Entry<Object, FieldValue>>();
// figure out the collection type
Type type = field.getBaseType();
if (type instanceof ParameterizedType)
@@ -100,8 +100,7 @@
for (EntryXmlItem i : items)
{
final Object key = XmlObjectConverter.convert(keyType, i.getKey().getInnerText());
- final Object value = XmlObjectConverter.convert(valueType, i.getValue().getInnerText());
- values.add(new EntryImpl(key, value));
+ values.add(new EntryImpl(key, i.getValue().getValue()));
}
}
@@ -113,8 +112,8 @@
field.setValue(instance, res);
for (int i = 0; i < values.size(); ++i)
{
- Entry<Object, Object> e = values.get(i);
- res.put(e.getKey(), e.getValue());
+ Entry<Object, FieldValue> e = values.get(i);
+ res.put(e.getKey(), e.getValue().value(valueType, ctx));
}
}
catch (Exception e)
@@ -123,11 +122,12 @@
}
}
- private final class EntryImpl implements Entry<Object, Object>
+ private final class EntryImpl implements Entry<Object, FieldValue>
{
- private Object key, value;
+ private Object key;
+ private FieldValue value;
- public EntryImpl(Object key, Object value)
+ public EntryImpl(Object key, FieldValue value)
{
this.key = key;
this.value = value;
@@ -138,12 +138,12 @@
return key;
}
- public Object getValue()
+ public FieldValue getValue()
{
return value;
}
- public Object setValue(Object value)
+ public FieldValue setValue(FieldValue value)
{
return this.value = value;
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java 2010-08-01 10:07:24 UTC (rev 13539)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -23,27 +23,32 @@
import javax.enterprise.context.spi.CreationalContext;
-import org.jboss.seam.xml.util.XmlObjectConverter;
import org.jboss.weld.extensions.util.properties.Property;
+/**
+ * Field value object for a simple field
+ *
+ * @author Stuart Douglas
+ *
+ */
public class SimpleFieldValue implements FieldValueObject
{
private final Property field;
- private final Object value;
+ private final FieldValue value;
- public SimpleFieldValue(Class<?> javaObject, final Property f, final String value)
+ public SimpleFieldValue(Class<?> javaObject, final Property f, FieldValue value)
{
this.field = f;
- this.value = XmlObjectConverter.convert(f.getJavaClass(), value);
+ this.value = value;
}
public void setValue(Object instance, CreationalContext<?> ctx)
{
try
{
- field.setValue(instance, value);
+ field.setValue(instance, value.value(field.getJavaClass(), ctx));
}
catch (Exception e)
{
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-01 10:07:24 UTC (rev 13539)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -34,7 +34,6 @@
import org.jboss.seam.xml.fieldset.ArrayFieldSet;
import org.jboss.seam.xml.fieldset.CollectionFieldSet;
import org.jboss.seam.xml.fieldset.FieldValueObject;
-import org.jboss.seam.xml.fieldset.InlineBeanFieldValue;
import org.jboss.seam.xml.fieldset.MapFieldSet;
import org.jboss.seam.xml.fieldset.SimpleFieldValue;
import org.jboss.seam.xml.util.TypeOccuranceInformation;
@@ -128,14 +127,10 @@
}
ValueXmlItem value = valueEntries.get(0);
BeanResult<?> result = value.getBeanResult(manager);
- if (result == null)
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, valueEntries.get(0).getValue());
+ if (result != null)
{
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, valueEntries.get(0).getInnerText());
- }
- else
- {
inlineBeans.add(result);
- fieldValue = new InlineBeanFieldValue(getFieldType(), value.getSyntheticQualifierId(), property, manager);
}
}
}
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-01 10:07:24 UTC (rev 13539)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -83,9 +83,9 @@
return key;
}
- public XmlItem getValue()
+ public ValueXmlItem getValue()
{
- return value;
+ return (ValueXmlItem) value;
}
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java 2010-08-01 10:07:24 UTC (rev 13539)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -24,6 +24,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
+import org.jboss.seam.xml.fieldset.ConstantFieldValue;
import org.jboss.seam.xml.fieldset.SimpleFieldValue;
import org.jboss.seam.xml.util.TypeOccuranceInformation;
import org.jboss.weld.extensions.util.properties.Properties;
@@ -41,7 +42,7 @@
this.property = getFieldValueSetter(c);
if (innerText != null && innerText.length() > 0)
{
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, innerText);
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, new ConstantFieldValue(innerText));
}
allowed.add(TypeOccuranceInformation.of(XmlItemType.ANNOTATION, null, null));
allowed.add(TypeOccuranceInformation.of(XmlItemType.VALUE, null, null));
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java 2010-08-01 10:07:24 UTC (rev 13539)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -23,6 +23,7 @@
import java.lang.reflect.Method;
+import org.jboss.seam.xml.fieldset.ConstantFieldValue;
import org.jboss.seam.xml.fieldset.FieldValueObject;
import org.jboss.seam.xml.fieldset.SimpleFieldValue;
import org.jboss.weld.extensions.util.properties.Properties;
@@ -43,7 +44,7 @@
this.property = Properties.createProperty(setter);
if (innerText != null && innerText.length() > 0)
{
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, innerText);
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, new ConstantFieldValue(innerText));
}
}
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-01 10:07:24 UTC (rev 13539)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java 2010-08-01 12:05:49 UTC (rev 13540)
@@ -28,6 +28,9 @@
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.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;
@@ -35,7 +38,9 @@
public class ValueXmlItem extends AbstractXmlItem
{
- int syntheticQualifierId;
+ private int syntheticQualifierId;
+ private BeanResult<?> inlineBean;
+ private BeanManager manager;
public ValueXmlItem(XmlItem parent, String innerText, String document, int lineno)
{
@@ -49,6 +54,7 @@
public BeanResult<?> getBeanResult(BeanManager manager)
{
+ this.manager = manager;
List<ClassXmlItem> inlineBeans = getChildrenOfType(ClassXmlItem.class);
if (!inlineBeans.isEmpty())
{
@@ -63,8 +69,10 @@
syntheticQualifierId = InlineBeanIdCreator.getId();
AnnotationXmlItem syntheticQualifier = new AnnotationXmlItem(this, InlineBeanQualifier.class, "" + syntheticQualifierId, Collections.EMPTY_MAP, getDocument(), getLineno());
inline.addChild(syntheticQualifier);
- return inline.createBeanResult(manager);
+ inlineBean = inline.createBeanResult(manager);
+ return inlineBean;
}
+ inlineBean = null;
return null;
}
@@ -72,4 +80,16 @@
{
return syntheticQualifierId;
}
+
+ public FieldValue getValue()
+ {
+ if (inlineBean == null)
+ {
+ return new ConstantFieldValue(innerText);
+ }
+ else
+ {
+ return new InlineBeanFieldValue(syntheticQualifierId, manager);
+ }
+ }
}
More information about the seam-commits
mailing list