Exemplo n.º 1
0
 @SuppressWarnings("unchecked")
 public void handleListenersElement(
     Element stepElement, BeanDefinition beanDefinition, ParserContext parserContext) {
   MutablePropertyValues propertyValues = beanDefinition.getPropertyValues();
   List<Element> listenersElements =
       DomUtils.getChildElementsByTagName(stepElement, LISTENERS_ELE);
   if (listenersElements.size() == 1) {
     Element listenersElement = listenersElements.get(0);
     CompositeComponentDefinition compositeDef =
         new CompositeComponentDefinition(
             listenersElement.getTagName(), parserContext.extractSource(stepElement));
     parserContext.pushContainingComponent(compositeDef);
     ManagedList listenerBeans = new ManagedList();
     if (propertyValues.contains("listeners")) {
       listenerBeans = (ManagedList) propertyValues.getPropertyValue("listeners").getValue();
     }
     listenerBeans.setMergeEnabled(
         listenersElement.hasAttribute(MERGE_ATTR)
             && Boolean.valueOf(listenersElement.getAttribute(MERGE_ATTR)));
     List<Element> listenerElements =
         DomUtils.getChildElementsByTagName(listenersElement, "listener");
     if (listenerElements != null) {
       for (Element listenerElement : listenerElements) {
         listenerBeans.add(parse(listenerElement, parserContext));
       }
     }
     propertyValues.addPropertyValue("listeners", listenerBeans);
     parserContext.popAndRegisterContainingComponent();
   }
 }
Exemplo n.º 2
0
  private ManagedList<AbstractBeanDefinition> parseListeners(
      Element element, ParserContext parserContext) {
    List<Element> listenersElements =
        DomUtils.getChildElementsByTagName(element, LISTENERS_ELEMENT);

    ManagedList<AbstractBeanDefinition> listeners = new ManagedList<AbstractBeanDefinition>();

    if (listenersElements.size() == 1) {
      Element listenersElement = listenersElements.get(0);
      CompositeComponentDefinition compositeDef =
          new CompositeComponentDefinition(
              listenersElement.getTagName(), parserContext.extractSource(element));
      parserContext.pushContainingComponent(compositeDef);
      listeners.setMergeEnabled(false);
      List<Element> listenerElements =
          DomUtils.getChildElementsByTagName(listenersElement, LISTENER_ELEMENT);
      for (Element listenerElement : listenerElements) {
        BeanDefinitionBuilder bd = BeanDefinitionBuilder.genericBeanDefinition(listenerType);
        bd.addPropertyValue(
            "delegate", new RuntimeBeanReference(listenerElement.getAttribute(REF_ATTRIBUTE)));
        listeners.add(bd.getBeanDefinition());
      }
      parserContext.popAndRegisterContainingComponent();
    } else if (listenersElements.size() > 1) {
      parserContext
          .getReaderContext()
          .error(
              "The '<listeners/>' element may not appear more than once in a single <job/>.",
              element);
    }

    return listeners;
  }