@SuppressWarnings("unchecked")
  public static BeanMetadataElement parseListenerElement(
      Element element, ParserContext parserContext, BeanDefinition enclosing) {
    String listenerRef = element.getAttribute(REF_ATTR);
    List<Element> beanElements = DomUtils.getChildElementsByTagName(element, BEAN_ELE);
    List<Element> refElements = DomUtils.getChildElementsByTagName(element, REF_ELE);

    verifyListenerAttributesAndSubelements(
        listenerRef, beanElements, refElements, element, parserContext);

    if (StringUtils.hasText(listenerRef)) {
      return new RuntimeBeanReference(listenerRef);
    } else if (beanElements.size() == 1) {
      Element beanElement = beanElements.get(0);
      BeanDefinitionHolder beanDefinitionHolder =
          parserContext.getDelegate().parseBeanDefinitionElement(beanElement, enclosing);
      parserContext
          .getDelegate()
          .decorateBeanDefinitionIfRequired(beanElement, beanDefinitionHolder);
      return beanDefinitionHolder;
    } else {
      return (BeanMetadataElement)
          parserContext.getDelegate().parsePropertySubElement(refElements.get(0), null);
    }
  }
  private ClassPathBeanDefinitionScanner configureScanner(
      ParserContext parserContext, BeanDefinitionRegistry registry) {
    XmlReaderContext readerContext = parserContext.getReaderContext();
    // Delegate bean definition registration to scanner class.
    ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(registry, false);
    scanner.setIncludeAnnotationConfig(false);
    scanner.addIncludeFilter(new AnnotationTypeFilter(Entity.class));

    scanner.setResourceLoader(readerContext.getResourceLoader());
    scanner.setBeanDefinitionDefaults(parserContext.getDelegate().getBeanDefinitionDefaults());
    scanner.setAutowireCandidatePatterns(
        parserContext.getDelegate().getAutowireCandidatePatterns());

    return scanner;
  }
  @Override
  protected void doParse(
      Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    super.doParse(element, parserContext, builder);

    BeanDefinitionBuilder redisConfigBeanBuilder =
        BeanDefinitionBuilder.genericBeanDefinition(RedisConnectionFactoryConfig.class.getName());

    BeanDefinition cloudPoolConfiguration = null;
    Element poolElement = DomUtils.getChildElementByTagName(element, ELEMENT_POOL);
    if (poolElement != null) {
      cloudPoolConfiguration = parsePoolElement(poolElement, parserContext);
    }
    redisConfigBeanBuilder.addConstructorArgValue(cloudPoolConfiguration);

    Element propertiesElement = DomUtils.getChildElementByTagName(element, CONNECTION_PROPERTIES);
    if (propertiesElement != null) {
      Map<?, ?> properties =
          parserContext
              .getDelegate()
              .parseMapElement(propertiesElement, builder.getRawBeanDefinition());
      redisConfigBeanBuilder.addConstructorArgValue(properties);
    }

    builder.addConstructorArgValue(redisConfigBeanBuilder.getBeanDefinition());
  }
 public static BeanComponentDefinition parseInnerHandlerDefinition(
     Element element, ParserContext parserContext) {
   // parses out the inner bean definition for concrete implementation if defined
   List<Element> childElements = DomUtils.getChildElementsByTagName(element, "bean");
   BeanComponentDefinition innerComponentDefinition = null;
   if (childElements != null && childElements.size() == 1) {
     Element beanElement = childElements.get(0);
     BeanDefinitionParserDelegate delegate = parserContext.getDelegate();
     BeanDefinitionHolder bdHolder = delegate.parseBeanDefinitionElement(beanElement);
     bdHolder = delegate.decorateBeanDefinitionIfRequired(beanElement, bdHolder);
     BeanDefinition inDef = bdHolder.getBeanDefinition();
     innerComponentDefinition = new BeanComponentDefinition(inDef, bdHolder.getBeanName());
   }
   String ref = element.getAttribute(REF_ATTRIBUTE);
   Assert.isTrue(
       !(StringUtils.hasText(ref) && innerComponentDefinition != null),
       "Ambiguous definition. Inner bean "
           + (innerComponentDefinition == null
               ? innerComponentDefinition
               : innerComponentDefinition.getBeanDefinition().getBeanClassName())
           + " declaration and \"ref\" "
           + ref
           + " are not allowed together.");
   return innerComponentDefinition;
 }
  @SuppressWarnings({"unchecked"})
  private void parseProcessors(
      Element element, ParserContext parserContext, GenericBeanDefinition beanDefinition) {
    Element processorsElement =
        DomUtils.getChildElementByTagName(element, EVENT_PROCESSORS_ELEMENT);

    Element snapshotTriggerElement =
        DomUtils.getChildElementByTagName(element, SNAPSHOT_TRIGGER_ELEMENT);
    if (snapshotTriggerElement != null) {
      BeanDefinition triggerDefinition =
          snapshotterTriggerParser.parse(snapshotTriggerElement, parserContext);
      PropertyValue aggregateCache = beanDefinition.getPropertyValues().getPropertyValue("cache");
      if (aggregateCache != null) {
        triggerDefinition.getPropertyValues().add("aggregateCache", aggregateCache.getValue());
      }
      beanDefinition.getPropertyValues().add(SNAPSHOTTER_TRIGGER_PROPERTY, triggerDefinition);
    }

    if (processorsElement != null) {
      List<Object> processorsList =
          parserContext.getDelegate().parseListElement(processorsElement, beanDefinition);
      if (!processorsList.isEmpty()) {
        beanDefinition.getPropertyValues().add(EVENT_STREAM_DECORATORS_PROPERTY, processorsList);
      }
    }
  }
  @Override
  protected void doParse(
      Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    String exchangeName = element.getAttribute(NAME_ATTRIBUTE);
    builder.addConstructorArgValue(new TypedStringValue(exchangeName));
    parseBindings(element, parserContext, builder, exchangeName);

    NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined(
        builder, element, DURABLE_ATTRIBUTE, true);
    NamespaceUtils.addConstructorArgBooleanValueIfAttributeDefined(
        builder, element, AUTO_DELETE_ATTRIBUTE, false);

    Element argumentsElement = DomUtils.getChildElementByTagName(element, ARGUMENTS_ELEMENT);
    if (argumentsElement != null) {

      String ref = argumentsElement.getAttribute(REF_ATTRIBUTE);
      Map<?, ?> map =
          parserContext
              .getDelegate()
              .parseMapElement(argumentsElement, builder.getRawBeanDefinition());
      if (StringUtils.hasText(ref)) {
        if (map != null && map.size() > 0) {
          parserContext
              .getReaderContext()
              .error("You cannot have both a 'ref' and a nested map", element);
        }
        builder.addConstructorArgReference(ref);
      } else {
        builder.addConstructorArgValue(map);
      }
    }

    NamespaceUtils.parseDeclarationControls(element, builder);
  }
  @Override
  protected final void doParse(
      final Element e, final ParserContext parserContext, final BeanDefinitionBuilder builder) {

    builder.addConstructorArgValue(
        parserContext.getDelegate().parseListElement(e, builder.getBeanDefinition()));
  }
