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