Package com.opengamma.web.analytics.blotter

Source Code of com.opengamma.web.analytics.blotter.MapMetaBeanFactory

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

import java.util.Map;
import java.util.Set;

import org.joda.beans.MetaBean;

import com.google.common.collect.Maps;
import com.opengamma.OpenGammaRuntimeException;
import com.opengamma.util.ArgumentChecker;

/**
* {@link MetaBeanFactory} where the {@link MetaBean} instances are keyed on the
* {@link BeanDataSource#getBeanTypeName() type name} of the bean.
*/
/* package */ class MapMetaBeanFactory implements MetaBeanFactory {

  private final Map<String, MetaBean> _metaBeans = Maps.newHashMap();

  /* package */ MapMetaBeanFactory(Set<MetaBean> metaBeans) {
    ArgumentChecker.notNull(metaBeans, "metaBeans");
    for (MetaBean metaBean : metaBeans) {
      _metaBeans.put(metaBean.beanType().getSimpleName(), metaBean);
    }
  }

  /**
   * @param beanData The bean data
   * @return The {@link MetaBean} keyed on the bean data's {@link BeanDataSource#getBeanTypeName() type name}, not null
   * @throws OpenGammaRuntimeException If there's no {@link MetaBean} keyed on the type name of the data source
   */
  @Override
  public MetaBean beanFor(BeanDataSource beanData) {
    MetaBean metaBean = _metaBeans.get(beanData.getBeanTypeName());
    if (metaBean == null) {
      throw new OpenGammaRuntimeException("No meta bean for type " + beanData.getBeanTypeName());
    }
    return metaBean;
  }
}
TOP

Related Classes of com.opengamma.web.analytics.blotter.MapMetaBeanFactory

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.