public static PersistentResourceXMLBuilder getBoundedQueueThreadPoolParser(
      BoundedQueueThreadPoolResourceDefinition definition) {
    PersistentResourceXMLBuilder builder =
        builder(definition)
            .addAttributes(
                PoolAttributeDefinitions.KEEPALIVE_TIME,
                PoolAttributeDefinitions.MAX_THREADS,
                PoolAttributeDefinitions.THREAD_FACTORY,
                PoolAttributeDefinitions.CORE_THREADS,
                PoolAttributeDefinitions.QUEUE_LENGTH,
                PoolAttributeDefinitions.ALLOW_CORE_TIMEOUT);

    if (!definition.isBlocking()) {
      builder.addAttribute(PoolAttributeDefinitions.HANDOFF_EXECUTOR);
    }
    return builder;
  }
/** @author Tomaz Cerar (c) 2015 Red Hat Inc. */
public class ThreadsParser2_0 extends PersistentResourceXMLParser {
  static final ThreadsParser2_0 INSTANCE = new ThreadsParser2_0();

  public static final PersistentResourceXMLBuilder THREAD_FACTORY_PARSER =
      getThreadFactoryParser(ThreadFactoryResourceDefinition.DEFAULT_INSTANCE);

  @SuppressWarnings("deprecation")
  private static final PersistentResourceXMLDescription xmlDescription =
      builder(new ThreadSubsystemResourceDefinition(false), Namespace.CURRENT.getUriString())
          .addChild(THREAD_FACTORY_PARSER)
          .addChild(
              getUnboundedQueueThreadPoolParser(
                  UnboundedQueueThreadPoolResourceDefinition.create(false)))
          .addChild(
              getBoundedQueueThreadPoolParser(
                  BoundedQueueThreadPoolResourceDefinition.create(false, false)))
          .addChild(
              getBoundedQueueThreadPoolParser(
                  BoundedQueueThreadPoolResourceDefinition.create(true, false)))
          .addChild(
              getQueuelessThreadPoolParser(
                  QueuelessThreadPoolResourceDefinition.create(false, false)))
          .addChild(
              getQueuelessThreadPoolParser(
                  QueuelessThreadPoolResourceDefinition.create(true, false)))
          .addChild(
              getScheduledThreadPoolParser(ScheduledThreadPoolResourceDefinition.create(false)))
          .build();

  @Override
  public PersistentResourceXMLDescription getParserDescription() {
    return xmlDescription;
  }

  public static PersistentResourceXMLBuilder getThreadFactoryParser(
      ThreadFactoryResourceDefinition factoryResourceDefinition) {
    return builder(factoryResourceDefinition)
        .addAttributes(
            PoolAttributeDefinitions.GROUP_NAME,
            PoolAttributeDefinitions.THREAD_NAME_PATTERN,
            PoolAttributeDefinitions.PRIORITY);
  }

  public static PersistentResourceXMLBuilder getUnboundedQueueThreadPoolParser(
      UnboundedQueueThreadPoolResourceDefinition resourceDefinition) {
    return builder(resourceDefinition)
        .addAttributes(
            PoolAttributeDefinitions.KEEPALIVE_TIME,
            PoolAttributeDefinitions.MAX_THREADS,
            PoolAttributeDefinitions.THREAD_FACTORY);
  }

  public static PersistentResourceXMLBuilder getScheduledThreadPoolParser(
      ScheduledThreadPoolResourceDefinition resourceDefinition) {
    return builder(resourceDefinition)
        .addAttributes(
            PoolAttributeDefinitions.KEEPALIVE_TIME,
            PoolAttributeDefinitions.MAX_THREADS,
            PoolAttributeDefinitions.THREAD_FACTORY);
  }

  public static PersistentResourceXMLBuilder getQueuelessThreadPoolParser(
      QueuelessThreadPoolResourceDefinition definition) {
    PersistentResourceXMLBuilder builder =
        builder(definition)
            .addAttributes(
                PoolAttributeDefinitions.KEEPALIVE_TIME,
                PoolAttributeDefinitions.MAX_THREADS,
                PoolAttributeDefinitions.THREAD_FACTORY);

    if (!definition.isBlocking()) {
      builder.addAttribute(PoolAttributeDefinitions.HANDOFF_EXECUTOR);
    }
    return builder;
  }

  public static PersistentResourceXMLBuilder getBoundedQueueThreadPoolParser(
      BoundedQueueThreadPoolResourceDefinition definition) {
    PersistentResourceXMLBuilder builder =
        builder(definition)
            .addAttributes(
                PoolAttributeDefinitions.KEEPALIVE_TIME,
                PoolAttributeDefinitions.MAX_THREADS,
                PoolAttributeDefinitions.THREAD_FACTORY,
                PoolAttributeDefinitions.CORE_THREADS,
                PoolAttributeDefinitions.QUEUE_LENGTH,
                PoolAttributeDefinitions.ALLOW_CORE_TIMEOUT);

    if (!definition.isBlocking()) {
      builder.addAttribute(PoolAttributeDefinitions.HANDOFF_EXECUTOR);
    }
    return builder;
  }
}