/**
* Copyright (C) 2009 - present by OpenGamma Inc. and the OpenGamma group of companies
*
* Please see distribution for license.
*/
package com.opengamma.master.config;
import java.util.Map;
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 org.threeten.bp.Instant;
import com.opengamma.core.config.impl.ConfigItem;
import com.opengamma.id.ObjectId;
import com.opengamma.id.UniqueId;
import com.opengamma.master.AbstractDocument;
import com.opengamma.util.PublicSPI;
/**
* A document used to pass into and out of the config master.
*/
@PublicSPI
@BeanDefinition
public class ConfigDocument extends AbstractDocument {
/**
* The config object held by the document.
*/
@PropertyDefinition(set = "manual")
private ConfigItem<?> _config;
/**
* The config unique identifier.
* This field is managed by the master but must be set for updates.
*/
@PropertyDefinition(get = "manual", set = "manual")
private UniqueId _uniqueId;
/**
* The document name.
*/
private String _name;
/**
* Creates an empty document.
* This constructor is here for automated bean construction.
* This document is invalid until the document class gets set.
*/
private ConfigDocument() {
}
/**
* Creates an empty document.
*
* @param configItem the config item
*/
public ConfigDocument(ConfigItem<?> configItem) {
// this method accepts a ? rather than a ConfigItem<?> for caller flexibility
setConfig(configItem);
}
/**
* Creates an instance.
*
* @param <T> the type
* @param value the value
* @param type the type of the value
* @param name the name
* @param uid the unique identifier
* @param versionFrom the version from
* @param versionTo the version to
* @param correctionFrom the correction from
* @param correctionTo the correction to
*/
public <T> ConfigDocument(T value, Class<T> type, String name, UniqueId uid, Instant versionFrom, Instant versionTo, Instant correctionFrom, Instant correctionTo) {
ConfigItem<T> item = ConfigItem.of(value);
item.setName(name);
setVersionFromInstant(versionFrom);
setVersionToInstant(versionTo);
setCorrectionFromInstant(correctionFrom);
setCorrectionToInstant(correctionTo);
item.setType(type);
setConfig(item);
}
//-------------------------------------------------------------------------
@Override
public UniqueId getUniqueId() {
if (_uniqueId == null && getConfig() != null && getConfig().getUniqueId() != null) {
_uniqueId = getConfig().getUniqueId();
}
return _uniqueId;
}
@Override
public void setUniqueId(UniqueId uniqueId) {
_uniqueId = uniqueId;
if (getConfig() != null) {
getConfig().setUniqueId(uniqueId);
}
}
@Override
public ObjectId getObjectId() {
return getConfig().getObjectId();
}
/**
* Gets the name of the config item.
*
* @return the name
*/
public String getName() {
if (_name == null && getConfig() != null && getConfig().getName() != null) {
_name = getConfig().getName();
}
return _name;
}
/**
* Sets the name of the config item.
*
* @param name the name
*/
public void setName(String name) {
_name = name;
if (getConfig() != null) {
getConfig().setName(_name);
}
}
@Override
public ConfigItem<?> getValue() {
return getConfig();
}
/**
* Sets the config item.
*
* @param object the config item
*/
public void setConfig(ConfigItem<?> object) {
_config = object;
if (object != null) {
if (_name == null && object.getName() != null) {
_name = object.getName();
} else if (_name != null && object.getName() == null) {
object.setName(_name);
}
if (_uniqueId == null && object.getUniqueId() != null) {
_uniqueId = object.getUniqueId();
} else if (_uniqueId != null && object.getUniqueId() == null) {
object.setUniqueId(_uniqueId);
}
}
}
/**
* Gets the object type.
*
* @return the type, may be null
*/
public Class<?> getType() {
if (getConfig() != null) {
return getConfig().getType();
} else {
return null;
}
}
//------------------------- AUTOGENERATED START -------------------------
///CLOVER:OFF
/**
* The meta-bean for {@code ConfigDocument}.
* @return the meta-bean, not null
*/
public static ConfigDocument.Meta meta() {
return ConfigDocument.Meta.INSTANCE;
}
static {
JodaBeanUtils.registerMetaBean(ConfigDocument.Meta.INSTANCE);
}
@Override
public ConfigDocument.Meta metaBean() {
return ConfigDocument.Meta.INSTANCE;
}
//-----------------------------------------------------------------------
/**
* Gets the config object held by the document.
* @return the value of the property
*/
public ConfigItem<?> getConfig() {
return _config;
}
/**
* Gets the the {@code config} property.
* @return the property, not null
*/
public final Property<ConfigItem<?>> config() {
return metaBean().config().createProperty(this);
}
//-----------------------------------------------------------------------
/**
* Gets the the {@code uniqueId} property.
* This field is managed by the master but must be set for updates.
* @return the property, not null
*/
public final Property<UniqueId> uniqueId() {
return metaBean().uniqueId().createProperty(this);
}
//-----------------------------------------------------------------------
@Override
public ConfigDocument clone() {
return JodaBeanUtils.cloneAlways(this);
}
@Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj != null && obj.getClass() == this.getClass()) {
ConfigDocument other = (ConfigDocument) obj;
return JodaBeanUtils.equal(getConfig(), other.getConfig()) &&
JodaBeanUtils.equal(getUniqueId(), other.getUniqueId()) &&
super.equals(obj);
}
return false;
}
@Override
public int hashCode() {
int hash = 7;
hash = hash * 31 + JodaBeanUtils.hashCode(getConfig());
hash = hash * 31 + JodaBeanUtils.hashCode(getUniqueId());
return hash ^ super.hashCode();
}
@Override
public String toString() {
StringBuilder buf = new StringBuilder(96);
buf.append("ConfigDocument{");
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("config").append('=').append(JodaBeanUtils.toString(getConfig())).append(',').append(' ');
buf.append("uniqueId").append('=').append(JodaBeanUtils.toString(getUniqueId())).append(',').append(' ');
}
//-----------------------------------------------------------------------
/**
* The meta-bean for {@code ConfigDocument}.
*/
public static class Meta extends AbstractDocument.Meta {
/**
* The singleton instance of the meta-bean.
*/
static final Meta INSTANCE = new Meta();
/**
* The meta-property for the {@code config} property.
*/
@SuppressWarnings({"unchecked", "rawtypes" })
private final MetaProperty<ConfigItem<?>> _config = DirectMetaProperty.ofReadWrite(
this, "config", ConfigDocument.class, (Class) ConfigItem.class);
/**
* The meta-property for the {@code uniqueId} property.
*/
private final MetaProperty<UniqueId> _uniqueId = DirectMetaProperty.ofReadWrite(
this, "uniqueId", ConfigDocument.class, UniqueId.class);
/**
* The meta-properties.
*/
private final Map<String, MetaProperty<?>> _metaPropertyMap$ = new DirectMetaPropertyMap(
this, (DirectMetaPropertyMap) super.metaPropertyMap(),
"config",
"uniqueId");
/**
* Restricted constructor.
*/
protected Meta() {
}
@Override
protected MetaProperty<?> metaPropertyGet(String propertyName) {
switch (propertyName.hashCode()) {
case -1354792126: // config
return _config;
case -294460212: // uniqueId
return _uniqueId;
}
return super.metaPropertyGet(propertyName);
}
@Override
public BeanBuilder<? extends ConfigDocument> builder() {
return new DirectBeanBuilder<ConfigDocument>(new ConfigDocument());
}
@Override
public Class<? extends ConfigDocument> beanType() {
return ConfigDocument.class;
}
@Override
public Map<String, MetaProperty<?>> metaPropertyMap() {
return _metaPropertyMap$;
}
//-----------------------------------------------------------------------
/**
* The meta-property for the {@code config} property.
* @return the meta-property, not null
*/
public final MetaProperty<ConfigItem<?>> config() {
return _config;
}
/**
* The meta-property for the {@code uniqueId} property.
* @return the meta-property, not null
*/
public final MetaProperty<UniqueId> uniqueId() {
return _uniqueId;
}
//-----------------------------------------------------------------------
@Override
protected Object propertyGet(Bean bean, String propertyName, boolean quiet) {
switch (propertyName.hashCode()) {
case -1354792126: // config
return ((ConfigDocument) bean).getConfig();
case -294460212: // uniqueId
return ((ConfigDocument) bean).getUniqueId();
}
return super.propertyGet(bean, propertyName, quiet);
}
@Override
protected void propertySet(Bean bean, String propertyName, Object newValue, boolean quiet) {
switch (propertyName.hashCode()) {
case -1354792126: // config
((ConfigDocument) bean).setConfig((ConfigItem<?>) newValue);
return;
case -294460212: // uniqueId
((ConfigDocument) bean).setUniqueId((UniqueId) newValue);
return;
}
super.propertySet(bean, propertyName, newValue, quiet);
}
}
///CLOVER:ON
//-------------------------- AUTOGENERATED END --------------------------
}