public void removeAttribute(String name) {
   if (SecurityUtil.isPackageProtectionEnabled()) {
     doPrivileged("removeAttribute", new Object[] {name});
   } else {
     context.removeAttribute(name);
   }
 }
Example #2
0
  /**
   * Bind the specified value with the specified context attribute name, replacing any existing
   * value for that name.
   *
   * @param name Attribute name to be bound
   * @param value New attribute value to be bound
   */
  public void setAttribute(String name, Object value) {

    // Name cannot be null
    if (name == null)
      throw new IllegalArgumentException(sm.getString("applicationContext.setAttribute.namenull"));

    // Null value is the same as removeAttribute()
    if (value == null) {
      removeAttribute(name);
      return;
    }

    Object oldValue = null;
    boolean replaced = false;

    // Add or replace the specified attribute
    synchronized (attributes) {
      // Check for read only attribute
      if (readOnlyAttributes.containsKey(name)) return;
      oldValue = attributes.get(name);
      if (oldValue != null) replaced = true;
      attributes.put(name, value);
    }

    // Notify interested application event listeners
    Object listeners[] = context.getApplicationListeners();
    if ((listeners == null) || (listeners.length == 0)) return;
    ServletContextAttributeEvent event = null;
    if (replaced)
      event = new ServletContextAttributeEvent(context.getServletContext(), name, oldValue);
    else event = new ServletContextAttributeEvent(context.getServletContext(), name, value);

    for (int i = 0; i < listeners.length; i++) {
      if (!(listeners[i] instanceof ServletContextAttributeListener)) continue;
      ServletContextAttributeListener listener = (ServletContextAttributeListener) listeners[i];
      try {
        if (replaced) {
          context.fireContainerEvent("beforeContextAttributeReplaced", listener);
          listener.attributeReplaced(event);
          context.fireContainerEvent("afterContextAttributeReplaced", listener);
        } else {
          context.fireContainerEvent("beforeContextAttributeAdded", listener);
          listener.attributeAdded(event);
          context.fireContainerEvent("afterContextAttributeAdded", listener);
        }
      } catch (Throwable t) {
        if (replaced) context.fireContainerEvent("afterContextAttributeReplaced", listener);
        else context.fireContainerEvent("afterContextAttributeAdded", listener);
        // FIXME - should we do anything besides log these?
        log(sm.getString("applicationContext.attributeEvent"), t);
      }
    }
  }
Example #3
0
  /** Clear all application-created attributes. */
  public void clearAttributes() {

    // Create list of attributes to be removed
    ArrayList list = new ArrayList();
    synchronized (attributes) {
      Iterator iter = attributes.keySet().iterator();
      while (iter.hasNext()) {
        list.add(iter.next());
      }
    }

    // Remove application originated attributes
    // (read only attributes will be left in place)
    Iterator keys = list.iterator();
    while (keys.hasNext()) {
      String key = (String) keys.next();
      removeAttribute(key);
    }
  }
 @Override
 public void removeAttribute(String name) throws RemoteException, RemoteException {
   tomcatAttributes.remove(name);
   // do nothing
   super.removeAttribute(name);
 }