Author: swd847
Date: 2010-03-30 05:57:11 -0400 (Tue, 30 Mar 2010)
New Revision: 12322
Added:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/TypeXmlItem.java
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/AllowedType.java
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/RestrictedType.java
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/SomeInterface.java
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/TypeInjectedClass.java
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/TypesTest.java
modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/types/
modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/types/types-test-beans.xml
Modified:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/XmlItemType.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
modules/xml/trunk/pom.xml
Log:
added ability to override field type
Modified: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
===================================================================
---
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java 2010-03-30
08:33:45 UTC (rev 12321)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java 2010-03-30
09:57:11 UTC (rev 12322)
@@ -19,7 +19,7 @@
allowed.add(XmlItemType.FIELD);
allowed.add(XmlItemType.METHOD);
allowed.add(XmlItemType.PARAMETERS);
-
+ allowed.add(XmlItemType.TYPE);
}
public Set<XmlItemType> getAllowedItem()
Modified: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java
===================================================================
---
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java 2010-03-30
08:33:45 UTC (rev 12321)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java 2010-03-30
09:57:11 UTC (rev 12322)
@@ -42,6 +42,7 @@
}
allowed.add(XmlItemType.ANNOTATION);
allowed.add(XmlItemType.VALUE);
+ allowed.add(XmlItemType.TYPE);
}
public Field getField()
Modified: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
===================================================================
---
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-03-30
08:33:45 UTC (rev 12321)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-03-30
09:57:11 UTC (rev 12322)
@@ -7,8 +7,10 @@
import java.lang.annotation.Annotation;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
+import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
@@ -277,6 +279,23 @@
Annotation a = createAnnotation(fi);
type.addToField(item.getField(), a);
}
+ List<TypeXmlItem> types = item.getChildrenOfType(TypeXmlItem.class);
+ if (types.size() > 1)
+ {
+ throw new XmlConfigurationException("Only one <type> element may
be present on a field", rb.getDocument(), rb.getLineno());
+ }
+ if (!types.isEmpty())
+ {
+ Set<Type> fieldTypes = new HashSet<Type>();
+ List<ClassXmlItem> overridenTypes =
types.get(0).getChildrenOfType(ClassXmlItem.class);
+ if (overridenTypes.size() != 1)
+ {
+ throw new XmlConfigurationException("<type> must have a single
child element", rb.getDocument(), rb.getLineno());
+ }
+
+ type.overrideFieldType(item.getField(),
overridenTypes.get(0).getJavaClass());
+ }
+
}
for (MethodXmlItem item : rb.getChildrenOfType(MethodXmlItem.class))
{
Added: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/TypeXmlItem.java
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/TypeXmlItem.java
(rev 0)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/TypeXmlItem.java 2010-03-30
09:57:11 UTC (rev 12322)
@@ -0,0 +1,30 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class TypeXmlItem extends AbstractXmlItem
+{
+
+ static final Set<XmlItemType> allowed = new HashSet<XmlItemType>();
+
+ static
+ {
+ allowed.add(XmlItemType.CLASS);
+ allowed.add(XmlItemType.ANNOTATION);
+ }
+
+ public TypeXmlItem(XmlItem parent, String document, int lineno)
+ {
+ super(XmlItemType.TYPE, parent, null, null, null, document, lineno);
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return allowed;
+ }
+}
Modified: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/XmlItemType.java
===================================================================
---
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/XmlItemType.java 2010-03-30
08:33:45 UTC (rev 12321)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/XmlItemType.java 2010-03-30
09:57:11 UTC (rev 12322)
@@ -6,5 +6,5 @@
public enum XmlItemType
{
- CLASS, METHOD, FIELD, ANNOTATION, VALUE, VETO, ENTRY, KEY, DEPENDENCY, PARAMETERS,
PARAMETER, ARRAY, OVERRIDE, EXTENDS;
+ CLASS, METHOD, FIELD, ANNOTATION, VALUE, VETO, ENTRY, KEY, DEPENDENCY, PARAMETERS,
PARAMETER, ARRAY, OVERRIDE, EXTENDS, TYPE;
}
Modified:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
===================================================================
---
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java 2010-03-30
08:33:45 UTC (rev 12321)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java 2010-03-30
09:57:11 UTC (rev 12322)
@@ -12,6 +12,7 @@
import org.jboss.seam.xml.model.OverrideXmlItem;
import org.jboss.seam.xml.model.ParameterXmlItem;
import org.jboss.seam.xml.model.ParametersXmlItem;
+import org.jboss.seam.xml.model.TypeXmlItem;
import org.jboss.seam.xml.model.ValueXmlItem;
import org.jboss.seam.xml.model.XmlItem;
import org.jboss.seam.xml.model.XmlItemType;
@@ -68,6 +69,10 @@
{
return new ParametersXmlItem(parent, node.getDocument(), node.getLineNo());
}
+ else if (item.equals("type"))
+ {
+ return new TypeXmlItem(parent, node.getDocument(), node.getLineNo());
+ }
// now deal with primitive types
Added:
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/AllowedType.java
===================================================================
--- modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/AllowedType.java
(rev 0)
+++
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/AllowedType.java 2010-03-30
09:57:11 UTC (rev 12322)
@@ -0,0 +1,6 @@
+package org.jboss.seam.xml.test.types;
+
+public class AllowedType implements SomeInterface
+{
+
+}
Added:
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/RestrictedType.java
===================================================================
---
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/RestrictedType.java
(rev 0)
+++
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/RestrictedType.java 2010-03-30
09:57:11 UTC (rev 12322)
@@ -0,0 +1,6 @@
+package org.jboss.seam.xml.test.types;
+
+public class RestrictedType implements SomeInterface
+{
+
+}
Added:
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/SomeInterface.java
===================================================================
--- modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/SomeInterface.java
(rev 0)
+++
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/SomeInterface.java 2010-03-30
09:57:11 UTC (rev 12322)
@@ -0,0 +1,6 @@
+package org.jboss.seam.xml.test.types;
+
+public interface SomeInterface
+{
+
+}
Added:
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/TypeInjectedClass.java
===================================================================
---
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/TypeInjectedClass.java
(rev 0)
+++
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/TypeInjectedClass.java 2010-03-30
09:57:11 UTC (rev 12322)
@@ -0,0 +1,6 @@
+package org.jboss.seam.xml.test.types;
+
+public class TypeInjectedClass
+{
+ public SomeInterface value;
+}
Added: modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/TypesTest.java
===================================================================
--- modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/TypesTest.java
(rev 0)
+++
modules/xml/trunk/core/src/test/java/org/jboss/seam/xml/test/types/TypesTest.java 2010-03-30
09:57:11 UTC (rev 12322)
@@ -0,0 +1,31 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.test.types;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.jboss.weld.environment.se.util.WeldManagerUtils;
+import org.testng.annotations.Test;
+
+/**
+ * tests that <types> restricts the allowed types of an injection point
+ */
+public class TypesTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "types-test-beans.xml";
+ }
+
+ @Test(enabled = true)
+ public void testTypeRestriction()
+ {
+
+ TypeInjectedClass x = WeldManagerUtils.getInstanceByType(manager,
TypeInjectedClass.class);
+ assert x.value instanceof AllowedType;
+
+ }
+}
Added:
modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/types/types-test-beans.xml
===================================================================
---
modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/types/types-test-beans.xml
(rev 0)
+++
modules/xml/trunk/core/src/test/resources/org/jboss/seam/xml/test/types/types-test-beans.xml 2010-03-30
09:57:11 UTC (rev 12322)
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="urn:java:seam:core"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.types">
+
+
+ <test:TypeInjectedClass>
+ <override/>
+ <test:value>
+ <Inject/>
+ <type>
+ <test:AllowedType/>
+ </type>
+ </test:value>
+ </test:TypeInjectedClass>
+
+</beans>
\ No newline at end of file
Modified: modules/xml/trunk/pom.xml
===================================================================
--- modules/xml/trunk/pom.xml 2010-03-30 08:33:45 UTC (rev 12321)
+++ modules/xml/trunk/pom.xml 2010-03-30 09:57:11 UTC (rev 12322)
@@ -58,7 +58,7 @@
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-extensions</artifactId>
- <version>1.0.0.Alpha1</version>
+ <version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>