myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dennisby...@apache.org
Subject svn commit: r511311 - in /myfaces/core/branches/jsf12/impl/src: main/java/org/apache/myfaces/config/ main/java/org/apache/myfaces/config/annotation/ test/java/org/apache/myfaces/config/annotation/
Date Sat, 24 Feb 2007 17:26:45 GMT
Author: dennisbyrne
Date: Sat Feb 24 09:26:43 2007
New Revision: 511311

URL: http://svn.apache.org/viewvc?view=rev&rev=511311
Log:
12 passing tests for @PreDestroy, refactored AnnotatedManagedBeanHandler
@PreDestroy still not being called by the implementation though

Modified:
    myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java
    myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandler.java
    myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedExceptionManagedBeanHandlerTestCase.java
    myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandlerTestCase.java
    myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedRuntimeExceptionManagedBeanHandlerTestCase.java

Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java?view=diff&rev=511311&r1=511310&r2=511311
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java
(original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/ManagedBeanBuilder.java
Sat Feb 24 09:26:43 2007
@@ -67,7 +67,7 @@
 
         final AnnotatedManagedBeanHandler handler = new AnnotatedManagedBeanHandler(bean,
beanConfiguration);
         
-        final boolean threwUnchecked = handler.run();
+        final boolean threwUnchecked = handler.invokePostConstruct();
         
         if(threwUnchecked)
         	return null;
@@ -302,7 +302,6 @@
     {
         String beanName = getFirstSegment(expression);
         ExternalContext externalContext = facesContext.getExternalContext();
-
         
 		// check scope objects
         if (beanName.equalsIgnoreCase("requestScope")) {

Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandler.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandler.java?view=diff&rev=511311&r1=511310&r2=511311
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandler.java
(original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandler.java
Sat Feb 24 09:26:43 2007
@@ -25,6 +25,10 @@
 
 	private ManagedBean beanConfiguration;
 
+	private static final String POST_CONSTRUCT = "javax.annotation.PostConstruct";
+	
+	private static final String PRE_DESTROY = "javax.annotation.PreDestroy";
+
 	public AnnotatedManagedBeanHandler(Object managedBean, ManagedBean beanConfiguration) {
 
 		if (managedBean == null) {
@@ -40,25 +44,37 @@
 
 	}
 
-	public boolean run() {
+	public boolean invokePreDestroy() {
+		return invoke(PRE_DESTROY);
+	}
+
+	public boolean invokePostConstruct() {
+		return invoke(POST_CONSTRUCT);
+	}
+	
+	private boolean invoke(String annotationName) {
 
 		boolean threwUnchecked = false;
 
 		if (ManagedBeanBuilder.NONE.equals(beanConfiguration.getManagedBeanScope())) {
-			; // this only applies to a, s, and r scope beans
+			if(log.isDebugEnabled())
+				log.debug( annotationName + " not processed for managed bean " 
+						+ beanConfiguration.getManagedBeanName() 
+						+ " because it is not in request, session, or "
+						+ "application scope.  See section 5.4 of the JSF 1.3 spec"); 
 		} else {
-			threwUnchecked = run(managedBean.getClass().getMethods());
+			threwUnchecked = invoke(managedBean.getClass().getMethods(), annotationName);
 		}
 
 		return threwUnchecked;
 	}
 
-	private boolean run(Method[] methods) {
+	private boolean invoke(Method[] methods, String annotationName) {
 
 		boolean threwUnchecked = false;
 
 		for (Method method : methods)
-			if (run(method)) {
+			if (invoke(method, annotationName)) {
 				threwUnchecked = true;
 				break;
 			}// break if we invoke method ? or invoke all w/ annoation?
@@ -66,16 +82,19 @@
 		return threwUnchecked;
 	}
 
-	private boolean run(Method method) {
+	private boolean invoke(Method method, String annotationName) {
 
 		Annotation[] annotations = method.getAnnotations();
 		boolean threwUnchecked = false;
 
-		for (Annotation annotation : annotations) {
-			if (isPostConstruct(annotation)) {
-				if (run(annotation, method)) {
+		for (Annotation annotation : annotations) 
+		{
+			if (isMatch(annotation, annotationName)) 
+			{
+				if (invoke(annotation, method)) 
+				{
 					threwUnchecked = true;
-					break; // spec says not to call anymore methods on this
+					break; // spec says not to call any more methods on this
 				}
 			}
 		}
@@ -83,13 +102,13 @@
 		return threwUnchecked;
 	}
 
-	private boolean run(Annotation annotation, Method method) {
+	private boolean invoke(Annotation annotation, Method method) {
 
 		boolean threwUnchecked = true; // start w/ pessimism
 
 		try {
 
-			method.invoke(managedBean, null);
+			method.invoke(managedBean, null); // what do we do for parameters?
 
 			threwUnchecked = false;
 
@@ -125,12 +144,12 @@
 				+ " See section 5.4.1 of the JSF specification.";
 	}
 
-	private boolean isPostConstruct(Annotation annotation) {
+	private boolean isMatch(Annotation annotation, String annotationName) {
 
 		final Class<? extends Annotation> annotationType = annotation.annotationType();
 		final String name = annotationType.getName();
 		// use the literal String because we want to avoid ClassDefNotFoundError
-		return "javax.annotation.PostConstruct".equals(name);
+		return annotationName.equals(name);
 
 	}
 }

Modified: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedExceptionManagedBeanHandlerTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedExceptionManagedBeanHandlerTestCase.java?view=diff&rev=511311&r1=511310&r2=511311
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedExceptionManagedBeanHandlerTestCase.java
(original)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedExceptionManagedBeanHandlerTestCase.java
Sat Feb 24 09:26:43 2007
@@ -24,65 +24,139 @@
 		handler = new AnnotatedManagedBeanHandler(managedBean, managedBeanConf);
 	}
 
-	public void testShouldNotBlowUpForNoneScope() {
+	public void testPostConstructShouldNotBlowUpForNoneScope() {
 
 		managedBeanConf.setScope(ManagedBeanBuilder.NONE);
 
 		boolean exceptionThrown = false;
 		
 		try {
-			handler.run();
+			handler.invokePostConstruct();
 		} catch (Exception e) {
 			exceptionThrown = true;			
 		}
 
 		assertFalse(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
 		assertFalse(exceptionThrown);
 	}
 
-	public void testShouldBlowUpForRequestScope() {
+	public void testPreDestroyShouldNotBlowUpForNoneScope() {
+
+		managedBeanConf.setScope(ManagedBeanBuilder.NONE);
+
+		boolean exceptionThrown = false;
+		
+		try {
+			handler.invokePreDestroy();
+		} catch (Exception e) {
+			exceptionThrown = true;			
+		}
+
+		assertFalse(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
+		assertFalse(exceptionThrown);
+	}
+	
+	public void testPostConstructShouldBlowUpForRequestScope() {
 
 		managedBeanConf.setScope(ManagedBeanBuilder.REQUEST);
 
 		boolean exceptionThrown = false;
 		
 		try {
-			handler.run();
+			handler.invokePostConstruct();
 		} catch (Exception e) {
 			exceptionThrown = true;			
 		}
 
 		assertTrue(exceptionThrown);
+		assertTrue(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
 	}
 
-	public void testShouldBlowUpForSessionScope() {
+	public void testPreDestroyShouldBlowUpForRequestScope() {
+
+		managedBeanConf.setScope(ManagedBeanBuilder.REQUEST);
+
+		boolean exceptionThrown = false;
+		
+		try {
+			handler.invokePreDestroy();
+		} catch (Exception e) {
+			exceptionThrown = true;			
+		}
+
+		assertTrue(exceptionThrown);
+		assertFalse(managedBean.isPostConstructCalled());
+		assertTrue(managedBean.isPreDestroyCalled());
+	}
+	
+	public void testPostConstructShouldBlowUpForSessionScope() {
 
 		managedBeanConf.setScope(ManagedBeanBuilder.SESSION);
 
 		boolean exceptionThrown = false;
 		
 		try {
-			handler.run();
+			handler.invokePostConstruct();
 		} catch (Exception e) {
 			exceptionThrown = true;			
 		}
 
 		assertTrue(exceptionThrown);
+		assertTrue(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
 	}
 
-	public void testShouldBlowUpForApplicationScope() {
+	public void testPreDestroyShouldBlowUpForSessionScope() {
+
+		managedBeanConf.setScope(ManagedBeanBuilder.SESSION);
+
+		boolean exceptionThrown = false;
+		
+		try {
+			handler.invokePreDestroy();
+		} catch (Exception e) {
+			exceptionThrown = true;			
+		}
+
+		assertTrue(exceptionThrown);
+		assertFalse(managedBean.isPostConstructCalled());
+		assertTrue(managedBean.isPreDestroyCalled());
+	}
+	
+	public void testPostConstructShouldBlowUpForApplicationScope() {
 
 		managedBeanConf.setScope(ManagedBeanBuilder.APPLICATION);
 
 		boolean exceptionThrown = false;
 		
 		try {
-			handler.run();
+			handler.invokePostConstruct();
 		} catch (Exception e) {
 			exceptionThrown = true;			
 		}
 
 		assertTrue(exceptionThrown);
+		assertTrue(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
 	}
 
+	public void testPreDestroyShouldBlowUpForApplicationScope() {
+
+		managedBeanConf.setScope(ManagedBeanBuilder.APPLICATION);
+
+		boolean exceptionThrown = false;
+		
+		try {
+			handler.invokePreDestroy();
+		} catch (Exception e) {
+			exceptionThrown = true;			
+		}
+
+		assertTrue(exceptionThrown);
+		assertFalse(managedBean.isPostConstructCalled());
+		assertTrue(managedBean.isPreDestroyCalled());
+	}
 }

Modified: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandlerTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandlerTestCase.java?view=diff&rev=511311&r1=511310&r2=511311
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandlerTestCase.java
(original)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedManagedBeanHandlerTestCase.java
Sat Feb 24 09:26:43 2007
@@ -22,40 +22,84 @@
 		handler = new AnnotatedManagedBeanHandler(managedBean, managedBeanConf);
 	}
 
-	public void testShouldNotInvokeForNoneScope() {
+	public void testPostConstructShouldNotInvokeForNoneScope() {
 
 		managedBeanConf.setScope(ManagedBeanBuilder.NONE);
-		boolean threwUnchecked = handler.run();
+		boolean threwUnchecked = handler.invokePostConstruct();
 		
 		assertFalse(threwUnchecked);
 		assertFalse(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
 	}
 
-	public void testShouldInvokeForRequestScope() {
+	public void testPreDestroyShouldNotInvokeForNoneScope() {
+
+		managedBeanConf.setScope(ManagedBeanBuilder.NONE);
+		boolean threwUnchecked = handler.invokePreDestroy();
+		
+		assertFalse(threwUnchecked);
+		assertFalse(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
+	}
+	
+	public void testPostConstructShouldInvokeForRequestScope() {
 		
 		managedBeanConf.setScope(ManagedBeanBuilder.REQUEST);
-		boolean threwUnchecked = handler.run();
+		boolean threwUnchecked = handler.invokePostConstruct();
 		
 		assertFalse(threwUnchecked);
 		assertTrue(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
 	}
 
-	public void testShouldInvokeForSessionScope() {
+	public void testPreDestroyShouldInvokeForRequestScope() {
+		
+		managedBeanConf.setScope(ManagedBeanBuilder.REQUEST);
+		boolean threwUnchecked = handler.invokePreDestroy();
+		
+		assertFalse(threwUnchecked);
+		assertFalse(managedBean.isPostConstructCalled());
+		assertTrue(managedBean.isPreDestroyCalled());
+	}
+	
+	public void testPostConstructShouldInvokeForSessionScope() {
 		
 		managedBeanConf.setScope(ManagedBeanBuilder.SESSION);
-		boolean threwUnchecked = handler.run();
+		boolean threwUnchecked = handler.invokePostConstruct();
 		
 		assertFalse(threwUnchecked);
 		assertTrue(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
 	}
 
-	public void testShouldInvokeForApplicationScope() {
+	public void testPreDestroyShouldInvokeForSessionScope() {
+		
+		managedBeanConf.setScope(ManagedBeanBuilder.SESSION);
+		boolean threwUnchecked = handler.invokePreDestroy();
+		
+		assertFalse(threwUnchecked);
+		assertFalse(managedBean.isPostConstructCalled());
+		assertTrue(managedBean.isPreDestroyCalled());
+	}
+	
+	public void testPostConstructShouldInvokeForApplicationScope() {
 		
 		managedBeanConf.setScope(ManagedBeanBuilder.APPLICATION);
-		boolean threwUnchecked = handler.run();
+		boolean threwUnchecked = handler.invokePostConstruct();
 		
 		assertFalse(threwUnchecked);
 		assertTrue(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
 	}
 
+	public void testPreDestroyShouldInvokeForApplicationScope() {
+		
+		managedBeanConf.setScope(ManagedBeanBuilder.APPLICATION);
+		boolean threwUnchecked = handler.invokePreDestroy();
+		
+		assertFalse(threwUnchecked);
+		assertFalse(managedBean.isPostConstructCalled());
+		assertTrue(managedBean.isPreDestroyCalled());
+	}
+	
 }

Modified: myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedRuntimeExceptionManagedBeanHandlerTestCase.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedRuntimeExceptionManagedBeanHandlerTestCase.java?view=diff&rev=511311&r1=511310&r2=511311
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedRuntimeExceptionManagedBeanHandlerTestCase.java
(original)
+++ myfaces/core/branches/jsf12/impl/src/test/java/org/apache/myfaces/config/annotation/AnnotatedRuntimeExceptionManagedBeanHandlerTestCase.java
Sat Feb 24 09:26:43 2007
@@ -22,40 +22,83 @@
 		handler = new AnnotatedManagedBeanHandler(managedBean, managedBeanConf);
 	}
 	
-	public void testShouldNotInvokeForNoneScope() {
+	public void testPostConstructShouldNotInvokeForNoneScope() {
 
 		managedBeanConf.setScope(ManagedBeanBuilder.NONE);
-		boolean threwUnchecked = handler.run();
+		boolean threwUnchecked = handler.invokePostConstruct();
 		
 		assertFalse(threwUnchecked);
 		assertFalse(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
 	}
 
-	public void testShouldInvokeForRequestScope() {
+	public void testPreDestroyShouldNotInvokeForNoneScope() {
+
+		managedBeanConf.setScope(ManagedBeanBuilder.NONE);
+		boolean threwUnchecked = handler.invokePreDestroy();
+		
+		assertFalse(threwUnchecked);
+		assertFalse(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
+	}
+	
+	public void testPostConstructShouldInvokeForRequestScope() {
 		
 		managedBeanConf.setScope(ManagedBeanBuilder.REQUEST);
-		boolean threwUnchecked = handler.run();
+		boolean threwUnchecked = handler.invokePostConstruct();
 		
 		assertTrue(threwUnchecked);
 		assertTrue(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
 	}
 
-	public void testShouldInvokeForSessionScope() {
+	public void testPreDestroyShouldInvokeForRequestScope() {
+		
+		managedBeanConf.setScope(ManagedBeanBuilder.REQUEST);
+		boolean threwUnchecked = handler.invokePreDestroy();
+		
+		assertTrue(threwUnchecked);
+		assertFalse(managedBean.isPostConstructCalled());
+		assertTrue(managedBean.isPreDestroyCalled());
+	}
+	
+	public void testPostConstructShouldInvokeForSessionScope() {
 		
 		managedBeanConf.setScope(ManagedBeanBuilder.SESSION);
-		boolean threwUnchecked = handler.run();
+		boolean threwUnchecked = handler.invokePostConstruct();
 		
 		assertTrue(threwUnchecked);
 		assertTrue(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
 	}
 
-	public void testShouldInvokeForApplicationScope() {
+	public void testPreDestroyShouldInvokeForSessionScope() {
+		
+		managedBeanConf.setScope(ManagedBeanBuilder.SESSION);
+		boolean threwUnchecked = handler.invokePreDestroy();
+		
+		assertTrue(threwUnchecked);
+		assertFalse(managedBean.isPostConstructCalled());
+		assertTrue(managedBean.isPreDestroyCalled());
+	}
+	
+	public void testPostConstructShouldInvokeForApplicationScope() {
 		
 		managedBeanConf.setScope(ManagedBeanBuilder.APPLICATION);
-		boolean threwUnchecked = handler.run();
+		boolean threwUnchecked = handler.invokePostConstruct();
 		
 		assertTrue(threwUnchecked);
 		assertTrue(managedBean.isPostConstructCalled());
+		assertFalse(managedBean.isPreDestroyCalled());
+	}
+
+	public void testPreDestroyShouldInvokeForApplicationScope() {
+		
+		managedBeanConf.setScope(ManagedBeanBuilder.APPLICATION);
+		boolean threwUnchecked = handler.invokePreDestroy();
+		
+		assertTrue(threwUnchecked);
+		assertFalse(managedBean.isPostConstructCalled());
+		assertTrue(managedBean.isPreDestroyCalled());
 	}
-	
 }



Mime
View raw message