You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by bo...@apache.org on 2007/03/06 23:37:42 UTC
svn commit: r515331 - in /myfaces:
core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/
current12/test-webapp/src/main/java/org/apache/myfaces/blank/
current12/test-webapp/src/main/webapp/WEB-INF/
Author: bommel
Date: Tue Mar 6 14:37:41 2007
New Revision: 515331
URL: http://svn.apache.org/viewvc?view=rev&rev=515331
Log:
(MYFACES-1246)
some enhancements and todo's
Modified:
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationProcessor.java
myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationProcessor.java
myfaces/current12/test-webapp/src/main/java/org/apache/myfaces/blank/HelloWorldBacking.java
myfaces/current12/test-webapp/src/main/webapp/WEB-INF/web.xml
Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationProcessor.java?view=diff&rev=515331&r1=515330&r2=515331
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationProcessor.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/NoInjectionAnnotationProcessor.java Tue Mar 6 14:37:41 2007
@@ -26,6 +26,11 @@
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+/**
+ * See SRV.14.5 Servlet Specification Version 2.5 JSR 154
+ * and Common Annotations for the Java Platform JSR 250
+
+ */
public class NoInjectionAnnotationProcessor implements AnnotationProcessor
{
@@ -37,12 +42,20 @@
throws IllegalAccessException, InvocationTargetException
{
+ // TODO the servlet spec is not clear about searching in superclass??
+
Method[] methods = instance.getClass().getDeclaredMethods();
Method postConstruct = null;
for (Method method : methods)
{
if (method.isAnnotationPresent(PostConstruct.class))
{
+ // a method that does not take any arguments
+ // the method must not be static
+ // must not throw any checked expections
+ // the return value must be void
+ // the method may be public, protected, package private or private
+
if ((postConstruct != null)
|| (method.getParameterTypes().length != 0)
|| (Modifier.isStatic(method.getModifiers()))
@@ -55,19 +68,10 @@
}
}
- // At the end the postconstruct annotated
- // method is invoked
- if (postConstruct != null)
- {
- boolean accessibility = postConstruct.isAccessible();
- postConstruct.setAccessible(true);
- postConstruct.invoke(instance);
- postConstruct.setAccessible(accessibility);
- }
+ invokeAnnotatedMethod(postConstruct, instance);
}
-
/**
* Call preDestroy method on the specified instance.
*/
@@ -75,12 +79,20 @@
throws IllegalAccessException, InvocationTargetException
{
+ // TODO the servlet spec is not clear about searching in superclass??
+ // May be only check non private fields and methods
Method[] methods = instance.getClass().getDeclaredMethods();
Method preDestroy = null;
for (Method method : methods)
{
if (method.isAnnotationPresent(PreDestroy.class))
{
+ // must not throw any checked expections
+ // the method must not be static
+ // must not throw any checked expections
+ // the return value must be void
+ // the method may be public, protected, package private or private
+
if ((preDestroy != null)
|| (method.getParameterTypes().length != 0)
|| (Modifier.isStatic(method.getModifiers()))
@@ -93,15 +105,7 @@
}
}
- // At the end the postconstruct annotated
- // method is invoked
- if (preDestroy != null)
- {
- boolean accessibility = preDestroy.isAccessible();
- preDestroy.setAccessible(true);
- preDestroy.invoke(instance);
- preDestroy.setAccessible(accessibility);
- }
+ invokeAnnotatedMethod(preDestroy, instance);
}
@@ -113,6 +117,20 @@
throws IllegalAccessException, InvocationTargetException, NamingException
{
+ }
+
+ private void invokeAnnotatedMethod(Method method, Object instance)
+ throws IllegalAccessException, InvocationTargetException
+ {
+ // At the end the annotated
+ // method is invoked
+ if (method != null)
+ {
+ boolean accessibility = method.isAccessible();
+ method.setAccessible(true);
+ method.invoke(instance);
+ method.setAccessible(accessibility);
+ }
}
}
Modified: myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationProcessor.java
URL: http://svn.apache.org/viewvc/myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationProcessor.java?view=diff&rev=515331&r1=515330&r2=515331
==============================================================================
--- myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationProcessor.java (original)
+++ myfaces/core/branches/jsf12/impl/src/main/java/org/apache/myfaces/config/annotation/ResourceAnnotationProcessor.java Tue Mar 6 14:37:41 2007
@@ -28,6 +28,7 @@
{
protected Context context;
+ private static final String JAVA_COMP_ENV = "java:comp/env/";
public ResourceAnnotationProcessor(Context context)
{
@@ -48,20 +49,34 @@
return;
}
+ checkAnnotation(instance.getClass(), instance);
+
+ /* TODO the servlet spec is not clear about searching in superclass??
+ * May be only check non private fields and methods
+ Class superclass = instance.getClass().getSuperclass();
+ while (superclass != null && (!superclass.equals(Object.class)))
+ {
+ checkAnnotation(superclass, instance);
+ superclass = superclass.getSuperclass();
+ } */
+ }
+
+ private void checkAnnotation(Class clazz, Object instance)
+ throws NamingException, IllegalAccessException, InvocationTargetException
+ {
// Initialize fields annotations
- Field[] fields = instance.getClass().getDeclaredFields();
+ Field[] fields = clazz.getDeclaredFields();
for (Field field : fields)
{
checkFieldAnnotation(field, instance);
}
// Initialize methods annotations
- Method[] methods = instance.getClass().getDeclaredMethods();
+ Method[] methods = clazz.getDeclaredMethods();
for (Method method : methods)
{
checkMethodAnnotation(method, instance);
}
-
}
protected void checkMethodAnnotation(Method method, Object instance)
@@ -93,19 +108,19 @@
{
Object lookedupResource;
- boolean accessibility ;
- if ((name != null) &&
- (name.length() > 0))
+ if ((name != null) && (name.length() > 0))
{
- lookedupResource = context.lookup(name);
+ // TODO local or global JNDI
+ lookedupResource = context.lookup(JAVA_COMP_ENV + name);
}
else
{
- lookedupResource = context.lookup(instance.getClass().getName() + "/" + field.getName());
+ // TODO local or global JNDI
+ lookedupResource = context.lookup(JAVA_COMP_ENV + instance.getClass().getName() + "/" + field.getName());
}
- accessibility = field.isAccessible();
+ boolean accessibility = field.isAccessible();
field.setAccessible(true);
field.set(instance, lookedupResource);
field.setAccessible(accessibility);
@@ -128,20 +143,20 @@
}
Object lookedupResource;
- boolean accessibility;
- if ((name != null) &&
- (name.length() > 0))
+ if ((name != null) && (name.length() > 0))
{
- lookedupResource = context.lookup(name);
+ // TODO local or global JNDI
+ lookedupResource = context.lookup(JAVA_COMP_ENV + name);
}
else
{
+ // TODO local or global JNDI
lookedupResource =
- context.lookup(instance.getClass().getName() + "/" + method.getName().substring(3));
+ context.lookup(JAVA_COMP_ENV + instance.getClass().getName() + "/" + method.getName().substring(3));
}
- accessibility = method.isAccessible();
+ boolean accessibility = method.isAccessible();
method.setAccessible(true);
method.invoke(instance, lookedupResource);
method.setAccessible(accessibility);
Modified: myfaces/current12/test-webapp/src/main/java/org/apache/myfaces/blank/HelloWorldBacking.java
URL: http://svn.apache.org/viewvc/myfaces/current12/test-webapp/src/main/java/org/apache/myfaces/blank/HelloWorldBacking.java?view=diff&rev=515331&r1=515330&r2=515331
==============================================================================
--- myfaces/current12/test-webapp/src/main/java/org/apache/myfaces/blank/HelloWorldBacking.java (original)
+++ myfaces/current12/test-webapp/src/main/java/org/apache/myfaces/blank/HelloWorldBacking.java Tue Mar 6 14:37:41 2007
@@ -23,11 +23,12 @@
import javax.faces.event.ActionEvent;
import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
/**
* A typical simple backing bean, that is backed to <code>helloworld.jsp</code>
*
- * @author <a href="mailto:matzew@apache.org">Matthias We�endorf</a>
+ * @author <a href="mailto:matzew@apache.org">Matthias WeÃendorf</a>
*/
public class HelloWorldBacking {
@@ -35,7 +36,8 @@
//properties
private String name;
private String greeting;
-
+ @Resource(name="testDouble")
+ private Double testDouble;
/**
* default empty constructor
*/
@@ -46,6 +48,7 @@
@PostConstruct()
public void postConstruct() {
log.error("PostConstruct");
+ log.error("Test Double " + testDouble);
}
//-------------------getter & setter
Modified: myfaces/current12/test-webapp/src/main/webapp/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/myfaces/current12/test-webapp/src/main/webapp/WEB-INF/web.xml?view=diff&rev=515331&r1=515330&r2=515331
==============================================================================
--- myfaces/current12/test-webapp/src/main/webapp/WEB-INF/web.xml (original)
+++ myfaces/current12/test-webapp/src/main/webapp/WEB-INF/web.xml Tue Mar 6 14:37:41 2007
@@ -21,6 +21,7 @@
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ metadata-complete="false"
version="2.5">
<description>MyProject web.xml</description>
@@ -173,5 +174,11 @@
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
+
+ <env-entry>
+ <env-entry-name>testDouble</env-entry-name>
+ <env-entry-value>0.99</env-entry-value>
+ <env-entry-type>java.lang.Double</env-entry-type>
+ </env-entry>
</web-app>