geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vamsic...@apache.org
Subject svn commit: r722395 - /geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
Date Tue, 02 Dec 2008 07:41:55 GMT
Author: vamsic007
Date: Mon Dec  1 23:41:55 2008
New Revision: 722395

URL: http://svn.apache.org/viewvc?rev=722395&view=rev
Log:
Add support for dependency injection in Servlet filters.
A little refactoring of code.

Modified:
    geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java

Modified: geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
URL: http://svn.apache.org/viewvc/geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java?rev=722395&r1=722394&r2=722395&view=diff
==============================================================================
--- geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
(original)
+++ geronimo/plugins/tuscany/trunk/geronimo-tuscany/src/main/java/org/apache/geronimo/tuscany/TuscanyModuleBuilderExtension.java
Mon Dec  1 23:41:55 2008
@@ -61,6 +61,7 @@
 import org.apache.geronimo.kernel.repository.Repository;
 import org.apache.geronimo.openejb.EjbDeployment;
 import org.apache.geronimo.openejb.deployment.EjbModule;
+import org.apache.geronimo.xbeans.javaee.FilterType;
 import org.apache.geronimo.xbeans.javaee.ServletType;
 import org.apache.geronimo.xbeans.javaee.WebAppType;
 import org.apache.openejb.assembler.classic.EjbJarInfo;
@@ -202,59 +203,80 @@
             String servletClassName = servlet.getServletClass().getStringValue().trim();
             try {
                 Class servletClass  = cl.loadClass(servletClassName);
-                for(Field field : servletClass.getDeclaredFields()) {
-                    if(field.isAnnotationPresent(Reference.class)) {
-                        Reference ref = field.getAnnotation(Reference.class);
-                        String referenceName = ref.name() != null && !ref.name().equals("")
? ref.name() : field.getName();
-                        holder.addInjection(servletClassName, new Injection(servletClassName,
field.getName(), servletClassName+"/"+field.getName()));
-                        compContext.put("env/"+servletClassName+"/"+field.getName(), new
SCAServiceReference(field.getType(), thisComponentName, referenceName, ref.required()));
-                    } else if(field.isAnnotationPresent(Property.class)) {
-                        Property prop = field.getAnnotation(Property.class);
-                        String propertyName = prop.name() != null && !prop.name().equals("")
? prop.name() : field.getName();
-                        holder.addInjection(servletClassName, new Injection(servletClassName,
field.getName(), servletClassName+"/"+field.getName()));
-                        compContext.put("env/"+servletClassName+"/"+field.getName(), new
SCAPropertyReference(field.getType(), thisComponentName, propertyName, prop.required()));
-                    } else if(field.isAnnotationPresent(ComponentName.class)) {
-                        holder.addInjection(servletClassName, new Injection(servletClassName,
field.getName(), servletClassName+"/"+field.getName()));
-                        compContext.put("env/"+servletClassName+"/"+field.getName(), thisComponentName);
-                    } else if(field.isAnnotationPresent(Context.class)) {
-                        holder.addInjection(servletClassName, new Injection(servletClassName,
field.getName(), servletClassName+"/"+field.getName()));
-                        compContext.put("env/"+servletClassName+"/"+field.getName(), new
SCAContextReference(thisComponentName));
-                    }
-                }
-                for(Method method : servletClass.getDeclaredMethods()) {
-                    if(!method.getName().startsWith("set") || method.getParameterTypes().length
!= 1) {
-                        continue;
-                    }
-                    String targetName = method.getName().substring(3);
-                    Class type = method.getParameterTypes()[0];
-                    
-                    if(method.isAnnotationPresent(Reference.class)) {
-                        Reference ref = method.getAnnotation(Reference.class);
-                        String referenceName = ref.name() != null && !ref.name().equals("")
? ref.name() : targetName;
-                        holder.addInjection(servletClassName, new Injection(servletClassName,
targetName, servletClassName+"/"+targetName));
-                        compContext.put("env/"+servletClassName+"/"+targetName, new SCAServiceReference(type,
thisComponentName, referenceName, ref.required()));
-                    } else if(method.isAnnotationPresent(Property.class)) {
-                        Property prop = method.getAnnotation(Property.class);
-                        String propertyName = prop.name() != null && !prop.name().equals("")
? prop.name() : targetName;
-                        holder.addInjection(servletClassName, new Injection(servletClassName,
targetName, servletClassName+"/"+targetName));
-                        compContext.put("env/"+servletClassName+"/"+targetName, new SCAPropertyReference(type,
thisComponentName, propertyName, prop.required()));
-                    } else if(method.isAnnotationPresent(ComponentName.class)) {
-                        holder.addInjection(servletClassName, new Injection(servletClassName,
targetName, servletClassName+"/"+targetName));
-                        compContext.put("env/"+servletClassName+"/"+targetName, thisComponentName);
-                    } else if(method.isAnnotationPresent(Context.class)) {
-                        holder.addInjection(servletClassName, new Injection(servletClassName,
targetName, servletClassName+"/"+targetName));
-                        compContext.put("env/"+servletClassName+"/"+targetName, new SCAContextReference(thisComponentName));
-                    }
-                }
+                processWebArtifactClass(servletClass, compContext, holder, thisComponentName);
+            } catch (ClassNotFoundException e) {
+                // TODO Auto-generated catch block
+                e.printStackTrace();
+            }
+        }
+       
+        FilterType[] filters = webApp.getFilterArray();
+        for(FilterType filter : filters) {
+            String filterClassName = filter.getFilterClass().getStringValue().trim();
+            try {
+                Class filterClass  = cl.loadClass(filterClassName);
+                processWebArtifactClass(filterClass, compContext, holder, thisComponentName);
             } catch (ClassNotFoundException e) {
                 // TODO Auto-generated catch block
                 e.printStackTrace();
             }
         }
 
