/** * 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.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.financial.security.EHCachingFinancialSecuritySource; import com.opengamma.financial.security.FinancialSecuritySource; import com.opengamma.financial.security.MasterFinancialSecuritySource; import com.opengamma.master.security.SecurityMaster; import com.opengamma.util.spring.SpringFactoryBean; /** * Spring factory bean to create the security source. */ @BeanDefinition public class FinancialSecuritySourceFactoryBean extends SpringFactoryBean<FinancialSecuritySource> { /** * The security master. */ @PropertyDefinition private SecurityMaster _securityMaster; /** * The cache manager. */ @PropertyDefinition private CacheManager _cacheManager; /** * Creates an instance. */ public FinancialSecuritySourceFactoryBean() { super(FinancialSecuritySource.class); } //------------------------------------------------------------------------- @Override protected FinancialSecuritySource createObject() { FinancialSecuritySource source = new MasterFinancialSecuritySource(getSecurityMaster()); if (getCacheManager() != null) { source = new EHCachingFinancialSecuritySource(source, getCacheManager()); } return source; } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code FinancialSecuritySourceFactoryBean}. * @return the meta-bean, not null */ public static FinancialSecuritySourceFactoryBean.Meta meta() { return FinancialSecuritySourceFactoryBean.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(FinancialSecuritySourceFactoryBean.Meta.INSTANCE); } @Override public FinancialSecuritySourceFactoryBean.Meta metaBean() { return FinancialSecuritySourceFactoryBean.Meta.INSTANCE; } //----------------------------------------------------------------------- /** * Gets the security master. * @return the value of the property */ public SecurityMaster getSecurityMaster() { return _securityMaster; } /** * Sets the security master. * @param securityMaster the new value of the property */ public void setSecurityMaster(SecurityMaster securityMaster) { this._securityMaster = securityMaster; } /** * Gets the the {@code securityMaster} property. * @return the property, not null */ public final Property<SecurityMaster> securityMaster() { return metaBean().securityMaster().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); } //----------------------------------------------------------------------- @Override public FinancialSecuritySourceFactoryBean clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { FinancialSecuritySourceFactoryBean other = (FinancialSecuritySourceFactoryBean) obj; return JodaBeanUtils.equal(getSecurityMaster(), other.getSecurityMaster()) && JodaBeanUtils.equal(getCacheManager(), other.getCacheManager()) && super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; hash = hash * 31 + JodaBeanUtils.hashCode(getSecurityMaster()); hash = hash * 31 + JodaBeanUtils.hashCode(getCacheManager()); return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(96); buf.append("FinancialSecuritySourceFactoryBean{"); 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("securityMaster").append('=').append(JodaBeanUtils.toString(getSecurityMaster())).append(',').append(' '); buf.append("cacheManager").append('=').append(JodaBeanUtils.toString(getCacheManager())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code FinancialSecuritySourceFactoryBean}. */ public static class Meta extends SpringFactoryBean.Meta<FinancialSecuritySource> { /** * The singleton instance of the meta-bean. */ static final Meta INSTANCE = new Meta(); /** * The meta-property for the {@code securityMaster} property. */ private final MetaProperty<SecurityMaster> _securityMaster = DirectMetaProperty.ofReadWrite( this, "securityMaster", FinancialSecuritySourceFactoryBean.class, SecurityMaster.class); /** * The meta-property for the {@code cacheManager} property. */ private final MetaProperty<CacheManager> _cacheManager = DirectMetaProperty.ofReadWrite( this, "cacheManager", FinancialSecuritySourceFactoryBean.class, CacheManager.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap(), "securityMaster", "cacheManager"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -887218750: // securityMaster return _securityMaster; case -1452875317: // cacheManager return _cacheManager; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends FinancialSecuritySourceFactoryBean> builder() { return new DirectBeanBuilder<FinancialSecuritySourceFactoryBean>(new FinancialSecuritySourceFactoryBean()); } @Override public Class<? extends FinancialSecuritySourceFactoryBean> beanType() { return FinancialSecuritySourceFactoryBean.class; } @Override public Map<String, MetaProperty<?>> metaPropertyMap() { return _metaPropertyMap$; } //----------------------------------------------------------------------- /** * The meta-property for the {@code securityMaster} property. * @return the meta-property, not null */ public final MetaProperty<SecurityMaster> securityMaster() { return _securityMaster; } /** * The meta-property for the {@code cacheManager} property. * @return the meta-property, not null */ public final MetaProperty<CacheManager> cacheManager() { return _cacheManager; } //----------------------------------------------------------------------- @Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -887218750: // securityMaster return ((FinancialSecuritySourceFactoryBean) bean).getSecurityMaster(); case -1452875317: // cacheManager return ((FinancialSecuritySourceFactoryBean) bean).getCacheManager(); } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case -887218750: // securityMaster ((FinancialSecuritySourceFactoryBean) bean).setSecurityMaster((SecurityMaster) newValue); return; case -1452875317: // cacheManager ((FinancialSecuritySourceFactoryBean) bean).setCacheManager((CacheManager) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }