/** {@inheritDoc} */
  @Override
  protected void doParse(
      @Nonnull final Element config,
      @Nonnull final ParserContext parserContext,
      @Nonnull final BeanDefinitionBuilder builder) {

    log.warn("PrincipalConnector feature is DEPRECATED in favor of subject c14n flows");

    builder.setInitMethodName("initialize");
    builder.setDestroyMethodName("destroy");

    super.doParse(config, parserContext, builder);

    // First up, add the per type decoders
    addSAMLDecoders(config, parserContext, builder);

    final String format = StringSupport.trimOrNull(config.getAttributeNS(null, "nameIDFormat"));
    builder.addConstructorArgValue(format);

    final String id = StringSupport.trimOrNull(config.getAttributeNS(null, "id"));
    builder.addPropertyValue("id", id);

    final List<Element> children = ElementSupport.getChildElements(config, RELYING_PARTY);
    final List<String> relyingParties = new ManagedList<>(children.size());

    for (Element child : children) {
      relyingParties.add(child.getTextContent());
    }

    builder.addPropertyValue("relyingParties", relyingParties);
  }
  @Override
  protected void doParse(
      Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    attributesToProperties(element, builder, "basedir");

    URL configFileURL;

    try {
      configFileURL = parserContext.getReaderContext().getResource().getURL();
    } catch (IOException e) {
      configFileURL = null;
    }

    if (configFileURL != null) {
      builder.addPropertyValue("configFileURL", configFileURL);
    }

    ElementSelector pathSelector = and(sameNs(element), name("path"));
    List<Object> paths = createManagedList(element, parserContext);

    for (Element subElement : subElements(element, pathSelector)) {
      paths.add(parsePath(subElement, parserContext));
    }

    builder.addPropertyValue("paths", paths);
  }
  /**
   * Registers bean definitions for a {@link PluginRegistry} to capture {@link RelProvider}
   * instances. Wraps the registry into a {@link DelegatingRelProvider} bean definition backed by
   * the registry.
   *
   * @param registry
   */
  private static void registerRelProviderPluginRegistryAndDelegate(
      BeanDefinitionRegistry registry) {

    Class<?> defaultRelProviderType =
        EVO_PRESENT ? EvoInflectorRelProvider.class : DefaultRelProvider.class;
    RootBeanDefinition defaultRelProviderBeanDefinition =
        new RootBeanDefinition(defaultRelProviderType);
    registry.registerBeanDefinition("defaultRelProvider", defaultRelProviderBeanDefinition);

    RootBeanDefinition annotationRelProviderBeanDefinition =
        new RootBeanDefinition(AnnotationRelProvider.class);
    registry.registerBeanDefinition("annotationRelProvider", annotationRelProviderBeanDefinition);

    BeanDefinitionBuilder registryFactoryBeanBuilder =
        BeanDefinitionBuilder.rootBeanDefinition(PluginRegistryFactoryBean.class);
    registryFactoryBeanBuilder.addPropertyValue("type", RelProvider.class);
    registryFactoryBeanBuilder.addPropertyValue("exclusions", DelegatingRelProvider.class);

    AbstractBeanDefinition registryBeanDefinition = registryFactoryBeanBuilder.getBeanDefinition();
    registry.registerBeanDefinition("relProviderPluginRegistry", registryBeanDefinition);

    BeanDefinitionBuilder delegateBuilder =
        BeanDefinitionBuilder.rootBeanDefinition(DelegatingRelProvider.class);
    delegateBuilder.addConstructorArgValue(registryBeanDefinition);

    AbstractBeanDefinition beanDefinition = delegateBuilder.getBeanDefinition();
    beanDefinition.setPrimary(true);
    registry.registerBeanDefinition(DELEGATING_REL_PROVIDER_BEAN_NAME, beanDefinition);
  }
  @Override
  protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
    final BeanDefinitionBuilder builder =
        BeanDefinitionBuilder.genericBeanDefinition(ContentEnricher.class);

    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "request-channel");
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "reply-channel");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "request-timeout");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "reply-timeout");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "requires-reply");

    List<Element> subElements = DomUtils.getChildElementsByTagName(element, "property");
    if (!CollectionUtils.isEmpty(subElements)) {
      ManagedMap<String, Object> expressions = new ManagedMap<String, Object>();
      for (Element subElement : subElements) {
        String name = subElement.getAttribute("name");
        BeanDefinition beanDefinition =
            IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression(
                "value", "expression", parserContext, subElement, true);
        expressions.put(name, beanDefinition);
      }
      builder.addPropertyValue("propertyExpressions", expressions);
    }

    subElements = DomUtils.getChildElementsByTagName(element, "header");
    if (!CollectionUtils.isEmpty(subElements)) {
      ManagedMap<String, Object> expressions = new ManagedMap<String, Object>();
      for (Element subElement : subElements) {
        String name = subElement.getAttribute("name");
        BeanDefinition expressionDefinition =
            IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression(
                "value", "expression", parserContext, subElement, true);
        BeanDefinitionBuilder valueProcessorBuilder =
            BeanDefinitionBuilder.genericBeanDefinition(
                IntegrationNamespaceUtils.BASE_PACKAGE
                    + ".transformer.support.ExpressionEvaluatingHeaderValueMessageProcessor");
        valueProcessorBuilder
            .addConstructorArgValue(expressionDefinition)
            .addConstructorArgValue(subElement.getAttribute("type"));
        IntegrationNamespaceUtils.setValueIfAttributeDefined(
            valueProcessorBuilder, subElement, "overwrite");
        expressions.put(name, valueProcessorBuilder.getBeanDefinition());
      }
      builder.addPropertyValue("headerExpressions", expressions);
    }

    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "should-clone-payload");

    String requestPayloadExpression = element.getAttribute("request-payload-expression");

    if (StringUtils.hasText(requestPayloadExpression)) {
      BeanDefinitionBuilder expressionBuilder =
          BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class);
      expressionBuilder.addConstructorArgValue(requestPayloadExpression);
      builder.addPropertyValue("requestPayloadExpression", expressionBuilder.getBeanDefinition());
    }

    return builder;
  }
