You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by ge...@apache.org on 2009/01/02 23:11:27 UTC

svn commit: r730849 - in /incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans: annotation/ component/ config/ container/ event/ inject/ util/ xml/

Author: gerdogdu
Date: Fri Jan  2 14:11:27 2009
New Revision: 730849

URL: http://svn.apache.org/viewvc?rev=730849&view=rev
Log:
Arranging and testing for M1 Release.

Added:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/InitializedManagerLiteral.java   (with props)
Modified:
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractComponent.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ResolutionUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/JNDIUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
    incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java

Added: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/InitializedManagerLiteral.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/InitializedManagerLiteral.java?rev=730849&view=auto
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/InitializedManagerLiteral.java (added)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/InitializedManagerLiteral.java Fri Jan  2 14:11:27 2009
@@ -0,0 +1,25 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one or more
+ *  contributor license agreements.  See the NOTICE file distributed with
+ *  this work for additional information regarding copyright ownership.
+ *  The ASF licenses this file to You under the Apache License, Version 2.0
+ *  (the "License"); you may not use this file except in compliance with
+ *  the License.  You may obtain a copy of the License at
+ * 
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.apache.webbeans.annotation;
+
+import javax.webbeans.AnnotationLiteral;
+import javax.webbeans.manager.Initialized;
+
+public class InitializedManagerLiteral extends AnnotationLiteral<Initialized> implements Initialized
+{
+
+}

Propchange: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/annotation/InitializedManagerLiteral.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractComponent.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractComponent.java?rev=730849&r1=730848&r2=730849&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractComponent.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/component/AbstractComponent.java Fri Jan  2 14:11:27 2009
@@ -95,7 +95,7 @@
 	protected boolean serializable;
 	
 	/**The bean allows nullable object*/
-	protected boolean nullable;
+	protected boolean nullable = true;
 
 	/**
 	 * Constructor definiton. Each subclass redefines its own constructor with

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java?rev=730849&r1=730848&r2=730849&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/DefinitionUtil.java Fri Jan  2 14:11:27 2009
@@ -134,6 +134,7 @@
 		if(clazz.isPrimitive() || clazz.isArray())
 		{
 			component.getTypes().add(clazz);
+			component.getTypes().add(Object.class);
 		}
 		else
 		{
@@ -375,6 +376,11 @@
 		ProducerComponentImpl<T> component = new ProducerComponentImpl<T>(parent, returnType);
 		component.setCreatorMethod(method);
 		
+		if(returnType.isPrimitive())
+		{
+			component.setNullable(false);
+		}
+		
 		defineSerializable(component);
 		
 		Class<? extends Annotation> deploymentType = DefinitionUtil.defineDeploymentType(component, method.getAnnotations(), "There are more than one @DeploymentType annotation in the component class : " + component.getReturnType().getName());

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java?rev=730849&r1=730848&r2=730849&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/config/WebBeansContainerDeployer.java Fri Jan  2 14:11:27 2009
@@ -30,8 +30,10 @@
 import javax.webbeans.ScopeType;
 import javax.webbeans.Specializes;
 import javax.webbeans.manager.Bean;
+import javax.webbeans.manager.Manager;
 
 import org.apache.webbeans.WebBeansConstants;
+import org.apache.webbeans.annotation.InitializedManagerLiteral;
 import org.apache.webbeans.component.ComponentImpl;
 import org.apache.webbeans.component.WebBeansType;
 import org.apache.webbeans.container.ManagerImpl;
@@ -107,6 +109,11 @@
 		{
 			throw new WebBeansDeploymentException(e);
 		}
+		finally
+		{
+			Manager manager = ManagerImpl.getManager();
+			manager.fireEvent(manager, new Annotation[]{new InitializedManagerLiteral()});
+		}
 	}
 	
 	private void deployFromClassPath(WebBeansScanner scanner) throws ClassNotFoundException

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java?rev=730849&r1=730848&r2=730849&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ManagerImpl.java Fri Jan  2 14:11:27 2009
@@ -261,7 +261,9 @@
 				isSetOnThis = true;
 			}
 			
-			if(!bean.getScopeType().equals(Dependent.class))
+			
+			/*@ScopeType is normal*/
+			if(WebBeansUtil.isScopeTypeNormal(bean.getScopeType()))
 			{
 				if(this.proxyMap.containsKey(bean))
 				{
@@ -274,7 +276,7 @@
 					this.proxyMap.put(bean, instance);
 				}
 			}
