You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by dj...@apache.org on 2007/05/25 02:02:30 UTC
svn commit: r541490 - in /geronimo/server/trunk/modules:
geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/AbstractWebModuleBuilder.java
Author: djencks
Date: Thu May 24 17:02:29 2007
New Revision: 541490
URL: http://svn.apache.org/viewvc?view=rev&rev=541490
Log:
GERONIMO-3188 Look for annotations in superclasses, and apply them when found
Modified:
geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/AbstractWebModuleBuilder.java
Modified: geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java?view=diff&rev=541490&r1=541489&r2=541490
==============================================================================
--- geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java (original)
+++ geronimo/server/trunk/modules/geronimo-j2ee/src/main/java/org/apache/geronimo/j2ee/annotation/Holder.java Thu May 24 17:02:29 2007
@@ -107,9 +107,35 @@
ObjectRecipe objectRecipe = new ObjectRecipe(className);
objectRecipe.allow(Option.FIELD_INJECTION);
objectRecipe.allow(Option.PRIVATE_PROPERTIES);
+ Class clazz;
+ try {
+ clazz = classLoader.loadClass(className);
+ } catch (ClassNotFoundException e) {
+ throw new InstantiationException("Can't load class " + className + " in classloader: " + classLoader);
+ }
+ List<NamingException> problems = new ArrayList<NamingException>();
+ while (clazz != Object.class) {
+ addInjections(clazz.getName(), context, objectRecipe, problems);
+ clazz = clazz.getSuperclass();
+ }
+ if (!problems.isEmpty()) {
+ throw new InstantiationException("Some objects to be injected were not found in jndi: " + problems);
+ }
+ Object result = objectRecipe.create(classLoader);
+ if (getPostConstruct() != null) {
+ try {
+ apply(result, null, postConstruct);
+ } catch (InvocationTargetException e) {
+ Throwable cause = e.getCause();
+ throw (InstantiationException) new InstantiationException("Could not call postConstruct method").initCause(cause);
+ }
+ }
+ return result;
+ }
+
+ private void addInjections(String className, Context context, ObjectRecipe objectRecipe, List<NamingException> problems) {
List<Injection> callbackHandlerinjections = getInjections(className);
if (callbackHandlerinjections != null) {
- List<NamingException> problems = new ArrayList<NamingException>();
for (Injection injection : callbackHandlerinjections) {
try {
String jndiName = injection.getJndiName();
@@ -127,20 +153,7 @@
problems.add(e);
}
}
- if (!problems.isEmpty()) {
- throw new InstantiationException("Some objects to be injected were not found in jndi: " + problems);
- }
- }
- Object result = objectRecipe.create(classLoader);
- if (getPostConstruct() != null) {
- try {
- apply(result, null, postConstruct);
- } catch (InvocationTargetException e) {
- Throwable cause = e.getCause();
- throw (InstantiationException) new InstantiationException("Could not call postConstruct method").initCause(cause);
- }
}
- return result;
}
public void destroyInstance(Object o) throws Exception {
Modified: geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/AbstractWebModuleBuilder.java
URL: http://svn.apache.org/viewvc/geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/AbstractWebModuleBuilder.java?view=diff&rev=541490&r1=541489&r2=541490
==============================================================================
--- geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/AbstractWebModuleBuilder.java (original)
+++ geronimo/server/trunk/modules/geronimo-web-2.5-builder/src/main/java/org/apache/geronimo/web25/deployment/AbstractWebModuleBuilder.java Thu May 24 17:02:29 2007
@@ -750,11 +750,10 @@
Class<?> clas;
try {
clas = classLoader.loadClass(cls.getStringValue());
- }
- catch (ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
throw new DeploymentException("AbstractWebModuleBuilder: Could not load servlet class: " + cls.getStringValue());
}
- classes.add(clas);
+ addClass(classes, clas);
}
}
@@ -765,11 +764,10 @@
Class<?> clas;
try {
clas = classLoader.loadClass(cls.getStringValue());
- }
- catch (ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
throw new DeploymentException("AbstractWebModuleBuilder: Could not load listener class: " + cls.getStringValue());
}
- classes.add(clas);
+ addClass(classes, clas);
}
// Get all the filters from the deployment descriptor
@@ -779,14 +777,20 @@
Class<?> clas;
try {
clas = classLoader.loadClass(cls.getStringValue());
- }
- catch (ClassNotFoundException e) {
+ } catch (ClassNotFoundException e) {
throw new DeploymentException("AbstractWebModuleBuilder: Could not load filter class: " + cls.getStringValue());
}
- classes.add(clas);
+ addClass(classes, clas);
}
return new ClassFinder(classes);
+ }
+
+ private void addClass(List<Class> classes, Class<?> clas) {
+ while (clas != Object.class) {
+ classes.add(clas);
+ clas = clas.getSuperclass();
+ }
}
protected void configureBasicWebModuleAttributes(WebAppType webApp, XmlObject vendorPlan, EARContext moduleContext, EARContext earContext, WebModule webModule, GBeanData webModuleData) throws DeploymentException {