Exemple #5
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);
 }
  /**
   * Create a new {@link BeanDefinitionBuilder} for the class {@link StoredProcExecutor}. Initialize
   * the wrapped {@link StoredProcExecutor} with common properties.
   *
   * @param element Must not be Null
   * @param parserContext Must not be Null
   * @return The {@link BeanDefinitionBuilder} for the {@link StoredProcExecutor}
   */
  public static BeanDefinitionBuilder getStoredProcExecutorBuilder(
      final Element element, final ParserContext parserContext) {

    Assert.notNull(element, "The provided element must not be Null.");
    Assert.notNull(parserContext, "The provided parserContext must not be Null.");

    final String dataSourceRef = element.getAttribute("data-source");

    final BeanDefinitionBuilder storedProcExecutorBuilder =
        BeanDefinitionBuilder.genericBeanDefinition(StoredProcExecutor.class);
    storedProcExecutorBuilder.addConstructorArgReference(dataSourceRef);

    final String storedProcedureName = element.getAttribute("stored-procedure-name");
    final String storedProcedureNameExpression =
        element.getAttribute("stored-procedure-name-expression");
    boolean hasStoredProcedureName = StringUtils.hasText(storedProcedureName);
    boolean hasStoredProcedureNameExpression = StringUtils.hasText(storedProcedureNameExpression);

    if (!(hasStoredProcedureName ^ hasStoredProcedureNameExpression)) {
      parserContext
          .getReaderContext()
          .error(
              "Exactly one of 'stored-procedure-name' or 'stored-procedure-name-expression' is required",
              element);
    }

    BeanDefinitionBuilder expressionBuilder;
    if (hasStoredProcedureNameExpression) {
      expressionBuilder = BeanDefinitionBuilder.genericBeanDefinition(ExpressionFactoryBean.class);
      expressionBuilder.addConstructorArgValue(storedProcedureNameExpression);
    } else {
      expressionBuilder = BeanDefinitionBuilder.genericBeanDefinition(LiteralExpression.class);
      expressionBuilder.addConstructorArgValue(storedProcedureName);
    }
    storedProcExecutorBuilder.addPropertyValue(
        "storedProcedureNameExpression", expressionBuilder.getBeanDefinition());

    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        storedProcExecutorBuilder, element, "ignore-column-meta-data");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        storedProcExecutorBuilder, element, "jdbc-call-operations-cache-size");

    final ManagedList<BeanDefinition> procedureParameterList =
        StoredProcParserUtils.getProcedureParameterBeanDefinitions(element, parserContext);
    final ManagedList<BeanDefinition> sqlParameterDefinitionList =
        StoredProcParserUtils.getSqlParameterDefinitionBeanDefinitions(element, parserContext);

    if (!procedureParameterList.isEmpty()) {
      storedProcExecutorBuilder.addPropertyValue("procedureParameters", procedureParameterList);
    }
    if (!sqlParameterDefinitionList.isEmpty()) {
      storedProcExecutorBuilder.addPropertyValue("sqlParameters", sqlParameterDefinitionList);
    }

    return storedProcExecutorBuilder;
  }
 protected void doParse(Element element, BeanDefinitionBuilder bean) {
   String id = element.getAttribute("id");
   String name = element.getAttribute("name");
   if (StringUtils.hasText(id)) {
     bean.addPropertyValue("id", Integer.valueOf(id));
   }
   if (StringUtils.hasText(name)) {
     bean.addPropertyValue("name", name);
   }
 }
 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));
 }
 /**
  * Parse attributes of "transactional" element and configure a {@link DefaultTransactionAttribute}
  * with provided "transactionDefinition" properties.
  */
 public static BeanDefinition configureTransactionDefinition(Element txElement) {
   BeanDefinitionBuilder txDefinitionBuilder =
       BeanDefinitionBuilder.genericBeanDefinition(DefaultTransactionAttribute.class);
   txDefinitionBuilder.addPropertyValue(
       "propagationBehaviorName", "PROPAGATION_" + txElement.getAttribute("propagation"));
   txDefinitionBuilder.addPropertyValue(
       "isolationLevelName", "ISOLATION_" + txElement.getAttribute("isolation"));
   txDefinitionBuilder.addPropertyValue("timeout", txElement.getAttribute("timeout"));
   txDefinitionBuilder.addPropertyValue("readOnly", txElement.getAttribute("read-only"));
   return txDefinitionBuilder.getBeanDefinition();
 }
 public static BeanDefinition buildTransportClientDef(String esNodes, String settingsFile) {
   BeanDefinitionBuilder nodeFactory =
       BeanDefinitionBuilder.rootBeanDefinition(ElasticsearchTransportClientFactoryBean.class);
   if (settingsFile != null && settingsFile.length() > 0) {
     nodeFactory.addPropertyValue("settingsFile", settingsFile);
   }
   if (esNodes != null && esNodes.length() > 0) {
     nodeFactory.addPropertyValue("esNodes", esNodes);
   }
   return nodeFactory.getBeanDefinition();
 }
