Seam SVN: r11969 - branches/community/Seam_2_2/src/main/org/jboss/seam/international.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2010-01-18 10:15:41 -0500 (Mon, 18 Jan 2010)
New Revision: 11969
Modified:
branches/community/Seam_2_2/src/main/org/jboss/seam/international/LocaleConfig.java
Log:
JBSEAM-4401
Modified: branches/community/Seam_2_2/src/main/org/jboss/seam/international/LocaleConfig.java
===================================================================
--- branches/community/Seam_2_2/src/main/org/jboss/seam/international/LocaleConfig.java 2010-01-16 22:13:59 UTC (rev 11968)
+++ branches/community/Seam_2_2/src/main/org/jboss/seam/international/LocaleConfig.java 2010-01-18 15:15:41 UTC (rev 11969)
@@ -20,6 +20,8 @@
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.log.LogProvider;
+import org.jboss.seam.log.Logging;
import org.jboss.seam.util.Strings;
/**
@@ -48,6 +50,8 @@
private String defaultLocale;
private List<String> supportedLocales;
+
+ private static final LogProvider log = Logging.getLogProvider(LocaleConfig.class);
@Create
public void initLocaleConfig()
@@ -86,6 +90,7 @@
public void setDefaultLocale(String defaultLocale)
{
this.defaultLocale = defaultLocale;
+ log.debug("Default locale was set to " + this.defaultLocale);
}
public List<String> getSupportedLocales()
@@ -96,6 +101,7 @@
public void setSupportedLocales(List<String> supportedLocales)
{
this.supportedLocales = supportedLocales;
+ log.debug("Supported locales are " + this.supportedLocales);
}
public static LocaleConfig instance()
@@ -138,6 +144,7 @@
}
catch (IllegalStateException e)
{
+ log.warn("JSF is not properly initialized, see http://jira.jboss.org/jira/browse/JBSEAM-4401");
// just in case, for units and the like
// if we can't do it, it just wan't meant to be
return null;
14 years, 11 months
Seam SVN: r11968 - in modules/xml/trunk/src: main/java/org/jboss/seam/xml/model and 1 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-01-16 17:13:59 -0500 (Sat, 16 Jan 2010)
New Revision: 11968
Added:
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/DirectFieldSetter.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldValueSetter.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MethodFieldSetter.java
Modified:
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java
Log:
Setting field values now respects getters and setters
Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java 2010-01-16 06:25:13 UTC (rev 11967)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java 2010-01-16 22:13:59 UTC (rev 11968)
@@ -5,7 +5,6 @@
package org.jboss.seam.xml.fieldset;
import java.lang.reflect.Array;
-import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
@@ -20,11 +19,11 @@
*/
public class ArrayFieldSet implements FieldValueObject
{
- Field field;
+ FieldValueSetter field;
List<AFS> values;
Class arrayType;
- public ArrayFieldSet(Field field, List<XmlItem> items)
+ public ArrayFieldSet(FieldValueSetter field, List<XmlItem> items)
{
this.field = field;
this.values = new ArrayList<AFS>();
Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java 2010-01-16 06:25:13 UTC (rev 11967)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java 2010-01-16 22:13:59 UTC (rev 11968)
@@ -4,7 +4,6 @@
*/
package org.jboss.seam.xml.fieldset;
-import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -31,12 +30,12 @@
*/
public class CollectionFieldSet implements FieldValueObject
{
- Field field;
+ FieldValueSetter field;
List<CFS> values;
Class elementType;
Class<? extends Collection> collectionType;
- public CollectionFieldSet(Field field, List<XmlItem> items)
+ public CollectionFieldSet(FieldValueSetter field, List<XmlItem> items)
{
this.field = field;
this.values = new ArrayList<CFS>();
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/DirectFieldSetter.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/DirectFieldSetter.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/DirectFieldSetter.java 2010-01-16 22:13:59 UTC (rev 11968)
@@ -0,0 +1,83 @@
+package org.jboss.seam.xml.fieldset;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Type;
+
+public class DirectFieldSetter implements FieldValueSetter
+{
+
+ Field field;
+
+ public DirectFieldSetter(Field field)
+ {
+ this.field = field;
+ field.setAccessible(true);
+ }
+
+ public void set(Object instance, Object value) throws IllegalAccessException
+ {
+ field.set(instance, value);
+ }
+
+ public Type getGenericType()
+ {
+ return field.getGenericType();
+ }
+
+ public Class getType()
+ {
+ return field.getType();
+ }
+
+ public String getName()
+ {
+ return field.getName();
+ }
+
+ public Class getDeclaringClass()
+ {
+ return field.getDeclaringClass();
+ }
+
+ public void setBoolean(Object instance, boolean value) throws IllegalAccessException, InvocationTargetException
+ {
+ field.setBoolean(instance, value);
+ }
+
+ public void setByte(Object instance, byte value) throws IllegalAccessException, InvocationTargetException
+ {
+ field.setByte(instance, value);
+ }
+
+ public void setChar(Object instance, char value) throws IllegalAccessException, InvocationTargetException
+ {
+ field.setChar(instance, value);
+ }
+
+ public void setDouble(Object instance, double value) throws IllegalAccessException, InvocationTargetException
+ {
+ field.setDouble(instance, value);
+ }
+
+ public void setFloat(Object instance, float value) throws IllegalAccessException, InvocationTargetException
+ {
+ field.setFloat(instance, value);
+ }
+
+ public void setInt(Object instance, int value) throws IllegalAccessException, InvocationTargetException
+ {
+ field.setInt(instance, value);
+ }
+
+ public void setLong(Object instance, long value) throws IllegalAccessException, InvocationTargetException
+ {
+ field.setLong(instance, value);
+ }
+
+ public void setShort(Object instance, short value) throws IllegalAccessException, InvocationTargetException
+ {
+ field.setShort(instance, value);
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldValueSetter.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldValueSetter.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldValueSetter.java 2010-01-16 22:13:59 UTC (rev 11968)
@@ -0,0 +1,35 @@
+package org.jboss.seam.xml.fieldset;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Type;
+
+public interface FieldValueSetter
+{
+
+ public void set(Object instance, Object value) throws IllegalAccessException, InvocationTargetException;
+
+ public Class getType();
+
+ public Type getGenericType();
+
+ public Class getDeclaringClass();
+
+ public String getName();
+
+ public void setInt(Object instance, int value) throws IllegalAccessException, InvocationTargetException;
+
+ public void setShort(Object instance, short value) throws IllegalAccessException, InvocationTargetException;
+
+ public void setLong(Object instance, long value) throws IllegalAccessException, InvocationTargetException;
+
+ public void setByte(Object instance, byte value) throws IllegalAccessException, InvocationTargetException;
+
+ public void setChar(Object instance, char value) throws IllegalAccessException, InvocationTargetException;
+
+ public void setDouble(Object instance, double value) throws IllegalAccessException, InvocationTargetException;
+
+ public void setFloat(Object instance, float value) throws IllegalAccessException, InvocationTargetException;
+
+ public void setBoolean(Object instance, boolean value) throws IllegalAccessException, InvocationTargetException;
+
+}
Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-01-16 06:25:13 UTC (rev 11967)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-01-16 22:13:59 UTC (rev 11968)
@@ -4,7 +4,6 @@
*/
package org.jboss.seam.xml.fieldset;
-import java.lang.reflect.Field;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -27,13 +26,13 @@
*/
public class MapFieldSet implements FieldValueObject
{
- Field field;
+ FieldValueSetter field;
List<MFS> values;
Class keyType;
Class valueType;
Class<? extends Map> collectionType;
- public MapFieldSet(Field field, List<EntryXmlItem> items)
+ public MapFieldSet(FieldValueSetter field, List<EntryXmlItem> items)
{
this.field = field;
this.values = new ArrayList<MFS>();
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MethodFieldSetter.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MethodFieldSetter.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MethodFieldSetter.java 2010-01-16 22:13:59 UTC (rev 11968)
@@ -0,0 +1,81 @@
+package org.jboss.seam.xml.fieldset;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+
+public class MethodFieldSetter implements FieldValueSetter
+{
+ Method method;
+
+ public MethodFieldSetter(Method method)
+ {
+ this.method = method;
+ }
+
+ public void set(Object instance, Object value) throws IllegalAccessException, InvocationTargetException
+ {
+ method.invoke(instance, value);
+ }
+
+ public Type getGenericType()
+ {
+ return method.getGenericParameterTypes()[0];
+ }
+
+ public String getName()
+ {
+ return method.getName();
+ }
+
+ public Class getDeclaringClass()
+ {
+ return method.getDeclaringClass();
+ }
+
+ public Class getType()
+ {
+ return method.getParameterTypes()[0];
+ }
+
+ public void setBoolean(Object instance, boolean value) throws IllegalAccessException, InvocationTargetException
+ {
+ set(instance, value);
+ }
+
+ public void setByte(Object instance, byte value) throws IllegalAccessException, InvocationTargetException
+ {
+ set(instance, value);
+ }
+
+ public void setChar(Object instance, char value) throws IllegalAccessException, InvocationTargetException
+ {
+ set(instance, value);
+ }
+
+ public void setDouble(Object instance, double value) throws IllegalAccessException, InvocationTargetException
+ {
+ set(instance, value);
+ }
+
+ public void setFloat(Object instance, float value) throws IllegalAccessException, InvocationTargetException
+ {
+ set(instance, value);
+ }
+
+ public void setInt(Object instance, int value) throws IllegalAccessException, InvocationTargetException
+ {
+ set(instance, value);
+ }
+
+ public void setLong(Object instance, long value) throws IllegalAccessException, InvocationTargetException
+ {
+ set(instance, value);
+ }
+
+ public void setShort(Object instance, short value) throws IllegalAccessException, InvocationTargetException
+ {
+ set(instance, value);
+ }
+
+}
Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java 2010-01-16 06:25:13 UTC (rev 11967)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java 2010-01-16 22:13:59 UTC (rev 11968)
@@ -4,21 +4,20 @@
*/
package org.jboss.seam.xml.fieldset;
-import java.lang.reflect.Field;
+import java.lang.reflect.InvocationTargetException;
import org.jboss.seam.xml.util.XmlObjectConverter;
public class SimpleFieldValue implements FieldValueObject
{
- final Field field;
+ final FieldValueSetter field;
FS setter;
- public SimpleFieldValue(Class javaObject, final Field f, final String value)
+ public SimpleFieldValue(Class javaObject, final FieldValueSetter f, final String value)
{
this.field = f;
- field.setAccessible(true);
Object fv = XmlObjectConverter.convert(f.getType(), value);
if (field.getType() == char.class)
@@ -27,7 +26,7 @@
final char val = (Character) fv;
setter = new FS()
{
- public void set(Object o) throws IllegalAccessException
+ public void set(Object o) throws IllegalAccessException, InvocationTargetException
{
field.setChar(o, val);
}
@@ -38,7 +37,7 @@
final int val = (Integer) fv;
setter = new FS()
{
- public void set(Object o) throws IllegalAccessException
+ public void set(Object o) throws IllegalAccessException, InvocationTargetException
{
field.setInt(o, val);
}
@@ -49,7 +48,7 @@
final short val = (Short) fv;
setter = new FS()
{
- public void set(Object o) throws IllegalAccessException
+ public void set(Object o) throws IllegalAccessException, InvocationTargetException
{
field.setShort(o, val);
}
@@ -60,7 +59,7 @@
final long val = (Long) fv;
setter = new FS()
{
- public void set(Object o) throws IllegalAccessException
+ public void set(Object o) throws IllegalAccessException, InvocationTargetException
{
field.setLong(o, val);
}
@@ -71,7 +70,7 @@
final byte val = (Byte) fv;
setter = new FS()
{
- public void set(Object o) throws IllegalAccessException
+ public void set(Object o) throws IllegalAccessException, InvocationTargetException
{
field.setByte(o, val);
}
@@ -82,7 +81,7 @@
final double val = (Double) fv;
setter = new FS()
{
- public void set(Object o) throws IllegalAccessException
+ public void set(Object o) throws IllegalAccessException, InvocationTargetException
{
field.setDouble(o, val);
}
@@ -93,18 +92,29 @@
final float val = (Float) fv;
setter = new FS()
{
- public void set(Object o) throws IllegalAccessException
+ public void set(Object o) throws IllegalAccessException, InvocationTargetException
{
field.setFloat(o, val);
}
};
}
+ else if (field.getType() == boolean.class)
+ {
+ final boolean val = (Boolean) fv;
+ setter = new FS()
+ {
+ public void set(Object o) throws IllegalAccessException, InvocationTargetException
+ {
+ field.setBoolean(o, val);
+ }
+ };
+ }
else
{
final Object val = fv;
setter = new FS()
{
- public void set(Object o) throws IllegalAccessException
+ public void set(Object o) throws IllegalAccessException, InvocationTargetException
{
field.set(o, val);
}
@@ -114,7 +124,7 @@
interface FS
{
- void set(Object o) throws IllegalAccessException;
+ void set(Object o) throws IllegalAccessException, InvocationTargetException;
}
public void setValue(Object instance)
Modified: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java 2010-01-16 22:13:59 UTC (rev 11968)
@@ -5,6 +5,7 @@
package org.jboss.seam.xml.model;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -14,24 +15,29 @@
import org.jboss.seam.xml.fieldset.ArrayFieldSet;
import org.jboss.seam.xml.fieldset.CollectionFieldSet;
+import org.jboss.seam.xml.fieldset.DirectFieldSetter;
import org.jboss.seam.xml.fieldset.FieldValueObject;
+import org.jboss.seam.xml.fieldset.FieldValueSetter;
import org.jboss.seam.xml.fieldset.MapFieldSet;
+import org.jboss.seam.xml.fieldset.MethodFieldSetter;
import org.jboss.seam.xml.fieldset.SimpleFieldValue;
public class FieldXmlItem extends AbstractXmlItem
{
+ FieldValueSetter fieldSetter;
+ FieldValueObject fieldValue;
Field field;
- FieldValueObject fieldValue;
HashSet<XmlItemType> allowed = new HashSet<XmlItemType>();
public FieldXmlItem(XmlItem parent, Field c, String innerText)
{
super(XmlItemType.FIELD, parent, parent.getJavaClass(), innerText, null);
this.field = c;
+ this.fieldSetter = getFieldValueSetter(c);
if (innerText != null && innerText.length() > 0)
{
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), c, innerText);
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), fieldSetter, innerText);
}
allowed.add(XmlItemType.ANNOTATION);
allowed.add(XmlItemType.VALUE);
@@ -78,7 +84,7 @@
}
if (!mapEntries.isEmpty())
{
- fieldValue = new MapFieldSet(field, mapEntries);
+ fieldValue = new MapFieldSet(fieldSetter, mapEntries);
}
}
else if (Collection.class.isAssignableFrom(field.getType()) || field.getType().isArray())
@@ -91,11 +97,11 @@
{
if (field.getType().isArray())
{
- fieldValue = new ArrayFieldSet(field, valueEntries);
+ fieldValue = new ArrayFieldSet(fieldSetter, valueEntries);
}
else
{
- fieldValue = new CollectionFieldSet(field, valueEntries);
+ fieldValue = new CollectionFieldSet(fieldSetter, valueEntries);
}
}
}
@@ -109,7 +115,7 @@
{
throw new RuntimeException("Non collection fields can only have a single <value> element Field:" + field.getDeclaringClass().getName() + '.' + field.getName());
}
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), field, valueEntries.get(0).getInnerText());
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), fieldSetter, valueEntries.get(0).getInnerText());
}
}
return true;
@@ -120,4 +126,27 @@
return allowed;
}
+ FieldValueSetter getFieldValueSetter(Field field)
+ {
+ String fieldName = field.getName();
+ String methodName = "set" + Character.toUpperCase(fieldName.charAt(0)) + fieldName.substring(1);
+ Method setter = null;
+ try
+ {
+ setter = field.getDeclaringClass().getMethod(methodName, field.getType());
+ }
+ catch (SecurityException e)
+ {
+
+ }
+ catch (NoSuchMethodException e)
+ {
+
+ }
+ if (setter != null)
+ {
+ return new MethodFieldSetter(setter);
+ }
+ return new DirectFieldSetter(field);
+ }
}
Modified: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java 2010-01-16 06:25:13 UTC (rev 11967)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java 2010-01-16 22:13:59 UTC (rev 11968)
@@ -11,7 +11,7 @@
public class FieldValueBean
{
- public int ivalue = 20;
+ private int ivalue = 20;
public String stringValue;
@@ -29,4 +29,14 @@
public long lvalue;
+ public void setIvalue(int value)
+ {
+ this.ivalue = value + 1;
+ }
+
+ public int getIvalue()
+ {
+ return ivalue;
+ }
+
}
Modified: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java 2010-01-16 06:25:13 UTC (rev 11967)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java 2010-01-16 22:13:59 UTC (rev 11968)
@@ -28,7 +28,7 @@
assert x.dvalue == 0;
assert x.enumValue == QualifierEnum.A;
assert x.fvalue == 0;
- assert x.ivalue == 10;
+ assert x.getIvalue() == 11;
assert x.lvalue == 23;
assert x.svalue == 4;
14 years, 11 months
Seam SVN: r11967 - in modules/xml/trunk: docs and 46 other directories.
by seam-commits@lists.jboss.org
Author: swd847
Date: 2010-01-16 01:25:13 -0500 (Sat, 16 Jan 2010)
New Revision: 11967
Added:
modules/xml/trunk/docs/
modules/xml/trunk/docs/pom.xml
modules/xml/trunk/docs/src/
modules/xml/trunk/docs/src/main/
modules/xml/trunk/docs/src/main/docbook/
modules/xml/trunk/docs/src/main/en-US/
modules/xml/trunk/docs/src/main/en-US/master.xml
modules/xml/trunk/docs/src/main/en-US/xml-general.xml
modules/xml/trunk/src/main/java/
modules/xml/trunk/src/main/java/org/
modules/xml/trunk/src/main/java/org/jboss/
modules/xml/trunk/src/main/java/org/jboss/seam/
modules/xml/trunk/src/main/java/org/jboss/seam/xml/
modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/
modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlDocument.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlDocumentProvider.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/
modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/BeanResult.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/XmlId.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/XmlResult.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldTypeSetter.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldValueObject.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/InjectionTargetWrapper.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/DependsXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/MethodXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ResultType.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/VetoXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItemType.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/ParserMain.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/SaxNode.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/CompositeNamespaceElementResolver.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/InvalidElementException.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceElementResolver.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceUtils.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/
modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/FileDataReader.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/XmlObjectConverter.java
modules/xml/trunk/src/main/resources/META-INF/services/
modules/xml/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
modules/xml/trunk/src/main/resources/META-INF/services/org.jboss.seam.xml.XmlExtension
modules/xml/trunk/src/test/
modules/xml/trunk/src/test/java/
modules/xml/trunk/src/test/java/org/
modules/xml/trunk/src/test/java/org/jboss/
modules/xml/trunk/src/test/java/org/jboss/seam/
modules/xml/trunk/src/test/java/org/jboss/seam/xml/
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/AbstractXMLTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/BootstrapTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/TestXmlProvider.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/ArrayFieldValue.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/CollectionFieldValue.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueProducer.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/MapFieldValue.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetArrayFieldValueBeanTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetCollectionFieldValueBeanTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetMapFieldValueBeanTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/OtherQualifier.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerFieldValueBeanTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerQualifier.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifiedBean1.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifiedBean2.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifierAttributesTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifierTestBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/RecieverBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptedBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorBinding.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/DecoratedInterface.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Decorator1.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTarget.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodValueBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/QualifiedType.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Qualifier1.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Qualifier2.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/QualifierEnum.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean1.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean2.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean3.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/SimpleBeanTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/VetoTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/VetoedBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/stereotype/
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/stereotype/Stereotype1.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/stereotype/StereotypeTest.java
modules/xml/trunk/src/test/resources/
modules/xml/trunk/src/test/resources/META-INF/
modules/xml/trunk/src/test/resources/META-INF/beans.xml
modules/xml/trunk/src/test/resources/META-INF/seam-beans.xml
modules/xml/trunk/src/test/resources/META-INF/services/
modules/xml/trunk/src/test/resources/META-INF/services/org.jboss.seam.xml.XmlExtension
modules/xml/trunk/src/test/resources/org/
modules/xml/trunk/src/test/resources/org/jboss/
modules/xml/trunk/src/test/resources/org/jboss/seam/
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/array-set-field-value-beans.xml
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/colection-set-field-value-beans.xml
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/map-set-field-value-beans.xml
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/set-field-value-beans.xml
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/producer-field-value-beans.xml
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/qualifier-attributes-test-beans.xml
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/interceptor/
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/interceptor/interceptor-beans.xml
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/simple/
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/simple/simple-beans.xml
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/simple/veto-beans.xml
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/stereotype/
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/stereotype/stereotype-beans.xml
Modified:
modules/xml/trunk/pom.xml
modules/xml/trunk/readme.txt
Log:
Initial commit of seam-xml
Added: modules/xml/trunk/docs/pom.xml
===================================================================
--- modules/xml/trunk/docs/pom.xml (rev 0)
+++ modules/xml/trunk/docs/pom.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,54 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>xml-reference-guide</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ <packaging>jdocbook</packaging>
+
+ <name>Seam XML Reference Guide</name>
+
+ <pluginRepositories>
+ <pluginRepository>
+ <id>repository.jboss.org</id>
+ <name>JBoss Repository</name>
+ <url>http://repository.jboss.org/maven2</url>
+ </pluginRepository>
+ </pluginRepositories>
+ <repositories>
+ <repository>
+ <id>repository.jboss.org</id>
+ <name>JBoss Repository</name>
+ <url>http://repository.jboss.org/maven2</url>
+ </repository>
+ </repositories>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.jboss.maven.plugins</groupId>
+ <artifactId>maven-jdocbook-plugin</artifactId>
+
+ <configuration>
+ <sourceDocumentName>master.xml</sourceDocumentName>
+ <masterTranslation>en-US</masterTranslation>
+ <formats>
+ <format>
+ <formatName>pdf</formatName>
+ <finalName>remoting-reference.pdf</finalName>
+ </format>
+ <format>
+ <formatName>html</formatName>
+ <finalName>index.html</finalName>
+ </format>
+ </formats>
+ <options>
+ <xincludeSupported>false</xincludeSupported>
+ </options>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added: modules/xml/trunk/docs/src/main/en-US/master.xml
===================================================================
--- modules/xml/trunk/docs/src/main/en-US/master.xml (rev 0)
+++ modules/xml/trunk/docs/src/main/en-US/master.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,11 @@
+<?xml version='1.0' encoding="utf-8"?>
+<!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN"
+ "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd" [ ]>
+<book lang="en">
+
+ <toc/>
+
+ <title>Seam XML Configuration</title>
+ <xi:include href="xml-general.xml" xmlns:xi="http://www.w3.org/2001/XInclude" />
+
+</book>
\ No newline at end of file
Added: modules/xml/trunk/docs/src/main/en-US/xml-general.xml
===================================================================
--- modules/xml/trunk/docs/src/main/en-US/xml-general.xml (rev 0)
+++ modules/xml/trunk/docs/src/main/en-US/xml-general.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,10 @@
+c<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.3//EN" "http://www.oasis-open.org/docbook/xml/4.3/docbookx.dtd">
+
+<chapter id="remoting">
+ <title>Seam XML Configuration</title>
+
+ <para>Seam provides a method for configuring JSR-299 beans using XML. </para>
+
+
+</chapter>
Property changes on: modules/xml/trunk/docs/src/main/en-US/xml-general.xml
___________________________________________________________________
Name: svn:executable
+ *
Modified: modules/xml/trunk/pom.xml
===================================================================
--- modules/xml/trunk/pom.xml 2010-01-15 19:06:49 UTC (rev 11966)
+++ modules/xml/trunk/pom.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -1,24 +1,19 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
+<?xml version="1.0"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>seam-parent</artifactId>
<groupId>org.jboss.seam</groupId>
- <artifactId>seam-parent</artifactId>
<version>3.0.0-SNAPSHOT</version>
</parent>
-
- <groupId>org.jboss.seam</groupId>
+
<artifactId>seam-xml</artifactId>
- <name>xml</name>
- <version>1.0-SNAPSHOT</version>
-
- <properties>
- <seam.version>3.0.0-SNAPSHOT</seam.version>
- </properties>
-
- <!-- Snapshots repo to get parent -->
+ <packaging>jar</packaging>
+ <version>3.0.0-SNAPSHOT</version>
+ <name>Seam XML Configuration</name>
+
<repositories>
<repository>
<id>oss.sonatype.org/jboss-snapshots</id>
@@ -32,21 +27,71 @@
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
- </repositories>
+ </repositories>
- <dependencies>
- <!-- CDI (JSR-299) -->
- <dependency>
- <groupId>javax.enterprise</groupId>
- <artifactId>cdi-api</artifactId>
- <scope>provided</scope>
- </dependency>
- </dependencies>
-
+ <properties>
+ <seam.version>3.0.0-SNAPSHOT</seam.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-core</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-extensions</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-se</artifactId>
+ <version>1.0.0-CR2</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>5.10</version>
+ <type>jar</type>
+ <classifier>jdk15</classifier>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
<scm>
<connection>scm:svn:http://anonsvn.jboss.org/repos/seam/modules/xml/trunk</connection>
<developerConnection>scm:svn:https://svn.jboss.org/repos/seam/modules/xml/trunk</developerConnection>
<url>http://fisheye.jboss.org/browse/Seam/modules/xml/trunk</url>
</scm>
-
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <configuration>
+ <workspace>${basedir}</workspace>
+
+ <downloadJavadocs>true</downloadJavadocs>
+ <downloadSources>true</downloadSources>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
Modified: modules/xml/trunk/readme.txt
===================================================================
--- modules/xml/trunk/readme.txt 2010-01-15 19:06:49 UTC (rev 11966)
+++ modules/xml/trunk/readme.txt 2010-01-16 06:25:13 UTC (rev 11967)
@@ -1,4 +1,73 @@
-Seam xml
-=============
+Seam XML Extensions Readme
-TODO
+To use:
+
+Place the seam-xml*.jar on the classpath,
+
+The extension will look for a file called seam-beans.xml in the root of all archives in the deployment. There is an extension mechanism
+that allows you to register other xml sources that will get documented in a future release (have a look at TestXmlProvider and the
+org.jboss.seam.xml.XmlExtension file if you want more info).
+
+The xml format:
+
+The best way to understand the format is with some examples:
+
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.beans">
+ <test:Bean1/>
+</Beans>
+
+This registers a single bean, org.jboss.seam.xml.test.beans.Bean1
+
+
+<Beans xmlns="urn:jbraze:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.beans">
+
+ <test:Bean1>
+ <test:bean2>
+ <Inject/>
+ </test:bean2>
+ </test:Bean1>
+
+ <test:Bean2>
+ <test:produceBean3>
+ <Produces/>
+ </test:produceBean3>
+ </test:Bean2>
+
+</Beans>
+
+This registers two beans, Bean1 has injection target, a field named bean2. Bean2 has a producer field named produceBean3.
+
+
+<Beans xmlns="urn:jbraze:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.beans">
+
+ <test:OtherQualifier>
+ <Qualifier/>
+ </test:OtherQualifier>
+
+ <test:QualifiedBean1>
+ <test:OtherQualifier value1="AA" value2="1">A</test:OtherQualifier>
+ </test:QualifiedBean1>
+
+ <test:QualifiedBean2>
+ <test:OtherQualifier value1="BB" value2="2" value="B" />
+ </test:QualifiedBean2>
+
+ <test:QualifierTestBean>
+ <test:bean1>
+ <test:OtherQualifier value1="AA" value2="1" value="A" />
+ <Inject/>
+ </test:bean1>
+ <test:bean2>
+ <test:OtherQualifier value1="BB" value2="2">B</test:OtherQualifier>
+ <Inject/>
+ </test:bean2>
+ </test:QualifierTestBean>
+
+</Beans>
+
+This registers a qualifier, and then registers two beans with the given values for the qualifiers attributes.
+QualifierTestBean has two injection points, also with qualifiers. For more examples look at the
+src/test/resources folder.
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/ClassPathXmlDocumentProvider.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,126 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.bootstrap;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.ListIterator;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.parsers.ParserConfigurationException;
+
+import org.xml.sax.InputSource;
+
+/**
+ * Document Provider that loads XML documents from the classpath
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class ClassPathXmlDocumentProvider implements XmlDocumentProvider
+{
+
+ static final String[] DEFAULT_RESOURCES = { "seam-beans.xml", "META-INF/seam-beans.xml", "WEB-INF/seam-beans.xml" };
+
+ final String[] resources;
+
+ public ClassPathXmlDocumentProvider()
+ {
+ resources = DEFAULT_RESOURCES;
+ }
+
+ public ClassPathXmlDocumentProvider(String[] resources)
+ {
+ this.resources = resources;
+ }
+
+ List<URL> docs;
+
+ ListIterator<URL> iterator;
+
+ DocumentBuilderFactory factory;
+ DocumentBuilder builder;
+
+ public void open()
+ {
+
+ factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(true);
+ factory.setIgnoringComments(true);
+ factory.setIgnoringElementContentWhitespace(true);
+ try
+ {
+ builder = factory.newDocumentBuilder();
+ }
+ catch (ParserConfigurationException e1)
+ {
+ throw new RuntimeException(e1);
+ }
+ docs = new ArrayList<URL>();
+ for (String i : resources)
+ {
+ try
+ {
+ Enumeration<URL> e = getClass().getClassLoader().getResources(i);
+ while (e.hasMoreElements())
+ {
+ docs.add(e.nextElement());
+ }
+ iterator = docs.listIterator();
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+
+ public void close()
+ {
+ // noop
+ }
+
+ public XmlDocument getNextDocument()
+ {
+
+ if (!iterator.hasNext())
+ {
+ return null;
+ }
+ try
+ {
+ final URL url = iterator.next();
+ return new XmlDocument()
+ {
+
+ public InputSource getInputSource()
+ {
+ try
+ {
+ return new InputSource(url.openStream());
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public String getFileUrl()
+ {
+ return url.toString();
+ }
+ };
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlDocument.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlDocument.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlDocument.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,14 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.bootstrap;
+
+import org.xml.sax.InputSource;
+
+public interface XmlDocument
+{
+ public InputSource getInputSource();
+
+ public String getFileUrl();
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlDocumentProvider.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlDocumentProvider.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlDocumentProvider.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,23 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.bootstrap;
+
+/**
+ * classes that implement this interface can be used to load other XML
+ * documents, this is useful for testing
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public interface XmlDocumentProvider
+{
+
+ void open();
+
+ XmlDocument getNextDocument();
+
+ void close();
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,211 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.bootstrap;
+
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.enterprise.inject.spi.ProcessInjectionTarget;
+
+import org.jboss.seam.xml.core.BeanResult;
+import org.jboss.seam.xml.core.XmlId;
+import org.jboss.seam.xml.core.XmlResult;
+import org.jboss.seam.xml.fieldset.FieldValueObject;
+import org.jboss.seam.xml.fieldset.InjectionTargetWrapper;
+import org.jboss.seam.xml.model.ModelBuilder;
+import org.jboss.seam.xml.parser.ParserMain;
+import org.jboss.seam.xml.parser.SaxNode;
+import org.jboss.seam.xml.util.FileDataReader;
+import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
+
+public class XmlExtension implements Extension
+{
+
+ AnnotationInstanceProvider ac = new AnnotationInstanceProvider();
+
+ static final String PROVIDERS_FILE = "META-INF/services/org.jboss.seam.xml.XmlExtension";
+
+ List<XmlResult> results = new ArrayList<XmlResult>();
+
+ Set<Class> veto = new HashSet<Class>();
+
+ Map<Class, AnnotatedType> types = new HashMap<Class, AnnotatedType>();
+
+ int count = 0;
+
+ /**
+ * map of syntetic bean id to a list of field value objects
+ */
+ Map<Integer, List<FieldValueObject>> fieldValues = new HashMap<Integer, List<FieldValueObject>>();
+
+ /**
+ * This is the entry point for the extension
+ */
+ public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event)
+ {
+ boolean problems = false;
+ StringBuilder problemString = new StringBuilder();
+
+ List<Class<? extends XmlDocumentProvider>> providers = getDocumentProviders();
+ for (Class<? extends XmlDocumentProvider> cl : providers)
+ {
+ try
+ {
+ XmlDocumentProvider provider = cl.newInstance();
+ provider.open();
+ XmlDocument d;
+ while ((d = provider.getNextDocument()) != null)
+ {
+ ParserMain parser = new ParserMain();
+ ModelBuilder builder = new ModelBuilder();
+ SaxNode parentNode = parser.parse(d.getInputSource(), d.getFileUrl());
+ ;
+ results.add(builder.build(parentNode));
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ for (XmlResult r : results)
+ {
+ if (!r.getProblems().isEmpty())
+ {
+ problems = true;
+ for (String i : r.getProblems())
+ {
+ problemString.append(i);
+ problemString.append("\n");
+ }
+ }
+ for (BeanResult b : r.getFieldValues().keySet())
+ {
+ int val = count++;
+ fieldValues.put(val, r.getFieldValues().get(b));
+ Map<String, Object> am = new HashMap<String, Object>();
+ am.put("value", val);
+ Annotation a = ac.get(XmlId.class, am);
+ b.getBuilder().addToClass(a);
+ }
+
+ for (Class b : r.getQualifiers())
+ {
+ event.addQualifier(b);
+ }
+ for (Class b : r.getInterceptorBindings())
+ {
+ event.addInterceptorBinding(b);
+ }
+ for (Entry<Class<? extends Annotation>, Annotation[]> b : r.getStereotypes().entrySet())
+ {
+ event.addStereotype(b.getKey(), b.getValue());
+ }
+ for (BeanResult bb : r.getBeans())
+ {
+ boolean install = true;
+ for (Object className : bb.getDependencies())
+ {
+ try
+ {
+ bb.getType().getClassLoader().loadClass(className.toString());
+ }
+ catch (ClassNotFoundException e)
+ {
+ install = false;
+ break;
+ }
+ }
+ if (install)
+ {
+ AnnotatedType tp = bb.getBuilder().create();
+ event.addAnnotatedType(tp);
+ types.put(tp.getJavaClass(), tp);
+ }
+ }
+ veto.addAll(r.getVeto());
+
+ }
+ if (problems)
+ {
+ throw new RuntimeException(problemString.toString());
+ }
+ }
+
+ public void processAnotated(@Observes ProcessAnnotatedType event)
+ {
+ // veto implementation
+ if (veto.contains(event.getAnnotatedType().getJavaClass()))
+ {
+ event.veto();
+ }
+ }
+
+ public void processInjectionTarget(@Observes ProcessInjectionTarget event)
+ {
+
+ AnnotatedType at = event.getAnnotatedType();
+ XmlId xid = at.getAnnotation(XmlId.class);
+ if (xid != null)
+ {
+ List<FieldValueObject> fvs = fieldValues.get(xid.value());
+ event.setInjectionTarget(new InjectionTargetWrapper(event.getInjectionTarget(), fvs));
+ }
+
+ }
+
+ public List<Class<? extends XmlDocumentProvider>> getDocumentProviders()
+ {
+ List<Class<? extends XmlDocumentProvider>> ret = new ArrayList<Class<? extends XmlDocumentProvider>>();
+ try
+ {
+ Enumeration<URL> urls = getClass().getClassLoader().getResources(PROVIDERS_FILE);
+ while (urls.hasMoreElements())
+ {
+
+ URL u = urls.nextElement();
+ String data = FileDataReader.readUrl(u);
+ String[] providers = data.split("\\s");
+ for (String provider : providers)
+ {
+ Class res = null;
+ try
+ {
+ res = getClass().getClassLoader().loadClass(provider);
+ }
+ catch (ClassNotFoundException e)
+ {
+ res = Thread.currentThread().getContextClassLoader().loadClass(provider);
+ }
+ if (res == null)
+ {
+ throw new RuntimeException("Could not load XML configuration provider " + provider + " configured in file " + u.toString());
+ }
+ ret.add(res);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ return ret;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/BeanResult.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/BeanResult.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/BeanResult.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,44 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.core;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
+
+public class BeanResult<X>
+{
+ NewAnnotatedTypeBuilder builder;
+ List<String> dependencies = new ArrayList<String>();
+ Class type;
+
+ public BeanResult(Class type)
+ {
+ this.type = type;
+ builder = new NewAnnotatedTypeBuilder<X>(type);
+ }
+
+ public NewAnnotatedTypeBuilder getBuilder()
+ {
+ return builder;
+ }
+
+ public void addDependency(String className)
+ {
+ dependencies.add(className);
+ }
+
+ public List<String> getDependencies()
+ {
+ return Collections.unmodifiableList(dependencies);
+ }
+
+ public Class getType()
+ {
+ return type;
+ }
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/XmlId.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/XmlId.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/XmlId.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,20 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.core;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+/**
+ * Annotation that allows tracing of annotated types through the startup proces
+ *
+ * @author stuart
+ *
+ */
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface XmlId
+{
+ int value();
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/XmlResult.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/XmlResult.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/XmlResult.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,83 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.core;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.seam.xml.fieldset.FieldValueObject;
+
+/**
+ * Stores the result of parsing an XML document
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class XmlResult
+{
+
+ Map<Class<? extends Annotation>, Annotation[]> stereotypes = new HashMap<Class<? extends Annotation>, Annotation[]>();
+
+ List<Class<? extends Annotation>> qualifiers = new ArrayList<Class<? extends Annotation>>();
+
+ List<Class<? extends Annotation>> interceptorBindings = new ArrayList<Class<? extends Annotation>>();
+
+ List<Class> veto = new ArrayList<Class>();
+
+ List<String> problems = new ArrayList<String>();
+
+ List<BeanResult> beans = new ArrayList<BeanResult>();
+
+ Map<BeanResult, List<FieldValueObject>> fieldValues = new HashMap<BeanResult, List<FieldValueObject>>();
+
+ public Map<Class<? extends Annotation>, Annotation[]> getStereotypes()
+ {
+ return stereotypes;
+ }
+
+ public List<Class<? extends Annotation>> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ public List<Class<? extends Annotation>> getInterceptorBindings()
+ {
+ return interceptorBindings;
+ }
+
+ public List<BeanResult> getBeans()
+ {
+ return beans;
+ }
+
+ public List<String> getProblems()
+ {
+ return problems;
+ }
+
+ public void addProblem(String p)
+ {
+ problems.add(p);
+ }
+
+ public Map<BeanResult, List<FieldValueObject>> getFieldValues()
+ {
+ return fieldValues;
+ }
+
+ public void addVeto(Class clazz)
+ {
+ veto.add(clazz);
+ }
+
+ public List<Class> getVeto()
+ {
+ return veto;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,153 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.fieldset;
+
+import java.lang.reflect.Array;
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.seam.xml.model.XmlItem;
+import org.jboss.seam.xml.util.XmlObjectConverter;
+
+/**
+ * class responsible for setting the value of array properties.
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class ArrayFieldSet implements FieldValueObject
+{
+ Field field;
+ List<AFS> values;
+ Class arrayType;
+
+ public ArrayFieldSet(Field field, List<XmlItem> items)
+ {
+ this.field = field;
+ this.values = new ArrayList<AFS>();
+
+ arrayType = field.getType().getComponentType();
+ AFS setter;
+ for (XmlItem i : items)
+ {
+ final Object fv = XmlObjectConverter.convert(arrayType, i.getInnerText());
+ if (field.getType() == char.class)
+ {
+
+ final char val = (Character) fv;
+ setter = new AFS()
+ {
+ public void set(Object o, int i) throws IllegalAccessException
+ {
+ Array.setChar(o, i, val);
+ }
+ };
+ }
+ else if (field.getType() == int.class)
+ {
+ final int val = (Integer) fv;
+ setter = new AFS()
+ {
+ public void set(Object o, int i) throws IllegalAccessException
+ {
+ Array.setInt(o, i, val);
+ }
+ };
+ }
+ else if (field.getType() == short.class)
+ {
+ final short val = (Short) fv;
+ setter = new AFS()
+ {
+ public void set(Object o, int i) throws IllegalAccessException
+ {
+ Array.setShort(o, i, val);
+ }
+ };
+ }
+ else if (field.getType() == long.class)
+ {
+ final long val = (Long) fv;
+ setter = new AFS()
+ {
+ public void set(Object o, int i) throws IllegalAccessException
+ {
+ Array.setLong(o, i, val);
+ }
+ };
+ }
+ else if (field.getType() == byte.class)
+ {
+ final byte val = (Byte) fv;
+ setter = new AFS()
+ {
+ public void set(Object o, int i) throws IllegalAccessException
+ {
+ Array.setByte(o, i, val);
+ }
+ };
+ }
+ else if (field.getType() == double.class)
+ {
+ final double val = (Double) fv;
+ setter = new AFS()
+ {
+ public void set(Object o, int i) throws IllegalAccessException
+ {
+ Array.setDouble(o, i, val);
+ }
+ };
+ }
+ else if (field.getType() == float.class)
+ {
+ final float val = (Float) fv;
+ setter = new AFS()
+ {
+ public void set(Object o, int i) throws IllegalAccessException
+ {
+ Array.setFloat(o, i, val);
+ }
+ };
+ }
+ else
+ {
+ final Object val = fv;
+ setter = new AFS()
+ {
+ public void set(Object o, int i) throws IllegalAccessException
+ {
+ Array.set(o, i, val);
+ }
+ };
+ }
+ values.add(setter);
+ }
+
+ }
+
+ public void setValue(Object instance)
+ {
+ try
+ {
+ Object array = Array.newInstance(arrayType, values.size());
+ field.set(instance, array);
+ for (int i = 0; i < values.size(); ++i)
+ {
+ values.get(i).set(array, i);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ interface AFS
+ {
+ void set(Object o, int i) throws IllegalAccessException;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,150 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.fieldset;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import org.jboss.seam.xml.model.XmlItem;
+import org.jboss.seam.xml.util.XmlObjectConverter;
+
+/**
+ * class responsible for setting the value of collection properties.
+ *
+ * It can deal with the following collection types: -Set -List -Collection
+ * -SortedSet -HashSet -ArrayList -TreeSet -LinkedList
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class CollectionFieldSet implements FieldValueObject
+{
+ Field field;
+ List<CFS> values;
+ Class elementType;
+ Class<? extends Collection> collectionType;
+
+ public CollectionFieldSet(Field field, List<XmlItem> items)
+ {
+ this.field = field;
+ this.values = new ArrayList<CFS>();
+ discoverElementType();
+
+ CFS setter;
+ for (XmlItem i : items)
+ {
+ final Object fv = XmlObjectConverter.convert(elementType, i.getInnerText());
+
+ setter = new CFS()
+ {
+ public void add(Collection o) throws IllegalAccessException
+ {
+ o.add(fv);
+ }
+ };
+
+ values.add(setter);
+ }
+
+ }
+
+ public void discoverElementType()
+ {
+ Type type = field.getGenericType();
+ if (type instanceof ParameterizedType)
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+
+ if (parameterizedType.getRawType() == Collection.class)
+ {
+ elementType = (Class) parameterizedType.getActualTypeArguments()[0];
+ collectionType = LinkedHashSet.class;
+ }
+ else if (parameterizedType.getRawType() == List.class)
+ {
+ elementType = (Class) parameterizedType.getActualTypeArguments()[0];
+ collectionType = ArrayList.class;
+ }
+ else if (parameterizedType.getRawType() == Set.class)
+ {
+ elementType = (Class) parameterizedType.getActualTypeArguments()[0];
+ collectionType = LinkedHashSet.class;
+ }
+ else if (parameterizedType.getRawType() == SortedSet.class)
+ {
+ elementType = (Class) parameterizedType.getActualTypeArguments()[0];
+ collectionType = TreeSet.class;
+ }
+ else if (parameterizedType.getRawType() == HashSet.class)
+ {
+ elementType = (Class) parameterizedType.getActualTypeArguments()[0];
+ collectionType = HashSet.class;
+ }
+ else if (parameterizedType.getRawType() == ArrayList.class)
+ {
+ elementType = (Class) parameterizedType.getActualTypeArguments()[0];
+ collectionType = ArrayList.class;
+ }
+ else if (parameterizedType.getRawType() == LinkedList.class)
+ {
+ elementType = (Class) parameterizedType.getActualTypeArguments()[0];
+ collectionType = LinkedList.class;
+ }
+ else if (parameterizedType.getRawType() == LinkedHashSet.class)
+ {
+ elementType = (Class) parameterizedType.getActualTypeArguments()[0];
+ collectionType = LinkedHashSet.class;
+ }
+ else if (parameterizedType.getRawType() == TreeSet.class)
+ {
+ elementType = (Class) parameterizedType.getActualTypeArguments()[0];
+ collectionType = TreeSet.class;
+ }
+ else
+ {
+ throw new RuntimeException("Could not determine element type for " + field.getDeclaringClass().getName() + "." + field.getName());
+ }
+
+ }
+ else
+ {
+ throw new RuntimeException("Could not determine element type for " + field.getDeclaringClass().getName() + "." + field.getName());
+ }
+
+ }
+
+ public void setValue(Object instance)
+ {
+ try
+ {
+ Collection res = collectionType.newInstance();
+ field.set(instance, res);
+ for (int i = 0; i < values.size(); ++i)
+ {
+ values.get(i).add(res);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ interface CFS
+ {
+ void add(Collection o) throws IllegalAccessException;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldTypeSetter.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldTypeSetter.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldTypeSetter.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,20 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.fieldset;
+
+import java.lang.reflect.Field;
+
+/**
+ * Interface the can set primitive types
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public interface FieldTypeSetter
+{
+
+ public void setField(String value, Field field);
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldValueObject.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldValueObject.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/FieldValueObject.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,12 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.fieldset;
+
+public interface FieldValueObject
+{
+
+ public void setValue(Object instance);
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/InjectionTargetWrapper.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/InjectionTargetWrapper.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/InjectionTargetWrapper.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,61 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.fieldset;
+
+import java.util.List;
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.InjectionPoint;
+import javax.enterprise.inject.spi.InjectionTarget;
+
+public class InjectionTargetWrapper<T> implements InjectionTarget<T>
+{
+ InjectionTarget<T> target;
+ List<FieldValueObject> fieldValues;
+
+ public InjectionTargetWrapper(InjectionTarget<T> target, List<FieldValueObject> fieldValues)
+ {
+ this.fieldValues = fieldValues;
+ this.target = target;
+ }
+
+ public void inject(T instance, CreationalContext<T> ctx)
+ {
+ target.inject(instance, ctx);
+
+ }
+
+ public void postConstruct(T instance)
+ {
+ for (FieldValueObject f : fieldValues)
+ {
+ f.setValue(instance);
+ }
+ target.postConstruct(instance);
+
+ }
+
+ public void preDestroy(T instance)
+ {
+ target.preDestroy(instance);
+ }
+
+ public void dispose(T instance)
+ {
+ target.dispose(instance);
+ }
+
+ public Set<InjectionPoint> getInjectionPoints()
+ {
+ return target.getInjectionPoints();
+ }
+
+ public T produce(CreationalContext<T> ctx)
+ {
+ return target.produce(ctx);
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,132 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.fieldset;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import org.jboss.seam.xml.model.EntryXmlItem;
+import org.jboss.seam.xml.util.XmlObjectConverter;
+
+/**
+ * class responsible for setting the value of map properties.
+ *
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class MapFieldSet implements FieldValueObject
+{
+ Field field;
+ List<MFS> values;
+ Class keyType;
+ Class valueType;
+ Class<? extends Map> collectionType;
+
+ public MapFieldSet(Field field, List<EntryXmlItem> items)
+ {
+ this.field = field;
+ this.values = new ArrayList<MFS>();
+ discoverElementType();
+
+ for (EntryXmlItem i : items)
+ {
+ MFS setter;
+ final Object key = XmlObjectConverter.convert(keyType, i.getKey().getInnerText());
+ final Object value = XmlObjectConverter.convert(valueType, i.getValue().getInnerText());
+ setter = new MFS()
+ {
+ public void add(Map m) throws IllegalAccessException
+ {
+ m.put(key, value);
+ }
+ };
+
+ values.add(setter);
+ }
+
+ }
+
+ public void discoverElementType()
+ {
+ Type type = field.getGenericType();
+ if (type instanceof ParameterizedType)
+ {
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+
+ if (parameterizedType.getRawType() == Map.class)
+ {
+ keyType = (Class) parameterizedType.getActualTypeArguments()[0];
+ valueType = (Class) parameterizedType.getActualTypeArguments()[1];
+ collectionType = LinkedHashMap.class;
+ }
+ else if (parameterizedType.getRawType() == LinkedHashMap.class)
+ {
+ keyType = (Class) parameterizedType.getActualTypeArguments()[0];
+ valueType = (Class) parameterizedType.getActualTypeArguments()[1];
+ collectionType = LinkedHashMap.class;
+ }
+ else if (parameterizedType.getRawType() == HashMap.class)
+ {
+ keyType = (Class) parameterizedType.getActualTypeArguments()[0];
+ valueType = (Class) parameterizedType.getActualTypeArguments()[1];
+ collectionType = HashMap.class;
+ }
+ else if (parameterizedType.getRawType() == SortedMap.class)
+ {
+ keyType = (Class) parameterizedType.getActualTypeArguments()[0];
+ valueType = (Class) parameterizedType.getActualTypeArguments()[1];
+ collectionType = TreeMap.class;
+ }
+ else if (parameterizedType.getRawType() == TreeMap.class)
+ {
+ keyType = (Class) parameterizedType.getActualTypeArguments()[0];
+ valueType = (Class) parameterizedType.getActualTypeArguments()[1];
+ collectionType = TreeMap.class;
+ }
+ else
+ {
+ throw new RuntimeException("Could not determine element type for map " + field.getDeclaringClass().getName() + "." + field.getName());
+ }
+
+ }
+ else
+ {
+ throw new RuntimeException("Could not determine element type for map " + field.getDeclaringClass().getName() + "." + field.getName());
+ }
+
+ }
+
+ public void setValue(Object instance)
+ {
+ try
+ {
+ Map res = collectionType.newInstance();
+ field.set(instance, res);
+ for (int i = 0; i < values.size(); ++i)
+ {
+ values.get(i).add(res);
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ interface MFS
+ {
+ void add(Map o) throws IllegalAccessException;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,132 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.fieldset;
+
+import java.lang.reflect.Field;
+
+import org.jboss.seam.xml.util.XmlObjectConverter;
+
+public class SimpleFieldValue implements FieldValueObject
+{
+
+ final Field field;
+
+ FS setter;
+
+ public SimpleFieldValue(Class javaObject, final Field f, final String value)
+ {
+ this.field = f;
+ field.setAccessible(true);
+
+ Object fv = XmlObjectConverter.convert(f.getType(), value);
+ if (field.getType() == char.class)
+ {
+
+ final char val = (Character) fv;
+ setter = new FS()
+ {
+ public void set(Object o) throws IllegalAccessException
+ {
+ field.setChar(o, val);
+ }
+ };
+ }
+ else if (field.getType() == int.class)
+ {
+ final int val = (Integer) fv;
+ setter = new FS()
+ {
+ public void set(Object o) throws IllegalAccessException
+ {
+ field.setInt(o, val);
+ }
+ };
+ }
+ else if (field.getType() == short.class)
+ {
+ final short val = (Short) fv;
+ setter = new FS()
+ {
+ public void set(Object o) throws IllegalAccessException
+ {
+ field.setShort(o, val);
+ }
+ };
+ }
+ else if (field.getType() == long.class)
+ {
+ final long val = (Long) fv;
+ setter = new FS()
+ {
+ public void set(Object o) throws IllegalAccessException
+ {
+ field.setLong(o, val);
+ }
+ };
+ }
+ else if (field.getType() == byte.class)
+ {
+ final byte val = (Byte) fv;
+ setter = new FS()
+ {
+ public void set(Object o) throws IllegalAccessException
+ {
+ field.setByte(o, val);
+ }
+ };
+ }
+ else if (field.getType() == double.class)
+ {
+ final double val = (Double) fv;
+ setter = new FS()
+ {
+ public void set(Object o) throws IllegalAccessException
+ {
+ field.setDouble(o, val);
+ }
+ };
+ }
+ else if (field.getType() == float.class)
+ {
+ final float val = (Float) fv;
+ setter = new FS()
+ {
+ public void set(Object o) throws IllegalAccessException
+ {
+ field.setFloat(o, val);
+ }
+ };
+ }
+ else
+ {
+ final Object val = fv;
+ setter = new FS()
+ {
+ public void set(Object o) throws IllegalAccessException
+ {
+ field.set(o, val);
+ }
+ };
+ }
+ }
+
+ interface FS
+ {
+ void set(Object o) throws IllegalAccessException;
+ }
+
+ public void setValue(Object instance)
+ {
+ try
+ {
+ setter.set(instance);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,98 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.seam.xml.fieldset.FieldValueObject;
+
+public abstract class AbstractXmlItem implements XmlItem
+{
+ final XmlItemType type;
+ final XmlItem parent;
+ final Class javaClass;
+
+ final String innerText;
+ final Map<String, String> attributes;
+
+ public String getInnerText()
+ {
+ return innerText;
+ }
+
+ public AbstractXmlItem(XmlItemType type, XmlItem parent, Class javaClass, String innerText, Map<String, String> attributes)
+ {
+ this.type = type;
+ this.parent = parent;
+ this.javaClass = javaClass;
+ this.innerText = innerText;
+ if (attributes == null)
+ {
+ this.attributes = new HashMap<String, String>();
+ }
+ else
+ {
+ this.attributes = attributes;
+ }
+ }
+
+ final List<XmlItem> children = new ArrayList<XmlItem>();
+
+ public void addChild(XmlItem xmlItem)
+ {
+ children.add(xmlItem);
+ }
+
+ public XmlItem getParent()
+ {
+ return parent;
+ }
+
+ public List<XmlItem> getChildren()
+ {
+ return Collections.unmodifiableList(children);
+ }
+
+ public XmlItemType getType()
+ {
+ return type;
+ }
+
+ public Field getField()
+ {
+ return null;
+ }
+
+ public Method getMethod()
+ {
+ return null;
+ }
+
+ public Class getJavaClass()
+ {
+ return javaClass;
+ }
+
+ public boolean resolveChildren()
+ {
+ return true;
+ }
+
+ public Map<String, String> getAttributes()
+ {
+ return attributes;
+ }
+
+ public FieldValueObject getFieldValue()
+ {
+ return null;
+ }
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,41 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.util.Collections;
+import java.util.Map;
+import java.util.Set;
+
+public class AnnotationXmlItem extends AbstractXmlItem
+{
+
+ /**
+ * create a class note. If the class is an annotation in can have inner text
+ * to represent the 'value' of the annotation, if can also have atrributes to
+ * represent other properties
+ *
+ * @param parent
+ * @param c
+ * @param innerText
+ * @param attributes
+ */
+ public AnnotationXmlItem(XmlItem parent, Class c, String innerText, Map<String, String> attributes)
+ {
+ super(XmlItemType.ANNOTATION, parent, c, innerText, attributes);
+ if (innerText != null)
+ {
+ if (!innerText.trim().equals(""))
+ {
+ attributes.put("value", innerText);
+ }
+ }
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return Collections.EMPTY_SET;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,116 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.seam.xml.fieldset.FieldValueObject;
+
+public class ArrayXmlItem implements XmlItem
+{
+
+ XmlItem child = null, parent;
+
+ Class javaClass;
+
+ public ArrayXmlItem(XmlItem parent)
+ {
+ allowed.add(XmlItemType.CLASS);
+ this.parent = parent;
+ }
+
+ Set<XmlItemType> allowed = new HashSet<XmlItemType>();
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return allowed;
+ }
+
+ public void addChild(XmlItem xmlItem)
+ {
+ if (child != null)
+ {
+ throw new RuntimeException("Array elements can only have one child");
+ }
+ child = xmlItem;
+ }
+
+ public Map<String, String> getAttributes()
+ {
+ return Collections.EMPTY_MAP;
+ }
+
+ public List<XmlItem> getChildren()
+ {
+ return Collections.singletonList(child);
+ }
+
+ public Field getField()
+ {
+ return null;
+ }
+
+ public FieldValueObject getFieldValue()
+ {
+ return null;
+ }
+
+ public String getInnerText()
+ {
+ return null;
+ }
+
+ public Class getJavaClass()
+ {
+ return javaClass;
+ }
+
+ public Method getMethod()
+ {
+ return null;
+ }
+
+ public XmlItem getParent()
+ {
+ return parent;
+ }
+
+ public XmlItemType getType()
+ {
+ return XmlItemType.CLASS;
+ }
+
+ public boolean resolveChildren()
+ {
+ if (child == null)
+ {
+ throw new RuntimeException("<array> element must have a child specifying the array type");
+ }
+ Class l = child.getJavaClass();
+ try
+ {
+ javaClass = getClass().getClassLoader().loadClass("[L" + l.getName() + ";");
+ }
+ catch (ClassNotFoundException e)
+ {
+ try
+ {
+ javaClass = Thread.currentThread().getContextClassLoader().loadClass("[L" + l.getName() + ";");
+ }
+ catch (ClassNotFoundException e2)
+ {
+ throw new RuntimeException("Cannot create array class from " + l.getName());
+ }
+ }
+ return true;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,47 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class ClassXmlItem extends AbstractXmlItem
+{
+
+ HashSet<XmlItemType> allowed = new HashSet<XmlItemType>();
+
+ /**
+ * create a class note. If the class is an annotation in can have inner text
+ * to represent the 'value' of the annotation, if can also have atrributes to
+ * represent other properties
+ *
+ * @param parent
+ * @param c
+ * @param innerText
+ * @param attributes
+ */
+ public ClassXmlItem(XmlItem parent, Class c)
+ {
+ super(XmlItemType.CLASS, parent, c, null, null);
+ if (innerText != null)
+ {
+ if (!innerText.trim().equals(""))
+ {
+ attributes.put("value", innerText);
+ }
+ }
+ allowed.add(XmlItemType.ANNOTATION);
+ allowed.add(XmlItemType.FIELD);
+ allowed.add(XmlItemType.METHOD);
+ allowed.add(XmlItemType.CLASS);
+
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return allowed;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/DependsXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/DependsXmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/DependsXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,23 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.util.Collections;
+import java.util.Set;
+
+public class DependsXmlItem extends AbstractXmlItem
+{
+
+ public DependsXmlItem(XmlItem parent, String innerTest)
+ {
+ super(XmlItemType.DEPENDENCY, parent, null, innerTest, null);
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return Collections.EMPTY_SET;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,69 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class EntryXmlItem extends AbstractXmlItem
+{
+
+ final Set<XmlItemType> allowed = new HashSet<XmlItemType>();
+
+ XmlItem key;
+ XmlItem value;
+
+ public EntryXmlItem(XmlItem parent)
+ {
+ super(XmlItemType.ENTRY, parent, null, null, null);
+ allowed.add(XmlItemType.VALUE);
+ allowed.add(XmlItemType.KEY);
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return allowed;
+ }
+
+ @Override
+ public boolean resolveChildren()
+ {
+ if (children.size() != 2)
+ {
+ throw new RuntimeException("<entry> tags must have two children, a <key> and a <value>");
+ }
+ for (XmlItem i : children)
+ {
+ if (i.getType() == XmlItemType.VALUE)
+ {
+ if (value != null)
+ {
+ throw new RuntimeException("<entry> tags must have two children, a <key> and a <value>");
+ }
+ value = i;
+ }
+ else if (i.getType() == XmlItemType.KEY)
+ {
+ if (key != null)
+ {
+ throw new RuntimeException("<entry> tags must have two children, a <key> and a <value>");
+ }
+ key = i;
+ }
+ }
+ return true;
+ }
+
+ public XmlItem getKey()
+ {
+ return key;
+ }
+
+ public XmlItem getValue()
+ {
+ return value;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,123 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.lang.reflect.Field;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+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.MapFieldSet;
+import org.jboss.seam.xml.fieldset.SimpleFieldValue;
+
+public class FieldXmlItem extends AbstractXmlItem
+{
+
+ Field field;
+ FieldValueObject fieldValue;
+ HashSet<XmlItemType> allowed = new HashSet<XmlItemType>();
+
+ public FieldXmlItem(XmlItem parent, Field c, String innerText)
+ {
+ super(XmlItemType.FIELD, parent, parent.getJavaClass(), innerText, null);
+ this.field = c;
+ if (innerText != null && innerText.length() > 0)
+ {
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), c, innerText);
+ }
+ allowed.add(XmlItemType.ANNOTATION);
+ allowed.add(XmlItemType.VALUE);
+ }
+
+ public Field getField()
+ {
+ return field;
+ }
+
+ @Override
+ public FieldValueObject getFieldValue()
+ {
+ return fieldValue;
+ }
+
+ @Override
+ public boolean resolveChildren()
+ {
+ List<EntryXmlItem> mapEntries = new ArrayList<EntryXmlItem>();
+ List<XmlItem> valueEntries = new ArrayList<XmlItem>();
+ if (fieldValue == null)
+ {
+ for (XmlItem i : children)
+ {
+ if (i.getType() == XmlItemType.VALUE)
+ {
+ valueEntries.add(i);
+ }
+ else if (i.getType() == XmlItemType.ENTRY)
+ {
+ mapEntries.add((EntryXmlItem) i);
+ }
+
+ }
+ }
+ if (!mapEntries.isEmpty() || !valueEntries.isEmpty())
+ {
+ if (Map.class.isAssignableFrom(field.getType()))
+ {
+ if (!valueEntries.isEmpty())
+ {
+ throw new RuntimeException("Map fields cannot have <value> elements as children,only <entry> elements Field:" + field.getDeclaringClass().getName() + '.' + field.getName());
+ }
+ if (!mapEntries.isEmpty())
+ {
+ fieldValue = new MapFieldSet(field, mapEntries);
+ }
+ }
+ else if (Collection.class.isAssignableFrom(field.getType()) || field.getType().isArray())
+ {
+ if (!mapEntries.isEmpty())
+ {
+ throw new RuntimeException("Collection fields must be set using <value> not <entry> Field:" + field.getDeclaringClass().getName() + '.' + field.getName());
+ }
+ if (!valueEntries.isEmpty())
+ {
+ if (field.getType().isArray())
+ {
+ fieldValue = new ArrayFieldSet(field, valueEntries);
+ }
+ else
+ {
+ fieldValue = new CollectionFieldSet(field, valueEntries);
+ }
+ }
+ }
+ else
+ {
+ if (!mapEntries.isEmpty())
+ {
+ throw new RuntimeException("Only Map fields can be set using <entry> Field:" + field.getDeclaringClass().getName() + '.' + field.getName());
+ }
+ if (valueEntries.size() != 1)
+ {
+ throw new RuntimeException("Non collection fields can only have a single <value> element Field:" + field.getDeclaringClass().getName() + '.' + field.getName());
+ }
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), field, valueEntries.get(0).getInnerText());
+ }
+ }
+ return true;
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return allowed;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/KeyXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,22 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.util.Collections;
+import java.util.Set;
+
+public class KeyXmlItem extends AbstractXmlItem
+{
+
+ public KeyXmlItem(XmlItem parent, String innerText)
+ {
+ super(XmlItemType.KEY, parent, null, innerText, null);
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return Collections.EMPTY_SET;
+ }
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/MethodXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/MethodXmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/MethodXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,103 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+public class MethodXmlItem extends AbstractXmlItem
+{
+
+ private String methodName;
+
+ Method method;
+ HashSet<XmlItemType> allowed = new HashSet<XmlItemType>();
+
+ public MethodXmlItem(XmlItem parent, String methodName)
+ {
+ super(XmlItemType.METHOD, parent, parent.getJavaClass(), null, null);
+ // methods are lazily resolved once we know the parameter types
+ this.methodName = methodName;
+ Method found = null;
+ for (Method m : javaClass.getMethods())
+ {
+ if (m.getName().equals(methodName))
+ {
+ if (found == null)
+ {
+ found = m;
+ }
+ else
+ {
+ // we have to methods with the same name so resolution
+ // will have to wait
+ return;
+ }
+ }
+ }
+ method = found;
+ allowed.add(XmlItemType.ANNOTATION);
+ allowed.add(XmlItemType.CLASS);
+ }
+
+ /**
+ * attempts to resolve a lazy method declaration. Returns true if it succeeds
+ * or is unessesary, false otherwise
+ *
+ * @param childeren
+ * @return
+ */
+ public boolean resolveChildren()
+ {
+ // return true if this is not a method or there was only
+ // only method to choose from
+ if (method != null)
+ {
+ return true;
+ }
+
+ List<Class> rtList = new ArrayList<Class>();
+ for (XmlItem c : children)
+ {
+ if (c.getType() == XmlItemType.CLASS)
+ {
+ Class cl = c.getJavaClass();
+ rtList.add(cl);
+ }
+ }
+ Class[] alAr = new Class[rtList.size()];
+ for (int i = 0; i < rtList.size(); ++i)
+ {
+ alAr[i] = rtList.get(i);
+ }
+
+ try
+ {
+ method = javaClass.getMethod(methodName, alAr);
+ return true;
+ }
+ catch (SecurityException e)
+ {
+ throw new RuntimeException("Security Exception resolving method " + methodName + " on class " + javaClass.getName());
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new RuntimeException("NoSuchMethodException resolving method " + methodName + " on class " + javaClass.getName());
+ }
+ }
+
+ public Method getMethod()
+ {
+ return method;
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return allowed;
+ }
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,375 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.enterprise.inject.Stereotype;
+import javax.inject.Qualifier;
+import javax.interceptor.InterceptorBinding;
+
+import org.jboss.seam.xml.core.BeanResult;
+import org.jboss.seam.xml.core.XmlResult;
+import org.jboss.seam.xml.fieldset.FieldValueObject;
+import org.jboss.seam.xml.parser.SaxNode;
+import org.jboss.seam.xml.parser.namespace.InvalidElementException;
+import org.jboss.seam.xml.parser.namespace.NamespaceElementResolver;
+import org.jboss.seam.xml.parser.namespace.PackageNamespaceElementResolver;
+import org.jboss.seam.xml.parser.namespace.RootNamespaceElementResolver;
+import org.jboss.seam.xml.util.XmlObjectConverter;
+import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
+import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
+import org.w3c.dom.DOMException;
+
+/**
+ * Parser for xml configration
+ *
+ * @author stuart
+ *
+ */
+public class ModelBuilder
+{
+
+ AnnotationInstanceProvider ac = new AnnotationInstanceProvider();
+
+ static final String ROOT_NAMESPACE = "urn:seam:core";
+
+ Map<String, NamespaceElementResolver> resolvers;
+
+ public XmlResult build(SaxNode root)
+ {
+
+ resolvers = new HashMap<String, NamespaceElementResolver>();
+
+ XmlResult ret = new XmlResult();
+
+ if (!root.getName().equals("Beans"))
+ {
+ throw new RuntimeException("Wrong root element for XML config file, expected:<Beans> found:" + root.getName());
+ }
+ if (!ROOT_NAMESPACE.equals(root.getNamespaceUri()))
+ {
+ throw new RuntimeException("Wrong root namespace for XML config file, expected:" + ROOT_NAMESPACE + " found:" + root.getNamespaceUri());
+ }
+
+ resolvers.put(ROOT_NAMESPACE, new RootNamespaceElementResolver());
+
+ List<SaxNode> children = root.getChildren();
+ for (SaxNode node : children)
+ {
+ try
+ {
+ // nodes with a null namespace are whitespace nodes etc
+ if (node.getNamespaceUri() != null)
+ {
+ XmlItem rb = resolveNode(node, null);
+ addNodeToResult(ret, rb);
+ }
+ }
+ catch (Exception e)
+ {
+ ret.addProblem(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ return ret;
+ }
+
+ private void addNodeToResult(XmlResult ret, XmlItem rb) throws InvalidElementException
+ {
+
+ if (rb.getType() == XmlItemType.CLASS || rb.getType() == XmlItemType.ANNOTATION)
+ {
+ ResultType type = getItemType(rb);
+ if (type == ResultType.BEAN)
+ {
+ BeanResult tp = buildAnnotatedType(rb);
+ ret.getBeans().add(tp);
+ List<FieldValueObject> fields = new ArrayList<FieldValueObject>();
+ for (XmlItem xi : rb.getChildren())
+ {
+ if (xi.getType() == XmlItemType.FIELD)
+ {
+ FieldValueObject f = xi.getFieldValue();
+ if (f != null)
+ {
+ fields.add(f);
+ }
+ }
+ }
+ if (!fields.isEmpty())
+ {
+ ret.getFieldValues().put(tp, fields);
+ }
+
+ }
+ else if (type == ResultType.QUALIFIER)
+ {
+ ret.getQualifiers().add(rb.getJavaClass());
+ }
+ else if (type == ResultType.INTERCEPTOR_BINDING)
+ {
+ ret.getInterceptorBindings().add(rb.getJavaClass());
+ }
+ else if (type == ResultType.STEREOTYPE)
+ {
+ addSteriotypeToResult(ret, rb);
+ }
+ }
+ else if (rb.getType() == XmlItemType.VETO)
+ {
+ for (XmlItem it : rb.getChildren())
+ {
+ ret.addVeto(it.getJavaClass());
+ }
+ }
+ }
+
+ protected XmlItem resolveNode(SaxNode node, XmlItem parent) throws DOMException, InvalidElementException
+ {
+ NamespaceElementResolver resolver = resolveNamepsace(node.getNamespaceUri());
+
+ Map<String, String> attributes = node.getAttributes();
+ String innerText = node.getInnerText().trim();
+ if (innerText.equals(""))
+ {
+ innerText = null;
+ }
+ XmlItem ret = resolver.getItemForNamespace(node.getName(), parent, innerText, attributes);
+
+ if (ret == null)
+ {
+ throw new InvalidElementException("Could not resolve node " + node.getName() + " in namespace " + node.getNamespaceUri());
+ }
+ List<SaxNode> children = node.getChildren();
+ for (SaxNode n : children)
+ {
+ if (n.getNamespaceUri() != null)
+ {
+ XmlItem rb = resolveNode(n, ret);
+ ret.addChild(rb);
+ }
+ }
+ ret.resolveChildren();
+ return ret;
+
+ }
+
+ protected NamespaceElementResolver resolveNamepsace(String namespaceURI)
+ {
+ if (resolvers.containsKey(namespaceURI))
+ {
+ return resolvers.get(namespaceURI);
+ }
+ String ns = namespaceURI.replaceFirst("urn:java:", "");
+ PackageNamespaceElementResolver res = new PackageNamespaceElementResolver(ns);
+ resolvers.put(namespaceURI, res);
+ return res;
+ }
+
+ /**
+ * Determines the type of an element by examining its child nodes
+ */
+ protected ResultType getItemType(XmlItem item) throws InvalidElementException
+ {
+
+ ResultType ret = null;
+ for (XmlItem it : item.getChildren())
+ {
+ if (it.getType() == XmlItemType.ANNOTATION)
+ {
+ if (it.getJavaClass() == InterceptorBinding.class)
+ {
+ if (ret != null)
+ {
+ throw new InvalidElementException("Element cannot be both an INTERCEPTOR_BINDING and a " + ret.toString());
+ }
+ else
+ {
+ ret = ResultType.INTERCEPTOR_BINDING;
+ }
+ }
+ else if (it.getJavaClass() == Qualifier.class)
+ {
+ if (ret != null)
+ {
+ throw new InvalidElementException("Element cannot be both an QUALIFIER and a " + ret.toString());
+ }
+ else
+ {
+ ret = ResultType.QUALIFIER;
+ }
+ }
+ else if (it.getJavaClass() == Stereotype.class)
+ {
+ if (ret != null)
+ {
+ throw new InvalidElementException("Element cannot be both an STEREOTYPE and a " + ret.toString());
+ }
+ else
+ {
+ ret = ResultType.STEREOTYPE;
+ }
+ }
+ }
+ else if (it.getType() == XmlItemType.VETO)
+ {
+ if (ret != null)
+ {
+ throw new InvalidElementException("Element cannot be both an VETO and a " + ret.toString());
+ }
+ else
+ {
+ ret = ResultType.VETO;
+ }
+ }
+
+ }
+ if (ret == null)
+ {
+ ret = ResultType.BEAN;
+ }
+ return ret;
+ }
+
+ BeanResult buildAnnotatedType(XmlItem rb) throws InvalidElementException
+ {
+ BeanResult result = new BeanResult(rb.getJavaClass());
+ NewAnnotatedTypeBuilder type = result.getBuilder();
+ // list of constructor arguments
+ List<XmlItem> constList = new ArrayList<XmlItem>();
+ for (XmlItem item : rb.getChildren())
+ {
+ if (item.getType() == XmlItemType.ANNOTATION)
+ {
+
+ Annotation a = createAnnotation(item);
+ type.addToClass(a);
+ }
+ else if (item.getType() == XmlItemType.CLASS)
+ {
+ constList.add(item);
+
+ }
+ else if (item.getType() == XmlItemType.FIELD)
+ {
+ for (XmlItem fi : item.getChildren())
+ {
+ if (fi.getType() == XmlItemType.ANNOTATION)
+ {
+ Annotation a = createAnnotation(fi);
+ type.addToField(item.getField(), a);
+ }
+ }
+ }
+ else if (item.getType() == XmlItemType.METHOD)
+ {
+ int paramCount = 0;
+ for (XmlItem fi : item.getChildren())
+ {
+ if (fi.getType() == XmlItemType.ANNOTATION)
+ {
+
+ // TODO: pass in attribute map
+ Annotation a = createAnnotation(fi);
+ type.addToMethod(item.getMethod(), a);
+ }
+ else if (fi.getType() == XmlItemType.CLASS)
+ {
+ int param = paramCount++;
+ for (XmlItem pan : fi.getChildren())
+ {
+ if (pan.getType() == XmlItemType.ANNOTATION)
+ {
+ Annotation a = createAnnotation(pan);
+ type.addToMethodParameter(item.getMethod(), param, a);
+ }
+ else
+ {
+ throw new RuntimeException("Method parameters may only have annotations as children in " + item.getJavaClass().getName());
+ }
+ }
+ }
+ }
+ }
+ else if (item.getType() == XmlItemType.DEPENDENCY)
+ {
+ result.getDependencies().add(item.getInnerText());
+ }
+ }
+ if (!constList.isEmpty())
+ {
+ // the bean defined constructor arguments
+ }
+ return result;
+ }
+
+ void addSteriotypeToResult(XmlResult ret, XmlItem rb) throws InvalidElementException
+ {
+
+ Annotation[] values = new Annotation[rb.getChildren().size()];
+ int count = 0;
+ for (XmlItem item : rb.getChildren())
+ {
+ if (item.getType() == XmlItemType.ANNOTATION)
+ {
+ Annotation a = createAnnotation(item);
+ values[count] = a;
+ }
+ else
+ {
+ throw new InvalidElementException("Setereotype " + rb.getJavaClass() + " has an item that does not represent an annotation in its XML configurations");
+ }
+ count++;
+ }
+ ret.getStereotypes().put(rb.getJavaClass(), values);
+
+ }
+
+ Annotation createAnnotation(XmlItem item) throws InvalidElementException
+ {
+ Map<String, Object> typedVars = new HashMap<String, Object>();
+ Class anClass = item.getJavaClass();
+ for (Entry<String, String> e : item.getAttributes().entrySet())
+ {
+ String mname = e.getKey();
+ Method m;
+ try
+ {
+ m = anClass.getDeclaredMethod(mname);
+ }
+ catch (Exception e1)
+ {
+ throw new InvalidElementException("Annotation " + item.getJavaClass().getName() + " does not have a member named " + mname + " ,error in XML");
+ }
+ Class returnType = m.getReturnType();
+ typedVars.put(mname, XmlObjectConverter.convert(returnType, e.getValue()));
+ }
+
+ return ac.get(item.getJavaClass(), typedVars);
+ }
+
+ public void validateXmlItem(XmlItem item)
+ {
+ Set<XmlItemType> allowed = item.getAllowedItem();
+ for (XmlItem i : item.getChildren())
+ {
+ if (!allowed.contains(item.getType()))
+ {
+ throw new RuntimeException("Item " + item.getType() + " is not allowed to contain " + i.getType());
+ }
+ validateXmlItem(i);
+ }
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ResultType.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ResultType.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ResultType.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,10 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+public enum ResultType
+{
+ BEAN, INTERCEPTOR_BINDING, STEREOTYPE, QUALIFIER, VETO;
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,22 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.util.Collections;
+import java.util.Set;
+
+public class ValueXmlItem extends AbstractXmlItem
+{
+
+ public ValueXmlItem(XmlItem parent, String innerText)
+ {
+ super(XmlItemType.VALUE, parent, null, innerText, null);
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return Collections.EMPTY_SET;
+ }
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/VetoXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/VetoXmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/VetoXmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,24 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.util.Collections;
+import java.util.Set;
+
+public class VetoXmlItem extends AbstractXmlItem
+{
+
+ public VetoXmlItem(XmlItem parent)
+ {
+ super(XmlItemType.VETO, parent, null, null, null);
+
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return Collections.singleton(XmlItemType.CLASS);
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItem.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItem.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,48 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.seam.xml.fieldset.FieldValueObject;
+
+public interface XmlItem
+{
+
+ public String getInnerText();
+
+ public void addChild(XmlItem xmlItem);
+
+ public XmlItem getParent();
+
+ public List<XmlItem> getChildren();
+
+ public XmlItemType getType();
+
+ public Field getField();
+
+ public Method getMethod();
+
+ public Class getJavaClass();
+
+ /**
+ * attempts to resolve any information that is not availbile at parse time
+ *
+ * @param childeren
+ * @return
+ */
+ public boolean resolveChildren();
+
+ public Map<String, String> getAttributes();
+
+ public FieldValueObject getFieldValue();
+
+ public Set<XmlItemType> getAllowedItem();
+
+}
\ No newline at end of file
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItemType.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItemType.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItemType.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,10 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+public enum XmlItemType
+{
+ CLASS, METHOD, FIELD, ANNOTATION, VALUE, VETO, ENTRY, KEY, DEPENDENCY;
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/ParserMain.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/ParserMain.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/ParserMain.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,111 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.parser;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.xml.sax.Attributes;
+import org.xml.sax.InputSource;
+import org.xml.sax.Locator;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.DefaultHandler;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+/**
+ * Parser for xml configration
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class ParserMain extends DefaultHandler
+{
+
+ SaxNode parentNode = null;
+
+ SaxNode currentNode = null;
+
+ Locator locator;
+
+ String currentText = "";
+
+ String document;
+
+ public SaxNode parse(InputSource inputSource, String fileUrl)
+ {
+ document = fileUrl;
+ try
+ {
+
+ XMLReader xr = XMLReaderFactory.createXMLReader();
+
+ xr.setContentHandler(this);
+ xr.setErrorHandler(this);
+ xr.parse(inputSource);
+
+ return parentNode;
+
+ }
+ catch (SAXException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (IOException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ }
+
+ @Override
+ public void characters(char[] ch, int start, int length) throws SAXException
+ {
+ currentText = currentText + new String(ch, start, length);
+ }
+
+ @Override
+ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException
+ {
+ Map<String, String> atmap = new HashMap<String, String>();
+ for (int i = 0; i < attributes.getLength(); ++i)
+ {
+ atmap.put(attributes.getLocalName(i), attributes.getValue(i));
+ }
+ int pos = 0;
+ if (locator != null)
+ {
+ pos = locator.getLineNumber();
+ }
+ SaxNode node = new SaxNode(localName, uri, atmap, currentNode, document, pos);
+ if (currentNode == null)
+ {
+ parentNode = node;
+ }
+ else
+ {
+ currentNode.addChild(node);
+ }
+
+ currentNode = node;
+ currentText = "";
+ }
+
+ @Override
+ public void endElement(String uri, String localName, String qName) throws SAXException
+ {
+ currentNode.setInnerText(currentText);
+ currentNode = currentNode.getParent();
+ currentText = "";
+ }
+
+ @Override
+ public void setDocumentLocator(Locator locator)
+ {
+ this.locator = locator;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/SaxNode.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/SaxNode.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/SaxNode.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,84 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.parser;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+public class SaxNode
+{
+
+ SaxNode(String name, String uri, Map<String, String> attributes, SaxNode parent, String document, int lineNo)
+ {
+ this.name = name;
+ this.namespaceUri = uri;
+ this.attributes = attributes;
+ this.parent = parent;
+ this.document = document;
+ this.lineNo = lineNo;
+ }
+
+ String innerText;
+ final String namespaceUri;
+ final String name;
+ final Map<String, String> attributes;
+ final String document;
+ final int lineNo;
+ List<SaxNode> children = new ArrayList<SaxNode>();
+ final SaxNode parent;
+
+ public String getInnerText()
+ {
+ return innerText;
+ }
+
+ public void setInnerText(String innerText)
+ {
+ this.innerText = innerText;
+ }
+
+ public String getNamespaceUri()
+ {
+ return namespaceUri;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public Map<String, String> getAttributes()
+ {
+ return attributes;
+ }
+
+ public String getDocument()
+ {
+ return document;
+ }
+
+ public int getLineNo()
+ {
+ return lineNo;
+ }
+
+ public void addChild(SaxNode node)
+ {
+ this.children.add(node);
+ }
+
+ public List<SaxNode> getChildren()
+ {
+ return Collections.unmodifiableList(children);
+ }
+
+ public SaxNode getParent()
+ {
+ return parent;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/CompositeNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/CompositeNamespaceElementResolver.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/CompositeNamespaceElementResolver.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,63 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.parser.namespace;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.seam.xml.model.XmlItem;
+
+/**
+ * Namespace resolver that searches through a list of packages
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class CompositeNamespaceElementResolver implements NamespaceElementResolver
+{
+
+ Set<String> notFound = new HashSet<String>();
+ List<PackageNamespaceElementResolver> resolvers = new ArrayList<PackageNamespaceElementResolver>();
+
+ public CompositeNamespaceElementResolver(Collection<String> packages)
+ {
+ for (String s : packages)
+ {
+ resolvers.add(new PackageNamespaceElementResolver(s));
+ }
+ }
+
+ public CompositeNamespaceElementResolver(String[] packages)
+ {
+ for (String s : packages)
+ {
+ resolvers.add(new PackageNamespaceElementResolver(s));
+ }
+ }
+
+ public XmlItem getItemForNamespace(String item, XmlItem parent, String innerText, Map<String, String> attributes) throws InvalidElementException
+ {
+ if (notFound.contains(item))
+ {
+ return null;
+ }
+
+ for (PackageNamespaceElementResolver p : resolvers)
+ {
+ XmlItem xi = p.getItemForNamespace(item, parent, innerText, attributes);
+ if (xi != null)
+ {
+ return xi;
+ }
+ }
+ notFound.add(item);
+ return null;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/InvalidElementException.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/InvalidElementException.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/InvalidElementException.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,16 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.parser.namespace;
+
+/**
+ * Exception thrown when both a method and a field have the same name
+ */
+public class InvalidElementException extends Exception
+{
+ public InvalidElementException(String message)
+ {
+ super(message);
+ }
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceElementResolver.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceElementResolver.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,16 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.parser.namespace;
+
+import java.util.Map;
+
+import org.jboss.seam.xml.model.XmlItem;
+
+public interface NamespaceElementResolver
+{
+
+ XmlItem getItemForNamespace(String item, XmlItem parent, String innerText, Map<String, String> attributes) throws InvalidElementException;
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceUtils.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceUtils.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/NamespaceUtils.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,65 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.parser.namespace;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+
+import org.jboss.seam.xml.model.FieldXmlItem;
+import org.jboss.seam.xml.model.MethodXmlItem;
+import org.jboss.seam.xml.model.XmlItem;
+
+class NamespaceUtils
+{
+ static XmlItem resolveMethodOrField(String name, XmlItem parent, String innerText) throws InvalidElementException
+ {
+ Class p = parent.getJavaClass();
+ Field f = null;
+ boolean methodFound = false;
+ f = getField(p, name);
+ for (Method m : parent.getJavaClass().getMethods())
+ {
+ if (m.getName().equals(name))
+ {
+ methodFound = true;
+ break;
+ }
+ }
+ if (methodFound && f != null)
+ {
+ throw new InvalidElementException(parent.getJavaClass().getName() + " has both a method and a field named " + name + " and so cannot be configured via XML");
+ }
+ if (methodFound)
+ {
+ return new MethodXmlItem(parent, name);
+ }
+ else if (f != null)
+ {
+ return new FieldXmlItem(parent, f, innerText);
+ }
+ return null;
+ }
+
+ /**
+ * we need access to private fields so we cannot just use getField
+ */
+ public static Field getField(Class parent, String name)
+ {
+ Class p = parent;
+ while (p != Object.class)
+ {
+ try
+ {
+ return p.getDeclaredField(name);
+ }
+ catch (Exception e1)
+ {
+
+ }
+ p = p.getSuperclass();
+ }
+ return null;
+ }
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,85 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.parser.namespace;
+
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.seam.xml.model.AnnotationXmlItem;
+import org.jboss.seam.xml.model.ClassXmlItem;
+import org.jboss.seam.xml.model.XmlItem;
+import org.jboss.seam.xml.model.XmlItemType;
+
+public class PackageNamespaceElementResolver implements NamespaceElementResolver
+{
+ String pack;
+ Map<String, Class> cache = new HashMap<String, Class>();
+ Set<String> notFound = new HashSet<String>();
+
+ public PackageNamespaceElementResolver(String pack)
+ {
+ this.pack = pack + ".";
+ }
+
+ public XmlItem getItemForNamespace(String name, XmlItem parent, String innerText, Map<String, String> attributes) throws InvalidElementException
+ {
+ if (notFound.contains(name))
+ {
+ return null;
+ }
+
+ try
+ {
+ Class c;
+ if (cache.containsKey(name))
+ {
+ c = cache.get(name);
+ }
+ else
+ {
+ c = getClass().getClassLoader().loadClass(pack + name);
+ cache.put(name, c);
+ }
+ if (c.isAnnotation())
+ {
+ return new AnnotationXmlItem(parent, c, innerText, attributes);
+ }
+ else
+ {
+ return new ClassXmlItem(parent, c);
+ }
+
+ }
+ catch (ClassNotFoundException e)
+ {
+
+ }
+ catch (NoClassDefFoundError e) // this can get thrown when there is a
+ // case insensitive file system
+ {
+
+ }
+ if (parent != null)
+ {
+ // if the item can be a method of a FIELD
+ if (parent.getAllowedItem().contains(XmlItemType.METHOD) || parent.getAllowedItem().contains(XmlItemType.FIELD))
+ {
+ return NamespaceUtils.resolveMethodOrField(name, parent, innerText);
+ }
+ else
+ {
+ notFound.add(name);
+ }
+ }
+ else
+ {
+ notFound.add(name);
+ }
+ return null;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,66 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.parser.namespace;
+
+import java.util.Map;
+
+import org.jboss.seam.xml.model.ArrayXmlItem;
+import org.jboss.seam.xml.model.DependsXmlItem;
+import org.jboss.seam.xml.model.EntryXmlItem;
+import org.jboss.seam.xml.model.KeyXmlItem;
+import org.jboss.seam.xml.model.ValueXmlItem;
+import org.jboss.seam.xml.model.VetoXmlItem;
+import org.jboss.seam.xml.model.XmlItem;
+
+public class RootNamespaceElementResolver implements NamespaceElementResolver
+{
+
+ CompositeNamespaceElementResolver delegate;
+ static final String[] namspaces = { "java.lang", "java.util", "javax.annotation", "javax.inject", "javax.enterprise.inject", "javax.enterprise.context", "javax.enterprise.event", "javax.decorator", "javax.interceptor", "javax.persistence", "javax.xml.ws", "javax.jms", "javax.sql" };
+
+ public RootNamespaceElementResolver()
+ {
+ delegate = new CompositeNamespaceElementResolver(namspaces);
+ }
+
+ public XmlItem getItemForNamespace(String item, XmlItem parent, String innerText, Map<String, String> attributes) throws InvalidElementException
+ {
+ XmlItem ret = getRootItem(item, parent, innerText);
+ if (ret != null)
+ return ret;
+ return delegate.getItemForNamespace(item, parent, innerText, attributes);
+
+ }
+
+ XmlItem getRootItem(String item, XmlItem parent, String innerText)
+ {
+ if (item.equals("value") || item.equals("v"))
+ {
+ return new ValueXmlItem(parent, innerText);
+ }
+ else if (item.equals("key") || item.equals("k"))
+ {
+ return new KeyXmlItem(parent, innerText);
+ }
+ else if (item.equals("entry") || item.equals("e"))
+ {
+ return new EntryXmlItem(parent);
+ }
+ else if (item.equals("array"))
+ {
+ return new ArrayXmlItem(parent);
+ }
+ else if (item.equals("veto"))
+ {
+ return new VetoXmlItem(parent);
+ }
+ else if (item.equals("depends"))
+ {
+ return new DependsXmlItem(parent, innerText);
+ }
+ return null;
+ }
+
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/FileDataReader.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/FileDataReader.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/FileDataReader.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,43 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.util;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+/**
+ * Utility class that reads a file or URL into a String
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class FileDataReader
+{
+
+ public static String readUrl(URL u) throws IOException
+ {
+ InputStream s = u.openStream();
+ String res = readFile(s);
+ s.close();
+ return res;
+ }
+
+ public static String readFile(InputStream file) throws IOException
+ {
+ InputStreamReader reader = new InputStreamReader(file);
+ StringBuilder fileData = new StringBuilder();
+ char[] buf = new char[1024];
+ int numRead = 0;
+
+ while ((numRead = reader.read(buf)) != -1)
+ {
+ String readData = String.valueOf(buf, 0, numRead);
+ fileData.append(readData);
+ }
+ return fileData.toString();
+ }
+}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/XmlObjectConverter.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/XmlObjectConverter.java (rev 0)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/XmlObjectConverter.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,172 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.util;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.util.Calendar;
+
+/**
+ * utility class that can convert a string representation of a type into an
+ * instance of that type
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class XmlObjectConverter
+{
+ public static Object convert(Class target, String value)
+ {
+ if (target == String.class)
+ {
+ return value;
+ }
+ else if (target.isEnum())
+ {
+ return Enum.valueOf((Class<Enum>) target, value);
+ }
+ else if (target == Class.class)
+ {
+ Class dval = null;
+
+ try
+ {
+ return XmlObjectConverter.class.getClassLoader().loadClass(value);
+ }
+ catch (ClassNotFoundException e)
+ {
+ try
+ {
+ return Thread.currentThread().getContextClassLoader().loadClass(value);
+ }
+ catch (ClassNotFoundException e1)
+ {
+ throw new RuntimeException("Could not set field value to class configured in XML: " + value, e1);
+ }
+ }
+ }
+ // Date and time
+ else if (java.sql.Date.class == target)
+ {
+ try
+ {
+ java.util.Date dval = DateFormat.getDateTimeInstance().parse(value);
+ return new java.sql.Date(dval.getYear(), dval.getMonth(), dval.getDay());
+
+ }
+ catch (ParseException e)
+ {
+ throw new RuntimeException("Cannot parse javax.sql.Date field value: " + value, e);
+ }
+
+ }
+ else if (java.sql.Time.class == target)
+ {
+ try
+ {
+ java.util.Date dval = DateFormat.getDateTimeInstance().parse(value);
+ return new java.sql.Time(dval.getHours(), dval.getMinutes(), dval.getSeconds());
+ }
+ catch (ParseException e)
+ {
+ throw new RuntimeException("Cannot parse javax.sql.Date field value: " + value, e);
+ }
+
+ }
+ else if (java.sql.Timestamp.class == target)
+ {
+ try
+ {
+ java.util.Date dval = DateFormat.getDateTimeInstance().parse(value);
+ return new java.sql.Timestamp(dval.getYear(), dval.getMonth(), dval.getDay(), dval.getHours(), dval.getMinutes(), dval.getSeconds(), 0);
+
+ }
+ catch (ParseException e)
+ {
+ throw new RuntimeException("Cannot parse javax.sql.Date field value: " + value, e);
+ }
+
+ }
+ else if (Calendar.class == target)
+ {
+ try
+ {
+ java.util.Date dval = DateFormat.getDateTimeInstance().parse(value);
+ final Calendar val = Calendar.getInstance();
+ val.setTime(dval);
+ return val;
+ }
+ catch (ParseException e)
+ {
+ throw new RuntimeException("Cannot parse Calendar field value: " + value, e);
+ }
+
+ }
+ else if (java.util.Date.class == target)
+ {
+ try
+ {
+ return DateFormat.getDateTimeInstance().parse(value);
+
+ }
+ catch (ParseException e)
+ {
+ throw new RuntimeException("Cannot parse Calendar field value: " + value, e);
+ }
+
+ }
+ else if (target == BigDecimal.class)
+ {
+ return new BigDecimal(value);
+ }
+ else if (target == BigInteger.class)
+ {
+ return new BigInteger(value);
+ }
+ // primitive types
+ else if (target == char.class || target == Character.class)
+ {
+ if (value.length() != 1)
+ {
+ throw new RuntimeException("Value of a char field must be exactly 1 character long");
+ }
+ return new Character(value.charAt(0));
+ }
+ else if (target == int.class || target == Integer.class)
+ {
+ return Integer.parseInt(value);
+
+ }
+ else if (target == short.class || target == Short.class)
+ {
+ return new Short(value);
+
+ }
+ else if (target == long.class || target == Long.class)
+ {
+ return new Long(value);
+ }
+ else if (target == byte.class || target == byte.class)
+ {
+ return new Byte(value);
+
+ }
+ else if (target == double.class || target == Double.class)
+ {
+ return new Double(value);
+ }
+ else if (target == float.class || target == Float.class)
+ {
+ return new Float(value);
+ }
+ else if (target == boolean.class || target == Boolean.class)
+ {
+ return new Boolean(value);
+ }
+ throw new RuntimeException("Could not convert value " + value + " to " + target.getName());
+ }
+}
Added: modules/xml/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
--- modules/xml/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension (rev 0)
+++ modules/xml/trunk/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1 @@
+org.jboss.seam.xml.bootstrap.XmlExtension
Added: modules/xml/trunk/src/main/resources/META-INF/services/org.jboss.seam.xml.XmlExtension
===================================================================
--- modules/xml/trunk/src/main/resources/META-INF/services/org.jboss.seam.xml.XmlExtension (rev 0)
+++ modules/xml/trunk/src/main/resources/META-INF/services/org.jboss.seam.xml.XmlExtension 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1 @@
+org.jboss.seam.xml.bootstrap.ClassPathXmlDocumentProvider
\ No newline at end of file
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/AbstractXMLTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/AbstractXMLTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/AbstractXMLTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,61 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test;
+
+import java.lang.annotation.Annotation;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.util.AnnotationLiteral;
+
+import org.jboss.weld.environment.se.StartMain;
+import org.jboss.weld.environment.se.events.Shutdown;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+
+public abstract class AbstractXMLTest
+{
+
+ public static String[] ARGS_EMPTY = new String[] {};
+
+ protected BeanManager manager;
+
+ protected abstract String getXmlFileName();
+
+ @BeforeClass
+ public void setup()
+ {
+ String fileName = getClass().getPackage().getName().replace('.', '/') + "/" + getXmlFileName();
+ TestXmlProvider.fileName = fileName;
+ manager = new StartMain(ARGS_EMPTY).go();
+ }
+
+ @AfterClass
+ public void teardown()
+ {
+ manager.fireEvent(manager, new ShutdownAnnotation());
+ }
+
+ public <T> T getReference(Class<T> clazz, Annotation... bindings)
+ {
+ Set<Bean<?>> beans = manager.getBeans(clazz, bindings);
+ if (beans.isEmpty())
+ {
+ throw new RuntimeException("No bean found with class: " + clazz + " and bindings " + bindings.toString());
+ }
+ else if (beans.size() != 1)
+ {
+ throw new RuntimeException("More than one bean found with class: " + clazz + " and bindings " + bindings.toString());
+ }
+ Bean bean = beans.iterator().next();
+ return (T) bean.create(manager.createCreationalContext(bean));
+ }
+
+ protected static class ShutdownAnnotation extends AnnotationLiteral<org.jboss.weld.environment.se.events.Shutdown> implements Shutdown
+ {
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/BootstrapTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/BootstrapTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/BootstrapTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,33 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test;
+
+import java.util.List;
+
+import org.jboss.seam.xml.bootstrap.XmlDocumentProvider;
+import org.jboss.seam.xml.bootstrap.XmlExtension;
+import org.testng.annotations.Test;
+
+/**
+ * Unit test for simple App.
+ */
+public class BootstrapTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "single-bean.xml";
+ }
+
+ @Test
+ public void testDocumentProviders()
+ {
+ XmlExtension x = getReference(XmlExtension.class);
+ List<Class<? extends XmlDocumentProvider>> providers = x.getDocumentProviders();
+ assert providers.size() == 2;
+
+ }
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,60 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.seam.xml.model.XmlItem;
+import org.jboss.seam.xml.model.XmlItemType;
+import org.jboss.seam.xml.parser.namespace.CompositeNamespaceElementResolver;
+import org.jboss.seam.xml.parser.namespace.InvalidElementException;
+import org.jboss.seam.xml.parser.namespace.NamespaceElementResolver;
+import org.jboss.seam.xml.parser.namespace.PackageNamespaceElementResolver;
+import org.jboss.seam.xml.test.simple.Bean1;
+import org.testng.annotations.Test;
+
+public class NamespaceResolverTest
+{
+
+ @Test
+ public void testPackageResolver() throws InvalidElementException
+ {
+ PackageNamespaceElementResolver resolver = new PackageNamespaceElementResolver("org.jboss.seam.xml.test.simple");
+ testResolver(resolver);
+ }
+
+ @Test
+ public void testCompositePackageResolver() throws InvalidElementException
+ {
+ List<String> namespaces = new ArrayList<String>();
+ namespaces.add("java.lang");
+ namespaces.add("java.util");
+ namespaces.add("org.jboss.seam.xml.test.simple");
+ CompositeNamespaceElementResolver resolver = new CompositeNamespaceElementResolver(namespaces);
+ testResolver(resolver);
+ }
+
+ public void testResolver(NamespaceElementResolver resolver) throws InvalidElementException
+ {
+
+ XmlItem item = resolver.getItemForNamespace("Bean1", null, null, null);
+ assert item.getJavaClass() == Bean1.class : "Namespace resolver returned wrong class type";
+ assert item.getType() == XmlItemType.CLASS : "Namespace resolver did not return class";
+ XmlItem method = resolver.getItemForNamespace("method1", item, null, null);
+ assert method.getType() == XmlItemType.METHOD : "Item returned wrong type";
+
+ method.resolveChildren();
+
+ assert method.getMethod() != null : "Could not resolve method";
+ assert method.getMethod().getParameterTypes().length == 0 : "Wrong method was resolved";
+
+ XmlItem field = resolver.getItemForNamespace("field1", item, null, null);
+ assert field.getType() == XmlItemType.FIELD : "Element of wrong type returned";
+ assert field.getField() != null : "field was not set";
+
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/TestXmlProvider.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/TestXmlProvider.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/TestXmlProvider.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,36 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test;
+
+import org.jboss.seam.xml.bootstrap.ClassPathXmlDocumentProvider;
+import org.jboss.seam.xml.bootstrap.XmlDocument;
+import org.jboss.seam.xml.bootstrap.XmlDocumentProvider;
+
+public class TestXmlProvider implements XmlDocumentProvider
+{
+
+ public static String fileName;
+
+ ClassPathXmlDocumentProvider docProvider;
+
+ public void close()
+ {
+ docProvider.close();
+ }
+
+ public XmlDocument getNextDocument()
+ {
+ return docProvider.getNextDocument();
+ }
+
+ public void open()
+ {
+ String[] r = new String[1];
+ r[0] = fileName;
+ docProvider = new ClassPathXmlDocumentProvider(r);
+ docProvider.open();
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/ArrayFieldValue.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/ArrayFieldValue.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/ArrayFieldValue.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,12 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+public class ArrayFieldValue
+{
+ public int[] iarray;
+ public Class[] carray;
+ public String[] sarray;
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/CollectionFieldValue.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/CollectionFieldValue.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/CollectionFieldValue.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,16 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+
+public class CollectionFieldValue
+{
+ public Set<Integer> iset;
+ public SortedSet<String> sset;
+ public List<Class> clist;
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueBean.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,32 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+import java.math.BigDecimal;
+
+import org.jboss.seam.xml.test.method.QualifierEnum;
+
+public class FieldValueBean
+{
+
+ public int ivalue = 20;
+
+ public String stringValue;
+
+ public QualifierEnum enumValue;
+
+ public boolean bvalue;
+
+ public float fvalue = 1;
+
+ public double dvalue = 1;
+
+ public BigDecimal bigDecimalValue;
+
+ public short svalue;
+
+ public long lvalue;
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueProducer.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueProducer.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/FieldValueProducer.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,10 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+public class FieldValueProducer
+{
+ public String value;
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/MapFieldValue.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/MapFieldValue.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/MapFieldValue.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,14 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+import java.util.Map;
+
+public class MapFieldValue
+{
+ public Map<Integer, String> map1;
+
+ public Map<String, Class> map2;
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetArrayFieldValueBeanTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetArrayFieldValueBeanTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetArrayFieldValueBeanTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,36 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.jboss.weld.environment.se.util.WeldManagerUtils;
+import org.testng.annotations.Test;
+
+public class SetArrayFieldValueBeanTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "array-set-field-value-beans.xml";
+ }
+
+ @Test
+ public void arrayFieldSetterTest()
+ {
+ ArrayFieldValue x = WeldManagerUtils.getInstanceByType(manager, ArrayFieldValue.class);
+ assert x.carray.length == 2;
+ assert x.iarray.length == 2;
+ assert x.sarray.length == 2;
+ assert x.sarray[0].equals("hello");
+ assert x.sarray[1].equals("world");
+ assert x.iarray[0] == 1;
+ assert x.iarray[1] == 2;
+ assert x.carray[0] == Integer.class;
+ assert x.carray[1] == Long.class;
+
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetCollectionFieldValueBeanTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetCollectionFieldValueBeanTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetCollectionFieldValueBeanTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,59 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.jboss.weld.environment.se.util.WeldManagerUtils;
+import org.testng.annotations.Test;
+
+public class SetCollectionFieldValueBeanTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "colection-set-field-value-beans.xml";
+ }
+
+ @Test
+ public void collectionSetFieldValue()
+ {
+ CollectionFieldValue x = WeldManagerUtils.getInstanceByType(manager, CollectionFieldValue.class);
+ assert x.iset.size() == 2;
+ assert x.clist.size() == 2;
+ assert x.sset.size() == 2;
+ boolean first = true;
+ for (String i : x.sset)
+ {
+ if (first)
+ {
+ assert i.equals("1");
+ first = false;
+ }
+ else
+ {
+ assert i.equals("2");
+ }
+
+ }
+ first = true;
+ for (Integer i : x.iset)
+ {
+ if (first)
+ {
+ assert i.equals(new Integer(1));
+ first = false;
+ }
+ else
+ {
+ assert i.equals(new Integer(2));
+ }
+
+ }
+ assert x.clist.get(0) == Integer.class;
+ assert x.clist.get(1) == Long.class;
+
+ }
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetFieldValueBeanTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,37 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+import java.math.BigDecimal;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.jboss.seam.xml.test.method.QualifierEnum;
+import org.testng.annotations.Test;
+
+public class SetFieldValueBeanTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "set-field-value-beans.xml";
+ }
+
+ @Test
+ public void simpleFieldSetterTest()
+ {
+ FieldValueBean x = getReference(FieldValueBean.class);
+ assert x.bigDecimalValue.compareTo(BigDecimal.TEN) == 0;
+ assert x.bvalue == true;
+ assert x.dvalue == 0;
+ assert x.enumValue == QualifierEnum.A;
+ assert x.fvalue == 0;
+ assert x.ivalue == 10;
+ assert x.lvalue == 23;
+ assert x.svalue == 4;
+
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetMapFieldValueBeanTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetMapFieldValueBeanTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/fieldset/SetMapFieldValueBeanTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,33 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.jboss.weld.environment.se.util.WeldManagerUtils;
+import org.testng.annotations.Test;
+
+public class SetMapFieldValueBeanTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "map-set-field-value-beans.xml";
+ }
+
+ @Test
+ public void mapSetFieldValue()
+ {
+ MapFieldValue x = WeldManagerUtils.getInstanceByType(manager, MapFieldValue.class);
+ assert x.map1.size() == 2;
+ assert x.map2.size() == 2;
+
+ assert x.map1.get(1).equals("hello");
+ assert x.map1.get(2).equals("world");
+ assert x.map2.get("1") == Integer.class;
+ assert x.map2.get("2") == Long.class;
+
+ }
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/OtherQualifier.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/OtherQualifier.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/OtherQualifier.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,16 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.injection;
+
+import org.jboss.seam.xml.test.method.QualifierEnum;
+
+public @interface OtherQualifier
+{
+ String value1();
+
+ int value2();
+
+ QualifierEnum value();
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerBean.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerBean.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,11 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.injection;
+
+public class ProducerBean
+{
+ public String value;
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerFieldValueBeanTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerFieldValueBeanTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerFieldValueBeanTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,27 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.injection;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.testng.annotations.Test;
+
+public class ProducerFieldValueBeanTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "producer-field-value-beans.xml";
+ }
+
+ @Test
+ public void testProducerField()
+ {
+
+ RecieverBean s = getReference(RecieverBean.class);
+ assert s.value.equals("hello world");
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerQualifier.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerQualifier.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/ProducerQualifier.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,21 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.injection;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target( { TYPE, METHOD, PARAMETER, FIELD })
+public @interface ProducerQualifier
+{
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifiedBean1.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifiedBean1.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifiedBean1.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,17 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.injection;
+
+import org.jboss.seam.xml.test.method.QualifiedType;
+
+public class QualifiedBean1 implements QualifiedType
+{
+
+ public int getBeanNumber()
+ {
+ return 1;
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifiedBean2.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifiedBean2.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifiedBean2.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,17 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.injection;
+
+import org.jboss.seam.xml.test.method.QualifiedType;
+
+public class QualifiedBean2 implements QualifiedType
+{
+
+ public int getBeanNumber()
+ {
+ return 2;
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifierAttributesTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifierAttributesTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifierAttributesTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,31 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.injection;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.jboss.weld.environment.se.util.WeldManagerUtils;
+import org.testng.annotations.Test;
+
+/**
+ * Test that XML configured Qualifiers work as expected
+ */
+public class QualifierAttributesTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "qualifier-attributes-test-beans.xml";
+ }
+
+ @Test()
+ public void tstQualifiersWithAttributes()
+ {
+ QualifierTestBean x = WeldManagerUtils.getInstanceByType(manager, QualifierTestBean.class);
+ assert x.bean1.getBeanNumber() == 1;
+ assert x.bean2.getBeanNumber() == 2;
+
+ }
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifierTestBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifierTestBean.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/QualifierTestBean.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,16 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.injection;
+
+import org.jboss.seam.xml.test.method.QualifiedType;
+
+public class QualifierTestBean
+{
+
+ public QualifiedType bean1;
+
+ public QualifiedType bean2;
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/RecieverBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/RecieverBean.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/injection/RecieverBean.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,10 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.injection;
+
+public class RecieverBean
+{
+ public String value;
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptedBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptedBean.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptedBean.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,16 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.interceptor;
+
+@InterceptorBinding
+public class InterceptedBean
+{
+
+ public String method()
+ {
+ return "hello";
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorBean.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorBean.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,18 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.interceptor;
+
+import javax.interceptor.AroundInvoke;
+import javax.interceptor.InvocationContext;
+
+public class InterceptorBean
+{
+
+ @AroundInvoke
+ public Object myMethod(InvocationContext context) throws Exception
+ {
+ return context.proceed().toString() + " world";
+ }
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorBinding.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorBinding.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorBinding.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,17 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.interceptor;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target( { ElementType.TYPE, ElementType.METHOD })
+public @interface InterceptorBinding
+{
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/interceptor/InterceptorTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,28 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.interceptor;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.testng.annotations.Test;
+
+public class InterceptorTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "interceptor-beans.xml";
+ }
+
+ @Test()
+ public void testInterceptors()
+ {
+
+ InterceptedBean x = getReference(InterceptedBean.class);
+ String res = x.method();
+ assert res.equals("hello world");
+
+ }
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/DecoratedInterface.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/DecoratedInterface.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/DecoratedInterface.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,9 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.method;
+
+public interface DecoratedInterface
+{
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Decorator1.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Decorator1.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Decorator1.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,16 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.method;
+
+public class Decorator1
+{
+
+ DecoratedInterface decoratedObject;
+
+ public void a()
+ {
+
+ }
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodBean.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodBean.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,20 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.method;
+
+public class MethodBean
+{
+
+ public int method()
+ {
+ return 1;
+ }
+
+ public int method(MethodValueBean bean)
+ {
+ return bean.value + 1;
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTarget.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTarget.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTarget.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,11 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.method;
+
+public class MethodTarget
+{
+
+ public int value1, value2;
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,29 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.method;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.testng.annotations.Test;
+
+public class MethodTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "method-beans.xml";
+ }
+
+ @Test
+ public void methodTest()
+ {
+ MethodTarget x = getReference(MethodTarget.class);
+ assert x != null;
+ assert x.value1 == 1;
+ assert x.value2 == 11;
+
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodValueBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodValueBean.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/MethodValueBean.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,10 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.method;
+
+public class MethodValueBean
+{
+ public int value = 10;
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/QualifiedType.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/QualifiedType.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/QualifiedType.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,11 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.method;
+
+public interface QualifiedType
+{
+ public int getBeanNumber();
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Qualifier1.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Qualifier1.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Qualifier1.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,14 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.method;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Qualifier1
+{
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Qualifier2.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Qualifier2.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/Qualifier2.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,14 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.method;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface Qualifier2
+{
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/QualifierEnum.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/QualifierEnum.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/method/QualifierEnum.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,10 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.method;
+
+public enum QualifierEnum
+{
+ A, B, C;
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean1.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean1.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean1.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,30 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.simple;
+
+public class Bean1
+{
+
+ public int value = 0;
+
+ public void method1()
+ {
+
+ }
+
+ public void method1(String param)
+ {
+
+ }
+
+ public String field1 = "aa";
+
+ public Bean2 bean2;
+
+ public void pcMethod()
+ {
+ value = 1;
+ }
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean2.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean2.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean2.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,27 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.simple;
+
+import java.util.Set;
+
+public class Bean2
+{
+ public void method1()
+ {
+
+ }
+
+ public String[] arrayField;
+
+ public int intField;
+ public String stringField;
+
+ public Set<String> setField;
+
+ public Bean3 produceBean3()
+ {
+ return new Bean3();
+ }
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean3.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean3.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/Bean3.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,10 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.simple;
+
+public class Bean3
+{
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/SimpleBeanTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/SimpleBeanTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/SimpleBeanTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,35 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.simple;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.jboss.weld.environment.se.util.WeldManagerUtils;
+import org.testng.annotations.Test;
+
+/**
+ * Unit test for simple App.
+ */
+public class SimpleBeanTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "simple-beans.xml";
+ }
+
+ @Test
+ public void simpleBeanTest()
+ {
+ Bean1 x = WeldManagerUtils.getInstanceByType(manager, Bean1.class);
+ assert x != null;
+ assert x.bean2 != null;
+
+ Bean3 y = WeldManagerUtils.getInstanceByType(manager, Bean3.class);
+ assert y != null;
+ assert x.value == 1 : "Post construct method not called";
+ }
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/VetoTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/VetoTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/VetoTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,34 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.simple;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.testng.annotations.Test;
+
+public class VetoTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "veto-beans.xml";
+ }
+
+ @Test
+ public void testInterceptors()
+ {
+
+ try
+ {
+ VetoedBean y = getReference(VetoedBean.class);
+ assert y != null : "Vetoed bean was installed";
+ }
+ catch (Exception e)
+ {
+ // we expect this to throw an exception instead of returning null
+ }
+
+ }
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/VetoedBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/VetoedBean.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/VetoedBean.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,10 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.simple;
+
+public class VetoedBean
+{
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/stereotype/Stereotype1.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/stereotype/Stereotype1.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/stereotype/Stereotype1.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,17 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.stereotype;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+(a)Target(ElementType.TYPE)
+public @interface Stereotype1
+{
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/stereotype/StereotypeTest.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/stereotype/StereotypeTest.java (rev 0)
+++ modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/stereotype/StereotypeTest.java 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,34 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.stereotype;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.jboss.seam.xml.test.interceptor.InterceptedBean;
+import org.jboss.weld.environment.se.util.WeldManagerUtils;
+import org.testng.annotations.Test;
+
+/**
+ * this is the same as the interceptor test except the interceptor is applied
+ * through a stereotype
+ */
+public class StereotypeTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "stereotype-beans.xml";
+ }
+
+ @Test(enabled = true)
+ public void testStereotypes()
+ {
+
+ InterceptedBean x = WeldManagerUtils.getInstanceByType(manager, InterceptedBean.class);
+ String res = x.method();
+ assert res.equals("hello world");
+
+ }
+}
Added: modules/xml/trunk/src/test/resources/META-INF/beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/META-INF/beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/META-INF/beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,9 @@
+<beans xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+ <interceptors>
+ <class>org.jboss.seam.xml.test.interceptor.InterceptorBean</class>
+ </interceptors>
+
+</beans>
Added: modules/xml/trunk/src/test/resources/META-INF/seam-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/META-INF/seam-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/META-INF/seam-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.interceptor">
+
+ <test:InterceptorBinding>
+ <InterceptorBinding/>
+ </test:InterceptorBinding>
+
+ <test:InterceptorBean>
+ <Interceptor/>
+ <test:InterceptorBinding/>
+ <test:myMethod>
+ <!-- AroundInvoke does not actually work due to what appears to be a weld bug -->
+ <AroundInvoke/>
+ </test:myMethod>
+ </test:InterceptorBean>
+
+</Beans>
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/META-INF/services/org.jboss.seam.xml.XmlExtension
===================================================================
--- modules/xml/trunk/src/test/resources/META-INF/services/org.jboss.seam.xml.XmlExtension (rev 0)
+++ modules/xml/trunk/src/test/resources/META-INF/services/org.jboss.seam.xml.XmlExtension 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1 @@
+org.jboss.seam.xml.test.TestXmlProvider
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/array-set-field-value-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/array-set-field-value-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/array-set-field-value-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,22 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.fieldset">
+ <veto>
+ <test:ArrayFieldValue/>
+ </veto>
+ <test:ArrayFieldValue>
+ <test:iarray>
+ <value>1</value>
+ <value>2</value>
+ </test:iarray>
+ <test:carray>
+ <value>java.lang.Integer</value>
+ <value>java.lang.Long</value>
+ </test:carray>
+ <test:sarray>
+ <value>hello</value>
+ <value>world</value>
+ </test:sarray>
+ </test:ArrayFieldValue>
+
+</Beans>
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/colection-set-field-value-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/colection-set-field-value-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/colection-set-field-value-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.fieldset">
+
+ <veto>
+ <test:CollectionFieldValue/>
+ </veto>
+
+ <test:CollectionFieldValue>
+ <test:iset>
+ <value>1</value>
+ <value>2</value>
+ </test:iset>
+ <test:clist>
+ <value>java.lang.Integer</value>
+ <value>java.lang.Long</value>
+ </test:clist>
+ <test:sset>
+ <value>2</value>
+ <value>1</value>
+ </test:sset>
+ </test:CollectionFieldValue>
+
+</Beans>
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/map-set-field-value-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/map-set-field-value-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/map-set-field-value-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.fieldset">
+ <veto>
+ <test:MapFieldValue />
+ </veto>
+ <test:MapFieldValue>
+ <test:map1>
+ <entry><key>1</key><value>hello</value></entry>
+ <entry><key>2</key><value>world</value></entry>
+ </test:map1>
+ <test:map2>
+ <e><k>1</k><v>java.lang.Integer</v></e>
+ <e><k>2</k><v>java.lang.Long</v></e>
+ </test:map2>
+
+ </test:MapFieldValue>
+
+</Beans>
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/set-field-value-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/set-field-value-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/fieldset/set-field-value-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.fieldset">
+
+ <veto>
+ <test:FieldValueBean />
+ <test:FieldValueProducer/>
+ </veto>
+
+ <test:FieldValueBean>
+ <test:ivalue>10</test:ivalue>
+ <test:stringValue>hello world</test:stringValue>
+ <test:enumValue>A</test:enumValue>
+ <test:fvalue>0</test:fvalue>
+ <test:dvalue>0</test:dvalue>
+ <test:bvalue>true</test:bvalue>
+ <test:lvalue>23</test:lvalue>
+ <test:svalue>4</test:svalue>
+ <test:bigDecimalValue>10</test:bigDecimalValue>
+ </test:FieldValueBean>
+
+
+</Beans>
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/producer-field-value-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/producer-field-value-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/producer-field-value-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.injection">
+
+ <test:ProducerQualifier>
+ <Qualifier/>
+ </test:ProducerQualifier>
+
+ <test:ProducerBean>
+ <test:value>
+ <Produces/>
+ <test:ProducerQualifier/>
+ <value>hello world</value>
+ </test:value>
+ </test:ProducerBean>
+
+ <test:RecieverBean>
+ <test:value>
+ <test:ProducerQualifier/>
+ <Inject/>
+ </test:value>
+ </test:RecieverBean>
+
+</Beans>
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/qualifier-attributes-test-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/qualifier-attributes-test-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/injection/qualifier-attributes-test-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.injection">
+
+ <test:OtherQualifier>
+ <Qualifier/>
+ </test:OtherQualifier>
+
+ <test:QualifiedBean1>
+ <test:OtherQualifier value1="AA" value2="1">A</test:OtherQualifier>
+ </test:QualifiedBean1>
+
+ <test:QualifiedBean2>
+ <test:OtherQualifier value1="BB" value2="2" value="B" />
+ </test:QualifiedBean2>
+
+ <test:QualifierTestBean>
+ <test:bean1>
+ <test:OtherQualifier value1="AA" value2="1" value="A" />
+ <Inject/>
+ </test:bean1>
+ <test:bean2>
+ <test:OtherQualifier value1="BB" value2="2">B</test:OtherQualifier>
+ <Inject/>
+ </test:bean2>
+ </test:QualifierTestBean>
+
+</Beans>
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/interceptor/interceptor-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/interceptor/interceptor-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/interceptor/interceptor-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.interceptor">
+
+ <veto>
+ <test:InterceptedBean/>
+ </veto>
+
+ <test:InterceptedBean>
+ <test:method>
+ <test:InterceptorBinding/>
+ </test:method>
+ </test:InterceptedBean>
+
+</Beans>
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/method/method-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.method">
+
+ <veto>
+ <test:MethodTarget/>
+ </veto>
+
+ <test:Qualifier1>
+ <Qualifier/>
+ </test:Qualifier1>
+
+ <test:Qualifier2>
+ <Qualifier/>
+ </test:Qualifier2>
+
+ <test:MethodBean>
+ <test:method>
+ <Produces/>
+ </test:method>
+
+ <test:method>
+ <Produces/>
+ <test:Qualifier1/>
+
+ <test:MethodValueBean>
+ <test:Qualifier2/>
+ </test:MethodValueBean>
+ </test:method>
+ </test:MethodBean>
+
+ <test:MethodTarget>
+ <test:value1><Inject/></test:value1>
+ <test:value2><Inject/><test:Qualifier1/></test:value2>
+ </test:MethodTarget>
+
+ <test:MethodValueBean>
+ <test:Qualifier2/>
+ </test:MethodValueBean>
+</Beans>
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/simple/simple-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/simple/simple-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/simple/simple-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.simple">
+
+ <test:Bean1>
+ <test:bean2>
+ <Inject/>
+ </test:bean2>
+
+ <test:pcMethod>
+ <PostConstruct/>
+ </test:pcMethod>
+
+ <test:value><Produces/></test:value>
+ </test:Bean1>
+
+ <test:Bean2>
+ <test:produceBean3>
+ <Produces/>
+ </test:produceBean3>
+ </test:Bean2>
+
+
+</Beans>
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/simple/veto-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/simple/veto-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/simple/veto-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.simple">
+
+ <veto>
+ <test:VetoedBean/>
+ </veto>
+
+</Beans>
\ No newline at end of file
Added: modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/stereotype/stereotype-beans.xml
===================================================================
--- modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/stereotype/stereotype-beans.xml (rev 0)
+++ modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/stereotype/stereotype-beans.xml 2010-01-16 06:25:13 UTC (rev 11967)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<Beans xmlns="urn:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.stereotype"
+ xmlns:int="urn:java:org.jboss.seam.xml.test.interceptor">
+
+ <test:Stereotype1>
+ <Stereotype/>
+ <int:InterceptorBinding/>
+ </test:Stereotype1>
+
+ <int:InterceptedBean>
+ <test:Stereotype1/>
+ </int:InterceptedBean>
+
+</Beans>
\ No newline at end of file
14 years, 11 months
Seam SVN: r11966 - build/trunk.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-15 14:06:49 -0500 (Fri, 15 Jan 2010)
New Revision: 11966
Modified:
build/trunk/checkout.sh
Log:
add xml module
Modified: build/trunk/checkout.sh
===================================================================
--- build/trunk/checkout.sh 2010-01-15 19:05:57 UTC (rev 11965)
+++ build/trunk/checkout.sh 2010-01-15 19:06:49 UTC (rev 11966)
@@ -23,7 +23,7 @@
SVNARGS=
SVNUPDATE=1
-MODULES="remoting drools faces international persistence security"
+MODULES="remoting drools faces international persistence security xml"
while getopts “h:r:d:v” OPTION
do
14 years, 11 months
Seam SVN: r11965 - in modules/xml/trunk: src and 3 other directories.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-15 14:05:57 -0500 (Fri, 15 Jan 2010)
New Revision: 11965
Added:
modules/xml/trunk/pom.xml
modules/xml/trunk/readme.txt
modules/xml/trunk/src/
modules/xml/trunk/src/main/
modules/xml/trunk/src/main/resources/
modules/xml/trunk/src/main/resources/META-INF/
modules/xml/trunk/src/main/resources/META-INF/beans.xml
Log:
import module structure
Added: modules/xml/trunk/pom.xml
===================================================================
--- modules/xml/trunk/pom.xml (rev 0)
+++ modules/xml/trunk/pom.xml 2010-01-15 19:05:57 UTC (rev 11965)
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>seam-parent</artifactId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.jboss.seam</groupId>
+ <artifactId>seam-xml</artifactId>
+ <name>xml</name>
+ <version>1.0-SNAPSHOT</version>
+
+ <properties>
+ <seam.version>3.0.0-SNAPSHOT</seam.version>
+ </properties>
+
+ <!-- Snapshots repo to get parent -->
+ <repositories>
+ <repository>
+ <id>oss.sonatype.org/jboss-snapshots</id>
+ <name>JBoss (Nexus) Snapshots Repository</name>
+ <url>http://oss.sonatype.org/content/repositories/jboss-snapshots</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <dependencies>
+ <!-- CDI (JSR-299) -->
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <scope>provided</scope>
+ </dependency>
+ </dependencies>
+
+ <scm>
+ <connection>scm:svn:http://anonsvn.jboss.org/repos/seam/modules/xml/trunk</connection>
+ <developerConnection>scm:svn:https://svn.jboss.org/repos/seam/modules/xml/trunk</developerConnection>
+ <url>http://fisheye.jboss.org/browse/Seam/modules/xml/trunk</url>
+ </scm>
+
+</project>
Added: modules/xml/trunk/readme.txt
===================================================================
--- modules/xml/trunk/readme.txt (rev 0)
+++ modules/xml/trunk/readme.txt 2010-01-15 19:05:57 UTC (rev 11965)
@@ -0,0 +1,4 @@
+Seam xml
+=============
+
+TODO
Added: modules/xml/trunk/src/main/resources/META-INF/beans.xml
===================================================================
--- modules/xml/trunk/src/main/resources/META-INF/beans.xml (rev 0)
+++ modules/xml/trunk/src/main/resources/META-INF/beans.xml 2010-01-15 19:05:57 UTC (rev 11965)
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ The contents of this file is permitted to be empty.
+ The schema definition is provided for your convenience.
+-->
+<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="
+ http://java.sun.com/xml/ns/javaee
+ http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+</beans>
14 years, 11 months
Seam SVN: r11964 - in modules: xml and 1 other directory.
by seam-commits@lists.jboss.org
Author: pete.muir(a)jboss.org
Date: 2010-01-15 14:04:59 -0500 (Fri, 15 Jan 2010)
New Revision: 11964
Added:
modules/xml/
modules/xml/branches/
modules/xml/tags/
modules/xml/trunk/
Log:
make xml module
14 years, 11 months
Seam SVN: r11963 - modules/drools/trunk/src/main/java/org/jboss/seam/drools.
by seam-commits@lists.jboss.org
Author: tsurdilovic
Date: 2010-01-14 13:58:26 -0500 (Thu, 14 Jan 2010)
New Revision: 11963
Modified:
modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java
Log:
Drools 5 Integration.
Modified: modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java
===================================================================
--- modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java 2010-01-14 12:40:26 UTC (rev 11962)
+++ modules/drools/trunk/src/main/java/org/jboss/seam/drools/KnowledgeSessionManager.java 2010-01-14 18:58:26 UTC (rev 11963)
@@ -5,7 +5,10 @@
import java.util.Map;
import java.util.Properties;
+import java.lang.annotation.Annotation;
+import javax.enterprise.inject.Any;
import javax.enterprise.inject.Disposes;
+import javax.enterprise.inject.Instance;
import javax.enterprise.inject.Produces;
import javax.enterprise.inject.spi.Bean;
import javax.enterprise.inject.spi.BeanManager;
@@ -45,19 +48,16 @@
BeanManager manager;
@Inject
- KnowledgeBase kbase;
-
- @Inject
public KnowledgeSessionManager(KnowledgeSessionManagerConfig ksessionManagerConfig)
{
this.ksessionManagerConfig = ksessionManagerConfig;
}
@Produces
- @Named
- public StatefulKnowledgeSession getStatefulSession(InjectionPoint injectionPoint) throws Exception
+ @Any
+ public StatefulKnowledgeSession getStatefulSession(InjectionPoint ip, Instance<KnowledgeBase> kbase) throws Exception
{
- StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession(getKSessionConfig(), null);
+ StatefulKnowledgeSession ksession = kbase.select(ip.getQualifiers().toArray(new Annotation[0])).get().newStatefulKnowledgeSession(getKSessionConfig(), null);
addEventListeners(ksession);
addWorkItemHandlers(ksession);
addAuditLog(ksession);
@@ -75,10 +75,10 @@
}
@Produces
- @Named
- public StatelessKnowledgeSession getStatelessSession(InjectionPoint injectionPoint) throws Exception
+ @Any
+ public StatelessKnowledgeSession getStatelessSession(InjectionPoint ip, Instance<KnowledgeBase> kbase) throws Exception
{
- StatelessKnowledgeSession ksession = kbase.newStatelessKnowledgeSession(getKSessionConfig());
+ StatelessKnowledgeSession ksession = kbase.select(ip.getQualifiers().toArray(new Annotation[0])).get().newStatelessKnowledgeSession(getKSessionConfig());
addEventListeners(ksession);
manager.fireEvent(new KnowledgeSessionCreatedEvent(-1));
return ksession;
@@ -151,6 +151,7 @@
public void addEventListeners(StatelessKnowledgeSession ksession) throws Exception{
if(ksessionManagerConfig.getEventListeners() != null) {
for(String eventListener : ksessionManagerConfig.getEventListeners()) {
+ @SuppressWarnings("unchecked")
Class eventListenerClass = Class.forName(eventListener);
Object eventListenerObject = eventListenerClass.newInstance();
14 years, 11 months
Seam SVN: r11962 - in branches/community/Seam_2_2: examples/mail/view and 2 other directories.
by seam-commits@lists.jboss.org
Author: oskutka(a)redhat.com
Date: 2010-01-14 07:40:26 -0500 (Thu, 14 Jan 2010)
New Revision: 11962
Modified:
branches/community/Seam_2_2/examples/mail/resources/WEB-INF/components.xml
branches/community/Seam_2_2/examples/mail/view/index.xhtml
branches/community/Seam_2_2/src/test/ftest/examples/build.xml
branches/community/Seam_2_2/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java
Log:
JBSEAM-4524 Create a functional test for mail example
Modified: branches/community/Seam_2_2/examples/mail/resources/WEB-INF/components.xml
===================================================================
--- branches/community/Seam_2_2/examples/mail/resources/WEB-INF/components.xml 2010-01-14 12:30:47 UTC (rev 11961)
+++ branches/community/Seam_2_2/examples/mail/resources/WEB-INF/components.xml 2010-01-14 12:40:26 UTC (rev 11962)
@@ -13,10 +13,10 @@
<core:init debug="true" jndi-pattern="@jndiPattern@" />
<!-- If you need to alter the SMTP gateway, comment out this mail-session, -->
- <mail:mail-session host="localhost" port="2525" username="test" password="test" />
+ <!--<mail:mail-session host="localhost" port="2525" /> -->
<!-- uncomment this one and set the host attribute to the name or IP address of your SMTP gateway-->
- <!-- <mail:mail-session host="smtp.foo.com" />-->
+ <mail:mail-session host="localhost" tls="false" port="2525" ssl="false" />
<!-- Configure meldware -->
<mail:meldware>
@@ -28,5 +28,5 @@
<!-- Meldware users -->
<mail:meldware-user name="meldwareUser.test" username="test" password="test" />
-
+
</components>
Modified: branches/community/Seam_2_2/examples/mail/view/index.xhtml
===================================================================
--- branches/community/Seam_2_2/examples/mail/view/index.xhtml 2010-01-14 12:30:47 UTC (rev 11961)
+++ branches/community/Seam_2_2/examples/mail/view/index.xhtml 2010-01-14 12:40:26 UTC (rev 11962)
@@ -17,23 +17,23 @@
<p>Welcome to the Seam Email example. This example demonstrates Seam's email templating.</p>
<p>You need to enter a name and email address to receive the example emails in the form below.</p>
- <h:form>
+ <h:form id="emailform" >
<h:panelGrid columns="2">
<h:outputText value="Name" />
<h:panelGroup>
- <h:inputText value="#{person.firstname}" required="true" />
- <h:inputText value="#{person.lastname}" required="true" />
+ <h:inputText value="#{person.firstname}" required="true" id="firstname" />
+ <h:inputText value="#{person.lastname}" required="true" id="lastname" />
</h:panelGroup>
<h:outputText value="Email Address" />
- <h:inputText value="#{person.address}" required="true"/>
+ <h:inputText value="#{person.address}" required="true" id="address" />
</h:panelGrid>
<h:panelGrid>
- <h:commandButton action="#{mailExample.send}" value="Send a simple email" />
- <h:commandButton action="#{mailExample.sendPlain}" value="Send Plain Text Email" />
- <h:commandButton action="#{mailExample.sendHtml}" value="Send HTML Email" />
- <h:commandButton action="#{mailExample.sendAttachment}" value="Send a simple email with attachment" />
- <h:commandButton action="#{mailExample.sendAsynchronous}" value="Send a simple email asynchronously" />
- <h:commandButton action="#{mailExample.sendTemplate}" value="Send a templated email" />
+ <h:commandButton action="#{mailExample.send}" id="sendSimple" value="Send a simple email" />
+ <h:commandButton action="#{mailExample.sendPlain}" id="sendPlain" value="Send Plain Text Email" />
+ <h:commandButton action="#{mailExample.sendHtml}" id="sendHtml" value="Send HTML Email" />
+ <h:commandButton action="#{mailExample.sendAttachment}" id="sendAttachment" value="Send a simple email with attachment" />
+ <h:commandButton action="#{mailExample.sendAsynchronous}" id="sendAsynchronous" value="Send a simple email asynchronously" />
+ <h:commandButton action="#{mailExample.sendTemplate}" id="sendTemplate" value="Send a templated email" />
</h:panelGrid>
<h:messages infoStyle="info" errorStyle="error" fatalStyle="fatal" warnStyle="warn" />
</h:form>
@@ -47,7 +47,7 @@
Name
</td>
<td>
- <input name="name" />
+ <input name="name" id="name" />
</td>
</tr>
<tr>
@@ -55,13 +55,13 @@
Email Address
</td>
<td>
- <input name="email" />
+ <input name="email" id="email" />
</td>
</tr>
<tr>
<td></td>
<td>
- <input type="submit" value="Send" />
+ <input type="submit" value="Send" id="sendServlet" />
</td>
</tr>
</table>
Modified: branches/community/Seam_2_2/src/test/ftest/examples/build.xml
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/build.xml 2010-01-14 12:30:47 UTC (rev 11961)
+++ branches/community/Seam_2_2/src/test/ftest/examples/build.xml 2010-01-14 12:40:26 UTC (rev 11962)
@@ -344,6 +344,11 @@
<dependency groupId="org.seleniumhq.selenium.client-drivers" artifactId="selenium-java-client-driver" version="1.0.1">
<exclusion groupId="org.codehaus.groovy.maven.runtime" artifactId="gmaven-runtime-default" />
</dependency>
+ <dependency groupId="org.subethamail" artifactId="subethasmtp-smtp" version="1.2" >
+ <!-- subethamail requires commons-logging 1.1 which requires log4j 1.2.12. But we provide log4j 1.2.14, which is completely ok -->
+ <exclusion groupId="log4j" artifactId="log4j" />
+ </dependency>
+ <dependency groupId="org.subethamail" artifactId="subethasmtp-wiser" version="1.2" />
</copyInlineDependencies>
<property name="copy.selenium.done" value="true" />
</target>
Modified: branches/community/Seam_2_2/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java
===================================================================
--- branches/community/Seam_2_2/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java 2010-01-14 12:30:47 UTC (rev 11961)
+++ branches/community/Seam_2_2/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java 2010-01-14 12:40:26 UTC (rev 11962)
@@ -1,15 +1,41 @@
package org.jboss.seam.example.mail.test.selenium;
import org.jboss.seam.example.common.test.selenium.SeamSeleniumTest;
+import org.subethamail.wiser.Wiser;
+import org.subethamail.wiser.WiserMessage;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.assertFalse;
public class SeleniumMailTest extends SeamSeleniumTest
{
public static final String HOME_PAGE = "/index.seam";
public static final String HOME_PAGE_TITLE = "Seam Mail";
+ public static final String ENVELOPE_SENDER = "peter@example.com|do-not-reply(a)jboss.com";
+ public static final String FIRSTNAME_INPUT = "id=emailform:firstname";
+ public static final String FIRSTNAME = "John";
+ public static final String LASTNAME_INPUT = "id=emailform:lastname";
+ public static final String LASTNAME = "Smith";
+ public static final String ADDRESS_INPUT = "id=emailform:address";
+ public static final String ADDRESS = "john.smith@localhost";
+ public static final String SERVLET_NAME_INPUT = "id=name";
+ public static final String SERVLET_ADDRESS_INPUT = "id=email";
+
+ public static final String SEND_SIMPLE_BUTTON = "id=emailform:sendSimple";
+ public static final String SEND_PLAIN_BUTTON = "id=emailform:sendPlain";
+ public static final String SEND_HTML_BUTTON = "id=emailform:sendHtml";
+ public static final String SEND_ATTACHMENT_BUTTON = "id=emailform:sendAttachment";
+ public static final String SEND_ASYNCHRONOUS_BUTTON = "id=emailform:sendAsynchronous";
+ public static final String SEND_TEMPLATE_BUTTON = "id=emailform:sendTemplate";
+ public static final String SEND_SERVLET_BUTTON = "id=sendServlet";
+
+ protected Wiser wiser;
+
@BeforeMethod
@Override
public void setUp()
@@ -19,6 +45,23 @@
}
/**
+ * We restart SMTP after each Method, because Wiser doesn't have mechanism to flush recieved emails.
+ */
+ @BeforeMethod
+ public void startSMTP()
+ {
+ wiser = new Wiser();
+ wiser.setPort(2525);
+ wiser.start();
+ }
+
+ @AfterMethod
+ public void stopSMTP()
+ {
+ wiser.stop();
+ }
+
+ /**
* Place holder - just verifies that example deploys
*/
@Test
@@ -26,4 +69,80 @@
{
assertEquals("Unexpected page title.", HOME_PAGE_TITLE, browser.getTitle());
}
+
+ @DataProvider(name = "sendMethods")
+ public Object[][] mailTest() {
+ return new Object[][] {
+ {SEND_SIMPLE_BUTTON, new String[] {"Content-Type: text/html; charset=ISO-8859-1", "Content-Disposition: inline", "<p>Dear " + FIRSTNAME + ",</p>"}},
+ {SEND_PLAIN_BUTTON, new String[] {"This is a plain text, email."}},
+ {SEND_HTML_BUTTON, new String[] {"Subject: Seam Mail", "Content-Type: multipart/mixed;", "Content-Type: multipart/alternative;", "Content-Type: text/plain; charset=ISO-8859-1", "This is the alternative text body for mail readers that don't support html", "Content-Type: text/html; charset=ISO-8859-1", "<p>This is an example <i>HTML</i> email sent by Seam.</p>"}},
+ {SEND_ATTACHMENT_BUTTON, new String[] {"Content-Type: multipart/mixed;","Content-Type: application/octet-stream; name=jboss.jpg", "/9j/4AAQSkZJRgABA"/*jpeg start*/, "Content-Type: application/octet-stream; name=numbers.csv", "3,Three,treis,trois", "Content-Type: image/png; name=" + FIRSTNAME + "_" + LASTNAME + ".jpg", "iVBORw0KGgo" /*png start*/ }},
+ {SEND_ASYNCHRONOUS_BUTTON, new String[] {"Content-Type: multipart/mixed;", "Content-Type: text/html; charset=ISO-8859-1", "Content-Disposition: inline", "<p>Dear " + FIRSTNAME + ",</p>"}},
+ {SEND_TEMPLATE_BUTTON, new String[] {"Subject: Templating with Seam Mail", "Content-Type: multipart/mixed;", "Content-Type: multipart/alternative;", "Content-Type: text/plain; charset=ISO-8859-1", "Sorry, your mail reader doesn't support html.", "Content-Type: text/html; charset=ISO-8859-1", "<p>Here's a dataTable</p><table>", "<td>Saturday</td>"}},
+ {SEND_SERVLET_BUTTON, new String[] {"Content-Type: multipart/mixed;", "Content-Disposition: inline", "Dear John Smith,", "This is a plain text, email."}}
+ };
+ }
+
+ /**
+ * Sends a mail and verifies it was delivered
+ */
+ @Test(dataProvider = "sendMethods")
+ public void mailTest(String buttonToClick, String[] expectedMessageContents) {
+ fillInInputs();
+ sendEmail(buttonToClick);
+ checkDelivered(expectedMessageContents);
+ }
+
+ /**
+ * Fills in html text inputs.
+ */
+ private void fillInInputs()
+ {
+ browser.type(FIRSTNAME_INPUT, FIRSTNAME);
+ browser.type(LASTNAME_INPUT, LASTNAME);
+ browser.type(ADDRESS_INPUT, ADDRESS);
+ browser.type(SERVLET_NAME_INPUT, FIRSTNAME + " " + LASTNAME);
+ browser.type(SERVLET_ADDRESS_INPUT, ADDRESS);
+ }
+
+ /**
+ * Sends an email by clicking on specified button. If the send method is asynchronous,
+ * waits for the associated action to take place. It assures that the email was sent
+ * by verifying appropriate message.
+ * @param buttonToClick
+ */
+ private void sendEmail(String buttonToClick)
+ {
+ browser.clickAndWait(buttonToClick);
+ if (buttonToClick.equals(SEND_ASYNCHRONOUS_BUTTON)) {
+ assertTrue(browser.isTextPresent("Seam Email")); // asynchronous email send produces no message, so we just check that we didn't end up on a debug page
+ try
+ {
+ Thread.sleep(4000);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ } else {
+ assertTrue("Expected message about successfuly sent mail. See also JBSEAM-3769.", browser.isTextPresent("Email sent successfully"));
+ }
+ }
+
+ /**
+ * Checks that the expected email was delivered.
+ * @param expectedMessageContents
+ */
+ private void checkDelivered(String[] expectedMessageContents)
+ {
+ assertFalse("Expected a message", wiser.getMessages().isEmpty());
+ WiserMessage message = wiser.getMessages().get(0); // although "send plain text" example sends 3 mails (To:, CC:, Bcc:) Wiser cannot distinquish between them so we just check the first mail.
+ assertEquals(ADDRESS, message.getEnvelopeReceiver());
+ assertTrue("Envelope sender (" + message.getEnvelopeSender() + ") doesn't match expected one (" + ENVELOPE_SENDER + ")", message.getEnvelopeSender().matches(ENVELOPE_SENDER));
+
+ for (String expectedMessageContent: expectedMessageContents) {
+ assertTrue("Didn't find expected text (" + expectedMessageContent + ") in the received email.", new String(message.getData()).contains(expectedMessageContent));
+ }
+ }
+
}
14 years, 11 months
Seam SVN: r11961 - in branches/enterprise/JBPAPP_4_3_FP01: examples/mail/view and 2 other directories.
by seam-commits@lists.jboss.org
Author: oskutka(a)redhat.com
Date: 2010-01-14 07:30:47 -0500 (Thu, 14 Jan 2010)
New Revision: 11961
Modified:
branches/enterprise/JBPAPP_4_3_FP01/examples/mail/resources/WEB-INF/components.xml
branches/enterprise/JBPAPP_4_3_FP01/examples/mail/view/index.xhtml
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java
Log:
JBQA-2922 Create a functional test for mail example
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/mail/resources/WEB-INF/components.xml
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/mail/resources/WEB-INF/components.xml 2010-01-14 12:27:45 UTC (rev 11960)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/mail/resources/WEB-INF/components.xml 2010-01-14 12:30:47 UTC (rev 11961)
@@ -13,7 +13,7 @@
<core:init debug="true" jndi-pattern="@jndiPattern@" />
<!-- If you need to alter the SMTP gateway, comment out this mail-session, -->
- <mail:mail-session host="localhost" port="2525" username="test" password="test" />
+ <mail:mail-session host="localhost" tls="false" port="2525" ssl="false" />
<!-- uncomment this one and set the host attribute to the name or IP address of your SMTP gateway-->
<!-- <mail:mail-session host="smtp.foo.com" />-->
Modified: branches/enterprise/JBPAPP_4_3_FP01/examples/mail/view/index.xhtml
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/examples/mail/view/index.xhtml 2010-01-14 12:27:45 UTC (rev 11960)
+++ branches/enterprise/JBPAPP_4_3_FP01/examples/mail/view/index.xhtml 2010-01-14 12:30:47 UTC (rev 11961)
@@ -17,23 +17,23 @@
<p>Welcome to the Seam Email example. This example demonstrates Seam's email templating.</p>
<p>You need to enter a name and email address to receive the example emails in the form below.</p>
- <h:form>
+ <h:form id="emailform" >
<h:panelGrid columns="2">
<h:outputText value="Name" />
<h:panelGroup>
- <h:inputText value="#{person.firstname}" required="true" />
- <h:inputText value="#{person.lastname}" required="true" />
+ <h:inputText value="#{person.firstname}" required="true" id="firstname" />
+ <h:inputText value="#{person.lastname}" required="true" id="lastname" />
</h:panelGroup>
<h:outputText value="Email Address" />
- <h:inputText value="#{person.address}" required="true"/>
+ <h:inputText value="#{person.address}" required="true" id="address" />
</h:panelGrid>
<h:panelGrid>
- <h:commandButton action="#{mailExample.send}" value="Send a simple email" />
- <h:commandButton action="#{mailExample.sendPlain}" value="Send Plain Text Email" />
- <h:commandButton action="#{mailExample.sendHtml}" value="Send HTML Email" />
- <h:commandButton action="#{mailExample.sendAttachment}" value="Send a simple email with attachment" />
- <h:commandButton action="#{mailExample.sendAsynchronous}" value="Send a simple email asynchronously" />
- <h:commandButton action="#{mailExample.sendTemplate}" value="Send a templated email" />
+ <h:commandButton action="#{mailExample.send}" id="sendSimple" value="Send a simple email" />
+ <h:commandButton action="#{mailExample.sendPlain}" id="sendPlain" value="Send Plain Text Email" />
+ <h:commandButton action="#{mailExample.sendHtml}" id="sendHtml" value="Send HTML Email" />
+ <h:commandButton action="#{mailExample.sendAttachment}" id="sendAttachment" value="Send a simple email with attachment" />
+ <h:commandButton action="#{mailExample.sendAsynchronous}" id="sendAsynchronous" value="Send a simple email asynchronously" />
+ <h:commandButton action="#{mailExample.sendTemplate}" id="sendTemplate" value="Send a templated email" />
</h:panelGrid>
<h:messages infoStyle="info" errorStyle="error" fatalStyle="fatal" warnStyle="warn" />
</h:form>
Modified: branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml 2010-01-14 12:27:45 UTC (rev 11960)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml 2010-01-14 12:30:47 UTC (rev 11961)
@@ -266,6 +266,11 @@
<dependency groupId="org.seleniumhq.selenium.client-drivers" artifactId="selenium-java-client-driver" version="1.0.1">
<exclusion groupId="org.codehaus.groovy.maven.runtime" artifactId="gmaven-runtime-default" />
</dependency>
+ <dependency groupId="org.subethamail" artifactId="subethasmtp-smtp" version="1.2" >
+ <!-- subethamail requires commons-logging 1.1 which requires log4j 1.2.12. But we provide log4j 1.2.14, which is completely ok -->
+ <exclusion groupId="log4j" artifactId="log4j" />
+ </dependency>
+ <dependency groupId="org.subethamail" artifactId="subethasmtp-wiser" version="1.2" />
</copyInlineDependencies>
<property name="copy.selenium.done" value="true" />
</target>
Modified: branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java 2010-01-14 12:27:45 UTC (rev 11960)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java 2010-01-14 12:30:47 UTC (rev 11961)
@@ -1,15 +1,38 @@
package org.jboss.seam.example.mail.test.selenium;
import org.jboss.seam.example.common.test.selenium.SeamSeleniumTest;
+import org.subethamail.wiser.Wiser;
+import org.subethamail.wiser.WiserMessage;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.assertFalse;
public class SeleniumMailTest extends SeamSeleniumTest
{
public static final String HOME_PAGE = "/index.seam";
public static final String HOME_PAGE_TITLE = "Seam Mail";
+ public static final String ENVELOPE_SENDER = "peter@example.com|do-not-reply(a)jboss.com";
+ public static final String FIRSTNAME_INPUT = "id=emailform:firstname";
+ public static final String FIRSTNAME = "John";
+ public static final String LASTNAME_INPUT = "id=emailform:lastname";
+ public static final String LASTNAME = "Smith";
+ public static final String ADDRESS_INPUT = "id=emailform:address";
+ public static final String ADDRESS = "john.smith@localhost";
+
+ public static final String SEND_SIMPLE_BUTTON = "id=emailform:sendSimple";
+ public static final String SEND_PLAIN_BUTTON = "id=emailform:sendPlain";
+ public static final String SEND_HTML_BUTTON = "id=emailform:sendHtml";
+ public static final String SEND_ATTACHMENT_BUTTON = "id=emailform:sendAttachment";
+ public static final String SEND_ASYNCHRONOUS_BUTTON = "id=emailform:sendAsynchronous";
+ public static final String SEND_TEMPLATE_BUTTON = "id=emailform:sendTemplate";
+
+ protected Wiser wiser;
+
@BeforeMethod
@Override
public void setUp()
@@ -19,6 +42,23 @@
}
/**
+ * We restart SMTP after each Method, because Wiser doesn't have mechanism to flush recieved emails.
+ */
+ @BeforeMethod
+ public void startSMTP()
+ {
+ wiser = new Wiser();
+ wiser.setPort(2525);
+ wiser.start();
+ }
+
+ @AfterMethod
+ public void stopSMTP()
+ {
+ wiser.stop();
+ }
+
+ /**
* Place holder - just verifies that example deploys
*/
@Test
@@ -26,4 +66,77 @@
{
assertEquals("Unexpected page title.", HOME_PAGE_TITLE, browser.getTitle());
}
+
+ @DataProvider(name = "sendMethods")
+ public Object[][] mailTest() {
+ return new Object[][] {
+ {SEND_SIMPLE_BUTTON, new String[] {"Content-Type: text/html; charset=ISO-8859-1", "Content-Disposition: inline", "<p>Dear " + FIRSTNAME + ",</p>"}},
+ {SEND_PLAIN_BUTTON, new String[] {"This is a plain text, email."}},
+ {SEND_HTML_BUTTON, new String[] {"Subject: Seam Mail", "Content-Type: multipart/mixed;", "Content-Type: multipart/alternative;", "Content-Type: text/plain; charset=ISO-8859-1", "This is the alternative text body for mail readers that don't support html", "Content-Type: text/html; charset=ISO-8859-1", "<p>This is an example <i>HTML</i> email sent by Seam.</p>"}},
+ {SEND_ATTACHMENT_BUTTON, new String[] {"Content-Type: multipart/mixed;","Content-Type: application/octet-stream; name=jboss.jpg", "/9j/4AAQSkZJRgABA"/*jpeg start*/, "Content-Type: application/octet-stream; name=numbers.csv", "3,Three,treis,trois", "Content-Type: image/png; name=" + FIRSTNAME + "_" + LASTNAME + ".jpg", "iVBORw0KGgo" /*png start*/ }},
+ {SEND_ASYNCHRONOUS_BUTTON, new String[] {"Content-Type: multipart/mixed;", "Content-Type: text/html; charset=ISO-8859-1", "Content-Disposition: inline", "<p>Dear " + FIRSTNAME + ",</p>"}},
+ {SEND_TEMPLATE_BUTTON, new String[] {"Subject: Templating with Seam Mail", "Content-Type: multipart/mixed;", "Content-Type: multipart/alternative;", "Content-Type: text/plain; charset=ISO-8859-1", "Sorry, your mail reader doesn't support html.", "Content-Type: text/html; charset=ISO-8859-1", "<p>Here's a dataTable</p><table>", "<td>Saturday</td>"}}
+ };
+ }
+
+ /**
+ * Sends a mail and verifies it was delivered
+ */
+ @Test(dataProvider = "sendMethods")
+ public void mailTest(String buttonToClick, String[] expectedMessageContents) {
+ fillInInputs();
+ sendEmail(buttonToClick);
+ checkDelivered(expectedMessageContents);
+ }
+
+ /**
+ * Fills in html text inputs.
+ */
+ private void fillInInputs()
+ {
+ browser.type(FIRSTNAME_INPUT, FIRSTNAME);
+ browser.type(LASTNAME_INPUT, LASTNAME);
+ browser.type(ADDRESS_INPUT, ADDRESS);
+ }
+
+ /**
+ * Sends an email by clicking on specified button. If the send method is asynchronous,
+ * waits for the associated action to take place. It assures that the email was sent
+ * by verifying appropriate message.
+ * @param buttonToClick
+ */
+ private void sendEmail(String buttonToClick)
+ {
+ browser.clickAndWait(buttonToClick);
+ if (buttonToClick.equals(SEND_ASYNCHRONOUS_BUTTON)) {
+ assertTrue(browser.isTextPresent("Seam Email")); // asynchronous email send produces no message, so we just check that we didn't end up on a debug page
+ try
+ {
+ Thread.sleep(4000);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ } else {
+ assertTrue("Expected message about successfuly sent mail. See also JBSEAM-3769.", browser.isTextPresent("Email sent successfully"));
+ }
+ }
+
+ /**
+ * Checks that the expected email was delivered.
+ * @param expectedMessageContents
+ */
+ private void checkDelivered(String[] expectedMessageContents)
+ {
+ assertFalse("Expected a message", wiser.getMessages().isEmpty());
+ WiserMessage message = wiser.getMessages().get(0); // although "send plain text" example sends 3 mails (To:, CC:, Bcc:) Wiser cannot distinquish between them so we just check the first mail.
+ assertEquals(ADDRESS, message.getEnvelopeReceiver());
+ assertTrue("Envelope sender (" + message.getEnvelopeSender() + ") doesn't match expected one (" + ENVELOPE_SENDER + ")", message.getEnvelopeSender().matches(ENVELOPE_SENDER));
+
+ for (String expectedMessageContent: expectedMessageContents) {
+ assertTrue("Didn't find expected text (" + expectedMessageContent + ") in the received email.", new String(message.getData()).contains(expectedMessageContent));
+ }
+ }
+
}
14 years, 11 months
Seam SVN: r11960 - in branches/enterprise/JBPAPP_5_0: examples/mail/view and 2 other directories.
by seam-commits@lists.jboss.org
Author: oskutka(a)redhat.com
Date: 2010-01-14 07:27:45 -0500 (Thu, 14 Jan 2010)
New Revision: 11960
Modified:
branches/enterprise/JBPAPP_5_0/examples/mail/resources/WEB-INF/components.xml
branches/enterprise/JBPAPP_5_0/examples/mail/view/index.xhtml
branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml
branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java
Log:
JBQA-2922 Create a functional test for mail example
Modified: branches/enterprise/JBPAPP_5_0/examples/mail/resources/WEB-INF/components.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/examples/mail/resources/WEB-INF/components.xml 2010-01-14 11:58:48 UTC (rev 11959)
+++ branches/enterprise/JBPAPP_5_0/examples/mail/resources/WEB-INF/components.xml 2010-01-14 12:27:45 UTC (rev 11960)
@@ -13,7 +13,7 @@
<core:init debug="true" jndi-pattern="@jndiPattern@" />
<!-- If you need to alter the SMTP gateway, comment out this mail-session, -->
- <mail:mail-session host="localhost" port="2525" username="test" password="test" />
+ <mail:mail-session host="localhost" tls="false" port="2525" ssl="false" />
<!-- uncomment this one and set the host attribute to the name or IP address of your SMTP gateway-->
<!-- <mail:mail-session host="smtp.foo.com" />-->
Modified: branches/enterprise/JBPAPP_5_0/examples/mail/view/index.xhtml
===================================================================
--- branches/enterprise/JBPAPP_5_0/examples/mail/view/index.xhtml 2010-01-14 11:58:48 UTC (rev 11959)
+++ branches/enterprise/JBPAPP_5_0/examples/mail/view/index.xhtml 2010-01-14 12:27:45 UTC (rev 11960)
@@ -17,23 +17,23 @@
<p>Welcome to the Seam Email example. This example demonstrates Seam's email templating.</p>
<p>You need to enter a name and email address to receive the example emails in the form below.</p>
- <h:form>
+ <h:form id="emailform" >
<h:panelGrid columns="2">
<h:outputText value="Name" />
<h:panelGroup>
- <h:inputText value="#{person.firstname}" required="true" />
- <h:inputText value="#{person.lastname}" required="true" />
+ <h:inputText value="#{person.firstname}" required="true" id="firstname" />
+ <h:inputText value="#{person.lastname}" required="true" id="lastname" />
</h:panelGroup>
<h:outputText value="Email Address" />
- <h:inputText value="#{person.address}" required="true"/>
+ <h:inputText value="#{person.address}" required="true" id="address" />
</h:panelGrid>
<h:panelGrid>
- <h:commandButton action="#{mailExample.send}" value="Send a simple email" />
- <h:commandButton action="#{mailExample.sendPlain}" value="Send Plain Text Email" />
- <h:commandButton action="#{mailExample.sendHtml}" value="Send HTML Email" />
- <h:commandButton action="#{mailExample.sendAttachment}" value="Send a simple email with attachment" />
- <h:commandButton action="#{mailExample.sendAsynchronous}" value="Send a simple email asynchronously" />
- <h:commandButton action="#{mailExample.sendTemplate}" value="Send a templated email" />
+ <h:commandButton action="#{mailExample.send}" id="sendSimple" value="Send a simple email" />
+ <h:commandButton action="#{mailExample.sendPlain}" id="sendPlain" value="Send Plain Text Email" />
+ <h:commandButton action="#{mailExample.sendHtml}" id="sendHtml" value="Send HTML Email" />
+ <h:commandButton action="#{mailExample.sendAttachment}" id="sendAttachment" value="Send a simple email with attachment" />
+ <h:commandButton action="#{mailExample.sendAsynchronous}" id="sendAsynchronous" value="Send a simple email asynchronously" />
+ <h:commandButton action="#{mailExample.sendTemplate}" id="sendTemplate" value="Send a templated email" />
</h:panelGrid>
<h:messages infoStyle="info" errorStyle="error" fatalStyle="fatal" warnStyle="warn" />
</h:form>
@@ -47,7 +47,7 @@
Name
</td>
<td>
- <input name="name" />
+ <input name="name" id="name" />
</td>
</tr>
<tr>
@@ -55,13 +55,13 @@
Email Address
</td>
<td>
- <input name="email" />
+ <input name="email" id="email" />
</td>
</tr>
<tr>
<td></td>
<td>
- <input type="submit" value="Send" />
+ <input type="submit" value="Send" id="sendServlet" />
</td>
</tr>
</table>
Modified: branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml 2010-01-14 11:58:48 UTC (rev 11959)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml 2010-01-14 12:27:45 UTC (rev 11960)
@@ -285,6 +285,11 @@
<dependency groupId="org.seleniumhq.selenium.client-drivers" artifactId="selenium-java-client-driver" version="1.0.1">
<exclusion groupId="org.codehaus.groovy.maven.runtime" artifactId="gmaven-runtime-default" />
</dependency>
+ <dependency groupId="org.subethamail" artifactId="subethasmtp-smtp" version="1.2" >
+ <!-- subethamail requires commons-logging 1.1 which requires log4j 1.2.12. But we provide log4j 1.2.14, which is completely ok -->
+ <exclusion groupId="log4j" artifactId="log4j" />
+ </dependency>
+ <dependency groupId="org.subethamail" artifactId="subethasmtp-wiser" version="1.2" />
</copyInlineDependencies>
<property name="copy.selenium.done" value="true" />
</target>
Modified: branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java 2010-01-14 11:58:48 UTC (rev 11959)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/mail/src/org/jboss/seam/example/mail/test/selenium/SeleniumMailTest.java 2010-01-14 12:27:45 UTC (rev 11960)
@@ -1,15 +1,41 @@
package org.jboss.seam.example.mail.test.selenium;
import org.jboss.seam.example.common.test.selenium.SeamSeleniumTest;
+import org.subethamail.wiser.Wiser;
+import org.subethamail.wiser.WiserMessage;
+import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import static org.testng.AssertJUnit.assertEquals;
+import static org.testng.AssertJUnit.assertTrue;
+import static org.testng.AssertJUnit.assertFalse;
public class SeleniumMailTest extends SeamSeleniumTest
{
public static final String HOME_PAGE = "/index.seam";
public static final String HOME_PAGE_TITLE = "Seam Mail";
+ public static final String ENVELOPE_SENDER = "peter@example.com|do-not-reply(a)jboss.com";
+ public static final String FIRSTNAME_INPUT = "id=emailform:firstname";
+ public static final String FIRSTNAME = "John";
+ public static final String LASTNAME_INPUT = "id=emailform:lastname";
+ public static final String LASTNAME = "Smith";
+ public static final String ADDRESS_INPUT = "id=emailform:address";
+ public static final String ADDRESS = "john.smith@localhost";
+ public static final String SERVLET_NAME_INPUT = "id=name";
+ public static final String SERVLET_ADDRESS_INPUT = "id=email";
+
+ public static final String SEND_SIMPLE_BUTTON = "id=emailform:sendSimple";
+ public static final String SEND_PLAIN_BUTTON = "id=emailform:sendPlain";
+ public static final String SEND_HTML_BUTTON = "id=emailform:sendHtml";
+ public static final String SEND_ATTACHMENT_BUTTON = "id=emailform:sendAttachment";
+ public static final String SEND_ASYNCHRONOUS_BUTTON = "id=emailform:sendAsynchronous";
+ public static final String SEND_TEMPLATE_BUTTON = "id=emailform:sendTemplate";
+ public static final String SEND_SERVLET_BUTTON = "id=sendServlet";
+
+ protected Wiser wiser;
+
@BeforeMethod
@Override
public void setUp()
@@ -19,6 +45,23 @@
}
/**
+ * We restart SMTP after each Method, because Wiser doesn't have mechanism to flush recieved emails.
+ */
+ @BeforeMethod
+ public void startSMTP()
+ {
+ wiser = new Wiser();
+ wiser.setPort(2525);
+ wiser.start();
+ }
+
+ @AfterMethod
+ public void stopSMTP()
+ {
+ wiser.stop();
+ }
+
+ /**
* Place holder - just verifies that example deploys
*/
@Test
@@ -26,4 +69,80 @@
{
assertEquals("Unexpected page title.", HOME_PAGE_TITLE, browser.getTitle());
}
+
+ @DataProvider(name = "sendMethods")
+ public Object[][] mailTest() {
+ return new Object[][] {
+ {SEND_SIMPLE_BUTTON, new String[] {"Content-Type: text/html; charset=ISO-8859-1", "Content-Disposition: inline", "<p>Dear " + FIRSTNAME + ",</p>"}},
+ {SEND_PLAIN_BUTTON, new String[] {"This is a plain text, email."}},
+ {SEND_HTML_BUTTON, new String[] {"Subject: Seam Mail", "Content-Type: multipart/mixed;", "Content-Type: multipart/alternative;", "Content-Type: text/plain; charset=ISO-8859-1", "This is the alternative text body for mail readers that don't support html", "Content-Type: text/html; charset=ISO-8859-1", "<p>This is an example <i>HTML</i> email sent by Seam.</p>"}},
+ {SEND_ATTACHMENT_BUTTON, new String[] {"Content-Type: multipart/mixed;","Content-Type: application/octet-stream; name=jboss.jpg", "/9j/4AAQSkZJRgABA"/*jpeg start*/, "Content-Type: application/octet-stream; name=numbers.csv", "3,Three,treis,trois", "Content-Type: image/png; name=" + FIRSTNAME + "_" + LASTNAME + ".jpg", "iVBORw0KGgo" /*png start*/ }},
+ {SEND_ASYNCHRONOUS_BUTTON, new String[] {"Content-Type: multipart/mixed;", "Content-Type: text/html; charset=ISO-8859-1", "Content-Disposition: inline", "<p>Dear " + FIRSTNAME + ",</p>"}},
+ {SEND_TEMPLATE_BUTTON, new String[] {"Subject: Templating with Seam Mail", "Content-Type: multipart/mixed;", "Content-Type: multipart/alternative;", "Content-Type: text/plain; charset=ISO-8859-1", "Sorry, your mail reader doesn't support html.", "Content-Type: text/html; charset=ISO-8859-1", "<p>Here's a dataTable</p><table>", "<td>Saturday</td>"}},
+ {SEND_SERVLET_BUTTON, new String[] {"Content-Type: multipart/mixed;", "Content-Disposition: inline", "Dear John Smith,", "This is a plain text, email."}}
+ };
+ }
+
+ /**
+ * Sends a mail and verifies it was delivered
+ */
+ @Test(dataProvider = "sendMethods")
+ public void mailTest(String buttonToClick, String[] expectedMessageContents) {
+ fillInInputs();
+ sendEmail(buttonToClick);
+ checkDelivered(expectedMessageContents);
+ }
+
+ /**
+ * Fills in html text inputs.
+ */
+ private void fillInInputs()
+ {
+ browser.type(FIRSTNAME_INPUT, FIRSTNAME);
+ browser.type(LASTNAME_INPUT, LASTNAME);
+ browser.type(ADDRESS_INPUT, ADDRESS);
+ browser.type(SERVLET_NAME_INPUT, FIRSTNAME + " " + LASTNAME);
+ browser.type(SERVLET_ADDRESS_INPUT, ADDRESS);
+ }
+
+ /**
+ * Sends an email by clicking on specified button. If the send method is asynchronous,
+ * waits for the associated action to take place. It assures that the email was sent
+ * by verifying appropriate message.
+ * @param buttonToClick
+ */
+ private void sendEmail(String buttonToClick)
+ {
+ browser.clickAndWait(buttonToClick);
+ if (buttonToClick.equals(SEND_ASYNCHRONOUS_BUTTON)) {
+ assertTrue(browser.isTextPresent("Seam Email")); // asynchronous email send produces no message, so we just check that we didn't end up on a debug page
+ try
+ {
+ Thread.sleep(4000);
+ }
+ catch (InterruptedException e)
+ {
+ e.printStackTrace();
+ }
+ } else {
+ assertTrue("Expected message about successfuly sent mail. See also JBSEAM-3769.", browser.isTextPresent("Email sent successfully"));
+ }
+ }
+
+ /**
+ * Checks that the expected email was delivered.
+ * @param expectedMessageContents
+ */
+ private void checkDelivered(String[] expectedMessageContents)
+ {
+ assertFalse("Expected a message", wiser.getMessages().isEmpty());
+ WiserMessage message = wiser.getMessages().get(0); // although "send plain text" example sends 3 mails (To:, CC:, Bcc:) Wiser cannot distinquish between them so we just check the first mail.
+ assertEquals(ADDRESS, message.getEnvelopeReceiver());
+ assertTrue("Envelope sender (" + message.getEnvelopeSender() + ") doesn't match expected one (" + ENVELOPE_SENDER + ")", message.getEnvelopeSender().matches(ENVELOPE_SENDER));
+
+ for (String expectedMessageContent: expectedMessageContents) {
+ assertTrue("Didn't find expected text (" + expectedMessageContent + ") in the received email.", new String(message.getData()).contains(expectedMessageContent));
+ }
+ }
+
}
14 years, 11 months