FileDocCategorySizeDatePackage
DependsHandler.javaAPI DocJBoss 4.2.14032Fri Jul 13 20:53:46 BST 2007org.jboss.injection

DependsHandler

public class DependsHandler extends Object implements InjectionHandler
author
Kabir Khan
version
$Revision: 60455 $

Fields Summary
private static final Logger
log
Constructors Summary
Methods Summary
public voidhandleClassAnnotations(java.lang.Class clazz, InjectionContainer container)

      Depends dep = (Depends)container.getAnnotation(Depends.class, clazz);
      if (dep == null) return;
      for (String dependency : dep.value())
      {
         container.getDependencyPolicy().addDependency(dependency);
      }
   
public voidhandleFieldAnnotations(java.lang.reflect.Field field, InjectionContainer container, java.util.Map injectors)

      Depends dep = container.getAnnotation(Depends.class, field.getDeclaringClass(), field);
      if (dep != null)
      {
         String[] names = dep.value();
         if (names.length != 1)
            throw new RuntimeException("@Depends on a field can only take one object name: " + field);
         ObjectName on = null;
         try
         {
            on = new ObjectName(names[0]);
         }
         catch (MalformedObjectNameException e)
         {
            throw new RuntimeException(e);
         }
         // don't replace other injections
         if (injectors.get(field) == null)
            injectors.put(field, new DependsFieldInjector(field, on));
         
         container.getDependencyPolicy().addDependency(names[0]);
      }
   
public voidhandleMethodAnnotations(java.lang.reflect.Method method, InjectionContainer container, java.util.Map injectors)

      Depends dep = container.getAnnotation(Depends.class, method.getDeclaringClass(), method);
      if (dep != null)
      {
         if (!method.getName().startsWith("set"))
            throw new RuntimeException("@EJB can only be used with a set method: " + method);
         String[] names = dep.value();
         if (names.length != 1)
            throw new RuntimeException("@Depends on a field can only take one object name: " + method);
         ObjectName on = null;
         try
         {
            on = new ObjectName(names[0]);
         }
         catch (MalformedObjectNameException e)
         {
            throw new RuntimeException(e);
         }
         
         // don't replace other injections
         if (injectors.get(method) == null)
            injectors.put(method, new DependsMethodInjector(method, on));
         
         container.getDependencyPolicy().addDependency(names[0]);
      }
   
public voidloadXml(org.jboss.metamodel.descriptor.EnvironmentRefGroup xml, InjectionContainer container)