Пример #8
0
  public BeanDefinitionHolder decorate(
      Node node, BeanDefinitionHolder definition, ParserContext parserContext) {

    BeanDefinition bd = definition.getBeanDefinition();
    List<?> list = parserContext.getDelegate().parseListElement((Element) node, bd);
    bd.getPropertyValues().addPropertyValue(getPropertyName(node), list);
    return definition;
  }
 @SuppressWarnings({"rawtypes", "unchecked"})
 public static ManagedList configureAdviceChain(
     Element adviceChainElement,
     Element txElement,
     BeanDefinition parentBeanDefinition,
     ParserContext parserContext) {
   ManagedList adviceChain = null;
   // Schema validation ensures txElement and adviceChainElement are mutually exclusive
   if (txElement != null) {
     adviceChain = new ManagedList();
     adviceChain.add(IntegrationNamespaceUtils.configureTransactionAttributes(txElement));
   }
   if (adviceChainElement != null) {
     adviceChain = new ManagedList();
     NodeList childNodes = adviceChainElement.getChildNodes();
     for (int i = 0; i < childNodes.getLength(); i++) {
       Node child = childNodes.item(i);
       if (child.getNodeType() == Node.ELEMENT_NODE) {
         Element childElement = (Element) child;
         String localName = child.getLocalName();
         if ("bean".equals(localName)) {
           BeanDefinitionHolder holder =
               parserContext
                   .getDelegate()
                   .parseBeanDefinitionElement(childElement, parentBeanDefinition);
           parserContext.registerBeanComponent(new BeanComponentDefinition(holder));
           adviceChain.add(new RuntimeBeanReference(holder.getBeanName()));
         } else if ("ref".equals(localName)) {
           String ref = childElement.getAttribute("bean");
           adviceChain.add(new RuntimeBeanReference(ref));
         } else {
           BeanDefinition customBeanDefinition =
               parserContext.getDelegate().parseCustomElement(childElement, parentBeanDefinition);
           if (customBeanDefinition == null) {
             parserContext
                 .getReaderContext()
                 .error("failed to parse custom element '" + localName + "'", childElement);
           }
           adviceChain.add(customBeanDefinition);
         }
       }
     }
   }
   return adviceChain;
 }
