/**
* Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.component.factory.master;
import java.util.HashMap;
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.master.position.PositionMaster;
import com.opengamma.master.position.impl.DataPositionMasterResource;
import com.opengamma.master.position.impl.DelegatingPositionMaster;
import com.opengamma.master.position.impl.RemotePositionMaster;
/**
* Component factory for the combined position master.
* <p>
* This factory creates a combined position master from an underlying and user master.
*/
@BeanDefinition
public class CombinedPositionMasterComponentFactory 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 position master.
*/
@PropertyDefinition(validate = "notNull")
private PositionMaster _underlyingPositionMaster;
/**
* The user position master.
*/
@PropertyDefinition(validate = "notNull")
private PositionMaster _userPositionMaster;
//-------------------------------------------------------------------------
@Override
public void init(ComponentRepository repo, LinkedHashMap<String, String> configuration) {
Map<String, PositionMaster> map = new HashMap<String, PositionMaster>();
String scheme = repo.getInfo(getUserPositionMaster()).getAttribute(ComponentInfoAttributes.UNIQUE_ID_SCHEME);
map.put(scheme, getUserPositionMaster());
PositionMaster master = new DelegatingPositionMaster(getUnderlyingPositionMaster(), map);
// register
ComponentInfo info = new ComponentInfo(PositionMaster.class, getClassifier());
info.addAttribute(ComponentInfoAttributes.LEVEL, 2);
info.addAttribute(ComponentInfoAttributes.REMOTE_CLIENT_JAVA, RemotePositionMaster.class);
repo.registerComponent(info, master);
if (isPublishRest()) {
repo.getRestComponents().publish(info, new DataPositionMasterResource(master));
}
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code CombinedPositionMasterComponentFactory}.
* @return the meta-bean, not null
*/
public static CombinedPositionMasterComponentFactory.Meta meta() {
return CombinedPositionMasterComponentFactory.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(CombinedPositionMasterComponentFactory.Meta.INSTANCE);
}
@Override
public CombinedPositionMasterComponentFactory.Meta metaBean() {
return CombinedPositionMasterComponentFactory.Meta.INSTANCE;
}
@Override
protected Object propertyGet(String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return getClassifier();
case -614707837: // publishRest
return isPublishRest();
case -440936024: // underlyingPositionMaster
return getUnderlyingPositionMaster();
case 1808868758: // userPositionMaster
return getUserPositionMaster();
}
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 -614707837: // publishRest
setPublishRest((Boolean) newValue);
return;
case -440936024: // underlyingPositionMaster
setUnderlyingPositionMaster((PositionMaster) newValue);
return;
case 1808868758: // userPositionMaster
setUserPositionMaster((PositionMaster) newValue);
return;
}
super.propertySet(propertyName, newValue, quiet);
}
@Override
protected void validate() {
JodaBeanUtils.notNull(_classifier, "classifier");
JodaBeanUtils.notNull(_underlyingPositionMaster, "underlyingPositionMaster");
JodaBeanUtils.notNull(_userPositionMaster, "userPositionMaster");
super.validate();
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
CombinedPositionMasterComponentFactory other = (CombinedPositionMasterComponentFactory) obj;
return JodaBeanUtils.equal(getClassifier(), other.getClassifier()) &&
JodaBeanUtils.equal(isPublishRest(), other.isPublishRest()) &&
JodaBeanUtils.equal(getUnderlyingPositionMaster(), other.getUnderlyingPositionMaster()) &&
JodaBeanUtils.equal(getUserPositionMaster(), other.getUserPositionMaster()) &&
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(getUnderlyingPositionMaster());
hash += hash * 31 + JodaBeanUtils.hashCode(getUserPositionMaster());
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 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 position master.
* @return the value of the property, not null
*/
public PositionMaster getUnderlyingPositionMaster() {
return _underlyingPositionMaster;
}
/**
* Sets the underlying position master.
* @param underlyingPositionMaster the new value of the property, not null
*/
public void setUnderlyingPositionMaster(PositionMaster underlyingPositionMaster) {
JodaBeanUtils.notNull(underlyingPositionMaster, "underlyingPositionMaster");
this._underlyingPositionMaster = underlyingPositionMaster;
}
/**
* Gets the the {@code underlyingPositionMaster} property.
* @return the property, not null
*/
public final Property<PositionMaster> underlyingPositionMaster() {
return metaBean().underlyingPositionMaster().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the user position master.
* @return the value of the property, not null
*/
public PositionMaster getUserPositionMaster() {
return _userPositionMaster;
}
/**
* Sets the user position master.
* @param userPositionMaster the new value of the property, not null
*/
public void setUserPositionMaster(PositionMaster userPositionMaster) {
JodaBeanUtils.notNull(userPositionMaster, "userPositionMaster");
this._userPositionMaster = userPositionMaster;
}
/**
* Gets the the {@code userPositionMaster} property.
* @return the property, not null
*/
public final Property<PositionMaster> userPositionMaster() {
return metaBean().userPositionMaster().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code CombinedPositionMasterComponentFactory}.
*/
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", CombinedPositionMasterComponentFactory.class, String.class);
/**
* The meta-property for the {@code publishRest} property.
*/
private final MetaProperty<Boolean> _publishRest = DirectMetaProperty.ofReadWrite(
this, "publishRest", CombinedPositionMasterComponentFactory.class, Boolean.TYPE);
/**
* The meta-property for the {@code underlyingPositionMaster} property.
*/
private final MetaProperty<PositionMaster> _underlyingPositionMaster = DirectMetaProperty.ofReadWrite(
this, "underlyingPositionMaster", CombinedPositionMasterComponentFactory.class, PositionMaster.class);
/**
* The meta-property for the {@code userPositionMaster} property.
*/
private final MetaProperty<PositionMaster> _userPositionMaster = DirectMetaProperty.ofReadWrite(
this, "userPositionMaster", CombinedPositionMasterComponentFactory.class, PositionMaster.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"classifier",
"publishRest",
"underlyingPositionMaster",
"userPositionMaster");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -281470431: // classifier
return _classifier;
case -614707837: // publishRest
return _publishRest;
case -440936024: // underlyingPositionMaster
return _underlyingPositionMaster;
case 1808868758: // userPositionMaster
return _userPositionMaster;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends CombinedPositionMasterComponentFactory> builder() {
return new DirectBeanBuilder<CombinedPositionMasterComponentFactory>(new CombinedPositionMasterComponentFactory());
}
@Override
public Class<? extends CombinedPositionMasterComponentFactory> beanType() {
return CombinedPositionMasterComponentFactory.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 underlyingPositionMaster} property.
* @return the meta-property, not null
*/
public final MetaProperty<PositionMaster> underlyingPositionMaster() {
return _underlyingPositionMaster;
}
/**
* The meta-property for the {@code userPositionMaster} property.
* @return the meta-property, not null
*/
public final MetaProperty<PositionMaster> userPositionMaster() {
return _userPositionMaster;
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}