/**
* Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.bbg.component;
import java.util.LinkedHashMap;
import java.util.Map;
import net.sf.ehcache.CacheManager;
import org.joda.beans.BeanBuilder;
import org.joda.beans.BeanDefinition;
import org.joda.beans.JodaBeanUtils;
import org.joda.beans.MetaProperty;
import org.joda.beans.Property;
import org.joda.beans.PropertyDefinition;
import org.joda.beans.impl.direct.DirectBeanBuilder;
import org.joda.beans.impl.direct.DirectMetaProperty;
import org.joda.beans.impl.direct.DirectMetaPropertyMap;
import com.opengamma.bbg.BloombergHistoricalTimeSeriesSource;
import com.opengamma.component.ComponentInfo;
import com.opengamma.component.ComponentRepository;
import com.opengamma.component.factory.AbstractComponentFactory;
import com.opengamma.core.historicaltimeseries.HistoricalTimeSeriesSource;
import com.opengamma.core.historicaltimeseries.impl.DataHistoricalTimeSeriesSourceResource;
import com.opengamma.core.historicaltimeseries.impl.EHCachingHistoricalTimeSeriesSource;
import com.opengamma.provider.historicaltimeseries.HistoricalTimeSeriesProvider;
/**
* Component factory for the Bloomberg time-series source.
* The source and this factory are now effectively deprecated by the provider
*/
@BeanDefinition
public class BloombergHistoricalTimeSeriesSourceComponentFactory extends AbstractComponentFactory {
/**
* The classifier that the factory should publish under.
*/
@PropertyDefinition(validate = "notNull")
private String _classifier;
/**
* The flag determining whether the component should be published by REST (default true).
*/
@PropertyDefinition
private boolean _publishRest = true;
/**
* The underlying time-series provider.
*/
@PropertyDefinition(validate = "notNull")
private HistoricalTimeSeriesProvider _historicalTimeSeriesProvider;
/**
* The optional cache manager.
* Caching will be added if this field is set.
*/
@PropertyDefinition
private CacheManager _cacheManager;
//-------------------------------------------------------------------------
@Override
public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) throws Exception {
HistoricalTimeSeriesSource source = initHistoricalTimeSeriesSource(repo);
ComponentInfo info = new ComponentInfo(BloombergHistoricalTimeSeriesSource.class, getClassifier());
repo.registerComponent(info, source);
if (isPublishRest()) {
repo.getRestComponents().publishResource(new DataHistoricalTimeSeriesSourceResource(source)); // publish in old way
}
}
protected HistoricalTimeSeriesSource initHistoricalTimeSeriesSource(ComponentRepository repo) {
HistoricalTimeSeriesSource source = new BloombergHistoricalTimeSeriesSource(getHistoricalTimeSeriesProvider());
if (getCacheManager() != null) {
source = new EHCachingHistoricalTimeSeriesSource(source, getCacheManager());
}
return source;
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code BloombergHistoricalTimeSeriesSourceComponentFactory}.
* @return the meta-bean, not null
*/
public static BloombergHistoricalTimeSeriesSourceComponentFactory.Meta meta() {
return BloombergHistoricalTimeSeriesSourceComponentFactory.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(BloombergHistoricalTimeSeriesSourceComponentFactory.Meta.INSTANCE);
}
@Override
public BloombergHistoricalTimeSeriesSourceComponentFactory.Meta metaBean() {
return BloombergHistoricalTimeSeriesSourceComponentFactory.Meta.INSTANCE;
}
@Override
protected Object propertyGet(String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return getClassifier();
case -614707837: // publishRest
return isPublishRest();
case -1592479713: // historicalTimeSeriesProvider
return getHistoricalTimeSeriesProvider();
case -1452875317: // cacheManager
return getCacheManager();
}
return super.propertyGet(propertyName, quiet);
}
@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
setClassifier((String) newValue);
return;
case -614707837: // publishRest
setPublishRest((Boolean) newValue);
return;
case -1592479713: // historicalTimeSeriesProvider
setHistoricalTimeSeriesProvider((HistoricalTimeSeriesProvider) newValue);
return;
case -1452875317: // cacheManager
setCacheManager((CacheManager) newValue);
return;
}
super.propertySet(propertyName, newValue, quiet);
}
@Override
protected void validate() {
JodaBeanUtils.notNull(_classifier, "classifier");
JodaBeanUtils.notNull(_historicalTimeSeriesProvider, "historicalTimeSeriesProvider");
super.validate();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
BloombergHistoricalTimeSeriesSourceComponentFactory other = (BloombergHistoricalTimeSeriesSourceComponentFactory) obj;
return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) &&
JodaBeanUtils.equal(isPublishRest(), other.isPublishRest()) &&
JodaBeanUtils.equal(getHistoricalTimeSeriesProvider(), other.getHistoricalTimeSeriesProvider()) &&
JodaBeanUtils.equal(getCacheManager(), other.getCacheManager()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash += hash * 31 + JodaBeanUtils.hashCode(getClassifier());
hash += hash * 31 + JodaBeanUtils.hashCode(isPublishRest());
hash += hash * 31 + JodaBeanUtils.hashCode(getHistoricalTimeSeriesProvider());
hash += hash * 31 + JodaBeanUtils.hashCode(getCacheManager());
return hash ^ super.hashCode();
}
//-----------------------------------------------------------------------
/**
* Gets the classifier that the factory should publish under.
* @return the value of the property, not null
*/
public String getClassifier() {
return _classifier;
}
/**
* Sets the classifier that the factory should publish under.
* @param classifier the new value of the property, not null
*/
public void setClassifier(String classifier) {
JodaBeanUtils.notNull(classifier, "classifier");
this._classifier = classifier;
}
/**
* Gets the the {@code classifier} property.
* @return the property, not null
*/
public final Property<String> classifier() {
return metaBean().classifier().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the flag determining whether the component should be published by REST (default true).
* @return the value of the property
*/
public boolean isPublishRest() {
return _publishRest;
}
/**
* Sets the flag determining whether the component should be published by REST (default true).
* @param publishRest the new value of the property
*/
public void setPublishRest(boolean publishRest) {
this._publishRest = publishRest;
}
/**
* Gets the the {@code publishRest} property.
* @return the property, not null
*/
public final Property<Boolean> publishRest() {
return metaBean().publishRest().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the underlying time-series provider.
* @return the value of the property, not null
*/
public HistoricalTimeSeriesProvider getHistoricalTimeSeriesProvider() {
return _historicalTimeSeriesProvider;
}
/**
* Sets the underlying time-series provider.
* @param historicalTimeSeriesProvider the new value of the property, not null
*/
public void setHistoricalTimeSeriesProvider(HistoricalTimeSeriesProvider historicalTimeSeriesProvider) {
JodaBeanUtils.notNull(historicalTimeSeriesProvider, "historicalTimeSeriesProvider");
this._historicalTimeSeriesProvider = historicalTimeSeriesProvider;
}
/**
* Gets the the {@code historicalTimeSeriesProvider} property.
* @return the property, not null
*/
public final Property<HistoricalTimeSeriesProvider> historicalTimeSeriesProvider() {
return metaBean().historicalTimeSeriesProvider().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the optional cache manager.
* Caching will be added if this field is set.
* @return the value of the property
*/
public CacheManager getCacheManager() {
return _cacheManager;
}
/**
* Sets the optional cache manager.
* Caching will be added if this field is set.
* @param cacheManager the new value of the property
*/
public void setCacheManager(CacheManager cacheManager) {
this._cacheManager = cacheManager;
}
/**
* Gets the the {@code cacheManager} property.
* Caching will be added if this field is set.
* @return the property, not null
*/
public final Property<CacheManager> cacheManager() {
return metaBean().cacheManager().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code BloombergHistoricalTimeSeriesSourceComponentFactory}.
*/
public static class Meta extends AbstractComponentFactory.Meta {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code classifier} property.
*/
private final MetaProperty<String> _classifier = DirectMetaProperty.ofReadWrite(
this, "classifier", BloombergHistoricalTimeSeriesSourceComponentFactory.class, String.class);
/**
* The meta-property for the {@code publishRest} property.
*/
private final MetaProperty<Boolean> _publishRest = DirectMetaProperty.ofReadWrite(
this, "publishRest", BloombergHistoricalTimeSeriesSourceComponentFactory.class, Boolean.TYPE);
/**
* The meta-property for the {@code historicalTimeSeriesProvider} property.
*/
private final MetaProperty<HistoricalTimeSeriesProvider> _historicalTimeSeriesProvider = DirectMetaProperty.ofReadWrite(
this, "historicalTimeSeriesProvider", BloombergHistoricalTimeSeriesSourceComponentFactory.class, HistoricalTimeSeriesProvider.class);
/**
* The meta-property for the {@code cacheManager} property.
*/
private final MetaProperty<CacheManager> _cacheManager = DirectMetaProperty.ofReadWrite(
this, "cacheManager", BloombergHistoricalTimeSeriesSourceComponentFactory.class, CacheManager.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"classifier",
"publishRest",
"historicalTimeSeriesProvider",
"cacheManager");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return _classifier;
case -614707837: // publishRest
return _publishRest;
case -1592479713: // historicalTimeSeriesProvider
return _historicalTimeSeriesProvider;
case -1452875317: // cacheManager
return _cacheManager;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends BloombergHistoricalTimeSeriesSourceComponentFactory> builder() {
return new DirectBeanBuilder<BloombergHistoricalTimeSeriesSourceComponentFactory>(new BloombergHistoricalTimeSeriesSourceComponentFactory());
}
@Override
public Class<? extends BloombergHistoricalTimeSeriesSourceComponentFactory> beanType() {
return BloombergHistoricalTimeSeriesSourceComponentFactory.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code classifier} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> classifier() {
return _classifier;
}
/**
* The meta-property for the {@code publishRest} property.
* @return the meta-property, not null
*/
public final MetaProperty<Boolean> publishRest() {
return _publishRest;
}
/**
* The meta-property for the {@code historicalTimeSeriesProvider} property.
* @return the meta-property, not null
*/
public final MetaProperty<HistoricalTimeSeriesProvider> historicalTimeSeriesProvider() {
return _historicalTimeSeriesProvider;
}
/**
* The meta-property for the {@code cacheManager} property.
* @return the meta-property, not null
*/
public final MetaProperty<CacheManager> cacheManager() {
return _cacheManager;
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}