Ejemplo n.º 1
0
  @SuppressWarnings({"unchecked"})
  public ConfigurationLoader(Object context) {
    caches = Iterators.asList(ServiceLoader.load(ConfigurationCacheProvider.class));
    Collections.sort(caches, new WeightedComparator());

    providers = Iterators.asList(ServiceLoader.load(ConfigurationProvider.class));
    Collections.sort(providers, new WeightedComparator());
  }
Ejemplo n.º 2
0
 @SuppressWarnings("unchecked")
 ConfigurationRuleBuilder(final ConfigurationBuilder config, final RuleBuilder rule) {
   this.interceptors =
       Iterators.asList(ServiceLoader.load(ConfigurationRuleBuilderInterceptor.class));
   this.wrapped = config;
   this.rule = rule;
 }
Ejemplo n.º 3
0
  @SuppressWarnings({"rawtypes", "unchecked"})
  public ParserContext(ConfigurationBuilder builder) {
    List<ElementHandler> loadedHandlers =
        Iterators.asList(ServiceLoader.load(ElementHandler.class));
    for (ElementHandler handler : loadedHandlers) {
      NamespaceElementHandler annotation =
          Annotations.getAnnotation(handler.getClass(), NamespaceElementHandler.class);
      if (annotation != null) {
        handlers.put(new HandlerId(annotation.namespace(), annotation.elementName()), handler);
      }
    }

    this.builder = builder;
  }
Ejemplo n.º 4
0
  /**
   * Called one by {@link #getAdapterFactory()} to obtain the {@link LogAdapterFactory} with the
   * highest priority.
   */
  @SuppressWarnings("unchecked")
  private static LogAdapterFactory createAdapterFactory() {
    List<LogAdapterFactory> factories =
        Iterators.asList(ServiceLoader.load(LogAdapterFactory.class));
    if (factories.isEmpty()) {
      /*
       * Always fall back to the JDK, even if our service loading mechanism is hosed for some reason.
       */
      factories = Arrays.asList((LogAdapterFactory) new JDKLogAdapterFactory());
    }

    /*
     * Sort factories by priority.
     */
    Collections.sort(factories, new WeightedComparator());

    /*
     * Use the factory with the highest priority.
     */
    return factories.get(0);
  }