[webbeans-commits] Webbeans SVN: r3610 - in extensions/trunk/bean-utils: src and 12 other directories.

webbeans-commits at lists.jboss.org webbeans-commits at lists.jboss.org
Thu Aug 27 12:30:31 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-08-27 12:30:29 -0400 (Thu, 27 Aug 2009)
New Revision: 3610

Added:
   extensions/trunk/bean-utils/pom.xml
   extensions/trunk/bean-utils/src/
   extensions/trunk/bean-utils/src/main/
   extensions/trunk/bean-utils/src/main/java/
   extensions/trunk/bean-utils/src/main/java/org/
   extensions/trunk/bean-utils/src/main/java/org/jboss/
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriber.java
   extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriberXXX.java
   extensions/trunk/bean-utils/src/main/resources/
   extensions/trunk/bean-utils/src/test/
   extensions/trunk/bean-utils/src/test/java/
   extensions/trunk/bean-utils/src/test/java/org/
   extensions/trunk/bean-utils/src/test/java/org/jboss/
   extensions/trunk/bean-utils/src/test/java/org/jboss/webbeans/
   extensions/trunk/bean-utils/src/test/java/org/jboss/webbeans/beanutils/
   extensions/trunk/bean-utils/src/test/java/org/jboss/webbeans/beanutils/impl/
Log:
Add bean-utils


Added: extensions/trunk/bean-utils/pom.xml
===================================================================
--- extensions/trunk/bean-utils/pom.xml	                        (rev 0)
+++ extensions/trunk/bean-utils/pom.xml	2009-08-27 16:30:29 UTC (rev 3610)
@@ -0,0 +1,103 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+   <parent>
+      <artifactId>webbeans-parent</artifactId>
+      <groupId>org.jboss.webbeans</groupId>
+      <version>1.0.0-SNAPSHOT</version>
+   </parent>
+   <modelVersion>4.0.0</modelVersion>
+   <groupId>org.jboss.webbeans</groupId>
+   <artifactId>webbeans-bean-utils</artifactId>
+   <version>1.0.0-SNAPSHOT</version>
+   <name>Web Beans Utilities For Managing Beans</name>
+   
+   <dependencies>
+
+      <dependency>
+         <groupId>org.testng</groupId>
+         <artifactId>testng</artifactId>
+         <scope>test</scope>
+         <classifier>jdk15</classifier>
+         <exclusions>
+         	<exclusion>
+         		<artifactId>junit</artifactId>
+         		<groupId>junit</groupId>
+         	</exclusion>
+         </exclusions>
+      </dependency>
+      
+      <dependency>
+         <groupId>org.jboss.webbeans</groupId>
+         <artifactId>webbeans-logging</artifactId>
+      </dependency>
+      
+      <dependency>
+      	<groupId>org.jboss.webbeans</groupId>
+      	<artifactId>webbeans-core</artifactId>
+         <scope>provided</scope>
+      </dependency>
+      
+      <dependency>
+      	<groupId>org.jboss.test-harness</groupId>
+      	<artifactId>jboss-test-harness</artifactId>
+      	<scope>test</scope>
+      </dependency>
+<!--      
+      <dependency>
+      	<groupId>org.jboss.test-harness</groupId>
+      	<artifactId>jboss-test-harness-jboss-as-50</artifactId>
+      	<scope>test</scope>
+      </dependency>
+      <dependency>
+      	<groupId>org.jboss.webbeans</groupId>
+      	<artifactId>webbeans-core</artifactId>
+      	<scope>test</scope>
+      </dependency>
+      
+      <dependency>
+         <groupId>org.jboss.webbeans</groupId>
+         <artifactId>webbeans-core-test</artifactId>
+         <scope>test</scope>
+      </dependency>
+      
+      <dependency>
+         <groupId>org.jboss.ejb3</groupId>
+         <artifactId>jboss-ejb3-api</artifactId>
+         <scope>test</scope>
+         <exclusions>
+            <exclusion>
+               <artifactId>jboss-jaxrpc</artifactId>
+               <groupId>jbossws</groupId>
+            </exclusion>
+            <exclusion>
+               <artifactId>jboss-transaction-api</artifactId>
+               <groupId>org.jboss.javaee</groupId>
+            </exclusion>
+            <exclusion>
+               <artifactId>jboss-jaxrpc</artifactId>
+               <groupId>jboss.jbossws</groupId>
+            </exclusion>
+         </exclusions>
+      </dependency>
+-->      
+   </dependencies>
+
+   <scm>
+      <connection>scm:svn:http://anonsvn.jboss.org/repos/webbeans/extensions</connection>
+      <developerConnection>scm:svn:https://svn.jboss.org/repos/webbeans/extensions</developerConnection>
+      <url>http://viewvc.jboss.org/cgi-bin/viewvc.cgi/webbeans/extensions</url>
+   </scm>
+
+   <build>
+      <defaultGoal>install</defaultGoal>
+      <plugins>
+         <plugin>
+            <groupId>org.apache.maven.plugins</groupId>
+            <artifactId>maven-release-plugin</artifactId>
+            <configuration>
+               <tagBase>https://svn.jboss.org/repos/webbeans/extensions/tags</tagBase>
+               <autoVersionSubmodules>true</autoVersionSubmodules>
+            </configuration>
+         </plugin>
+      </plugins>
+   </build>
+</project>

