/** * 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 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.component.ComponentInfo; import com.opengamma.component.ComponentRepository; import com.opengamma.component.factory.AbstractComponentFactory; import com.opengamma.component.factory.ComponentInfoAttributes; import com.opengamma.core.legalentity.LegalEntitySource; import com.opengamma.core.legalentity.impl.DataLegalEntitySourceResource; import com.opengamma.core.legalentity.impl.EHCachingLegalEntitySource; import com.opengamma.core.legalentity.impl.RemoteLegalEntitySource; import com.opengamma.master.legalentity.LegalEntityMaster; import com.opengamma.master.legalentity.impl.MasterLegalEntitySource; /** * Component factory providing the {@link LegalEntitySource}. */ @BeanDefinition public class LegalEntitySourceComponentFactory extends AbstractComponentFactory { /** * The classifier that the factory should publish under. */ @PropertyDefinition(validate = "notNull") private String _classifier; /** * The flag determining whether the component should be published by REST (default true). */ @PropertyDefinition private boolean _publishRest = true; /** * The underlying convention master. */ @PropertyDefinition(validate = "notNull") private LegalEntityMaster _legalEntityMaster; /** * The cache manager. */ @PropertyDefinition private CacheManager _cacheManager; //------------------------------------------------------------------------- /** * Initializes the convention source, setting up component information and REST. * Override using {@link #createLegalEntitySource(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) { LegalEntitySource source = createLegalEntitySource(repo); ComponentInfo info = new ComponentInfo(LegalEntitySource.class, getClassifier()); info.addAttribute(ComponentInfoAttributes.LEVEL, 1); info.addAttribute(ComponentInfoAttributes.REMOTE_CLIENT_JAVA, RemoteLegalEntitySource.class); repo.registerComponent(info, source); if (isPublishRest()) { repo.getRestComponents().publish(info, new DataLegalEntitySourceResource(source)); } } /** * Creates the convention source without registering it. * * @param repo the component repository, only used to register secondary items like lifecycle, not null * @return the convention source, not null */ protected LegalEntitySource createLegalEntitySource(final ComponentRepository repo) { LegalEntitySource source = new MasterLegalEntitySource(getLegalEntityMaster()); if (getCacheManager() != null) { source = new EHCachingLegalEntitySource(source, getCacheManager()); } return source; } //------------------------- AUTOGENERATED START ------------------------- ///CLOVER:OFF /** * The meta-bean for {@code LegalEntitySourceComponentFactory}. * @return the meta-bean, not null */ public static LegalEntitySourceComponentFactory.Meta meta() { return LegalEntitySourceComponentFactory.Meta.INSTANCE; } static { JodaBeanUtils.registerMetaBean(LegalEntitySourceComponentFactory.Meta.INSTANCE); } @Override public LegalEntitySourceComponentFactory.Meta metaBean() { return LegalEntitySourceComponentFactory.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 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); } //----------------------------------------------------------------------- /** * Gets the underlying convention master. * @return the value of the property, not null */ public LegalEntityMaster getLegalEntityMaster() { return _legalEntityMaster; } /** * Sets the underlying convention master. * @param legalEntityMaster the new value of the property, not null */ public void setLegalEntityMaster(LegalEntityMaster legalEntityMaster) { JodaBeanUtils.notNull(legalEntityMaster, "legalEntityMaster"); this._legalEntityMaster = legalEntityMaster; } /** * Gets the the {@code legalEntityMaster} property. * @return the property, not null */ public final Property<LegalEntityMaster> legalEntityMaster() { return metaBean().legalEntityMaster().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 LegalEntitySourceComponentFactory clone() { return JodaBeanUtils.cloneAlways(this); } @Override public boolean equals(Object obj) { if (obj == this) { return true; } if (obj != null && obj.getClass() == this.getClass()) { LegalEntitySourceComponentFactory other = (LegalEntitySourceComponentFactory) obj; return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) && (isPublishRest() == other.isPublishRest()) && JodaBeanUtils.equal(getLegalEntityMaster(), other.getLegalEntityMaster()) && JodaBeanUtils.equal(getCacheManager(), other.getCacheManager()) && super.equals(obj); } return false; } @Override public int hashCode() { int hash = 7; hash = hash * 31 + JodaBeanUtils.hashCode(getClassifier()); hash = hash * 31 + JodaBeanUtils.hashCode(isPublishRest()); hash = hash * 31 + JodaBeanUtils.hashCode(getLegalEntityMaster()); hash = hash * 31 + JodaBeanUtils.hashCode(getCacheManager()); return hash ^ super.hashCode(); } @Override public String toString() { StringBuilder buf = new StringBuilder(160); buf.append("LegalEntitySourceComponentFactory{"); 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("publishRest").append('=').append(JodaBeanUtils.toString(isPublishRest())).append(',').append(' '); buf.append("legalEntityMaster").append('=').append(JodaBeanUtils.toString(getLegalEntityMaster())).append(',').append(' '); buf.append("cacheManager").append('=').append(JodaBeanUtils.toString(getCacheManager())).append(',').append(' '); } //----------------------------------------------------------------------- /** * The meta-bean for {@code LegalEntitySourceComponentFactory}. */ 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", LegalEntitySourceComponentFactory.class, String.class); /** * The meta-property for the {@code publishRest} property. */ private final MetaProperty<Boolean> _publishRest = DirectMetaProperty.ofReadWrite( this, "publishRest", LegalEntitySourceComponentFactory.class, Boolean.TYPE); /** * The meta-property for the {@code legalEntityMaster} property. */ private final MetaProperty<LegalEntityMaster> _legalEntityMaster = DirectMetaProperty.ofReadWrite( this, "legalEntityMaster", LegalEntitySourceComponentFactory.class, LegalEntityMaster.class); /** * The meta-property for the {@code cacheManager} property. */ private final MetaProperty<CacheManager> _cacheManager = DirectMetaProperty.ofReadWrite( this, "cacheManager", LegalEntitySourceComponentFactory.class, CacheManager.class); /** * The meta-properties. */ private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap( this, (DirectMetaPropertyMap) super.metaPropertyMap(), "classifier", "publishRest", "legalEntityMaster", "cacheManager"); /** * Restricted constructor. */ protected Meta() { } @Override protected MetaProperty<?> metaPropertyGet(String propertyName) { switch (propertyName.hashCode()) { case -281470431: // classifier return _classifier; case -614707837: // publishRest return _publishRest; case -1944474242: // legalEntityMaster return _legalEntityMaster; case -1452875317: // cacheManager return _cacheManager; } return super.metaPropertyGet(propertyName); } @Override public BeanBuilder<? extends LegalEntitySourceComponentFactory> builder() { return new DirectBeanBuilder<LegalEntitySourceComponentFactory>(new LegalEntitySourceComponentFactory()); } @Override public Class<? extends LegalEntitySourceComponentFactory> beanType() { return LegalEntitySourceComponentFactory.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 publishRest} property. * @return the meta-property, not null */ public final MetaProperty<Boolean> publishRest() { return _publishRest; } /** * The meta-property for the {@code legalEntityMaster} property. * @return the meta-property, not null */ public final MetaProperty<LegalEntityMaster> legalEntityMaster() { return _legalEntityMaster; } /** * 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 -281470431: // classifier return ((LegalEntitySourceComponentFactory) bean).getClassifier(); case -614707837: // publishRest return ((LegalEntitySourceComponentFactory) bean).isPublishRest(); case -1944474242: // legalEntityMaster return ((LegalEntitySourceComponentFactory) bean).getLegalEntityMaster(); case -1452875317: // cacheManager return ((LegalEntitySourceComponentFactory) bean).getCacheManager(); } return super.propertyGet(bean, propertyName, quiet); } @Override protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) { switch (propertyName.hashCode()) { case -281470431: // classifier ((LegalEntitySourceComponentFactory) bean).setClassifier((String) newValue); return; case -614707837: // publishRest ((LegalEntitySourceComponentFactory) bean).setPublishRest((Boolean) newValue); return; case -1944474242: // legalEntityMaster ((LegalEntitySourceComponentFactory) bean).setLegalEntityMaster((LegalEntityMaster) newValue); return; case -1452875317: // cacheManager ((LegalEntitySourceComponentFactory) bean).setCacheManager((CacheManager) newValue); return; } super.propertySet(bean, propertyName, newValue, quiet); } @Override protected void validate(Bean bean) { JodaBeanUtils.notNull(((LegalEntitySourceComponentFactory) bean)._classifier, "classifier"); JodaBeanUtils.notNull(((LegalEntitySourceComponentFactory) bean)._legalEntityMaster, "legalEntityMaster"); super.validate(bean); } } ///CLOVER:ON //-------------------------- AUTOGENERATED END -------------------------- }