Exemple #11
0
    @Override
    protected final void doParse(
        Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
      Object condition = parseCondition(element, parserContext, builder);

      if (condition != null) {
        builder.addPropertyValue("condition", condition);
      }

      builder.addPropertyValue("block", parsePipeline(element, parserContext));
    }
Exemple #12
0
  @Override
  protected void doParse(Element element, BeanDefinitionBuilder builder) {
    String clz = element.getAttribute("class");
    String key = element.getAttribute("key");

    builder.addPropertyValue("typeClass", clz);
    if (StringUtils.hasText(key)) {
      builder.addPropertyValue("key", key);
    }

    super.doParse(element, builder);
  }
  @Override
  protected void doParse(Element element, BeanDefinitionBuilder builder) {
    String url = element.getAttribute("url");
    //        String port = element.getAttribute("port");
    String pollingIntervalMs = element.getAttribute("polling-interval-ms");

    builder.addPropertyValue("url", url);
    //        builder.addPropertyValue("port", Integer.valueOf(port));
    if (StringUtils.hasText(pollingIntervalMs)) {
      builder.addPropertyValue("pollingIntervalMs", Integer.valueOf(pollingIntervalMs));
    }
  }
 @Override
 protected AbstractBeanDefinition parseInternal(Element element, ParserContext parserContext) {
   BeanDefinitionBuilder builder =
       BeanDefinitionBuilder.genericBeanDefinition(RequestHandlerRetryAdvice.class);
   BeanDefinitionBuilder retryTemplateBuilder =
       BeanDefinitionBuilder.genericBeanDefinition(RetryTemplate.class);
   boolean customTemplate = false;
   Element backOffPolicyEle = DomUtils.getChildElementByTagName(element, "fixed-back-off");
   BeanDefinitionBuilder backOffBuilder = null;
   if (backOffPolicyEle != null) {
     backOffBuilder = BeanDefinitionBuilder.genericBeanDefinition(FixedBackOffPolicy.class);
     IntegrationNamespaceUtils.setValueIfAttributeDefined(
         backOffBuilder, backOffPolicyEle, "interval", "backOffPeriod");
   } else {
     backOffPolicyEle = DomUtils.getChildElementByTagName(element, "exponential-back-off");
     if (backOffPolicyEle != null) {
       backOffBuilder =
           BeanDefinitionBuilder.genericBeanDefinition(ExponentialBackOffPolicy.class);
       IntegrationNamespaceUtils.setValueIfAttributeDefined(
           backOffBuilder, backOffPolicyEle, "initial", "initialInterval");
       IntegrationNamespaceUtils.setValueIfAttributeDefined(
           backOffBuilder, backOffPolicyEle, "multiplier");
       IntegrationNamespaceUtils.setValueIfAttributeDefined(
           backOffBuilder, backOffPolicyEle, "maximum", "maxInterval");
     }
   }
   if (backOffBuilder != null) {
     retryTemplateBuilder.addPropertyValue("backOffPolicy", backOffBuilder.getBeanDefinition());
     customTemplate = true;
   }
   String maxAttemptsAttr = element.getAttribute("max-attempts");
   if (StringUtils.hasText(maxAttemptsAttr)) {
     BeanDefinitionBuilder retryPolicyBuilder =
         BeanDefinitionBuilder.genericBeanDefinition(SimpleRetryPolicy.class);
     IntegrationNamespaceUtils.setValueIfAttributeDefined(
         retryPolicyBuilder, element, "max-attempts");
     retryTemplateBuilder.addPropertyValue("retryPolicy", retryPolicyBuilder.getBeanDefinition());
     customTemplate = true;
   }
   if (customTemplate) {
     builder.addPropertyValue("retryTemplate", retryTemplateBuilder.getBeanDefinition());
   }
   String recoveryChannelAttr = element.getAttribute("recovery-channel");
   if (StringUtils.hasText(recoveryChannelAttr)) {
     BeanDefinitionBuilder emsrBuilder =
         BeanDefinitionBuilder.genericBeanDefinition(ErrorMessageSendingRecoverer.class);
     emsrBuilder.addConstructorArgReference(recoveryChannelAttr);
     IntegrationNamespaceUtils.setValueIfAttributeDefined(emsrBuilder, element, "send-timeout");
     builder.addPropertyValue("recoveryCallback", emsrBuilder.getBeanDefinition());
   }
   return builder.getBeanDefinition();
 }
 /**
  * Parse a "transactional" element and configure a {@link TransactionInterceptor} with
  * "transactionManager" and other "transactionDefinition" properties. For example, this advisor
  * will be applied on the Polling Task proxy
  *
  * @see AbstractPollingEndpoint
  */
 public static BeanDefinition configureTransactionAttributes(Element txElement) {
   BeanDefinition txDefinition = configureTransactionDefinition(txElement);
   BeanDefinitionBuilder attributeSourceBuilder =
       BeanDefinitionBuilder.genericBeanDefinition(MatchAlwaysTransactionAttributeSource.class);
   attributeSourceBuilder.addPropertyValue("transactionAttribute", txDefinition);
   BeanDefinitionBuilder txInterceptorBuilder =
       BeanDefinitionBuilder.genericBeanDefinition(TransactionInterceptor.class);
   txInterceptorBuilder.addPropertyReference(
       "transactionManager", txElement.getAttribute("transaction-manager"));
   txInterceptorBuilder.addPropertyValue(
       "transactionAttributeSource", attributeSourceBuilder.getBeanDefinition());
   return txInterceptorBuilder.getBeanDefinition();
 }
  /*
   * (non-Javadoc)
   * @see org.springframework.data.repository.config.RepositoryConfigurationExtensionSupport#postProcess(org.springframework.beans.factory.support.BeanDefinitionBuilder, org.springframework.data.repository.config.RepositoryConfigurationSource)
   */
  @Override
  public void postProcess(BeanDefinitionBuilder builder, RepositoryConfigurationSource source) {

    String transactionManagerRef = source.getAttribute("transactionManagerRef");
    builder.addPropertyValue(
        "transactionManager",
        transactionManagerRef == null
            ? DEFAULT_TRANSACTION_MANAGER_BEAN_NAME
            : transactionManagerRef);
    builder.addPropertyValue(
        "entityManager", getEntityManagerBeanDefinitionFor(source, source.getSource()));
    builder.addPropertyReference("mappingContext", JPA_MAPPING_CONTEXT_BEAN_NAME);
  }
  /**
   * @param storedProcComponent
   * @param parserContext
   */
  public static ManagedList<BeanDefinition> getProcedureParameterBeanDefinitions(
      Element storedProcComponent, ParserContext parserContext) {

    ManagedList<BeanDefinition> procedureParameterList = new ManagedList<BeanDefinition>();

    List<Element> parameterChildElements =
        DomUtils.getChildElementsByTagName(storedProcComponent, "parameter");

    for (Element childElement : parameterChildElements) {

      BeanDefinitionBuilder parameterBuilder =
          BeanDefinitionBuilder.genericBeanDefinition(ProcedureParameter.class);

      String name = childElement.getAttribute("name");
      String expression = childElement.getAttribute("expression");
      String value = childElement.getAttribute("value");
      String type = childElement.getAttribute("type");

      if (StringUtils.hasText(name)) {
        parameterBuilder.addPropertyValue("name", name);
      }

      if (StringUtils.hasText(expression)) {
        parameterBuilder.addPropertyValue("expression", expression);
      }

      if (StringUtils.hasText(value)) {

        if (!StringUtils.hasText(type)) {

          if (LOGGER.isInfoEnabled()) {
            LOGGER.info(
                String.format(
                    "Type attribute not set for Store "
                        + "Procedure parameter '%s'. Defaulting to "
                        + "'java.lang.String'.",
                    value));
          }

          parameterBuilder.addPropertyValue("value", new TypedStringValue(value, String.class));

        } else {
          parameterBuilder.addPropertyValue("value", new TypedStringValue(value, type));
        }
      }

      procedureParameterList.add(parameterBuilder.getBeanDefinition());
    }

    return procedureParameterList;
  }
  @SuppressWarnings("unchecked")
  public void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    builder.addPropertyValue(
        "delegate", parseListenerElement(element, parserContext, builder.getRawBeanDefinition()));

    ManagedMap metaDataMap = new ManagedMap();
    for (String metaDataPropertyName : getMethodNameAttributes()) {
      String listenerMethod = element.getAttribute(metaDataPropertyName);
      if (StringUtils.hasText(listenerMethod)) {
        metaDataMap.put(metaDataPropertyName, listenerMethod);
      }
    }
    builder.addPropertyValue("metaDataMap", metaDataMap);
  }
  /**
   * @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();
  }
  /**
   * Load the template BeanDefinition and call {@link #transform(ConfigurableListableBeanFactory,
   * BeanDefinition, Element, ParserContext)} to apply runtime configuration value to it. <code>
   * builder</code> will be configured to instantiate the bean in the Spring context that we are
   * parsing.
   *
   * <p>During parsing, an instance of {@link
   * TemplateBeanDefinitionParser.TemplateComponentDefinition} is pushed onto <code>ParserContext
   * </code> so that nested tags can access the enclosing template configuration with a call to
   * {@link #findEnclosingTemplateFactory(ParserContext)}. Subclasses can override {@link
   * #newComponentDefinition(String, Object, DefaultListableBeanFactory)} to provide a subclass of
   * {@link TemplateBeanDefinitionParser.TemplateComponentDefinition} to the parser context if
   * necessary.
   */
  @Override
  protected final void doParse(
      Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {

    // if we have multiple nested bean definitions, we only parse the template factory
    // once.  this allows configuration changes made by enclosing bean parsers to be inherited
    // by contained beans, which is quite useful.
    DefaultListableBeanFactory templateFactory = findEnclosingTemplateFactory(parserContext);
    TemplateComponentDefinition tcd = null;
    if (templateFactory == null) {

      // no nesting -- load the template XML configuration from the classpath.
      final BeanFactory parentFactory = (BeanFactory) parserContext.getRegistry();
      templateFactory = new DefaultListableBeanFactory(parentFactory);

      // load template bean definitions
      DefaultResourceLoader loader = new DefaultResourceLoader();
      XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(templateFactory);
      reader.setResourceLoader(loader);
      reader.setEntityResolver(new ResourceEntityResolver(loader));
      reader.loadBeanDefinitions(templateResource);

      // propagate factory post-processors from the source factory into the template
      // factory.
      BeanDefinition ppChain = new RootBeanDefinition(ChainingBeanFactoryPostProcessor.class);
      ppChain.getPropertyValues().addPropertyValue("targetFactory", templateFactory);
      parserContext.getReaderContext().registerWithGeneratedName(ppChain);

      // push component definition onto the parser stack for the benefit of
      // nested bean definitions.
      tcd =
          newComponentDefinition(
              element.getNodeName(), parserContext.extractSource(element), templateFactory);
      parserContext.pushContainingComponent(tcd);
    }

    try {
      // allow subclasses to apply overrides to the template bean definition.
      BeanDefinition def = templateFactory.getBeanDefinition(templateId);
      transform(templateFactory, def, element, parserContext);

      // setup our factory bean to instantiate the modified bean definition upon request.
      builder.addPropertyValue("beanFactory", templateFactory);
      builder.addPropertyValue("beanName", templateId);
      builder.getRawBeanDefinition().setAttribute("id", def.getAttribute("id"));

    } finally {
      if (tcd != null) parserContext.popContainingComponent();
    }
  }
  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;
  }
  /** {@inheritDoc} */
  protected void doParse(Element config, BeanDefinitionBuilder builder) {
    log.info(
        "Parsing configuration for profile handler: {}",
        XMLHelper.getXSIType(config).getLocalPart());

    builder.addPropertyValue("requestPaths", getRequestPaths(config));
  }
  @Override
  protected void doParse(
      final Element element,
      final ParserContext parserContext,
      final BeanDefinitionBuilder builder) {
    String serviceRef = element.getAttribute("service-ref");
    builder.addConstructorArgValue(":" + serviceRef);
    builder.addConstructorArgReference(serviceRef);
    String marker = element.getAttribute("marker");
    if (StringUtils.hasLength(marker)) {
      Class<?> theClass =
          ClassUtils.resolveClassName(marker, Thread.currentThread().getContextClassLoader());
      if (!theClass.isAnnotation()) {
        throw new ConfigurationException(
            String.format("The class '%s' is not an annotation", marker));
      }
      builder.addPropertyValue("markerAnnotation", theClass);
    }

    // Register the post processor if there is not already one in this context
    String beanName = NamespaceBeanFactoryPostProcessor.class.getName();
    if (!parserContext.getRegistry().containsBeanDefinition(beanName)) {
      BeanDefinitionBuilder namespacePostProcessor =
          BeanDefinitionBuilder.genericBeanDefinition(NamespaceBeanFactoryPostProcessor.class);
      parserContext.registerBeanComponent(
          new BeanComponentDefinition(namespacePostProcessor.getBeanDefinition(), beanName));
    }
  }
 @Override
 protected BeanDefinitionBuilder buildBeanDefinition(
     Element element, ParserContext parserContext) {
   BeanDefinitionBuilder builder =
       BeanDefinitionBuilder.genericBeanDefinition(AmqpChannelFactoryBean.class);
   String messageDriven = element.getAttribute("message-driven");
   if (StringUtils.hasText(messageDriven)) {
     builder.addConstructorArgValue(messageDriven);
   }
   String connectionFactory = element.getAttribute("connection-factory");
   if (!StringUtils.hasText(connectionFactory)) {
     connectionFactory = "rabbitConnectionFactory";
   }
   builder.addPropertyReference("connectionFactory", connectionFactory);
   if ("channel".equals(element.getLocalName())) {
     builder.addPropertyValue("pubSub", false);
   } else if ("publish-subscribe-channel".equals(element.getLocalName())) {
     builder.addPropertyValue("pubSub", true);
   }
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "acknowledge-mode");
   IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "advice-chain");
   IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "amqp-admin");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "channel-transacted");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "concurrent-consumers");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "encoding");
   IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "error-handler");
   IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "exchange");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(
       builder, element, "expose-listener-channel");
   IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-converter");
   IntegrationNamespaceUtils.setReferenceIfAttributeDefined(
       builder, element, "message-properties-converter");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "phase");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "prefetch-count");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "queue-name");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "receive-timeout");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "recovery-interval");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "shutdown-timeout");
   IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "task-executor");
   IntegrationNamespaceUtils.setReferenceIfAttributeDefined(
       builder, element, "transaction-attribute");
   IntegrationNamespaceUtils.setReferenceIfAttributeDefined(
       builder, element, "transaction-manager");
   IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "tx-size");
   return builder;
 }
 public BeanDefinition parse(Element element, ParserContext parserContent) {
   BeanDefinitionBuilder builder =
       BeanDefinitionBuilder.rootBeanDefinition(GetMentionsMessageProcessor.class.getName());
   String configRef = element.getAttribute("config-ref");
   if ((configRef != null) && (!StringUtils.isBlank(configRef))) {
     builder.addPropertyValue("moduleObject", configRef);
   }
   if ((element.getAttribute("page") != null)
       && (!StringUtils.isBlank(element.getAttribute("page")))) {
     builder.addPropertyValue("page", element.getAttribute("page"));
   }
   if ((element.getAttribute("count") != null)
       && (!StringUtils.isBlank(element.getAttribute("count")))) {
     builder.addPropertyValue("count", element.getAttribute("count"));
   }
   if ((element.getAttribute("sinceId") != null)
       && (!StringUtils.isBlank(element.getAttribute("sinceId")))) {
     builder.addPropertyValue("sinceId", element.getAttribute("sinceId"));
   }
   BeanDefinition definition = builder.getBeanDefinition();
   definition.setAttribute(
       MuleHierarchicalBeanDefinitionParserDelegate.MULE_NO_RECURSE, Boolean.TRUE);
   MutablePropertyValues propertyValues =
       parserContent.getContainingBeanDefinition().getPropertyValues();
   if (parserContent
       .getContainingBeanDefinition()
       .getBeanClassName()
       .equals("org.mule.config.spring.factories.PollingMessageSourceFactoryBean")) {
     propertyValues.addPropertyValue("messageProcessor", definition);
   } else {
     if (parserContent
         .getContainingBeanDefinition()
         .getBeanClassName()
         .equals("org.mule.enricher.MessageEnricher")) {
       propertyValues.addPropertyValue("enrichmentMessageProcessor", definition);
     } else {
       PropertyValue messageProcessors = propertyValues.getPropertyValue("messageProcessors");
       if ((messageProcessors == null) || (messageProcessors.getValue() == null)) {
         propertyValues.addPropertyValue("messageProcessors", new ManagedList());
       }
       List listMessageProcessors =
           ((List) propertyValues.getPropertyValue("messageProcessors").getValue());
       listMessageProcessors.add(definition);
     }
   }
   return definition;
 }
  public void parseListeners(
      Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    ManagedList<AbstractBeanDefinition> listeners = parseListeners(element, parserContext);

    if (listeners.size() > 0) {
      builder.addPropertyValue(propertyKey, listeners);
    }
  }
 @Override
 protected void doParse(
     Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
   if (element.hasAttribute(XMLConstants.DURATION)) {
     builder.addPropertyValue(XMLConstants.ITERATIONS, -1);
     builder.addPropertyValue(XMLConstants.DURATION, element.getAttribute(XMLConstants.DURATION));
   } else {
     if (element.hasAttribute(XMLConstants.MAX_DURATION)) {
       builder.addPropertyValue(
           XMLConstants.DURATION, element.getAttribute(XMLConstants.MAX_DURATION));
     } else {
       builder.addPropertyValue(XMLConstants.DURATION, null);
     }
     builder.addPropertyValue(
         XMLConstants.ITERATIONS, element.getAttribute(XMLConstants.ITERATIONS));
   }
 }
  @Override
  protected BeanMetadataElement parseSource(Element element, ParserContext parserContext) {

    final BeanDefinitionBuilder jpaPollingChannelAdapterBuilder =
        BeanDefinitionBuilder.genericBeanDefinition(JpaPollingChannelAdapter.class);

    final BeanDefinitionBuilder jpaExecutorBuilder =
        JpaParserUtils.getJpaExecutorBuilder(element, parserContext);

    String maxNumberOfResults = element.getAttribute("max-number-of-results");
    boolean hasMaxNumberOfResults = StringUtils.hasText(maxNumberOfResults);

    String maxResults = element.getAttribute("max-results");
    boolean hasMaxResults = StringUtils.hasText(maxResults);

    if (hasMaxNumberOfResults) {
      parserContext
          .getReaderContext()
          .warning("'max-number-of-results' is deprecated in favor of 'max-results'", element);
      if (hasMaxResults) {
        parserContext
            .getReaderContext()
            .error("'max-number-of-results' and 'max-results' are mutually exclusive", element);
      } else {
        element.setAttribute("max-results", maxNumberOfResults);
      }
    }

    BeanDefinition definition =
        IntegrationNamespaceUtils.createExpressionDefinitionFromValueOrExpression(
            "max-results", "max-results-expression", parserContext, element, false);
    if (definition != null) {
      jpaExecutorBuilder.addPropertyValue("maxResultsExpression", definition);
    }
    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        jpaExecutorBuilder, element, "delete-after-poll");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        jpaExecutorBuilder, element, "flush-after-delete", "flush");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        jpaExecutorBuilder, element, "delete-in-batch");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        jpaExecutorBuilder, element, "expect-single-result");
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(
        jpaExecutorBuilder, element, "parameter-source");

    final BeanDefinition jpaExecutorBuilderBeanDefinition = jpaExecutorBuilder.getBeanDefinition();
    final String channelAdapterId =
        this.resolveId(
            element, jpaPollingChannelAdapterBuilder.getRawBeanDefinition(), parserContext);
    final String jpaExecutorBeanName = channelAdapterId + ".jpaExecutor";

    parserContext.registerBeanComponent(
        new BeanComponentDefinition(jpaExecutorBuilderBeanDefinition, jpaExecutorBeanName));

    jpaPollingChannelAdapterBuilder.addConstructorArgReference(jpaExecutorBeanName);

    return jpaPollingChannelAdapterBuilder.getBeanDefinition();
  }
  @Override
  protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
    BeanDefinitionBuilder builder =
        BeanDefinitionBuilder.genericBeanDefinition(
            "org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler");
    builder.addConstructorArgValue(element.getAttribute("url"));
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "http-method");

    String restTemplate = element.getAttribute("rest-template");
    if (StringUtils.hasText(restTemplate)) {
      HttpAdapterParsingUtils.verifyNoRestTemplateAttributes(element, parserContext);
      builder.addConstructorArgReference(restTemplate);
    } else {
      for (String referenceAttributeName :
          HttpAdapterParsingUtils.REST_TEMPLATE_REFERENCE_ATTRIBUTES) {
        IntegrationNamespaceUtils.setReferenceIfAttributeDefined(
            builder, element, referenceAttributeName);
      }
    }

    String headerMapper = element.getAttribute("header-mapper");
    String mappedRequestHeaders = element.getAttribute("mapped-request-headers");
    String mappedResponseHeaders = element.getAttribute("mapped-response-headers");
    if (StringUtils.hasText(headerMapper)) {
      if (StringUtils.hasText(mappedRequestHeaders) || StringUtils.hasText(mappedResponseHeaders)) {
        parserContext
            .getReaderContext()
            .error(
                "Neither 'mappped-request-headers' or 'mapped-response-headers' "
                    + "attributes are allowed when a 'header-mapper' has been specified.",
                parserContext.extractSource(element));
        return null;
      }
      builder.addPropertyReference("headerMapper", headerMapper);
    } else {
      BeanDefinitionBuilder headerMapperBuilder =
          BeanDefinitionBuilder.genericBeanDefinition(
              "org.springframework.integration.http.support.DefaultHttpHeaderMapper");
      headerMapperBuilder.setFactoryMethod("outboundMapper");
      IntegrationNamespaceUtils.setValueIfAttributeDefined(
          headerMapperBuilder, element, "mapped-request-headers", "outboundHeaderNames");
      IntegrationNamespaceUtils.setValueIfAttributeDefined(
          headerMapperBuilder, element, "mapped-response-headers", "inboundHeaderNames");
      builder.addPropertyValue("headerMapper", headerMapperBuilder.getBeanDefinition());
    }
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "charset");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        builder, element, "extract-request-payload", "extractPayload");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        builder, element, "expected-response-type");
    IntegrationNamespaceUtils.setValueIfAttributeDefined(
        builder, element, "reply-timeout", "sendTimeout");
    IntegrationNamespaceUtils.setReferenceIfAttributeDefined(
        builder, element, "reply-channel", "outputChannel");
    HttpAdapterParsingUtils.configureUriVariableExpressions(builder, element);
    IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "transfer-cookies");
    return builder;
  }
