/**
   * Set the specified environment entries in the naming context.
   *
   * @param env the environment entry
   */
  public void addEnvironment(ContextEnvironment env) {

    Object value = null;
    // Instantiating a new instance of the correct object type, and
    // initializing it.
    String type = env.getType();
    try {
      if (type.equals("java.lang.String")) {
        value = env.getValue();
      } else if (type.equals("java.lang.Byte")) {
        if (env.getValue() == null) {
          value = Byte.valueOf((byte) 0);
        } else {
          value = Byte.decode(env.getValue());
        }
      } else if (type.equals("java.lang.Short")) {
        if (env.getValue() == null) {
          value = Short.valueOf((short) 0);
        } else {
          value = Short.decode(env.getValue());
        }
      } else if (type.equals("java.lang.Integer")) {
        if (env.getValue() == null) {
          value = Integer.valueOf(0);
        } else {
          value = Integer.decode(env.getValue());
        }
      } else if (type.equals("java.lang.Long")) {
        if (env.getValue() == null) {
          value = Long.valueOf(0);
        } else {
          value = Long.decode(env.getValue());
        }
      } else if (type.equals("java.lang.Boolean")) {
        value = Boolean.valueOf(env.getValue());
      } else if (type.equals("java.lang.Double")) {
        if (env.getValue() == null) {
          value = Double.valueOf(0);
        } else {
          value = Double.valueOf(env.getValue());
        }
      } else if (type.equals("java.lang.Float")) {
        if (env.getValue() == null) {
          value = Float.valueOf(0);
        } else {
          value = Float.valueOf(env.getValue());
        }
      } else if (type.equals("java.lang.Character")) {
        if (env.getValue() == null) {
          value = Character.valueOf((char) 0);
        } else {
          if (env.getValue().length() == 1) {
            value = Character.valueOf(env.getValue().charAt(0));
          } else {
            throw new IllegalArgumentException();
          }
        }
      } else {
        value = constructEnvEntry(env.getType(), env.getValue());
        if (value == null) {
          logger.error(sm.getString("naming.invalidEnvEntryType", env.getName()));
        }
      }
    } catch (NumberFormatException e) {
      logger.error(sm.getString("naming.invalidEnvEntryValue", env.getName()));
    } catch (IllegalArgumentException e) {
      logger.error(sm.getString("naming.invalidEnvEntryValue", env.getName()));
    }

    // Binding the object to the appropriate name
    if (value != null) {
      try {
        if (logger.isDebugEnabled()) logger.debug("  Adding environment entry " + env.getName());
        createSubcontexts(envCtx, env.getName());
        envCtx.bind(env.getName(), value);
      } catch (NamingException e) {
        logger.error(sm.getString("naming.invalidEnvEntryValue", e));
      }
    }
  }
  /**
   * Process a property change on the naming resources, by making the corresponding addition or
   * removal to the associated JNDI context.
   *
   * @param name Property name of the change to be processed
   * @param oldValue The old value (or <code>null</code> if adding)
   * @param newValue The new value (or <code>null</code> if removing)
   */
  private void processGlobalResourcesChange(String name, Object oldValue, Object newValue) {

    if (name.equals("ejb")) {
      if (oldValue != null) {
        ContextEjb ejb = (ContextEjb) oldValue;
        if (ejb.getName() != null) {
          removeEjb(ejb.getName());
        }
      }
      if (newValue != null) {
        ContextEjb ejb = (ContextEjb) newValue;
        if (ejb.getName() != null) {
          addEjb(ejb);
        }
      }
    } else if (name.equals("environment")) {
      if (oldValue != null) {
        ContextEnvironment env = (ContextEnvironment) oldValue;
        if (env.getName() != null) {
          removeEnvironment(env.getName());
        }
      }
      if (newValue != null) {
        ContextEnvironment env = (ContextEnvironment) newValue;
        if (env.getName() != null) {
          addEnvironment(env);
        }
      }
    } else if (name.equals("localEjb")) {
      if (oldValue != null) {
        ContextLocalEjb ejb = (ContextLocalEjb) oldValue;
        if (ejb.getName() != null) {
          removeLocalEjb(ejb.getName());
        }
      }
      if (newValue != null) {
        ContextLocalEjb ejb = (ContextLocalEjb) newValue;
        if (ejb.getName() != null) {
          addLocalEjb(ejb);
        }
      }
    } else if (name.equals("resource")) {
      if (oldValue != null) {
        ContextResource resource = (ContextResource) oldValue;
        if (resource.getName() != null) {
          removeResource(resource.getName());
        }
      }
      if (newValue != null) {
        ContextResource resource = (ContextResource) newValue;
        if (resource.getName() != null) {
          addResource(resource);
        }
      }
    } else if (name.equals("resourceEnvRef")) {
      if (oldValue != null) {
        ContextResourceEnvRef resourceEnvRef = (ContextResourceEnvRef) oldValue;
        if (resourceEnvRef.getName() != null) {
          removeResourceEnvRef(resourceEnvRef.getName());
        }
      }
      if (newValue != null) {
        ContextResourceEnvRef resourceEnvRef = (ContextResourceEnvRef) newValue;
        if (resourceEnvRef.getName() != null) {
          addResourceEnvRef(resourceEnvRef);
        }
      }
    } else if (name.equals("resourceLink")) {
      if (oldValue != null) {
        ContextResourceLink rl = (ContextResourceLink) oldValue;
        if (rl.getName() != null) {
          removeResourceLink(rl.getName());
        }
      }
      if (newValue != null) {
        ContextResourceLink rl = (ContextResourceLink) newValue;
        if (rl.getName() != null) {
          addResourceLink(rl);
        }
      }
    } else if (name.equals("service")) {
      if (oldValue != null) {
        ContextService service = (ContextService) oldValue;
        if (service.getName() != null) {
          removeService(service.getName());
        }
      }
      if (newValue != null) {
        ContextService service = (ContextService) newValue;
        if (service.getName() != null) {
          addService(service);
        }
      }
    }
  }