Author: swd847
Date: 2010-07-25 04:15:58 -0400 (Sun, 25 Jul 2010)
New Revision: 13499
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanFieldValue.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanIdCreator.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanQualifier.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Horse.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/HorseShoe.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/InlineBeanFieldValueBeanTest.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Knight.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Sword.java
modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/inline-bean-field-value-beans.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/core/BeanResult.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResultType.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/XmlResult.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/FieldValueObject.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InjectionTargetWrapper.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AnnotationUtils.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.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/EntryXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldValueXmlItem.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/MethodXmlItem.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/ValueXmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/XmlItem.java
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/TypeOccuranceInformation.java
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java
Log:
inital attempt an inline beans, needs cleanup
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-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -66,6 +66,7 @@
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.core.Veto;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -112,9 +113,9 @@
{
log.info("Reading XML file: " + d.getFileUrl());
ParserMain parser = new ParserMain();
- ModelBuilder builder = new ModelBuilder();
+ ModelBuilder builder = new ModelBuilder(d.getFileUrl());
SaxNode parentNode = parser.parse(d.getInputSource(), d.getFileUrl(),
errors);
- results.add(builder.build(parentNode, d.getFileUrl()));
+ results.add(builder.build(parentNode, beanManager));
}
}
catch (Exception e)
@@ -150,14 +151,17 @@
errors.add(new RuntimeException(i));
}
}
- for (BeanResult<?> b : r.getFieldValues().keySet())
+ for (BeanResult<?> b : r.getFlattenedBeans())
{
- 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);
+ if (!b.getFieldValues().isEmpty())
+ {
+ int val = count++;
+ fieldValues.put(val, b.getFieldValues());
+ 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<? extends Annotation> b : r.getInterceptorBindings())
@@ -170,7 +174,7 @@
log.info("Adding XML Defined Stereotype: " +
b.getKey().getName());
event.addStereotype(b.getKey(), b.getValue());
}
- for (BeanResult<?> bb : r.getBeans())
+ for (BeanResult<?> bb : r.getFlattenedBeans())
{
GenericBeanResult found = null;
for (Class<?> g : genericBeans.keySet())
@@ -230,18 +234,6 @@
List<FieldValueObject> fvs = fieldValues.get(xid.value());
event.setInjectionTarget(new
InjectionTargetWrapper<T>(event.getInjectionTarget(), fvs));
}
- for (XmlResult r : results)
- {
- for (Entry<Class<?>, List<FieldValueObject>> e :
r.getInterfaceFieldValues().entrySet())
- {
- if (e.getKey().isAssignableFrom(event.getAnnotatedType().getJavaClass()))
- {
- log.info("Wrapping InjectionTarget to set field values based on
interface " + e.getKey().getName() + ": " +
event.getAnnotatedType().getJavaClass().getName());
- List<FieldValueObject> fvs = e.getValue();
- event.setInjectionTarget(new
InjectionTargetWrapper<T>(event.getInjectionTarget(), fvs));
- }
- }
- }
}
public void processAfterBeanDeployment(@Observes AfterBeanDiscovery event)
@@ -317,9 +309,11 @@
AnnotatedType<?> type = c.getBuilder().create();
AnnotatedTypeBuilder<?> gb = AnnotatedTypeBuilder.newInstance(type);
- if (c.getBeanType() == BeanResultType.SPECIALISE)
+ if (c.getBeanType() == BeanResultType.MODIFIES)
{
gb.readAnnotationsFromUnderlyingType();
+ // we don't want to keep the veto annotation on the class
+ gb.removeFromClass(Veto.class);
}
// if the original type was qualified @Default we add that as well
if (!isQualifierPresent(type, beanManager))
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResult.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -21,25 +21,42 @@
*/
package org.jboss.seam.xml.core;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.jboss.seam.xml.fieldset.FieldValueObject;
import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
+import org.jboss.weld.extensions.core.Veto;
public class BeanResult<X>
{
- final AnnotatedTypeBuilder<X> builder;
- final Class<X> type;
- final BeanResultType beanType;
+ private final AnnotatedTypeBuilder<X> builder;
+ private final Class<X> type;
+ private final BeanResultType beanType;
+ private final List<FieldValueObject> fieldValues;
+ private final List<BeanResult<?>> inlineBeans;
- public BeanResult(Class<X> type, boolean readAnnotations, BeanResultType
beanType)
+ public BeanResult(Class<X> type, boolean readAnnotations, BeanResultType
beanType, List<FieldValueObject> fieldValues, List<BeanResult<?>>
inlineBeans)
{
this.type = type;
builder = AnnotatedTypeBuilder.newInstance(type);
if (readAnnotations)
{
builder.readAnnotationsFromUnderlyingType();
+ // we don't want to keep the veto annotation on the class
+ builder.removeFromClass(Veto.class);
}
this.beanType = beanType;
+ this.fieldValues = new ArrayList<FieldValueObject>(fieldValues);
+ this.inlineBeans = new ArrayList<BeanResult<?>>(inlineBeans);
}
+ public List<BeanResult<?>> getInlineBeans()
+ {
+ return inlineBeans;
+ }
+
public AnnotatedTypeBuilder<X> getBuilder()
{
return builder;
@@ -55,4 +72,9 @@
return beanType;
}
+ public List<FieldValueObject> getFieldValues()
+ {
+ return Collections.unmodifiableList(fieldValues);
+ }
+
}
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResultType.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResultType.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/BeanResultType.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -23,5 +23,5 @@
public enum BeanResultType
{
- ADD, OVERRIDE, SPECIALISE;
+ ADD, REPLACES, MODIFIES;
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/XmlResult.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/XmlResult.java 2010-07-25
04:43:53 UTC (rev 13498)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/core/XmlResult.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -27,8 +27,6 @@
import java.util.List;
import java.util.Map;
-import org.jboss.seam.xml.fieldset.FieldValueObject;
-
/**
* Stores the result of parsing an XML document
*
@@ -52,10 +50,6 @@
private final List<GenericBeanResult> genericBeans = new
ArrayList<GenericBeanResult>();
- private final Map<BeanResult<?>, List<FieldValueObject>> fieldValues
= new HashMap<BeanResult<?>, List<FieldValueObject>>();
-
- private final Map<Class<?>, List<FieldValueObject>>
interfaceFieldValues = new HashMap<Class<?>, List<FieldValueObject>>();
-
private final String sortKey;
public XmlResult(String fileUrl)
@@ -108,24 +102,38 @@
return beans;
}
- public List<String> getProblems()
+ /**
+ * Gets all beans from the result, including inline beans
+ *
+ * @return
+ */
+ public List<BeanResult<?>> getFlattenedBeans()
{
- return problems;
+ List<BeanResult<?>> results = new
ArrayList<BeanResult<?>>();
+ for (BeanResult<?> a : beans)
+ {
+ getFlattenedBeans(a, results);
+ }
+ return results;
}
- public void addProblem(String p)
+ private void getFlattenedBeans(BeanResult<?> r, List<BeanResult<?>>
results)
{
- problems.add(p);
+ results.add(r);
+ for (BeanResult<?> a : r.getInlineBeans())
+ {
+ getFlattenedBeans(a, results);
+ }
}
- public void addFieldValue(BeanResult<?> res, List<FieldValueObject> list)
+ public List<String> getProblems()
{
- fieldValues.put(res, list);
+ return problems;
}
- public Map<BeanResult<?>, List<FieldValueObject>> getFieldValues()
+ public void addProblem(String p)
{
- return fieldValues;
+ problems.add(p);
}
public void addVeto(Class<?> clazz)
@@ -138,16 +146,6 @@
return veto;
}
- public void addInterfaceFieldValues(Class<?> clazz, List<FieldValueObject>
values)
- {
- interfaceFieldValues.put(clazz, values);
- }
-
- public Map<Class<?>, List<FieldValueObject>>
getInterfaceFieldValues()
- {
- return interfaceFieldValues;
- }
-
public void addGenericBean(GenericBeanResult result)
{
genericBeans.add(result);
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/ArrayFieldSet.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -25,6 +25,9 @@
import java.util.ArrayList;
import java.util.List;
+import javax.enterprise.context.spi.CreationalContext;
+
+import org.jboss.seam.xml.model.ValueXmlItem;
import org.jboss.seam.xml.model.XmlItem;
import org.jboss.seam.xml.util.XmlObjectConverter;
@@ -40,7 +43,7 @@
final private List<AFS> values;
final private Class arrayType;
- public ArrayFieldSet(FieldValueSetter field, List<XmlItem> items)
+ public ArrayFieldSet(FieldValueSetter field, List<ValueXmlItem> items)
{
this.field = field;
this.values = new ArrayList<AFS>();
@@ -144,7 +147,7 @@
}
- public void setValue(Object instance)
+ public void setValue(Object instance, CreationalContext<?> ctx)
{
try
{
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/CollectionFieldSet.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -33,6 +33,9 @@
import java.util.SortedSet;
import java.util.TreeSet;
+import javax.enterprise.context.spi.CreationalContext;
+
+import org.jboss.seam.xml.model.ValueXmlItem;
import org.jboss.seam.xml.model.XmlItem;
import org.jboss.seam.xml.util.TypeReader;
import org.jboss.seam.xml.util.XmlObjectConverter;
@@ -53,7 +56,7 @@
private final Class<?> elementType;
private final Class<? extends Collection> collectionType;
- public CollectionFieldSet(FieldValueSetter field, List<XmlItem> items)
+ public CollectionFieldSet(FieldValueSetter field, List<ValueXmlItem> items)
{
this.field = field;
this.values = new ArrayList<CFS>();
@@ -128,7 +131,7 @@
}
- public void setValue(Object instance)
+ public void setValue(Object instance, CreationalContext<?> ctx)
{
try
{
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/FieldValueObject.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/FieldValueObject.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/FieldValueObject.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -21,6 +21,8 @@
*/
package org.jboss.seam.xml.fieldset;
+import javax.enterprise.context.spi.CreationalContext;
+
/**
* FieldValueObjects set field values for a given instance
*
@@ -29,7 +31,6 @@
*/
public interface FieldValueObject
{
+ public void setValue(Object instance, CreationalContext<?> ctx);
- public void setValue(Object instance);
-
}
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InjectionTargetWrapper.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InjectionTargetWrapper.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InjectionTargetWrapper.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -43,7 +43,7 @@
{
for (FieldValueObject f : fieldValues)
{
- f.setValue(instance);
+ f.setValue(instance, ctx);
}
target.inject(instance, ctx);
}
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanFieldValue.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanFieldValue.java
(rev 0)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanFieldValue.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -0,0 +1,75 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.seam.xml.fieldset;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+/**
+ * Field value object for an inline bean definition
+ *
+ * @author Stuart Douglas
+ *
+ */
+public class InlineBeanFieldValue implements FieldValueObject
+{
+
+ private final FieldValueSetter field;
+
+ private final int beanId;
+
+ private final Class<?> type;
+
+ private final InlineBeanQualifier.InlineBeanQualifierLiteral literal;
+
+ private final BeanManager manager;
+
+ private Bean<?> bean;
+
+ public InlineBeanFieldValue(Class<?> type, int syntheticBeanQualifierNo,
FieldValueSetter setter, BeanManager manager)
+ {
+ this.beanId = syntheticBeanQualifierNo;
+ this.field = setter;
+ this.type = type;
+ this.literal = new InlineBeanQualifier.InlineBeanQualifierLiteral(beanId);
+ this.manager = manager;
+ }
+
+ public void setValue(Object instance, CreationalContext<?> ctx)
+ {
+ if (bean == null)
+ {
+ bean = manager.resolve(manager.getBeans(type, literal));
+ }
+ Object obj = manager.getReference(bean, type, ctx);
+ try
+ {
+ field.set(instance, obj);
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+}
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanIdCreator.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanIdCreator.java
(rev 0)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanIdCreator.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -0,0 +1,11 @@
+package org.jboss.seam.xml.fieldset;
+
+public class InlineBeanIdCreator
+{
+ static int count = 0;
+
+ public static int getId()
+ {
+ return count++;
+ }
+}
Added:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanQualifier.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanQualifier.java
(rev 0)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/InlineBeanQualifier.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -0,0 +1,61 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.seam.xml.fieldset;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Qualifier;
+
+/**
+ * Internal qualifier used for inline beans
+ *
+ * @author Stuart Douglas
+ *
+ */
+@Qualifier
+(a)Retention(RetentionPolicy.RUNTIME)
+@Target( { ElementType.TYPE, ElementType.FIELD, ElementType.METHOD })
+public @interface InlineBeanQualifier
+{
+ int value();
+
+ static class InlineBeanQualifierLiteral extends
AnnotationLiteral<InlineBeanQualifier> implements InlineBeanQualifier
+ {
+ private final int value;
+
+ public InlineBeanQualifierLiteral(int value)
+ {
+ this.value = value;
+ }
+
+ public int value()
+ {
+ return value;
+ }
+
+ }
+
+}
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/MapFieldSet.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -31,6 +31,8 @@
import java.util.SortedMap;
import java.util.TreeMap;
+import javax.enterprise.context.spi.CreationalContext;
+
import org.jboss.seam.xml.model.EntryXmlItem;
import org.jboss.seam.xml.util.TypeReader;
import org.jboss.seam.xml.util.XmlObjectConverter;
@@ -117,7 +119,7 @@
}
- public void setValue(Object instance)
+ public void setValue(Object instance, CreationalContext<?> ctx)
{
try
{
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-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/fieldset/SimpleFieldValue.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -23,6 +23,10 @@
import java.lang.reflect.InvocationTargetException;
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.seam.xml.model.ModelBuilder;
import org.jboss.seam.xml.util.XmlObjectConverter;
public class SimpleFieldValue implements FieldValueObject
@@ -144,7 +148,7 @@
void set(Object o) throws IllegalAccessException, InvocationTargetException;
}
- public void setValue(Object instance)
+ public void setValue(Object instance, CreationalContext<?> ctx)
{
try
{
@@ -156,4 +160,10 @@
}
}
+ public void initalize(ModelBuilder modelBuilder, BeanManager manager)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
}
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AbstractXmlItem.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -27,6 +27,8 @@
import java.util.List;
import java.util.Map;
+import javax.enterprise.inject.spi.BeanManager;
+
public abstract class AbstractXmlItem implements XmlItem
{
protected final XmlItemType type;
@@ -57,7 +59,7 @@
}
else
{
- this.attributes = attributes;
+ this.attributes = new HashMap<String, String>(attributes);
}
this.lineno = lineno;
this.document = document;
@@ -100,7 +102,7 @@
return javaClass;
}
- public boolean resolveChildren()
+ public boolean resolveChildren(BeanManager manager)
{
return true;
}
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AnnotationUtils.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AnnotationUtils.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AnnotationUtils.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -1,3 +1,26 @@
+/*
+ * JBoss, Home of Professional Opimport java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.jboss.seam.xml.util.XmlConfigurationException;
+import org.jboss.seam.xml.util.XmlObjectConverter;
+import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
+ublished 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.model;
import java.lang.annotation.Annotation;
@@ -10,6 +33,11 @@
import org.jboss.seam.xml.util.XmlObjectConverter;
import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
+/**
+ *
+ * @author Stuart Douglas
+ *
+ */
class AnnotationUtils
{
final private static AnnotationInstanceProvider annotationInstanceProvider = new
AnnotationInstanceProvider();
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/AnnotationXmlItem.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -38,7 +38,7 @@
{
if (!innerText.trim().equals(""))
{
- attributes.put("value", innerText);
+ this.attributes.put("value", innerText);
}
}
allowed.add(TypeOccuranceInformation.of(XmlItemType.ANNOTATION, null, null));
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ArrayXmlItem.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -25,6 +25,8 @@
import java.util.List;
import java.util.Map;
+import javax.enterprise.inject.spi.BeanManager;
+
import org.jboss.seam.xml.util.XmlConfigurationException;
public class ArrayXmlItem extends ParameterXmlItem
@@ -50,7 +52,7 @@
}
}
- public boolean resolveChildren()
+ public boolean resolveChildren(BeanManager manager)
{
List<ClassXmlItem> classXmlItems = getChildrenOfType(ClassXmlItem.class);
if (classXmlItems.isEmpty())
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-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ClassXmlItem.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -32,11 +32,13 @@
import java.util.Set;
import java.util.Map.Entry;
+import javax.enterprise.inject.spi.BeanManager;
import javax.enterprise.util.AnnotationLiteral;
import javax.inject.Inject;
import org.jboss.seam.xml.core.BeanResult;
import org.jboss.seam.xml.core.BeanResultType;
+import org.jboss.seam.xml.fieldset.FieldValueObject;
import org.jboss.seam.xml.util.TypeOccuranceInformation;
import org.jboss.seam.xml.util.XmlConfigurationException;
import org.jboss.weld.extensions.annotated.AnnotatedTypeBuilder;
@@ -99,7 +101,7 @@
return values;
}
- public BeanResult<?> createBeanResult()
+ public BeanResult<?> createBeanResult(BeanManager manager)
{
boolean override = !getChildrenOfType(ReplacesXmlItem.class).isEmpty();
boolean extend = !getChildrenOfType(ModifiesXmlItem.class).isEmpty();
@@ -110,16 +112,39 @@
}
if (override)
{
- beanType = BeanResultType.OVERRIDE;
+ beanType = BeanResultType.REPLACES;
}
else if (extend)
{
- beanType = BeanResultType.SPECIALISE;
+ beanType = BeanResultType.MODIFIES;
}
+ List<BeanResult> inlineBeans = new ArrayList<BeanResult>();
+ // get all the field values from the bean
+ Set<String> configuredFields = new HashSet<String>();
+ List<FieldValueObject> fields = new ArrayList<FieldValueObject>();
+ for (FieldValueXmlItem xi : getChildrenOfType(FieldValueXmlItem.class))
+ {
+ inlineBeans.addAll(xi.getInlineBeans());
+ FieldValueObject f = xi.getFieldValue();
+ if (f != null)
+ {
+ fields.add(f);
+ configuredFields.add(xi.getFieldName());
+ }
+ }
+ for (FieldValueXmlItem f : getShorthandFieldValues())
+ {
+ if (configuredFields.contains(f.getFieldName()))
+ {
+ throw new XmlConfigurationException("Field configured in two places:
" + getJavaClass().getName() + "." + f.getFieldName(), getDocument(),
getLineno());
+ }
+ fields.add(f.getFieldValue());
+ }
+
// if it is an extend we want to read the annotations from the underlying
// class
- BeanResult<?> result = new BeanResult(getJavaClass(), extend, beanType);
+ BeanResult<?> result = new BeanResult(getJavaClass(), extend, beanType,
fields, inlineBeans);
AnnotatedTypeBuilder<?> type = result.getBuilder();
// list of constructor arguments
List<ParameterXmlItem> constList = new ArrayList<ParameterXmlItem>();
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/EntryXmlItem.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -24,6 +24,8 @@
import java.util.HashSet;
import java.util.Set;
+import javax.enterprise.inject.spi.BeanManager;
+
import org.jboss.seam.xml.util.TypeOccuranceInformation;
import org.jboss.seam.xml.util.XmlConfigurationException;
@@ -48,7 +50,7 @@
}
@Override
- public boolean resolveChildren()
+ public boolean resolveChildren(BeanManager manager)
{
if (children.size() != 2)
{
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldValueXmlItem.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldValueXmlItem.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldValueXmlItem.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -21,6 +21,9 @@
*/
package org.jboss.seam.xml.model;
+import java.util.Collection;
+
+import org.jboss.seam.xml.core.BeanResult;
import org.jboss.seam.xml.fieldset.FieldValueObject;
public interface FieldValueXmlItem
@@ -28,4 +31,6 @@
public FieldValueObject getFieldValue();
public String getFieldName();
+
+ public Collection<? extends BeanResult> getInlineBeans();
}
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-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/FieldXmlItem.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -30,11 +30,15 @@
import java.util.Map;
import java.util.Set;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.seam.xml.core.BeanResult;
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.InlineBeanFieldValue;
import org.jboss.seam.xml.fieldset.MapFieldSet;
import org.jboss.seam.xml.fieldset.MethodFieldSetter;
import org.jboss.seam.xml.fieldset.SimpleFieldValue;
@@ -48,6 +52,7 @@
FieldValueObject fieldValue;
Field field;
HashSet<TypeOccuranceInformation> allowed = new
HashSet<TypeOccuranceInformation>();
+ List<BeanResult<?>> inlineBeans = new
ArrayList<BeanResult<?>>();
public FieldXmlItem(XmlItem parent, Field c, String innerText, String document, int
lineno)
{
@@ -74,17 +79,17 @@
}
@Override
- public boolean resolveChildren()
+ public boolean resolveChildren(BeanManager manager)
{
List<EntryXmlItem> mapEntries = new ArrayList<EntryXmlItem>();
- List<XmlItem> valueEntries = new ArrayList<XmlItem>();
+ List<ValueXmlItem> valueEntries = new ArrayList<ValueXmlItem>();
if (fieldValue == null)
{
for (XmlItem i : children)
{
if (i.getType() == XmlItemType.VALUE)
{
- valueEntries.add(i);
+ valueEntries.add((ValueXmlItem) i);
}
else if (i.getType() == XmlItemType.ENTRY)
{
@@ -134,7 +139,17 @@
{
throw new XmlConfigurationException("Non collection fields can only
have a single <value> element Field:" + field.getDeclaringClass().getName() +
'.' + field.getName(), getDocument(), getLineno());
}
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), fieldSetter,
valueEntries.get(0).getInnerText());
+ ValueXmlItem value = valueEntries.get(0);
+ BeanResult<?> result = value.getBeanResult(manager);
+ if (result == null)
+ {
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), fieldSetter,
valueEntries.get(0).getInnerText());
+ }
+ else
+ {
+ inlineBeans.add(result);
+ fieldValue = new InlineBeanFieldValue(field.getType(),
value.getSyntheticQualifierId(), fieldSetter, manager);
+ }
}
}
return true;
@@ -173,4 +188,9 @@
{
return field.getName();
}
+
+ public Collection<? extends BeanResult> getInlineBeans()
+ {
+ return inlineBeans;
+ }
}
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/MethodXmlItem.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/MethodXmlItem.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/MethodXmlItem.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -27,6 +27,8 @@
import java.util.List;
import java.util.Set;
+import javax.enterprise.inject.spi.BeanManager;
+
import org.jboss.seam.xml.util.TypeOccuranceInformation;
import org.jboss.seam.xml.util.XmlConfigurationException;
@@ -74,7 +76,7 @@
* @param childeren
* @return
*/
- public boolean resolveChildren()
+ public boolean resolveChildren(BeanManager manager)
{
// return true if this is not a method or there was only
// only method to choose from
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-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -22,7 +22,6 @@
package org.jboss.seam.xml.model;
import java.lang.annotation.Annotation;
-import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
@@ -30,6 +29,7 @@
import java.util.Set;
import javax.enterprise.inject.Stereotype;
+import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Qualifier;
import javax.interceptor.InterceptorBinding;
@@ -37,7 +37,6 @@
import org.jboss.seam.xml.core.BeanResultType;
import org.jboss.seam.xml.core.GenericBeanResult;
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.CompositeNamespaceElementResolver;
import org.jboss.seam.xml.parser.namespace.NamespaceElementResolver;
@@ -58,16 +57,20 @@
static final String BEANS_ROOT_NAMESPACE =
"http://java.sun.com/xml/ns/javaee";
+ private final XmlResult ret;
+
+ public ModelBuilder(String fileUrl)
+ {
+ ret = new XmlResult(fileUrl);
+ }
+
/**
* builds an XML result from a parsed xml document
*/
- public XmlResult build(SaxNode root, String fileUrl)
+ public XmlResult build(SaxNode root, BeanManager manager)
{
-
Map<String, NamespaceElementResolver> resolvers = new HashMap<String,
NamespaceElementResolver>();
- XmlResult ret = new XmlResult(fileUrl);
-
if (!root.getName().equals("beans"))
{
throw new XmlConfigurationException("Wrong root element for XML config
file, expected:<beans> found:" + root.getName(), root.getDocument(),
root.getLineNo());
@@ -92,9 +95,12 @@
{
continue;
}
- XmlItem rb = resolveNode(node, null, resolvers);
+ XmlItem rb = resolveNode(node, null, resolvers, manager);
// validateXmlItem(rb);
- addNodeToResult(ret, rb);
+ if (rb != null)
+ {
+ addNodeToResult(rb, manager);
+ }
}
}
catch (Exception e)
@@ -108,7 +114,7 @@
}
@SuppressWarnings("unchecked")
- private void addNodeToResult(XmlResult ret, XmlItem xmlItem)
+ public void addNodeToResult(XmlItem xmlItem, BeanManager manager)
{
validateXmlItem(xmlItem);
if (xmlItem.getType() == XmlItemType.CLASS || xmlItem.getType() ==
XmlItemType.ANNOTATION)
@@ -119,46 +125,14 @@
{
ClassXmlItem cxml = (ClassXmlItem) xmlItem;
// get the AnnotatedType information
- BeanResult<?> beanResult = cxml.createBeanResult();
+ BeanResult<?> beanResult = cxml.createBeanResult(manager);
ret.addBean(beanResult);
// <override> or <speciailizes> need to veto the bean
if (beanResult.getBeanType() != BeanResultType.ADD)
{
ret.addVeto(beanResult.getType());
}
- // get all the field values from the bean
- Set<String> configuredFields = new HashSet<String>();
- List<FieldValueObject> fields = new
ArrayList<FieldValueObject>();
- for (FieldValueXmlItem xi : cxml.getChildrenOfType(FieldValueXmlItem.class))
- {
- FieldValueObject f = xi.getFieldValue();
- if (f != null)
- {
- fields.add(f);
- configuredFields.add(xi.getFieldName());
- }
- }
- for (FieldValueXmlItem f : cxml.getShorthandFieldValues())
- {
- if (configuredFields.contains(f.getFieldName()))
- {
- throw new XmlConfigurationException("Field configured in two
places: " + cxml.getJavaClass().getName() + "." + f.getFieldName(),
cxml.getDocument(), cxml.getLineno());
- }
- fields.add(f.getFieldValue());
- }
-
- if (!fields.isEmpty())
- {
- if (xmlItem.getJavaClass().isInterface())
- {
- ret.addInterfaceFieldValues(beanResult.getType(), fields);
- }
- else
- {
- ret.addFieldValue(beanResult, fields);
- }
- }
}
else if (resultType == ResultType.QUALIFIER)
{
@@ -180,7 +154,7 @@
Set<BeanResult<?>> classes = new
HashSet<BeanResult<?>>();
for (ClassXmlItem c : xmlItem.getChildrenOfType(ClassXmlItem.class))
{
- BeanResult<?> br = c.createBeanResult();
+ BeanResult<?> br = c.createBeanResult(manager);
if (br.getBeanType() != BeanResultType.ADD)
{
ret.addVeto(br.getType());
@@ -194,10 +168,13 @@
/**
* resolves the appropriate java elements from the xml
*/
- protected XmlItem resolveNode(SaxNode node, XmlItem parent, Map<String,
NamespaceElementResolver> resolvers)
+ protected XmlItem resolveNode(SaxNode node, XmlItem parent, Map<String,
NamespaceElementResolver> resolvers, BeanManager manager)
{
NamespaceElementResolver resolver = resolveNamepsace(node.getNamespaceUri(),
resolvers);
-
+ if (resolver == null)
+ {
+ return null;
+ }
XmlItem ret = resolver.getItemForNamespace(node, parent);
if (ret == null)
@@ -209,11 +186,11 @@
{
if (n.getNamespaceUri() != null)
{
- XmlItem rb = resolveNode(n, ret, resolvers);
+ XmlItem rb = resolveNode(n, ret, resolvers, manager);
ret.addChild(rb);
}
}
- ret.resolveChildren();
+ ret.resolveChildren(manager);
return ret;
}
@@ -224,6 +201,10 @@
{
return resolvers.get(namespaceURI);
}
+ if (!namespaceURI.startsWith("urn:java:"))
+ {
+ return null;
+ }
String ns = namespaceURI.replaceFirst("urn:java:", "");
CompositeNamespaceElementResolver res = new
CompositeNamespaceElementResolver(ns.split(":"));
resolvers.put(namespaceURI, res);
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-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/PropertyXmlItem.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -29,10 +29,14 @@
import java.util.Map;
import java.util.Set;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.seam.xml.core.BeanResult;
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.FieldValueSetter;
+import org.jboss.seam.xml.fieldset.InlineBeanFieldValue;
import org.jboss.seam.xml.fieldset.MapFieldSet;
import org.jboss.seam.xml.fieldset.MethodFieldSetter;
import org.jboss.seam.xml.fieldset.SimpleFieldValue;
@@ -47,6 +51,7 @@
String name;
Class<?> type;
HashSet<TypeOccuranceInformation> allowed = new
HashSet<TypeOccuranceInformation>();
+ List<BeanResult<?>> inlineBeans = new
ArrayList<BeanResult<?>>();
public PropertyXmlItem(XmlItem parent, String name, Method setter, String innerText,
String document, int lineno)
{
@@ -68,17 +73,17 @@
}
@Override
- public boolean resolveChildren()
+ public boolean resolveChildren(BeanManager manager)
{
List<EntryXmlItem> mapEntries = new ArrayList<EntryXmlItem>();
- List<XmlItem> valueEntries = new ArrayList<XmlItem>();
+ List<ValueXmlItem> valueEntries = new ArrayList<ValueXmlItem>();
if (fieldValue == null)
{
for (XmlItem i : children)
{
if (i.getType() == XmlItemType.VALUE)
{
- valueEntries.add(i);
+ valueEntries.add((ValueXmlItem) i);
}
else if (i.getType() == XmlItemType.ENTRY)
{
@@ -128,7 +133,17 @@
{
throw new XmlConfigurationException("Non collection fields can only
have a single <value> element Field:" + parent.getJavaClass().getName() +
'.' + name, getDocument(), getLineno());
}
- fieldValue = new SimpleFieldValue(parent.getJavaClass(), fieldSetter,
valueEntries.get(0).getInnerText());
+ ValueXmlItem value = valueEntries.get(0);
+ BeanResult<?> result = value.getBeanResult(manager);
+ if (result == null)
+ {
+ fieldValue = new SimpleFieldValue(parent.getJavaClass(), fieldSetter,
valueEntries.get(0).getInnerText());
+ }
+ else
+ {
+ inlineBeans.add(result);
+ fieldValue = new InlineBeanFieldValue(type,
value.getSyntheticQualifierId(), fieldSetter, manager);
+ }
}
}
return true;
@@ -144,4 +159,8 @@
return name;
}
+ public Collection<? extends BeanResult> getInlineBeans()
+ {
+ return inlineBeans;
+ }
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/ValueXmlItem.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -22,12 +22,20 @@
package org.jboss.seam.xml.model;
import java.util.Collections;
+import java.util.List;
import java.util.Set;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.seam.xml.core.BeanResult;
+import org.jboss.seam.xml.fieldset.InlineBeanIdCreator;
+import org.jboss.seam.xml.fieldset.InlineBeanQualifier;
import org.jboss.seam.xml.util.TypeOccuranceInformation;
+import org.jboss.seam.xml.util.XmlConfigurationException;
public class ValueXmlItem extends AbstractXmlItem
{
+ int syntheticQualifierId;
public ValueXmlItem(XmlItem parent, String innerText, String document, int lineno)
{
@@ -39,4 +47,29 @@
return Collections.singleton(TypeOccuranceInformation.of(XmlItemType.CLASS, null,
1));
}
+ public BeanResult<?> getBeanResult(BeanManager manager)
+ {
+ List<ClassXmlItem> inlineBeans = getChildrenOfType(ClassXmlItem.class);
+ if (!inlineBeans.isEmpty())
+ {
+ ClassXmlItem inline = inlineBeans.get(0);
+ for (AnnotationXmlItem i : inline.getChildrenOfType(AnnotationXmlItem.class))
+ {
+ if (manager.isQualifier((Class) i.getJavaClass()))
+ {
+ throw new XmlConfigurationException("Cannot define qualifiers on
inline beans", i.getDocument(), i.getLineno());
+ }
+ }
+ syntheticQualifierId = InlineBeanIdCreator.getId();
+ AnnotationXmlItem syntheticQualifier = new AnnotationXmlItem(this,
InlineBeanQualifier.class, "" + syntheticQualifierId, Collections.EMPTY_MAP,
getDocument(), getLineno());
+ inline.addChild(syntheticQualifier);
+ return inline.createBeanResult(manager);
+ }
+ return null;
+ }
+
+ public int getSyntheticQualifierId()
+ {
+ return syntheticQualifierId;
+ }
}
Modified: modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/XmlItem.java
===================================================================
--- modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/XmlItem.java 2010-07-25
04:43:53 UTC (rev 13498)
+++ modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/model/XmlItem.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -24,6 +24,8 @@
import java.util.List;
import java.util.Set;
+import javax.enterprise.inject.spi.BeanManager;
+
import org.jboss.seam.xml.util.TypeOccuranceInformation;
public interface XmlItem
@@ -47,7 +49,7 @@
* @param childeren
* @return
*/
- public boolean resolveChildren();
+ public boolean resolveChildren(BeanManager manager);
public Set<TypeOccuranceInformation> getAllowedItem();
Modified:
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/TypeOccuranceInformation.java
===================================================================
---
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/TypeOccuranceInformation.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/main/java/org/jboss/seam/xml/util/TypeOccuranceInformation.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -1,3 +1,24 @@
+/*
+ * 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.util;
import java.util.Set;
Modified:
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java
===================================================================
---
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java 2010-07-25
04:43:53 UTC (rev 13498)
+++
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/NamespaceResolverTest.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -67,7 +67,7 @@
XmlItem method = resolver.getItemForNamespace(new SaxNode("method1",
null, null, null, null, 0), item);
Assert.assertTrue("Item returned wrong type", method.getType() ==
XmlItemType.METHOD);
- method.resolveChildren();
+ method.resolveChildren(null);
Assert.assertTrue("Could not resolve method", ((MethodXmlItem)
method).getMethod() != null);
Assert.assertTrue("Wrong method was resolved", ((MethodXmlItem)
method).getMethod().getParameterTypes().length == 0);
Added: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Horse.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Horse.java
(rev 0)
+++
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Horse.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -0,0 +1,48 @@
+/*
+ * 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.fieldset;
+
+public class Horse
+{
+ private HorseShoe shoe;
+ private String name;
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(String name)
+ {
+ this.name = name;
+ }
+
+ public HorseShoe getShoe()
+ {
+ return shoe;
+ }
+
+ public void setShoe(HorseShoe shoe)
+ {
+ this.shoe = shoe;
+ }
+}
Added:
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/HorseShoe.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/HorseShoe.java
(rev 0)
+++
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/HorseShoe.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -0,0 +1,27 @@
+/*
+ * 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.fieldset;
+
+public class HorseShoe
+{
+
+}
Added:
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/InlineBeanFieldValueBeanTest.java
===================================================================
---
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/InlineBeanFieldValueBeanTest.java
(rev 0)
+++
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/InlineBeanFieldValueBeanTest.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.seam.xml.test.fieldset;
+
+import junit.framework.Assert;
+
+import org.jboss.seam.xml.test.AbstractXMLTest;
+import org.junit.Test;
+
+public class InlineBeanFieldValueBeanTest extends AbstractXMLTest
+{
+
+ @Override
+ protected String getXmlFileName()
+ {
+ return "inline-bean-field-value-beans.xml";
+ }
+
+ @Test
+ public void simpleInlineBeanTest()
+ {
+ Knight knight = getReference(Knight.class,
org.jboss.weld.literal.DefaultLiteral.INSTANCE);
+ Assert.assertTrue(knight.getSword().getType().equals("sharp"));
+ Assert.assertTrue(knight.getHorse().getShoe() != null);
+ Assert.assertTrue(knight.getHorse().getName().equals("billy"));
+ }
+
+}
Added: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Knight.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Knight.java
(rev 0)
+++
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Knight.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -0,0 +1,52 @@
+/*
+ * 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.fieldset;
+
+import org.jboss.weld.extensions.core.Veto;
+
+@Veto
+public class Knight
+{
+ Sword sword;
+
+ Horse horse;
+
+ public Sword getSword()
+ {
+ return sword;
+ }
+
+ public void setSword(Sword sword)
+ {
+ this.sword = sword;
+ }
+
+ public Horse getHorse()
+ {
+ return horse;
+ }
+
+ public void setHorse(Horse horse)
+ {
+ this.horse = horse;
+ }
+}
Added: modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Sword.java
===================================================================
--- modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Sword.java
(rev 0)
+++
modules/xml/trunk/impl/src/test/java/org/jboss/seam/xml/test/fieldset/Sword.java 2010-07-25
08:15:58 UTC (rev 13499)
@@ -0,0 +1,38 @@
+/*
+ * 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.fieldset;
+
+public class Sword
+{
+ String type;
+
+ public String getType()
+ {
+ return type;
+ }
+
+ public void setType(String type)
+ {
+ this.type = type;
+ }
+
+}
Added:
modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/inline-bean-field-value-beans.xml
===================================================================
---
modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/inline-bean-field-value-beans.xml
(rev 0)
+++
modules/xml/trunk/impl/src/test/resources/org/jboss/seam/xml/test/fieldset/inline-bean-field-value-beans.xml 2010-07-25
08:15:58 UTC (rev 13499)
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<beans xmlns="urn:java:ee"
+ xmlns:test="urn:java:org.jboss.seam.xml.test.fieldset">
+
+ <test:Knight>
+
+ <test:sword>
+ <value>
+ <test:Sword type="sharp"/>
+ </value>
+ </test:sword>
+
+ <test:horse>
+ <value>
+ <test:Horse>
+ <test:name>
+ <value>billy</value>
+ </test:name>
+ <test:shoe>
+ <Inject/>
+ </test:shoe>
+ </test:Horse>
+ </value>
+ </test:horse>
+
+ </test:Knight>
+
+</beans>
\ No newline at end of file