Exemple #30
0
  protected void parseChild(
      Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
    Element parent = (Element) element.getParentNode();
    String serviceName = parent.getAttribute(ATTRIBUTE_NAME);
    builder.addPropertyReference("service", serviceName);

    // Create a BeanDefinition for the nested object factory and set it a
    // property value for the component
    AbstractBeanDefinition objectFactoryBeanDefinition = new GenericBeanDefinition();
    objectFactoryBeanDefinition.setBeanClass(OBJECT_FACTORY_TYPE);
    objectFactoryBeanDefinition
        .getPropertyValues()
        .addPropertyValue(AbstractObjectFactory.ATTRIBUTE_OBJECT_CLASS, componentInstanceClass);
    objectFactoryBeanDefinition.setInitMethodName(Initialisable.PHASE_NAME);
    objectFactoryBeanDefinition.setDestroyMethodName(Disposable.PHASE_NAME);
    Map props = new HashMap();
    for (int i = 0; i < element.getAttributes().getLength(); i++) {
      Node n = element.getAttributes().item(i);
      props.put(n.getLocalName(), n.getNodeValue());
    }
    String returnData = null;

    NodeList list = element.getChildNodes();
    for (int i = 0; i < list.getLength(); i++) {
      if ("return-data".equals(list.item(i).getLocalName())) {
        Element rData = (Element) list.item(i);
        if (StringUtils.isNotEmpty(rData.getAttribute("file"))) {
          String file = rData.getAttribute("file");
          try {
            returnData = IOUtils.getResourceAsString(file, getClass());
          } catch (IOException e) {
            throw new BeanCreationException("Failed to load test-data resource: " + file, e);
          }
        } else {
          returnData = rData.getTextContent();
        }
      } else if ("callback".equals(list.item(i).getLocalName())) {
        Element ele = (Element) list.item(i);
        String c = ele.getAttribute("class");
        try {
          EventCallback cb = (EventCallback) ClassUtils.instanciateClass(c);
          props.put("eventCallback", cb);

        } catch (Exception e) {
          throw new BeanCreationException("Failed to load event-callback: " + c, e);
        }
      }
    }

    if (returnData != null) {
      props.put("returnData", returnData);
    }
    objectFactoryBeanDefinition.getPropertyValues().addPropertyValue("properties", props);

    builder.addPropertyValue("objectFactory", objectFactoryBeanDefinition);

    super.parseChild(element, parserContext, builder);
  }