/**
* Copyright (C) 2012 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.component.factory.source;
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.opengamma.component.ComponentInfo;
import com.opengamma.component.ComponentRepository;
import com.opengamma.component.factory.AbstractComponentFactory;
import com.opengamma.core.config.ConfigSource;
import com.opengamma.financial.analytics.ircurve.calcconfig.ConfigDBCurveCalculationConfigSource;
import com.opengamma.financial.analytics.ircurve.calcconfig.CurveCalculationConfigSource;
import com.opengamma.id.VersionCorrection;
/**
* Component factory providing the {@code CurveCalculationConfigSource}.
* <p>
* This is a minimal class that does not contain any caching or REST capabilities.
*/
@BeanDefinition
public class CurveCalculationConfigSourceComponentFactory extends AbstractComponentFactory {
/**
* The classifier that the factory should publish under.
*/
@PropertyDefinition(validate = "notNull")
private String _classifier;
/**
* The config source to wrap.
*/
@PropertyDefinition(validate = "notNull")
private ConfigSource _configSource;
//-------------------------------------------------------------------------
/**
* Initializes the curve calculation config source, setting up component information and REST. Override using {@link #createCurveCalculationConfigSource(ComponentRepository)}.
*
* @param repo the component repository, not null
* @param configuration the remaining configuration, not null
*/
@Override
public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) {
CurveCalculationConfigSource source = createCurveCalculationConfigSource(repo);
ComponentInfo info = new ComponentInfo(CurveCalculationConfigSource.class, getClassifier());
repo.registerComponent(info, source);
}
/**
* Creates the curve calculation config source without registering it.
*
* @param repo the component repository, only used to register secondary items like lifecycle, not null
* @return the curve calculation config source, not null
*/
protected ConfigDBCurveCalculationConfigSource createCurveCalculationConfigSource(ComponentRepository repo) {
return new ConfigDBCurveCalculationConfigSource(getConfigSource(), VersionCorrection.LATEST);
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code CurveCalculationConfigSourceComponentFactory}.
* @return the meta-bean, not null
*/
public static CurveCalculationConfigSourceComponentFactory.Meta meta() {
return CurveCalculationConfigSourceComponentFactory.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(CurveCalculationConfigSourceComponentFactory.Meta.INSTANCE);
}
@Override
public CurveCalculationConfigSourceComponentFactory.Meta metaBean() {
return CurveCalculationConfigSourceComponentFactory.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* 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 config source to wrap.
* @return the value of the property, not null
*/
public ConfigSource getConfigSource() {
return _configSource;
}
/**
* Sets the config source to wrap.
* @param configSource the new value of the property, not null
*/
public void setConfigSource(ConfigSource configSource) {
JodaBeanUtils.notNull(configSource, "configSource");
this._configSource = configSource;
}
/**
* Gets the the {@code configSource} property.
* @return the property, not null
*/
public final Property<ConfigSource> configSource() {
return metaBean().configSource().createProperty(this);
}
//-----------------------------------------------------------------------
@Override
public CurveCalculationConfigSourceComponentFactory clone() {
return JodaBeanUtils.cloneAlways(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
CurveCalculationConfigSourceComponentFactory other = (CurveCalculationConfigSourceComponentFactory) obj;
return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) &&
JodaBeanUtils.equal(getConfigSource(), other.getConfigSource()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash = hash * 31 + JodaBeanUtils.hashCode(getClassifier());
hash = hash * 31 + JodaBeanUtils.hashCode(getConfigSource());
return hash ^ super.hashCode();
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("CurveCalculationConfigSourceComponentFactory{");
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("configSource").append('=').append(JodaBeanUtils.toString(getConfigSource())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code CurveCalculationConfigSourceComponentFactory}.
*/
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", CurveCalculationConfigSourceComponentFactory.class, String.class);
/**
* The meta-property for the {@code configSource} property.
*/
private final MetaProperty<ConfigSource> _configSource = DirectMetaProperty.ofReadWrite(
this, "configSource", CurveCalculationConfigSourceComponentFactory.class, ConfigSource.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"classifier",
"configSource");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return _classifier;
case 195157501: // configSource
return _configSource;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends CurveCalculationConfigSourceComponentFactory> builder() {
return new DirectBeanBuilder<CurveCalculationConfigSourceComponentFactory>(new CurveCalculationConfigSourceComponentFactory());
}
@Override
public Class<? extends CurveCalculationConfigSourceComponentFactory> beanType() {
return CurveCalculationConfigSourceComponentFactory.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 configSource} property.
* @return the meta-property, not null
*/
public final MetaProperty<ConfigSource> configSource() {
return _configSource;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return ((CurveCalculationConfigSourceComponentFactory) bean).getClassifier();
case 195157501: // configSource
return ((CurveCalculationConfigSourceComponentFactory) bean).getConfigSource();
}
return super.propertyGet(bean, propertyName, quiet);
}
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
((CurveCalculationConfigSourceComponentFactory) bean).setClassifier((String) newValue);
return;
case 195157501: // configSource
((CurveCalculationConfigSourceComponentFactory) bean).setConfigSource((ConfigSource) newValue);
return;
}
super.propertySet(bean, propertyName, newValue, quiet);
}
@Override
protected void validate(Bean bean) {
JodaBeanUtils.notNull(((CurveCalculationConfigSourceComponentFactory) bean)._classifier, "classifier");
JodaBeanUtils.notNull(((CurveCalculationConfigSourceComponentFactory) bean)._configSource, "configSource");
super.validate(bean);
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}