Ejemplo n.º 1
0
  /**
   * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element,
   *     org.springframework.beans.factory.xml.ParserContext)
   */
  @SuppressWarnings("unchecked")
  public BeanDefinition parse(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanDefinition =
        BeanDefinitionBuilder.rootBeanDefinition(PurgeJmsQueuesAction.class);
    beanDefinition.addPropertyValue("name", element.getLocalName());

    DescriptionElementParser.doParse(element, beanDefinition);

    String connectionFactory = "connectionFactory"; // default value

    if (element.hasAttribute("connection-factory")) {
      connectionFactory = element.getAttribute("connection-factory");
    }

    if (!StringUtils.hasText(connectionFactory)) {
      parserContext
          .getReaderContext()
          .error("'connection-factory' attribute must not be empty for this element", element);
    }

    beanDefinition.addPropertyReference("connectionFactory", connectionFactory);

    if (element.hasAttribute("receive-timeout")) {
      beanDefinition.addPropertyValue("receiveTimeout", element.getAttribute("receive-timeout"));
    }

    List<String> queueNames = new ArrayList<String>();
    ManagedList queueRefs = new ManagedList();

    List<?> queueElements = DomUtils.getChildElementsByTagName(element, "queue");
    for (Iterator<?> iter = queueElements.iterator(); iter.hasNext(); ) {
      Element queue = (Element) iter.next();
      String queueName = queue.getAttribute("name");
      String queueRef = queue.getAttribute("ref");

      if (StringUtils.hasText(queueName)) {
        queueNames.add(queueName);
      } else if (StringUtils.hasText(queueRef)) {
        queueRefs.add(BeanDefinitionBuilder.childBeanDefinition(queueRef).getBeanDefinition());
      } else {
        throw new BeanCreationException(
            "Element 'queue' must set one of the attributes 'name' or 'ref'");
      }
    }

    beanDefinition.addPropertyValue("queueNames", queueNames);
    beanDefinition.addPropertyValue("queues", queueRefs);

    return beanDefinition.getBeanDefinition();
  }
Ejemplo n.º 2
0
  /**
   * @see org.springframework.beans.factory.xml.BeanDefinitionParser#parse(org.w3c.dom.Element,
   *     org.springframework.beans.factory.xml.ParserContext)
   */
  public BeanDefinition parse(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder beanDefinition =
        BeanDefinitionBuilder.rootBeanDefinition(AntRunAction.class);

    DescriptionElementParser.doParse(element, beanDefinition);

    BeanDefinitionParserUtils.setPropertyValue(
        beanDefinition, element.getAttribute("build-file"), "buildFilePath");

    Element executeElement = DomUtils.getChildElementByTagName(element, "execute");
    BeanDefinitionParserUtils.setPropertyValue(
        beanDefinition, executeElement.getAttribute("target"), "target");
    BeanDefinitionParserUtils.setPropertyValue(
        beanDefinition, executeElement.getAttribute("targets"), "targets");

    Properties properties = new Properties();
    Element propertiesElement = DomUtils.getChildElementByTagName(element, "properties");
    if (propertiesElement != null) {
      BeanDefinitionParserUtils.setPropertyValue(
          beanDefinition, propertiesElement.getAttribute("file"), "propertyFilePath");

      List<?> propertyElements = DomUtils.getChildElementsByTagName(propertiesElement, "property");
      if (propertyElements.size() > 0) {
        for (Iterator<?> iter = propertyElements.iterator(); iter.hasNext(); ) {
          Element propertyElement = (Element) iter.next();
          properties.put(
              propertyElement.getAttribute("name"), propertyElement.getAttribute("value"));
        }

        beanDefinition.addPropertyValue("properties", properties);
      }
    }

    BeanDefinitionParserUtils.setPropertyReference(
        beanDefinition, element.getAttribute("build-listener"), "buildListener");

    beanDefinition.addPropertyValue("name", element.getLocalName());

    return beanDefinition.getBeanDefinition();
  }