Esempio n. 1
0
 /**
  * Removes a specific <tt>UserCapsNodeListener</tt> from the list of
  * <tt>UserCapsNodeListener</tt>s interested in events notifying about changes in the list of user
  * caps nodes of this <tt>EntityCapsManager</tt>.
  *
  * @param listener the <tt>UserCapsNodeListener</tt> which is no longer interested in events
  *     notifying about changes in the list of user caps nodes of this <tt>EntityCapsManager</tt>
  */
 public void removeUserCapsNodeListener(UserCapsNodeListener listener) {
   if (listener != null) {
     synchronized (userCapsNodeListeners) {
       userCapsNodeListeners.remove(listener);
     }
   }
 }
Esempio n. 2
0
  public synchronized boolean removeLeafElement(String xmlName, String element) {
    List<Child> children = this.children; // fix the snapshot that we'll work with

    for (Child child : children) {
      if (child.name.equals(xmlName) && ((LeafChild) child).value.equals(element)) {
        return children.remove(child);
      }
    }
    return false;
  }
  /**
   * Expires a specific <tt>Content</tt> of this <tt>Conference</tt> (i.e. if the specified
   * <tt>content</tt> is not in the list of <tt>Content</tt>s of this <tt>Conference</tt>, does
   * nothing).
   *
   * @param content the <tt>Content</tt> to be expired by this <tt>Conference</tt>
   */
  public void expireContent(Content content) {
    boolean expireContent;

    synchronized (contents) {
      if (contents.contains(content)) {
        contents.remove(content);
        expireContent = true;
      } else expireContent = false;
    }
    if (expireContent) content.expire();
  }
 // returns null if we don't have anything free
 private static synchronized Class getFreeVMImplClass() {
   while (!freeVMClasses.isEmpty()) {
     SoftReference ref = (SoftReference) freeVMClasses.remove(0);
     Object o = ref.get();
     if (o != null) {
       if (DEBUG) {
         System.out.println("re-using loaded VirtualMachineImpl");
       }
       return (Class) o;
     }
   }
   return null;
 }
Esempio n. 5
0
  /**
   * Initialization method that will find out all constructors and potential static factory methods
   * the class has.
   *
   * <p>Starting with 1.2, it will also apply mix-in annotations, as per [JACKSON-76]
   *
   * @param includeAll If true, includes all creator methods; if false, will only include the
   *     no-arguments "default" constructor
   */
  public void resolveCreators(boolean includeAll) {
    // Then see which constructors we have
    _constructors = null;
    for (Constructor<?> ctor : _class.getDeclaredConstructors()) {
      switch (ctor.getParameterTypes().length) {
        case 0:
          _defaultConstructor = _constructConstructor(ctor, true);
          break;
        default:
          if (includeAll) {
            if (_constructors == null) {
              _constructors = new ArrayList<AnnotatedConstructor>();
            }
            _constructors.add(_constructConstructor(ctor, false));
          }
      }
    }
    // and if need be, augment with mix-ins
    if (_primaryMixIn != null) {
      if (_defaultConstructor != null || _constructors != null) {
        _addConstructorMixIns(_primaryMixIn);
      }
    }

    /* And then... let's remove all constructors that are
     * deemed to be ignorable after all annotations have been
     * properly collapsed.
     */
    if (_defaultConstructor != null) {
      if (_annotationIntrospector.isIgnorableConstructor(_defaultConstructor)) {
        _defaultConstructor = null;
      }
    }
    if (_constructors != null) {
      // count down to allow safe removal
      for (int i = _constructors.size(); --i >= 0; ) {
        if (_annotationIntrospector.isIgnorableConstructor(_constructors.get(i))) {
          _constructors.remove(i);
        }
      }
    }

    _creatorMethods = null;

    if (includeAll) {
      /* Then static methods which are potential factory
       * methods
       */
      for (Method m : _class.getDeclaredMethods()) {
        if (!Modifier.isStatic(m.getModifiers())) {
          continue;
        }
        int argCount = m.getParameterTypes().length;
        // factory methods take at least one arg:
        if (argCount < 1) {
          continue;
        }
        if (_creatorMethods == null) {
          _creatorMethods = new ArrayList<AnnotatedMethod>();
        }
        _creatorMethods.add(_constructCreatorMethod(m));
      }
      // mix-ins to mix in?
      if (_primaryMixIn != null && _creatorMethods != null) {
        _addFactoryMixIns(_primaryMixIn);
      }
      // anything to ignore at this point?
      if (_creatorMethods != null) {
        // count down to allow safe removal
        for (int i = _creatorMethods.size(); --i >= 0; ) {
          if (_annotationIntrospector.isIgnorableMethod(_creatorMethods.get(i))) {
            _creatorMethods.remove(i);
          }
        }
      }
    }
  }
Esempio n. 6
0
  /** Receive notification of the end of an element. */
  @Override
  public void endElement(String uri, String l, String q) {
    /*
     * 1. If current element is a String, update its value from the string buffer.
     * 2. Add the element to parent.
     */
    ElementInfo element = _stack.remove(_stack.size() - 1);
    _logger.fine("endElement " + element);
    if (element.type == null) {
      _logger.warning("Element " + element.name + " not created ");
      return;
    } else if (_chars.length() > 0) {
      try {
        injectProperty(element.data, String.class, _chars.toString(), null, null);
      } catch (Exception x) {
        if (!_lenient) {
          throw new BeanAssemblyException(
              "Failed to set characters to object " + element.type.getName(), x);
        } else {
          _logger.warning("Failed to set characters to parent " + element.data);
        }
      }
    }
    _chars.setLength(0);
    _logger.fine(
        "<<ElementInfo: "
            + element.type.getName()
            + " in "
            + element
            + "\n    @as is "
            + element.inst.get("@as")
            + "\n    @id is "
            + element.inst.get("@id"));

    if (List.class.isAssignableFrom(element.data.getClass()) && element.name.endsWith("...")) {
      List<?> list = (List<?>) element.data;
      Object array = Array.newInstance(element.type, list.size());
      for (int i = 0; i < list.size(); ++i) {
        Array.set(array, i, list.get(i));
      }
      element.data = array;
    }

    String id = element.inst.get("@id");
    if (id != null) {
      // locally stored object - not added to the parent
      _local.put(id, element);
    } else if (!_stack.isEmpty()) {
      // inject into the parent as a property
      ElementInfo parent = _stack.get(_stack.size() - 1);
      _logger.fine("Parent is " + parent.data.getClass().getName());
      try {
        String as = element.inst.get("@as");
        if (as != null) {
          injectProperty(
              parent.data,
              element.type,
              element.data,
              Strings.toCamelCase(as, '-', false),
              element.args.complete());
        } else {
          injectProperty(parent.data, element.type, element.data, null, element.args.complete());
        }
      } catch (Exception x) {
        if (!_lenient) {
          throw new BeanAssemblyException(
              "Failed to set value " + element.data + " to parent " + parent.data, x);
        } else {
          _logger.log(
              Level.WARNING,
              "Failed to set value " + element.data + " to parent " + parent.data,
              x);
        }
      }
    }
    _top = element.data;
  }