-			
+			/*@ScopeType is not normal*/
 			else
 			{
 				context = getContext(bean.getScopeType());

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ResolutionUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ResolutionUtil.java?rev=730849&r1=730848&r2=730849&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ResolutionUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/container/ResolutionUtil.java Fri Jan  2 14:11:27 2009
@@ -21,12 +21,15 @@
 import java.util.Set;
 
 import javax.webbeans.AmbiguousDependencyException;
+import javax.webbeans.ScopeType;
 import javax.webbeans.UnsatisfiedDependencyException;
 import javax.webbeans.manager.Bean;
 
+import org.apache.webbeans.component.AbstractComponent;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
 import org.apache.webbeans.util.ClassUtil;
+import org.apache.webbeans.util.WebBeansUtil;
 
 public final class ResolutionUtil
 {
@@ -63,8 +66,8 @@
 			throw new AmbiguousDependencyException("There is more than one api type with : " + type.getName());
 		}
 		
-		//Bean<T> bean = resolvedSet.iterator().next();
-		//WebBeansUtil.checkUnproxiableApiType((AbstractComponent<?>), bean.getScopeType().getAnnotation(ScopeType.class));
+		Bean<T> bean = resolvedSet.iterator().next();
+		WebBeansUtil.checkUnproxiableApiType(bean, bean.getScopeType().getAnnotation(ScopeType.class));
 		
 	}
 }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java?rev=730849&r1=730848&r2=730849&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/event/NotificationManager.java Fri Jan  2 14:11:27 2009
@@ -40,6 +40,7 @@
 import org.apache.webbeans.logger.WebBeansLogger;
 import org.apache.webbeans.util.AnnotationUtil;
 import org.apache.webbeans.util.Asserts;
+import org.apache.webbeans.util.JNDIUtil;
 
 @SuppressWarnings("unchecked")
 public final class NotificationManager implements Synchronization
@@ -48,8 +49,6 @@
 	
 	private Map<Class<?>, Set<ObserverImpl<?>>> observers = new ConcurrentHashMap<Class<?>, Set<ObserverImpl<?>>>();
 		
-	private TransactionManager transactionManager;
-	
 	private Set<TransactionalNotifier> transactionSet = new CopyOnWriteArraySet<TransactionalNotifier>();
 	
 	public NotificationManager()
@@ -206,7 +205,7 @@
 					TransactionalObserverType type = beanObserver.getType();
 					if(!type.equals(TransactionalObserverType.NONE))
 					{
-						Transaction transaction = this.transactionManager.getTransaction();
+						Transaction transaction = JNDIUtil.getCurrentTransactionManager().getTransaction();
 						if(transaction != null)
 						{
 							transaction.registerSynchronization(this);
@@ -238,7 +237,8 @@
 						{
 							observer.notify(event);
 						}
-					}else
+					}
+					else
 					{
 						observer.notify(event);
 					}
