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

EnvEntryEncInjector

public class EnvEntryEncInjector extends Object implements EncInjector
Comment
author
Bill Burke
version
$Revision: 60233 $

Fields Summary
private static final Logger
log
private String
name
private String
entryType
private String
value
Constructors Summary
public EnvEntryEncInjector(String encName, String entryType, String value)



         
   
      this.name = encName;
      this.entryType = entryType;
      this.value = value;
   
Methods Summary
protected java.lang.ObjectgetEnvEntryValue()

      Class type = Thread.currentThread().getContextClassLoader().loadClass(entryType);
      if (type == String.class)
      {
         return value;
      }
      else if (type == Integer.class)
      {
         return new Integer(value);
      }
      else if (type == Long.class)
      {
         return new Long(value);
      }
      else if (type == Double.class)
      {
         return new Double(value);
      }
      else if (type == Float.class)
      {
         return new Float(value);
      }
      else if (type == Byte.class)
      {
         return new Byte(value);
      }
      else if (type == Character.class)
      {
         String input = value;
         if (input == null || input.length() == 0)
         {
            return new Character((char) 0);
         }
         else
         {
            if (input.length() > 1)
               // TODO: Add deployment context
               log.warn("Warning character env-entry is too long: binding="
                       + name + " value=" + input);
            return new Character(input.charAt(0));
         }
      }
      else if (type == Short.class)
      {
         return new Short(value);
      }
      else if (type == Boolean.class)
      {
         return new Boolean(value);
      }
      else
      {
         return value;
      }
   
public voidinject(InjectionContainer container)

      try
      {
         Util.rebind(container.getEnc(),
                 name,
                 getEnvEntryValue());
      }
      catch (Exception e)
      {
         throw new RuntimeException("Invalid <env-entry> name: " + name, e);
      }