[seam-commits] Seam SVN: r13661 - in modules/xml/trunk/impl/src: main/java/org/jboss/seam/xml/core and 7 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri Aug 27 21:45:25 EDT 2010
Author: swd847
Date: 2010-08-27 21:45:24 -0400 (Fri, 27 Aug 2010)
New Revision: 13661
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/VirtualProducerField.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/virtualproducer/
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/virtualproducer/VirtualProducerFieldTest.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/virtualproducer/VirtualProducerQualifier.java
modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/virtualproducer/
modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/virtualproducer/virtualproducer.xml
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ResultType.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
Log:
virtual producer fields, still needs more work
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java 2010-08-28 00:25:27 UTC (rev 13660)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -36,10 +36,6 @@
import javax.enterprise.event.Observes;
import javax.enterprise.inject.spi.AfterBeanDiscovery;
import javax.enterprise.inject.spi.Annotated;
-import javax.enterprise.inject.spi.AnnotatedConstructor;
-import javax.enterprise.inject.spi.AnnotatedField;
-import javax.enterprise.inject.spi.AnnotatedMethod;
-import javax.enterprise.inject.spi.AnnotatedParameter;
import javax.enterprise.inject.spi.AnnotatedType;
import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.inject.spi.BeforeBeanDiscovery;
@@ -59,8 +55,6 @@
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.annotated.AnnotatedTypeBuilder;
-import org.jboss.weld.extensions.core.Exact;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -166,7 +160,7 @@
bb.getBuilder().addToClass(new AnnotationLiteral<XmlConfiguredBean>()
{
});
- AnnotatedType<?> tp = fixExactSupport(bb.getBuilder()).create();
+ AnnotatedType<?> tp = bb.getBuilder().create();
log.info("Adding XML Defined Bean: " + tp.getJavaClass().getName());
event.addAnnotatedType(tp);
}
@@ -267,48 +261,4 @@
return false;
}
- /**
- * temprary hack to support @Exact in seam-xml, remove once WELD-485 is
- * resolved
- */
- public <X> AnnotatedTypeBuilder<X> fixExactSupport(AnnotatedTypeBuilder<X> old)
- {
- AnnotatedType<X> pat = old.create();
- AnnotatedTypeBuilder<X> builder = new AnnotatedTypeBuilder<X>().readFromType(pat);
- // support for @Exact
- // fields
- for (AnnotatedField<? super X> f : pat.getFields())
- {
- if (f.isAnnotationPresent(Exact.class))
- {
- Class<?> type = f.getAnnotation(Exact.class).value();
- builder.overrideFieldType(f.getJavaMember(), type);
- }
- }
- // method parameters
- for (AnnotatedMethod<? super X> m : pat.getMethods())
- {
- for (AnnotatedParameter<? super X> p : m.getParameters())
- {
- if (p.isAnnotationPresent(Exact.class))
- {
- Class<?> type = p.getAnnotation(Exact.class).value();
- builder.overrideMethodParameterType(m.getJavaMember(), p.getPosition(), type);
- }
- }
- }
- // constructor parameters
- for (AnnotatedConstructor<X> c : pat.getConstructors())
- {
- for (AnnotatedParameter<? super X> p : c.getParameters())
- {
- if (p.isAnnotationPresent(Exact.class))
- {
- Class<?> type = p.getAnnotation(Exact.class).value();
- builder.overrideConstructorParameterType(c.getJavaMember(), p.getPosition(), type);
- }
- }
- }
- return builder;
- }
}
Added: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/VirtualProducerField.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/VirtualProducerField.java (rev 0)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/VirtualProducerField.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.xml.core;
+
+/**
+ * This class used to reigister virtual producer fields
+ *
+ * @author stuart
+ *
+ */
+public class VirtualProducerField
+{
+ public Object field;
+}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java 2010-08-28 00:25:27 UTC (rev 13660)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -39,17 +39,20 @@
private final FieldValue value;
- public SimpleFieldValue(Class<?> javaObject, final Property f, FieldValue value)
+ private final Class<?> type;
+
+ public SimpleFieldValue(Class<?> javaObject, final Property<?> f, FieldValue value, Class<?> type)
{
this.field = f;
this.value = value;
+ this.type = type == null ? field.getJavaClass() : type;
}
public void setValue(Object instance, CreationalContext<?> ctx, BeanManager manager)
{
try
{
- field.setValue(instance, value.value(field.getJavaClass(), ctx, manager));
+ field.setValue(instance, value.value(type, ctx, manager));
}
catch (Exception e)
{
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java 2010-08-28 00:25:27 UTC (rev 13660)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractFieldXmlItem.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -49,14 +49,16 @@
public abstract class AbstractFieldXmlItem extends AbstractXmlItem
{
- protected Property property;
+ protected Property<?> property;
protected FieldValueObject fieldValue;
protected HashSet<TypeOccuranceInformation> allowed = new HashSet<TypeOccuranceInformation>();
+ private final Class<?> overridenFieldType;
List<BeanResult<?>> inlineBeans = new ArrayList<BeanResult<?>>();
- public AbstractFieldXmlItem(XmlItemType type, XmlItem parent, Class<?> javaClass, String innerText, Map<String, String> attributes, String document, int lineno)
+ public AbstractFieldXmlItem(XmlItemType type, XmlItem parent, Class<?> javaClass, String innerText, Map<String, String> attributes, Class<?> overridenFieldType, String document, int lineno)
{
super(type, parent, javaClass, innerText, attributes, document, lineno);
+ this.overridenFieldType = overridenFieldType;
}
public FieldValueObject getFieldValue()
@@ -143,7 +145,7 @@
}
ValueXmlItem value = valueEntries.get(0);
BeanResult<?> result = value.getBeanResult(manager);
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, value.getValue());
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, value.getValue(), overridenFieldType);
if (result != null)
{
inlineBeans.add(result);
@@ -169,4 +171,9 @@
return inlineBeans;
}
+ public Class<?> getOverridenFieldType()
+ {
+ return overridenFieldType;
+ }
+
}
\ No newline at end of file
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java 2010-08-28 00:25:27 UTC (rev 13660)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -26,6 +26,7 @@
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -38,6 +39,7 @@
import org.jboss.seam.xml.core.BeanResult;
import org.jboss.seam.xml.core.BeanResultType;
+import org.jboss.seam.xml.core.VirtualProducerField;
import org.jboss.seam.xml.fieldset.FieldValueObject;
import org.jboss.seam.xml.util.TypeOccuranceInformation;
import org.jboss.seam.xml.util.XmlConfigurationException;
@@ -58,6 +60,8 @@
allowed.add(TypeOccuranceInformation.of(XmlItemType.PARAMETERS, null, null));
allowed.add(TypeOccuranceInformation.of(XmlItemType.REPLACE, null, null));
allowed.add(TypeOccuranceInformation.of(XmlItemType.MODIFIES, null, null));
+ allowed.add(TypeOccuranceInformation.of(XmlItemType.VALUE, null, null));
+ allowed.add(TypeOccuranceInformation.of(XmlItemType.ENTRY, null, null));
}
public Set<TypeOccuranceInformation> getAllowedItem()
@@ -74,7 +78,7 @@
Field field = Reflections.findDeclaredField(getJavaClass(), e.getKey());
if (field != null)
{
- values.add(new FieldXmlItem(this, field, e.getValue(), document, lineno));
+ values.add(new FieldXmlItem(this, field, e.getValue(), null, document, lineno));
}
else
{
@@ -224,6 +228,39 @@
return result;
}
+ public BeanResult<?> createVirtualFieldBeanResult(BeanManager manager)
+ {
+ boolean override = !getChildrenOfType(ReplacesXmlItem.class).isEmpty();
+ boolean extend = !getChildrenOfType(ModifiesXmlItem.class).isEmpty();
+ Field member;
+ try
+ {
+ member = VirtualProducerField.class.getField("field");
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ BeanResultType beanType = BeanResultType.ADD;
+ if (override || extend)
+ {
+ throw new XmlConfigurationException("A virtual producer field may not containe <override> or <extend> tags", getDocument(), getLineno());
+ }
+ ClassXmlItem vclass = new ClassXmlItem(null, VirtualProducerField.class, Collections.EMPTY_MAP, document, lineno);
+ FieldXmlItem field = new FieldXmlItem(vclass, member, null, getJavaClass(), document, lineno);
+ vclass.addChild(field);
+ for (XmlItem i : this.getChildren())
+ {
+ field.addChild(i);
+ }
+ field.resolveChildren(manager);
+ BeanResult<?> result = vclass.createBeanResult(manager);
+ AnnotatedTypeBuilder<?> builder = result.getBuilder();
+ builder.overrideFieldType(member, this.getJavaClass());
+ return result;
+ }
+
private Constructor<?> resolveConstructor(List<ParameterXmlItem> constList)
{
Class<?>[] params = new Class[constList.size()];
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java 2010-08-28 00:25:27 UTC (rev 13660)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -37,9 +37,9 @@
private final Field field;
- public FieldXmlItem(XmlItem parent, Field c, String innerText, String document, int lineno)
+ public FieldXmlItem(XmlItem parent, Field c, String innerText, Class<?> overridenFieldType, String document, int lineno)
{
- super(XmlItemType.FIELD, parent, parent.getJavaClass(), innerText, null, document, lineno);
+ super(XmlItemType.FIELD, parent, parent.getJavaClass(), innerText, null, overridenFieldType, document, lineno);
this.field = c;
this.property = getFieldValueSetter(c);
@@ -54,7 +54,7 @@
{
fv = new ConstantFieldValue(innerText);
}
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, fv);
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, fv, overridenFieldType);
}
allowed.add(TypeOccuranceInformation.of(XmlItemType.ANNOTATION, null, null));
allowed.add(TypeOccuranceInformation.of(XmlItemType.VALUE, null, null));
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-08-28 00:25:27 UTC (rev 13660)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Set;
+import javax.enterprise.inject.Produces;
import javax.enterprise.inject.Stereotype;
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Qualifier;
@@ -133,8 +134,19 @@
{
ret.addVeto(beanResult.getType());
}
-
}
+ else if (resultType == ResultType.VIRTUAL_PRODUCER)
+ {
+ ClassXmlItem cxml = (ClassXmlItem) xmlItem;
+ // get the AnnotatedType information
+ BeanResult<?> beanResult = cxml.createVirtualFieldBeanResult(manager);
+ ret.addBean(beanResult);
+ // <override> or <speciailizes> need to veto the bean
+ if (beanResult.getBeanType() != BeanResultType.ADD)
+ {
+ ret.addVeto(beanResult.getType());
+ }
+ }
else if (resultType == ResultType.QUALIFIER)
{
ret.addQualifier((Class) xmlItem.getJavaClass());
@@ -228,6 +240,17 @@
ret = ResultType.QUALIFIER;
}
}
+ else if (it.getJavaClass() == Produces.class)
+ {
+ if (ret != null)
+ {
+ throw new XmlConfigurationException("Element cannot be both an virtual producer field and a " + ret.toString(), item.getDocument(), item.getLineno());
+ }
+ else
+ {
+ ret = ResultType.VIRTUAL_PRODUCER;
+ }
+ }
else if (it.getJavaClass() == Stereotype.class)
{
if (ret != null)
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java 2010-08-28 00:25:27 UTC (rev 13660)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -39,7 +39,7 @@
public PropertyXmlItem(XmlItem parent, String name, Method setter, String innerText, String document, int lineno)
{
- super(XmlItemType.FIELD, parent, parent.getJavaClass(), innerText, null, document, lineno);
+ super(XmlItemType.FIELD, parent, parent.getJavaClass(), innerText, null, null, document, lineno);
this.name = name;
this.type = setter.getParameterTypes()[0];
this.declaringClass = setter.getDeclaringClass();
@@ -55,7 +55,7 @@
{
fv = new ConstantFieldValue(innerText);
}
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, fv);
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), property, fv, null);
}
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ResultType.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ResultType.java 2010-08-28 00:25:27 UTC (rev 13660)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ResultType.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -23,5 +23,5 @@
public enum ResultType
{
- BEAN, INTERCEPTOR_BINDING, STEREOTYPE, QUALIFIER, VETO;
+ BEAN, INTERCEPTOR_BINDING, STEREOTYPE, QUALIFIER, VIRTUAL_PRODUCER;
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java 2010-08-28 00:25:27 UTC (rev 13660)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -135,7 +135,7 @@
}
else if (f != null)
{
- return new FieldXmlItem(parent, f, innerText, document, lineno);
+ return new FieldXmlItem(parent, f, innerText, null, document, lineno);
}
String methodName = "set" + Character.toUpperCase(name.charAt(0)) + name.substring(1);
Added: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/virtualproducer/VirtualProducerFieldTest.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/virtualproducer/VirtualProducerFieldTest.java (rev 0)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/virtualproducer/VirtualProducerFieldTest.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.seam.xml.test.virtualproducer;
+
+import javax.enterprise.util.AnnotationLiteral;
+
+import junit.framework.Assert;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.junit.Test;
+
+public class VirtualProducerFieldTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "virtualproducer.xml";
+ }
+
+ @Test
+ public void testSimpleVirtualProducerField()
+ {
+ String value = getReference(String.class, new AnnotationLiteral<VirtualProducerQualifier>()
+ {
+ });
+ Assert.assertEquals("Hello World", value);
+
+ }
+}
Added: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/virtualproducer/VirtualProducerQualifier.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/virtualproducer/VirtualProducerQualifier.java (rev 0)
+++ modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/virtualproducer/VirtualProducerQualifier.java 2010-08-28 01:45:24 UTC (rev 13661)
@@ -0,0 +1,16 @@
+package org.jboss.seam.xml.test.virtualproducer;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.inject.Qualifier;
+
+ at Retention(RetentionPolicy.RUNTIME)
+ at Target(value = { ElementType.FIELD, ElementType.METHOD, ElementType.TYPE })
+ at Qualifier
+public @interface VirtualProducerQualifier
+{
+
+}
Added: modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/virtualproducer/virtualproducer.xml
===================================================================
--- modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/virtualproducer/virtualproducer.xml (rev 0)
+++ modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/virtualproducer/virtualproducer.xml 2010-08-28 01:45:24 UTC (rev 13661)
@@ -0,0 +1,11 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="urn:java:ee"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.virtualproducer">
+
+ <String>
+ <Produces/>
+ <test:VirtualProducerQualifier/>
+ <value>Hello World</value>
+ </String>
+
+</beans>
\ No newline at end of file
More information about the seam-commits
mailing list