@@ -294,38 +294,24 @@
 		{
 			Iterator<TransactionalNotifier> it = this.transactionSet.iterator();
 			
-			if(status == Status.STATUS_COMMITTED)
+			while(it.hasNext())
 			{
-				//Call @AfterTransactionSuccess
-				while(it.hasNext())
+				TransactionalNotifier notifier = it.next();				
+
+				notifier.notifyAfterCompletion();
+
+				if(status == Status.STATUS_COMMITTED)
 				{
-					TransactionalNotifier notifier = it.next();
 					notifier.notifyAfterCompletionSuccess();
+
 				}
-				
-			}
-			else if(status == Status.STATUS_ROLLEDBACK)
-			{
-				//Call @AfterTransactionFailure
-				while(it.hasNext())
+				else if(status == Status.STATUS_ROLLEDBACK)
 				{
-					TransactionalNotifier notifier = it.next();
 					notifier.notifyAfterCompletionFailure();
 				}
+					
+			}			
 				
-			}
-			else
-			{
-				//Call @AfterTransactionCompletion
-				while(it.hasNext())
-				{
-					TransactionalNotifier notifier = it.next();
-					notifier.notifyAfterCompletion();
-				}
-				
-			}
-			
-			
 		}catch(Throwable e)
 		{
 			logger.error("Exception is occured in the transational observer ",e);

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java?rev=730849&r1=730848&r2=730849&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/inject/AbstractInjectable.java Fri Jan  2 14:11:27 2009
@@ -67,6 +67,7 @@
 	{
 		DependentContext context = (DependentContext)ManagerImpl.getManager().getContext(Dependent.class);
 		boolean isSetOnThis = false;
+		
 		try
 		{
 			if(!context.isActive())
@@ -89,10 +90,14 @@
 			ResolutionUtil.checkResolvedBeans(componentSet, type);
 			
 			AbstractComponent<?> component = (AbstractComponent<?>)componentSet.iterator().next();
+			
+			/*Nullable check*/
+			WebBeansUtil.checkNullable(type, component);
 
 			if (component.getScopeType().equals(Dependent.class))
 			{
 				return injectForDependent(component);
+				
 			} else
 			{
 				return injectForComponent(component);

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/JNDIUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/JNDIUtil.java?rev=730849&r1=730848&r2=730849&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/JNDIUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/JNDIUtil.java Fri Jan  2 14:11:27 2009
@@ -18,6 +18,7 @@
 
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
+import javax.transaction.TransactionManager;
 
 import org.apache.webbeans.exception.WebBeansException;
 import org.apache.webbeans.logger.WebBeansLogger;
@@ -26,6 +27,8 @@
 {
 	private static InitialContext initialContext = null;
 	
+	private static TransactionManager transactionManager = null;
+	
 	private static final WebBeansLogger LOGGER = WebBeansLogger.getLogger(JNDIUtil.class);
 	
 	static
@@ -82,5 +85,23 @@
 		}
 		
 	}
+	
+	public static TransactionManager getCurrentTransactionManager()
+	{
+		if(transactionManager == null)
+		{
+			try
+			{
+				transactionManager = (TransactionManager)getInitialContext().lookup("java:/TransactionManager");
+				
+			} catch (NamingException e)
+			{
+				LOGGER.error("Unable to get TransactionManager",e);
+				throw new WebBeansException(e);
+			}
+		}
+		
+		return transactionManager;
+	}
 
 }

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java?rev=730849&r1=730848&r2=730849&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/util/WebBeansUtil.java Fri Jan  2 14:11:27 2009
@@ -58,6 +58,7 @@
 import javax.webbeans.Named;
 import javax.webbeans.New;
 import javax.webbeans.Fires;
+import javax.webbeans.NullableDependencyException;
 import javax.webbeans.Observes;
 import javax.webbeans.Produces;
 import javax.webbeans.RequestScoped;
@@ -469,6 +470,7 @@
 		comp.addBindingType(new NewLiteral());
 		comp.setName(null);
 		comp.addApiType(clazz);
+		comp.addApiType(Object.class);
 		comp.setType(new ProductionLiteral());
 
 		return comp;
@@ -511,6 +513,7 @@
 		managerComponent.setType(new StandardLiteral());
 		managerComponent.addBindingType(new CurrentLiteral());
 		managerComponent.addApiType(Manager.class);
+		managerComponent.addApiType(Object.class);
 		
 		return managerComponent;
 	}
@@ -521,6 +524,7 @@
 		
 		conversationComp.addApiType(Conversation.class);
 		conversationComp.addApiType(ConversationImpl.class);
+		conversationComp.addApiType(Object.class);
 		conversationComp.setImplScopeType(new RequestedScopeLiteral());
 		conversationComp.setType(new StandardLiteral());
 		conversationComp.addBindingType(new CurrentLiteral());
@@ -1121,21 +1125,57 @@
 		}
 	}
 
