Author: swd847
Date: 2010-03-04 22:44:36 -0500 (Thu, 04 Mar 2010)
New Revision: 12098
Added:
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ExtendsXmlItem.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/OverrideXmlItem.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedBean.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedQualifier1.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedQualifier2.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/OverriddenBean.java
Removed:
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/DependsXmlItem.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/dependency/
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/dependency/dependency-beans.xml
Modified:
modules/xml/trunk/pom.xml
modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/BeanResult.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/XmlResult.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/XmlItemType.java
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/AbstractXMLTest.java
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/SimpleBeanTest.java
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/simple/simple-beans.xml
Log:
added <extends> and <override> tags
Modified: modules/xml/trunk/pom.xml
===================================================================
--- modules/xml/trunk/pom.xml 2010-03-04 17:57:27 UTC (rev 12097)
+++ modules/xml/trunk/pom.xml 2010-03-05 03:44:36 UTC (rev 12098)
@@ -46,8 +46,8 @@
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
- <artifactId>weld-extensions</artifactId>
- <version>1.0.0-SNAPSHOT</version>
+ <artifactId>weld-extensions-core</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
Modified: 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 2010-03-04
17:57:27 UTC (rev 12097)
+++
modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -33,6 +33,7 @@
import org.jboss.seam.xml.parser.SaxNode;
import org.jboss.seam.xml.util.FileDataReader;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
+import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
public class XmlExtension implements Extension
{
@@ -47,6 +48,8 @@
Map<Class<?>, AnnotatedType<?>> types = new
HashMap<Class<?>, AnnotatedType<?>>();
+ Map<Class<?>, BeanResult<?>> beanExtensions = new
HashMap<Class<?>, BeanResult<?>>();
+
int count = 0;
/**
@@ -74,7 +77,6 @@
ParserMain parser = new ParserMain();
ModelBuilder builder = new ModelBuilder();
SaxNode parentNode = parser.parse(d.getInputSource(), d.getFileUrl(),
errors);
- ;
results.add(builder.build(parentNode));
}
}
@@ -118,26 +120,14 @@
}
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);
- }
+ AnnotatedType<?> tp = bb.getBuilder().create();
+ event.addAnnotatedType(tp);
+ types.put(tp.getJavaClass(), tp);
}
+ for (BeanResult<?> bb : r.getExtendBeans())
+ {
+ beanExtensions.put(bb.getType(), bb);
+ }
veto.addAll(r.getVeto());
}
@@ -150,6 +140,13 @@
{
event.veto();
}
+ Class javaClass = event.getAnnotatedType().getJavaClass();
+ if (beanExtensions.containsKey(javaClass))
+ {
+ NewAnnotatedTypeBuilder typeBuilder =
beanExtensions.get(javaClass).getBuilder();
+ typeBuilder.mergeAnnotations(event.getAnnotatedType(), false);
+ event.setAnnotatedType(typeBuilder.create());
+ }
}
public <T> void processInjectionTarget(@Observes ProcessInjectionTarget<T>
event)
Modified: 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 2010-03-04
17:57:27 UTC (rev 12097)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/BeanResult.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -4,17 +4,13 @@
*/
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<X> builder;
- List<String> dependencies = new ArrayList<String>();
Class<X> type;
+ boolean override, extend;
public BeanResult(Class<X> type)
{
@@ -27,18 +23,28 @@
return builder;
}
- public void addDependency(String className)
+ public Class<X> getType()
{
- dependencies.add(className);
+ return type;
}
- public List<String> getDependencies()
+ public boolean isOverride()
{
- return Collections.unmodifiableList(dependencies);
+ return override;
}
- public Class<X> getType()
+ public void setOverride(boolean override)
{
- return type;
+ this.override = override;
}
+
+ public boolean isExtend()
+ {
+ return extend;
+ }
+
+ public void setExtend(boolean extend)
+ {
+ this.extend = extend;
+ }
}
Modified: 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 2010-03-04
17:57:27 UTC (rev 12097)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/XmlResult.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -33,6 +33,8 @@
List<BeanResult<?>> beans = new ArrayList<BeanResult<?>>();
+ List<BeanResult<?>> extendBeans = new
ArrayList<BeanResult<?>>();
+
Map<BeanResult<?>, List<FieldValueObject>> fieldValues = new
HashMap<BeanResult<?>, List<FieldValueObject>>();
public Map<Class<? extends Annotation>, Annotation[]> getStereotypes()
@@ -80,4 +82,9 @@
return veto;
}
+ public List<BeanResult<?>> getExtendBeans()
+ {
+ return extendBeans;
+ }
+
}
Deleted: 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 2010-03-04
17:57:27 UTC (rev 12097)
+++
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/DependsXmlItem.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -1,23 +0,0 @@
-/*
- * 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, String document, int lineno)
- {
- super(XmlItemType.DEPENDENCY, parent, null, innerTest, null, document, lineno);
- }
-
- public Set<XmlItemType> getAllowedItem()
- {
- return Collections.emptySet();
- }
-
-}
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ExtendsXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ExtendsXmlItem.java
(rev 0)
+++
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ExtendsXmlItem.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -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 ExtendsXmlItem extends AbstractXmlItem
+{
+
+ public ExtendsXmlItem(XmlItem parent, String document, int lineno)
+ {
+ super(XmlItemType.EXTENDS, parent, null, null, null, document, lineno);
+
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return Collections.emptySet();
+ }
+
+}
Modified: 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 2010-03-04
17:57:27 UTC (rev 12097)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -95,7 +95,18 @@
if (type == ResultType.BEAN)
{
BeanResult<?> tp = buildAnnotatedType(rb);
- ret.getBeans().add(tp);
+ if (tp.isExtend())
+ {
+ ret.getExtendBeans().add(tp);
+ }
+ else
+ {
+ ret.getBeans().add(tp);
+ }
+ if (tp.isOverride())
+ {
+ ret.addVeto(tp.getType());
+ }
List<FieldValueObject> fields = new
ArrayList<FieldValueObject>();
for (FieldXmlItem xi : rb.getChildrenOfType(FieldXmlItem.class))
{
@@ -237,6 +248,15 @@
// list of constructor arguments
List<XmlItem> constList = new ArrayList<XmlItem>();
+ boolean override = !rb.getChildrenOfType(OverrideXmlItem.class).isEmpty();
+ boolean extend = !rb.getChildrenOfType(ExtendsXmlItem.class).isEmpty();
+ if (override && extend)
+ {
+ throw new XmlConfigurationException("A bean may not both <override>
and <extend> an existing bean", rb.getDocument(), rb.getLineno());
+ }
+ result.setOverride(override);
+ result.setExtend(extend);
+
for (AnnotationXmlItem item : rb.getChildrenOfType(AnnotationXmlItem.class))
{
Annotation a = createAnnotation(item);
@@ -275,10 +295,6 @@
}
}
- for (DependsXmlItem item : rb.getChildrenOfType(DependsXmlItem.class))
- {
- result.addDependency(item.getInnerText());
- }
if (!constList.isEmpty())
{
Added: modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/OverrideXmlItem.java
===================================================================
--- modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/OverrideXmlItem.java
(rev 0)
+++
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/OverrideXmlItem.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -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 OverrideXmlItem extends AbstractXmlItem
+{
+
+ public OverrideXmlItem(XmlItem parent, String document, int lineno)
+ {
+ super(XmlItemType.OVERRIDE, parent, null, null, null, document, lineno);
+
+ }
+
+ public Set<XmlItemType> getAllowedItem()
+ {
+ return Collections.emptySet();
+ }
+
+}
Modified: 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 2010-03-04
17:57:27 UTC (rev 12097)
+++ modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/XmlItemType.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -6,5 +6,5 @@
public enum XmlItemType
{
- CLASS, METHOD, FIELD, ANNOTATION, VALUE, VETO, ENTRY, KEY, DEPENDENCY, PARAMETER,
ARRAY, OVERRIDE;
+ CLASS, METHOD, FIELD, ANNOTATION, VALUE, VETO, ENTRY, KEY, DEPENDENCY, PARAMETER,
ARRAY, OVERRIDE, EXTENDS;
}
Modified:
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 2010-03-04
17:57:27 UTC (rev 12097)
+++
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/RootNamespaceElementResolver.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -6,9 +6,10 @@
import org.jboss.seam.xml.model.ArrayXmlItem;
import org.jboss.seam.xml.model.ClassXmlItem;
-import org.jboss.seam.xml.model.DependsXmlItem;
import org.jboss.seam.xml.model.EntryXmlItem;
+import org.jboss.seam.xml.model.ExtendsXmlItem;
import org.jboss.seam.xml.model.KeyXmlItem;
+import org.jboss.seam.xml.model.OverrideXmlItem;
import org.jboss.seam.xml.model.ParameterXmlItem;
import org.jboss.seam.xml.model.ValueXmlItem;
import org.jboss.seam.xml.model.VetoXmlItem;
@@ -59,10 +60,14 @@
{
return new VetoXmlItem(parent, node.getDocument(), node.getLineNo());
}
- else if (item.equals("depends"))
+ else if (item.equals("override"))
{
- return new DependsXmlItem(parent, node.getInnerText(), node.getDocument(),
node.getLineNo());
+ return new OverrideXmlItem(parent, node.getDocument(), node.getLineNo());
}
+ else if (item.equals("extends"))
+ {
+ return new ExtendsXmlItem(parent, node.getDocument(), node.getLineNo());
+ }
// now deal with primitive types
Modified: 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 2010-03-04
17:57:27 UTC (rev 12097)
+++
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/AbstractXMLTest.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -17,11 +17,8 @@
public abstract class AbstractXMLTest
{
-
- public static String[] ARGS_EMPTY = new String[] {};
-
protected BeanManager manager;
-
+
Weld weld;
protected abstract String getXmlFileName();
@@ -39,7 +36,7 @@
@AfterClass
public void teardown()
{
- weld.shutdown();
+ weld.shutdown();
}
public <T> T getReference(Class<T> clazz, Annotation... bindings)
@@ -52,7 +49,7 @@
else if (beans.size() != 1)
{
StringBuilder bs = new StringBuilder("[");
- for(Annotation a : bindings)
+ for (Annotation a : bindings)
{
bs.append(a.toString() + ",");
}
@@ -63,5 +60,4 @@
return (T) bean.create(manager.createCreationalContext(bean));
}
-
}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedBean.java
(rev 0)
+++
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedBean.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -0,0 +1,7 @@
+package org.jboss.seam.xml.test.simple;
+
+@ExtendedQualifier1
+public class ExtendedBean
+{
+
+}
Added:
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedQualifier1.java
===================================================================
---
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedQualifier1.java
(rev 0)
+++
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedQualifier1.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -0,0 +1,13 @@
+package org.jboss.seam.xml.test.simple;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import javax.inject.Qualifier;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface ExtendedQualifier1
+{
+
+}
Added:
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedQualifier2.java
===================================================================
---
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedQualifier2.java
(rev 0)
+++
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/ExtendedQualifier2.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -0,0 +1,13 @@
+package org.jboss.seam.xml.test.simple;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+
+import javax.inject.Qualifier;
+
+(a)Retention(RetentionPolicy.RUNTIME)
+@Qualifier
+public @interface ExtendedQualifier2
+{
+
+}
Added: modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/OverriddenBean.java
===================================================================
--- modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/OverriddenBean.java
(rev 0)
+++
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/OverriddenBean.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -0,0 +1,6 @@
+package org.jboss.seam.xml.test.simple;
+
+public class OverriddenBean
+{
+
+}
Modified:
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 2010-03-04
17:57:27 UTC (rev 12097)
+++
modules/xml/trunk/src/test/java/org/jboss/seam/xml/test/simple/SimpleBeanTest.java 2010-03-05
03:44:36 UTC (rev 12098)
@@ -4,6 +4,11 @@
*/
package org.jboss.seam.xml.test.simple;
+import java.util.Set;
+
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.util.AnnotationLiteral;
+
import org.jboss.seam.xml.test.AbstractXMLTest;
import org.jboss.weld.environment.se.util.WeldManagerUtils;
import org.testng.annotations.Test;
@@ -32,4 +37,27 @@
assert x.value == 1 : "Post construct method not called";
}
+ @Test
+ public void testOverride()
+ {
+ Set<Bean<?>> beans = manager.getBeans(OverriddenBean.class);
+ assert beans.size() == 1;
+ assert beans.iterator().next().getName().equals("someBean");
+
+ }
+
+ @Test
+ public void testExtends()
+ {
+ AnnotationLiteral<ExtendedQualifier1> e1 = new
AnnotationLiteral<ExtendedQualifier1>()
+ {
+ };
+ AnnotationLiteral<ExtendedQualifier2> e2 = new
AnnotationLiteral<ExtendedQualifier2>()
+ {
+ };
+
+ ExtendedBean ext = getReference(ExtendedBean.class, e1, e2);
+ assert ext != null;
+
+ }
}
Deleted:
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/dependency/dependency-beans.xml
===================================================================
---
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/dependency/dependency-beans.xml 2010-03-04
17:57:27 UTC (rev 12097)
+++
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/dependency/dependency-beans.xml 2010-03-05
03:44:36 UTC (rev 12098)
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<Beans xmlns="urn:seam:core"
- xmlns:test="urn:java:org.jboss.seam.xml.test.dependency">
- <veto>
- <test:AdvancedTimer/>
- </veto>
-
- <test:AdvancedTimer>
- <Specializes/>
-
<depends>com.advanced.timer.server.that.is.not.on.the.ClassPath</depends>
- </test:AdvancedTimer>
-
-</Beans>
\ No newline at end of file
Modified:
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 2010-03-04
17:57:27 UTC (rev 12097)
+++
modules/xml/trunk/src/test/resources/org/jboss/seam/xml/test/simple/simple-beans.xml 2010-03-05
03:44:36 UTC (rev 12098)
@@ -24,5 +24,14 @@
</test:produceBean3>
</test:Bean2>
+ <test:OverriddenBean>
+ <override/>
+ <Named>someBean</Named>
+ </test:OverriddenBean>
+
+ <test:ExtendedBean>
+ <extends/>
+ <test:ExtendedQualifier2/>
+ </test:ExtendedBean>
</Beans>
\ No newline at end of file