Author: swd847
Date: 2010-03-06 17:58:32 -0500 (Sat, 06 Mar 2010)
New Revision: 12113
Added:
modules/xml/trunk/core/
modules/xml/trunk/core/pom.xml
modules/xml/trunk/core/src/
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/BeanResult.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/XmlResult.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
Removed:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/BeanResult.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/XmlResult.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/util/ReflectionUtils.java
modules/xml/trunk/pom.xml
modules/xml/trunk/src/
Modified:
modules/xml/trunk/examples/princess-rescue/pom.xml
Log:
changed structure of seam-xml
Copied: modules/xml/trunk/core/pom.xml (from rev 12110, modules/xml/trunk/pom.xml)
===================================================================
--- modules/xml/trunk/core/pom.xml (rev 0)
+++ modules/xml/trunk/core/pom.xml 2010-03-06 22:58:32 UTC (rev 12113)
@@ -0,0 +1,105 @@
+<?xml version="1.0"?>
+<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <artifactId>seam-parent</artifactId>
+ <groupId>org.jboss.seam</groupId>
+ <version>3.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>seam-xml-core</artifactId>
+ <packaging>jar</packaging>
+ <version>3.0.0-SNAPSHOT</version>
+ <name>Seam XML Extension Core</name>
+
+ <repositories>
+ <repository>
+ <
id>oss.sonatype.org/jboss-snapshots</id>
+ <name>JBoss (Nexus) Snapshots Repository</name>
+
<
url>http://oss.sonatype.org/content/repositories/jboss-snapshots</u...
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ <updatePolicy>never</updatePolicy>
+ </snapshots>
+ </repository>
+ </repositories>
+
+ <properties>
+ <seam.version>3.0.0-SNAPSHOT</seam.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>javax.enterprise</groupId>
+ <artifactId>cdi-api</artifactId>
+ <version>1.0-SP1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-core</artifactId>
+ <version>1.0.1-Final</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-extensions-core</artifactId>
+ <version>1.0.1-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.jboss.weld</groupId>
+ <artifactId>weld-se</artifactId>
+ <version>1.0.1-Final</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.testng</groupId>
+ <artifactId>testng</artifactId>
+ <version>5.10</version>
+ <type>jar</type>
+ <classifier>jdk15</classifier>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <scm>
+
<
connection>scm:svn:http://anonsvn.jboss.org/repos/seam/modules/xml/tru...
+
<
developerConnection>scm:svn:https://svn.jboss.org/repos/seam/modules/x...
+ <
url>http://fisheye.jboss.org/browse/Seam/modules/xml/trunk/core</ur...
+ </scm>
+
+ <build>
+
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <configuration>
+ <source>1.5</source>
+ <target>1.5</target>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-eclipse-plugin</artifactId>
+ <configuration>
+ <workspace>${basedir}</workspace>
+
+ <downloadJavadocs>true</downloadJavadocs>
+ <downloadSources>true</downloadSources>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <forkMode>once</forkMode>
+ <argLine>-Xmx512m</argLine>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
Copied: modules/xml/trunk/core/src (from rev 12110, modules/xml/trunk/src)
Deleted:
modules/xml/trunk/core/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-06
21:42:25 UTC (rev 12110)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java 2010-03-06
22:58:32 UTC (rev 12113)
@@ -1,210 +0,0 @@
-/*
- * Distributed under the LGPL License
- *
- */
-package org.jboss.seam.xml.bootstrap;
-
-import java.lang.annotation.Annotation;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import javax.enterprise.event.Observes;
-import javax.enterprise.inject.spi.AfterBeanDiscovery;
-import javax.enterprise.inject.spi.AnnotatedType;
-import javax.enterprise.inject.spi.BeforeBeanDiscovery;
-import javax.enterprise.inject.spi.Extension;
-import javax.enterprise.inject.spi.ProcessAnnotatedType;
-import javax.enterprise.inject.spi.ProcessInjectionTarget;
-
-import org.jboss.seam.xml.core.BeanResult;
-import org.jboss.seam.xml.core.XmlId;
-import org.jboss.seam.xml.core.XmlResult;
-import org.jboss.seam.xml.fieldset.FieldValueObject;
-import org.jboss.seam.xml.fieldset.InjectionTargetWrapper;
-import org.jboss.seam.xml.model.ModelBuilder;
-import org.jboss.seam.xml.parser.ParserMain;
-import org.jboss.seam.xml.parser.SaxNode;
-import org.jboss.seam.xml.util.FileDataReader;
-import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
-import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
-
-public class XmlExtension implements Extension
-{
-
- AnnotationInstanceProvider ac = new AnnotationInstanceProvider();
-
- static final String PROVIDERS_FILE =
"META-INF/services/org.jboss.seam.xml.XmlExtension";
-
- List<XmlResult> results = new ArrayList<XmlResult>();
-
- Set<Class<?>> veto = new HashSet<Class<?>>();
-
- Map<Class<?>, AnnotatedType<?>> types = new
HashMap<Class<?>, AnnotatedType<?>>();
-
- Map<Class<?>, BeanResult<?>> beanExtensions = new
HashMap<Class<?>, BeanResult<?>>();
-
- int count = 0;
-
- /**
- * map of syntetic bean id to a list of field value objects
- */
- Map<Integer, List<FieldValueObject>> fieldValues = new HashMap<Integer,
List<FieldValueObject>>();
-
- List<Exception> errors = new ArrayList<Exception>();
-
- /**
- * This is the entry point for the extension
- */
- public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event)
- {
- List<Class<? extends XmlDocumentProvider>> providers =
getDocumentProviders();
- for (Class<? extends XmlDocumentProvider> cl : providers)
- {
- try
- {
- XmlDocumentProvider provider = cl.newInstance();
- provider.open();
- XmlDocument d;
- while ((d = provider.getNextDocument()) != null)
- {
- ParserMain parser = new ParserMain();
- ModelBuilder builder = new ModelBuilder();
- SaxNode parentNode = parser.parse(d.getInputSource(), d.getFileUrl(),
errors);
- results.add(builder.build(parentNode));
- }
- }
- catch (Exception e)
- {
- errors.add(e);
- }
- }
-
- for (XmlResult r : results)
- {
- if (!r.getProblems().isEmpty())
- {
-
- for (String i : r.getProblems())
- {
- errors.add(new RuntimeException(i));
- }
- }
- for (BeanResult<?> b : r.getFieldValues().keySet())
- {
- int val = count++;
- fieldValues.put(val, r.getFieldValues().get(b));
- Map<String, Object> am = new HashMap<String, Object>();
- am.put("value", val);
- Annotation a = ac.get(XmlId.class, am);
- b.getBuilder().addToClass(a);
- }
-
- for (Class<? extends Annotation> b : r.getQualifiers())
- {
- event.addQualifier(b);
- }
- for (Class<? extends Annotation> b : r.getInterceptorBindings())
- {
- event.addInterceptorBinding(b);
- }
- for (Entry<Class<? extends Annotation>, Annotation[]> b :
r.getStereotypes().entrySet())
- {
- event.addStereotype(b.getKey(), b.getValue());
- }
- for (BeanResult<?> bb : r.getBeans())
- {
- 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());
-
- }
- }
-
- public <T> void processAnotated(@Observes ProcessAnnotatedType<T> event)
- {
- // veto implementation
- if (veto.contains(event.getAnnotatedType().getJavaClass()))
- {
- 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)
- {
-
- AnnotatedType<T> at = event.getAnnotatedType();
- XmlId xid = at.getAnnotation(XmlId.class);
- if (xid != null)
- {
- List<FieldValueObject> fvs = fieldValues.get(xid.value());
- event.setInjectionTarget(new
InjectionTargetWrapper<T>(event.getInjectionTarget(), fvs));
- }
-
- }
-
- public void processAfterBeanDeployment(@Observes AfterBeanDiscovery event)
- {
- for (Exception t : errors)
- {
- event.addDefinitionError(t);
- }
- }
-
- public List<Class<? extends XmlDocumentProvider>> getDocumentProviders()
- {
- List<Class<? extends XmlDocumentProvider>> ret = new
ArrayList<Class<? extends XmlDocumentProvider>>();
- try
- {
- Enumeration<URL> urls =
getClass().getClassLoader().getResources(PROVIDERS_FILE);
- while (urls.hasMoreElements())
- {
-
- URL u = urls.nextElement();
- String data = FileDataReader.readUrl(u);
- String[] providers = data.split("\\s");
- for (String provider : providers)
- {
- Class res = null;
- try
- {
- res = getClass().getClassLoader().loadClass(provider);
- }
- catch (ClassNotFoundException e)
- {
- res =
Thread.currentThread().getContextClassLoader().loadClass(provider);
- }
- if (res == null)
- {
- throw new RuntimeException("Could not load XML configuration
provider " + provider + " configured in file " + u.toString());
- }
- ret.add(res);
- }
- }
- }
- catch (Exception e)
- {
- throw new RuntimeException(e);
- }
- return ret;
- }
-}
Copied:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java (from
rev 12111,
modules/xml/trunk/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java)
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java
(rev 0)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/bootstrap/XmlExtension.java 2010-03-06
22:58:32 UTC (rev 12113)
@@ -0,0 +1,198 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.bootstrap;
+
+import java.lang.annotation.Annotation;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Enumeration;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.AfterBeanDiscovery;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessAnnotatedType;
+import javax.enterprise.inject.spi.ProcessInjectionTarget;
+
+import org.jboss.seam.xml.core.BeanResult;
+import org.jboss.seam.xml.core.XmlId;
+import org.jboss.seam.xml.core.XmlResult;
+import org.jboss.seam.xml.fieldset.FieldValueObject;
+import org.jboss.seam.xml.fieldset.InjectionTargetWrapper;
+import org.jboss.seam.xml.model.ModelBuilder;
+import org.jboss.seam.xml.parser.ParserMain;
+import org.jboss.seam.xml.parser.SaxNode;
+import org.jboss.seam.xml.util.FileDataReader;
+import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
+
+public class XmlExtension implements Extension
+{
+
+ AnnotationInstanceProvider ac = new AnnotationInstanceProvider();
+
+ static final String PROVIDERS_FILE =
"META-INF/services/org.jboss.seam.xml.XmlExtension";
+
+ List<XmlResult> results = new ArrayList<XmlResult>();
+
+ Set<Class<?>> veto = new HashSet<Class<?>>();
+
+ Map<Class<?>, AnnotatedType<?>> types = new
HashMap<Class<?>, AnnotatedType<?>>();
+
+ int count = 0;
+
+ /**
+ * map of syntetic bean id to a list of field value objects
+ */
+ Map<Integer, List<FieldValueObject>> fieldValues = new HashMap<Integer,
List<FieldValueObject>>();
+
+ List<Exception> errors = new ArrayList<Exception>();
+
+ /**
+ * This is the entry point for the extension
+ */
+ public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event)
+ {
+ List<Class<? extends XmlDocumentProvider>> providers =
getDocumentProviders();
+ for (Class<? extends XmlDocumentProvider> cl : providers)
+ {
+ try
+ {
+ XmlDocumentProvider provider = cl.newInstance();
+ provider.open();
+ XmlDocument d;
+ while ((d = provider.getNextDocument()) != null)
+ {
+ ParserMain parser = new ParserMain();
+ ModelBuilder builder = new ModelBuilder();
+ SaxNode parentNode = parser.parse(d.getInputSource(), d.getFileUrl(),
errors);
+ results.add(builder.build(parentNode));
+ }
+ }
+ catch (Exception e)
+ {
+ errors.add(e);
+ }
+ }
+
+ for (XmlResult r : results)
+ {
+ if (!r.getProblems().isEmpty())
+ {
+
+ for (String i : r.getProblems())
+ {
+ errors.add(new RuntimeException(i));
+ }
+ }
+ for (BeanResult<?> b : r.getFieldValues().keySet())
+ {
+ int val = count++;
+ fieldValues.put(val, r.getFieldValues().get(b));
+ Map<String, Object> am = new HashMap<String, Object>();
+ am.put("value", val);
+ Annotation a = ac.get(XmlId.class, am);
+ b.getBuilder().addToClass(a);
+ }
+
+ for (Class<? extends Annotation> b : r.getQualifiers())
+ {
+ event.addQualifier(b);
+ }
+ for (Class<? extends Annotation> b : r.getInterceptorBindings())
+ {
+ event.addInterceptorBinding(b);
+ }
+ for (Entry<Class<? extends Annotation>, Annotation[]> b :
r.getStereotypes().entrySet())
+ {
+ event.addStereotype(b.getKey(), b.getValue());
+ }
+ for (BeanResult<?> bb : r.getBeans())
+ {
+ AnnotatedType<?> tp = bb.getBuilder().create();
+ event.addAnnotatedType(tp);
+ types.put(tp.getJavaClass(), tp);
+ }
+
+ veto.addAll(r.getVeto());
+
+ }
+ }
+
+ public <T> void processAnotated(@Observes ProcessAnnotatedType<T> event)
+ {
+ // veto implementation
+ if (veto.contains(event.getAnnotatedType().getJavaClass()))
+ {
+ event.veto();
+ }
+
+ }
+
+ public <T> void processInjectionTarget(@Observes ProcessInjectionTarget<T>
event)
+ {
+
+ AnnotatedType<T> at = event.getAnnotatedType();
+ XmlId xid = at.getAnnotation(XmlId.class);
+ if (xid != null)
+ {
+ List<FieldValueObject> fvs = fieldValues.get(xid.value());
+ event.setInjectionTarget(new
InjectionTargetWrapper<T>(event.getInjectionTarget(), fvs));
+ }
+
+ }
+
+ public void processAfterBeanDeployment(@Observes AfterBeanDiscovery event)
+ {
+ for (Exception t : errors)
+ {
+ event.addDefinitionError(t);
+ }
+ }
+
+ public List<Class<? extends XmlDocumentProvider>> getDocumentProviders()
+ {
+ List<Class<? extends XmlDocumentProvider>> ret = new
ArrayList<Class<? extends XmlDocumentProvider>>();
+ try
+ {
+ Enumeration<URL> urls =
getClass().getClassLoader().getResources(PROVIDERS_FILE);
+ while (urls.hasMoreElements())
+ {
+
+ URL u = urls.nextElement();
+ String data = FileDataReader.readUrl(u);
+ String[] providers = data.split("\\s");
+ for (String provider : providers)
+ {
+ Class res = null;
+ try
+ {
+ res = getClass().getClassLoader().loadClass(provider);
+ }
+ catch (ClassNotFoundException e)
+ {
+ res =
Thread.currentThread().getContextClassLoader().loadClass(provider);
+ }
+ if (res == null)
+ {
+ throw new RuntimeException("Could not load XML configuration
provider " + provider + " configured in file " + u.toString());
+ }
+ ret.add(res);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException(e);
+ }
+ return ret;
+ }
+}
Deleted: modules/xml/trunk/core/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-06
21:42:25 UTC (rev 12110)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/BeanResult.java 2010-03-06
22:58:32 UTC (rev 12113)
@@ -1,50 +0,0 @@
-/*
- * Distributed under the LGPL License
- *
- */
-package org.jboss.seam.xml.core;
-
-import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
-
-public class BeanResult<X>
-{
- NewAnnotatedTypeBuilder<X> builder;
- Class<X> type;
- boolean override, extend;
-
- public BeanResult(Class<X> type)
- {
- this.type = type;
- builder = new NewAnnotatedTypeBuilder<X>(type);
- }
-
- public NewAnnotatedTypeBuilder<X> getBuilder()
- {
- return builder;
- }
-
- public Class<X> getType()
- {
- return type;
- }
-
- public boolean isOverride()
- {
- return override;
- }
-
- public void setOverride(boolean override)
- {
- this.override = override;
- }
-
- public boolean isExtend()
- {
- return extend;
- }
-
- public void setExtend(boolean extend)
- {
- this.extend = extend;
- }
-}
Copied: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/BeanResult.java (from
rev 12111, modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/BeanResult.java)
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/BeanResult.java
(rev 0)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/BeanResult.java 2010-03-06
22:58:32 UTC (rev 12113)
@@ -0,0 +1,50 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.core;
+
+import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
+
+public class BeanResult<X>
+{
+ NewAnnotatedTypeBuilder<X> builder;
+ Class<X> type;
+ boolean override, extend;
+
+ public BeanResult(Class<X> type, boolean readAnnotations)
+ {
+ this.type = type;
+ builder = new NewAnnotatedTypeBuilder<X>(type, readAnnotations);
+ }
+
+ public NewAnnotatedTypeBuilder<X> getBuilder()
+ {
+ return builder;
+ }
+
+ public Class<X> getType()
+ {
+ return type;
+ }
+
+ public boolean isOverride()
+ {
+ return override;
+ }
+
+ public void setOverride(boolean override)
+ {
+ this.override = override;
+ }
+
+ public boolean isExtend()
+ {
+ return extend;
+ }
+
+ public void setExtend(boolean extend)
+ {
+ this.extend = extend;
+ }
+}
Deleted: modules/xml/trunk/core/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-06
21:42:25 UTC (rev 12110)
+++ modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/XmlResult.java 2010-03-06
22:58:32 UTC (rev 12113)
@@ -1,90 +0,0 @@
-/*
- * Distributed under the LGPL License
- *
- */
-package org.jboss.seam.xml.core;
-
-import java.lang.annotation.Annotation;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.jboss.seam.xml.fieldset.FieldValueObject;
-
-/**
- * Stores the result of parsing an XML document
- *
- * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
- *
- */
-public class XmlResult
-{
-
- Map<Class<? extends Annotation>, Annotation[]> stereotypes = new
HashMap<Class<? extends Annotation>, Annotation[]>();
-
- List<Class<? extends Annotation>> qualifiers = new ArrayList<Class<?
extends Annotation>>();
-
- List<Class<? extends Annotation>> interceptorBindings = new
ArrayList<Class<? extends Annotation>>();
-
- List<Class<?>> veto = new ArrayList<Class<?>>();
-
- List<String> problems = new ArrayList<String>();
-
- List<BeanResult<?>> beans = new ArrayList<BeanResult<?>>();
-
- List<BeanResult<?>> extendBeans = new
ArrayList<BeanResult<?>>();
-
- Map<BeanResult<?>, List<FieldValueObject>> fieldValues = new
HashMap<BeanResult<?>, List<FieldValueObject>>();
-
- public Map<Class<? extends Annotation>, Annotation[]> getStereotypes()
- {
- return stereotypes;
- }
-
- public List<Class<? extends Annotation>> getQualifiers()
- {
- return qualifiers;
- }
-
- public List<Class<? extends Annotation>> getInterceptorBindings()
- {
- return interceptorBindings;
- }
-
- public List<BeanResult<?>> getBeans()
- {
- return beans;
- }
-
- public List<String> getProblems()
- {
- return problems;
- }
-
- public void addProblem(String p)
- {
- problems.add(p);
- }
-
- public Map<BeanResult<?>, List<FieldValueObject>> getFieldValues()
- {
- return fieldValues;
- }
-
- public void addVeto(Class<?> clazz)
- {
- veto.add(clazz);
- }
-
- public List<Class<?>> getVeto()
- {
- return veto;
- }
-
- public List<BeanResult<?>> getExtendBeans()
- {
- return extendBeans;
- }
-
-}
Copied: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/XmlResult.java (from
rev 12111, modules/xml/trunk/src/main/java/org/jboss/seam/xml/core/XmlResult.java)
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/XmlResult.java
(rev 0)
+++ modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/core/XmlResult.java 2010-03-06
22:58:32 UTC (rev 12113)
@@ -0,0 +1,83 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.core;
+
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.jboss.seam.xml.fieldset.FieldValueObject;
+
+/**
+ * Stores the result of parsing an XML document
+ *
+ * @author Stuart Douglas <stuart(a)baileyroberts.com.au>
+ *
+ */
+public class XmlResult
+{
+
+ Map<Class<? extends Annotation>, Annotation[]> stereotypes = new
HashMap<Class<? extends Annotation>, Annotation[]>();
+
+ List<Class<? extends Annotation>> qualifiers = new ArrayList<Class<?
extends Annotation>>();
+
+ List<Class<? extends Annotation>> interceptorBindings = new
ArrayList<Class<? extends Annotation>>();
+
+ List<Class<?>> veto = new ArrayList<Class<?>>();
+
+ List<String> problems = new ArrayList<String>();
+
+ List<BeanResult<?>> beans = new ArrayList<BeanResult<?>>();
+
+ Map<BeanResult<?>, List<FieldValueObject>> fieldValues = new
HashMap<BeanResult<?>, List<FieldValueObject>>();
+
+ public Map<Class<? extends Annotation>, Annotation[]> getStereotypes()
+ {
+ return stereotypes;
+ }
+
+ public List<Class<? extends Annotation>> getQualifiers()
+ {
+ return qualifiers;
+ }
+
+ public List<Class<? extends Annotation>> getInterceptorBindings()
+ {
+ return interceptorBindings;
+ }
+
+ public List<BeanResult<?>> getBeans()
+ {
+ return beans;
+ }
+
+ public List<String> getProblems()
+ {
+ return problems;
+ }
+
+ public void addProblem(String p)
+ {
+ problems.add(p);
+ }
+
+ public Map<BeanResult<?>, List<FieldValueObject>> getFieldValues()
+ {
+ return fieldValues;
+ }
+
+ public void addVeto(Class<?> clazz)
+ {
+ veto.add(clazz);
+ }
+
+ public List<Class<?>> getVeto()
+ {
+ return veto;
+ }
+
+}
Deleted: modules/xml/trunk/core/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-06
21:42:25 UTC (rev 12110)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-03-06
22:58:32 UTC (rev 12113)
@@ -1,404 +0,0 @@
-/*
- * Distributed under the LGPL License
- *
- */
-package org.jboss.seam.xml.model;
-
-import java.lang.annotation.Annotation;
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import java.util.Map.Entry;
-
-import javax.enterprise.inject.Stereotype;
-import javax.enterprise.util.AnnotationLiteral;
-import javax.inject.Inject;
-import javax.inject.Qualifier;
-import javax.interceptor.InterceptorBinding;
-
-import org.jboss.seam.xml.core.BeanResult;
-import org.jboss.seam.xml.core.XmlResult;
-import org.jboss.seam.xml.fieldset.FieldValueObject;
-import org.jboss.seam.xml.parser.SaxNode;
-import org.jboss.seam.xml.parser.namespace.CompositeNamespaceElementResolver;
-import org.jboss.seam.xml.parser.namespace.NamespaceElementResolver;
-import org.jboss.seam.xml.parser.namespace.RootNamespaceElementResolver;
-import org.jboss.seam.xml.util.ReflectionUtils;
-import org.jboss.seam.xml.util.XmlConfigurationException;
-import org.jboss.seam.xml.util.XmlObjectConverter;
-import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
-import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
-
-/**
- * Builds an XML result from sax nodes
- *
- * @author stuart
- *
- */
-public class ModelBuilder
-{
-
- AnnotationInstanceProvider ac = new AnnotationInstanceProvider();
-
- static final String ROOT_NAMESPACE = "urn:seam:core";
-
- Map<String, NamespaceElementResolver> resolvers;
-
- public XmlResult build(SaxNode root)
- {
-
- resolvers = new HashMap<String, NamespaceElementResolver>();
-
- XmlResult ret = new XmlResult();
-
- if (!root.getName().equals("Beans"))
- {
- throw new XmlConfigurationException("Wrong root element for XML config
file, expected:<Beans> found:" + root.getName(), root.getDocument(),
root.getLineNo());
- }
- if (!ROOT_NAMESPACE.equals(root.getNamespaceUri()))
- {
- throw new XmlConfigurationException("Wrong root namespace for XML config
file, expected:" + ROOT_NAMESPACE + " found:" + root.getNamespaceUri(),
root.getDocument(), root.getLineNo());
- }
-
- resolvers.put(ROOT_NAMESPACE, new RootNamespaceElementResolver());
-
- List<SaxNode> children = root.getChildren();
- for (SaxNode node : children)
- {
- try
- {
- // nodes with a null namespace are whitespace nodes etc
- if (node.getNamespaceUri() != null)
- {
- XmlItem rb = resolveNode(node, null);
- // validateXmlItem(rb);
- addNodeToResult(ret, rb);
- }
- }
- catch (Exception e)
- {
- ret.addProblem(e.getMessage());
- e.printStackTrace();
- }
- }
-
- return ret;
- }
-
- @SuppressWarnings("unchecked")
- private void addNodeToResult(XmlResult ret, XmlItem rb)
- {
-
- if (rb.getType() == XmlItemType.CLASS || rb.getType() == XmlItemType.ANNOTATION)
- {
- ResultType type = getItemType(rb);
- if (type == ResultType.BEAN)
- {
- BeanResult<?> tp = buildAnnotatedType((ClassXmlItem) rb);
- 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))
- {
- FieldValueObject f = xi.getFieldValue();
- if (f != null)
- {
- fields.add(f);
- }
- }
- if (!fields.isEmpty())
- {
- ret.getFieldValues().put(tp, fields);
- }
- }
- else if (type == ResultType.QUALIFIER)
- {
- ret.getQualifiers().add((Class) rb.getJavaClass());
- }
- else if (type == ResultType.INTERCEPTOR_BINDING)
- {
- ret.getInterceptorBindings().add((Class) rb.getJavaClass());
- }
- else if (type == ResultType.STEREOTYPE)
- {
- addStereotypeToResult(ret, rb);
- }
- }
- else if (rb.getType() == XmlItemType.VETO)
- {
- for (XmlItem it : rb.getChildren())
- {
- ret.addVeto(it.getJavaClass());
- }
- }
- }
-
- protected XmlItem resolveNode(SaxNode node, XmlItem parent)
- {
- NamespaceElementResolver resolver = resolveNamepsace(node.getNamespaceUri());
-
- XmlItem ret = resolver.getItemForNamespace(node, parent);
-
- if (ret == null)
- {
- throw new XmlConfigurationException("Could not resolve node " +
node.getName() + " in namespace " + node.getNamespaceUri(), node.getDocument(),
node.getLineNo());
- }
- List<SaxNode> children = node.getChildren();
- for (SaxNode n : children)
- {
- if (n.getNamespaceUri() != null)
- {
- XmlItem rb = resolveNode(n, ret);
- ret.addChild(rb);
- }
- }
- ret.resolveChildren();
- return ret;
-
- }
-
- protected NamespaceElementResolver resolveNamepsace(String namespaceURI)
- {
- if (resolvers.containsKey(namespaceURI))
- {
- return resolvers.get(namespaceURI);
- }
- String ns = namespaceURI.replaceFirst("urn:java:", "");
- CompositeNamespaceElementResolver res = new
CompositeNamespaceElementResolver(ns.split(":"));
- resolvers.put(namespaceURI, res);
- return res;
- }
-
- /**
- * Determines the type of an element by examining its child nodes
- */
- protected ResultType getItemType(XmlItem item)
- {
-
- ResultType ret = null;
- for (AnnotationXmlItem it : item.getChildrenOfType(AnnotationXmlItem.class))
- {
- if (it.getJavaClass() == InterceptorBinding.class)
- {
- if (ret != null)
- {
- throw new XmlConfigurationException("Element cannot be both an
INTERCEPTOR_BINDING and a " + ret.toString(), item.getDocument(), item.getLineno());
- }
- else
- {
- ret = ResultType.INTERCEPTOR_BINDING;
- }
- }
- else if (it.getJavaClass() == Qualifier.class)
- {
- if (ret != null)
- {
- throw new XmlConfigurationException("Element cannot be both an
QUALIFIER and a " + ret.toString(), item.getDocument(), item.getLineno());
- }
- else
- {
- ret = ResultType.QUALIFIER;
- }
- }
- else if (it.getJavaClass() == Stereotype.class)
- {
- if (ret != null)
- {
- throw new XmlConfigurationException("Element cannot be both an
STEREOTYPE and a " + ret.toString(), item.getDocument(), item.getLineno());
- }
- else
- {
- ret = ResultType.STEREOTYPE;
- }
- }
- }
-
- if (ret == null)
- {
- ret = ResultType.BEAN;
- }
- return ret;
- }
-
- @SuppressWarnings("unchecked")
- BeanResult<?> buildAnnotatedType(ClassXmlItem rb)
- {
- BeanResult<?> result = new BeanResult(rb.getJavaClass());
- NewAnnotatedTypeBuilder<?> type = result.getBuilder();
- // list of constructor arguments
- List<ParameterXmlItem> constList = new ArrayList<ParameterXmlItem>();
-
- 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);
- type.addToClass(a);
- }
- List<ParametersXmlItem> constructorParameters =
rb.getChildrenOfType(ParametersXmlItem.class);
- if (constructorParameters.size() > 1)
- {
- throw new XmlConfigurationException("A method may only have a single
<parameters> element", rb.getDocument(), rb.getLineno());
- }
- else if (!constructorParameters.isEmpty())
- {
- for (ParameterXmlItem item :
constructorParameters.get(0).getChildrenOfType(ParameterXmlItem.class))
- {
- constList.add(item);
- }
- }
- for (FieldXmlItem item : rb.getChildrenOfType(FieldXmlItem.class))
- {
- for (AnnotationXmlItem fi : item.getChildrenOfType(AnnotationXmlItem.class))
- {
- Annotation a = createAnnotation(fi);
- type.addToField(item.getField(), a);
- }
- }
- for (MethodXmlItem item : rb.getChildrenOfType(MethodXmlItem.class))
- {
- int paramCount = 0;
-
- for (AnnotationXmlItem fi : item.getChildrenOfType(AnnotationXmlItem.class))
- {
- Annotation a = createAnnotation(fi);
- type.addToMethod(item.getMethod(), a);
- }
- List<ParametersXmlItem> parameters =
item.getChildrenOfType(ParametersXmlItem.class);
- if (parameters.size() > 1)
- {
- throw new XmlConfigurationException("A method may only have a single
<parameters> element", item.getDocument(), item.getLineno());
- }
- else if (!parameters.isEmpty())
- {
- for (ParameterXmlItem fi :
parameters.get(0).getChildrenOfType(ParameterXmlItem.class))
- {
- int param = paramCount++;
- for (AnnotationXmlItem pan :
fi.getChildrenOfType(AnnotationXmlItem.class))
- {
- Annotation a = createAnnotation(pan);
- type.addToMethodParameter(item.getMethod(), param, a);
- }
- }
- }
-
- }
-
- if (!constList.isEmpty())
- {
- int paramCount = 0;
- Constructor<?> c = resolveConstructor(rb, constList);
- // we automatically add inject to the constructor
- type.addToConstructor((Constructor) c, new AnnotationLiteral<Inject>()
- {
- });
- for (ParameterXmlItem fi : constList)
- {
- int param = paramCount++;
- for (AnnotationXmlItem pan : fi.getChildrenOfType(AnnotationXmlItem.class))
- {
- Annotation a = createAnnotation(pan);
- type.addToConstructorParameter((Constructor) c, param, a);
- }
- }
- }
- return result;
- }
-
- protected static Constructor<?> resolveConstructor(ClassXmlItem bean,
List<ParameterXmlItem> constList)
- {
- Class<?>[] params = new Class[constList.size()];
- for (int i = 0; i < constList.size(); ++i)
- {
- params[i] = constList.get(i).getJavaClass();
- }
- Constructor<?> ret = ReflectionUtils.getConstructor(bean.getJavaClass(),
params);
- if (ret == null)
- {
- throw new XmlConfigurationException("Could not resolve constructor for
" + bean.getJavaClass() + " with arguments " + params, bean.getDocument(),
bean.getLineno());
- }
- return ret;
- }
-
- @SuppressWarnings("unchecked")
- void addStereotypeToResult(XmlResult ret, XmlItem rb)
- {
-
- Annotation[] values = new Annotation[rb.getChildren().size()];
- int count = 0;
- for (XmlItem item : rb.getChildren())
- {
- if (item.getType() == XmlItemType.ANNOTATION)
- {
- Annotation a = createAnnotation((AnnotationXmlItem) item);
- values[count] = a;
- }
- else
- {
- throw new XmlConfigurationException("Setereotype " +
rb.getJavaClass() + " has an item that does not represent an annotation in its XML
configurations", rb.getDocument(), rb.getLineno());
- }
- count++;
- }
- ret.getStereotypes().put((Class) rb.getJavaClass(), values);
-
- }
-
- @SuppressWarnings("unchecked")
- Annotation createAnnotation(AnnotationXmlItem item)
- {
- Map<String, Object> typedVars = new HashMap<String, Object>();
- Class<?> anClass = item.getJavaClass();
- for (Entry<String, String> e : item.getAttributes().entrySet())
- {
- String mname = e.getKey();
- Method m;
- try
- {
- m = anClass.getDeclaredMethod(mname);
- }
- catch (Exception e1)
- {
- throw new XmlConfigurationException("Annotation " +
item.getJavaClass().getName() + " does not have a member named " + mname +
" ,error in XML", item.getDocument(), item.getLineno());
- }
- Class<?> returnType = m.getReturnType();
- typedVars.put(mname, XmlObjectConverter.convert(returnType, e.getValue()));
- }
-
- return ac.get((Class) item.getJavaClass(), typedVars);
- }
-
- public void validateXmlItem(XmlItem item)
- {
- Set<XmlItemType> allowed = item.getAllowedItem();
- for (XmlItem i : item.getChildren())
- {
- if (!allowed.contains(item.getType()))
- {
- throw new XmlConfigurationException("Item " + item.getType() +
" is not allowed to contain " + i.getType(), item.getDocument(),
item.getLineno());
- }
- validateXmlItem(i);
- }
- }
-
-}
Copied: modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
(from rev 12111,
modules/xml/trunk/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java)
===================================================================
--- modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java
(rev 0)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/model/ModelBuilder.java 2010-03-06
22:58:32 UTC (rev 12113)
@@ -0,0 +1,400 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.model;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
+
+import javax.enterprise.inject.Stereotype;
+import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Inject;
+import javax.inject.Qualifier;
+import javax.interceptor.InterceptorBinding;
+
+import org.jboss.seam.xml.core.BeanResult;
+import org.jboss.seam.xml.core.XmlResult;
+import org.jboss.seam.xml.fieldset.FieldValueObject;
+import org.jboss.seam.xml.parser.SaxNode;
+import org.jboss.seam.xml.parser.namespace.CompositeNamespaceElementResolver;
+import org.jboss.seam.xml.parser.namespace.NamespaceElementResolver;
+import org.jboss.seam.xml.parser.namespace.RootNamespaceElementResolver;
+import org.jboss.seam.xml.util.XmlConfigurationException;
+import org.jboss.seam.xml.util.XmlObjectConverter;
+import org.jboss.weld.extensions.util.AnnotationInstanceProvider;
+import org.jboss.weld.extensions.util.ReflectionUtils;
+import org.jboss.weld.extensions.util.annotated.NewAnnotatedTypeBuilder;
+
+/**
+ * Builds an XML result from sax nodes
+ *
+ * @author stuart
+ *
+ */
+public class ModelBuilder
+{
+
+ AnnotationInstanceProvider ac = new AnnotationInstanceProvider();
+
+ static final String ROOT_NAMESPACE = "urn:seam:core";
+
+ Map<String, NamespaceElementResolver> resolvers;
+
+ public XmlResult build(SaxNode root)
+ {
+
+ resolvers = new HashMap<String, NamespaceElementResolver>();
+
+ XmlResult ret = new XmlResult();
+
+ if (!root.getName().equals("Beans"))
+ {
+ throw new XmlConfigurationException("Wrong root element for XML config
file, expected:<Beans> found:" + root.getName(), root.getDocument(),
root.getLineNo());
+ }
+ if (!ROOT_NAMESPACE.equals(root.getNamespaceUri()))
+ {
+ throw new XmlConfigurationException("Wrong root namespace for XML config
file, expected:" + ROOT_NAMESPACE + " found:" + root.getNamespaceUri(),
root.getDocument(), root.getLineNo());
+ }
+
+ resolvers.put(ROOT_NAMESPACE, new RootNamespaceElementResolver());
+
+ List<SaxNode> children = root.getChildren();
+ for (SaxNode node : children)
+ {
+ try
+ {
+ // nodes with a null namespace are whitespace nodes etc
+ if (node.getNamespaceUri() != null)
+ {
+ XmlItem rb = resolveNode(node, null);
+ // validateXmlItem(rb);
+ addNodeToResult(ret, rb);
+ }
+ }
+ catch (Exception e)
+ {
+ ret.addProblem(e.getMessage());
+ e.printStackTrace();
+ }
+ }
+
+ return ret;
+ }
+
+ @SuppressWarnings("unchecked")
+ private void addNodeToResult(XmlResult ret, XmlItem rb)
+ {
+
+ if (rb.getType() == XmlItemType.CLASS || rb.getType() == XmlItemType.ANNOTATION)
+ {
+ ResultType type = getItemType(rb);
+ if (type == ResultType.BEAN)
+ {
+ BeanResult<?> tp = buildAnnotatedType((ClassXmlItem) rb);
+ ret.getBeans().add(tp);
+ if (tp.isOverride() || tp.isExtend())
+ {
+ ret.addVeto(tp.getType());
+ }
+ List<FieldValueObject> fields = new
ArrayList<FieldValueObject>();
+ for (FieldXmlItem xi : rb.getChildrenOfType(FieldXmlItem.class))
+ {
+ FieldValueObject f = xi.getFieldValue();
+ if (f != null)
+ {
+ fields.add(f);
+ }
+ }
+ if (!fields.isEmpty())
+ {
+ ret.getFieldValues().put(tp, fields);
+ }
+ }
+ else if (type == ResultType.QUALIFIER)
+ {
+ ret.getQualifiers().add((Class) rb.getJavaClass());
+ }
+ else if (type == ResultType.INTERCEPTOR_BINDING)
+ {
+ ret.getInterceptorBindings().add((Class) rb.getJavaClass());
+ }
+ else if (type == ResultType.STEREOTYPE)
+ {
+ addStereotypeToResult(ret, rb);
+ }
+ }
+ else if (rb.getType() == XmlItemType.VETO)
+ {
+ for (XmlItem it : rb.getChildren())
+ {
+ ret.addVeto(it.getJavaClass());
+ }
+ }
+ }
+
+ protected XmlItem resolveNode(SaxNode node, XmlItem parent)
+ {
+ NamespaceElementResolver resolver = resolveNamepsace(node.getNamespaceUri());
+
+ XmlItem ret = resolver.getItemForNamespace(node, parent);
+
+ if (ret == null)
+ {
+ throw new XmlConfigurationException("Could not resolve node " +
node.getName() + " in namespace " + node.getNamespaceUri(), node.getDocument(),
node.getLineNo());
+ }
+ List<SaxNode> children = node.getChildren();
+ for (SaxNode n : children)
+ {
+ if (n.getNamespaceUri() != null)
+ {
+ XmlItem rb = resolveNode(n, ret);
+ ret.addChild(rb);
+ }
+ }
+ ret.resolveChildren();
+ return ret;
+
+ }
+
+ protected NamespaceElementResolver resolveNamepsace(String namespaceURI)
+ {
+ if (resolvers.containsKey(namespaceURI))
+ {
+ return resolvers.get(namespaceURI);
+ }
+ String ns = namespaceURI.replaceFirst("urn:java:", "");
+ CompositeNamespaceElementResolver res = new
CompositeNamespaceElementResolver(ns.split(":"));
+ resolvers.put(namespaceURI, res);
+ return res;
+ }
+
+ /**
+ * Determines the type of an element by examining its child nodes
+ */
+ protected ResultType getItemType(XmlItem item)
+ {
+
+ ResultType ret = null;
+ for (AnnotationXmlItem it : item.getChildrenOfType(AnnotationXmlItem.class))
+ {
+ if (it.getJavaClass() == InterceptorBinding.class)
+ {
+ if (ret != null)
+ {
+ throw new XmlConfigurationException("Element cannot be both an
INTERCEPTOR_BINDING and a " + ret.toString(), item.getDocument(), item.getLineno());
+ }
+ else
+ {
+ ret = ResultType.INTERCEPTOR_BINDING;
+ }
+ }
+ else if (it.getJavaClass() == Qualifier.class)
+ {
+ if (ret != null)
+ {
+ throw new XmlConfigurationException("Element cannot be both an
QUALIFIER and a " + ret.toString(), item.getDocument(), item.getLineno());
+ }
+ else
+ {
+ ret = ResultType.QUALIFIER;
+ }
+ }
+ else if (it.getJavaClass() == Stereotype.class)
+ {
+ if (ret != null)
+ {
+ throw new XmlConfigurationException("Element cannot be both an
STEREOTYPE and a " + ret.toString(), item.getDocument(), item.getLineno());
+ }
+ else
+ {
+ ret = ResultType.STEREOTYPE;
+ }
+ }
+ }
+
+ if (ret == null)
+ {
+ ret = ResultType.BEAN;
+ }
+ return ret;
+ }
+
+ @SuppressWarnings("unchecked")
+ BeanResult<?> buildAnnotatedType(ClassXmlItem rb)
+ {
+ boolean override = !rb.getChildrenOfType(OverrideXmlItem.class).isEmpty();
+ boolean extend = !rb.getChildrenOfType(ExtendsXmlItem.class).isEmpty();
+
+ // if it is an extend we want to read the annotations from the underlying
+ // class
+ BeanResult<?> result = new BeanResult(rb.getJavaClass(), extend);
+ NewAnnotatedTypeBuilder<?> type = result.getBuilder();
+ // list of constructor arguments
+ List<ParameterXmlItem> constList = new ArrayList<ParameterXmlItem>();
+
+ 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);
+ type.addToClass(a);
+ }
+ List<ParametersXmlItem> constructorParameters =
rb.getChildrenOfType(ParametersXmlItem.class);
+ if (constructorParameters.size() > 1)
+ {
+ throw new XmlConfigurationException("A method may only have a single
<parameters> element", rb.getDocument(), rb.getLineno());
+ }
+ else if (!constructorParameters.isEmpty())
+ {
+ for (ParameterXmlItem item :
constructorParameters.get(0).getChildrenOfType(ParameterXmlItem.class))
+ {
+ constList.add(item);
+ }
+ }
+ for (FieldXmlItem item : rb.getChildrenOfType(FieldXmlItem.class))
+ {
+ for (AnnotationXmlItem fi : item.getChildrenOfType(AnnotationXmlItem.class))
+ {
+ Annotation a = createAnnotation(fi);
+ type.addToField(item.getField(), a);
+ }
+ }
+ for (MethodXmlItem item : rb.getChildrenOfType(MethodXmlItem.class))
+ {
+ int paramCount = 0;
+
+ for (AnnotationXmlItem fi : item.getChildrenOfType(AnnotationXmlItem.class))
+ {
+ Annotation a = createAnnotation(fi);
+ type.addToMethod(item.getMethod(), a);
+ }
+ List<ParametersXmlItem> parameters =
item.getChildrenOfType(ParametersXmlItem.class);
+ if (parameters.size() > 1)
+ {
+ throw new XmlConfigurationException("A method may only have a single
<parameters> element", item.getDocument(), item.getLineno());
+ }
+ else if (!parameters.isEmpty())
+ {
+ for (ParameterXmlItem fi :
parameters.get(0).getChildrenOfType(ParameterXmlItem.class))
+ {
+ int param = paramCount++;
+ for (AnnotationXmlItem pan :
fi.getChildrenOfType(AnnotationXmlItem.class))
+ {
+ Annotation a = createAnnotation(pan);
+ type.addToMethodParameter(item.getMethod(), param, a);
+ }
+ }
+ }
+
+ }
+
+ if (!constList.isEmpty())
+ {
+ int paramCount = 0;
+ Constructor<?> c = resolveConstructor(rb, constList);
+ // we automatically add inject to the constructor
+ type.addToConstructor((Constructor) c, new AnnotationLiteral<Inject>()
+ {
+ });
+ for (ParameterXmlItem fi : constList)
+ {
+ int param = paramCount++;
+ for (AnnotationXmlItem pan : fi.getChildrenOfType(AnnotationXmlItem.class))
+ {
+ Annotation a = createAnnotation(pan);
+ type.addToConstructorParameter((Constructor) c, param, a);
+ }
+ }
+ }
+ return result;
+ }
+
+ protected static Constructor<?> resolveConstructor(ClassXmlItem bean,
List<ParameterXmlItem> constList)
+ {
+ Class<?>[] params = new Class[constList.size()];
+ for (int i = 0; i < constList.size(); ++i)
+ {
+ params[i] = constList.get(i).getJavaClass();
+ }
+ Constructor<?> ret = ReflectionUtils.getConstructor(bean.getJavaClass(),
params);
+ if (ret == null)
+ {
+ throw new XmlConfigurationException("Could not resolve constructor for
" + bean.getJavaClass() + " with arguments " + params, bean.getDocument(),
bean.getLineno());
+ }
+ return ret;
+ }
+
+ @SuppressWarnings("unchecked")
+ void addStereotypeToResult(XmlResult ret, XmlItem rb)
+ {
+
+ Annotation[] values = new Annotation[rb.getChildren().size()];
+ int count = 0;
+ for (XmlItem item : rb.getChildren())
+ {
+ if (item.getType() == XmlItemType.ANNOTATION)
+ {
+ Annotation a = createAnnotation((AnnotationXmlItem) item);
+ values[count] = a;
+ }
+ else
+ {
+ throw new XmlConfigurationException("Setereotype " +
rb.getJavaClass() + " has an item that does not represent an annotation in its XML
configurations", rb.getDocument(), rb.getLineno());
+ }
+ count++;
+ }
+ ret.getStereotypes().put((Class) rb.getJavaClass(), values);
+
+ }
+
+ @SuppressWarnings("unchecked")
+ Annotation createAnnotation(AnnotationXmlItem item)
+ {
+ Map<String, Object> typedVars = new HashMap<String, Object>();
+ Class<?> anClass = item.getJavaClass();
+ for (Entry<String, String> e : item.getAttributes().entrySet())
+ {
+ String mname = e.getKey();
+ Method m;
+ try
+ {
+ m = anClass.getDeclaredMethod(mname);
+ }
+ catch (Exception e1)
+ {
+ throw new XmlConfigurationException("Annotation " +
item.getJavaClass().getName() + " does not have a member named " + mname +
" ,error in XML", item.getDocument(), item.getLineno());
+ }
+ Class<?> returnType = m.getReturnType();
+ typedVars.put(mname, XmlObjectConverter.convert(returnType, e.getValue()));
+ }
+
+ return ac.get((Class) item.getJavaClass(), typedVars);
+ }
+
+ public void validateXmlItem(XmlItem item)
+ {
+ Set<XmlItemType> allowed = item.getAllowedItem();
+ for (XmlItem i : item.getChildren())
+ {
+ if (!allowed.contains(item.getType()))
+ {
+ throw new XmlConfigurationException("Item " + item.getType() +
" is not allowed to contain " + i.getType(), item.getDocument(),
item.getLineno());
+ }
+ validateXmlItem(i);
+ }
+ }
+
+}
Deleted:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
===================================================================
---
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java 2010-03-06
21:42:25 UTC (rev 12110)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java 2010-03-06
22:58:32 UTC (rev 12113)
@@ -1,97 +0,0 @@
-/*
- * Distributed under the LGPL License
- *
- */
-package org.jboss.seam.xml.parser.namespace;
-
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.jboss.seam.xml.model.AnnotationXmlItem;
-import org.jboss.seam.xml.model.ClassXmlItem;
-import org.jboss.seam.xml.model.ParameterXmlItem;
-import org.jboss.seam.xml.model.XmlItem;
-import org.jboss.seam.xml.model.XmlItemType;
-import org.jboss.seam.xml.parser.SaxNode;
-import org.jboss.seam.xml.util.ReflectionUtils;
-
-public class PackageNamespaceElementResolver implements NamespaceElementResolver
-{
- String pack;
- Map<String, Class<?>> cache = new HashMap<String,
Class<?>>();
- Set<String> notFound = new HashSet<String>();
-
- public PackageNamespaceElementResolver(String pack)
- {
- this.pack = pack + ".";
- }
-
- public XmlItem getItemForNamespace(SaxNode node, XmlItem parent)
- {
- String name = node.getName();
- if (notFound.contains(name))
- {
- return null;
- }
-
- try
- {
- Class<?> c;
- if (cache.containsKey(name))
- {
- c = cache.get(name);
- }
- else
- {
- c = getClass().getClassLoader().loadClass(pack + name);
- cache.put(name, c);
- }
- if (c.isAnnotation())
- {
- return new AnnotationXmlItem(parent, c, node.getInnerText(),
node.getAttributes(), node.getDocument(), node.getLineNo());
- }
- else
- {
- // if it is a method or constructor parameter
- if (parent != null && parent.getType() == XmlItemType.PARAMETERS)
- {
- return new ParameterXmlItem(parent, c, node.getDocument(),
node.getLineNo());
- }
- else
- {
- return new ClassXmlItem(parent, c, node.getDocument(), node.getLineNo());
- }
- }
-
- }
- catch (ClassNotFoundException e)
- {
-
- }
- catch (NoClassDefFoundError e) // this can get thrown when there is a
- // case insensitive file system
- {
-
- }
- if (parent != null)
- {
- // if the item can be a method of a FIELD
- if (parent.getAllowedItem().contains(XmlItemType.METHOD) ||
parent.getAllowedItem().contains(XmlItemType.FIELD))
- {
- return ReflectionUtils.resolveMethodOrField(name, parent,
node.getInnerText(), node.getDocument(), node.getLineNo());
- }
- else
- {
- notFound.add(name);
- }
- }
- else
- {
- notFound.add(name);
- }
- return null;
- }
-
-}
Copied:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
(from rev 12111,
modules/xml/trunk/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java)
===================================================================
---
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java
(rev 0)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/parser/namespace/PackageNamespaceElementResolver.java 2010-03-06
22:58:32 UTC (rev 12113)
@@ -0,0 +1,122 @@
+/*
+ * Distributed under the LGPL License
+ *
+ */
+package org.jboss.seam.xml.parser.namespace;
+
+import java.lang.reflect.Field;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
+import org.jboss.seam.xml.model.AnnotationXmlItem;
+import org.jboss.seam.xml.model.ClassXmlItem;
+import org.jboss.seam.xml.model.FieldXmlItem;
+import org.jboss.seam.xml.model.MethodXmlItem;
+import org.jboss.seam.xml.model.ParameterXmlItem;
+import org.jboss.seam.xml.model.XmlItem;
+import org.jboss.seam.xml.model.XmlItemType;
+import org.jboss.seam.xml.parser.SaxNode;
+import org.jboss.seam.xml.util.XmlConfigurationException;
+import org.jboss.weld.extensions.util.ReflectionUtils;
+
+public class PackageNamespaceElementResolver implements NamespaceElementResolver
+{
+ String pack;
+ Map<String, Class<?>> cache = new HashMap<String,
Class<?>>();
+ Set<String> notFound = new HashSet<String>();
+
+ public PackageNamespaceElementResolver(String pack)
+ {
+ this.pack = pack + ".";
+ }
+
+ public XmlItem getItemForNamespace(SaxNode node, XmlItem parent)
+ {
+ String name = node.getName();
+ if (notFound.contains(name))
+ {
+ return null;
+ }
+
+ try
+ {
+ Class<?> c;
+ if (cache.containsKey(name))
+ {
+ c = cache.get(name);
+ }
+ else
+ {
+ c = getClass().getClassLoader().loadClass(pack + name);
+ cache.put(name, c);
+ }
+ if (c.isAnnotation())
+ {
+ return new AnnotationXmlItem(parent, c, node.getInnerText(),
node.getAttributes(), node.getDocument(), node.getLineNo());
+ }
+ else
+ {
+ // if it is a method or constructor parameter
+ if (parent != null && parent.getType() == XmlItemType.PARAMETERS)
+ {
+ return new ParameterXmlItem(parent, c, node.getDocument(),
node.getLineNo());
+ }
+ else
+ {
+ return new ClassXmlItem(parent, c, node.getDocument(), node.getLineNo());
+ }
+ }
+
+ }
+ catch (ClassNotFoundException e)
+ {
+
+ }
+ catch (NoClassDefFoundError e) // this can get thrown when there is a
+ // case insensitive file system
+ {
+
+ }
+ if (parent != null)
+ {
+ // if the item can be a method of a FIELD
+ if (parent.getAllowedItem().contains(XmlItemType.METHOD) ||
parent.getAllowedItem().contains(XmlItemType.FIELD))
+ {
+ return resolveMethodOrField(name, parent, node.getInnerText(),
node.getDocument(), node.getLineNo());
+ }
+ else
+ {
+ notFound.add(name);
+ }
+ }
+ else
+ {
+ notFound.add(name);
+ }
+ return null;
+ }
+
+ public static XmlItem resolveMethodOrField(String name, XmlItem parent, String
innerText, String document, int lineno)
+ {
+ Class<?> p = parent.getJavaClass();
+ Field f = null;
+ boolean methodFound = ReflectionUtils.methodExists(p, name);
+ f = ReflectionUtils.getField(p, name);
+
+ if (methodFound && f != null)
+ {
+ throw new XmlConfigurationException(parent.getJavaClass().getName() + " has
both a method and a field named " + name + " and so cannot be configured via
XML", document, lineno);
+ }
+ if (methodFound)
+ {
+ return new MethodXmlItem(parent, name, document, lineno);
+ }
+ else if (f != null)
+ {
+ return new FieldXmlItem(parent, f, innerText, document, lineno);
+ }
+ return null;
+ }
+}
Deleted:
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/util/ReflectionUtils.java
===================================================================
---
modules/xml/trunk/src/main/java/org/jboss/seam/xml/util/ReflectionUtils.java 2010-03-06
21:42:25 UTC (rev 12110)
+++
modules/xml/trunk/core/src/main/java/org/jboss/seam/xml/util/ReflectionUtils.java 2010-03-06
22:58:32 UTC (rev 12113)
@@ -1,112 +0,0 @@
-/*
- * Distributed under the LGPL License
- *
- */
-package org.jboss.seam.xml.util;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-
-import org.jboss.seam.xml.model.FieldXmlItem;
-import org.jboss.seam.xml.model.MethodXmlItem;
-import org.jboss.seam.xml.model.XmlItem;
-
-public class ReflectionUtils
-{
- public static XmlItem resolveMethodOrField(String name, XmlItem parent, String
innerText, String document, int lineno)
- {
- Class<?> p = parent.getJavaClass();
- Field f = null;
- boolean methodFound = methodExists(p, name);
- f = getField(p, name);
-
- if (methodFound && f != null)
- {
- throw new XmlConfigurationException(parent.getJavaClass().getName() + " has
both a method and a field named " + name + " and so cannot be configured via
XML", document, lineno);
- }
- if (methodFound)
- {
- return new MethodXmlItem(parent, name, document, lineno);
- }
- else if (f != null)
- {
- return new FieldXmlItem(parent, f, innerText, document, lineno);
- }
- return null;
- }
-
- /**
- * we need access to private fields so we cannot just use getField
- */
- public static Field getField(Class<?> parent, String name)
- {
- Class<?> p = parent;
- while (p != Object.class)
- {
- try
- {
- return p.getDeclaredField(name);
- }
- catch (Exception e1)
- {
-
- }
- p = p.getSuperclass();
- }
- return null;
- }
-
- public static boolean methodExists(Class<?> parent, String name)
- {
- Class<?> p = parent;
- while (p != Object.class)
- {
- for (Method m : p.getDeclaredMethods())
- {
- if (m.getName().equals(name))
- {
- return true;
- }
- }
- p = p.getSuperclass();
- }
- return false;
- }
-
- public static Method getMethod(Class<?> parent, String name, Class<?>...
args)
- {
- Class<?> p = parent;
- while (p != Object.class)
- {
- try
- {
- return p.getDeclaredMethod(name, args);
- }
- catch (Exception e1)
- {
-
- }
- p = p.getSuperclass();
- }
- return null;
- }
-
- public static Constructor<?> getConstructor(Class<?> parent,
Class<?>... args)
- {
- Class<?> p = parent;
- while (p != Object.class)
- {
- try
- {
- return p.getDeclaredConstructor(args);
- }
- catch (Exception e1)
- {
-
- }
- p = p.getSuperclass();
- }
- return null;
- }
-}
Modified: modules/xml/trunk/examples/princess-rescue/pom.xml
===================================================================
--- modules/xml/trunk/examples/princess-rescue/pom.xml 2010-03-06 22:45:55 UTC (rev
12112)
+++ modules/xml/trunk/examples/princess-rescue/pom.xml 2010-03-06 22:58:32 UTC (rev
12113)
@@ -8,7 +8,7 @@
<groupId>org.jboss.seam.xml.examples</groupId>
<artifactId>princess-rescue</artifactId>
<packaging>war</packaging>
- <name>princess-rescue</name>
+ <name>Seam XML Example Princess Rescue</name>
<version>1.0.0-SNAPSHOT</version>
<properties>
@@ -48,7 +48,7 @@
<dependency>
<groupId>org.jboss.seam</groupId>
- <artifactId>seam-xml</artifactId>
+ <artifactId>seam-xml-core</artifactId>
<version>3.0.0-SNAPSHOT</version>
</dependency>
Deleted: modules/xml/trunk/pom.xml
===================================================================
--- modules/xml/trunk/pom.xml 2010-03-06 22:45:55 UTC (rev 12112)
+++ modules/xml/trunk/pom.xml 2010-03-06 22:58:32 UTC (rev 12113)
@@ -1,105 +0,0 @@
-<?xml version="1.0"?>
-<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
- <modelVersion>4.0.0</modelVersion>
-
- <parent>
- <artifactId>seam-parent</artifactId>
- <groupId>org.jboss.seam</groupId>
- <version>3.0.0-SNAPSHOT</version>
- </parent>
-
- <artifactId>seam-xml</artifactId>
- <packaging>jar</packaging>
- <version>3.0.0-SNAPSHOT</version>
- <name>Seam XML Configuration</name>
-
- <repositories>
- <repository>
- <
id>oss.sonatype.org/jboss-snapshots</id>
- <name>JBoss (Nexus) Snapshots Repository</name>
-
<
url>http://oss.sonatype.org/content/repositories/jboss-snapshots</u...
- <releases>
- <enabled>false</enabled>
- </releases>
- <snapshots>
- <enabled>true</enabled>
- <updatePolicy>never</updatePolicy>
- </snapshots>
- </repository>
- </repositories>
-
- <properties>
- <seam.version>3.0.0-SNAPSHOT</seam.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>javax.enterprise</groupId>
- <artifactId>cdi-api</artifactId>
- <version>1.0-SP1</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.weld</groupId>
- <artifactId>weld-core</artifactId>
- <version>1.0.1-Final</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.weld</groupId>
- <artifactId>weld-extensions-core</artifactId>
- <version>1.0.1-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.jboss.weld</groupId>
- <artifactId>weld-se</artifactId>
- <version>1.0.1-Final</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.testng</groupId>
- <artifactId>testng</artifactId>
- <version>5.10</version>
- <type>jar</type>
- <classifier>jdk15</classifier>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <scm>
-
<
connection>scm:svn:http://anonsvn.jboss.org/repos/seam/modules/xml/tru...
-
<
developerConnection>scm:svn:https://svn.jboss.org/repos/seam/modules/x...
- <
url>http://fisheye.jboss.org/browse/Seam/modules/xml/trunk</url>
- </scm>
-
- <build>
-
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-compiler-plugin</artifactId>
- <configuration>
- <source>1.5</source>
- <target>1.5</target>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-eclipse-plugin</artifactId>
- <configuration>
- <workspace>${basedir}</workspace>
-
- <downloadJavadocs>true</downloadJavadocs>
- <downloadSources>true</downloadSources>
- </configuration>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <forkMode>once</forkMode>
- <argLine>-Xmx512Mb</argLine>
- </configuration>
- </plugin>
- </plugins>
- </build>
-</project>