/**
 * Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
 *
 * Please see distribution for license.
 */
package com.opengamma.web.bundle;

import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import com.opengamma.util.ArgumentChecker;

/**
 * Manages the CSS/Javascript bundles.
 * <p>
 * This acts as the root of the tree.
 */
public class BundleManager {

  /**
   * The map of bundles by ID.
   */
  private Map<String, Bundle> _bundleMap = new ConcurrentHashMap<String, Bundle>();

  /**
   * Creates an instance.
   */
  public BundleManager() {
  }

  //-------------------------------------------------------------------------
  /**
   * Looks up a bundle by ID.
   * 
   * @param id  the ID to look up, not null
   * @return the bundle, null if not found
   */
  public Bundle getBundle(String id) {
    return _bundleMap.get(id);
  }

  /**
   * Adds a bundle to the manager.
   * 
   * @param bundle  the bundle to add, not null
   */
  public void addBundle(Bundle bundle) {
    ArgumentChecker.notNull(bundle, "bundle");
    ArgumentChecker.notNull(bundle.getId(), "bundle.id");
    
    // recursively add children as well
    for (Bundle loop : bundle.getAllBundles()) {
      _bundleMap.put(loop.getId(), loop);
    }
  }

  /**
   * Gets the set of all bundle IDs.
   * 
   * @return the unmodifiable bundle ID set, not null
   */
  public Set<String> getBundleIds() {
    return Collections.unmodifiableSet(_bundleMap.keySet());
  }

}

@@ -218,16 +218,44 @@
 il.Map;%0A
+import java.util.Map.Entry;%0A
 import j
@@ -316,16 +316,127 @@
 shMap;%0A%0A
+import org.apache.commons.lang.builder.ToStringBuilder;%0Aimport org.apache.commons.lang.builder.ToStringStyle;%0A%0A
 import c
@@ -1686,10 +1686,400 @@
 );%0A  %7D%0A%0A
+  @Override%0A  public String toString() %7B%0A    ToStringBuilder builder = new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE);%0A    for (Entry%3CString, Bundle%3E entry : _bundleMap.entrySet()) %7B%0A      builder.append(entry.getKey(), entry.getValue().toString());%0A    %7D%0A    return builder.toString();%0A//    return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);%0A  %7D%0A%0A
 %7D%0A

Add toString to BundleManager for debug purpose