-	public static void checkUnproxiableApiType(Class<?> apiType, ScopeType scopeType)
+	public static void checkUnproxiableApiType(Bean<?> bean, ScopeType scopeType)
 	{
-		Asserts.assertNotNull("apiType", "apiType parameter can not be null");
+		Asserts.assertNotNull("bean", "bean parameter can not be null");
 		Asserts.assertNotNull(scopeType, "scopeType parameter can not be null");
 
-		Constructor<?> cons = ClassUtil.isContaintNoArgConstructor(apiType);
-		if (ClassUtil.isPrivate(cons.getModifiers()) || 
-				ClassUtil.isPrimitive(apiType) || 
-				ClassUtil.isArray(apiType) || 
-				ClassUtil.isFinal(apiType.getModifiers()) 
-				|| ClassUtil.hasFinalMethod(apiType))
+		Set<Class<?>> types = bean.getTypes();
+		Class<?> superClass = null;
+		for(Class<?> type : types)
+		{
+	        if(!type.isInterface())
+	        {
+				if ((superClass == null) 
+		        		|| (superClass.isAssignableFrom(type) && type != Object.class ))
+		         {
+		        	superClass = type;
+		         }
+	
+	        }			
+		}
+				
+		if(superClass != null)
+		{
+			Constructor<?> cons = ClassUtil.isContaintNoArgConstructor(superClass);
+			
+			if ( ClassUtil.isPrimitive(superClass) 
+					|| ClassUtil.isArray(superClass) 
+					|| ClassUtil.isFinal(superClass.getModifiers()) 
+					|| ClassUtil.hasFinalMethod(superClass)
+					|| (cons == null || ClassUtil.isPrivate(cons.getModifiers())))
+			{
+				if (scopeType.normal())
+				{
+					throw new UnproxyableDependencyException("WebBeans with api type with normal scope must be proxiable to inject, but class : " + superClass.getName() + " is not proxiable type");
+				}
+			}
+			
+		}
+		
+	}
+	
+	
+	public static void checkNullable(Class<?> type ,AbstractComponent<?> component)
+	{
+		Asserts.assertNotNull(type,"type parameter can not be null");
+		Asserts.assertNotNull(component,"component parameter can not be null");
+		
+		if(type.isPrimitive())
 		{
-			if (!scopeType.normal())
+			if(component.isNullable())
 			{
-				throw new UnproxyableDependencyException("WebBeans with api type with normal scope must be proxiable to inject, but class : " + apiType.getName() + " is not proxiable type");
+				throw new NullableDependencyException("Injection point for primitive type resolves webbeans component with return type : " + component.getReturnType().getName() + " with nullable");
 			}
 		}
 	}
@@ -1301,4 +1341,28 @@
 			}			
 		}		
 	}
+	
+	public static boolean isScopeTypeNormal(Class<? extends Annotation> scopeType)
+	{
+		Asserts.assertNotNull(scopeType, "scopeType argument can not be null");
+		
+		if(scopeType.isAnnotationPresent(ScopeType.class))
+		{
+			ScopeType scope = scopeType.getAnnotation(ScopeType.class);
+			if(scope.normal())
+			{
+				return true;
+			}
+			
+			else
+			{
+				return false;
+			}
+		}
+		else
+		{
+			throw new IllegalArgumentException("scopeType argument must be annotated with @ScopeType");
+		}
+		
+	}
 }
\ No newline at end of file

Modified: incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java
URL: http://svn.apache.org/viewvc/incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java?rev=730849&r1=730848&r2=730849&view=diff
==============================================================================
--- incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java (original)
+++ incubator/openwebbeans/trunk/webbeans-impl/src/main/java/org/apache/webbeans/xml/XMLDefinitionUtil.java Fri Jan  2 14:11:27 2009
@@ -583,8 +583,15 @@
 			
 			producerComponentImpl.setActualTypeArguments(model.getActualTypeArguments());
 			producerComponentImpl.addApiType(model.getInjectionClassType());
+			
+			if(model.getInjectionClassType().isPrimitive())
+			{
+				producerComponentImpl.setNullable(false);
+			}
 		}
 		
+		producerComponentImpl.addApiType(Object.class);
+		
 		/*Set creator method*/
 		producerComponentImpl.setCreatorMethod(producesMethod);