+        // Add dependency so that EmbeddedRuntime starts before the WebAppContext
+        ((GBeanData)earContext.getConfiguration().findGBeanDatas(Collections.singleton(new
AbstractNameQuery(module.getModuleName()))).toArray()[0]).addDependency(abstractName);
+        
         namingBuilders.buildNaming(webApp, vendorWebApp, webModule, buildingContext);
     }
 
+    private void processWebArtifactClass(Class clazz, Map compContext, Holder holder, String
componentName) {
+        System.out.println("Processing class "+clazz);
+        String className = clazz.getName();
+        for(Field field : clazz.getDeclaredFields()) {
+            if(field.isAnnotationPresent(Reference.class)) {
+                Reference ref = field.getAnnotation(Reference.class);
+                String referenceName = ref.name() != null && !ref.name().equals("")
? ref.name() : field.getName();
+                holder.addInjection(className, new Injection(className, field.getName(),
className+"/"+field.getName()));
+                compContext.put("env/"+className+"/"+field.getName(), new SCAServiceReference(field.getType(),
componentName, referenceName, ref.required()));
+            } else if(field.isAnnotationPresent(Property.class)) {
+                Property prop = field.getAnnotation(Property.class);
+                String propertyName = prop.name() != null && !prop.name().equals("")
? prop.name() : field.getName();
+                holder.addInjection(className, new Injection(className, field.getName(),
className+"/"+field.getName()));
+                compContext.put("env/"+className+"/"+field.getName(), new SCAPropertyReference(field.getType(),
componentName, propertyName, prop.required()));
+            } else if(field.isAnnotationPresent(ComponentName.class)) {
+                holder.addInjection(className, new Injection(className, field.getName(),
className+"/"+field.getName()));
+                compContext.put("env/"+className+"/"+field.getName(), componentName);
+            } else if(field.isAnnotationPresent(Context.class)) {
+                holder.addInjection(className, new Injection(className, field.getName(),
className+"/"+field.getName()));
+                compContext.put("env/"+className+"/"+field.getName(), new SCAContextReference(componentName));
+            }
+        }
+        for(Method method : clazz.getDeclaredMethods()) {
+            if(!method.getName().startsWith("set") || method.getParameterTypes().length !=
1) {
+                continue;
+            }
+            String targetName = method.getName().substring(3);
+            Class type = method.getParameterTypes()[0];
+            
+            if(method.isAnnotationPresent(Reference.class)) {
+                Reference ref = method.getAnnotation(Reference.class);
+                String referenceName = ref.name() != null && !ref.name().equals("")
? ref.name() : targetName;
+                holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
+                compContext.put("env/"+className+"/"+targetName, new SCAServiceReference(type,
componentName, referenceName, ref.required()));
+            } else if(method.isAnnotationPresent(Property.class)) {
+                Property prop = method.getAnnotation(Property.class);
+                String propertyName = prop.name() != null && !prop.name().equals("")
? prop.name() : targetName;
+                holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
+                compContext.put("env/"+className+"/"+targetName, new SCAPropertyReference(type,
componentName, propertyName, prop.required()));
+            } else if(method.isAnnotationPresent(ComponentName.class)) {
+                holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
+                compContext.put("env/"+className+"/"+targetName, componentName);
+            } else if(method.isAnnotationPresent(Context.class)) {
+                holder.addInjection(className, new Injection(className, targetName, className+"/"+targetName));
+                compContext.put("env/"+className+"/"+targetName, new SCAContextReference(componentName));
+            }
+        }
+    }
+
     private void handleEjbModule(EARContext earContext, Module module, ClassLoader cl, Collection
repository) throws DeploymentException {
         System.out.println("Inside TuscanyModuleBuilderExtension.handleEjbModule()");
         



Mime
View raw message