Beispiel #1
0
  /**
   * Creates a new attribute service using the given providers and user provided default attribute
   * values.
   */
  public AttributeService(
      Iterable<? extends AttributeProvider> providers, Map<String, ?> userProvidedDefaults) {
    ImmutableMap.Builder<String, AttributeProvider> byViewNameBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<Class<?>, AttributeProvider> byViewTypeBuilder = ImmutableMap.builder();
    ImmutableMap.Builder<Class<?>, AttributeProvider> byAttributesTypeBuilder =
        ImmutableMap.builder();

    ImmutableList.Builder<FileAttribute<?>> defaultAttributesBuilder = ImmutableList.builder();

    for (AttributeProvider provider : providers) {
      byViewNameBuilder.put(provider.name(), provider);
      byViewTypeBuilder.put(provider.viewType(), provider);
      if (provider.attributesType() != null) {
        byAttributesTypeBuilder.put(provider.attributesType(), provider);
      }

      for (Map.Entry<String, ?> entry : provider.defaultValues(userProvidedDefaults).entrySet()) {
        defaultAttributesBuilder.add(new SimpleFileAttribute<>(entry.getKey(), entry.getValue()));
      }
    }

    this.providersByName = byViewNameBuilder.build();
    this.providersByViewType = byViewTypeBuilder.build();
    this.providersByAttributesType = byAttributesTypeBuilder.build();
    this.defaultValues = defaultAttributesBuilder.build();
  }
Beispiel #2
0
  private static void addStandardProvider(Map<String, AttributeProvider> result, String view) {
    AttributeProvider provider = StandardAttributeProviders.get(view);

    if (provider == null) {
      if (!result.containsKey(view)) {
        throw new IllegalStateException("no provider found for attribute view '" + view + "'");
      }
    } else {
      result.put(provider.name(), provider);
    }
  }
Beispiel #3
0
  private static Iterable<AttributeProvider> getProviders(Configuration configuration) {
    Map<String, AttributeProvider> result = new HashMap<>();

    for (AttributeProvider provider : configuration.attributeProviders) {
      result.put(provider.name(), provider);
    }

    for (String view : configuration.attributeViews) {
      addStandardProvider(result, view);
    }

    addMissingProviders(result);

    return Collections.unmodifiableCollection(result.values());
  }