/** * Copyright (C) 2015 - present by OpenGamma Inc. and the OpenGamma group of companies * <p/> * Please see distribution for license. */ package com.opengamma.sesame.component; import java.util.LinkedHashMap; import java.util.Map; import org.joda.beans.Bean; 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.google.common.collect.ImmutableList; import com.opengamma.component.ComponentRepository; import com.opengamma.component.factory.AbstractComponentFactory; import com.opengamma.sesame.marketdata.CompositeMarketDataFactory; import com.opengamma.sesame.marketdata.HistoricalMarketDataFactory; import com.opengamma.sesame.marketdata.LiveMarketDataFactory; import com.opengamma.sesame.marketdata.MarketDataFactory; import com.opengamma.sesame.marketdata.SnapshotMarketDataFactory; /** * Component factory for building a market data factory that combines multiple data sources. */ @BeanDefinition public class CompositeMarketDataFactoryComponentFactory extends AbstractComponentFactory { /** The name under which the component is published. */ @PropertyDefinition(validate = "notNull") private String _classifier; /** Factory for live market data. */ @PropertyDefinition private LiveMarketDataFactory _liveMarketDataFactory; /** Factory for market data stored in a snapshot. */ @PropertyDefinition private SnapshotMarketDataFactory _snapshotMarketDataFactory; /** Factory for historical market data stored in time series. */ @PropertyDefinition private HistoricalMarketDataFactory _historicalMarketDataFactory; @Override public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) throws Exception { ImmutableList.Builder<MarketDataFactory<?>> factoryListBuilder = ImmutableList.builder(); if (_liveMarketDataFactory != null) { factoryListBuilder.add(_liveMarketDataFactory); } if (_snapshotMarketDataFactory != null) { factoryListBuilder.add(_snapshotMarketDataFactory); } if (_historicalMarketDataFactory != null) { factoryListBuilder.add(_historicalMarketDataFactory); } CompositeMarketDataFactory compositeFactory = new CompositeMarketDataFactory(factoryListBuilder.build()); repo.registerComponent(MarketDataFactory.class, _classifier, compositeFactory); } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code CompositeMarketDataFactoryComponentFactory}. * @return the meta-bean, not null */ public static CompositeMarketDataFactoryComponentFactory.Meta meta() { return CompositeMarketDataFactoryComponentFactory.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(CompositeMarketDataFactoryComponentFactory.Meta.INSTANCE); } @Override public CompositeMarketDataFactoryComponentFactory.Meta metaBean() { return CompositeMarketDataFactoryComponentFactory.Meta.INSTANCE; } //----------------------------------------------------------------------- /** * Gets the name under which the component is published. * @return the value of the property, not null */ public String getClassifier() { return _classifier; } /** * Sets the name under which the component is published. * @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 factory for live market data. * @return the value of the property */ public LiveMarketDataFactory getLiveMarketDataFactory() { return _liveMarketDataFactory; } /** * Sets factory for live market data. * @param liveMarketDataFactory the new value of the property */ public void setLiveMarketDataFactory(LiveMarketDataFactory liveMarketDataFactory) { this._liveMarketDataFactory = liveMarketDataFactory; } /** * Gets the the {@code liveMarketDataFactory} property. * @return the property, not null */ public final Property<LiveMarketDataFactory> liveMarketDataFactory() { return metaBean().liveMarketDataFactory().createProperty(this); } //----------------------------------------------------------------------- /** * Gets factory for market data stored in a snapshot. * @return the value of the property */ public SnapshotMarketDataFactory getSnapshotMarketDataFactory() { return _snapshotMarketDataFactory; } /** * Sets factory for market data stored in a snapshot. * @param snapshotMarketDataFactory the new value of the property */ public void setSnapshotMarketDataFactory(SnapshotMarketDataFactory snapshotMarketDataFactory) { this._snapshotMarketDataFactory = snapshotMarketDataFactory; } /** * Gets the the {@code snapshotMarketDataFactory} property. * @return the property, not null */ public final Property<SnapshotMarketDataFactory> snapshotMarketDataFactory() { return metaBean().snapshotMarketDataFactory().createProperty(this); } //----------------------------------------------------------------------- /** * Gets factory for historical market data stored in time series. * @return the value of the property */ public HistoricalMarketDataFactory getHistoricalMarketDataFactory() { return _historicalMarketDataFactory; } /** * Sets factory for historical market data stored in time series. * @param historicalMarketDataFactory the new value of the property */ public void setHistoricalMarketDataFactory(HistoricalMarketDataFactory historicalMarketDataFactory) { this._historicalMarketDataFactory = historicalMarketDataFactory; } /** * Gets the the {@code historicalMarketDataFactory} property. * @return the property, not null */ public final Property<HistoricalMarketDataFactory> historicalMarketDataFactory() { return metaBean().historicalMarketDataFactory().createProperty(this); } //----------------------------------------------------------------------- @Override public CompositeMarketDataFactoryComponentFactory clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { CompositeMarketDataFactoryComponentFactory other = (CompositeMarketDataFactoryComponentFactory) obj; return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) && JodaBeanUtils.equal(getLiveMarketDataFactory(), other.getLiveMarketDataFactory()) && JodaBeanUtils.equal(getSnapshotMarketDataFactory(), other.getSnapshotMarketDataFactory()) && JodaBeanUtils.equal(getHistoricalMarketDataFactory(), other.getHistoricalMarketDataFactory()) && super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; hash = hash * 31 + JodaBeanUtils.hashCode(getClassifier()); hash = hash * 31 + JodaBeanUtils.hashCode(getLiveMarketDataFactory()); hash = hash * 31 + JodaBeanUtils.hashCode(getSnapshotMarketDataFactory()); hash = hash * 31 + JodaBeanUtils.hashCode(getHistoricalMarketDataFactory()); return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(160); buf.append("CompositeMarketDataFactoryComponentFactory{"); int len = buf.length(); toString(buf); if (buf.length() > len) { buf.setLength(buf.length() - 2); } buf.append('}'); return buf.toString(); } @Override protected void toString(StringBuilder buf) { super.toString(buf); buf.append("classifier").append('=').append(JodaBeanUtils.toString(getClassifier())).append(',').append(' '); buf.append("liveMarketDataFactory").append('=').append(JodaBeanUtils.toString(getLiveMarketDataFactory())).append(',').append(' '); buf.append("snapshotMarketDataFactory").append('=').append(JodaBeanUtils.toString(getSnapshotMarketDataFactory())).append(',').append(' '); buf.append("historicalMarketDataFactory").append('=').append(JodaBeanUtils.toString(getHistoricalMarketDataFactory())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code CompositeMarketDataFactoryComponentFactory}. */ 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", CompositeMarketDataFactoryComponentFactory.class, String.class); /** * The meta-property for the {@code liveMarketDataFactory} property. */ private final MetaProperty<LiveMarketDataFactory> _liveMarketDataFactory = DirectMetaProperty.ofReadWrite( this, "liveMarketDataFactory", CompositeMarketDataFactoryComponentFactory.class, LiveMarketDataFactory.class); /** * The meta-property for the {@code snapshotMarketDataFactory} property. */ private final MetaProperty<SnapshotMarketDataFactory> _snapshotMarketDataFactory = DirectMetaProperty.ofReadWrite( this, "snapshotMarketDataFactory", CompositeMarketDataFactoryComponentFactory.class, SnapshotMarketDataFactory.class); /** * The meta-property for the {@code historicalMarketDataFactory} property. */ private final MetaProperty<HistoricalMarketDataFactory> _historicalMarketDataFactory = DirectMetaProperty.ofReadWrite( this, "historicalMarketDataFactory", CompositeMarketDataFactoryComponentFactory.class, HistoricalMarketDataFactory.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap(), "classifier", "liveMarketDataFactory", "snapshotMarketDataFactory", "historicalMarketDataFactory"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -281470431: // classifier return _classifier; case 855711896: // liveMarketDataFactory return _liveMarketDataFactory; case 706496192: // snapshotMarketDataFactory return _snapshotMarketDataFactory; case -789173126: // historicalMarketDataFactory return _historicalMarketDataFactory; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends CompositeMarketDataFactoryComponentFactory> builder() { return new DirectBeanBuilder<CompositeMarketDataFactoryComponentFactory>(new CompositeMarketDataFactoryComponentFactory()); } @Override public Class<? extends CompositeMarketDataFactoryComponentFactory> beanType() { return CompositeMarketDataFactoryComponentFactory.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 liveMarketDataFactory} property. * @return the meta-property, not null */ public final MetaProperty<LiveMarketDataFactory> liveMarketDataFactory() { return _liveMarketDataFactory; } /** * The meta-property for the {@code snapshotMarketDataFactory} property. * @return the meta-property, not null */ public final MetaProperty<SnapshotMarketDataFactory> snapshotMarketDataFactory() { return _snapshotMarketDataFactory; } /** * The meta-property for the {@code historicalMarketDataFactory} property. * @return the meta-property, not null */ public final MetaProperty<HistoricalMarketDataFactory> historicalMarketDataFactory() { return _historicalMarketDataFactory; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -281470431: // classifier return ((CompositeMarketDataFactoryComponentFactory) bean).getClassifier(); case 855711896: // liveMarketDataFactory return ((CompositeMarketDataFactoryComponentFactory) bean).getLiveMarketDataFactory(); case 706496192: // snapshotMarketDataFactory return ((CompositeMarketDataFactoryComponentFactory) bean).getSnapshotMarketDataFactory(); case -789173126: // historicalMarketDataFactory return ((CompositeMarketDataFactoryComponentFactory) bean).getHistoricalMarketDataFactory(); } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case -281470431: // classifier ((CompositeMarketDataFactoryComponentFactory) bean).setClassifier((String) newValue); return; case 855711896: // liveMarketDataFactory ((CompositeMarketDataFactoryComponentFactory) bean).setLiveMarketDataFactory((LiveMarketDataFactory) newValue); return; case 706496192: // snapshotMarketDataFactory ((CompositeMarketDataFactoryComponentFactory) bean).setSnapshotMarketDataFactory((SnapshotMarketDataFactory) newValue); return; case -789173126: // historicalMarketDataFactory ((CompositeMarketDataFactoryComponentFactory) bean).setHistoricalMarketDataFactory((HistoricalMarketDataFactory) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } @Override protected void validate(Bean bean) { JodaBeanUtils.notNull(((CompositeMarketDataFactoryComponentFactory) bean)._classifier, "classifier"); super.validate(bean); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }