/**
* Copyright (C) 2013 - 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.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.component.factory.ComponentInfoAttributes;
import com.opengamma.core.security.SecuritySource;
import com.opengamma.core.security.impl.DataSecuritySourceResource;
import com.opengamma.core.security.impl.NonVersionedRedisSecuritySource;
import com.opengamma.core.security.impl.RemoteSecuritySource;
import com.opengamma.util.redis.RedisConnector;
/**
* Component factory providing {@link NonVersionedRedisSecuritySource}.
*/
@BeanDefinition
public class NonVersionedRedisSecuritySourceComponentFactory extends AbstractComponentFactory {
/**
* The classifier that the factory should publish under.
*/
@PropertyDefinition(validate = "notNull")
private String _classifier;
/**
* Connector to the underlying Redis instance to use.
*/
@PropertyDefinition(validate = "notNull")
private RedisConnector _redisConnector;
/**
* If set (optional) prefixes all Redis keys with the specified value.
*/
@PropertyDefinition(validate = "notNull")
private String _redisPrefix = "";
/**
* The flag determining whether the component should be published by REST (default true).
*/
@PropertyDefinition
private boolean _publishRest = true;
@Override
public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) throws Exception {
NonVersionedRedisSecuritySource source = new NonVersionedRedisSecuritySource(getRedisConnector().getJedisPool(), getRedisPrefix());
ComponentInfo sourceInfo = new ComponentInfo(SecuritySource.class, getClassifier());
sourceInfo.addAttribute(ComponentInfoAttributes.LEVEL, 1);
sourceInfo.addAttribute(ComponentInfoAttributes.REMOTE_CLIENT_JAVA, RemoteSecuritySource.class);
repo.registerComponent(sourceInfo, source);
ComponentInfo redisInfo = new ComponentInfo(NonVersionedRedisSecuritySource.class, getClassifier());
redisInfo.addAttribute(ComponentInfoAttributes.LEVEL, 1);
repo.registerComponent(redisInfo, source);
if (isPublishRest()) {
repo.getRestComponents().publish(sourceInfo, new DataSecuritySourceResource(source));
}
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code NonVersionedRedisSecuritySourceComponentFactory}.
* @return the meta-bean, not null
*/
public static NonVersionedRedisSecuritySourceComponentFactory.Meta meta() {
return NonVersionedRedisSecuritySourceComponentFactory.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(NonVersionedRedisSecuritySourceComponentFactory.Meta.INSTANCE);
}
@Override
public NonVersionedRedisSecuritySourceComponentFactory.Meta metaBean() {
return NonVersionedRedisSecuritySourceComponentFactory.Meta.INSTANCE;
}
@Override
protected Object propertyGet(String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return getClassifier();
case -745461486: // redisConnector
return getRedisConnector();
case -2024915987: // redisPrefix
return getRedisPrefix();
case -614707837: // publishRest
return isPublishRest();
}
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 -745461486: // redisConnector
setRedisConnector((RedisConnector) newValue);
return;
case -2024915987: // redisPrefix
setRedisPrefix((String) newValue);
return;
case -614707837: // publishRest
setPublishRest((Boolean) newValue);
return;
}
super.propertySet(propertyName, newValue, quiet);
}
@Override
protected void validate() {
JodaBeanUtils.notNull(_classifier, "classifier");
JodaBeanUtils.notNull(_redisConnector, "redisConnector");
JodaBeanUtils.notNull(_redisPrefix, "redisPrefix");
super.validate();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
NonVersionedRedisSecuritySourceComponentFactory other = (NonVersionedRedisSecuritySourceComponentFactory) obj;
return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) &&
JodaBeanUtils.equal(getRedisConnector(), other.getRedisConnector()) &&
JodaBeanUtils.equal(getRedisPrefix(), other.getRedisPrefix()) &&
JodaBeanUtils.equal(isPublishRest(), other.isPublishRest()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash += hash * 31 + JodaBeanUtils.hashCode(getClassifier());
hash += hash * 31 + JodaBeanUtils.hashCode(getRedisConnector());
hash += hash * 31 + JodaBeanUtils.hashCode(getRedisPrefix());
hash += hash * 31 + JodaBeanUtils.hashCode(isPublishRest());
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 connector to the underlying Redis instance to use.
* @return the value of the property, not null
*/
public RedisConnector getRedisConnector() {
return _redisConnector;
}
/**
* Sets connector to the underlying Redis instance to use.
* @param redisConnector the new value of the property, not null
*/
public void setRedisConnector(RedisConnector redisConnector) {
JodaBeanUtils.notNull(redisConnector, "redisConnector");
this._redisConnector = redisConnector;
}
/**
* Gets the the {@code redisConnector} property.
* @return the property, not null
*/
public final Property<RedisConnector> redisConnector() {
return metaBean().redisConnector().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets if set (optional) prefixes all Redis keys with the specified value.
* @return the value of the property, not null
*/
public String getRedisPrefix() {
return _redisPrefix;
}
/**
* Sets if set (optional) prefixes all Redis keys with the specified value.
* @param redisPrefix the new value of the property, not null
*/
public void setRedisPrefix(String redisPrefix) {
JodaBeanUtils.notNull(redisPrefix, "redisPrefix");
this._redisPrefix = redisPrefix;
}
/**
* Gets the the {@code redisPrefix} property.
* @return the property, not null
*/
public final Property<String> redisPrefix() {
return metaBean().redisPrefix().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);
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code NonVersionedRedisSecuritySourceComponentFactory}.
*/
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", NonVersionedRedisSecuritySourceComponentFactory.class, String.class);
/**
* The meta-property for the {@code redisConnector} property.
*/
private final MetaProperty<RedisConnector> _redisConnector = DirectMetaProperty.ofReadWrite(
this, "redisConnector", NonVersionedRedisSecuritySourceComponentFactory.class, RedisConnector.class);
/**
* The meta-property for the {@code redisPrefix} property.
*/
private final MetaProperty<String> _redisPrefix = DirectMetaProperty.ofReadWrite(
this, "redisPrefix", NonVersionedRedisSecuritySourceComponentFactory.class, String.class);
/**
* The meta-property for the {@code publishRest} property.
*/
private final MetaProperty<Boolean> _publishRest = DirectMetaProperty.ofReadWrite(
this, "publishRest", NonVersionedRedisSecuritySourceComponentFactory.class, Boolean.TYPE);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"classifier",
"redisConnector",
"redisPrefix",
"publishRest");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return _classifier;
case -745461486: // redisConnector
return _redisConnector;
case -2024915987: // redisPrefix
return _redisPrefix;
case -614707837: // publishRest
return _publishRest;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends NonVersionedRedisSecuritySourceComponentFactory> builder() {
return new DirectBeanBuilder<NonVersionedRedisSecuritySourceComponentFactory>(new NonVersionedRedisSecuritySourceComponentFactory());
}
@Override
public Class<? extends NonVersionedRedisSecuritySourceComponentFactory> beanType() {
return NonVersionedRedisSecuritySourceComponentFactory.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 redisConnector} property.
* @return the meta-property, not null
*/
public final MetaProperty<RedisConnector> redisConnector() {
return _redisConnector;
}
/**
* The meta-property for the {@code redisPrefix} property.
* @return the meta-property, not null
*/
public final MetaProperty<String> redisPrefix() {
return _redisPrefix;
}
/**
* The meta-property for the {@code publishRest} property.
* @return the meta-property, not null
*/
public final MetaProperty<Boolean> publishRest() {
return _publishRest;
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}