/**
* Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.financial.spring;
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.core.position.PositionSource;
import com.opengamma.core.position.impl.EHCachingPositionSource;
import com.opengamma.master.portfolio.PortfolioMaster;
import com.opengamma.master.position.PositionMaster;
import com.opengamma.master.position.impl.MasterPositionSource;
import com.opengamma.util.spring.SpringFactoryBean;
/**
* Spring factory bean to create the position source.
*/
@BeanDefinition
public class PositionSourceFactoryBean extends SpringFactoryBean<PositionSource> {
/**
* The portfolio master.
*/
@PropertyDefinition
private PortfolioMaster _portfolioMaster;
/**
* The position master.
*/
@PropertyDefinition
private PositionMaster _positionMaster;
/**
* The cache manager.
*/
@PropertyDefinition
private CacheManager _cacheManager;
/**
* Creates an instance.
*/
public PositionSourceFactoryBean() {
super(PositionSource.class);
}
//-------------------------------------------------------------------------
@Override
protected PositionSource createObject() {
PositionSource source = new MasterPositionSource(getPortfolioMaster(), getPositionMaster());
if (getCacheManager() != null) {
source = new EHCachingPositionSource(source, getCacheManager());
}
return source;
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code PositionSourceFactoryBean}.
* @return the meta-bean, not null
*/
public static PositionSourceFactoryBean.Meta meta() {
return PositionSourceFactoryBean.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(PositionSourceFactoryBean.Meta.INSTANCE);
}
@Override
public PositionSourceFactoryBean.Meta metaBean() {
return PositionSourceFactoryBean.Meta.INSTANCE;
}
@Override
protected Object propertyGet(String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -772274742: // portfolioMaster
return getPortfolioMaster();
case -1840419605: // positionMaster
return getPositionMaster();
case -1452875317: // cacheManager
return getCacheManager();
}
return super.propertyGet(propertyName, quiet);
}
@Override
protected void propertySet(String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -772274742: // portfolioMaster
setPortfolioMaster((PortfolioMaster) newValue);
return;
case -1840419605: // positionMaster
setPositionMaster((PositionMaster) newValue);
return;
case -1452875317: // cacheManager
setCacheManager((CacheManager) newValue);
return;
}
super.propertySet(propertyName, newValue, quiet);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
PositionSourceFactoryBean other = (PositionSourceFactoryBean) obj;
return JodaBeanUtils.equal(getPortfolioMaster(), other.getPortfolioMaster()) &&
JodaBeanUtils.equal(getPositionMaster(), other.getPositionMaster()) &&
JodaBeanUtils.equal(getCacheManager(), other.getCacheManager()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash += hash * 31 + JodaBeanUtils.hashCode(getPortfolioMaster());
hash += hash * 31 + JodaBeanUtils.hashCode(getPositionMaster());
hash += hash * 31 + JodaBeanUtils.hashCode(getCacheManager());
return hash ^ super.hashCode();
}
//-----------------------------------------------------------------------
/**
* Gets the portfolio master.
* @return the value of the property
*/
public PortfolioMaster getPortfolioMaster() {
return _portfolioMaster;
}
/**
* Sets the portfolio master.
* @param portfolioMaster the new value of the property
*/
public void setPortfolioMaster(PortfolioMaster portfolioMaster) {
this._portfolioMaster = portfolioMaster;
}
/**
* Gets the the {@code portfolioMaster} property.
* @return the property, not null
*/
public final Property<PortfolioMaster> portfolioMaster() {
return metaBean().portfolioMaster().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the position master.
* @return the value of the property
*/
public PositionMaster getPositionMaster() {
return _positionMaster;
}
/**
* Sets the position master.
* @param positionMaster the new value of the property
*/
public void setPositionMaster(PositionMaster positionMaster) {
this._positionMaster = positionMaster;
}
/**
* Gets the the {@code positionMaster} property.
* @return the property, not null
*/
public final Property<PositionMaster> positionMaster() {
return metaBean().positionMaster().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the cache manager.
* @return the value of the property
*/
public CacheManager getCacheManager() {
return _cacheManager;
}
/**
* Sets the cache manager.
* @param cacheManager the new value of the property
*/
public void setCacheManager(CacheManager cacheManager) {
this._cacheManager = cacheManager;
}
/**
* Gets the the {@code cacheManager} property.
* @return the property, not null
*/
public final Property<CacheManager> cacheManager() {
return metaBean().cacheManager().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code PositionSourceFactoryBean}.
*/
public static class Meta extends SpringFactoryBean.Meta<PositionSource> {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code portfolioMaster} property.
*/
private final MetaProperty<PortfolioMaster> _portfolioMaster = DirectMetaProperty.ofReadWrite(
this, "portfolioMaster", PositionSourceFactoryBean.class, PortfolioMaster.class);
/**
* The meta-property for the {@code positionMaster} property.
*/
private final MetaProperty<PositionMaster> _positionMaster = DirectMetaProperty.ofReadWrite(
this, "positionMaster", PositionSourceFactoryBean.class, PositionMaster.class);
/**
* The meta-property for the {@code cacheManager} property.
*/
private final MetaProperty<CacheManager> _cacheManager = DirectMetaProperty.ofReadWrite(
this, "cacheManager", PositionSourceFactoryBean.class, CacheManager.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"portfolioMaster",
"positionMaster",
"cacheManager");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -772274742: // portfolioMaster
return _portfolioMaster;
case -1840419605: // positionMaster
return _positionMaster;
case -1452875317: // cacheManager
return _cacheManager;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends PositionSourceFactoryBean> builder() {
return new DirectBeanBuilder<PositionSourceFactoryBean>(new PositionSourceFactoryBean());
}
@Override
public Class<? extends PositionSourceFactoryBean> beanType() {
return PositionSourceFactoryBean.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code portfolioMaster} property.
* @return the meta-property, not null
*/
public final MetaProperty<PortfolioMaster> portfolioMaster() {
return _portfolioMaster;
}
/**
* The meta-property for the {@code positionMaster} property.
* @return the meta-property, not null
*/
public final MetaProperty<PositionMaster> positionMaster() {
return _positionMaster;
}
/**
* 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 --------------------------
}