Пример #10
0
 protected void doParse(
     Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
   Map parsedMap =
       parserContext.getDelegate().parseMapElement(element, builder.getRawBeanDefinition());
   builder.addPropertyValue("sourceMap", parsedMap);
   builder.addPropertyValue("targetMapClass", mapClass.getName());
   getBeanAssembler(element, builder)
       .setBeanFlag(MuleHierarchicalBeanDefinitionParserDelegate.MULE_NO_RECURSE);
 }
  private AbstractBeanDefinition parseSessionFactory(
      Element element,
      String dataSourceId,
      BeanDefinitionRegistry targetRegistry,
      ParserContext parserContext) {
    String sessionFactoryId =
        StringUtils.hasText(element.getAttribute(ID_ATTRIBUTE))
            ? element.getAttribute(ID_ATTRIBUTE)
            : "sessionFactory";
    AbstractBeanDefinition sessionFactoryBean = new GenericBeanDefinition();
    sessionFactoryBean.setBeanClass(ConfigurableLocalSessionFactoryBean.class);

    MutablePropertyValues propertyValues = sessionFactoryBean.getPropertyValues();
    final RuntimeBeanReference dataSourceRef = new RuntimeBeanReference(dataSourceId);
    propertyValues.addPropertyValue("dataSource", dataSourceRef);

    Class<?> configClass = lookupConfigClass(element, parserContext);
    propertyValues.addPropertyValue("configClass", configClass);

    final String configLocation = element.getAttribute(CONFIG_LOCATION_ATTRIBUTE);
    if (StringUtils.hasText(configLocation)) {
      propertyValues.addPropertyValue("configLocation", configLocation);
    }

    propertyValues.addPropertyValue(
        GrailsApplication.APPLICATION_ID,
        new RuntimeBeanReference(GrailsApplication.APPLICATION_ID));

    targetRegistry.registerBeanDefinition(sessionFactoryId, sessionFactoryBean);

    final String lobHandlerRef = element.getAttribute(LOB_HANDLER_ATTRIBUTE);
    if (StringUtils.hasText(lobHandlerRef)) {
      propertyValues.addPropertyValue("lobHandler", new RuntimeBeanReference(lobHandlerRef));
    } else {
      GenericBeanDefinition lobHandler = new GenericBeanDefinition();
      lobHandler.setBeanClass(SpringLobHandlerDetectorFactoryBean.class);
      lobHandler.getPropertyValues().addPropertyValue("pooledConnection", true);
      lobHandler.getPropertyValues().addPropertyValue("dataSource", dataSourceRef);
      propertyValues.addPropertyValue("lobHandler", lobHandler);
    }

    String transactionManagerRef = element.getAttribute(TRANSACTION_MANAGER_ATTRIBUTE);
    if (StringUtils.hasText(transactionManagerRef)) {
      targetRegistry.registerAlias(transactionManagerRef, "transactionManager");
    } else {
      GenericBeanDefinition transactionManagerBean = new GenericBeanDefinition();
      transactionManagerBean.setBeanClass(GrailsHibernateTransactionManager.class);
      transactionManagerBean
          .getPropertyValues()
          .addPropertyValue("sessionFactory", new RuntimeBeanReference(sessionFactoryId));

      targetRegistry.registerBeanDefinition("transactionManager", transactionManagerBean);
    }

    parserContext.getDelegate().parsePropertyElements(element, sessionFactoryBean);
    return sessionFactoryBean;
  }
 protected void parseChild(
     Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
   super.parseChild(element, parserContext, builder);
   final Map parseMap =
       ((MuleHierarchicalBeanDefinitionParserDelegate) parserContext.getDelegate())
           .parseMapElement(
               element, childElementName, childElementKeyAttribute, childElementValueAttribute);
   builder.addPropertyValue("sourceMap", parseMap);
   builder.addPropertyValue("targetMapClass", super.getBeanClass(element));
 }
 private ManagedList<Object> extractBeanSubElements(
     Element parentElement, ParserContext parserContext) {
   ManagedList<Object> list = new ManagedList<Object>();
   list.setSource(parserContext.extractSource(parentElement));
   for (Element beanElement : DomUtils.getChildElementsByTagName(parentElement, "bean", "ref")) {
     Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null);
     list.add(object);
   }
   return list;
 }
 private ManagedList<?> getDeferredResultInterceptors(
     Element element, Object source, ParserContext parserContext) {
   ManagedList<? super Object> interceptors = new ManagedList<Object>();
   Element asyncElement = DomUtils.getChildElementByTagName(element, "async-support");
   if (asyncElement != null) {
     Element interceptorsElement =
         DomUtils.getChildElementByTagName(asyncElement, "deferred-result-interceptors");
     if (interceptorsElement != null) {
       interceptors.setSource(source);
       for (Element converter : DomUtils.getChildElementsByTagName(interceptorsElement, "bean")) {
         BeanDefinitionHolder beanDef =
             parserContext.getDelegate().parseBeanDefinitionElement(converter);
         beanDef =
             parserContext.getDelegate().decorateBeanDefinitionIfRequired(converter, beanDef);
         interceptors.add(beanDef);
       }
     }
   }
   return interceptors;
 }
    private void processAuthzChain(
        Element element, ParserContext parserContext, BeanDefinitionBuilder bean) {
      NodeList children = element.getChildNodes();
      for (int i = 0; i < children.getLength(); i++) {
        Node n = children.item(i);
        if (n.getNodeType() == Node.ELEMENT_NODE) {
          String name = n.getLocalName();

          if ("bootstrapPips".equals(name) || "pips".equals(name) || "pdps".equals(name)) {
            List<?> list =
                parserContext.getDelegate().parseListElement((Element) n, bean.getBeanDefinition());
            bean.addPropertyValue(name, list);
          }
        }
      }
    }
 /**
  * Parse a "poller" element to provide a reference for the target BeanDefinitionBuilder. If the
  * poller element does not contain a "ref" attribute, this will create and register a
  * PollerMetadata instance and then add it as a property reference of the target builder.
  *
  * @param pollerElement the "poller" element to parse
  * @param targetBuilder the builder that expects the "trigger" property
  * @param parserContext the parserContext for the target builder
  */
 public static void configurePollerMetadata(
     Element pollerElement, BeanDefinitionBuilder targetBuilder, ParserContext parserContext) {
   if (pollerElement.hasAttribute("ref")) {
     int numberOfAttributes = pollerElement.getAttributes().getLength();
     if (numberOfAttributes != 1) {
       /*
        * When importing the core namespace, e.g. into jdbc, we get a 'default="false"' attribute,
        * even if not explicitly declared.
        */
       if (!(numberOfAttributes == 2
           && pollerElement.hasAttribute("default")
           && pollerElement.getAttribute("default").equals("false"))) {
         parserContext
             .getReaderContext()
             .error(
                 "A 'poller' element that provides a 'ref' must have no other attributes.",
                 pollerElement);
       }
     }
     if (pollerElement.getChildNodes().getLength() != 0) {
       parserContext
           .getReaderContext()
           .error(
               "A 'poller' element that provides a 'ref' must have no child elements.",
               pollerElement);
     }
     targetBuilder.addPropertyReference("pollerMetadata", pollerElement.getAttribute("ref"));
   } else {
     BeanDefinition beanDefinition =
         parserContext
             .getDelegate()
             .parseCustomElement(pollerElement, targetBuilder.getBeanDefinition());
     if (beanDefinition == null) {
       parserContext.getReaderContext().error("BeanDefinition must not be null", pollerElement);
     }
     targetBuilder.addPropertyValue("pollerMetadata", beanDefinition);
   }
 }
