/*
 * #%L
 * wcm.io
 * %%
 * Copyright (C) 2017 wcm.io
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */
package io.wcm.devops.conga.generator.spi.context;

import java.util.Collections;
import java.util.Map;

/**
 * Context for {@link io.wcm.devops.conga.generator.spi.ValueProviderPlugin}.
 */
public final class ValueProviderContext extends AbstractPluginContext<ValueProviderContext> {

  private Map<String, Map<String, Object>> valueProviderConfig;

  /**
   * @return Configuration for value providers.
   *         The outer map uses the value provider plugin name as key, the inner map contain the config properties.
   *         Never null.
   */
  public Map<String, Map<String, Object>> getValueProviderConfig() {
    if (this.valueProviderConfig == null) {
      return Collections.emptyMap();
    }
    return this.valueProviderConfig;
  }

  /**
   * @param valueProviderPluginName Value provider plugin name
   * @return Configuration for the given value provider. Never null.
   */
  public Map<String, Object> getValueProviderConfig(String valueProviderPluginName) {
    Map<String, Object> config = getValueProviderConfig().get(valueProviderPluginName);
    if (config == null) {
      return Collections.emptyMap();
    }
    return config;
  }

  /**
   * @param value Configuration for value providers.
   *          The outer map uses the value provider plugin name as key, the inner map contain the config properties.
   * @return this
   */
  public ValueProviderContext valueProviderConfig(Map<String, Map<String, Object>> value) {
    this.valueProviderConfig = value;
    return this;
  }

}

@@ -703,16 +703,42 @@
 ctions;%0A
+import java.util.HashMap;%0A
 import j
@@ -996,16 +996,84 @@
 rConfig;
+%0A  private Map%3CString, Object%3E valueProviderCache = new HashMap%3C%3E();
 %0A%0A  /**%0A
@@ -2228,10 +2228,768 @@
 s;%0A  %7D%0A%0A
+  /**%0A   * Get cache object put by value provider plugin implementation.%0A   * @param valueProviderPluginName Value provider plugin name%0A   * @return Cache object or null if none was set yet%0A   * @param %3CT%3E Cache object type%0A   */%0A  @SuppressWarnings(%22unchecked%22)%0A  public %3CT%3E T getValueProviderCache(String valueProviderPluginName) %7B%0A    return (T)valueProviderCache.get(valueProviderPluginName);%0A  %7D%0A%0A  /**%0A   * Put cache object from value provider plugin implementation.%0A   * @param valueProviderPluginName Value provider plugin name%0A   * @param object Cache object%0A   * @param %3CT%3E Cache object type%0A   */%0A  public %3CT%3E void setValueProviderCache(String valueProviderPluginName, T object) %7B%0A    valueProviderCache.put(valueProviderPluginName, object);%0A  %7D%0A%0A
 %7D%0A

allow to store cache objects in value provider context