Added: extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriber.java
===================================================================
--- extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriber.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriber.java	2009-08-27 16:30:29 UTC (rev 3610)
@@ -0,0 +1,60 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.webbeans.beanutils;
+
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.bean.SimpleBean;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.introspector.jlr.WBClassImpl;
+import org.jboss.webbeans.resources.ClassTransformer;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeanDescriber<T>
+{
+   public static <T> Bean<T> describeBean(AnnotatedType<T> type, BeanManager beanManager)
+   {
+      if (type == null)
+         throw new IllegalArgumentException("Null type");
+      if (beanManager == null)
+         throw new IllegalArgumentException("Null beanManager");
+      if (beanManager instanceof BeanManagerImpl == false)
+         throw new IllegalArgumentException("BeanManager is not an instance of BeanManagerImpl");
+      
+      WBClass<T> clazz = type instanceof WBClass ? 
+            (WBClass<T>)type :
+               WBClassImpl.of(type, ((BeanManagerImpl)beanManager).getServices().get(ClassTransformer.class));
+      
+      Bean<T> bean = SimpleBean.of(clazz, (BeanManagerImpl)beanManager);
+      
+      //TODO How to get BeanDeployerEnvironment?
+      ((SimpleBean<T>)bean).initialize(null);
+      return bean;
+   }
+}