Пример #17
0
  @Override
  protected void doParse(Element element, ParserContext ctx, BeanDefinitionBuilder bean) {
    boolean isAbstract = false;
    boolean publish = true;
    NamedNodeMap atts = element.getAttributes();
    String bus = element.getAttribute("bus");
    if (StringUtils.isEmpty(bus)) {
      addBusWiringAttribute(bean, BusWiringType.CONSTRUCTOR);
    } else {
      bean.addConstructorArgReference(bus);
    }
    for (int i = 0; i < atts.getLength(); i++) {
      Attr node = (Attr) atts.item(i);
      String val = node.getValue();
      String pre = node.getPrefix();
      String name = node.getLocalName();

      if ("createdFromAPI".equals(name)) {
        bean.setAbstract(true);
        isAbstract = true;
      } else if (isAttribute(pre, name) && !"publish".equals(name) && !"bus".equals(name)) {
        if ("endpointName".equals(name) || "serviceName".equals(name)) {
          QName q = parseQName(element, val);
          bean.addPropertyValue(name, q);
        } else if ("depends-on".equals(name)) {
          bean.addDependsOn(val);
        } else if (IMPLEMENTOR.equals(name)) {
          loadImplementor(bean, val);
        } else if (!"name".equals(name)) {
          mapToProperty(bean, name, val);
        }
      } else if ("abstract".equals(name)) {
        bean.setAbstract(true);
        isAbstract = true;
      } else if ("publish".equals(name)) {
        publish = "true".equals(val);
      }
    }

    Element elem = DOMUtils.getFirstElement(element);
    while (elem != null) {
      String name = elem.getLocalName();
      if ("properties".equals(name)) {
        Map<?, ?> map = ctx.getDelegate().parseMapElement(elem, bean.getBeanDefinition());
        bean.addPropertyValue("properties", map);
      } else if ("binding".equals(name)) {
        setFirstChildAsProperty(elem, ctx, bean, "bindingConfig");
      } else if ("inInterceptors".equals(name)
          || "inFaultInterceptors".equals(name)
          || "outInterceptors".equals(name)
          || "outFaultInterceptors".equals(name)
          || "features".equals(name)
          || "schemaLocations".equals(name)
          || "handlers".equals(name)) {
        List<?> list = ctx.getDelegate().parseListElement(elem, bean.getBeanDefinition());
        bean.addPropertyValue(name, list);
      } else if (IMPLEMENTOR.equals(name)) {
        ctx.getDelegate().parseConstructorArgElement(elem, bean.getBeanDefinition());
      } else {
        setFirstChildAsProperty(elem, ctx, bean, name);
      }
      elem = DOMUtils.getNextElement(elem);
    }
    if (!isAbstract) {
      if (publish) {
        bean.setInitMethodName("publish");
      }
      bean.setDestroyMethodName("stop");
    }
    // We don't want to delay the registration of our Server
    bean.setLazyInit(false);
  }
  private ManagedList<?> getMessageConverters(
      Element element, Object source, ParserContext parserContext) {
    Element convertersElement = DomUtils.getChildElementByTagName(element, "message-converters");
    ManagedList<? super Object> messageConverters = new ManagedList<Object>();
    if (convertersElement != null) {
      messageConverters.setSource(source);
      for (Element beanElement :
          DomUtils.getChildElementsByTagName(convertersElement, "bean", "ref")) {
        Object object = parserContext.getDelegate().parsePropertySubElement(beanElement, null);
        messageConverters.add(object);
      }
    }

    if (convertersElement == null
        || Boolean.valueOf(convertersElement.getAttribute("register-defaults"))) {
      messageConverters.setSource(source);
      messageConverters.add(createConverterDefinition(ByteArrayHttpMessageConverter.class, source));

      RootBeanDefinition stringConverterDef =
          createConverterDefinition(StringHttpMessageConverter.class, source);
      stringConverterDef.getPropertyValues().add("writeAcceptCharset", false);
      messageConverters.add(stringConverterDef);

      messageConverters.add(createConverterDefinition(ResourceHttpMessageConverter.class, source));
      messageConverters.add(createConverterDefinition(SourceHttpMessageConverter.class, source));
      messageConverters.add(
          createConverterDefinition(AllEncompassingFormHttpMessageConverter.class, source));

      if (romePresent) {
        messageConverters.add(
            createConverterDefinition(AtomFeedHttpMessageConverter.class, source));
        messageConverters.add(
            createConverterDefinition(RssChannelHttpMessageConverter.class, source));
      }

      if (jackson2XmlPresent) {
        RootBeanDefinition jacksonConverterDef =
            createConverterDefinition(MappingJackson2XmlHttpMessageConverter.class, source);
        GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
        jacksonFactoryDef.getPropertyValues().add("createXmlMapper", true);
        jacksonConverterDef
            .getConstructorArgumentValues()
            .addIndexedArgumentValue(0, jacksonFactoryDef);
        messageConverters.add(jacksonConverterDef);
      } else if (jaxb2Present) {
        messageConverters.add(
            createConverterDefinition(Jaxb2RootElementHttpMessageConverter.class, source));
      }

      if (jackson2Present) {
        RootBeanDefinition jacksonConverterDef =
            createConverterDefinition(MappingJackson2HttpMessageConverter.class, source);
        GenericBeanDefinition jacksonFactoryDef = createObjectMapperFactoryDefinition(source);
        jacksonConverterDef
            .getConstructorArgumentValues()
            .addIndexedArgumentValue(0, jacksonFactoryDef);
        messageConverters.add(jacksonConverterDef);
      } else if (gsonPresent) {
        messageConverters.add(createConverterDefinition(GsonHttpMessageConverter.class, source));
      }
    }
    return messageConverters;
  }
 protected void parseChild(
     Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
   super.parseChild(element, parserContext, builder);
   Properties parsedProps = parserContext.getDelegate().parsePropsElement(element);
   builder.addPropertyValue("properties", parsedProps);
 }