Added: extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriberXXX.java
===================================================================
--- extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriberXXX.java	                        (rev 0)
+++ extensions/trunk/bean-utils/src/main/java/org/jboss/webbeans/beanutils/BeanDescriberXXX.java	2009-08-27 16:30:29 UTC (rev 3610)
@@ -0,0 +1,192 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file 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.webbeans.beanutils;
+
+import java.lang.annotation.Annotation;
+import java.util.HashSet;
+import java.util.Set;
+
+import javax.enterprise.context.Dependent;
+import javax.enterprise.context.ScopeType;
+import javax.enterprise.inject.BindingType;
+import javax.enterprise.inject.Policy;
+import javax.enterprise.inject.spi.AnnotatedType;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.stereotype.Stereotype;
+
+import org.jboss.webbeans.BeanManagerImpl;
+import org.jboss.webbeans.DefinitionException;
+import org.jboss.webbeans.bean.AbstractClassBean;
+import org.jboss.webbeans.introspector.WBClass;
+import org.jboss.webbeans.literal.AnyLiteral;
+import org.jboss.webbeans.literal.CurrentLiteral;
+import org.jboss.webbeans.log.LogProvider;
+import org.jboss.webbeans.log.Logging;
+import org.jboss.webbeans.metadata.cache.MergedStereotypes;
+
+/**
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class BeanDescriberXXX<T, E>
+{
+   // Logger
+   private static final LogProvider log = Logging.getLogProvider(AbstractClassBean.class);
+   
+   WBClass<T> type;
+   
+   BeanManagerImpl beanManager;
+   
+   private MergedStereotypes<T, E> mergedStereotypes;
+   
+   private static final Annotation ANY_LITERAL = new AnyLiteral();
+
+   private static final Annotation CURRENT_LITERAL = new CurrentLiteral();
+
+   
+   public BeanDescriberXXX(AnnotatedType<T> type, BeanManager beanManager)
+   {
+      if (type == null)
+         throw new IllegalArgumentException("Null type");
+      if (beanManager == null)
+         throw new IllegalArgumentException("Null beanManager");
+      if (type instanceof WBClass == false)
+         throw new IllegalArgumentException("Type is not an instance of WBType");
+      if (beanManager instanceof BeanManagerImpl == false)
+         throw new IllegalArgumentException("BeanManaget is not an instance of BeanManagerImpl");
+      
+      this.type = (WBClass<T>)type;
+      this.beanManager = (BeanManagerImpl)beanManager;
+      
+      
+   }
+   
+   
+   public Class<? extends Annotation> determineScopeType(AnnotatedType<?> annotatedType)
+   {
+      if (annotatedType instanceof WBClass == false)
+         throw new IllegalArgumentException("Annotated type is not an instance of WBType");
+      
+      final WBClass<?> type = (WBClass<?>)annotatedType;
+      Class<? extends Annotation> scopeType = null;
+      
+      for (WBClass<?> clazz = type; clazz != null; clazz = clazz.getWBSuperclass())
+      {
+         Set<Annotation> scopeTypes = clazz.getDeclaredMetaAnnotations(ScopeType.class);
+         scopeTypes = clazz.getDeclaredMetaAnnotations(ScopeType.class);
+         if (scopeTypes.size() == 1)
+         {
+            if (type.isAnnotationPresent(scopeTypes.iterator().next().annotationType()))
+            {
+               scopeType = scopeTypes.iterator().next().annotationType();
+               log.trace("Scope " + scopeType + " specified by annotation");
+            }
+            break;
+         }
+         else if (scopeTypes.size() > 1)
+         {
+            throw new DefinitionException("At most one scope may be specified on " + type);
+         }
+      }
+
+      if (scopeType == null)
+      {
+         scopeType = initScopeTypeFromStereotype();
+      }
+
+      if (scopeType == null)
+      {
+         scopeType = Dependent.class;
+         log.trace("Using default @Dependent scope");
+      }
+      return scopeType;
+   }
+   
+   public Set<Annotation> determineBindings(boolean includeDefaultBindings)
+   {
+      Set<Annotation> bindings = new HashSet<Annotation>();
+      bindings.addAll(type.getMetaAnnotations(BindingType.class));
+      if (includeDefaultBindings)
+         initDefaultBindings(bindings);
+      log.trace("Using binding types " + bindings + " specified by annotations");
+      return bindings;
+   }
+
+   
+   public Set<Class<? extends Annotation>> determineStereotypes()
+   {
+      return getMergedStereotypes().getStereotypes();
+   }
+   
+   public boolean determinePolicy()
+   {
+      if (type.isAnnotationPresent(Policy.class))
+      {
+         return true;
+      }
+      else
+      {
+         return getMergedStereotypes().isPolicy();
+      }
+   }
+
+
+   protected Class<? extends Annotation> initScopeTypeFromStereotype()
+   {
+      Class<? extends Annotation> scopeType = null;
+      Set<Annotation> possibleScopeTypes = getMergedStereotypes().getPossibleScopeTypes();
+      if (possibleScopeTypes.size() == 1)
+      {
+         scopeType = possibleScopeTypes.iterator().next().annotationType();
+         if (log.isTraceEnabled())
+            log.trace("Scope " + scopeType + " specified by stereotype");
+         return scopeType;
+      }
+      else if (possibleScopeTypes.size() > 1)
+      {
+         throw new DefinitionException("All stereotypes must specify the same scope OR a scope must be specified on " + type);
+      }
+      else
+      {
+         return null;
+      }
+   }
+
+   protected MergedStereotypes<T, E> getMergedStereotypes()
+   {
+      if (mergedStereotypes == null)
+         mergedStereotypes = new MergedStereotypes<T, E>(type.getMetaAnnotations(Stereotype.class), beanManager);
+
+      return mergedStereotypes;
+   }
+   
+   protected void initDefaultBindings(Set<Annotation> bindings)
+   {
+      if (bindings.size() == 0)
+      {
+         log.trace("Adding default @Current binding type");
+         bindings.add(CURRENT_LITERAL);
+      }
+      bindings.add(ANY_LITERAL);
+   }
+}




More information about the weld-commits mailing list